|
1 | 1 | // SPDX-License-Identifier: GPL-2.0
|
2 | 2 | /* Author: Dan Scally <[email protected]> */
|
3 | 3 |
|
| 4 | +#include <linux/acpi.h> |
4 | 5 | #include <linux/i2c.h>
|
5 | 6 | #include <linux/kernel.h>
|
6 | 7 | #include <linux/mfd/core.h>
|
@@ -95,20 +96,64 @@ static int skl_int3472_tps68470_calc_type(struct acpi_device *adev)
|
95 | 96 | return DESIGNED_FOR_WINDOWS;
|
96 | 97 | }
|
97 | 98 |
|
| 99 | +/* |
| 100 | + * Return the size of the flexible array member, because we'll need that later |
| 101 | + * on to pass .pdata_size to cells. |
| 102 | + */ |
| 103 | +static int |
| 104 | +skl_int3472_fill_clk_pdata(struct device *dev, struct tps68470_clk_platform_data **clk_pdata) |
| 105 | +{ |
| 106 | + struct acpi_device *adev = ACPI_COMPANION(dev); |
| 107 | + struct acpi_device *consumer; |
| 108 | + unsigned int n_consumers = 0; |
| 109 | + const char *sensor_name; |
| 110 | + unsigned int i = 0; |
| 111 | + |
| 112 | + for_each_acpi_consumer_dev(adev, consumer) |
| 113 | + n_consumers++; |
| 114 | + |
| 115 | + if (!n_consumers) { |
| 116 | + dev_err(dev, "INT3472 seems to have no dependents\n"); |
| 117 | + return -ENODEV; |
| 118 | + } |
| 119 | + |
| 120 | + *clk_pdata = devm_kzalloc(dev, struct_size(*clk_pdata, consumers, n_consumers), |
| 121 | + GFP_KERNEL); |
| 122 | + if (!*clk_pdata) |
| 123 | + return -ENOMEM; |
| 124 | + |
| 125 | + (*clk_pdata)->n_consumers = n_consumers; |
| 126 | + i = 0; |
| 127 | + |
| 128 | + for_each_acpi_consumer_dev(adev, consumer) { |
| 129 | + sensor_name = devm_kasprintf(dev, GFP_KERNEL, I2C_DEV_NAME_FORMAT, |
| 130 | + acpi_dev_name(consumer)); |
| 131 | + if (!sensor_name) |
| 132 | + return -ENOMEM; |
| 133 | + |
| 134 | + (*clk_pdata)->consumers[i].consumer_dev_name = sensor_name; |
| 135 | + i++; |
| 136 | + } |
| 137 | + |
| 138 | + acpi_dev_put(consumer); |
| 139 | + |
| 140 | + return n_consumers; |
| 141 | +} |
| 142 | + |
98 | 143 | static int skl_int3472_tps68470_probe(struct i2c_client *client)
|
99 | 144 | {
|
100 | 145 | struct acpi_device *adev = ACPI_COMPANION(&client->dev);
|
101 | 146 | const struct int3472_tps68470_board_data *board_data;
|
102 |
| - struct tps68470_clk_platform_data clk_pdata = {}; |
| 147 | + struct tps68470_clk_platform_data *clk_pdata; |
103 | 148 | struct mfd_cell *cells;
|
104 | 149 | struct regmap *regmap;
|
| 150 | + int n_consumers; |
105 | 151 | int device_type;
|
106 | 152 | int ret;
|
107 | 153 |
|
108 |
| - ret = skl_int3472_get_sensor_adev_and_name(&client->dev, NULL, |
109 |
| - &clk_pdata.consumer_dev_name); |
110 |
| - if (ret) |
111 |
| - return ret; |
| 154 | + n_consumers = skl_int3472_fill_clk_pdata(&client->dev, &clk_pdata); |
| 155 | + if (n_consumers < 0) |
| 156 | + return n_consumers; |
112 | 157 |
|
113 | 158 | regmap = devm_regmap_init_i2c(client, &tps68470_regmap_config);
|
114 | 159 | if (IS_ERR(regmap)) {
|
@@ -142,8 +187,8 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client)
|
142 | 187 | * the clk + regulators must be ready when this happens.
|
143 | 188 | */
|
144 | 189 | cells[0].name = "tps68470-clk";
|
145 |
| - cells[0].platform_data = &clk_pdata; |
146 |
| - cells[0].pdata_size = sizeof(clk_pdata); |
| 190 | + cells[0].platform_data = clk_pdata; |
| 191 | + cells[0].pdata_size = struct_size(clk_pdata, consumers, n_consumers); |
147 | 192 | cells[1].name = "tps68470-regulator";
|
148 | 193 | cells[1].platform_data = (void *)board_data->tps68470_regulator_pdata;
|
149 | 194 | cells[1].pdata_size = sizeof(struct tps68470_regulator_platform_data);
|
|
0 commit comments