Message ID | 20241008073430.3992087-8-wenst@chromium.org |
---|---|
State | Superseded |
Headers | show |
Series | [v8,1/8] of: dynamic: Add of_changeset_update_prop_string | expand |
On Tue, Oct 08, 2024 at 03:34:26PM +0800, Chen-Yu Tsai wrote: > Some devices are designed and manufactured with some components having > multiple drop-in replacement options. These components are often > connected to the mainboard via ribbon cables, having the same signals > and pin assignments across all options. These may include the display > panel and touchscreen on laptops and tablets, and the trackpad on > laptops. Sometimes which component option is used in a particular device > can be detected by some firmware provided identifier, other times that > information is not available, and the kernel has to try to probe each > device. > > This change attempts to make the "probe each device" case cleaner. The > current approach is to have all options added and enabled in the device > tree. The kernel would then bind each device and run each driver's probe > function. This works, but has been broken before due to the introduction > of asynchronous probing, causing multiple instances requesting "shared" > resources, such as pinmuxes, GPIO pins, interrupt lines, at the same > time, with only one instance succeeding. Work arounds for these include > moving the pinmux to the parent I2C controller, using GPIO hogs or > pinmux settings to keep the GPIO pins in some fixed configuration, and > requesting the interrupt line very late. Such configurations can be seen > on the MT8183 Krane Chromebook tablets, and the Qualcomm sc8280xp-based > Lenovo Thinkpad 13S. > > Instead of this delicate dance between drivers and device tree quirks, > this change introduces a simple I2C component prober. For any given > class of devices on the same I2C bus, it will go through all of them, > doing a simple I2C read transfer and see which one of them responds. > It will then enable the device that responds. > > This requires some minor modifications in the existing device tree. > The status for all the device nodes for the component options must be > set to "fail-needs-probe". This makes it clear that some mechanism is > needed to enable one of them, and also prevents the prober and device > drivers running at the same time. ... > +#include <linux/array_size.h> > +#include <linux/errno.h> > +#include <linux/i2c-of-prober.h> > +#include <linux/module.h> > +#include <linux/of.h> > +#include <linux/platform_device.h> > +static int chromeos_i2c_component_prober(struct device *dev, const void *_data) > +{ > + const struct chromeos_i2c_probe_data *data = _data; > + struct i2c_of_probe_simple_ctx ctx = { > + .opts = data->opts Leave trailing comma in such cases (when it's not a terminator and not on the same line with the variable definition). > + }; > + > + return i2c_of_probe_component(dev, data->cfg, &ctx); > +} > + > +static const struct chromeos_i2c_probe_data chromeos_i2c_probe_dumb_touchscreen = { > + .cfg = &(const struct i2c_of_probe_cfg) { Perhaps you can introduce something like #define DEFINE_I2C_OF_PROBE_CFG(_type_, _ops_) \ (struct ...) { \ .ops = _ops_, \ .type = #_type_, \ } and use it here as .cfg = DEFINE_I2C_OF_PROBE_CFG(touchscreen, NULL), > + .type = "touchscreen" Ditto. > + } Ditto. > +}; > + > +static const struct i2c_of_probe_cfg chromeos_i2c_probe_simple_trackpad_cfg = { > + .ops = &i2c_of_probe_simple_ops, > + .type = "trackpad" Leave a comma. > +}; ... > +static const struct chromeos_i2c_probe_data chromeos_i2c_probe_hana_trackpad = { > + .cfg = &chromeos_i2c_probe_simple_trackpad_cfg, .cfg = DEFINE_I2C_OF_PROBE_CFG(trackpad, i2c_of_probe_simple_ops), Or even #define DEFINE_I2C_OF_PROBE_CFG_SIMPLE(_type_) \ DEFINE_I2C_OF_PROBE_CFG(type, &i2c_of_probe_simple_ops) > + .opts = &(const struct i2c_of_probe_simple_opts) { Perhaps also DEFINE_xxx for this compound literal? > + .res_node_compatible = "elan,ekth3000", > + .supply_name = "vcc", > + /* > + * ELAN trackpad needs 2 ms for H/W init and 100 ms for F/W init. > + * Synaptics trackpad needs 100 ms. > + * However, the regulator is set to "always-on", presumably to > + * avoid this delay. The ELAN driver is also missing delays. > + */ > + .post_power_on_delay_ms = 0, > + } > +}; > + > +static const struct hw_prober_entry hw_prober_platforms[] = { > + { .compatible = "google,hana", .prober = chromeos_i2c_component_prober, .data = &chromeos_i2c_probe_dumb_touchscreen }, > + { .compatible = "google,hana", .prober = chromeos_i2c_component_prober, .data = &chromeos_i2c_probe_hana_trackpad }, These strings are a bit long, perhaps wrap on one member per line? > +};
On Thu, Oct 10, 2024 at 06:29:44PM +0300, Andy Shevchenko wrote: > On Tue, Oct 08, 2024 at 03:34:26PM +0800, Chen-Yu Tsai wrote: ... > > +static const struct chromeos_i2c_probe_data chromeos_i2c_probe_dumb_touchscreen = { > > + .cfg = &(const struct i2c_of_probe_cfg) { > > Perhaps you can introduce something like > > #define DEFINE_I2C_OF_PROBE_CFG(_type_, _ops_) \ > (struct ...) { \ > .ops = _ops_, \ > .type = #_type_, \ > } > > and use it here as > > .cfg = DEFINE_I2C_OF_PROBE_CFG(touchscreen, NULL), > > > + .type = "touchscreen" > > Ditto. This was for leaving trailing comma. > > + } > > Ditto. > > > +}; > > + > > +static const struct i2c_of_probe_cfg chromeos_i2c_probe_simple_trackpad_cfg = { > > + .ops = &i2c_of_probe_simple_ops, > > + .type = "trackpad" > > Leave a comma. > > > +}; ... > > + .cfg = &chromeos_i2c_probe_simple_trackpad_cfg, > > .cfg = DEFINE_I2C_OF_PROBE_CFG(trackpad, i2c_of_probe_simple_ops), > > Or even > > #define DEFINE_I2C_OF_PROBE_CFG_SIMPLE(_type_) \ > DEFINE_I2C_OF_PROBE_CFG(type, &i2c_of_probe_simple_ops) With that also looking at the above #define DEFINE_I2C_OF_PROBE_CFG_NONE(_type_) \ DEFINE_I2C_OF_PROBE_CFG(type, NULL)
On Thu, Oct 10, 2024 at 11:32 PM Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote: > > On Thu, Oct 10, 2024 at 06:29:44PM +0300, Andy Shevchenko wrote: > > On Tue, Oct 08, 2024 at 03:34:26PM +0800, Chen-Yu Tsai wrote: > > ... > > > > +static const struct chromeos_i2c_probe_data chromeos_i2c_probe_dumb_touchscreen = { > > > + .cfg = &(const struct i2c_of_probe_cfg) { > > > > Perhaps you can introduce something like > > > > #define DEFINE_I2C_OF_PROBE_CFG(_type_, _ops_) \ > > (struct ...) { \ > > .ops = _ops_, \ > > .type = #_type_, \ > > } > > > > and use it here as > > > > .cfg = DEFINE_I2C_OF_PROBE_CFG(touchscreen, NULL), > > > > > + .type = "touchscreen" > > > > Ditto. > > This was for leaving trailing comma. Ack. > > > + } > > > > Ditto. > > > > > +}; > > > + > > > +static const struct i2c_of_probe_cfg chromeos_i2c_probe_simple_trackpad_cfg = { > > > + .ops = &i2c_of_probe_simple_ops, > > > + .type = "trackpad" > > > > Leave a comma. Ack > > > +}; > > ... > > > > + .cfg = &chromeos_i2c_probe_simple_trackpad_cfg, > > > > .cfg = DEFINE_I2C_OF_PROBE_CFG(trackpad, i2c_of_probe_simple_ops), > > > > Or even > > > > #define DEFINE_I2C_OF_PROBE_CFG_SIMPLE(_type_) \ > > DEFINE_I2C_OF_PROBE_CFG(type, &i2c_of_probe_simple_ops) I'm not inclined on using compound literals here. "simple X cfg" will likely get shared between multiple |chromeos_i2c_probe_data| entries, and AFAIK the toolchain can't merge them. So we would end up with one compound literal per entry, even if their contents are the same. > With that also looking at the above > > #define DEFINE_I2C_OF_PROBE_CFG_NONE(_type_) \ > DEFINE_I2C_OF_PROBE_CFG(type, NULL) For the "dumb" case it makes sense though, since it would be one instance per type. But we could go further and just wrap the whole |chromeos_i2c_probe_data| declaration. ChenYu
On Thu, Oct 10, 2024 at 11:29 PM Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote: > > On Tue, Oct 08, 2024 at 03:34:26PM +0800, Chen-Yu Tsai wrote: > > Some devices are designed and manufactured with some components having > > multiple drop-in replacement options. These components are often > > connected to the mainboard via ribbon cables, having the same signals > > and pin assignments across all options. These may include the display > > panel and touchscreen on laptops and tablets, and the trackpad on > > laptops. Sometimes which component option is used in a particular device > > can be detected by some firmware provided identifier, other times that > > information is not available, and the kernel has to try to probe each > > device. > > > > This change attempts to make the "probe each device" case cleaner. The > > current approach is to have all options added and enabled in the device > > tree. The kernel would then bind each device and run each driver's probe > > function. This works, but has been broken before due to the introduction > > of asynchronous probing, causing multiple instances requesting "shared" > > resources, such as pinmuxes, GPIO pins, interrupt lines, at the same > > time, with only one instance succeeding. Work arounds for these include > > moving the pinmux to the parent I2C controller, using GPIO hogs or > > pinmux settings to keep the GPIO pins in some fixed configuration, and > > requesting the interrupt line very late. Such configurations can be seen > > on the MT8183 Krane Chromebook tablets, and the Qualcomm sc8280xp-based > > Lenovo Thinkpad 13S. > > > > Instead of this delicate dance between drivers and device tree quirks, > > this change introduces a simple I2C component prober. For any given > > class of devices on the same I2C bus, it will go through all of them, > > doing a simple I2C read transfer and see which one of them responds. > > It will then enable the device that responds. > > > > This requires some minor modifications in the existing device tree. > > The status for all the device nodes for the component options must be > > set to "fail-needs-probe". This makes it clear that some mechanism is > > needed to enable one of them, and also prevents the prober and device > > drivers running at the same time. > > ... > > > +#include <linux/array_size.h> > > +#include <linux/errno.h> > > +#include <linux/i2c-of-prober.h> > > +#include <linux/module.h> > > +#include <linux/of.h> > > +#include <linux/platform_device.h> > > > +static int chromeos_i2c_component_prober(struct device *dev, const void *_data) > > +{ > > + const struct chromeos_i2c_probe_data *data = _data; > > + struct i2c_of_probe_simple_ctx ctx = { > > + .opts = data->opts > > Leave trailing comma in such cases (when it's not a terminator and > not on the same line with the variable definition). Ack. > > + }; > > + > > + return i2c_of_probe_component(dev, data->cfg, &ctx); > > +} > > + > > +static const struct chromeos_i2c_probe_data chromeos_i2c_probe_dumb_touchscreen = { > > + .cfg = &(const struct i2c_of_probe_cfg) { > > Perhaps you can introduce something like > > #define DEFINE_I2C_OF_PROBE_CFG(_type_, _ops_) \ > (struct ...) { \ > .ops = _ops_, \ > .type = #_type_, \ > } > > and use it here as > > .cfg = DEFINE_I2C_OF_PROBE_CFG(touchscreen, NULL), Overall reply about the compound literals is in my other email. > > + .type = "touchscreen" > > Ditto. Ack. > > > + } > > Ditto. > > > +}; > > + > > +static const struct i2c_of_probe_cfg chromeos_i2c_probe_simple_trackpad_cfg = { > > + .ops = &i2c_of_probe_simple_ops, > > + .type = "trackpad" > > Leave a comma. Ack. > > +}; > > ... > > > +static const struct chromeos_i2c_probe_data chromeos_i2c_probe_hana_trackpad = { > > + .cfg = &chromeos_i2c_probe_simple_trackpad_cfg, > > .cfg = DEFINE_I2C_OF_PROBE_CFG(trackpad, i2c_of_probe_simple_ops), > > Or even > > #define DEFINE_I2C_OF_PROBE_CFG_SIMPLE(_type_) \ > DEFINE_I2C_OF_PROBE_CFG(type, &i2c_of_probe_simple_ops) > > > + .opts = &(const struct i2c_of_probe_simple_opts) { > > Perhaps also DEFINE_xxx for this compound literal? I think it's better to leave this one as is. Not every entry will use the same combination of parameters. And having the entry spelled out like this makes it easier to read which value is for what parameter, instead of having to go up to the macro definition. For comparison, this entry uses just two of the parameters, while for another platform I'm working on the full set of parameters is needed. > > + .res_node_compatible = "elan,ekth3000", > > + .supply_name = "vcc", > > + /* > > + * ELAN trackpad needs 2 ms for H/W init and 100 ms for F/W init. > > + * Synaptics trackpad needs 100 ms. > > + * However, the regulator is set to "always-on", presumably to > > + * avoid this delay. The ELAN driver is also missing delays. > > + */ > > + .post_power_on_delay_ms = 0, > > + } > > +}; > > + > > +static const struct hw_prober_entry hw_prober_platforms[] = { > > + { .compatible = "google,hana", .prober = chromeos_i2c_component_prober, .data = &chromeos_i2c_probe_dumb_touchscreen }, > > + { .compatible = "google,hana", .prober = chromeos_i2c_component_prober, .data = &chromeos_i2c_probe_hana_trackpad }, > > These strings are a bit long, perhaps wrap on one member per line? Sure. ChenYu > > +}; > > -- > With Best Regards, > Andy Shevchenko > >
On Mon, Oct 14, 2024 at 12:56:20PM +0800, Chen-Yu Tsai wrote: > On Thu, Oct 10, 2024 at 11:32 PM Andy Shevchenko > <andriy.shevchenko@linux.intel.com> wrote: > > On Thu, Oct 10, 2024 at 06:29:44PM +0300, Andy Shevchenko wrote: > > > On Tue, Oct 08, 2024 at 03:34:26PM +0800, Chen-Yu Tsai wrote: ... > > > > + .cfg = &chromeos_i2c_probe_simple_trackpad_cfg, > > > > > > .cfg = DEFINE_I2C_OF_PROBE_CFG(trackpad, i2c_of_probe_simple_ops), > > > > > > Or even > > > > > > #define DEFINE_I2C_OF_PROBE_CFG_SIMPLE(_type_) \ > > > DEFINE_I2C_OF_PROBE_CFG(type, &i2c_of_probe_simple_ops) > > I'm not inclined on using compound literals here. "simple X cfg" will > likely get shared between multiple |chromeos_i2c_probe_data| entries, > and AFAIK the toolchain can't merge them. So we would end up with one > compound literal per entry, even if their contents are the same. I'm not sure I follow, you are using compound literal _already_. How does my proposal change that? > > With that also looking at the above > > > > #define DEFINE_I2C_OF_PROBE_CFG_NONE(_type_) \ > > DEFINE_I2C_OF_PROBE_CFG(type, NULL) > > For the "dumb" case it makes sense though, since it would be one instance > per type. But we could go further and just wrap the whole > |chromeos_i2c_probe_data| declaration. Maybe it's too far from now...
On Mon, Oct 14, 2024 at 03:04:44PM +0800, Chen-Yu Tsai wrote: > On Thu, Oct 10, 2024 at 11:29 PM Andy Shevchenko > <andriy.shevchenko@linux.intel.com> wrote: > > On Tue, Oct 08, 2024 at 03:34:26PM +0800, Chen-Yu Tsai wrote: ... > > > +static const struct chromeos_i2c_probe_data chromeos_i2c_probe_hana_trackpad = { > > > + .cfg = &chromeos_i2c_probe_simple_trackpad_cfg, > > > > .cfg = DEFINE_I2C_OF_PROBE_CFG(trackpad, i2c_of_probe_simple_ops), > > > > Or even > > > > #define DEFINE_I2C_OF_PROBE_CFG_SIMPLE(_type_) \ > > DEFINE_I2C_OF_PROBE_CFG(type, &i2c_of_probe_simple_ops) > > > > > + .opts = &(const struct i2c_of_probe_simple_opts) { > > > > Perhaps also DEFINE_xxx for this compound literal? > > I think it's better to leave this one as is. Using a compound literal like this questions the entire approach. Why you can't you drop it and use the static initializers? > Not every entry will > use the same combination of parameters. And having the entry spelled > out like this makes it easier to read which value is for what > parameter, instead of having to go up to the macro definition. > > For comparison, this entry uses just two of the parameters, while for > another platform I'm working on the full set of parameters is needed. > > > > + .res_node_compatible = "elan,ekth3000", > > > + .supply_name = "vcc", > > > + /* > > > + * ELAN trackpad needs 2 ms for H/W init and 100 ms for F/W init. > > > + * Synaptics trackpad needs 100 ms. > > > + * However, the regulator is set to "always-on", presumably to > > > + * avoid this delay. The ELAN driver is also missing delays. > > > + */ > > > + .post_power_on_delay_ms = 0, > > > + } > > > +};
On Mon, Oct 14, 2024 at 7:23 PM Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote: > > On Mon, Oct 14, 2024 at 12:56:20PM +0800, Chen-Yu Tsai wrote: > > On Thu, Oct 10, 2024 at 11:32 PM Andy Shevchenko > > <andriy.shevchenko@linux.intel.com> wrote: > > > On Thu, Oct 10, 2024 at 06:29:44PM +0300, Andy Shevchenko wrote: > > > > On Tue, Oct 08, 2024 at 03:34:26PM +0800, Chen-Yu Tsai wrote: > > ... > > > > > > + .cfg = &chromeos_i2c_probe_simple_trackpad_cfg, > > > > > > > > .cfg = DEFINE_I2C_OF_PROBE_CFG(trackpad, i2c_of_probe_simple_ops), > > > > > > > > Or even > > > > > > > > #define DEFINE_I2C_OF_PROBE_CFG_SIMPLE(_type_) \ > > > > DEFINE_I2C_OF_PROBE_CFG(type, &i2c_of_probe_simple_ops) > > > > I'm not inclined on using compound literals here. "simple X cfg" will > > likely get shared between multiple |chromeos_i2c_probe_data| entries, > > and AFAIK the toolchain can't merge them. So we would end up with one > > compound literal per entry, even if their contents are the same. > > I'm not sure I follow, you are using compound literal _already_. > How does my proposal change that? I'm using it where it makes sense, i.e. where the embedded variable is not going to be shared with other instances. For the dumb probers, there's only going to be one instance per "type". For the simple probers, the config part is still one instance per "type", but the parameters are board and component specific. There will be multiple instances. Hence the config part can be shared, while the parameters likely won't be. > > > With that also looking at the above > > > > > > #define DEFINE_I2C_OF_PROBE_CFG_NONE(_type_) \ > > > DEFINE_I2C_OF_PROBE_CFG(type, NULL) > > > > For the "dumb" case it makes sense though, since it would be one instance > > per type. But we could go further and just wrap the whole > > |chromeos_i2c_probe_data| declaration. > > Maybe it's too far from now... This is what I have: #define DEFINE_CHROMEOS_I2C_PROBE_DATA_DUMB(_type) \ static const struct chromeos_i2c_probe_data chromeos_i2c_probe_dumb_ ## _type = { \ .cfg = &(const struct i2c_of_probe_cfg) { \ .type = #_type, \ }, \ }; DEFINE_CHROMEOS_I2C_PROBE_DATA_DUMB(touchscreen); ChenYu
On Mon, Oct 14, 2024 at 02:25:27PM +0300, Andy Shevchenko wrote: > On Mon, Oct 14, 2024 at 03:04:44PM +0800, Chen-Yu Tsai wrote: > > On Thu, Oct 10, 2024 at 11:29 PM Andy Shevchenko > > <andriy.shevchenko@linux.intel.com> wrote: > > > On Tue, Oct 08, 2024 at 03:34:26PM +0800, Chen-Yu Tsai wrote: > > ... > > > > > +static const struct chromeos_i2c_probe_data chromeos_i2c_probe_hana_trackpad = { > > > > + .cfg = &chromeos_i2c_probe_simple_trackpad_cfg, > > > > > > .cfg = DEFINE_I2C_OF_PROBE_CFG(trackpad, i2c_of_probe_simple_ops), > > > > > > Or even > > > > > > #define DEFINE_I2C_OF_PROBE_CFG_SIMPLE(_type_) \ > > > DEFINE_I2C_OF_PROBE_CFG(type, &i2c_of_probe_simple_ops) > > > > > > > + .opts = &(const struct i2c_of_probe_simple_opts) { > > > > > > Perhaps also DEFINE_xxx for this compound literal? > > > > I think it's better to leave this one as is. > > Using a compound literal like this questions the entire approach. I don't follow. It's a valid use. > Why you can't you drop it and use the static initializers? Did you mean split that part out as a separate variable: static const struct i2c_of_probe_simple_opts chromeos_i2c_probe_voltorb_tch_opts = { .res_node_compatible = "elan,ekth6915", .supply_name = "vcc33", .gpio_name = "reset", .post_power_on_delay_ms = 1, .post_gpio_config_delay_ms = 300, .gpio_assert_to_enable = true, }; static const struct chromeos_i2c_probe_data chromeos_i2c_probe_voltorb_touchscreen = { .cfg = &chromeos_i2c_probe_simple_touchscreen_cfg, .opts = &chromeos_i2c_probe_voltorb_tch_opts, }; Instead of the following, which is slightly shorter, and gets rid of one explicit symbol name: static const struct chromeos_i2c_probe_data chromeos_i2c_probe_voltorb_touchscreen = { .cfg = &chromeos_i2c_probe_simple_touchscreen_cfg, .opts = &(const struct i2c_of_probe_simple_opts) { .res_node_compatible = "elan,ekth6915", .supply_name = "vcc33", .gpio_name = "reset", .post_power_on_delay_ms = 1, .post_gpio_config_delay_ms = 300, .gpio_assert_to_enable = true, }, }; ChenYu > > Not every entry will > > use the same combination of parameters. And having the entry spelled > > out like this makes it easier to read which value is for what > > parameter, instead of having to go up to the macro definition. > > > > For comparison, this entry uses just two of the parameters, while for > > another platform I'm working on the full set of parameters is needed. > > > > > > + .res_node_compatible = "elan,ekth3000", > > > > + .supply_name = "vcc", > > > > + /* > > > > + * ELAN trackpad needs 2 ms for H/W init and 100 ms for F/W init. > > > > + * Synaptics trackpad needs 100 ms. > > > > + * However, the regulator is set to "always-on", presumably to > > > > + * avoid this delay. The ELAN driver is also missing delays. > > > > + */ > > > > + .post_power_on_delay_ms = 0, > > > > + } > > > > +}; > > -- > With Best Regards, > Andy Shevchenko > >
On Tue, Oct 15, 2024 at 02:32:54PM +0800, Chen-Yu Tsai wrote: > On Mon, Oct 14, 2024 at 7:23 PM Andy Shevchenko > <andriy.shevchenko@linux.intel.com> wrote: > > On Mon, Oct 14, 2024 at 12:56:20PM +0800, Chen-Yu Tsai wrote: > > > On Thu, Oct 10, 2024 at 11:32 PM Andy Shevchenko > > > <andriy.shevchenko@linux.intel.com> wrote: > > > > On Thu, Oct 10, 2024 at 06:29:44PM +0300, Andy Shevchenko wrote: > > > > > On Tue, Oct 08, 2024 at 03:34:26PM +0800, Chen-Yu Tsai wrote: ... > > > > > > + .cfg = &chromeos_i2c_probe_simple_trackpad_cfg, > > > > > > > > > > .cfg = DEFINE_I2C_OF_PROBE_CFG(trackpad, i2c_of_probe_simple_ops), > > > > > > > > > > Or even > > > > > > > > > > #define DEFINE_I2C_OF_PROBE_CFG_SIMPLE(_type_) \ > > > > > DEFINE_I2C_OF_PROBE_CFG(type, &i2c_of_probe_simple_ops) > > > > > > I'm not inclined on using compound literals here. "simple X cfg" will > > > likely get shared between multiple |chromeos_i2c_probe_data| entries, > > > and AFAIK the toolchain can't merge them. So we would end up with one > > > compound literal per entry, even if their contents are the same. > > > > I'm not sure I follow, you are using compound literal _already_. > > How does my proposal change that? > > I'm using it where it makes sense, i.e. where the embedded variable > is not going to be shared with other instances. > > For the dumb probers, there's only going to be one instance per "type". > > For the simple probers, the config part is still one instance per "type", > but the parameters are board and component specific. There will be > multiple instances. Hence the config part can be shared, while the > parameters likely won't be. > > > > > With that also looking at the above > > > > > > > > #define DEFINE_I2C_OF_PROBE_CFG_NONE(_type_) \ > > > > DEFINE_I2C_OF_PROBE_CFG(type, NULL) > > > > > > For the "dumb" case it makes sense though, since it would be one instance > > > per type. But we could go further and just wrap the whole > > > |chromeos_i2c_probe_data| declaration. > > > > Maybe it's too far from now... > > This is what I have: > > #define DEFINE_CHROMEOS_I2C_PROBE_DATA_DUMB(_type) > \ > static const struct chromeos_i2c_probe_data > chromeos_i2c_probe_dumb_ ## _type = { \ > .cfg = &(const struct i2c_of_probe_cfg) { But the below is static initializer, why do you need a compound literal here? > \ > .type = #_type, > \ > }, > \ > }; > > DEFINE_CHROMEOS_I2C_PROBE_DATA_DUMB(touchscreen); s/dumb/simple/g
On Tue, Oct 15, 2024 at 7:24 PM Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote: > > On Tue, Oct 15, 2024 at 02:32:54PM +0800, Chen-Yu Tsai wrote: > > On Mon, Oct 14, 2024 at 7:23 PM Andy Shevchenko > > <andriy.shevchenko@linux.intel.com> wrote: > > > On Mon, Oct 14, 2024 at 12:56:20PM +0800, Chen-Yu Tsai wrote: > > > > On Thu, Oct 10, 2024 at 11:32 PM Andy Shevchenko > > > > <andriy.shevchenko@linux.intel.com> wrote: > > > > > On Thu, Oct 10, 2024 at 06:29:44PM +0300, Andy Shevchenko wrote: > > > > > > On Tue, Oct 08, 2024 at 03:34:26PM +0800, Chen-Yu Tsai wrote: > > ... > > > > > > > > + .cfg = &chromeos_i2c_probe_simple_trackpad_cfg, > > > > > > > > > > > > .cfg = DEFINE_I2C_OF_PROBE_CFG(trackpad, i2c_of_probe_simple_ops), > > > > > > > > > > > > Or even > > > > > > > > > > > > #define DEFINE_I2C_OF_PROBE_CFG_SIMPLE(_type_) \ > > > > > > DEFINE_I2C_OF_PROBE_CFG(type, &i2c_of_probe_simple_ops) > > > > > > > > I'm not inclined on using compound literals here. "simple X cfg" will > > > > likely get shared between multiple |chromeos_i2c_probe_data| entries, > > > > and AFAIK the toolchain can't merge them. So we would end up with one > > > > compound literal per entry, even if their contents are the same. > > > > > > I'm not sure I follow, you are using compound literal _already_. > > > How does my proposal change that? > > > > I'm using it where it makes sense, i.e. where the embedded variable > > is not going to be shared with other instances. > > > > For the dumb probers, there's only going to be one instance per "type". > > > > For the simple probers, the config part is still one instance per "type", > > but the parameters are board and component specific. There will be > > multiple instances. Hence the config part can be shared, while the > > parameters likely won't be. > > > > > > > With that also looking at the above > > > > > > > > > > #define DEFINE_I2C_OF_PROBE_CFG_NONE(_type_) \ > > > > > DEFINE_I2C_OF_PROBE_CFG(type, NULL) > > > > > > > > For the "dumb" case it makes sense though, since it would be one instance > > > > per type. But we could go further and just wrap the whole > > > > |chromeos_i2c_probe_data| declaration. > > > > > > Maybe it's too far from now... > > > > This is what I have: > > > > #define DEFINE_CHROMEOS_I2C_PROBE_DATA_DUMB(_type) > > \ > > static const struct chromeos_i2c_probe_data > > chromeos_i2c_probe_dumb_ ## _type = { \ > > > .cfg = &(const struct i2c_of_probe_cfg) { > > But the below is static initializer, why do you need a compound literal here? Because .cfg takes a pointer to a struct. It's not an embedded struct. The compound literal creates the internal struct, and then its address is taken and assigned to the .cfg field. Does that make sense? > > \ > > .type = #_type, > > \ > > }, > > \ > > }; > > > > DEFINE_CHROMEOS_I2C_PROBE_DATA_DUMB(touchscreen); > > s/dumb/simple/g "simple" is taken. This is "dumb" as in it does not need any helpers. Maybe "no-op" if you don't like the negative connotation? ChenYu
On Tue, Oct 15, 2024 at 08:18:50PM +0800, Chen-Yu Tsai wrote: > On Tue, Oct 15, 2024 at 7:24 PM Andy Shevchenko > <andriy.shevchenko@linux.intel.com> wrote: > > On Tue, Oct 15, 2024 at 02:32:54PM +0800, Chen-Yu Tsai wrote: > > > On Mon, Oct 14, 2024 at 7:23 PM Andy Shevchenko > > > <andriy.shevchenko@linux.intel.com> wrote: > > > > On Mon, Oct 14, 2024 at 12:56:20PM +0800, Chen-Yu Tsai wrote: > > > > > On Thu, Oct 10, 2024 at 11:32 PM Andy Shevchenko > > > > > <andriy.shevchenko@linux.intel.com> wrote: > > > > > > On Thu, Oct 10, 2024 at 06:29:44PM +0300, Andy Shevchenko wrote: > > > > > > > On Tue, Oct 08, 2024 at 03:34:26PM +0800, Chen-Yu Tsai wrote: ... > > > > > > > > + .cfg = &chromeos_i2c_probe_simple_trackpad_cfg, > > > > > > > > > > > > > > .cfg = DEFINE_I2C_OF_PROBE_CFG(trackpad, i2c_of_probe_simple_ops), > > > > > > > > > > > > > > Or even > > > > > > > > > > > > > > #define DEFINE_I2C_OF_PROBE_CFG_SIMPLE(_type_) \ > > > > > > > DEFINE_I2C_OF_PROBE_CFG(type, &i2c_of_probe_simple_ops) > > > > > > > > > > I'm not inclined on using compound literals here. "simple X cfg" will > > > > > likely get shared between multiple |chromeos_i2c_probe_data| entries, > > > > > and AFAIK the toolchain can't merge them. So we would end up with one > > > > > compound literal per entry, even if their contents are the same. > > > > > > > > I'm not sure I follow, you are using compound literal _already_. > > > > How does my proposal change that? > > > > > > I'm using it where it makes sense, i.e. where the embedded variable > > > is not going to be shared with other instances. > > > > > > For the dumb probers, there's only going to be one instance per "type". > > > > > > For the simple probers, the config part is still one instance per "type", > > > but the parameters are board and component specific. There will be > > > multiple instances. Hence the config part can be shared, while the > > > parameters likely won't be. > > > > > > > > > With that also looking at the above > > > > > > > > > > > > #define DEFINE_I2C_OF_PROBE_CFG_NONE(_type_) \ > > > > > > DEFINE_I2C_OF_PROBE_CFG(type, NULL) > > > > > > > > > > For the "dumb" case it makes sense though, since it would be one instance > > > > > per type. But we could go further and just wrap the whole > > > > > |chromeos_i2c_probe_data| declaration. > > > > > > > > Maybe it's too far from now... > > > > > > This is what I have: > > > > > > #define DEFINE_CHROMEOS_I2C_PROBE_DATA_DUMB(_type) > > > \ > > > static const struct chromeos_i2c_probe_data > > > chromeos_i2c_probe_dumb_ ## _type = { \ > > > > > .cfg = &(const struct i2c_of_probe_cfg) { > > > > But the below is static initializer, why do you need a compound literal here? > > Because .cfg takes a pointer to a struct. It's not an embedded struct. > The compound literal creates the internal struct, and then its address > is taken and assigned to the .cfg field. > > Does that make sense? Okay, I see now. Yeah, I have no preferences here, I saw the code like in split version or like in yours. I _slightly_ bend to non-compound literal variant, but again here it might be not worth doing a such. > > > \ > > > .type = #_type, > > > \ > > > }, > > > \ > > > }; > > > > > > DEFINE_CHROMEOS_I2C_PROBE_DATA_DUMB(touchscreen); > > > > s/dumb/simple/g > > "simple" is taken. This is "dumb" as in it does not need any helpers. > Maybe "no-op" if you don't like the negative connotation? _BY_TYPE ?
Hi, On Tue, Oct 8, 2024 at 12:35 AM Chen-Yu Tsai <wenst@chromium.org> wrote: > > Some devices are designed and manufactured with some components having > multiple drop-in replacement options. These components are often > connected to the mainboard via ribbon cables, having the same signals > and pin assignments across all options. These may include the display > panel and touchscreen on laptops and tablets, and the trackpad on > laptops. Sometimes which component option is used in a particular device > can be detected by some firmware provided identifier, other times that > information is not available, and the kernel has to try to probe each > device. > > This change attempts to make the "probe each device" case cleaner. The > current approach is to have all options added and enabled in the device > tree. The kernel would then bind each device and run each driver's probe > function. This works, but has been broken before due to the introduction > of asynchronous probing, causing multiple instances requesting "shared" > resources, such as pinmuxes, GPIO pins, interrupt lines, at the same > time, with only one instance succeeding. Work arounds for these include > moving the pinmux to the parent I2C controller, using GPIO hogs or > pinmux settings to keep the GPIO pins in some fixed configuration, and > requesting the interrupt line very late. Such configurations can be seen > on the MT8183 Krane Chromebook tablets, and the Qualcomm sc8280xp-based > Lenovo Thinkpad 13S. > > Instead of this delicate dance between drivers and device tree quirks, > this change introduces a simple I2C component prober. For any given > class of devices on the same I2C bus, it will go through all of them, > doing a simple I2C read transfer and see which one of them responds. > It will then enable the device that responds. > > This requires some minor modifications in the existing device tree. > The status for all the device nodes for the component options must be > set to "fail-needs-probe". This makes it clear that some mechanism is > needed to enable one of them, and also prevents the prober and device > drivers running at the same time. > > Signed-off-by: Chen-Yu Tsai <wenst@chromium.org> > Acked-by: Tzung-Bi Shih <tzungbi@kernel.org> > --- > Maintainer expects this to be merged through I2C tree. > > Changes since v7: > - Corrected Makefile item order > - Replaced "failed-needs-probe" with "fail-needs-probe" in commit message > - Added include of "linux/of.h" for of_machine_is_compatible() > - Switched to simple probe helpers for trackpads on Hana > > Changes since v6: > - Adapted to new I2C OF prober interface > - Collected Acked-by > > Changes since v5: > - Adapt to new i2c_of_probe_component() parameters > > Changes since v4: > - Fix Kconfig dependency > - Update copyright year > - Drop "linux/of.h" header > - Include "linux/errno.h" > - Move |int ret| declaration to top of block > - Return -ENODEV on no match instead of 0 > - Unregister platform driver and device unconditionally after previous > change > > Changes since v3: > - Include linux/init.h > - Rewrite for loop in driver probe function as suggested by Andy > - Make prober driver buildable as module > - Ignore prober errors other than probe deferral > > Changes since v2: > - Addressed Rob's comments > - Move remaining driver code to drivers/platform/chrome/ > - Depend on rather than select CONFIG_I2C > - Copy machine check to driver init function > - Addressed Andy's comments > - Explicitly mention "device tree" or OF in driver name, description > and Kconfig symbol > - Drop filename from inside the file > - Switch to passing "struct device *" to shorten lines > - Move "ret = 0" to just before for_each_child_of_node(i2c_node, node) > - Make loop variable size_t (instead of unsigned int as Andy asked) > - Use PLATFORM_DEVID_NONE instead of raw -1 > - Use standard goto error path pattern in hw_prober_driver_init() > > - Changes since v1: > - New patch > --- > drivers/platform/chrome/Kconfig | 11 ++ > drivers/platform/chrome/Makefile | 1 + > .../platform/chrome/chromeos_of_hw_prober.c | 140 ++++++++++++++++++ > 3 files changed, 152 insertions(+) Reviewed-by: Douglas Anderson <dianders@chromium.org>
diff --git a/drivers/platform/chrome/Kconfig b/drivers/platform/chrome/Kconfig index 7dbeb786352a..b7dbaf77b6db 100644 --- a/drivers/platform/chrome/Kconfig +++ b/drivers/platform/chrome/Kconfig @@ -61,6 +61,17 @@ config CHROMEOS_TBMC To compile this driver as a module, choose M here: the module will be called chromeos_tbmc. +config CHROMEOS_OF_HW_PROBER + tristate "ChromeOS Device Tree Hardware Prober" + depends on OF + depends on I2C + select OF_DYNAMIC + default OF + help + This option enables the device tree hardware prober for ChromeOS + devices. The driver will probe the correct component variant in + devices that have multiple drop-in options for one component. + config CROS_EC tristate "ChromeOS Embedded Controller" select CROS_EC_PROTO diff --git a/drivers/platform/chrome/Makefile b/drivers/platform/chrome/Makefile index 2dcc6ccc2302..fb8335458a22 100644 --- a/drivers/platform/chrome/Makefile +++ b/drivers/platform/chrome/Makefile @@ -6,6 +6,7 @@ CFLAGS_cros_ec_sensorhub_ring.o:= -I$(src) obj-$(CONFIG_CHROMEOS_ACPI) += chromeos_acpi.o obj-$(CONFIG_CHROMEOS_LAPTOP) += chromeos_laptop.o +obj-$(CONFIG_CHROMEOS_OF_HW_PROBER) += chromeos_of_hw_prober.o obj-$(CONFIG_CHROMEOS_PRIVACY_SCREEN) += chromeos_privacy_screen.o obj-$(CONFIG_CHROMEOS_PSTORE) += chromeos_pstore.o obj-$(CONFIG_CHROMEOS_TBMC) += chromeos_tbmc.o diff --git a/drivers/platform/chrome/chromeos_of_hw_prober.c b/drivers/platform/chrome/chromeos_of_hw_prober.c new file mode 100644 index 000000000000..0cb4676eeca2 --- /dev/null +++ b/drivers/platform/chrome/chromeos_of_hw_prober.c @@ -0,0 +1,140 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * ChromeOS Device Tree Hardware Prober + * + * Copyright (c) 2024 Google LLC + */ + +#include <linux/array_size.h> +#include <linux/errno.h> +#include <linux/i2c-of-prober.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> + +#define DRV_NAME "chromeos_of_hw_prober" + +/** + * struct hw_prober_entry - Holds an entry for the hardware prober + * + * @compatible: compatible string to match against the machine + * @prober: prober function to call when machine matches + * @data: extra data for the prober function + */ +struct hw_prober_entry { + const char *compatible; + int (*prober)(struct device *dev, const void *data); + const void *data; +}; + +struct chromeos_i2c_probe_data { + const struct i2c_of_probe_cfg *cfg; + const struct i2c_of_probe_simple_opts *opts; +}; + +static int chromeos_i2c_component_prober(struct device *dev, const void *_data) +{ + const struct chromeos_i2c_probe_data *data = _data; + struct i2c_of_probe_simple_ctx ctx = { + .opts = data->opts + }; + + return i2c_of_probe_component(dev, data->cfg, &ctx); +} + +static const struct chromeos_i2c_probe_data chromeos_i2c_probe_dumb_touchscreen = { + .cfg = &(const struct i2c_of_probe_cfg) { + .type = "touchscreen" + } +}; + +static const struct i2c_of_probe_cfg chromeos_i2c_probe_simple_trackpad_cfg = { + .ops = &i2c_of_probe_simple_ops, + .type = "trackpad" +}; + +static const struct chromeos_i2c_probe_data chromeos_i2c_probe_hana_trackpad = { + .cfg = &chromeos_i2c_probe_simple_trackpad_cfg, + .opts = &(const struct i2c_of_probe_simple_opts) { + .res_node_compatible = "elan,ekth3000", + .supply_name = "vcc", + /* + * ELAN trackpad needs 2 ms for H/W init and 100 ms for F/W init. + * Synaptics trackpad needs 100 ms. + * However, the regulator is set to "always-on", presumably to + * avoid this delay. The ELAN driver is also missing delays. + */ + .post_power_on_delay_ms = 0, + } +}; + +static const struct hw_prober_entry hw_prober_platforms[] = { + { .compatible = "google,hana", .prober = chromeos_i2c_component_prober, .data = &chromeos_i2c_probe_dumb_touchscreen }, + { .compatible = "google,hana", .prober = chromeos_i2c_component_prober, .data = &chromeos_i2c_probe_hana_trackpad }, +}; + +static int chromeos_of_hw_prober_probe(struct platform_device *pdev) +{ + for (size_t i = 0; i < ARRAY_SIZE(hw_prober_platforms); i++) { + int ret; + + if (!of_machine_is_compatible(hw_prober_platforms[i].compatible)) + continue; + + ret = hw_prober_platforms[i].prober(&pdev->dev, hw_prober_platforms[i].data); + /* Ignore unrecoverable errors and keep going through other probers */ + if (ret == -EPROBE_DEFER) + return ret; + } + + return 0; +} + +static struct platform_driver chromeos_of_hw_prober_driver = { + .probe = chromeos_of_hw_prober_probe, + .driver = { + .name = DRV_NAME, + }, +}; + +static struct platform_device *chromeos_of_hw_prober_pdev; + +static int chromeos_of_hw_prober_driver_init(void) +{ + size_t i; + int ret; + + for (i = 0; i < ARRAY_SIZE(hw_prober_platforms); i++) + if (of_machine_is_compatible(hw_prober_platforms[i].compatible)) + break; + if (i == ARRAY_SIZE(hw_prober_platforms)) + return -ENODEV; + + ret = platform_driver_register(&chromeos_of_hw_prober_driver); + if (ret) + return ret; + + chromeos_of_hw_prober_pdev = + platform_device_register_simple(DRV_NAME, PLATFORM_DEVID_NONE, NULL, 0); + if (IS_ERR(chromeos_of_hw_prober_pdev)) + goto err; + + return 0; + +err: + platform_driver_unregister(&chromeos_of_hw_prober_driver); + + return PTR_ERR(chromeos_of_hw_prober_pdev); +} +module_init(chromeos_of_hw_prober_driver_init); + +static void chromeos_of_hw_prober_driver_exit(void) +{ + platform_device_unregister(chromeos_of_hw_prober_pdev); + platform_driver_unregister(&chromeos_of_hw_prober_driver); +} +module_exit(chromeos_of_hw_prober_driver_exit); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("ChromeOS device tree hardware prober"); +MODULE_IMPORT_NS(I2C_OF_PROBER);