From patchwork Sun May 27 13:55:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 10429377 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A276560362 for ; Sun, 27 May 2018 13:57:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F52528C80 for ; Sun, 27 May 2018 13:57:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8113F28C78; Sun, 27 May 2018 13:57:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AC95E28C71 for ; Sun, 27 May 2018 13:57:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=LAMDJdtOJmeyBOWMCDE3g80RBKdslGFAzuBkBSFiv4Q=; b=gMvuiKAPDETIYuFC2CDJav60SB fKhgf7X0LOcvr0QdBPYSBiRRMfR9BWiEuPGLlyUmOORIhSP/dnFd8IXC+g/e49MHNU1vUvzzCSLPr 4DSt8Ti1g58pYi7eHv9kzYSfc1ny6L3X/IuIigmodQsYahUF6Wj5eKscAaQApAAG+GwdngocJ1+dB hHR6Oprz48u3T7JZRwIz8Az0jZel0DJXdB+lH/DH7RVSpBSCo3YbgfskbLg6b7abXccoHIwS6iTmB nnmVH6RK4bEzmQLrKwa3kL8UD5nFAaSMTDToWjDvBgbtPe5nOM4oBABTLukXKrvcM2rUXsQJsP4J6 vyV6RwEQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fMwAK-0002dZ-D5; Sun, 27 May 2018 13:56:56 +0000 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fMw9a-0002Ho-Uf for linux-arm-kernel@lists.infradead.org; Sun, 27 May 2018 13:56:22 +0000 Received: by mail-wr0-x241.google.com with SMTP id u12-v6so16212905wrn.8 for ; Sun, 27 May 2018 06:56:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DXGHB6khPzj0+w6AbTq+C+UXVTuC+9xOLCO004pfDb8=; b=LOFP4N4LndBLng432lYk1Hhg7NmvaBSWvBvquqWWCrLz2CHOjx+0DwF++9EWfmOE7a LWTa606IBheRNQpro+ZsuTNY2BwWMNN9PVFQ+5mR5y+x9kNFUHPlQR+DXhhSe/g20bvx U0S1Nzs7eoRp19uU6pXxMTH3FuiCkJPhJGf+rnmkNHqOdnQi5tl0lUZweXXnKXneYVZl aHLya6sHAbMPFs/H0xV2XQXxF3oAWN/87vnX60+mVSv4eVaERRvFtPNiZD/RYtu6l7wi tbkQlNkHrP4YSE7cOJqdzXwWreGyg99wKqlr3cWa9qqvMFGLP5n3+VlwXdVmq0t0gOSq 4Jeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DXGHB6khPzj0+w6AbTq+C+UXVTuC+9xOLCO004pfDb8=; b=JT0dBNarv/R9QrVonT8fwCaYlY4VA3Iqm2MBrUADW1QWN0Yv0WY5f3UyyqbmcqEIF5 vpyf1NFX4Tge0MoY0d6VK1Or/ymkqXskKrBO9XYR94zOJrF2TV1GE5TEkgHgCCvPqMu/ pHdGTC1uQ49aCTovQNfIc9ocuTlfSoxU0luk4AnA5Ed9N6jsOj96KCngJGxUG1xbI0Fk xXf5UrLf8/CNb7nNHkX9DY5bO0tnstN9R0NzZvJ83wNK/nodJEhQkIQulFAxm0oEz0/2 Et8d6K8xir9KNjSGWtUyU0l1oLDO7zmLWt4XZGG2HIGN/nay/M44mJ3wyH6vI1hWuBmx AAOQ== X-Gm-Message-State: ALKqPwfEDlwX2S/P8zmVCzkZBgPRCmlADgTz6m0y+53oS5bHg+E8jCYp PbnJ7dAjwWLaaE7hj2dQY90= X-Google-Smtp-Source: ADUXVKLFgOjxOL+8xOTpyBDhjMzt7zo8OCi58268z+bzJB3tlv0bEvBgr01uqmjV4c55o88YhUYgmw== X-Received: by 2002:a19:e9d3:: with SMTP id j80-v6mr649327lfk.129.1527429359118; Sun, 27 May 2018 06:55:59 -0700 (PDT) Received: from localhost.localdomain (apn-31-0-67-177.dynamic.gprs.plus.pl. [31.0.67.177]) by smtp.gmail.com with ESMTPSA id n63-v6sm1411502lfb.46.2018.05.27.06.55.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 27 May 2018 06:55:58 -0700 (PDT) From: Janusz Krzysztofik To: Tony Lindgren Subject: [PATCH 2/2] ARM: OMAP1: ams-delta: assign LED GPIO numbers from descriptors Date: Sun, 27 May 2018 15:55:48 +0200 Message-Id: <20180527135548.7904-2-jmkrzyszt@gmail.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180527135548.7904-1-jmkrzyszt@gmail.com> References: <20180527135548.7904-1-jmkrzyszt@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180527_065611_017451_8E9DE431 X-CRM114-Status: GOOD ( 21.94 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-omap@vger.kernel.org, Janusz Krzysztofik , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Aaro Koskinen MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Assign a label to latch1 GPIO device the LEDs hang off, enumerate its pins for the purpose of indexing gpio_led table, remove hardcoded GPIO numbers from that table replacing them with invalid GPIO numbers and remove initialization of incompletely described LED device from machine_init. As soon as the latch1 GPIO device is registered, use its label to find respective GPIO chip, identify each LED's GPIO descriptor by its pin number and assign its gobal GPIO number to the gpio_led table. Once completed, register the LED device. Created and tested against linux-v4.17-rc3. Signed-off-by: Janusz Krzysztofik --- arch/arm/mach-omap1/board-ams-delta.c | 116 ++++++++++++++++++++++++++++------ 1 file changed, 98 insertions(+), 18 deletions(-) diff --git a/arch/arm/mach-omap1/board-ams-delta.c b/arch/arm/mach-omap1/board-ams-delta.c index cdba8decc532..d4b26352ddde 100644 --- a/arch/arm/mach-omap1/board-ams-delta.c +++ b/arch/arm/mach-omap1/board-ams-delta.c @@ -179,7 +179,10 @@ static struct resource latch1_resources[] = { }, }; +#define LATCH1_LABEL "latch1" + static struct bgpio_pdata latch1_pdata = { + .label = LATCH1_LABEL, .base = LATCH1_GPIO_BASE, .ngpio = LATCH1_NGPIO, }; @@ -194,6 +197,15 @@ static struct platform_device latch1_gpio_device = { }, }; +#define LATCH1_PIN_LED_CAMERA 0 +#define LATCH1_PIN_LED_ADVERT 1 +#define LATCH1_PIN_LED_MAIL 2 +#define LATCH1_PIN_LED_HANDSFREE 3 +#define LATCH1_PIN_LED_VOICEMAIL 4 +#define LATCH1_PIN_LED_VOICE 5 +#define LATCH1_PIN_DOCKIT1 6 +#define LATCH1_PIN_DOCKIT2 7 + static struct resource latch2_resources[] = { [0] = { .name = "dat", @@ -398,38 +410,43 @@ static struct gpiod_lookup_table ams_delta_lcd_gpio_table = { }, }; -static const struct gpio_led gpio_leds[] __initconst = { - { +/* + * Dynamically allocated GPIO numbers must be obtained fromm GPIO device + * before they can be put in the gpio_led table. Before that happens, + * initialize the table with invalid GPIO numbers, not 0. + */ +static struct gpio_led gpio_leds[] __initdata = { + [LATCH1_PIN_LED_CAMERA] = { .name = "camera", - .gpio = LATCH1_GPIO_BASE + 0, + .gpio = -EINVAL, .default_state = LEDS_GPIO_DEFSTATE_OFF, #ifdef CONFIG_LEDS_TRIGGERS .default_trigger = "ams_delta_camera", #endif }, - { + [LATCH1_PIN_LED_ADVERT] = { .name = "advert", - .gpio = LATCH1_GPIO_BASE + 1, + .gpio = -EINVAL, .default_state = LEDS_GPIO_DEFSTATE_OFF, }, - { + [LATCH1_PIN_LED_MAIL] = { .name = "email", - .gpio = LATCH1_GPIO_BASE + 2, + .gpio = -EINVAL, .default_state = LEDS_GPIO_DEFSTATE_OFF, }, - { + [LATCH1_PIN_LED_HANDSFREE] = { .name = "handsfree", - .gpio = LATCH1_GPIO_BASE + 3, + .gpio = -EINVAL, .default_state = LEDS_GPIO_DEFSTATE_OFF, }, - { + [LATCH1_PIN_LED_VOICEMAIL] = { .name = "voicemail", - .gpio = LATCH1_GPIO_BASE + 4, + .gpio = -EINVAL, .default_state = LEDS_GPIO_DEFSTATE_OFF, }, - { + [LATCH1_PIN_LED_VOICE] = { .name = "voice", - .gpio = LATCH1_GPIO_BASE + 5, + .gpio = -EINVAL, .default_state = LEDS_GPIO_DEFSTATE_OFF, }, }; @@ -542,6 +559,22 @@ static struct gpiod_lookup_table *late_gpio_tables[] __initdata = { &ams_delta_nand_gpio_table, }; +/* + * Some drivers may not use GPIO lookup tables but need to be provided + * with GPIO numbers. The same applies to GPIO based IRQ lines - some + * drivers may even not use GPIO layer but expect just IRQ numbers. + * We could either define GPIO lookup tables then use them on behalf + * of those devices, or we can use GPIO driver level methods for + * identification of GPIO and IRQ numbers. For the purpose of the latter, + * defina a helper function which identifies GPIO chips by their labels. + */ +static int gpiochip_match_by_label(struct gpio_chip *chip, void *data) +{ + char *label = data; + + return !strcmp(label, chip->label); +} + static void __init ams_delta_init(void) { /* mux pins for uarts */ @@ -571,7 +604,6 @@ static void __init ams_delta_init(void) led_trigger_register_simple("ams_delta_camera", &ams_delta_camera_led_trigger); #endif - gpio_led_register_device(-1, &leds_pdata); platform_add_devices(ams_delta_devices, ARRAY_SIZE(ams_delta_devices)); /* @@ -643,16 +675,68 @@ static struct platform_device ams_delta_modem_device = { }, }; +/* + * leds-gpio driver doesn't make use of GPIO lookup tables, + * it has to be provided with GPIO numbers over platform data + * if GPIO descriptor info can't be obtained from device tree. + * We could either define GPIO lookup tables and use them on behalf + * of the leds-gpio device, or we can use GPIO driver level methods + * for identification of GPIO numbers as long as we don't support + * device tree. Let's do the latter. + */ +static void __init ams_delta_led_init(struct gpio_chip *chip) +{ + struct gpio_desc *gpiod; + int i; + + for (i = LATCH1_PIN_LED_CAMERA; i < LATCH1_PIN_DOCKIT1; i++) { + gpiod = gpiochip_request_own_desc(chip, i, NULL); + if (IS_ERR(gpiod)) { + pr_warn("%s: %s GPIO %d request failed (%ld)\n", + __func__, LATCH1_LABEL, i, PTR_ERR(gpiod)); + continue; + } + + /* Assign GPIO numbers to LED device. */ + gpio_leds[i].gpio = desc_to_gpio(gpiod); + + gpiochip_free_own_desc(gpiod); + } + + gpio_led_register_device(PLATFORM_DEVID_NONE, &leds_pdata); +} + +/* + * The purpose of this function is to take care of assignment of GPIO numbers + * to platform devices which depend on GPIO lines provided by Amstrad Delta + * latch1 and/or latch2 GPIO devices but don't use GPIO lookup tables. + * The function may be called as soon as latch1/latch2 GPIO devices are + * initilized. Since basic-mmio-gpio driver is not registered before + * device_initcall, this may happen at erliest during device_initcall_sync. + * Dependent devices shouldn't be registered before that, their + * registration may be performed from within this function or later. + */ static int __init ams_delta_gpio_init(void) { + struct gpio_chip *chip; int err; + if (!machine_is_ams_delta()) + return -ENODEV; + + chip = gpiochip_find(LATCH1_LABEL, gpiochip_match_by_label); + if (!chip) + pr_err("%s: latch1 GPIO chip not found\n", __func__); + else + ams_delta_led_init(chip); + err = gpio_request_array(latch_gpios, ARRAY_SIZE(latch_gpios)); if (err) pr_err("Couldn't take over latch1/latch2 GPIO pins\n"); return err; } +device_initcall_sync(ams_delta_gpio_init); static void __init ams_delta_late_devices(void) { @@ -712,10 +796,6 @@ static int __init late_init(void) { int err; - err = ams_delta_gpio_init(); - if (err) - return err; - ams_delta_late_devices(); err = modem_nreset_init();