From patchwork Wed Jan 24 00:27:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10181185 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 61BAF601D5 for ; Wed, 24 Jan 2018 00:28:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 52460285EF for ; Wed, 24 Jan 2018 00:28:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 46C8E28672; Wed, 24 Jan 2018 00:28:25 +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=-4.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.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 585E5285EF for ; Wed, 24 Jan 2018 00:28:24 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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:In-Reply-To:References: List-Owner; bh=n1IRsN8iW8/VyzXpjzi3C9bL7T0W6jUlsn8EldL2V8g=; b=hUfG4yR1vRkxJF bzHYE+ydh//SIQXKYzBIK9m2QVau/YUf2JrMjc989S3e6ancVRFoXDG8oSQr6RsQbsJuGO/mnvxuh L7FdH4F5C91JmDfLxZWpxP2EhPqB5VkdZuLcChp/2X1Zpf0sem7er0vVwlJfTTYPN2xIpApl1geHd mVYL0Mf+EasAMbJ5+5IapxADoHjOD2g91cCUDyE+rnbLM1niPvSkxPwfA7YVtk863/klUdRkhlKXz P4AW5taZA1pi5jenrb7i69/hLZZV5WdHmdYoYE8GAtxRWz+Jgd9zVMj8Qm2xqGMBHmHSKsFotBNTF 3W66BdZGFzadkf1OxeQg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1ee8v9-0003df-0K; Wed, 24 Jan 2018 00:28:07 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1ee8v0-0003cX-Dg for linux-amlogic@lists.infradead.org; Wed, 24 Jan 2018 00:28:04 +0000 Received: by mail-wm0-x243.google.com with SMTP id f71so5191661wmf.0 for ; Tue, 23 Jan 2018 16:27:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=WOjl3RifymzFX0chL9ImmdoAqNYXRNh4A+dO38H6LJw=; b=e7Nv3/6PAgxDYz39cfKPtEVrHXdMbeVSl8oSShxlH2/a9YV9x6Bzw6hFoJsqWJnzi9 co74nOYJKs/1mENyQ+VKBAcquF1p/4A1bN/8664Bw+G3oASDxczE/bVjq7ksMYtYJ61S uqePrbzU1OZ2sRO8Wn3dm0zkNcroia585rf18S5u7RUyXxXkkmIhZ53WeVRwfQ/xCyO5 YLfzk8Qj1PwKrD9r6l09McdDismVQCy4eFsDUrqK/PaaXHYgZM0oMuLRJnotj5z8eclr 6ddjaZbIOocJ7uiWFN22cjAvIqjhUPVXhp//wii1qACY5exg/Fp2uOGovPxhK1G5lnoX w1cw== 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:mime-version :content-transfer-encoding; bh=WOjl3RifymzFX0chL9ImmdoAqNYXRNh4A+dO38H6LJw=; b=ma1V5rwOZyETnIZv1lBBQr0O+Y0BN0I+36x1yR61pwd8lzoVBj+Y6tgrCVTKq9+97H b7sYmSpHxdTTcnkA2h+6LaivglZYUY3bPGEYWAjcYpQb/juY0q2lspHbZ2mcH6DvlB/A jVGGmD7lwqqksqltYz9nY4zm+0ZZ5hdEsKkFiU1A1stxhOihyIcPMJ4YGtKG1PJ9Gb2k ERqvQN62a3L+qUQKjSOccu6WxPHT9I9FQA4jNFvt3PkXilO4/+DTdXISADVd8nlZ2epC 3ry/89f/5EppA83lgnwfW6bVEF3LvK1Z0GCZM+IhxNJHOD2coHDL1SIiPz/4DWM90+0T 7oUw== X-Gm-Message-State: AKwxyte+nqnJFcuvqJ/A0LrQGjUnRl2g4brttV1//dfywEUbVz8jbYZM RI4ZbJBTBABgCxZt8ppxYEs= X-Google-Smtp-Source: AH8x224FTBxNVyhH/TNJqYJgcoEewfDzzjrAjkLMVHze59Gek6plKVrqI56KRzkiJgTxlvKK+tHV0A== X-Received: by 10.28.167.5 with SMTP id q5mr3559004wme.90.1516753666347; Tue, 23 Jan 2018 16:27:46 -0800 (PST) Received: from blackbox.darklights.net (p5DD9BE0D.dip0.t-ipconnect.de. [93.217.190.13]) by smtp.googlemail.com with ESMTPSA id g64sm41351wmf.20.2018.01.23.16.27.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Jan 2018 16:27:45 -0800 (PST) From: Martin Blumenstingl To: khilman@baylibre.com, linux-gpio@vger.kernel.org, linux-amlogic@lists.infradead.org, carlo@caione.org, jbrunet@baylibre.com Subject: [RFC PATCH v1] pinctrl: meson: meson8b: fix requesting GPIOs greater than GPIOZ_3 Date: Wed, 24 Jan 2018 01:27:38 +0100 Message-Id: <20180124002738.32338-1-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.16.1 MIME-Version: 1.0 X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Blumenstingl , linus.walleij@linaro.org, linus.luessing@c0d3.blue Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Meson8b is a cost reduced variant of the Meson8 SoC. It's package size is smaller than Meson8. Unfortunately there are a few key differences which cannot be seen without close inspection of the code and the public S805 data-sheet: - the GPIOX bank is missing the GPIOX_12, GPIOX_13, GPIOX_14 and GPIOX_15 GPIOs - the GPIOY bank is missing the GPIOY_2, GPIOY_4, GPIOY_5, GPIOY_15 and GPIOY_16 GPIOs - the GPIODV bank is missing all GPIOs except GPIODV_9, GPIODV_24, GPIODV_25, GPIODV_26, GPIODV_27, GPIODV_28 and GPIODV_29 - the GPIOZ bank is missing completely - there is a new GPIO bank called "DIF" - (all other pads exist on both, Meson8 and Meson8b) The pinctrl-meson driver internally uses struct meson_bank, which assumes that the GPIOs are continuous, without any holes in between. This also matches with how the registers work: - GPIOX_0 for example uses bit 0 for switching this pad between input/output, configuring pull-up/down, etc. - GPIOX_16 uses bit 16 for switching this pad between input/output, configuring pull-up/down/, etc GPIOX_16 uses bit 16 even though GPIOX12..15 don't exist. (This is probably the reason why Meson8b inherits the dt-bindings - with all GPIO IDs - from Meson8) This means that Meson8b only has 83 actual GPIO lines. Without any holes there would be 130 GPIO lines in total (120 are inherited from Meson8 plus 10 new from the DIF bank). The pinctrl framework handles holes in the pin list fine, which can be seen in debugfs: $ cat /sys/kernel/debug/pinctrl/c1109880.pinctrl/pins pin 9 (GPIOX_9) c1109880.pinctrl pin 10 (GPIOX_10) c1109880.pinctrl pin 11 (GPIOX_11) c1109880.pinctrl pin 16 (GPIOX_16) c1109880.pinctrl pin 17 (GPIOX_17) c1109880.pinctrl GPIOs which don't exist cannot be requested either ("base" of the GPIO controller is 382): $ echo 394 > /sys/class/gpio/export meson8b-pinctrl c1109880.pinctrl: pin 12 is not registered so it cannot be requested meson8b-pinctrl c1109880.pinctrl: pin-12 (cbus-banks:394) status -22 Unfortunately GPIOs greater GPIOZ_3 (whose ID is 83 - as a reminder: this is exactly the number of actual GPIO lines on Meson8b) cannot be requested. Using CARD_6 (ID 100, "base of the GPIO controller is 382) as an example: $ echo 482 > /sys/class/gpio/export export_store: invalid GPIO 482 The problem here is that struct gpio_chip's "ngpio" is set to 83. Thus requesting a GPIO higher than 83 fails. Commit 984cffdeaeb7ea ("pinctrl: Fix gpio/pin mapping for Meson8b") fixed this problem a while ago, by setting "ngpio" to 130. Unfortunately this broke again while cleaning up the pinctrl-meson driver in commit db80f0e158e621 ("pinctrl: meson: get rid of unneeded domain structures"), which started using ARRAY_SIZE(meson8b_cbus_pins) - which evaluates to 83 - as "ngpio". This is now fixed by introducing a new "override_ngpio" field in struct meson_pinctrl_data. This value is passed to struct gpio_chip's "ngpio" when set - if override_ngpio is <= 0 then num_pins is used (which works for all other Meson SoCs, except Meson8b). The definitions in "include/dt-bindings/gpio/meson8b-gpio.h" were not changed. Cleaning up these definitions would allow us to get rid of the GPIOZ definitions (which are inherited from Meson8). However, we still need to handle GPIO banks with holes (such as GPIOX), so this include is not touched for now (touching it could also break the device-tree ABI). Meson8b's AO GPIO controller is not affected by this issue since it does not have any holes in it - only the CBUS GPIO controller is affected. This was initially seen by Linus Lüssing who was preparing SD card support on Odroid-C1 which uses CARD_6 as "card detect" GPIO. Fixes: db80f0e158e621 ("pinctrl: meson: get rid of unneeded domain structures") Reported-by: Linus Lüssing Signed-off-by: Martin Blumenstingl --- drivers/pinctrl/meson/pinctrl-meson.c | 7 ++++++- drivers/pinctrl/meson/pinctrl-meson.h | 1 + drivers/pinctrl/meson/pinctrl-meson8b.c | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/pinctrl/meson/pinctrl-meson.c b/drivers/pinctrl/meson/pinctrl-meson.c index 29a458da78db..1befe67fd187 100644 --- a/drivers/pinctrl/meson/pinctrl-meson.c +++ b/drivers/pinctrl/meson/pinctrl-meson.c @@ -413,7 +413,12 @@ static int meson_gpiolib_register(struct meson_pinctrl *pc) pc->chip.get = meson_gpio_get; pc->chip.set = meson_gpio_set; pc->chip.base = -1; - pc->chip.ngpio = pc->data->num_pins; + + if (pc->data->override_ngpio > 0) + pc->chip.ngpio = pc->data->override_ngpio; + else + pc->chip.ngpio = pc->data->num_pins; + pc->chip.can_sleep = false; pc->chip.of_node = pc->of_node; pc->chip.of_gpio_n_cells = 2; diff --git a/drivers/pinctrl/meson/pinctrl-meson.h b/drivers/pinctrl/meson/pinctrl-meson.h index 183b6e471635..afd7efaad9bb 100644 --- a/drivers/pinctrl/meson/pinctrl-meson.h +++ b/drivers/pinctrl/meson/pinctrl-meson.h @@ -108,6 +108,7 @@ struct meson_pinctrl_data { struct meson_bank *banks; unsigned int num_banks; const struct pinmux_ops *pmx_ops; + unsigned int override_ngpio; }; struct meson_pinctrl { diff --git a/drivers/pinctrl/meson/pinctrl-meson8b.c b/drivers/pinctrl/meson/pinctrl-meson8b.c index 5bd808dc81e1..05bb4c3143d9 100644 --- a/drivers/pinctrl/meson/pinctrl-meson8b.c +++ b/drivers/pinctrl/meson/pinctrl-meson8b.c @@ -916,6 +916,20 @@ static struct meson_pinctrl_data meson8b_cbus_pinctrl_data = { .num_funcs = ARRAY_SIZE(meson8b_cbus_functions), .num_banks = ARRAY_SIZE(meson8b_cbus_banks), .pmx_ops = &meson8_pmx_ops, + /* + * there are holes in the meson8b_cbus_pins mapping because we are + * mapping the GPIO identifiers to register bits. on Meson8b some bits + * (and thus the corresponding pads) are not used on the SoC + * (presumably because they were skipped because Meson8b is a cost + * reduced variant of Meson8 and it didn't make sense to create a whole + * new register layout for this variant). + * this informs the GPIO framework know about the number of GPIOs we + * have, including the pins which are not available on Meson8b (= the + * holes). The pinctrl/GPIO framework knows the holes because it checks + * all pinctrl_pin_desc in meson8b_cbus_pins and reports an error as + * soon as a GPIO is requested which is not part of meson8b_cbus_pins. + */ + .override_ngpio = 130, }; static struct meson_pinctrl_data meson8b_aobus_pinctrl_data = {