Message ID | 20231009-pxa-gpio-v7-2-c8f5f403e856@skole.hr |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp2053094vqo; Mon, 9 Oct 2023 11:34:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFzK3DTim/n1XTm1tDMfcexpYjqypn7DoKg8A3a5Seh/DIZG5Es+EvZGXGIKY701Rnk1nix X-Received: by 2002:a05:6a21:788f:b0:161:a795:2322 with SMTP id bf15-20020a056a21788f00b00161a7952322mr20286982pzc.18.1696876469057; Mon, 09 Oct 2023 11:34:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696876469; cv=none; d=google.com; s=arc-20160816; b=RgXcQA/WXMDdC4CkX3uX4BYq7oIs3bQDBqLHNJBYEvkZB8tZXUFiV6v8w25pxT9paO L+XXrJ7YOOfI2zUpwNldx6QCsvE64vrM/k+DPNirmLh6en2UpZNvj5ta6ouJWG8oDwGb /FyrLJTKyj6f6Vflx5V3GLLNuUWoqTnDJEUGwxo7J3nSb2eNdnGuXC4CIde0ycM2U/xE VdcN7MFIEKhYoYsBbq14L4EdcgOu0fGr/opKD3EjYYy0rfFVmqDJPUJlRLE4Gkp5DmBz d4UW2qxhi43N8XuLZ27ZJx8YLNZyDjWDVDVXAMj3ADlk1gOAj+He/eaf6r1jqpjSXNFA nP7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from; bh=fFXERX5Mjw9o8ODRscxnc+LYIBlMljYnODp9ya817nk=; fh=H4D8raVEE9ToK4xcGS9/Pnvmhs2QUzCYuQTuaKubzik=; b=IBSW2ovREfUZhy6XSd4mZ4/wAM6jCaMFSKSk9OZu2tOjFT4Xd9AMiXEpg7MCT2sBcn h5mjyVkhnSH/fffjBGWS3TBqOgAhhjCbjKFi4DeJRoMODvMhHX0hx2S2mie6qr8n7j7l RIiawFy+A9a7SIRuQvYITfRRM4zOyR3Iy2fdVs0U8AujzjyyhUtkCxorNSsxho8JnpNo jCNdI1UwR0Z7U1QZOrSNMVAugunP04NlDiZZeUTsV05ZD1f/8YFgNBvdhZ+TR9MiJVY/ 0gagIvU8OOB7+RF5IMs73UF5UraMJ5DbASE+xqe6VTBQt68YqY3ElYQlh5iAKYXfxb3R pplA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id q7-20020a170902eb8700b001c3886b091asi9799321plg.127.2023.10.09.11.34.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 11:34:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 42933801B6C2; Mon, 9 Oct 2023 11:34:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378088AbjJISeY (ORCPT <rfc822;ezelljr.billy@gmail.com> + 18 others); Mon, 9 Oct 2023 14:34:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377501AbjJISeS (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 9 Oct 2023 14:34:18 -0400 Received: from mx.skole.hr (mx2.hosting.skole.hr [161.53.165.186]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECFA6A3; Mon, 9 Oct 2023 11:34:16 -0700 (PDT) Received: from mx2.hosting.skole.hr (localhost.localdomain [127.0.0.1]) by mx.skole.hr (mx.skole.hr) with ESMTP id 369F084A5E; Mon, 9 Oct 2023 20:34:15 +0200 (CEST) From: =?utf-8?q?Duje_Mihanovi=C4=87?= <duje.mihanovic@skole.hr> Date: Mon, 09 Oct 2023 20:33:59 +0200 Subject: [PATCH RFT v7 2/6] ARM: pxa: Convert Spitz LEDs to GPIO descriptors MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20231009-pxa-gpio-v7-2-c8f5f403e856@skole.hr> References: <20231009-pxa-gpio-v7-0-c8f5f403e856@skole.hr> In-Reply-To: <20231009-pxa-gpio-v7-0-c8f5f403e856@skole.hr> To: Daniel Mack <daniel@zonque.org>, Haojian Zhuang <haojian.zhuang@gmail.com>, Robert Jarzmik <robert.jarzmik@free.fr>, Russell King <linux@armlinux.org.uk>, Alan Stern <stern@rowland.harvard.edu>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Linus Walleij <linus.walleij@linaro.org>, Bartosz Golaszewski <brgl@bgdev.pl>, Andy Shevchenko <andy@kernel.org>, Dmitry Torokhov <dmitry.torokhov@gmail.com>, Mark Brown <broonie@kernel.org> Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, linux-gpio@vger.kernel.org, linux-input@vger.kernel.org, linux-spi@vger.kernel.org, =?utf-8?q?Duje_Miha?= =?utf-8?q?novi=C4=87?= <duje.mihanovic@skole.hr> X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1901; i=duje.mihanovic@skole.hr; h=from:subject:message-id; bh=1yohBJVEfo/Ind1Hy9PsJ4oqUarD4e31qtGoJ3pSoVs=; b=owEBbQKS/ZANAwAIAZoRnrBCLZbhAcsmYgBlJEebN4SaAkwbFMrouTWoLrPxDXVIwqGRBrDWP T7+X4lCGGSJAjMEAAEIAB0WIQRT351NnD/hEPs2LXiaEZ6wQi2W4QUCZSRHmwAKCRCaEZ6wQi2W 4YnTD/9TbKA78usjrLVWzYn9dLTIC4KdDQgikMTjRVQOAVbRYlss86P3CeKlsB5ZFqC0/TJHPrr fEWfYLaxdi2WeaDUqyVQRMxkAH2LB0NY6vdZD7qXi+gFhEhV5hhmAI0ePxcloR+iUXi75dM65W4 XR7TqoDRK8VWqOr4CEr/6SUnlzie2FgjMhWHZv8l8JwcZrWEVCEt0qpPh5//TGcbzcUT5MKrmaJ z4kS+/hSiY/vXVuZ2YfYA+jxk2kQ/u8sOZ8Dg+37uVYRJJaevxXWmT6jHIJng6BEkqp/VQnatfr kD5q/+dRRpxVDqkt09i13ejeCkG4IHv/VidcpJbccv2FKqdd8SMywmVxgLMrlstOxFuodl19vaX 3xahrJ/po+rZO87FFR7uC6H5mPOUSPRKZziGZZPx+RXv0RIy7hWgzVv6MKBf8rsdWngEm2LLkHx nNAF4IcXUoQXiYt2a8H2EGTaA37ccrKH6ZlpjfpnG0MDkQ9cTP+TvuifoveZ+32Yhh7AYTuSha+ /ZxRixBZUV49nvkwfJ8KyD7FLRaqqJNDZG1b5Sis2N9DhExqnWoKpZxzaKkIrJdN1nkQeTfiSKZ GfYYS256QOkH48AS0O9Fr+9YpTmOUthr9Pz/+GZO7zhYbMCCIw9ING02edmdxEWrh1dLNUV5khg zXFzN58cPTKJ36Q== X-Developer-Key: i=duje.mihanovic@skole.hr; a=openpgp; fpr=53DF9D4D9C3FE110FB362D789A119EB0422D96E1 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 09 Oct 2023 11:34:28 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779303940380984706 X-GMAIL-MSGID: 1779303940380984706 |
Series |
ARM: pxa: GPIO descriptor conversions
|
|
Commit Message
Duje Mihanović
Oct. 9, 2023, 6:33 p.m. UTC
Sharp's Spitz board still uses the legacy GPIO interface for configuring its two onboard LEDs. Convert them to use the GPIO descriptor interface. Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Duje Mihanović <duje.mihanovic@skole.hr> --- arch/arm/mach-pxa/spitz.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
Comments
On Mon, Oct 9, 2023 at 8:34 PM Duje Mihanović <duje.mihanovic@skole.hr> wrote: > > Sharp's Spitz board still uses the legacy GPIO interface for configuring > its two onboard LEDs. > > Convert them to use the GPIO descriptor interface. > > Reviewed-by: Linus Walleij <linus.walleij@linaro.org> > Signed-off-by: Duje Mihanović <duje.mihanovic@skole.hr> > --- > arch/arm/mach-pxa/spitz.c | 20 ++++++++++++++++++-- > 1 file changed, 18 insertions(+), 2 deletions(-) > > diff --git a/arch/arm/mach-pxa/spitz.c b/arch/arm/mach-pxa/spitz.c > index 535e2b2e997b..29907abc4513 100644 > --- a/arch/arm/mach-pxa/spitz.c > +++ b/arch/arm/mach-pxa/spitz.c > @@ -452,16 +452,25 @@ static inline void spitz_keys_init(void) {} > * LEDs > ******************************************************************************/ > #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE) > +static struct gpiod_lookup_table spitz_led_gpio_table = { > + .dev_id = "leds-gpio", > + .table = { > + GPIO_LOOKUP_IDX("pxa-gpio", SPITZ_GPIO_LED_ORANGE, NULL, 0, > + GPIO_ACTIVE_HIGH), > + GPIO_LOOKUP_IDX("pxa-gpio", SPITZ_GPIO_LED_GREEN, NULL, 1, > + GPIO_ACTIVE_HIGH), > + { } > + } > +}; > + > static struct gpio_led spitz_gpio_leds[] = { > { > .name = "spitz:amber:charge", > .default_trigger = "sharpsl-charge", > - .gpio = SPITZ_GPIO_LED_ORANGE, > }, > { > .name = "spitz:green:hddactivity", > .default_trigger = "disk-activity", > - .gpio = SPITZ_GPIO_LED_GREEN, > }, > }; > > @@ -478,9 +487,16 @@ static struct platform_device spitz_led_device = { > }, > }; > > +static struct gpio_descs *leds; > + > static void __init spitz_leds_init(void) > { > + gpiod_add_lookup_table(&spitz_led_gpio_table); > platform_device_register(&spitz_led_device); > + leds = gpiod_get_array_optional(&spitz_led_device.dev, > + NULL, GPIOD_ASIS); > + spitz_gpio_leds[0].gpiod = leds->desc[0]; > + spitz_gpio_leds[1].gpiod = leds->desc[1]; > } > #else > static inline void spitz_leds_init(void) {} > > -- > 2.42.0 > > Gah! I should have noticed this earlier but this is a perfect candidate for using hogs. Can you use gpiod_add_hogs() from linux/gpio/machine.h instead? That would save you having the lookup and the static leds descriptor array. Bart
On Tuesday, October 10, 2023 1:12:05 PM CEST Bartosz Golaszewski wrote: > Gah! I should have noticed this earlier but this is a perfect > candidate for using hogs. Can you use gpiod_add_hogs() from > linux/gpio/machine.h instead? That would save you having the lookup > and the static leds descriptor array. From what I can tell, the hogs keep a certain pin at a certain state as long as the machine is powered on. Is this really what we want to do with LEDs or am I missing something? Regards, Duje
On Tue, Oct 10, 2023 at 6:33 PM Duje Mihanović <duje.mihanovic@skole.hr> wrote: > > On Tuesday, October 10, 2023 1:12:05 PM CEST Bartosz Golaszewski wrote: > > Gah! I should have noticed this earlier but this is a perfect > > candidate for using hogs. Can you use gpiod_add_hogs() from > > linux/gpio/machine.h instead? That would save you having the lookup > > and the static leds descriptor array. > > From what I can tell, the hogs keep a certain pin at a certain state as long > as the machine is powered on. Is this really what we want to do with LEDs or > am I missing something? > It doesn't seem like anyone is using these GPIOs once they're requested? Wouldn't the above definitios be analogous to: GPIO_HOG("pxa-gpio", SPITZ_GPIO_LED_ORANGE, NULL, GPIO_ACTIVE_HIGH, GPIOD_ASIS) GPIO_HOG("pxa-gpio", SPITZ_GPIO_LED_GREEN, NULL, GPIO_ACTIVE_HIGH, GPIOD_ASIS) ? Bart
On Tue, Oct 10, 2023 at 7:39 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote: > It doesn't seem like anyone is using these GPIOs once they're > requested? Wouldn't the above definitios be analogous to: > > GPIO_HOG("pxa-gpio", SPITZ_GPIO_LED_ORANGE, NULL, GPIO_ACTIVE_HIGH, GPIOD_ASIS) > GPIO_HOG("pxa-gpio", SPITZ_GPIO_LED_GREEN, NULL, GPIO_ACTIVE_HIGH, GPIOD_ASIS) They are used: + spitz_gpio_leds[0].gpiod = leds->desc[0]; + spitz_gpio_leds[1].gpiod = leds->desc[1]; The descriptors are passed to the leds-gpio driver. But wait: no. This whole thing: +static struct gpio_descs *leds; + (...) + leds = gpiod_get_array_optional(&spitz_led_device.dev, + NULL, GPIOD_ASIS); + spitz_gpio_leds[0].gpiod = leds->desc[0]; + spitz_gpio_leds[1].gpiod = leds->desc[1]; Just delete all that. The leds-gpio driver will request and use the lines. It was just so unorthodox that I missed it. Adding the descriptor table is enough. Yours, Linus Walleij
On Tue, Oct 10, 2023 at 10:04 PM Linus Walleij <linus.walleij@linaro.org> wrote: > > On Tue, Oct 10, 2023 at 7:39 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote: > > > It doesn't seem like anyone is using these GPIOs once they're > > requested? Wouldn't the above definitios be analogous to: > > > > GPIO_HOG("pxa-gpio", SPITZ_GPIO_LED_ORANGE, NULL, GPIO_ACTIVE_HIGH, GPIOD_ASIS) > > GPIO_HOG("pxa-gpio", SPITZ_GPIO_LED_GREEN, NULL, GPIO_ACTIVE_HIGH, GPIOD_ASIS) > > They are used: > + spitz_gpio_leds[0].gpiod = leds->desc[0]; > + spitz_gpio_leds[1].gpiod = leds->desc[1]; > > The descriptors are passed to the leds-gpio driver. > > But wait: no. > > This whole thing: > > +static struct gpio_descs *leds; > + > (...) > + leds = gpiod_get_array_optional(&spitz_led_device.dev, > + NULL, GPIOD_ASIS); > + spitz_gpio_leds[0].gpiod = leds->desc[0]; > + spitz_gpio_leds[1].gpiod = leds->desc[1]; > > Just delete all that. > > The leds-gpio driver will request and use the lines. > > It was just so unorthodox that I missed it. Adding the descriptor > table is enough. Ah, good catch. Your suggestion is of course the correct one. Bart > > Yours, > Linus Walleij
diff --git a/arch/arm/mach-pxa/spitz.c b/arch/arm/mach-pxa/spitz.c index 535e2b2e997b..29907abc4513 100644 --- a/arch/arm/mach-pxa/spitz.c +++ b/arch/arm/mach-pxa/spitz.c @@ -452,16 +452,25 @@ static inline void spitz_keys_init(void) {} * LEDs ******************************************************************************/ #if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE) +static struct gpiod_lookup_table spitz_led_gpio_table = { + .dev_id = "leds-gpio", + .table = { + GPIO_LOOKUP_IDX("pxa-gpio", SPITZ_GPIO_LED_ORANGE, NULL, 0, + GPIO_ACTIVE_HIGH), + GPIO_LOOKUP_IDX("pxa-gpio", SPITZ_GPIO_LED_GREEN, NULL, 1, + GPIO_ACTIVE_HIGH), + { } + } +}; + static struct gpio_led spitz_gpio_leds[] = { { .name = "spitz:amber:charge", .default_trigger = "sharpsl-charge", - .gpio = SPITZ_GPIO_LED_ORANGE, }, { .name = "spitz:green:hddactivity", .default_trigger = "disk-activity", - .gpio = SPITZ_GPIO_LED_GREEN, }, }; @@ -478,9 +487,16 @@ static struct platform_device spitz_led_device = { }, }; +static struct gpio_descs *leds; + static void __init spitz_leds_init(void) { + gpiod_add_lookup_table(&spitz_led_gpio_table); platform_device_register(&spitz_led_device); + leds = gpiod_get_array_optional(&spitz_led_device.dev, + NULL, GPIOD_ASIS); + spitz_gpio_leds[0].gpiod = leds->desc[0]; + spitz_gpio_leds[1].gpiod = leds->desc[1]; } #else static inline void spitz_leds_init(void) {}