From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796217404; b=FXmUxnW/4rGK1AQ+UzZHsIIqtKoaCHSHaOnjD6JxYK7472mBHq0gxhIIjZmnobVb6Qwb xZeQgc4z0f7hHYT5xxBLzI86WDtOzQEoGuPdiQstbp1HE25bXvcldDErYTTYkV2e3jkCV qA4cTUzraPJ/rm2YYFRj5stTjEPuJPTFzu76kPXU1AvN7ELauwmCzCKOrlwqM9jKA/LWY vhLf2VI9rjjNx1SfsXHgO9KoxTDf5pkXLXmV8k9ohqpk9pZ+NyuXWy1rsJkzeI4aNQiyf wL9Eyl3qhTyPCp7p/TYspgq0g0TWK7UjcVa6Wxf8LyX1sIeFa7xsQPO0Yl9N9xN8tOw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796217404; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=CbZNa3TYS/dm3wW98LAO6zk7V2ygAnJkHz2EtldKhtA=; b=Zqk7GA3NlM5o70ce2yRT6FLXXCBFLG1hQSnZSPhB6QVQkqcgg1LaEHT5bLryCscjivL0 aICA8F/ts2kWlH5DwbOaxz8Yv4svNGK/YUZaSI2eLA4+nWrUvEvuMHoRxyhRE+Uez2q/F iqQpaXtY+DHf6fWoRx/M297rxJCW+PuYsu3AlBB0u/o1K6U38OZl1KyP2xrOFcgaserRB j9yLnGDGFjmJ0xQH94+BH0940IOL8CbbB7q9Y3qkSlushFGAVhQYd5JChvueH3zDCkPRF Tp60ILGHsaPE2CRQTNFb99cC3/uJFisgetvmHmahOb8x3y3Tq5SYrVlMOjDaOWbVtpw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gsuZTXWB; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E84C5606A31A; Wed, 2 Dec 2026 13:16:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gsuZTXWB Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796217403; b=GBFVB/E5wm2TAUnWuzEvu8bkrb3NWV3wXpqQ/sOkfowTzTaC+RABwBMhKMi7/Nsne/HS 6PlMlX/Ihh5+LXRZjaXbUCYic7YPPWS4E4p7Liv54kUoquMe2dMbar1jaqTvLY6AGUmKu z6T1swzLmiNshUdbahRYeMWPg8Y0YLaVKo5SwQOpUYwtzzjTCJwchplj3XB6inIYgNlGi Ahc9E/zgN6JFAl6uOxnYzZbASlSjEZ1iQTagpXjA3R02qJDkzLNhMDh8+uV2SrdxanMgv A/2yYnpyMkjnLPZFImdiqu9EpgS1GCjdTs7u1Pg3j8nc1rAhDMG0F3GHwgPVemwA7Dw== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796217403; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=CbZNa3TYS/dm3wW98LAO6zk7V2ygAnJkHz2EtldKhtA=; b=Nktal2EI0mIn7APafFrGk3S37qriqfP6mUxMp1NEox20ybhyZXuiLso1wUL33b7N1Hr2 4Ad/BnwLORLt1UVrdg7QFW2T0JV1HRt3eSNmb08FMLHulIOiab6iROjU9lJg9AM4uqGtL JWa4KfGRV8DW9/GW+zMng0lM15mV9CTYF/Rk15o9ny0xOGxwvCtz4cXn89ZBBiq7uOGBu s0/6t0bdj+R3J6hERKpQfUSodidTxO1YpAg+/ue/TlrTpfEbWpJNYIa8U8RP2AZKBDsF4 /cL2LrBq1FCc6ylJNGbCSnbZYvdIHg2HFaY/WA0ur6sAyFAFHP25ningQtAZFIgTHUA== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id EDEEC1F00A15; Wed, 2 Dec 2026 13:16:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796217403; bh=CbZNa3TYS/dm3wW98LAO6zk7V2ygAnJkHz2EtldKhtA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=gsuZTXWBgyHANhqjk/oLCdydN90IL4Az41n+NdACUkaOivMwBrD7diWR0Q+PyFWfy LR+P37MnQ2UzWWZeC0wsDOH7hHHyJVXxH+ZOW6MUSWEgikz26E1sSDB03dw9BTJqH6 IzafTMgRymsD9A3hps43wBMAC7ikwBoZJCZkieqom0AvPUjEL7SpoxQVqfAwyhq5vE Y//woP3Pi8dQgtfHqPCoToy3Zf6XNe9t+W/y0BkJftCX6XFfNA/TjImXawob08uTyx ylauFF8y5o5acgGjk5Ue+EpwmV+GhVIr/xrG+0VNgN+pCogM53X6cJsRYSK5kjwo0N lqOEyPa0wk7gA== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 7C0AA4F40C; Wed, 2 Dec 2026 13:16:23 +0000 (UTC) From: Anatoliy Oleinikov via B4 Relay Date: Wed, 02 Dec 2026 16:15:47 +0300 Subject: [PATCH v2 2/2] i2c: i2c-gpio: Enhance driver for buses with shared SDA X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261202-i2c-gpio-shared-sda-v2-2-7b6afaa5ab2a@wizle.tech> References: <20261202-i2c-gpio-shared-sda-v2-0-7b6afaa5ab2a@wizle.tech> In-Reply-To: <20261202-i2c-gpio-shared-sda-v2-0-7b6afaa5ab2a@wizle.tech> To: Andi Shyti , linux-i2c@vger.kernel.org Cc: Wolfram Sang , Markus Stockhausen , Linus Walleij , Bartosz Golaszewski , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Anatoliy Oleinikov X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796217382; l=15443; i=admin@wizle.tech; s=20261202; h=from:subject:message-id; bh=tiLeHMYbfXo7LCdOKRXlzXxarzS8IIO0hjHNRO1iQo0=; b=neD/jdxuUetSK8z6RrHkETTVp8sci8ecN7pKpVpEpilUe8nJIP8CDJkx5A/AhvHvL3eAHvexU T+5YeiBYMhVBeZa40S1Tm6URfq8XjepqjjZLeB5GjLb54TiyoeDauG9 X-Developer-Key: i=admin@wizle.tech; a=ed25519; pk=hbyYTn3b70/Mc+SQK74Eisxf7NdLpEDQYKQqi8345mA= X-Endpoint-Received: by B4 Relay for admin@wizle.tech/20261202 with auth_id=1720 X-Original-From: Anatoliy Oleinikov Reply-To: admin@wizle.tech Content-Transfer-Encoding: 7bit From: Anatoliy Oleinikov Some Realtek based switches share the data line instead of the clock line among the I2C buses of their SFP cages. E.g. the Acorid GLS7700-24F8G-4X drives 24 SFP cages through three RTL8231 GPIO expanders. Each cage has its own SCL, while every four cages share one SDA. Generalize the shared SCL handling so that it covers both lines. - Turn the shared SCL structure and its helpers into line based ones. The connection id, the index into the legacy "gpios" property and the lockdep class are passed in. SDA is detected, requested and reference counted exactly like SCL: by the phandle and all additional cells of its devicetree reference. - A pin can be shared as SCL or as SDA, but not as both. Such a devicetree is rejected with -EINVAL. - The custom lock_ops take the adapter bus lock, the SCL mutex and then the SDA mutex, and release them in reverse order. This serializes all buses that share either line. The SCL and SDA mutexes have separate lockdep classes and are always taken in the same order, so the nesting cannot deadlock. - Skip the i2c-algo-bit bus test when SDA can be shared, as it already is for SCL. The test toggles the lines without the bus lock. Buses without a shared SDA behave as before. Their SDA mutex is private to the adapter and never contended. Tested on the Acorid GLS7700-24F8G-4X with an OpenWrt 6.18 kernel that carries the shared SCL backport and this change, with kzalloc() for kzalloc_obj(): the EEPROM of a module read the same 50 times in a row while the other three cages on its SDA were probed in parallel. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Anatoliy Oleinikov --- drivers/i2c/busses/i2c-gpio.c | 189 +++++++++++++++++++++++++----------------- 1 file changed, 112 insertions(+), 77 deletions(-) diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c index 552fcbb1eaed..315a46ee64c2 100644 --- a/drivers/i2c/busses/i2c-gpio.c +++ b/drivers/i2c/busses/i2c-gpio.c @@ -18,12 +18,18 @@ #include #include -static LIST_HEAD(i2c_gpio_scl_list); -static DEFINE_MUTEX(i2c_gpio_scl_list_lock); +static LIST_HEAD(i2c_gpio_line_list); +static DEFINE_MUTEX(i2c_gpio_line_list_lock); static struct lock_class_key i2c_gpio_scl_lock_key; +static struct lock_class_key i2c_gpio_sda_lock_key; -struct i2c_gpio_scl_data { +/* + * An SCL or SDA line, possibly shared by several buses. A transfer holds the lock of its SCL + * line and then that of its SDA line, so buses sharing either line are serialized. + */ +struct i2c_gpio_line_data { struct fwnode_reference_args args; + const char *con_id; struct gpio_desc *gpio; struct rt_mutex lock; struct list_head list; @@ -31,8 +37,8 @@ struct i2c_gpio_scl_data { }; struct i2c_gpio_private_data { - struct gpio_desc *sda; - struct i2c_gpio_scl_data *scl; + struct i2c_gpio_line_data *sda; + struct i2c_gpio_line_data *scl; struct i2c_adapter adap; struct i2c_algo_bit_data bit_data; struct i2c_gpio_platform_data pdata; @@ -57,7 +63,7 @@ static void i2c_gpio_setsda_val(void *data, int state) { struct i2c_gpio_private_data *priv = data; - gpiod_set_value_cansleep(priv->sda, state); + gpiod_set_value_cansleep(priv->sda->gpio, state); } /* @@ -77,7 +83,7 @@ static int i2c_gpio_getsda(void *data) { struct i2c_gpio_private_data *priv = data; - return gpiod_get_value_cansleep(priv->sda); + return gpiod_get_value_cansleep(priv->sda->gpio); } static int i2c_gpio_getscl(void *data) @@ -89,17 +95,28 @@ static int i2c_gpio_getscl(void *data) static void i2c_gpio_lock_bus(struct i2c_adapter *adap, unsigned int flags) { + struct i2c_gpio_private_data *priv = adap_to_priv(adap); + /* Take care about adapter lock. See i2c_adapter_lock_bus() and others. */ rt_mutex_lock_nested(&adap->bus_lock, i2c_adapter_depth(adap)); - rt_mutex_lock(&adap_to_priv(adap)->scl->lock); + rt_mutex_lock(&priv->scl->lock); + rt_mutex_lock(&priv->sda->lock); } static int i2c_gpio_trylock_bus(struct i2c_adapter *adap, unsigned int flags) { + struct i2c_gpio_private_data *priv = adap_to_priv(adap); + if (!rt_mutex_trylock(&adap->bus_lock)) return 0; - if (!rt_mutex_trylock(&adap_to_priv(adap)->scl->lock)) { + if (!rt_mutex_trylock(&priv->scl->lock)) { + rt_mutex_unlock(&adap->bus_lock); + return 0; + } + + if (!rt_mutex_trylock(&priv->sda->lock)) { + rt_mutex_unlock(&priv->scl->lock); rt_mutex_unlock(&adap->bus_lock); return 0; } @@ -109,7 +126,10 @@ static int i2c_gpio_trylock_bus(struct i2c_adapter *adap, unsigned int flags) static void i2c_gpio_unlock_bus(struct i2c_adapter *adap, unsigned int flags) { - rt_mutex_unlock(&adap_to_priv(adap)->scl->lock); + struct i2c_gpio_private_data *priv = adap_to_priv(adap); + + rt_mutex_unlock(&priv->sda->lock); + rt_mutex_unlock(&priv->scl->lock); rt_mutex_unlock(&adap->bus_lock); } @@ -358,8 +378,8 @@ static struct gpio_desc *i2c_gpio_get_desc(struct device *dev, int ret; /* - * Don't use resource-managed functions. SCL may be shared across adapters and has - * its own lifetime management. SDA uses the same path for consistency. + * Don't use resource-managed functions. SCL and SDA may be shared across adapters and + * have their own lifetime management. */ retdesc = gpiod_get(dev, con_id, gflags); if (!IS_ERR(retdesc)) { @@ -389,26 +409,30 @@ static struct gpio_desc *i2c_gpio_get_desc(struct device *dev, return retdesc; } -static struct i2c_gpio_scl_data *i2c_gpio_create_scl(struct device *dev) +static struct i2c_gpio_line_data *i2c_gpio_create_line(struct device *dev, const char *con_id, + unsigned int index, + struct lock_class_key *key) { struct fwnode_handle *fwnode = dev_fwnode(dev); + char propname[sizeof("scl-gpios")]; struct fwnode_reference_args args; - struct i2c_gpio_scl_data *scl; + struct i2c_gpio_line_data *line; bool sharable = false; int ret; /* - * SCL gpios can be shared if they are defined in the devicetree and have at least one - * cell in addition to the phandle. This is usually the pin. To support complex designs + * SCL and SDA gpios can be shared if they are defined in the devicetree and have at least + * one cell in addition to the phandle. This is usually the pin. To support complex designs * with arbitrary of_xlate() mappings handle the node cells opaque. */ if (fwnode) { - ret = fwnode_property_get_reference_args(fwnode, "scl-gpios", + snprintf(propname, sizeof(propname), "%s-gpios", con_id); + ret = fwnode_property_get_reference_args(fwnode, propname, "#gpio-cells", 0, 0, &args); if (ret) /* try the ancient way */ ret = fwnode_property_get_reference_args(fwnode, "gpios", - "#gpio-cells", 0, 1, &args); + "#gpio-cells", 0, index, &args); if (!ret) { if (args.nargs >= 1) @@ -418,34 +442,35 @@ static struct i2c_gpio_scl_data *i2c_gpio_create_scl(struct device *dev) } } - scl = kzalloc_obj(*scl); - if (!scl) { + line = kzalloc_obj(*line); + if (!line) { if (sharable) fwnode_handle_put(args.fwnode); return ERR_PTR(-ENOMEM); } if (sharable) { - scl->args.fwnode = args.fwnode; - scl->args.nargs = args.nargs; - memcpy(scl->args.args, args.args, sizeof(args.args[0]) * args.nargs); + line->args.fwnode = args.fwnode; + line->args.nargs = args.nargs; + memcpy(line->args.args, args.args, sizeof(args.args[0]) * args.nargs); } - rt_mutex_init(&scl->lock); - lockdep_set_class(&scl->lock, &i2c_gpio_scl_lock_key); - refcount_set(&scl->ref, 1); + line->con_id = con_id; + rt_mutex_init(&line->lock); + lockdep_set_class(&line->lock, key); + refcount_set(&line->ref, 1); - return scl; + return line; } -static void i2c_gpio_free_scl(struct i2c_gpio_scl_data *scl) +static void i2c_gpio_free_line(struct i2c_gpio_line_data *line) { - if (scl->args.fwnode) - fwnode_handle_put(scl->args.fwnode); - kfree(scl); + if (line->args.fwnode) + fwnode_handle_put(line->args.fwnode); + kfree(line); } -static bool i2c_gpio_scl_matches(struct i2c_gpio_scl_data *a, struct i2c_gpio_scl_data *b) +static bool i2c_gpio_line_matches(struct i2c_gpio_line_data *a, struct i2c_gpio_line_data *b) { if (!a->args.fwnode || !b->args.fwnode || a->args.fwnode != b->args.fwnode || a->args.nargs != b->args.nargs) @@ -455,67 +480,77 @@ static bool i2c_gpio_scl_matches(struct i2c_gpio_scl_data *a, struct i2c_gpio_sc } /* - * Look up an existing or create a new shared SCL structure. Optimistic setup sequence always - * creates and tries to add a new entry to the list. This uses minimum locking and afterwards - * requests the GPIO without a lock held. Concurrent probes for the same SCL pin see the entry - * and do not race into a second gpiod_get(). Until everything is setup they terminate with - * -EPROBE_DEFER. + * Look up an existing or create a new shared SCL or SDA structure. Optimistic setup sequence + * always creates and tries to add a new entry to the list. This uses minimum locking and + * afterwards requests the GPIO without a lock held. Concurrent probes for the same pin see the + * entry and do not race into a second gpiod_get(). Until everything is setup they terminate with + * -EPROBE_DEFER. A pin can be shared as SCL or as SDA, but not as both. */ -static struct i2c_gpio_scl_data *i2c_gpio_lookup_scl(struct device *dev, enum gpiod_flags gflags) +static struct i2c_gpio_line_data *i2c_gpio_lookup_line(struct device *dev, const char *con_id, + unsigned int index, + struct lock_class_key *key, + enum gpiod_flags gflags) { - struct i2c_gpio_scl_data *scl, *new_scl; + struct i2c_gpio_line_data *line, *new_line; struct gpio_desc *gpio; - new_scl = i2c_gpio_create_scl(dev); - if (IS_ERR(new_scl)) - return new_scl; + new_line = i2c_gpio_create_line(dev, con_id, index, key); + if (IS_ERR(new_line)) + return new_line; - scoped_guard(mutex, &i2c_gpio_scl_list_lock) { - list_for_each_entry(scl, &i2c_gpio_scl_list, list) { - if (!i2c_gpio_scl_matches(scl, new_scl)) + scoped_guard(mutex, &i2c_gpio_line_list_lock) { + list_for_each_entry(line, &i2c_gpio_line_list, list) { + if (!i2c_gpio_line_matches(line, new_line)) continue; - i2c_gpio_free_scl(new_scl); - if (!scl->gpio) + i2c_gpio_free_line(new_line); + if (strcmp(line->con_id, con_id)) { + dev_err(dev, "%s pin (%pfwP %llu) already used as %s\n", con_id, + line->args.fwnode, line->args.args[0], line->con_id); + return ERR_PTR(-EINVAL); + } + + if (!line->gpio) return ERR_PTR(-EPROBE_DEFER); - refcount_inc(&scl->ref); - if (scl->args.fwnode) - dev_dbg(dev, "reusing shared SCL (%pfwP)\n", scl->args.fwnode); + refcount_inc(&line->ref); + if (line->args.fwnode) + dev_dbg(dev, "reusing shared %s (%pfwP)\n", con_id, + line->args.fwnode); - return scl; + return line; } - list_add(&new_scl->list, &i2c_gpio_scl_list); + list_add(&new_line->list, &i2c_gpio_line_list); } - gpio = i2c_gpio_get_desc(dev, "scl", 1, gflags); + gpio = i2c_gpio_get_desc(dev, con_id, index, gflags); if (IS_ERR(gpio)) { - scoped_guard(mutex, &i2c_gpio_scl_list_lock) - list_del(&new_scl->list); - i2c_gpio_free_scl(new_scl); + scoped_guard(mutex, &i2c_gpio_line_list_lock) + list_del(&new_line->list); + i2c_gpio_free_line(new_line); return ERR_CAST(gpio); } - scoped_guard(mutex, &i2c_gpio_scl_list_lock) - new_scl->gpio = gpio; + scoped_guard(mutex, &i2c_gpio_line_list_lock) + new_line->gpio = gpio; - if (new_scl->args.fwnode) - dev_dbg(dev, "registered shared SCL (%pfwP)\n", new_scl->args.fwnode); + if (new_line->args.fwnode) + dev_dbg(dev, "registered shared %s (%pfwP)\n", con_id, new_line->args.fwnode); - return new_scl; + return new_line; } -static void i2c_gpio_cleanup_scl(struct i2c_gpio_scl_data *scl) +static void i2c_gpio_cleanup_line(struct i2c_gpio_line_data *line) { - if (!refcount_dec_and_mutex_lock(&scl->ref, &i2c_gpio_scl_list_lock)) + if (!refcount_dec_and_mutex_lock(&line->ref, &i2c_gpio_line_list_lock)) return; - list_del(&scl->list); + list_del(&line->list); /* An adapter that finds no entry requests the pin, so it must be free by then */ - gpiod_put(scl->gpio); - mutex_unlock(&i2c_gpio_scl_list_lock); - i2c_gpio_free_scl(scl); + gpiod_put(line->gpio); + mutex_unlock(&i2c_gpio_line_list_lock); + i2c_gpio_free_line(line); } static int i2c_gpio_probe(struct platform_device *pdev) @@ -560,7 +595,7 @@ static int i2c_gpio_probe(struct platform_device *pdev) gflags = GPIOD_OUT_HIGH; else gflags = GPIOD_OUT_HIGH_OPEN_DRAIN; - priv->sda = i2c_gpio_get_desc(dev, "sda", 0, gflags); + priv->sda = i2c_gpio_lookup_line(dev, "sda", 0, &i2c_gpio_sda_lock_key, gflags); if (IS_ERR(priv->sda)) return PTR_ERR(priv->sda); @@ -568,18 +603,18 @@ static int i2c_gpio_probe(struct platform_device *pdev) gflags = GPIOD_OUT_HIGH; else gflags = GPIOD_OUT_HIGH_OPEN_DRAIN; - priv->scl = i2c_gpio_lookup_scl(dev, gflags); + priv->scl = i2c_gpio_lookup_line(dev, "scl", 1, &i2c_gpio_scl_lock_key, gflags); if (IS_ERR(priv->scl)) { ret = PTR_ERR(priv->scl); goto err_cleanup_sda; } - if (gpiod_cansleep(priv->sda) || gpiod_cansleep(priv->scl->gpio)) + if (gpiod_cansleep(priv->sda->gpio) || gpiod_cansleep(priv->scl->gpio)) dev_warn(dev, "Slow GPIO pins might wreak havoc into I2C/SMBus bus timing"); else bit_data->can_do_atomic = true; - bit_data->skip_bit_test = !!priv->scl->args.fwnode; + bit_data->skip_bit_test = priv->scl->args.fwnode || priv->sda->args.fwnode; bit_data->setsda = i2c_gpio_setsda_val; bit_data->setscl = i2c_gpio_setscl_val; @@ -608,7 +643,7 @@ static int i2c_gpio_probe(struct platform_device *pdev) else snprintf(adap->name, sizeof(adap->name), "i2c-gpio%d", pdev->id); - /* Always use shared SCL aware locking */ + /* Always use shared SCL and SDA aware locking */ adap->lock_ops = &i2c_gpio_lock_ops; adap->algo_data = bit_data; adap->class = I2C_CLASS_HWMON; @@ -628,7 +663,7 @@ static int i2c_gpio_probe(struct platform_device *pdev) * from the descriptor, then provide that instead. */ dev_info(dev, "using lines %u (SDA) and %u (SCL%s)\n", - desc_to_gpio(priv->sda), desc_to_gpio(priv->scl->gpio), + desc_to_gpio(priv->sda->gpio), desc_to_gpio(priv->scl->gpio), pdata->scl_is_output_only ? ", no clock stretching" : ""); @@ -637,9 +672,9 @@ static int i2c_gpio_probe(struct platform_device *pdev) return 0; err_cleanup_scl: - i2c_gpio_cleanup_scl(priv->scl); + i2c_gpio_cleanup_line(priv->scl); err_cleanup_sda: - gpiod_put(priv->sda); + i2c_gpio_cleanup_line(priv->sda); return ret; } @@ -653,8 +688,8 @@ static void i2c_gpio_remove(struct platform_device *pdev) adap = &priv->adap; i2c_del_adapter(adap); - i2c_gpio_cleanup_scl(priv->scl); - gpiod_put(priv->sda); + i2c_gpio_cleanup_line(priv->scl); + i2c_gpio_cleanup_line(priv->sda); } static const struct of_device_id i2c_gpio_dt_ids[] = { -- Git-157)