Re: [PATCH v7 2/2] i2c: i2c-gpio: Enhance driver for buses with shared SCL

Wolfram Sang <[email protected]>
Newsgroups org.kernel.vger.linux-i2c,org.kernel.vger.linux-gpio,org.kernel.vger.linux-kernel
Message-ID <alfvXUq_lNXhKQZk@ninjato>
On Tue, Jul 14, 2026 at 06:29:15PM +0200, Markus Stockhausen wrote:
> Some lower end hardware (especially Realtek based switches) are
> designed with multiple I2C buses that share a single clock line.
> E.g. the D-Link DGS-1250-28X realizes 4 I2C SFP busses with 5 GPIOs.
> 
> Enhance the i2c-gpio driver so it can handle such hardware designs.
> 
> - Detect shared SCL GPIOs that are used by multiple I2C buses in the
>   devicetree by using a "unique identifier". This is basically the
>   phandle and all additional cells.
> 
> - The first probing instance allocates and requests the shared SCL
>   GPIO with an associated rt_mutex. Subsequent instances detect the
>   existing entry via the identifier and increment a reference count
>   to reuse the descriptor.
> 
> - All data transfers are serialized via custom lock_ops that handle
>   both the standard adapter bus lock and the shared SCL mutex. This
>   ensures mutual exclusion across adapters sharing the clock line.
> 
> - This shared SCL detection works only for dts based systems where
>   the GPIO node has at least one cell (usually the pin). GPIOs in
>   legacy systems without devicetree will be handled individudally
>   as before.
> 
> This patch was successfully tested on Linksys LGS310C that has two
> SFP slots with two GPIO based I2C buses that share a single SCL.
> Test environment: OpenWrt snapshot ported to kernel 6.19.14
> including CONFIG_GPIO_SHARED=y and CONFIG_GPIO_SHARED_PROXY=y.
> 
> Signed-off-by: Markus Stockhausen <[email protected]>
> Tested-by: Sander Vanheule <[email protected]>
> Reviewed-by: Bartosz Golaszewski <[email protected]>
> Reviewed-by: Wolfram Sang <[email protected]>

Tested-by: Wolfram Sang <[email protected]>

Cool stuff! It took a bit of handling gory details, but I could not only
check that there are no regression with non-SCL-shared busses. I could
also try two busses with shared SCL and it worked like a charm.
Congrats!

Andi, from my side, you can pick up these two patches. I will put them
also in my 'for-andi' branch to increase their visibility.
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEEOZGx6rniZ1Gk92RdFA3kzBSgKbYFAmpX71wACgkQFA3kzBSg
KbZzBQ//ScYdJvdIg65ub4h25ib+LfEuCwpSdHrUwnU9IgJv3PFL76qInl+7x0Si
+3X/HOhRtwkn0mvYAZPCw9WzLavPRMAFfUaz2vh8eh8V3FqLcZC1e3KaHlWrZtBB
JEqA6ap/Mt9XOJeA1OIesDpwd1KEEWUMkYJ4iwUFNutMvnPljoeL5K5QjJb44Hmv
V7mg8AhyURHYCdz0+0CbqyytR/IWkXoIR0NI27VW7oTgh0H7f2ik8OdhdFZl2ZeZ
9XiwMLZXHF2fSifrL3pnBHZw/+ik92eiD8T5cKguyhuQcfsVn7UrWkxSdZ1deR3e
35620OpS1hHpA8dDnyQ+TngdLVG+0mqC67jG78ZHP3Lm5Pti+YdU12nhgUIK63wS
9C2fGtkvwDMbOi4sZhSBpDjbb0rEr71sQp1PBx4srJwp0b3wZ3AtZk+ZBFxaDIvi
tWDIgz5HQpqwUD13r9pxDDoGn8rZUEtaimNapxcDbaDrQy3xe3wXPlt5bmxdMDFI
WqUyJYcCczZRPmkdl/obp22VMhI9osFi3g7EEKYCpilPljlSPmObo6ejWSjj3ZkL
wJc6pErNh+WxKZD1WpFu/gNhnAGSUgYB7UGhFIKUBw1qgw5lLu5i8VZMk1VTnCy0
j6j4fPU/76lLk9RwljAkAnyIQE2TrGQorgZTotbByYu/KlRpQmg=
=2y6S
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.