Skip to content

Commit 19d8d6e

Browse files
committed
platform/x86: int3472: Pass tps68470_regulator_platform_data to the tps68470-regulator MFD-cell
Pass tps68470_regulator_platform_data to the tps68470-regulator MFD-cell, specifying the voltages of the various regulators and tying the regulators to the sensor supplies so that sensors which use the TPS68470 can find their regulators. Since the voltages and supply connections are board-specific, this introduces a DMI matches int3472_tps68470_board_data struct which contains the necessary per-board info. This per-board info also includes GPIO lookup information for the sensor IO lines which may be connected to the tps68470 GPIOs. Reviewed-by: Andy Shevchenko <[email protected]> Signed-off-by: Hans de Goede <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent d3d76ae commit 19d8d6e

File tree

4 files changed

+199
-1
lines changed

4 files changed

+199
-1
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
obj-$(CONFIG_INTEL_SKL_INT3472) += intel_skl_int3472_discrete.o \
22
intel_skl_int3472_tps68470.o
33
intel_skl_int3472_discrete-y := discrete.o clk_and_regulator.o common.o
4-
intel_skl_int3472_tps68470-y := tps68470.o common.o
4+
intel_skl_int3472_tps68470-y := tps68470.o tps68470_board_data.o common.o

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
/* Author: Dan Scally <[email protected]> */
33

44
#include <linux/i2c.h>
5+
#include <linux/kernel.h>
56
#include <linux/mfd/core.h>
67
#include <linux/mfd/tps68470.h>
78
#include <linux/platform_device.h>
89
#include <linux/platform_data/tps68470.h>
910
#include <linux/regmap.h>
11+
#include <linux/string.h>
1012

1113
#include "common.h"
14+
#include "tps68470.h"
1215

1316
#define DESIGNED_FOR_CHROMEOS 1
1417
#define DESIGNED_FOR_WINDOWS 2
@@ -95,6 +98,7 @@ static int skl_int3472_tps68470_calc_type(struct acpi_device *adev)
9598
static int skl_int3472_tps68470_probe(struct i2c_client *client)
9699
{
97100
struct acpi_device *adev = ACPI_COMPANION(&client->dev);
101+
const struct int3472_tps68470_board_data *board_data;
98102
struct tps68470_clk_platform_data clk_pdata = {};
99103
struct mfd_cell *cells;
100104
struct regmap *regmap;
@@ -123,6 +127,10 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client)
123127
device_type = skl_int3472_tps68470_calc_type(adev);
124128
switch (device_type) {
125129
case DESIGNED_FOR_WINDOWS:
130+
board_data = int3472_tps68470_get_board_data(dev_name(&client->dev));
131+
if (!board_data)
132+
return dev_err_probe(&client->dev, -ENODEV, "No board-data found for this model\n");
133+
126134
cells = kcalloc(TPS68470_WIN_MFD_CELL_COUNT, sizeof(*cells), GFP_KERNEL);
127135
if (!cells)
128136
return -ENOMEM;
@@ -137,12 +145,20 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client)
137145
cells[0].platform_data = &clk_pdata;
138146
cells[0].pdata_size = sizeof(clk_pdata);
139147
cells[1].name = "tps68470-regulator";
148+
cells[1].platform_data = (void *)board_data->tps68470_regulator_pdata;
149+
cells[1].pdata_size = sizeof(struct tps68470_regulator_platform_data);
140150
cells[2].name = "tps68470-gpio";
141151

152+
gpiod_add_lookup_table(board_data->tps68470_gpio_lookup_table);
153+
142154
ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_NONE,
143155
cells, TPS68470_WIN_MFD_CELL_COUNT,
144156
NULL, 0, NULL);
145157
kfree(cells);
158+
159+
if (ret)
160+
gpiod_remove_lookup_table(board_data->tps68470_gpio_lookup_table);
161+
146162
break;
147163
case DESIGNED_FOR_CHROMEOS:
148164
ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_NONE,
@@ -157,6 +173,17 @@ static int skl_int3472_tps68470_probe(struct i2c_client *client)
157173
return ret;
158174
}
159175

176+
static int skl_int3472_tps68470_remove(struct i2c_client *client)
177+
{
178+
const struct int3472_tps68470_board_data *board_data;
179+
180+
board_data = int3472_tps68470_get_board_data(dev_name(&client->dev));
181+
if (board_data)
182+
gpiod_remove_lookup_table(board_data->tps68470_gpio_lookup_table);
183+
184+
return 0;
185+
}
186+
160187
static const struct acpi_device_id int3472_device_id[] = {
161188
{ "INT3472", 0 },
162189
{ }
@@ -169,6 +196,7 @@ static struct i2c_driver int3472_tps68470 = {
169196
.acpi_match_table = int3472_device_id,
170197
},
171198
.probe_new = skl_int3472_tps68470_probe,
199+
.remove = skl_int3472_tps68470_remove,
172200
};
173201
module_i2c_driver(int3472_tps68470);
174202

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* TI TPS68470 PMIC platform data definition.
4+
*
5+
* Copyright (c) 2021 Red Hat Inc.
6+
*
7+
* Red Hat authors:
8+
* Hans de Goede <[email protected]>
9+
*/
10+
11+
#ifndef _INTEL_SKL_INT3472_TPS68470_H
12+
#define _INTEL_SKL_INT3472_TPS68470_H
13+
14+
struct gpiod_lookup_table;
15+
struct tps68470_regulator_platform_data;
16+
17+
struct int3472_tps68470_board_data {
18+
const char *dev_name;
19+
struct gpiod_lookup_table *tps68470_gpio_lookup_table;
20+
const struct tps68470_regulator_platform_data *tps68470_regulator_pdata;
21+
};
22+
23+
const struct int3472_tps68470_board_data *int3472_tps68470_get_board_data(const char *dev_name);
24+
25+
#endif
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* TI TPS68470 PMIC platform data definition.
4+
*
5+
* Copyright (c) 2021 Dan Scally <[email protected]>
6+
* Copyright (c) 2021 Red Hat Inc.
7+
*
8+
* Red Hat authors:
9+
* Hans de Goede <[email protected]>
10+
*/
11+
12+
#include <linux/dmi.h>
13+
#include <linux/gpio/machine.h>
14+
#include <linux/platform_data/tps68470.h>
15+
#include <linux/regulator/machine.h>
16+
#include "tps68470.h"
17+
18+
static struct regulator_consumer_supply int347a_core_consumer_supplies[] = {
19+
REGULATOR_SUPPLY("dvdd", "i2c-INT347A:00"),
20+
};
21+
22+
static struct regulator_consumer_supply int347a_ana_consumer_supplies[] = {
23+
REGULATOR_SUPPLY("avdd", "i2c-INT347A:00"),
24+
};
25+
26+
static struct regulator_consumer_supply int347a_vcm_consumer_supplies[] = {
27+
REGULATOR_SUPPLY("vdd", "i2c-INT347A:00-VCM"),
28+
};
29+
30+
static struct regulator_consumer_supply int347a_vsio_consumer_supplies[] = {
31+
REGULATOR_SUPPLY("dovdd", "i2c-INT347A:00"),
32+
REGULATOR_SUPPLY("vsio", "i2c-INT347A:00-VCM"),
33+
};
34+
35+
static const struct regulator_init_data surface_go_tps68470_core_reg_init_data = {
36+
.constraints = {
37+
.min_uV = 1200000,
38+
.max_uV = 1200000,
39+
.apply_uV = true,
40+
.valid_ops_mask = REGULATOR_CHANGE_STATUS,
41+
},
42+
.num_consumer_supplies = ARRAY_SIZE(int347a_core_consumer_supplies),
43+
.consumer_supplies = int347a_core_consumer_supplies,
44+
};
45+
46+
static const struct regulator_init_data surface_go_tps68470_ana_reg_init_data = {
47+
.constraints = {
48+
.min_uV = 2815200,
49+
.max_uV = 2815200,
50+
.apply_uV = true,
51+
.valid_ops_mask = REGULATOR_CHANGE_STATUS,
52+
},
53+
.num_consumer_supplies = ARRAY_SIZE(int347a_ana_consumer_supplies),
54+
.consumer_supplies = int347a_ana_consumer_supplies,
55+
};
56+
57+
static const struct regulator_init_data surface_go_tps68470_vcm_reg_init_data = {
58+
.constraints = {
59+
.min_uV = 2815200,
60+
.max_uV = 2815200,
61+
.apply_uV = true,
62+
.valid_ops_mask = REGULATOR_CHANGE_STATUS,
63+
},
64+
.num_consumer_supplies = ARRAY_SIZE(int347a_vcm_consumer_supplies),
65+
.consumer_supplies = int347a_vcm_consumer_supplies,
66+
};
67+
68+
/* Ensure the always-on VIO regulator has the same voltage as VSIO */
69+
static const struct regulator_init_data surface_go_tps68470_vio_reg_init_data = {
70+
.constraints = {
71+
.min_uV = 1800600,
72+
.max_uV = 1800600,
73+
.apply_uV = true,
74+
.always_on = true,
75+
},
76+
};
77+
78+
static const struct regulator_init_data surface_go_tps68470_vsio_reg_init_data = {
79+
.constraints = {
80+
.min_uV = 1800600,
81+
.max_uV = 1800600,
82+
.apply_uV = true,
83+
.valid_ops_mask = REGULATOR_CHANGE_STATUS,
84+
},
85+
.num_consumer_supplies = ARRAY_SIZE(int347a_vsio_consumer_supplies),
86+
.consumer_supplies = int347a_vsio_consumer_supplies,
87+
};
88+
89+
static const struct tps68470_regulator_platform_data surface_go_tps68470_pdata = {
90+
.reg_init_data = {
91+
[TPS68470_CORE] = &surface_go_tps68470_core_reg_init_data,
92+
[TPS68470_ANA] = &surface_go_tps68470_ana_reg_init_data,
93+
[TPS68470_VCM] = &surface_go_tps68470_vcm_reg_init_data,
94+
[TPS68470_VIO] = &surface_go_tps68470_vio_reg_init_data,
95+
[TPS68470_VSIO] = &surface_go_tps68470_vsio_reg_init_data,
96+
},
97+
};
98+
99+
static struct gpiod_lookup_table surface_go_tps68470_gpios = {
100+
.dev_id = "i2c-INT347A:00",
101+
.table = {
102+
GPIO_LOOKUP("tps68470-gpio", 9, "reset", GPIO_ACTIVE_LOW),
103+
GPIO_LOOKUP("tps68470-gpio", 7, "powerdown", GPIO_ACTIVE_LOW)
104+
}
105+
};
106+
107+
static const struct int3472_tps68470_board_data surface_go_tps68470_board_data = {
108+
.dev_name = "i2c-INT3472:05",
109+
.tps68470_gpio_lookup_table = &surface_go_tps68470_gpios,
110+
.tps68470_regulator_pdata = &surface_go_tps68470_pdata,
111+
};
112+
113+
static const struct dmi_system_id int3472_tps68470_board_data_table[] = {
114+
{
115+
.matches = {
116+
DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
117+
DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Surface Go"),
118+
},
119+
.driver_data = (void *)&surface_go_tps68470_board_data,
120+
},
121+
{
122+
.matches = {
123+
DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
124+
DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Surface Go 2"),
125+
},
126+
.driver_data = (void *)&surface_go_tps68470_board_data,
127+
},
128+
{ }
129+
};
130+
131+
const struct int3472_tps68470_board_data *int3472_tps68470_get_board_data(const char *dev_name)
132+
{
133+
const struct int3472_tps68470_board_data *board_data;
134+
const struct dmi_system_id *match;
135+
136+
for (match = dmi_first_match(int3472_tps68470_board_data_table);
137+
match;
138+
match = dmi_first_match(match + 1)) {
139+
board_data = match->driver_data;
140+
if (strcmp(board_data->dev_name, dev_name) == 0)
141+
return board_data;
142+
}
143+
144+
return NULL;
145+
}

0 commit comments

Comments
 (0)