1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * TI TPS68470 PMIC platform data definition.
4  *
5  * Copyright (c) 2021 Dan Scally <djrscally@gmail.com>
6  * Copyright (c) 2021 Red Hat Inc.
7  *
8  * Red Hat authors:
9  * Hans de Goede <hdegoede@redhat.com>
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 	REGULATOR_SUPPLY("vddd", "i2c-INT347E:00"),
34 };
35 
36 static struct regulator_consumer_supply int347a_aux1_consumer_supplies[] = {
37 	REGULATOR_SUPPLY("vdda", "i2c-INT347E:00"),
38 };
39 
40 static struct regulator_consumer_supply int347a_aux2_consumer_supplies[] = {
41 	REGULATOR_SUPPLY("vdddo", "i2c-INT347E:00"),
42 };
43 
44 static const struct regulator_init_data surface_go_tps68470_core_reg_init_data = {
45 	.constraints = {
46 		.min_uV = 1200000,
47 		.max_uV = 1200000,
48 		.apply_uV = true,
49 		.valid_ops_mask = REGULATOR_CHANGE_STATUS,
50 	},
51 	.num_consumer_supplies = ARRAY_SIZE(int347a_core_consumer_supplies),
52 	.consumer_supplies = int347a_core_consumer_supplies,
53 };
54 
55 static const struct regulator_init_data surface_go_tps68470_ana_reg_init_data = {
56 	.constraints = {
57 		.min_uV = 2815200,
58 		.max_uV = 2815200,
59 		.apply_uV = true,
60 		.valid_ops_mask = REGULATOR_CHANGE_STATUS,
61 	},
62 	.num_consumer_supplies = ARRAY_SIZE(int347a_ana_consumer_supplies),
63 	.consumer_supplies = int347a_ana_consumer_supplies,
64 };
65 
66 static const struct regulator_init_data surface_go_tps68470_vcm_reg_init_data = {
67 	.constraints = {
68 		.min_uV = 2815200,
69 		.max_uV = 2815200,
70 		.apply_uV = true,
71 		.valid_ops_mask = REGULATOR_CHANGE_STATUS,
72 	},
73 	.num_consumer_supplies = ARRAY_SIZE(int347a_vcm_consumer_supplies),
74 	.consumer_supplies = int347a_vcm_consumer_supplies,
75 };
76 
77 /* Ensure the always-on VIO regulator has the same voltage as VSIO */
78 static const struct regulator_init_data surface_go_tps68470_vio_reg_init_data = {
79 	.constraints = {
80 		.min_uV = 1800600,
81 		.max_uV = 1800600,
82 		.apply_uV = true,
83 		.always_on = true,
84 	},
85 };
86 
87 static const struct regulator_init_data surface_go_tps68470_vsio_reg_init_data = {
88 	.constraints = {
89 		.min_uV = 1800600,
90 		.max_uV = 1800600,
91 		.apply_uV = true,
92 		.valid_ops_mask = REGULATOR_CHANGE_STATUS,
93 	},
94 	.num_consumer_supplies = ARRAY_SIZE(int347a_vsio_consumer_supplies),
95 	.consumer_supplies = int347a_vsio_consumer_supplies,
96 };
97 
98 static const struct regulator_init_data surface_go_tps68470_aux1_reg_init_data = {
99 	.constraints = {
100 		.min_uV = 2815200,
101 		.max_uV = 2815200,
102 		.apply_uV = 1,
103 		.valid_ops_mask = REGULATOR_CHANGE_STATUS,
104 	},
105 	.num_consumer_supplies = ARRAY_SIZE(int347a_aux1_consumer_supplies),
106 	.consumer_supplies = int347a_aux1_consumer_supplies,
107 };
108 
109 static const struct regulator_init_data surface_go_tps68470_aux2_reg_init_data = {
110 	.constraints = {
111 		.min_uV = 1800600,
112 		.max_uV = 1800600,
113 		.apply_uV = 1,
114 		.valid_ops_mask = REGULATOR_CHANGE_STATUS,
115 	},
116 	.num_consumer_supplies = ARRAY_SIZE(int347a_aux2_consumer_supplies),
117 	.consumer_supplies = int347a_aux2_consumer_supplies,
118 };
119 
120 static const struct tps68470_regulator_platform_data surface_go_tps68470_pdata = {
121 	.reg_init_data = {
122 		[TPS68470_CORE] = &surface_go_tps68470_core_reg_init_data,
123 		[TPS68470_ANA]  = &surface_go_tps68470_ana_reg_init_data,
124 		[TPS68470_VCM]  = &surface_go_tps68470_vcm_reg_init_data,
125 		[TPS68470_VIO] = &surface_go_tps68470_vio_reg_init_data,
126 		[TPS68470_VSIO] = &surface_go_tps68470_vsio_reg_init_data,
127 		[TPS68470_AUX1] = &surface_go_tps68470_aux1_reg_init_data,
128 		[TPS68470_AUX2] = &surface_go_tps68470_aux2_reg_init_data,
129 	},
130 };
131 
132 static struct gpiod_lookup_table surface_go_int347a_gpios = {
133 	.dev_id = "i2c-INT347A:00",
134 	.table = {
135 		GPIO_LOOKUP("tps68470-gpio", 9, "reset", GPIO_ACTIVE_LOW),
136 		GPIO_LOOKUP("tps68470-gpio", 7, "powerdown", GPIO_ACTIVE_LOW),
137 		{ }
138 	}
139 };
140 
141 static struct gpiod_lookup_table surface_go_int347e_gpios = {
142 	.dev_id = "i2c-INT347E:00",
143 	.table = {
144 		GPIO_LOOKUP("tps68470-gpio", 5, "enable", GPIO_ACTIVE_HIGH),
145 		{ }
146 	}
147 };
148 
149 static const struct int3472_tps68470_board_data surface_go_tps68470_board_data = {
150 	.dev_name = "i2c-INT3472:05",
151 	.tps68470_regulator_pdata = &surface_go_tps68470_pdata,
152 	.n_gpiod_lookups = 2,
153 	.tps68470_gpio_lookup_tables = {
154 		&surface_go_int347a_gpios,
155 		&surface_go_int347e_gpios,
156 	},
157 };
158 
159 static const struct int3472_tps68470_board_data surface_go3_tps68470_board_data = {
160 	.dev_name = "i2c-INT3472:01",
161 	.tps68470_regulator_pdata = &surface_go_tps68470_pdata,
162 	.n_gpiod_lookups = 1,
163 	.tps68470_gpio_lookup_tables = {
164 		&surface_go_int347a_gpios
165 	},
166 };
167 
168 static const struct dmi_system_id int3472_tps68470_board_data_table[] = {
169 	{
170 		.matches = {
171 			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
172 			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Surface Go"),
173 		},
174 		.driver_data = (void *)&surface_go_tps68470_board_data,
175 	},
176 	{
177 		.matches = {
178 			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
179 			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Surface Go 2"),
180 		},
181 		.driver_data = (void *)&surface_go_tps68470_board_data,
182 	},
183 	{
184 		.matches = {
185 			DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
186 			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Surface Go 3"),
187 		},
188 		.driver_data = (void *)&surface_go3_tps68470_board_data,
189 	},
190 	{ }
191 };
192 
193 const struct int3472_tps68470_board_data *int3472_tps68470_get_board_data(const char *dev_name)
194 {
195 	const struct int3472_tps68470_board_data *board_data;
196 	const struct dmi_system_id *match;
197 
198 	for (match = dmi_first_match(int3472_tps68470_board_data_table);
199 	     match;
200 	     match = dmi_first_match(match + 1)) {
201 		board_data = match->driver_data;
202 		if (strcmp(board_data->dev_name, dev_name) == 0)
203 			return board_data;
204 	}
205 
206 	return NULL;
207 }
208