[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5ebcd038-a2c7-458d-a04e-31771765ec1f@alliedtelesis.co.nz>
Date: Thu, 19 Sep 2024 09:44:21 +1200
From: Chris Packham <chris.packham@...iedtelesis.co.nz>
To: Andi Shyti <andi.shyti@...nel.org>
Cc: robh@...nel.org, krzk+dt@...nel.org, conor+dt@...nel.org,
tsbogend@...ha.franken.de, linux-i2c@...r.kernel.org,
devicetree@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-mips@...r.kernel.org
Subject: Re: [PATCH 5/5] i2c: rtl9300: Add multiplexing support
Hi Andi, Rob,
On 19/09/24 08:36, Andi Shyti wrote:
> Hi Chris,
>
> ...
>
>> -module_platform_driver(rtl9300_i2c_driver);
>> +static int rtl9300_i2c_select_chan(struct i2c_mux_core *muxc, u32 chan)
>> +{
>> + struct i2c_adapter *adap = muxc->parent;
>> + struct rtl9300_i2c *i2c = i2c_get_adapdata(adap);
>> + int ret;
>> +
>> + ret = rtl9300_i2c_config_io(i2c, chan);
>> + if (ret)
>> + return ret;
>> +
>> + return 0;
> return "rtl9300_i2c_config_io()"?
Ack.
>> +}
> ...
>
>> +static int rtl9300_i2c_mux_probe_fw(struct rtl9300_i2c_chan *mux, struct platform_device *pdev)
>> +{
>> + struct device *dev = &pdev->dev;
>> + struct fwnode_handle *fwnode = dev_fwnode(dev);
>> + struct device_node *np = dev->of_node;
>> + struct device_node *adap_np;
>> + struct i2c_adapter *adap = NULL;
>> + struct fwnode_handle *child;
>> + unsigned int *chans;
>> + int i = 0;
>> +
>> + if (!is_of_node(fwnode))
>> + return -EOPNOTSUPP;
>> +
>> + if (!np)
>> + return -ENODEV;
>> +
>> + adap_np = of_parse_phandle(np, "i2c-parent", 0);
>> + if (!adap_np) {
>> + dev_err(&pdev->dev, "Cannot parse i2c-parent\n");
>> + return -ENODEV;
> return dev_err_probe(...)?
Ack.
>> + }
>> + adap = of_find_i2c_adapter_by_node(adap_np);
>> + of_node_put(adap_np);
> ...
>
>> +static int __init rtl9300_i2c_init(void)
>> +{
>> + return platform_register_drivers(drivers, ARRAY_SIZE(drivers));
>> +}
>> +module_init(rtl9300_i2c_init);
>> +
>> +static void __exit rtl9300_i2c_exit(void)
>> +{
>> + platform_unregister_drivers(drivers, ARRAY_SIZE(drivers));
>> +}
>> +module_exit(rtl9300_i2c_exit);
> You could use module_platform_driver()
Can I though? I want to support both the simple I2C controller and the
MUX mode with the same driver. Which is why I've ended up with two
drivers to register.
On the binding patch, Rob made the suggestion that I just make the
i2c-mux part of the parent. I did consider that but quickly got tied in
knots because I couldn't figure out how to have a device that is both an
adapter and a mux. The main problem was that any child nodes of an i2c
adapter in the device tree are presumed to be I2C devices and get probed
automatically by of_i2c_register_devices(). Equally I can't register a
mux without having an adapter that the mux operates over.
>
> Thanks,
> Andi
>
>>
>> MODULE_DESCRIPTION("RTL9300 I2C controller driver");
>> MODULE_LICENSE("GPL");
>> --
>> 2.46.1
>>
Powered by blists - more mailing lists