Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2459879rdb; Wed, 4 Oct 2023 01:36:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IElaE1ZyOb9heuL3K4Kvm/rxgxZLUBMba1o0Xwxs/1/U2A127phDeTerAs+9PuWKjtajs3L X-Received: by 2002:a05:6a20:3cab:b0:15a:bf8:7dfc with SMTP id b43-20020a056a203cab00b0015a0bf87dfcmr1869617pzj.15.1696408570588; Wed, 04 Oct 2023 01:36:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696408570; cv=none; d=google.com; s=arc-20160816; b=TyPZqppBJRJFJYO6s2whpQn+CLvYf6OF4M9PzihEcXmD+k4ElXJPKAYLnqay1YH4vi xOEldcagHuI2DUI6qdn/Av3s0unw3eQVph7tQjI/97d4Ro+gDG+kUxzpaR/5p+00YZvo JLIC2SLs8vVtEFfy8Ll4IDmEm3++U7SIjBHNDnbFXpi//EzX8UDlLhHyG7eeGCZ8GuJk qchNloajPc/Muzov4sTsGOBnOch/mjHX6G5ATVZUjQ1dSuucbsYxTRoA7+3OKVXNZodY 3x1GMq2Fxx4XSXK3maExB30ab7p0eVvWcTtnmAy76kHyNuSQjcVb9J3F82Wqkyqg+z0s h5YA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:to:subject:message-id :date:from:in-reply-to:references:mime-version:dkim-signature; bh=V9Pvz5wjW4nQEQ8U042AuTMhwGm2vJJWl+JdrrFRANE=; fh=ynr5EydnKPGN370L74nTPR8zCMhIMJeqe00ZNKlXGaM=; b=Yq2xs9hIO8vKZ+fVl1eDbXPpP4qnowvUmbX/+EcxeV+TkWKeT/C3KXeMSXgovZjLpx FQhagLeRRqoAz1tg8qut4aWav55R3mcpUgkBSW/hdfQibEnulQGsg51ZWF6R/4+/3hQK vN8lXxo8ZpbpVIKBpOXx2tqFgZ1ErtYGJ1xU7zOuta1LtdUvupL6nt/2PXEenXAhLd4n 7u2k2+e5l9vF0wyhP1UwRHQsSp5CVUy8MM65m30ZATMevTHKLeNgPHG11OTRjdF7LUIp 48z+pXQdH+vxuchwc1a/+7Y2sjnwJ4wPdRkuJGU//n072SqUWeWTqpHxP0wHnwkQKCQL l9gA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mOp6+Svv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id f13-20020a170902ce8d00b001c62ce41077si3585665plg.492.2023.10.04.01.36.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 01:36:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mOp6+Svv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 2497C80323D8; Wed, 4 Oct 2023 01:35:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241709AbjJDIfX (ORCPT + 99 others); Wed, 4 Oct 2023 04:35:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241688AbjJDIfW (ORCPT ); Wed, 4 Oct 2023 04:35:22 -0400 Received: from mail-yw1-x112b.google.com (mail-yw1-x112b.google.com [IPv6:2607:f8b0:4864:20::112b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86969A7 for ; Wed, 4 Oct 2023 01:35:18 -0700 (PDT) Received: by mail-yw1-x112b.google.com with SMTP id 00721157ae682-5a2478862dbso22660817b3.2 for ; Wed, 04 Oct 2023 01:35:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696408517; x=1697013317; darn=vger.kernel.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=V9Pvz5wjW4nQEQ8U042AuTMhwGm2vJJWl+JdrrFRANE=; b=mOp6+SvvY1EPvyAmrP0haBzCOHQTDIV2iQyA6NxNWzZBRqFsLTRbkuUV9Cr60uliXn z8YIx4lW/6DaL17qylB0Kv+lXip64aEMiKrGyDbl3VFSBdgxujoZO0NE7VVKZrBgW7kp DFWhxJenY0juQNs0L9xbvs0EGaoJT+y3KUR4ccdQbyZ33WMl3YVJVgQoYM+AF6QCZDxK Rc7H6rNcF3qgZpW6ysEoDREtyLh1dnwP8WoitzfglPCwG7oQVO+BfFQGEw/6ErfV8hWc PXIiiYXGc0uRXdwhT2UfB4ez5Mi/iBp64HYVf6/UJ4z/dWgRHOSz2hm9zbMicMGZffnn snzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696408517; x=1697013317; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=V9Pvz5wjW4nQEQ8U042AuTMhwGm2vJJWl+JdrrFRANE=; b=IB8M6FZDRE5hkXuLTKat4G/wamg1kb5eh/D/rc6BOdQo9/teGyqPiydUjqH52YUHjN BIyoYZftj9Qkr+KAOxiB/0mkiEnXiTM4O25FXcR8ilqKoEuVLEmELjtHurcxmN6CMNOk PaTTSKgw0SJAOsvdhduQxGjcXWlNHU+V6ADG9y0o7G8rrOppVlyK61ZXg1fWpMnz3g1I oJz8xNOAt/1b71CmiVDEOqeGHu9qcZsFwTDn6oBv99ZfuQvHCSzi/WLn2iHtlvn/kL1U alYaDaXgSoHXGlU9foWqiLAZDKfbnEZCGPgHqwtqct0lihKserdlH7Q5gv2y8pQSQO7V OhPA== X-Gm-Message-State: AOJu0YwCdGf+JNzSG0bzx0+tSugeYQHwTtJvDzlBwl0sIIrtlhtLnugP f8KjTcSRk+VbDP1A3VZW5m0R/aSiU4Mq2m0tJphE/A== X-Received: by 2002:a0d:d203:0:b0:58d:7ec3:16c4 with SMTP id u3-20020a0dd203000000b0058d7ec316c4mr1815920ywd.34.1696408517703; Wed, 04 Oct 2023 01:35:17 -0700 (PDT) MIME-Version: 1.0 References: <20231002021602.260100-1-takahiro.akashi@linaro.org> <20231002021602.260100-4-takahiro.akashi@linaro.org> In-Reply-To: From: Linus Walleij Date: Wed, 4 Oct 2023 10:35:05 +0200 Message-ID: Subject: Re: [RFC 3/4] gpio: scmi: add SCMI pinctrl based gpio driver To: AKASHI Takahiro , Linus Walleij , sudeep.holla@arm.com, cristian.marussi@arm.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, Oleksii_Moisieiev@epam.com, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 04 Oct 2023 01:35:34 -0700 (PDT) Hi Takahiro, I see you are on track with this! Some clarifications: On Wed, Oct 4, 2023 at 8:53=E2=80=AFAM AKASHI Takahiro wrote: > I'm still not sure whether my approach can be applied to any other > pinctrl-based gpio drivers, in which extra (driver-specific) operations > might be needed around the generic pinctrl_gpio helpers (i.e. gpiolib.c). > For instance, look at gpio-tegra.c: Yeah, it kind of requires a "pure" pin controller underneath that don't want to do anything else on any operations, otherwise we are back to a per-soc pin control driver. But I think it is appropriate for abstractions that strive to provide "total abstraction behind a firmware", so such as SCMI or ACPI (heh). > > Skip this, let's use device properties instead. They will anyways just = translate > > to OF properties in the OF case. > > Okay, I don't know how device properties work, though. They are pretty much 1-to-1 slot-ins for the corresponding of_* functions, passing struct device * instead of struct device_node *, if you look in include/linux/property.h you will feel at home very quickly. > > > +static int scmi_gpio_get_direction(struct gpio_chip *chip, unsigned = int offset) > > > > Rename all functions pinctrl_gpio_* > > Well, this change will result in name conflicts against existing > pinctrl_gpio_direction_[in|out]out(). So use "pin_control_gpio_" prefix. Yeah that works, or pincontro_by_gpio_ or such. > Not sure how the last case (in_en && out_en && DRIVE_OPEN_DRAIN) works. I wrote some documentation! But it is hidden deep in the docs: https://docs.kernel.org/driver-api/gpio/driver.html#gpio-lines-with-open-dr= ain-source-support > In order to be able to read a value as an input pin, I think, we need > to set the output status to Hi-Z. Then we should recognize it as "INPUT"? > In this case, however, we cannot distinguish the other case where we want > to use the pin as OUTPUT and drive it to (active) high. With open drain, on GPIO controllers that do not support a native open drain mode, we emulate open drain output high by switching the line into input mode. The line in this case has a pull-up resistor (internal or external) and as input mode is high-Z the pull up resistor will pull the signal high, to any level - could be e.g 48V which is helpful for some serial links. But this case is really tricky so it can be hard to get things right, I get a bit confused and so we need to think about it a few times. > > > +static void scmi_gpio_set(struct gpio_chip *chip, unsigned int offse= t, int val) > > > > static int? > > Unfortunately, the function prototype of "set" in struct gpio_device is > void (*set)(struct gpio_chip *gc, unsigned int offset, int value)= ; > > So we cannot propagate an error to the caller. Grrr that must be my fault. Sorry about not fixing this :( > > No need to add & 0x01, the gpiolib core already does this. > > Which part of gpiolib core? chip->set =3D scmi_gpio_set; gets called like this in gpiolib: gpiod_direction_output_raw_commit(..., int value) { int val =3D !!value; (...) gc->set(gc, gpio_chip_hwgpio(desc), val); Notice clamping int val =3D !!value; will make the passed val 0 or 1. > > > +static u16 sum_up_ngpios(struct gpio_chip *chip) > > > +{ > > > + struct gpio_pin_range *range; > > > + struct gpio_device *gdev =3D chip->gpiodev; > > > + u16 ngpios =3D 0; > > > + > > > + list_for_each_entry(range, &gdev->pin_ranges, node) { > > > + ngpios +=3D range->range.npins; > > > + } > > > > This works but isn't really the intended use case of the ranges. > > Feel a bit uncertain about it, but I can't think of anything better. > > And I guess these come directly out of SCMI so it's first hand > > information about all GPIOs. > > I don't get your point. > However many pins SCMI firmware (or other normal pin controllers) might > expose, the total number of pins available by this driver is limited by > "gpio-ranges" property. > So the sum as "ngpios" should make sense unless a user accidentally > specifies a wrong range of pins. Yes. And it is this fact that the same number need to appear in two places and double-specification will sooner or later bring us to the situation where the two do not agree, and what do we do then? If the ranges come from firmware, which is subject to change such as "oops we forgot this pin", the GPIO number will just insert itself among the already existing ones: say we have two ranges: 1: 0..5 2: 6..9 Ooops forgot a GPIO in the first range, it has to be bumped to 0..6. But somewhere in the device tree there is: foo-gpios =3D <&scmi_gpio 7 GPIO_OUT_LOW>; So now this is wrong (need to be changed to 8) and we have zero tooling to detect this, the author just has to be very careful all the time. But I honestly do not know any better way. > > which in turn becomes just pinctrl_gpio_set_config(), which > > is what we want. > > > > The second cell in two-cell GPIOs already supports passing > > GPIO_PUSH_PULL, GPIO_OPEN_DRAIN, GPIO_OPEN_SOURCE, > > GPIO_PULL_UP, GPIO_PULL_DOWN, GPIO_PULL_DISABLE, > > which you can this way trivially pass down to the pin control driver. > > > > NB: make sure the scmi pin control driver returns error for > > unknown configs. > > Well, the error will be determined by SCMI firmware(server) > not the driver itself :) Hehe, I think it is good that the SCMI firmware gets some exercise from day 1! Yours, Linus Walleij