Message ID | 20220216225304.53911-4-djrscally@gmail.com (mailing list archive) |
---|---|
State | Changes Requested, archived |
Headers | show |
Series | Add multiple-consumer support to int3472-tps68470 driver | expand |
Hi Daniel,
I love your patch! Perhaps something to improve:
[auto build test WARNING on rafael-pm/linux-next]
[also build test WARNING on clk/clk-next linus/master v5.17-rc4 next-20220216]
[cannot apply to platform-drivers-x86/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Daniel-Scally/Add-multiple-consumer-support-to-int3472-tps68470-driver/20220217-065452
base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
config: x86_64-randconfig-m001 (https://download.01.org/0day-ci/archive/20220217/202202171110.7EOaTUJH-lkp@intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
smatch warnings:
drivers/platform/x86/intel/int3472/tps68470.c:155 skl_int3472_tps68470_probe() warn: unsigned 'n_consumers' is never less than zero.
vim +/n_consumers +155 drivers/platform/x86/intel/int3472/tps68470.c
142
143 static int skl_int3472_tps68470_probe(struct i2c_client *client)
144 {
145 struct acpi_device *adev = ACPI_COMPANION(&client->dev);
146 const struct int3472_tps68470_board_data *board_data;
147 struct tps68470_clk_platform_data *clk_pdata;
148 unsigned int n_consumers;
149 struct mfd_cell *cells;
150 struct regmap *regmap;
151 int device_type;
152 int ret;
153
154 n_consumers = skl_int3472_fill_clk_pdata(&client->dev, &clk_pdata);
> 155 if (n_consumers < 0)
156 return n_consumers;
157
158 regmap = devm_regmap_init_i2c(client, &tps68470_regmap_config);
159 if (IS_ERR(regmap)) {
160 dev_err(&client->dev, "Failed to create regmap: %ld\n", PTR_ERR(regmap));
161 return PTR_ERR(regmap);
162 }
163
164 i2c_set_clientdata(client, regmap);
165
166 ret = tps68470_chip_init(&client->dev, regmap);
167 if (ret < 0) {
168 dev_err(&client->dev, "TPS68470 init error %d\n", ret);
169 return ret;
170 }
171
172 device_type = skl_int3472_tps68470_calc_type(adev);
173 switch (device_type) {
174 case DESIGNED_FOR_WINDOWS:
175 board_data = int3472_tps68470_get_board_data(dev_name(&client->dev));
176 if (!board_data)
177 return dev_err_probe(&client->dev, -ENODEV, "No board-data found for this model\n");
178
179 cells = kcalloc(TPS68470_WIN_MFD_CELL_COUNT, sizeof(*cells), GFP_KERNEL);
180 if (!cells)
181 return -ENOMEM;
182
183 /*
184 * The order of the cells matters here! The clk must be first
185 * because the regulator depends on it. The gpios must be last,
186 * acpi_gpiochip_add() calls acpi_dev_clear_dependencies() and
187 * the clk + regulators must be ready when this happens.
188 */
189 cells[0].name = "tps68470-clk";
190 cells[0].platform_data = clk_pdata;
191 cells[0].pdata_size = struct_size(clk_pdata, consumers, n_consumers);
192 cells[1].name = "tps68470-regulator";
193 cells[1].platform_data = (void *)board_data->tps68470_regulator_pdata;
194 cells[1].pdata_size = sizeof(struct tps68470_regulator_platform_data);
195 cells[2].name = "tps68470-gpio";
196
197 gpiod_add_lookup_table(board_data->tps68470_gpio_lookup_table);
198
199 ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_NONE,
200 cells, TPS68470_WIN_MFD_CELL_COUNT,
201 NULL, 0, NULL);
202 kfree(cells);
203
204 if (ret)
205 gpiod_remove_lookup_table(board_data->tps68470_gpio_lookup_table);
206
207 break;
208 case DESIGNED_FOR_CHROMEOS:
209 ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_NONE,
210 tps68470_cros, ARRAY_SIZE(tps68470_cros),
211 NULL, 0, NULL);
212 break;
213 default:
214 dev_err(&client->dev, "Failed to add MFD devices\n");
215 return device_type;
216 }
217
218 /*
219 * No acpi_dev_clear_dependencies() here, since the acpi_gpiochip_add()
220 * for the GPIO cell already does this.
221 */
222
223 return ret;
224 }
225
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Hi, On 2/16/22 23:53, Daniel Scally wrote: > At present, the int3472-tps68470 only supports a single clock consumer when > passing platform data to the clock driver. In some devices multiple > sensors depend on the clock provided by a single TPS68470 and so all > need to be able to acquire the clock. Support passing multiple > consumers as platform data. > > Signed-off-by: Daniel Scally <djrscally@gmail.com> Thanks, patch looks good to me: Reviewed-by: Hans de Goede <hdegoede@redhat.com> Michael, I plan to merge this entire series through the platform-drivers-x86 git tree, may I have your ack for merging the clk bits from this ? Regards, Hans > --- > drivers/clk/clk-tps68470.c | 13 ++-- > drivers/platform/x86/intel/int3472/tps68470.c | 59 ++++++++++++++++--- > include/linux/platform_data/tps68470.h | 7 ++- > 3 files changed, 67 insertions(+), 12 deletions(-) > > diff --git a/drivers/clk/clk-tps68470.c b/drivers/clk/clk-tps68470.c > index e5fbefd6ac2d..38f44b5b9b1b 100644 > --- a/drivers/clk/clk-tps68470.c > +++ b/drivers/clk/clk-tps68470.c > @@ -200,7 +200,9 @@ static int tps68470_clk_probe(struct platform_device *pdev) > .flags = CLK_SET_RATE_GATE, > }; > struct tps68470_clkdata *tps68470_clkdata; > + struct tps68470_clk_consumer *consumer; > int ret; > + int i; > > tps68470_clkdata = devm_kzalloc(&pdev->dev, sizeof(*tps68470_clkdata), > GFP_KERNEL); > @@ -223,10 +225,13 @@ static int tps68470_clk_probe(struct platform_device *pdev) > return ret; > > if (pdata) { > - ret = devm_clk_hw_register_clkdev(&pdev->dev, > - &tps68470_clkdata->clkout_hw, > - pdata->consumer_con_id, > - pdata->consumer_dev_name); > + for (i = 0; i < pdata->n_consumers; i++) { > + consumer = &pdata->consumers[i]; > + ret = devm_clk_hw_register_clkdev(&pdev->dev, > + &tps68470_clkdata->clkout_hw, > + consumer->consumer_con_id, > + consumer->consumer_dev_name); > + } > } > > return ret; > diff --git a/drivers/platform/x86/intel/int3472/tps68470.c b/drivers/platform/x86/intel/int3472/tps68470.c > index 22f61b47f9e5..b535564712bb 100644 > --- a/drivers/platform/x86/intel/int3472/tps68470.c > +++ b/drivers/platform/x86/intel/int3472/tps68470.c > @@ -1,6 +1,7 @@ > // SPDX-License-Identifier: GPL-2.0 > /* Author: Dan Scally <djrscally@gmail.com> */ > > +#include <linux/acpi.h> > #include <linux/i2c.h> > #include <linux/kernel.h> > #include <linux/mfd/core.h> > @@ -95,20 +96,64 @@ static int skl_int3472_tps68470_calc_type(struct acpi_device *adev) > return DESIGNED_FOR_WINDOWS; > } > > +/* > + * Return the size of the flexible array member, because we'll need that later > + * on to pass .pdata_size to cells. > + */ > +static int > +skl_int3472_fill_clk_pdata(struct device *dev, struct tps68470_clk_platform_data **clk_pdata) > +{ > + struct acpi_device *adev = ACPI_COMPANION(dev); > + struct acpi_device *consumer; > + unsigned int n_consumers = 0; > + const char *sensor_name; > + unsigned int i = 0; > + > + for_each_acpi_consumer_dev(adev, consumer) > + n_consumers++; > + > + if (!n_consumers) { > + dev_err(dev, "INT3472 seems to have no dependents\n"); > + return -ENODEV; > + } > + > + *clk_pdata = devm_kzalloc(dev, struct_size(*clk_pdata, consumers, n_consumers), > + GFP_KERNEL); > + if (!*clk_pdata) > + return -ENOMEM; > + > + (*clk_pdata)->n_consumers = n_consumers; > + i = 0; > + > + for_each_acpi_consumer_dev(adev, consumer) { > + sensor_name = devm_kasprintf(dev, GFP_KERNEL, I2C_DEV_NAME_FORMAT, > + acpi_dev_name(consumer)); > + if (!sensor_name) > + return -ENOMEM; > + > + (*clk_pdata)->consumers[i].consumer_dev_name = sensor_name; > + i++; > + } > + > + acpi_dev_put(consumer); > + > + return n_consumers; > +} > + > static int skl_int3472_tps68470_probe(struct i2c_client *client) > { > struct acpi_device *adev = ACPI_COMPANION(&client->dev); > const struct int3472_tps68470_board_data *board_data; > - struct tps68470_clk_platform_data clk_pdata = {}; > + struct tps68470_clk_platform_data *clk_pdata; > + unsigned int n_consumers; > struct mfd_cell *cells; > struct regmap *regmap; > int device_type; > int ret; > > - ret = skl_int3472_get_sensor_adev_and_name(&client->dev, NULL, > - &clk_pdata.consumer_dev_name); > - if (ret) > - return ret; > + n_consumers = skl_int3472_fill_clk_pdata(&client->dev, &clk_pdata); > + if (n_consumers < 0) > + return n_consumers; > > regmap = devm_regmap_init_i2c(client, &tps68470_regmap_config); > if (IS_ERR(regmap)) { > @@ -142,8 +187,8 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client) > * the clk + regulators must be ready when this happens. > */ > cells[0].name = "tps68470-clk"; > - cells[0].platform_data = &clk_pdata; > - cells[0].pdata_size = sizeof(clk_pdata); > + cells[0].platform_data = clk_pdata; > + cells[0].pdata_size = struct_size(clk_pdata, consumers, n_consumers); > cells[1].name = "tps68470-regulator"; > cells[1].platform_data = (void *)board_data->tps68470_regulator_pdata; > cells[1].pdata_size = sizeof(struct tps68470_regulator_platform_data); > diff --git a/include/linux/platform_data/tps68470.h b/include/linux/platform_data/tps68470.h > index 126d082c3f2e..e605a2cab07f 100644 > --- a/include/linux/platform_data/tps68470.h > +++ b/include/linux/platform_data/tps68470.h > @@ -27,9 +27,14 @@ struct tps68470_regulator_platform_data { > const struct regulator_init_data *reg_init_data[TPS68470_NUM_REGULATORS]; > }; > > -struct tps68470_clk_platform_data { > +struct tps68470_clk_consumer { > const char *consumer_dev_name; > const char *consumer_con_id; > }; > > +struct tps68470_clk_platform_data { > + unsigned int n_consumers; > + struct tps68470_clk_consumer consumers[]; > +}; > + > #endif
Hi, On 2/17/22 04:22, kernel test robot wrote: > Hi Daniel, > > I love your patch! Perhaps something to improve: > > [auto build test WARNING on rafael-pm/linux-next] > [also build test WARNING on clk/clk-next linus/master v5.17-rc4 next-20220216] > [cannot apply to platform-drivers-x86/for-next] > [If your patch is applied to the wrong git tree, kindly drop us a note. > And when submitting patch, we suggest to use '--base' as documented in > https://git-scm.com/docs/git-format-patch] > > url: https://github.com/0day-ci/linux/commits/Daniel-Scally/Add-multiple-consumer-support-to-int3472-tps68470-driver/20220217-065452 > base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next > config: x86_64-randconfig-m001 (https://download.01.org/0day-ci/archive/20220217/202202171110.7EOaTUJH-lkp@intel.com/config) > compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 > > If you fix the issue, kindly add following tag as appropriate > Reported-by: kernel test robot <lkp@intel.com> > > smatch warnings: > drivers/platform/x86/intel/int3472/tps68470.c:155 skl_int3472_tps68470_probe() warn: unsigned 'n_consumers' is never less than zero. Right this needs to be an int, not an unsigned int. Daniel, please fix this for v2. Regards, Hans > > vim +/n_consumers +155 drivers/platform/x86/intel/int3472/tps68470.c > > 142 > 143 static int skl_int3472_tps68470_probe(struct i2c_client *client) > 144 { > 145 struct acpi_device *adev = ACPI_COMPANION(&client->dev); > 146 const struct int3472_tps68470_board_data *board_data; > 147 struct tps68470_clk_platform_data *clk_pdata; > 148 unsigned int n_consumers; > 149 struct mfd_cell *cells; > 150 struct regmap *regmap; > 151 int device_type; > 152 int ret; > 153 > 154 n_consumers = skl_int3472_fill_clk_pdata(&client->dev, &clk_pdata); > > 155 if (n_consumers < 0) > 156 return n_consumers; > 157 > 158 regmap = devm_regmap_init_i2c(client, &tps68470_regmap_config); > 159 if (IS_ERR(regmap)) { > 160 dev_err(&client->dev, "Failed to create regmap: %ld\n", PTR_ERR(regmap)); > 161 return PTR_ERR(regmap); > 162 } > 163 > 164 i2c_set_clientdata(client, regmap); > 165 > 166 ret = tps68470_chip_init(&client->dev, regmap); > 167 if (ret < 0) { > 168 dev_err(&client->dev, "TPS68470 init error %d\n", ret); > 169 return ret; > 170 } > 171 > 172 device_type = skl_int3472_tps68470_calc_type(adev); > 173 switch (device_type) { > 174 case DESIGNED_FOR_WINDOWS: > 175 board_data = int3472_tps68470_get_board_data(dev_name(&client->dev)); > 176 if (!board_data) > 177 return dev_err_probe(&client->dev, -ENODEV, "No board-data found for this model\n"); > 178 > 179 cells = kcalloc(TPS68470_WIN_MFD_CELL_COUNT, sizeof(*cells), GFP_KERNEL); > 180 if (!cells) > 181 return -ENOMEM; > 182 > 183 /* > 184 * The order of the cells matters here! The clk must be first > 185 * because the regulator depends on it. The gpios must be last, > 186 * acpi_gpiochip_add() calls acpi_dev_clear_dependencies() and > 187 * the clk + regulators must be ready when this happens. > 188 */ > 189 cells[0].name = "tps68470-clk"; > 190 cells[0].platform_data = clk_pdata; > 191 cells[0].pdata_size = struct_size(clk_pdata, consumers, n_consumers); > 192 cells[1].name = "tps68470-regulator"; > 193 cells[1].platform_data = (void *)board_data->tps68470_regulator_pdata; > 194 cells[1].pdata_size = sizeof(struct tps68470_regulator_platform_data); > 195 cells[2].name = "tps68470-gpio"; > 196 > 197 gpiod_add_lookup_table(board_data->tps68470_gpio_lookup_table); > 198 > 199 ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_NONE, > 200 cells, TPS68470_WIN_MFD_CELL_COUNT, > 201 NULL, 0, NULL); > 202 kfree(cells); > 203 > 204 if (ret) > 205 gpiod_remove_lookup_table(board_data->tps68470_gpio_lookup_table); > 206 > 207 break; > 208 case DESIGNED_FOR_CHROMEOS: > 209 ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_NONE, > 210 tps68470_cros, ARRAY_SIZE(tps68470_cros), > 211 NULL, 0, NULL); > 212 break; > 213 default: > 214 dev_err(&client->dev, "Failed to add MFD devices\n"); > 215 return device_type; > 216 } > 217 > 218 /* > 219 * No acpi_dev_clear_dependencies() here, since the acpi_gpiochip_add() > 220 * for the GPIO cell already does this. > 221 */ > 222 > 223 return ret; > 224 } > 225 > > --- > 0-DAY CI Kernel Test Service, Intel Corporation > https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org >
Hi Hans On 22/02/2022 14:44, Hans de Goede wrote: > Hi, > > On 2/17/22 04:22, kernel test robot wrote: >> Hi Daniel, >> >> I love your patch! Perhaps something to improve: >> >> [auto build test WARNING on rafael-pm/linux-next] >> [also build test WARNING on clk/clk-next linus/master v5.17-rc4 next-20220216] >> [cannot apply to platform-drivers-x86/for-next] >> [If your patch is applied to the wrong git tree, kindly drop us a note. >> And when submitting patch, we suggest to use '--base' as documented in >> https://git-scm.com/docs/git-format-patch] >> >> url: https://github.com/0day-ci/linux/commits/Daniel-Scally/Add-multiple-consumer-support-to-int3472-tps68470-driver/20220217-065452 >> base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next >> config: x86_64-randconfig-m001 (https://download.01.org/0day-ci/archive/20220217/202202171110.7EOaTUJH-lkp@intel.com/config) >> compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 >> >> If you fix the issue, kindly add following tag as appropriate >> Reported-by: kernel test robot <lkp@intel.com> >> >> smatch warnings: >> drivers/platform/x86/intel/int3472/tps68470.c:155 skl_int3472_tps68470_probe() warn: unsigned 'n_consumers' is never less than zero. > Right this needs to be an int, not an unsigned int. Daniel, please fix this for v2. Will do! And thanks for your comments / tags on the rest of the series; I'll post a new version some time this week. Dan > > Regards, > > Hans > > > >> vim +/n_consumers +155 drivers/platform/x86/intel/int3472/tps68470.c >> >> 142 >> 143 static int skl_int3472_tps68470_probe(struct i2c_client *client) >> 144 { >> 145 struct acpi_device *adev = ACPI_COMPANION(&client->dev); >> 146 const struct int3472_tps68470_board_data *board_data; >> 147 struct tps68470_clk_platform_data *clk_pdata; >> 148 unsigned int n_consumers; >> 149 struct mfd_cell *cells; >> 150 struct regmap *regmap; >> 151 int device_type; >> 152 int ret; >> 153 >> 154 n_consumers = skl_int3472_fill_clk_pdata(&client->dev, &clk_pdata); >> > 155 if (n_consumers < 0) >> 156 return n_consumers; >> 157 >> 158 regmap = devm_regmap_init_i2c(client, &tps68470_regmap_config); >> 159 if (IS_ERR(regmap)) { >> 160 dev_err(&client->dev, "Failed to create regmap: %ld\n", PTR_ERR(regmap)); >> 161 return PTR_ERR(regmap); >> 162 } >> 163 >> 164 i2c_set_clientdata(client, regmap); >> 165 >> 166 ret = tps68470_chip_init(&client->dev, regmap); >> 167 if (ret < 0) { >> 168 dev_err(&client->dev, "TPS68470 init error %d\n", ret); >> 169 return ret; >> 170 } >> 171 >> 172 device_type = skl_int3472_tps68470_calc_type(adev); >> 173 switch (device_type) { >> 174 case DESIGNED_FOR_WINDOWS: >> 175 board_data = int3472_tps68470_get_board_data(dev_name(&client->dev)); >> 176 if (!board_data) >> 177 return dev_err_probe(&client->dev, -ENODEV, "No board-data found for this model\n"); >> 178 >> 179 cells = kcalloc(TPS68470_WIN_MFD_CELL_COUNT, sizeof(*cells), GFP_KERNEL); >> 180 if (!cells) >> 181 return -ENOMEM; >> 182 >> 183 /* >> 184 * The order of the cells matters here! The clk must be first >> 185 * because the regulator depends on it. The gpios must be last, >> 186 * acpi_gpiochip_add() calls acpi_dev_clear_dependencies() and >> 187 * the clk + regulators must be ready when this happens. >> 188 */ >> 189 cells[0].name = "tps68470-clk"; >> 190 cells[0].platform_data = clk_pdata; >> 191 cells[0].pdata_size = struct_size(clk_pdata, consumers, n_consumers); >> 192 cells[1].name = "tps68470-regulator"; >> 193 cells[1].platform_data = (void *)board_data->tps68470_regulator_pdata; >> 194 cells[1].pdata_size = sizeof(struct tps68470_regulator_platform_data); >> 195 cells[2].name = "tps68470-gpio"; >> 196 >> 197 gpiod_add_lookup_table(board_data->tps68470_gpio_lookup_table); >> 198 >> 199 ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_NONE, >> 200 cells, TPS68470_WIN_MFD_CELL_COUNT, >> 201 NULL, 0, NULL); >> 202 kfree(cells); >> 203 >> 204 if (ret) >> 205 gpiod_remove_lookup_table(board_data->tps68470_gpio_lookup_table); >> 206 >> 207 break; >> 208 case DESIGNED_FOR_CHROMEOS: >> 209 ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_NONE, >> 210 tps68470_cros, ARRAY_SIZE(tps68470_cros), >> 211 NULL, 0, NULL); >> 212 break; >> 213 default: >> 214 dev_err(&client->dev, "Failed to add MFD devices\n"); >> 215 return device_type; >> 216 } >> 217 >> 218 /* >> 219 * No acpi_dev_clear_dependencies() here, since the acpi_gpiochip_add() >> 220 * for the GPIO cell already does this. >> 221 */ >> 222 >> 223 return ret; >> 224 } >> 225 >> >> --- >> 0-DAY CI Kernel Test Service, Intel Corporation >> https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org >>
Quoting Hans de Goede (2022-02-21 01:59:09) > Hi, > > On 2/16/22 23:53, Daniel Scally wrote: > > At present, the int3472-tps68470 only supports a single clock consumer when > > passing platform data to the clock driver. In some devices multiple > > sensors depend on the clock provided by a single TPS68470 and so all > > need to be able to acquire the clock. Support passing multiple > > consumers as platform data. > > > > Signed-off-by: Daniel Scally <djrscally@gmail.com> > > Thanks, patch looks good to me: > > Reviewed-by: Hans de Goede <hdegoede@redhat.com> > > Michael, I plan to merge this entire series through the platform-drivers-x86 git > tree, may I have your ack for merging the clk bits from this ? > With the type fix Reviewed-by: Stephen Boyd <sboyd@kernel.org> Acked-by: Stephen Boyd <sboyd@kernel.org>
Hi Stephen, On 2/25/22 01:49, Stephen Boyd wrote: > Quoting Hans de Goede (2022-02-21 01:59:09) >> Hi, >> >> On 2/16/22 23:53, Daniel Scally wrote: >>> At present, the int3472-tps68470 only supports a single clock consumer when >>> passing platform data to the clock driver. In some devices multiple >>> sensors depend on the clock provided by a single TPS68470 and so all >>> need to be able to acquire the clock. Support passing multiple >>> consumers as platform data. >>> >>> Signed-off-by: Daniel Scally <djrscally@gmail.com> >> >> Thanks, patch looks good to me: >> >> Reviewed-by: Hans de Goede <hdegoede@redhat.com> >> >> Michael, I plan to merge this entire series through the platform-drivers-x86 git >> tree, may I have your ack for merging the clk bits from this ? >> > > With the type fix > > Reviewed-by: Stephen Boyd <sboyd@kernel.org> > Acked-by: Stephen Boyd <sboyd@kernel.org> Thanks, and sorry for not addressing you, I should have seen that there are 2 clk subsys maintainers (and I know from experience that you are the most active maintainer recently). Regards, Hans
diff --git a/drivers/clk/clk-tps68470.c b/drivers/clk/clk-tps68470.c index e5fbefd6ac2d..38f44b5b9b1b 100644 --- a/drivers/clk/clk-tps68470.c +++ b/drivers/clk/clk-tps68470.c @@ -200,7 +200,9 @@ static int tps68470_clk_probe(struct platform_device *pdev) .flags = CLK_SET_RATE_GATE, }; struct tps68470_clkdata *tps68470_clkdata; + struct tps68470_clk_consumer *consumer; int ret; + int i; tps68470_clkdata = devm_kzalloc(&pdev->dev, sizeof(*tps68470_clkdata), GFP_KERNEL); @@ -223,10 +225,13 @@ static int tps68470_clk_probe(struct platform_device *pdev) return ret; if (pdata) { - ret = devm_clk_hw_register_clkdev(&pdev->dev, - &tps68470_clkdata->clkout_hw, - pdata->consumer_con_id, - pdata->consumer_dev_name); + for (i = 0; i < pdata->n_consumers; i++) { + consumer = &pdata->consumers[i]; + ret = devm_clk_hw_register_clkdev(&pdev->dev, + &tps68470_clkdata->clkout_hw, + consumer->consumer_con_id, + consumer->consumer_dev_name); + } } return ret; diff --git a/drivers/platform/x86/intel/int3472/tps68470.c b/drivers/platform/x86/intel/int3472/tps68470.c index 22f61b47f9e5..b535564712bb 100644 --- a/drivers/platform/x86/intel/int3472/tps68470.c +++ b/drivers/platform/x86/intel/int3472/tps68470.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 /* Author: Dan Scally <djrscally@gmail.com> */ +#include <linux/acpi.h> #include <linux/i2c.h> #include <linux/kernel.h> #include <linux/mfd/core.h> @@ -95,20 +96,64 @@ static int skl_int3472_tps68470_calc_type(struct acpi_device *adev) return DESIGNED_FOR_WINDOWS; } +/* + * Return the size of the flexible array member, because we'll need that later + * on to pass .pdata_size to cells. + */ +static int +skl_int3472_fill_clk_pdata(struct device *dev, struct tps68470_clk_platform_data **clk_pdata) +{ + struct acpi_device *adev = ACPI_COMPANION(dev); + struct acpi_device *consumer; + unsigned int n_consumers = 0; + const char *sensor_name; + unsigned int i = 0; + + for_each_acpi_consumer_dev(adev, consumer) + n_consumers++; + + if (!n_consumers) { + dev_err(dev, "INT3472 seems to have no dependents\n"); + return -ENODEV; + } + + *clk_pdata = devm_kzalloc(dev, struct_size(*clk_pdata, consumers, n_consumers), + GFP_KERNEL); + if (!*clk_pdata) + return -ENOMEM; + + (*clk_pdata)->n_consumers = n_consumers; + i = 0; + + for_each_acpi_consumer_dev(adev, consumer) { + sensor_name = devm_kasprintf(dev, GFP_KERNEL, I2C_DEV_NAME_FORMAT, + acpi_dev_name(consumer)); + if (!sensor_name) + return -ENOMEM; + + (*clk_pdata)->consumers[i].consumer_dev_name = sensor_name; + i++; + } + + acpi_dev_put(consumer); + + return n_consumers; +} + static int skl_int3472_tps68470_probe(struct i2c_client *client) { struct acpi_device *adev = ACPI_COMPANION(&client->dev); const struct int3472_tps68470_board_data *board_data; - struct tps68470_clk_platform_data clk_pdata = {}; + struct tps68470_clk_platform_data *clk_pdata; + unsigned int n_consumers; struct mfd_cell *cells; struct regmap *regmap; int device_type; int ret; - ret = skl_int3472_get_sensor_adev_and_name(&client->dev, NULL, - &clk_pdata.consumer_dev_name); - if (ret) - return ret; + n_consumers = skl_int3472_fill_clk_pdata(&client->dev, &clk_pdata); + if (n_consumers < 0) + return n_consumers; regmap = devm_regmap_init_i2c(client, &tps68470_regmap_config); if (IS_ERR(regmap)) { @@ -142,8 +187,8 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client) * the clk + regulators must be ready when this happens. */ cells[0].name = "tps68470-clk"; - cells[0].platform_data = &clk_pdata; - cells[0].pdata_size = sizeof(clk_pdata); + cells[0].platform_data = clk_pdata; + cells[0].pdata_size = struct_size(clk_pdata, consumers, n_consumers); cells[1].name = "tps68470-regulator"; cells[1].platform_data = (void *)board_data->tps68470_regulator_pdata; cells[1].pdata_size = sizeof(struct tps68470_regulator_platform_data); diff --git a/include/linux/platform_data/tps68470.h b/include/linux/platform_data/tps68470.h index 126d082c3f2e..e605a2cab07f 100644 --- a/include/linux/platform_data/tps68470.h +++ b/include/linux/platform_data/tps68470.h @@ -27,9 +27,14 @@ struct tps68470_regulator_platform_data { const struct regulator_init_data *reg_init_data[TPS68470_NUM_REGULATORS]; }; -struct tps68470_clk_platform_data { +struct tps68470_clk_consumer { const char *consumer_dev_name; const char *consumer_con_id; }; +struct tps68470_clk_platform_data { + unsigned int n_consumers; + struct tps68470_clk_consumer consumers[]; +}; + #endif
At present, the int3472-tps68470 only supports a single clock consumer when passing platform data to the clock driver. In some devices multiple sensors depend on the clock provided by a single TPS68470 and so all need to be able to acquire the clock. Support passing multiple consumers as platform data. Signed-off-by: Daniel Scally <djrscally@gmail.com> --- drivers/clk/clk-tps68470.c | 13 ++-- drivers/platform/x86/intel/int3472/tps68470.c | 59 ++++++++++++++++--- include/linux/platform_data/tps68470.h | 7 ++- 3 files changed, 67 insertions(+), 12 deletions(-)