From patchwork Thu Jan 25 15:08:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jan_Kundr=C3=A1t?= X-Patchwork-Id: 866573 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=cesnet.cz header.i=@cesnet.cz header.b="JRQsIPwH"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zSqpr4nkqz9sNr for ; Sat, 27 Jan 2018 07:13:24 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752076AbeAZUNY (ORCPT ); Fri, 26 Jan 2018 15:13:24 -0500 Received: from office2.cesnet.cz ([195.113.144.244]:32838 "EHLO office2.cesnet.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751814AbeAZUNX (ORCPT ); Fri, 26 Jan 2018 15:13:23 -0500 Received: from localhost (unknown [IPv6:2001:718:1:2c:4c87:d4a8:de7f:541e]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by office2.cesnet.cz (Postfix) with ESMTPSA id D45B0400064; Fri, 26 Jan 2018 21:13:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cesnet.cz; s=office2; t=1516997601; bh=r/OzWSn6gaPvwfroV+mVMswfsIxqRxOu2baXictfC6s=; h=Resent-Date:Resent-From:Resent-To:Resent-Cc:In-Reply-To: References:From:Date:Subject:To:Cc; b=JRQsIPwHVS6/HrfNBv8Ma3o5E8pC2wticbQUMRtyQjXolDEx/opCM4kGU7FjmIIt3 H2bF54qc1qVdiccJ+huvbQf+EnjXeG/O+SP1jK10XOxDm0bm8k4sFQZqXeGK7j7UR1 s60pTLxxWhZ3WNg+hbuRAmXGm+IaxYQZbXN8FOk0= Message-Id: <9e78a4a697c8d4d3028ea8780bd925471b49af3c.1516997103.git.jan.kundrat@cesnet.cz> In-Reply-To: References: From: =?utf-8?q?Jan_Kundr=C3=A1t?= Date: Thu, 25 Jan 2018 16:08:35 +0100 Subject: [PATCH 1/4] pinctrl: mcp23s08: IRQ behavior for open-drain interrupts MIME-Version: 1.0 To: linux-gpio@vger.kernel.org Cc: linux-spi@vger.kernel.org, Linus Walleij , Phil Reid , Sebastian Reichel Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org The hardware supports three different IRQ modes: - open drain, i.e., an active-low output which requires an external pull-up and supports IRQ line sharing, - active low, with push-pull output, - active high, with push-pull output. My understanding of electronics is limited, but it is "wrong" to connect different push-pull outpus together. It could sort-of work if the chips/board actually have some resistors there, but it's an ugly thing to do. In the past, this driver did not touch the ODR bit (for open-drain) operation. During power-on-reset, it is set to zero. Unless some platform code actually set this bit to one, this means that the code never supported open drain operation. This change makes this handling explicit. If you want sharing of the IRQ line, then use the microchip,irq-open-drain mode and add an external pull-up. There's some risk here. If, e.g., the bootloader sets the ODR bit for some reason, the HW shares the IRQ lines, and nobody changes the DT, then your HW will suddenly use push-pull driver for the IRQ line. If there is any other chip on the same lane, the HW might suffer (my chip survived this when I "tested" this by accident with no bootloader code to set the ODR bit). Signed-off-by: Jan Kundrát --- .../bindings/pinctrl/pinctrl-mcp23s08.txt | 4 ++ drivers/pinctrl/pinctrl-mcp23s08.c | 82 +++++++++++++++------- 2 files changed, 61 insertions(+), 25 deletions(-) diff --git a/Documentation/devicetree/bindings/pinctrl/pinctrl-mcp23s08.txt b/Documentation/devicetree/bindings/pinctrl/pinctrl-mcp23s08.txt index 9c451c20dda4..92aa91027c68 100644 --- a/Documentation/devicetree/bindings/pinctrl/pinctrl-mcp23s08.txt +++ b/Documentation/devicetree/bindings/pinctrl/pinctrl-mcp23s08.txt @@ -58,6 +58,10 @@ Optional device specific properties: On devices with only one interrupt output this property is useless. - microchip,irq-active-high: Sets the INTPOL flag in the IOCON register. This configures the IRQ output polarity as active high. +- microchip,irq-open-drain: Sets the ODR flag in the IOCON register. This + configures the IRQ output as active low open-drain and allows sharing + of the IRQ line among several chips. Note that irq-active-high and + irq-open-drain are mutually exclusive. Example I2C (with interrupt): gpiom1: gpio@20 { diff --git a/drivers/pinctrl/pinctrl-mcp23s08.c b/drivers/pinctrl/pinctrl-mcp23s08.c index c017860619d6..186101c575e3 100644 --- a/drivers/pinctrl/pinctrl-mcp23s08.c +++ b/drivers/pinctrl/pinctrl-mcp23s08.c @@ -54,9 +54,15 @@ struct mcp23s08; +enum mcp23s08_irq_regime { + MCP_IRQ_PULL_LOW, + MCP_IRQ_PUSH_UP, + MCP_IRQ_OPEN_DRAIN +}; + struct mcp23s08 { u8 addr; - bool irq_active_high; + enum mcp23s08_irq_regime irq_regime; bool reg_shift; u16 irq_rise; @@ -625,10 +631,17 @@ static int mcp23s08_irq_setup(struct mcp23s08 *mcp) int err; unsigned long irqflags = IRQF_ONESHOT | IRQF_SHARED; - if (mcp->irq_active_high) - irqflags |= IRQF_TRIGGER_HIGH; - else + switch (mcp->irq_regime) { + case MCP_IRQ_PULL_LOW: irqflags |= IRQF_TRIGGER_LOW; + break; + case MCP_IRQ_PUSH_UP: + irqflags |= IRQF_TRIGGER_HIGH; + break; + case MCP_IRQ_OPEN_DRAIN: + irqflags |= IRQF_TRIGGER_LOW | IRQF_SHARED; + break; + } err = devm_request_threaded_irq(chip->parent, mcp->irq, NULL, mcp23s08_irq, @@ -780,7 +793,7 @@ static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev, mcp->dev = dev; mcp->addr = addr; - mcp->irq_active_high = false; + mcp->irq_regime = MCP_IRQ_PULL_LOW; mcp->chip.direction_input = mcp23s08_direction_input; mcp->chip.get = mcp23s08_get; @@ -866,33 +879,52 @@ static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev, mcp->irq_controller = device_property_read_bool(dev, "interrupt-controller"); if (mcp->irq && mcp->irq_controller) { - mcp->irq_active_high = - device_property_read_bool(dev, - "microchip,irq-active-high"); + bool irq_active_high = device_property_read_bool(dev, + "microchip,irq-active-high"); + bool irq_open_drain = device_property_read_bool(dev, + "microchip,irq-open-drain"); + if (irq_active_high && irq_open_drain) { + dev_err(dev, "microchip,irq-open-drain and " + "microchip,irq-active-high are mutually exclusive\n"); + ret = -EINVAL; + goto fail; + } else if (irq_active_high) { + mcp->irq_regime = MCP_IRQ_PUSH_UP; + } else if (irq_open_drain) { + mcp->irq_regime = MCP_IRQ_OPEN_DRAIN; + } mirror = device_property_read_bool(dev, "microchip,irq-mirror"); } - if ((status & IOCON_SEQOP) || !(status & IOCON_HAEN) || mirror || - mcp->irq_active_high) { - /* mcp23s17 has IOCON twice, make sure they are in sync */ - status &= ~(IOCON_SEQOP | (IOCON_SEQOP << 8)); - status |= IOCON_HAEN | (IOCON_HAEN << 8); - if (mcp->irq_active_high) - status |= IOCON_INTPOL | (IOCON_INTPOL << 8); - else - status &= ~(IOCON_INTPOL | (IOCON_INTPOL << 8)); + /* mcp23s17 has IOCON twice, make sure they are in sync */ + status &= ~(IOCON_SEQOP | (IOCON_SEQOP << 8)); + status |= IOCON_HAEN | (IOCON_HAEN << 8); - if (mirror) - status |= IOCON_MIRROR | (IOCON_MIRROR << 8); + switch (mcp->irq_regime) { + case MCP_IRQ_PUSH_UP: + status |= IOCON_INTPOL | (IOCON_INTPOL << 8); + status &= ~(IOCON_ODR | (IOCON_ODR << 8)); + break; + case MCP_IRQ_PULL_LOW: + status &= ~(IOCON_INTPOL | (IOCON_INTPOL << 8)); + status &= ~(IOCON_ODR | (IOCON_ODR << 8)); + break; + case MCP_IRQ_OPEN_DRAIN: + /* ODR overrides INTPOL */ + status |= IOCON_ODR | (IOCON_ODR << 8); + break; + } - if (type == MCP_TYPE_S18 || type == MCP_TYPE_018) - status |= IOCON_INTCC | (IOCON_INTCC << 8); + if (mirror) + status |= IOCON_MIRROR | (IOCON_MIRROR << 8); - ret = mcp_write(mcp, MCP_IOCON, status); - if (ret < 0) - goto fail; - } + if (type == MCP_TYPE_S18 || type == MCP_TYPE_018) + status |= IOCON_INTCC | (IOCON_INTCC << 8); + + ret = mcp_write(mcp, MCP_IOCON, status); + if (ret < 0) + goto fail; ret = devm_gpiochip_add_data(dev, &mcp->chip, mcp); if (ret < 0) From patchwork Thu Jan 25 17:29:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jan_Kundr=C3=A1t?= X-Patchwork-Id: 866574 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=cesnet.cz header.i=@cesnet.cz header.b="njt7/KrF"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zSqpv3x3jz9sNr for ; Sat, 27 Jan 2018 07:13:27 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752175AbeAZUN0 (ORCPT ); Fri, 26 Jan 2018 15:13:26 -0500 Received: from office2.cesnet.cz ([195.113.144.244]:32858 "EHLO office2.cesnet.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752118AbeAZUN0 (ORCPT ); Fri, 26 Jan 2018 15:13:26 -0500 Received: from localhost (unknown [IPv6:2001:718:1:2c:4c87:d4a8:de7f:541e]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by office2.cesnet.cz (Postfix) with ESMTPSA id E2587400065; Fri, 26 Jan 2018 21:13:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cesnet.cz; s=office2; t=1516997604; bh=++6oe+uthz2hOaUzAkuSvUcD1wbkvbEBgJCyWolxRwM=; h=Resent-Date:Resent-From:Resent-To:Resent-Cc:In-Reply-To: References:From:Date:Subject:To:Cc; b=njt7/KrFR7C/pxSARfwz1Db0g+G4gxOiPcX8HhhP6Ib/tsySHLYCtKgXfMs/tc5oj fYtbuLjrh5h9VxOi02yQBwNKhLhEvE8vVKkAmdS9u7DofAK593RQ7Zc8tsto3hkEYc /IerVRHeqcI4mMyyvRQe+lMU9ihk4HPLtm4m0ZtA= Message-Id: In-Reply-To: References: From: =?utf-8?q?Jan_Kundr=C3=A1t?= Date: Thu, 25 Jan 2018 18:29:15 +0100 Subject: [PATCH 2/4] pinctrl: mcp23s08: spi: Fix regmap debugfs entries MIME-Version: 1.0 To: linux-gpio@vger.kernel.org Cc: linux-spi@vger.kernel.org, Linus Walleij , Phil Reid , Sebastian Reichel Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org The SPI version of this chip allows several devices to be present on the same SPI bus via a local address. If this is in action and if the kernel has debugfs, however, the code attempts to create duplicate entries for the regmap's debugfs: mcp23s08 spi1.1: Failed to create debugfs directory This patch simply assigns a local name matching the device logical address to the `struct regmap_config`. No changes are needed for MCP23S18 because that device does not support any logical addressing. Similarly, I2C devices do not need any action, either, because they are already different in their I2C address. A similar problem is present for the pinctrl debugfs instance, but that one is not addressed by this patch. Signed-off-by: Jan Kundrát --- drivers/pinctrl/pinctrl-mcp23s08.c | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/drivers/pinctrl/pinctrl-mcp23s08.c b/drivers/pinctrl/pinctrl-mcp23s08.c index 186101c575e3..8dc758bacdd1 100644 --- a/drivers/pinctrl/pinctrl-mcp23s08.c +++ b/drivers/pinctrl/pinctrl-mcp23s08.c @@ -788,6 +788,7 @@ static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev, { int status, ret; bool mirror = false; + struct regmap_config *one_regmap_config = NULL; mutex_init(&mcp->lock); @@ -808,22 +809,36 @@ static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev, switch (type) { #ifdef CONFIG_SPI_MASTER case MCP_TYPE_S08: - mcp->regmap = devm_regmap_init(dev, &mcp23sxx_spi_regmap, mcp, - &mcp23x08_regmap); - mcp->reg_shift = 0; - mcp->chip.ngpio = 8; - mcp->chip.label = "mcp23s08"; - break; - case MCP_TYPE_S17: + switch (type) { + case MCP_TYPE_S08: + one_regmap_config = + devm_kmemdup(dev, &mcp23x08_regmap, + sizeof(struct regmap_config), GFP_KERNEL); + mcp->reg_shift = 0; + mcp->chip.ngpio = 8; + mcp->chip.label = "mcp23s08"; + break; + case MCP_TYPE_S17: + one_regmap_config = + devm_kmemdup(dev, &mcp23x17_regmap, + sizeof(struct regmap_config), GFP_KERNEL); + mcp->reg_shift = 1; + mcp->chip.ngpio = 16; + mcp->chip.label = "mcp23s17"; + break; + } + if (!one_regmap_config) + return -ENOMEM; + + one_regmap_config->name = devm_kasprintf(dev, GFP_KERNEL, "%d", (addr & ~0x40) >> 1); mcp->regmap = devm_regmap_init(dev, &mcp23sxx_spi_regmap, mcp, - &mcp23x17_regmap); - mcp->reg_shift = 1; - mcp->chip.ngpio = 16; - mcp->chip.label = "mcp23s17"; + one_regmap_config); break; case MCP_TYPE_S18: + if (!one_regmap_config) + return -ENOMEM; mcp->regmap = devm_regmap_init(dev, &mcp23sxx_spi_regmap, mcp, &mcp23x17_regmap); mcp->reg_shift = 1; From patchwork Fri Jan 26 19:16:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jan_Kundr=C3=A1t?= X-Patchwork-Id: 866575 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=cesnet.cz header.i=@cesnet.cz header.b="ZjvZrAnQ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zSqpx5X6Tz9sNr for ; Sat, 27 Jan 2018 07:13:29 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752188AbeAZUN3 (ORCPT ); Fri, 26 Jan 2018 15:13:29 -0500 Received: from office2.cesnet.cz ([195.113.144.244]:32868 "EHLO office2.cesnet.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752118AbeAZUN2 (ORCPT ); Fri, 26 Jan 2018 15:13:28 -0500 Received: from localhost (unknown [IPv6:2001:718:1:2c:4c87:d4a8:de7f:541e]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by office2.cesnet.cz (Postfix) with ESMTPSA id 19FC8400066; Fri, 26 Jan 2018 21:13:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cesnet.cz; s=office2; t=1516997607; bh=974mQwIS7nEa9hzVAU+UJPMWyqJTqG5U6EIsBEmcMlg=; h=Resent-Date:Resent-From:Resent-To:Resent-Cc:In-Reply-To: References:From:Date:Subject:To:Cc; b=ZjvZrAnQouc311RGBM4pFPpQIlTxaR5qNj9CzF2zOPSuL555iGrH3tgcmgu5W5nVS sGOkR+N0k8H5Ne2dirAopWDcRYbHkdJgYfUmMZjFe8RD5qbiT13LIMSjOHGqidSK03 irCajW0uChD6/Ym03dSh1KDqLeGfAbhxuZ0w2EFY= Message-Id: <03c5ea4d98804e4ea6b0927e5bf103106e438142.1516997103.git.jan.kundrat@cesnet.cz> In-Reply-To: References: From: =?utf-8?q?Jan_Kundr=C3=A1t?= Date: Fri, 26 Jan 2018 20:16:47 +0100 Subject: [PATCH 3/4] pinctrl: mcp23s08: spi: Add HW address to gpio_chip.label MIME-Version: 1.0 To: linux-gpio@vger.kernel.org Cc: linux-spi@vger.kernel.org, Linus Walleij , Phil Reid , Sebastian Reichel Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org When several devices are sharing one hardware SPI CS, there is no visual clue in `lsgpio` or in /sys/kernel/debug/gpio about which one is which one. Stuff depends on the enumeration order, and therefore lower chip addresses always go first, but that's just an implementation detail. This change includes the device-specific address in the debug output: gpiochip4: GPIOs 464-479, parent: spi/spi1.1, mcp23s17.2, can sleep: gpiochip3: GPIOs 480-495, parent: spi/spi1.1, mcp23s17.1, can sleep: Signed-off-by: Jan Kundrát --- drivers/pinctrl/pinctrl-mcp23s08.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/pinctrl/pinctrl-mcp23s08.c b/drivers/pinctrl/pinctrl-mcp23s08.c index 8dc758bacdd1..c76c9d4b26c9 100644 --- a/drivers/pinctrl/pinctrl-mcp23s08.c +++ b/drivers/pinctrl/pinctrl-mcp23s08.c @@ -789,6 +789,7 @@ static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev, int status, ret; bool mirror = false; struct regmap_config *one_regmap_config = NULL; + int raw_chip_address = (addr & ~0x40) >> 1; mutex_init(&mcp->lock); @@ -817,7 +818,8 @@ static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev, sizeof(struct regmap_config), GFP_KERNEL); mcp->reg_shift = 0; mcp->chip.ngpio = 8; - mcp->chip.label = "mcp23s08"; + mcp->chip.label = devm_kasprintf(dev, GFP_KERNEL, + "mcp23s08.%d", raw_chip_address); break; case MCP_TYPE_S17: one_regmap_config = @@ -825,13 +827,14 @@ static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev, sizeof(struct regmap_config), GFP_KERNEL); mcp->reg_shift = 1; mcp->chip.ngpio = 16; - mcp->chip.label = "mcp23s17"; + mcp->chip.label = devm_kasprintf(dev, GFP_KERNEL, + "mcp23s17.%d", raw_chip_address); break; } if (!one_regmap_config) return -ENOMEM; - one_regmap_config->name = devm_kasprintf(dev, GFP_KERNEL, "%d", (addr & ~0x40) >> 1); + one_regmap_config->name = devm_kasprintf(dev, GFP_KERNEL, "%d", raw_chip_address); mcp->regmap = devm_regmap_init(dev, &mcp23sxx_spi_regmap, mcp, one_regmap_config); break; From patchwork Fri Jan 26 15:06:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jan_Kundr=C3=A1t?= X-Patchwork-Id: 866576 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=cesnet.cz header.i=@cesnet.cz header.b="lftx9mN4"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zSqq02zChz9sNr for ; Sat, 27 Jan 2018 07:13:32 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752232AbeAZUNb (ORCPT ); Fri, 26 Jan 2018 15:13:31 -0500 Received: from office2.cesnet.cz ([195.113.144.244]:32880 "EHLO office2.cesnet.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752118AbeAZUNa (ORCPT ); Fri, 26 Jan 2018 15:13:30 -0500 Received: from localhost (unknown [IPv6:2001:718:1:2c:4c87:d4a8:de7f:541e]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by office2.cesnet.cz (Postfix) with ESMTPSA id 6B51A400068; Fri, 26 Jan 2018 21:13:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cesnet.cz; s=office2; t=1516997609; bh=JIYe0dVz+dmjFooyyhppJAxsyAJeJw5057eMRsz5UAI=; h=Resent-Date:Resent-From:Resent-To:Resent-Cc:In-Reply-To: References:From:Date:Subject:To:Cc; b=lftx9mN4+qmAOWyYkgEgTNFnjDBw5dieDYLOqv2/PH8aI8CUNj/rcs/Sglk0dxHhi sCE489qXpMtyvtD72tWCu5j8p7xQAJ539hIMJnWP2YnQULhMsrriw3hefa35MNg7Py OXhMo+m1oycSwOBWXy6VXuePoI1GswXSaiLl+Ofo= Message-Id: In-Reply-To: References: From: =?utf-8?q?Jan_Kundr=C3=A1t?= Date: Fri, 26 Jan 2018 16:06:37 +0100 Subject: [PATCH 4/4] pinctrl: mcp23s08: spi: Fix duplicate pinctrl debugfs entries MIME-Version: 1.0 To: linux-gpio@vger.kernel.org Cc: linux-spi@vger.kernel.org, Linus Walleij , Phil Reid , Sebastian Reichel Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org This is a bit more involved because the pinctrl core so far always assumed that one device (with a unique dev_name) only contains a single pinctrl thing. This is not true for the mcp23s08 driver for chips connected over SPI. They have a "logical address" which means that several chips can share one physical CS signal. A downside of this patch are some possibly ugly names for the debugfs entries, such as "spi1.1-mcp23xxx-pinctrl.2", etc. Signed-off-by: Jan Kundrát --- drivers/pinctrl/core.c | 18 ++++++++++++++++-- drivers/pinctrl/pinctrl-mcp23s08.c | 9 ++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c index 4c8d5b23e4d0..dc7a77f2f9fe 100644 --- a/drivers/pinctrl/core.c +++ b/drivers/pinctrl/core.c @@ -1856,9 +1856,23 @@ static struct dentry *debugfs_root; static void pinctrl_init_device_debugfs(struct pinctrl_dev *pctldev) { struct dentry *device_root; + const char *debugfs_name; + + if (pctldev->desc->name && + strcmp(dev_name(pctldev->dev), pctldev->desc->name)) { + debugfs_name = devm_kasprintf(pctldev->dev, GFP_KERNEL, + "%s-%s", dev_name(pctldev->dev), + pctldev->desc->name); + if (!debugfs_name) { + pr_warn("failed to determine debugfs dir name for %s\n", + dev_name(pctldev->dev)); + return; + } + } else { + debugfs_name = dev_name(pctldev->dev); + } - device_root = debugfs_create_dir(dev_name(pctldev->dev), - debugfs_root); + device_root = debugfs_create_dir(debugfs_name, debugfs_root); pctldev->device_root = device_root; if (IS_ERR(device_root) || !device_root) { diff --git a/drivers/pinctrl/pinctrl-mcp23s08.c b/drivers/pinctrl/pinctrl-mcp23s08.c index c76c9d4b26c9..1f3971d02084 100644 --- a/drivers/pinctrl/pinctrl-mcp23s08.c +++ b/drivers/pinctrl/pinctrl-mcp23s08.c @@ -954,7 +954,14 @@ static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev, goto fail; } - mcp->pinctrl_desc.name = "mcp23xxx-pinctrl"; + if (one_regmap_config) { + mcp->pinctrl_desc.name = devm_kasprintf(dev, GFP_KERNEL, + "mcp23xxx-pinctrl.%d", raw_chip_address); + if (!mcp->pinctrl_desc.name) + return -ENOMEM; + } else { + mcp->pinctrl_desc.name = "mcp23xxx-pinctrl"; + } mcp->pinctrl_desc.pctlops = &mcp_pinctrl_ops; mcp->pinctrl_desc.confops = &mcp_pinconf_ops; mcp->pinctrl_desc.npins = mcp->chip.ngpio;