From nobody Wed Feb 5 22:50:21 2025 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E3811EEA3B; Wed, 15 Jan 2025 09:26:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736933173; cv=none; b=dWRV/8BIZqcLFEGe6hfnf4QDUyOLWPVTIUC0hgA7dtL7swMv1V4T217/yRI7rdUoZvhKevul7nefff/8kvlh7By6XrLPwjATPmtfDjwYt6PwpYsu08w5O9ppDG3AbqqnxZmC4llAnQZ2q6PLX77wlbAJM0E9lqnMu0sPZdc7Ojk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736933173; c=relaxed/simple; bh=05xUnlEEGWyE6VyY2NeI1CZqHWb3u6KY2mAYidFtbrg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=H3GkoADBqKANVmt7KcJNJkrbcvDy+hVmjqDQ39fVzdCp7wJdMyjwok57btKasBY81Gi32PBd9N7JJ1rbcJyC1UXCAr8SrKrT7LQZdTLNqjp9LdnoE3V1L61TOakWFA2poQ5dWC7yJU4cXpyTVi3iSd7jqQAcUmjF/9pTDxzKgwk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=cFEInFoW; arc=none smtp.client-ip=217.70.183.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="cFEInFoW" Received: by mail.gandi.net (Postfix) with ESMTPSA id 46FA6FF80F; Wed, 15 Jan 2025 09:26:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1736933168; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vWZab+YacBd3UYeWTypp2z8Nc+CF1bnoieIofMzLNzw=; b=cFEInFoWvhfi9dbocKcOPmh+cp0b09QjMwzdYZAautsm1gPjPrma7t9WZGOYz89y3vgD+K 4vmWWwgAmqsBT5MI90QWXxn414YFFJloFPr38UoCpYsGHZ96prQA9jiLuU79DMGzd1/g98 YCpllzuokxjd9vMjthUyM7YD4zKxcYpARun0C0s/Zw6tQjPGwRyM+edm7RLPNP3Ii4O79B Mw9Aiv6HlyetWInvfbXs++L5d+CohmiRdkDd4fdl3DF6mE+sToq/lT34C/fSPSqxUl91SF dNE1fpI/Q0Q3cF7o+2fWibEhsYWN+n4s7zGor56wHcfiEAARPRYROpNSRQTbQw== From: Romain Gantois Date: Wed, 15 Jan 2025 10:25:41 +0100 Subject: [PATCH v6 4/9] i2c: use client addresses directly in ATR interface Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250115-fpc202-v6-4-d47a34820753@bootlin.com> References: <20250115-fpc202-v6-0-d47a34820753@bootlin.com> In-Reply-To: <20250115-fpc202-v6-0-d47a34820753@bootlin.com> To: Wolfram Sang , Tomi Valkeinen , Luca Ceresoli , Andi Shyti , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Derek Kiernan , Dragan Cvetic , Arnd Bergmann , Greg Kroah-Hartman , Mauro Carvalho Chehab , Linus Walleij , Bartosz Golaszewski Cc: Thomas Petazzoni , Kory Maincent , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-media@vger.kernel.org, linux-gpio@vger.kernel.org, Romain Gantois X-Mailer: b4 0.14.2 X-GND-Sasl: romain.gantois@bootlin.com The I2C Address Translator (ATR) module defines mappings from i2c_client structs to aliases. However, only the physical address of each i2c_client struct is actually relevant to the workings of the ATR module. Moreover, some drivers require address translation functionality but do not allocate i2c_client structs, accessing the adapter directly instead. The SFP subsystem is an example of this. Replace the "i2c_client" field of the i2c_atr_alias_pair struct with a u16 "addr" field. Rewrite helper functions and callbacks as needed. Reviewed-by: Tomi Valkeinen Signed-off-by: Romain Gantois --- drivers/i2c/i2c-atr.c | 52 ++++++++++++++++-----------------------= ---- drivers/media/i2c/ds90ub960.c | 24 ++++++++++---------- include/linux/i2c-atr.h | 20 ++++++++--------- 3 files changed, 41 insertions(+), 55 deletions(-) diff --git a/drivers/i2c/i2c-atr.c b/drivers/i2c/i2c-atr.c index f21475ae592183a45b5e46a20e7a0699fb88132c..f04bd4f9e3143837c035cd08d23= d5dfc37f151cb 100644 --- a/drivers/i2c/i2c-atr.c +++ b/drivers/i2c/i2c-atr.c @@ -21,16 +21,16 @@ #define ATR_MAX_SYMLINK_LEN 11 /* Longest name is 10 chars: "channel-99" */ =20 /** - * struct i2c_atr_alias_pair - Holds the alias assigned to a client. + * struct i2c_atr_alias_pair - Holds the alias assigned to a client addres= s. * @node: List node - * @client: Pointer to the client on the child bus + * @addr: Address of the client on the child bus. * @alias: I2C alias address assigned by the driver. * This is the address that will be used to issue I2C transactions * on the parent (physical) bus. */ struct i2c_atr_alias_pair { struct list_head node; - const struct i2c_client *client; + u16 addr; u16 alias; }; =20 @@ -97,27 +97,13 @@ struct i2c_atr { struct i2c_adapter *adapter[] __counted_by(max_adapters); }; =20 -static struct i2c_atr_alias_pair * -i2c_atr_find_mapping_by_client(const struct list_head *list, - const struct i2c_client *client) -{ - struct i2c_atr_alias_pair *c2a; - - list_for_each_entry(c2a, list, node) { - if (c2a->client =3D=3D client) - return c2a; - } - - return NULL; -} - static struct i2c_atr_alias_pair * i2c_atr_find_mapping_by_addr(const struct list_head *list, u16 phys_addr) { struct i2c_atr_alias_pair *c2a; =20 list_for_each_entry(c2a, list, node) { - if (c2a->client->addr =3D=3D phys_addr) + if (c2a->addr =3D=3D phys_addr) return c2a; } =20 @@ -313,8 +299,8 @@ static void i2c_atr_release_alias(struct i2c_atr *atr, = u16 alias) dev_warn(atr->dev, "Unable to find mapped alias\n"); } =20 -static int i2c_atr_attach_client(struct i2c_adapter *adapter, - const struct i2c_client *client) +static int i2c_atr_attach_addr(struct i2c_adapter *adapter, + u16 addr) { struct i2c_atr_chan *chan =3D adapter->algo_data; struct i2c_atr *atr =3D chan->atr; @@ -334,14 +320,14 @@ static int i2c_atr_attach_client(struct i2c_adapter *= adapter, goto err_release_alias; } =20 - ret =3D atr->ops->attach_client(atr, chan->chan_id, client, alias); + ret =3D atr->ops->attach_addr(atr, chan->chan_id, addr, alias); if (ret) goto err_free; =20 - dev_dbg(atr->dev, "chan%u: client 0x%02x mapped at alias 0x%02x (%s)\n", - chan->chan_id, client->addr, alias, client->name); + dev_dbg(atr->dev, "chan%u: using alias 0x%02x for addr 0x%02x\n", + chan->chan_id, alias, addr); =20 - c2a->client =3D client; + c2a->addr =3D addr; c2a->alias =3D alias; list_add(&c2a->node, &chan->alias_list); =20 @@ -355,16 +341,16 @@ static int i2c_atr_attach_client(struct i2c_adapter *= adapter, return ret; } =20 -static void i2c_atr_detach_client(struct i2c_adapter *adapter, - const struct i2c_client *client) +static void i2c_atr_detach_addr(struct i2c_adapter *adapter, + u16 addr) { struct i2c_atr_chan *chan =3D adapter->algo_data; struct i2c_atr *atr =3D chan->atr; struct i2c_atr_alias_pair *c2a; =20 - atr->ops->detach_client(atr, chan->chan_id, client); + atr->ops->detach_addr(atr, chan->chan_id, addr); =20 - c2a =3D i2c_atr_find_mapping_by_client(&chan->alias_list, client); + c2a =3D i2c_atr_find_mapping_by_addr(&chan->alias_list, addr); if (!c2a) { /* This should never happen */ dev_warn(atr->dev, "Unable to find address mapping\n"); @@ -374,8 +360,8 @@ static void i2c_atr_detach_client(struct i2c_adapter *a= dapter, i2c_atr_release_alias(atr, c2a->alias); =20 dev_dbg(atr->dev, - "chan%u: client 0x%02x unmapped from alias 0x%02x (%s)\n", - chan->chan_id, client->addr, c2a->alias, client->name); + "chan%u: detached alias 0x%02x from addr 0x%02x\n", + chan->chan_id, c2a->alias, addr); =20 list_del(&c2a->node); kfree(c2a); @@ -405,7 +391,7 @@ static int i2c_atr_bus_notifier_call(struct notifier_bl= ock *nb, =20 switch (event) { case BUS_NOTIFY_ADD_DEVICE: - ret =3D i2c_atr_attach_client(client->adapter, client); + ret =3D i2c_atr_attach_addr(client->adapter, client->addr); if (ret) dev_err(atr->dev, "Failed to attach remote client '%s': %d\n", @@ -413,7 +399,7 @@ static int i2c_atr_bus_notifier_call(struct notifier_bl= ock *nb, break; =20 case BUS_NOTIFY_DEL_DEVICE: - i2c_atr_detach_client(client->adapter, client); + i2c_atr_detach_addr(client->adapter, client->addr); break; =20 default: @@ -506,7 +492,7 @@ struct i2c_atr *i2c_atr_new(struct i2c_adapter *parent,= struct device *dev, if (max_adapters > ATR_MAX_ADAPTERS) return ERR_PTR(-EINVAL); =20 - if (!ops || !ops->attach_client || !ops->detach_client) + if (!ops || !ops->attach_addr || !ops->detach_addr) return ERR_PTR(-EINVAL); =20 atr =3D kzalloc(struct_size(atr, adapter, max_adapters), GFP_KERNEL); diff --git a/drivers/media/i2c/ds90ub960.c b/drivers/media/i2c/ds90ub960.c index 0c83c07c287c5eb168ec5d761f3d803c96d1e649..92bdd9f44c4d138903cf4ef45be= d1c20687589ad 100644 --- a/drivers/media/i2c/ds90ub960.c +++ b/drivers/media/i2c/ds90ub960.c @@ -1026,8 +1026,8 @@ static int ub960_ind_update_bits(struct ub960_data *p= riv, u8 block, u8 reg, * I2C-ATR (address translator) */ =20 -static int ub960_atr_attach_client(struct i2c_atr *atr, u32 chan_id, - const struct i2c_client *client, u16 alias) +static int ub960_atr_attach_addr(struct i2c_atr *atr, u32 chan_id, + u16 addr, u16 alias) { struct ub960_data *priv =3D i2c_atr_get_driver_data(atr); struct ub960_rxport *rxport =3D priv->rxports[chan_id]; @@ -1046,21 +1046,21 @@ static int ub960_atr_attach_client(struct i2c_atr *= atr, u32 chan_id, return -EADDRNOTAVAIL; } =20 - rxport->aliased_addrs[reg_idx] =3D client->addr; + rxport->aliased_addrs[reg_idx] =3D addr; =20 ub960_rxport_write(priv, chan_id, UB960_RR_SLAVE_ID(reg_idx), - client->addr << 1); + addr << 1); ub960_rxport_write(priv, chan_id, UB960_RR_SLAVE_ALIAS(reg_idx), alias << 1); =20 dev_dbg(dev, "rx%u: client 0x%02x assigned alias 0x%02x at slot %u\n", - rxport->nport, client->addr, alias, reg_idx); + rxport->nport, addr, alias, reg_idx); =20 return 0; } =20 -static void ub960_atr_detach_client(struct i2c_atr *atr, u32 chan_id, - const struct i2c_client *client) +static void ub960_atr_detach_addr(struct i2c_atr *atr, u32 chan_id, + u16 addr) { struct ub960_data *priv =3D i2c_atr_get_driver_data(atr); struct ub960_rxport *rxport =3D priv->rxports[chan_id]; @@ -1070,13 +1070,13 @@ static void ub960_atr_detach_client(struct i2c_atr = *atr, u32 chan_id, guard(mutex)(&rxport->aliased_addrs_lock); =20 for (reg_idx =3D 0; reg_idx < ARRAY_SIZE(rxport->aliased_addrs); reg_idx+= +) { - if (rxport->aliased_addrs[reg_idx] =3D=3D client->addr) + if (rxport->aliased_addrs[reg_idx] =3D=3D addr) break; } =20 if (reg_idx =3D=3D ARRAY_SIZE(rxport->aliased_addrs)) { dev_err(dev, "rx%u: client 0x%02x is not mapped!\n", - rxport->nport, client->addr); + rxport->nport, addr); return; } =20 @@ -1085,12 +1085,12 @@ static void ub960_atr_detach_client(struct i2c_atr = *atr, u32 chan_id, ub960_rxport_write(priv, chan_id, UB960_RR_SLAVE_ALIAS(reg_idx), 0); =20 dev_dbg(dev, "rx%u: client 0x%02x released at slot %u\n", rxport->nport, - client->addr, reg_idx); + addr, reg_idx); } =20 static const struct i2c_atr_ops ub960_atr_ops =3D { - .attach_client =3D ub960_atr_attach_client, - .detach_client =3D ub960_atr_detach_client, + .attach_addr =3D ub960_atr_attach_addr, + .detach_addr =3D ub960_atr_detach_addr, }; =20 static int ub960_init_atr(struct ub960_data *priv) diff --git a/include/linux/i2c-atr.h b/include/linux/i2c-atr.h index 4d5da161c22516b3294e73702ace7a4546cdd588..14c1f9175c0db6a8a9c6ef5d771= ae68361132a76 100644 --- a/include/linux/i2c-atr.h +++ b/include/linux/i2c-atr.h @@ -20,20 +20,20 @@ struct i2c_atr; =20 /** * struct i2c_atr_ops - Callbacks from ATR to the device driver. - * @attach_client: Notify the driver of a new device connected on a child - * bus, with the alias assigned to it. The driver must - * configure the hardware to use the alias. - * @detach_client: Notify the driver of a device getting disconnected. The - * driver must configure the hardware to stop using the - * alias. + * @attach_addr: Notify the driver of a new device connected on a child + * bus, with the alias assigned to it. The driver must + * configure the hardware to use the alias. + * @detach_addr: Notify the driver of a device getting disconnected. The + * driver must configure the hardware to stop using the + * alias. * * All these functions return 0 on success, a negative error code otherwis= e. */ struct i2c_atr_ops { - int (*attach_client)(struct i2c_atr *atr, u32 chan_id, - const struct i2c_client *client, u16 alias); - void (*detach_client)(struct i2c_atr *atr, u32 chan_id, - const struct i2c_client *client); + int (*attach_addr)(struct i2c_atr *atr, u32 chan_id, + u16 addr, u16 alias); + void (*detach_addr)(struct i2c_atr *atr, u32 chan_id, + u16 addr); }; =20 /** --=20 2.47.1