Skip to content

Commit 4819033

Browse files
author
Bartosz Golaszewski
committed
Merge tag 'platform-drivers-x86-ib-int3472-v6.7' of https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86 into gpio/for-next
Immutable branch between pdx86 int3472 branch and GPIO due for the v6.7 merge window. platform-drivers-x86-ib-int3472-v6.7: v6.6-rc1 + platform-drivers-x86-int3472 for merging into the GPIO subsystem for v6.7.
2 parents 03a975c + 5ccf987 commit 4819033

File tree

4 files changed

+94
-94
lines changed

4 files changed

+94
-94
lines changed

drivers/platform/x86/intel/int3472/clk_and_regulator.c

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,8 @@ int skl_int3472_register_dsm_clock(struct int3472_discrete_device *int3472)
162162
}
163163

164164
int skl_int3472_register_gpio_clock(struct int3472_discrete_device *int3472,
165-
struct acpi_resource_gpio *agpio, u32 polarity)
165+
struct gpio_desc *gpio)
166166
{
167-
char *path = agpio->resource_source.string_ptr;
168167
struct clk_init_data init = {
169168
.ops = &skl_int3472_clock_ops,
170169
.flags = CLK_GET_RATE_NOCACHE,
@@ -174,26 +173,12 @@ int skl_int3472_register_gpio_clock(struct int3472_discrete_device *int3472,
174173
if (int3472->clock.cl)
175174
return -EBUSY;
176175

177-
int3472->clock.ena_gpio = acpi_get_and_request_gpiod(path, agpio->pin_table[0],
178-
"int3472,clk-enable");
179-
if (IS_ERR(int3472->clock.ena_gpio)) {
180-
ret = PTR_ERR(int3472->clock.ena_gpio);
181-
int3472->clock.ena_gpio = NULL;
182-
return dev_err_probe(int3472->dev, ret, "getting clk-enable GPIO\n");
183-
}
184-
185-
if (polarity == GPIO_ACTIVE_LOW)
186-
gpiod_toggle_active_low(int3472->clock.ena_gpio);
187-
188-
/* Ensure the pin is in output mode and non-active state */
189-
gpiod_direction_output(int3472->clock.ena_gpio, 0);
176+
int3472->clock.ena_gpio = gpio;
190177

191178
init.name = kasprintf(GFP_KERNEL, "%s-clk",
192179
acpi_dev_name(int3472->adev));
193-
if (!init.name) {
194-
ret = -ENOMEM;
195-
goto out_put_gpio;
196-
}
180+
if (!init.name)
181+
return -ENOMEM;
197182

198183
int3472->clock.frequency = skl_int3472_get_clk_frequency(int3472);
199184

@@ -219,8 +204,6 @@ int skl_int3472_register_gpio_clock(struct int3472_discrete_device *int3472,
219204
clk_unregister(int3472->clock.clk);
220205
out_free_init_name:
221206
kfree(init.name);
222-
out_put_gpio:
223-
gpiod_put(int3472->clock.ena_gpio);
224207

225208
return ret;
226209
}
@@ -232,7 +215,6 @@ void skl_int3472_unregister_clock(struct int3472_discrete_device *int3472)
232215

233216
clkdev_drop(int3472->clock.cl);
234217
clk_unregister(int3472->clock.clk);
235-
gpiod_put(int3472->clock.ena_gpio);
236218
}
237219

238220
/*
@@ -273,14 +255,13 @@ static const struct dmi_system_id skl_int3472_regulator_second_sensor[] = {
273255
};
274256

275257
int skl_int3472_register_regulator(struct int3472_discrete_device *int3472,
276-
struct acpi_resource_gpio *agpio)
258+
struct gpio_desc *gpio)
277259
{
278-
char *path = agpio->resource_source.string_ptr;
279260
struct regulator_init_data init_data = { };
280261
struct regulator_config cfg = { };
281262
const char *second_sensor = NULL;
282263
const struct dmi_system_id *id;
283-
int i, j, ret;
264+
int i, j;
284265

285266
id = dmi_first_match(skl_int3472_regulator_second_sensor);
286267
if (id)
@@ -314,16 +295,7 @@ int skl_int3472_register_regulator(struct int3472_discrete_device *int3472,
314295
int3472->regulator.supply_name,
315296
&int3472_gpio_regulator_ops);
316297

317-
int3472->regulator.gpio = acpi_get_and_request_gpiod(path, agpio->pin_table[0],
318-
"int3472,regulator");
319-
if (IS_ERR(int3472->regulator.gpio)) {
320-
ret = PTR_ERR(int3472->regulator.gpio);
321-
int3472->regulator.gpio = NULL;
322-
return dev_err_probe(int3472->dev, ret, "getting regulator GPIO\n");
323-
}
324-
325-
/* Ensure the pin is in output mode and non-active state */
326-
gpiod_direction_output(int3472->regulator.gpio, 0);
298+
int3472->regulator.gpio = gpio;
327299

328300
cfg.dev = &int3472->adev->dev;
329301
cfg.init_data = &init_data;
@@ -332,21 +304,11 @@ int skl_int3472_register_regulator(struct int3472_discrete_device *int3472,
332304
int3472->regulator.rdev = regulator_register(int3472->dev,
333305
&int3472->regulator.rdesc,
334306
&cfg);
335-
if (IS_ERR(int3472->regulator.rdev)) {
336-
ret = PTR_ERR(int3472->regulator.rdev);
337-
goto err_free_gpio;
338-
}
339307

340-
return 0;
341-
342-
err_free_gpio:
343-
gpiod_put(int3472->regulator.gpio);
344-
345-
return ret;
308+
return PTR_ERR_OR_ZERO(int3472->regulator.rdev);
346309
}
347310

348311
void skl_int3472_unregister_regulator(struct int3472_discrete_device *int3472)
349312
{
350313
regulator_unregister(int3472->regulator.rdev);
351-
gpiod_put(int3472->regulator.gpio);
352314
}

drivers/platform/x86/intel/int3472/common.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,15 @@ int skl_int3472_get_sensor_adev_and_name(struct device *dev,
117117
const char **name_ret);
118118

119119
int skl_int3472_register_gpio_clock(struct int3472_discrete_device *int3472,
120-
struct acpi_resource_gpio *agpio, u32 polarity);
120+
struct gpio_desc *gpio);
121121
int skl_int3472_register_dsm_clock(struct int3472_discrete_device *int3472);
122122
void skl_int3472_unregister_clock(struct int3472_discrete_device *int3472);
123123

124124
int skl_int3472_register_regulator(struct int3472_discrete_device *int3472,
125-
struct acpi_resource_gpio *agpio);
125+
struct gpio_desc *gpio);
126126
void skl_int3472_unregister_regulator(struct int3472_discrete_device *int3472);
127127

128-
int skl_int3472_register_pled(struct int3472_discrete_device *int3472,
129-
struct acpi_resource_gpio *agpio, u32 polarity);
128+
int skl_int3472_register_pled(struct int3472_discrete_device *int3472, struct gpio_desc *gpio);
130129
void skl_int3472_unregister_pled(struct int3472_discrete_device *int3472);
131130

132131
#endif

drivers/platform/x86/intel/int3472/discrete.c

Lines changed: 79 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,15 @@ static void skl_int3472_log_sensor_module_name(struct int3472_discrete_device *i
5252
}
5353
}
5454

55-
static int skl_int3472_map_gpio_to_sensor(struct int3472_discrete_device *int3472,
56-
struct acpi_resource_gpio *agpio,
57-
const char *func, u32 polarity)
55+
static int skl_int3472_fill_gpiod_lookup(struct gpiod_lookup *table_entry,
56+
struct acpi_resource_gpio *agpio,
57+
const char *func, u32 polarity)
5858
{
5959
char *path = agpio->resource_source.string_ptr;
60-
struct gpiod_lookup *table_entry;
6160
struct acpi_device *adev;
6261
acpi_handle handle;
6362
acpi_status status;
6463

65-
if (int3472->n_sensor_gpios >= INT3472_MAX_SENSOR_GPIOS) {
66-
dev_warn(int3472->dev, "Too many GPIOs mapped\n");
67-
return -EINVAL;
68-
}
69-
7064
status = acpi_get_handle(NULL, path, &handle);
7165
if (ACPI_FAILURE(status))
7266
return -EINVAL;
@@ -75,18 +69,62 @@ static int skl_int3472_map_gpio_to_sensor(struct int3472_discrete_device *int347
7569
if (!adev)
7670
return -ENODEV;
7771

78-
table_entry = &int3472->gpios.table[int3472->n_sensor_gpios];
7972
table_entry->key = acpi_dev_name(adev);
8073
table_entry->chip_hwnum = agpio->pin_table[0];
8174
table_entry->con_id = func;
8275
table_entry->idx = 0;
8376
table_entry->flags = polarity;
8477

78+
return 0;
79+
}
80+
81+
static int skl_int3472_map_gpio_to_sensor(struct int3472_discrete_device *int3472,
82+
struct acpi_resource_gpio *agpio,
83+
const char *func, u32 polarity)
84+
{
85+
int ret;
86+
87+
if (int3472->n_sensor_gpios >= INT3472_MAX_SENSOR_GPIOS) {
88+
dev_warn(int3472->dev, "Too many GPIOs mapped\n");
89+
return -EINVAL;
90+
}
91+
92+
ret = skl_int3472_fill_gpiod_lookup(&int3472->gpios.table[int3472->n_sensor_gpios],
93+
agpio, func, polarity);
94+
if (ret)
95+
return ret;
96+
8597
int3472->n_sensor_gpios++;
8698

8799
return 0;
88100
}
89101

102+
/* This should *really* only be used when there's no other way... */
103+
static struct gpio_desc *
104+
skl_int3472_gpiod_get_from_temp_lookup(struct int3472_discrete_device *int3472,
105+
struct acpi_resource_gpio *agpio,
106+
const char *func, u32 polarity)
107+
{
108+
struct gpio_desc *desc;
109+
int ret;
110+
111+
struct gpiod_lookup_table *lookup __free(kfree) =
112+
kzalloc(struct_size(lookup, table, 2), GFP_KERNEL);
113+
if (!lookup)
114+
return ERR_PTR(-ENOMEM);
115+
116+
lookup->dev_id = dev_name(int3472->dev);
117+
ret = skl_int3472_fill_gpiod_lookup(&lookup->table[0], agpio, func, polarity);
118+
if (ret)
119+
return ERR_PTR(ret);
120+
121+
gpiod_add_lookup_table(lookup);
122+
desc = devm_gpiod_get(int3472->dev, func, GPIOD_OUT_LOW);
123+
gpiod_remove_lookup_table(lookup);
124+
125+
return desc;
126+
}
127+
90128
static void int3472_get_func_and_polarity(u8 type, const char **func, u32 *polarity)
91129
{
92130
switch (type) {
@@ -156,6 +194,7 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,
156194
struct acpi_resource_gpio *agpio;
157195
u8 active_value, pin, type;
158196
union acpi_object *obj;
197+
struct gpio_desc *gpio;
159198
const char *err_msg;
160199
const char *func;
161200
u32 polarity;
@@ -206,22 +245,38 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,
206245

207246
break;
208247
case INT3472_GPIO_TYPE_CLK_ENABLE:
209-
ret = skl_int3472_register_gpio_clock(int3472, agpio, polarity);
210-
if (ret)
211-
err_msg = "Failed to register clock\n";
212-
213-
break;
214248
case INT3472_GPIO_TYPE_PRIVACY_LED:
215-
ret = skl_int3472_register_pled(int3472, agpio, polarity);
216-
if (ret)
217-
err_msg = "Failed to register LED\n";
218-
219-
break;
220249
case INT3472_GPIO_TYPE_POWER_ENABLE:
221-
ret = skl_int3472_register_regulator(int3472, agpio);
222-
if (ret)
223-
err_msg = "Failed to map regulator to sensor\n";
224-
250+
gpio = skl_int3472_gpiod_get_from_temp_lookup(int3472, agpio, func, polarity);
251+
if (IS_ERR(gpio)) {
252+
ret = PTR_ERR(gpio);
253+
err_msg = "Failed to get GPIO\n";
254+
break;
255+
}
256+
257+
switch (type) {
258+
case INT3472_GPIO_TYPE_CLK_ENABLE:
259+
ret = skl_int3472_register_gpio_clock(int3472, gpio);
260+
if (ret)
261+
err_msg = "Failed to register clock\n";
262+
263+
break;
264+
case INT3472_GPIO_TYPE_PRIVACY_LED:
265+
ret = skl_int3472_register_pled(int3472, gpio);
266+
if (ret)
267+
err_msg = "Failed to register LED\n";
268+
269+
break;
270+
case INT3472_GPIO_TYPE_POWER_ENABLE:
271+
ret = skl_int3472_register_regulator(int3472, gpio);
272+
if (ret)
273+
err_msg = "Failed to map regulator to sensor\n";
274+
275+
break;
276+
default: /* Never reached */
277+
ret = -EINVAL;
278+
break;
279+
}
225280
break;
226281
default:
227282
dev_warn(int3472->dev,

drivers/platform/x86/intel/int3472/led.c

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,15 @@ static int int3472_pled_set(struct led_classdev *led_cdev,
1616
return 0;
1717
}
1818

19-
int skl_int3472_register_pled(struct int3472_discrete_device *int3472,
20-
struct acpi_resource_gpio *agpio, u32 polarity)
19+
int skl_int3472_register_pled(struct int3472_discrete_device *int3472, struct gpio_desc *gpio)
2120
{
22-
char *p, *path = agpio->resource_source.string_ptr;
21+
char *p;
2322
int ret;
2423

2524
if (int3472->pled.classdev.dev)
2625
return -EBUSY;
2726

28-
int3472->pled.gpio = acpi_get_and_request_gpiod(path, agpio->pin_table[0],
29-
"int3472,privacy-led");
30-
if (IS_ERR(int3472->pled.gpio))
31-
return dev_err_probe(int3472->dev, PTR_ERR(int3472->pled.gpio),
32-
"getting privacy LED GPIO\n");
33-
34-
if (polarity == GPIO_ACTIVE_LOW)
35-
gpiod_toggle_active_low(int3472->pled.gpio);
36-
37-
/* Ensure the pin is in output mode and non-active state */
38-
gpiod_direction_output(int3472->pled.gpio, 0);
27+
int3472->pled.gpio = gpio;
3928

4029
/* Generate the name, replacing the ':' in the ACPI devname with '_' */
4130
snprintf(int3472->pled.name, sizeof(int3472->pled.name),
@@ -50,18 +39,14 @@ int skl_int3472_register_pled(struct int3472_discrete_device *int3472,
5039

5140
ret = led_classdev_register(int3472->dev, &int3472->pled.classdev);
5241
if (ret)
53-
goto err_free_gpio;
42+
return ret;
5443

5544
int3472->pled.lookup.provider = int3472->pled.name;
5645
int3472->pled.lookup.dev_id = int3472->sensor_name;
5746
int3472->pled.lookup.con_id = "privacy-led";
5847
led_add_lookup(&int3472->pled.lookup);
5948

6049
return 0;
61-
62-
err_free_gpio:
63-
gpiod_put(int3472->pled.gpio);
64-
return ret;
6550
}
6651

6752
void skl_int3472_unregister_pled(struct int3472_discrete_device *int3472)
@@ -71,5 +56,4 @@ void skl_int3472_unregister_pled(struct int3472_discrete_device *int3472)
7156

7257
led_remove_lookup(&int3472->pled.lookup);
7358
led_classdev_unregister(&int3472->pled.classdev);
74-
gpiod_put(int3472->pled.gpio);
7559
}

0 commit comments

Comments
 (0)