This source file includes following definitions.
- cht_int33fe_check_for_max17047
- cht_int33fe_setup_dp
- cht_int33fe_remove_nodes
- cht_int33fe_add_nodes
- cht_int33fe_register_max17047
- cht_int33fe_probe
- cht_int33fe_remove
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #include <linux/acpi.h>
21 #include <linux/i2c.h>
22 #include <linux/interrupt.h>
23 #include <linux/module.h>
24 #include <linux/pci.h>
25 #include <linux/platform_device.h>
26 #include <linux/regulator/consumer.h>
27 #include <linux/slab.h>
28 #include <linux/usb/pd.h>
29
30 #define EXPECTED_PTYPE 4
31
32 enum {
33 INT33FE_NODE_FUSB302,
34 INT33FE_NODE_MAX17047,
35 INT33FE_NODE_PI3USB30532,
36 INT33FE_NODE_DISPLAYPORT,
37 INT33FE_NODE_USB_CONNECTOR,
38 INT33FE_NODE_MAX,
39 };
40
41 struct cht_int33fe_data {
42 struct i2c_client *max17047;
43 struct i2c_client *fusb302;
44 struct i2c_client *pi3usb30532;
45
46 struct fwnode_handle *dp;
47 };
48
49 static const struct software_node nodes[];
50
51 static const struct software_node_ref_args pi3usb30532_ref = {
52 &nodes[INT33FE_NODE_PI3USB30532]
53 };
54
55 static const struct software_node_ref_args dp_ref = {
56 &nodes[INT33FE_NODE_DISPLAYPORT]
57 };
58
59 static struct software_node_ref_args mux_ref;
60
61 static const struct software_node_reference usb_connector_refs[] = {
62 { "orientation-switch", 1, &pi3usb30532_ref},
63 { "mode-switch", 1, &pi3usb30532_ref},
64 { "displayport", 1, &dp_ref},
65 { }
66 };
67
68 static const struct software_node_reference fusb302_refs[] = {
69 { "usb-role-switch", 1, &mux_ref},
70 { }
71 };
72
73
74
75
76
77
78
79
80
81 static int cht_int33fe_check_for_max17047(struct device *dev, void *data)
82 {
83 struct i2c_client **max17047 = data;
84 struct acpi_device *adev;
85 const char *hid;
86
87 adev = ACPI_COMPANION(dev);
88 if (!adev)
89 return 0;
90
91 hid = acpi_device_hid(adev);
92
93
94 if (strcmp(hid, "MAX17047"))
95 return 0;
96
97 *max17047 = to_i2c_client(dev);
98 return 1;
99 }
100
101 static const char * const max17047_suppliers[] = { "bq24190-charger" };
102
103 static const struct property_entry max17047_props[] = {
104 PROPERTY_ENTRY_STRING_ARRAY("supplied-from", max17047_suppliers),
105 { }
106 };
107
108 static const struct property_entry fusb302_props[] = {
109 PROPERTY_ENTRY_STRING("linux,extcon-name", "cht_wcove_pwrsrc"),
110 { }
111 };
112
113 #define PDO_FIXED_FLAGS \
114 (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP | PDO_FIXED_USB_COMM)
115
116 static const u32 src_pdo[] = {
117 PDO_FIXED(5000, 1500, PDO_FIXED_FLAGS),
118 };
119
120 static const u32 snk_pdo[] = {
121 PDO_FIXED(5000, 400, PDO_FIXED_FLAGS),
122 PDO_VAR(5000, 12000, 3000),
123 };
124
125 static const struct property_entry usb_connector_props[] = {
126 PROPERTY_ENTRY_STRING("data-role", "dual"),
127 PROPERTY_ENTRY_STRING("power-role", "dual"),
128 PROPERTY_ENTRY_STRING("try-power-role", "sink"),
129 PROPERTY_ENTRY_U32_ARRAY("source-pdos", src_pdo),
130 PROPERTY_ENTRY_U32_ARRAY("sink-pdos", snk_pdo),
131 PROPERTY_ENTRY_U32("op-sink-microwatt", 2500000),
132 { }
133 };
134
135 static const struct software_node nodes[] = {
136 { "fusb302", NULL, fusb302_props, fusb302_refs },
137 { "max17047", NULL, max17047_props },
138 { "pi3usb30532" },
139 { "displayport" },
140 { "connector", &nodes[0], usb_connector_props, usb_connector_refs },
141 { }
142 };
143
144 static int cht_int33fe_setup_dp(struct cht_int33fe_data *data)
145 {
146 struct fwnode_handle *fwnode;
147 struct pci_dev *pdev;
148
149 fwnode = software_node_fwnode(&nodes[INT33FE_NODE_DISPLAYPORT]);
150 if (!fwnode)
151 return -ENODEV;
152
153
154 pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, NULL);
155 if (!pdev || pdev->vendor != PCI_VENDOR_ID_INTEL) {
156 pci_dev_put(pdev);
157 return -ENODEV;
158 }
159
160
161 data->dp = device_get_named_child_node(&pdev->dev, "DD02");
162 pci_dev_put(pdev);
163 if (!data->dp)
164 return -ENODEV;
165
166 fwnode->secondary = ERR_PTR(-ENODEV);
167 data->dp->secondary = fwnode;
168
169 return 0;
170 }
171
172 static void cht_int33fe_remove_nodes(struct cht_int33fe_data *data)
173 {
174 software_node_unregister_nodes(nodes);
175
176 if (mux_ref.node) {
177 fwnode_handle_put(software_node_fwnode(mux_ref.node));
178 mux_ref.node = NULL;
179 }
180
181 if (data->dp) {
182 data->dp->secondary = NULL;
183 fwnode_handle_put(data->dp);
184 data->dp = NULL;
185 }
186 }
187
188 static int cht_int33fe_add_nodes(struct cht_int33fe_data *data)
189 {
190 int ret;
191
192 ret = software_node_register_nodes(nodes);
193 if (ret)
194 return ret;
195
196
197
198
199
200
201
202
203
204 mux_ref.node = software_node_find_by_name(NULL, "intel-xhci-usb-sw");
205 if (!mux_ref.node) {
206 ret = -EPROBE_DEFER;
207 goto err_remove_nodes;
208 }
209
210
211
212
213
214 ret = cht_int33fe_setup_dp(data);
215 if (ret)
216 goto err_remove_nodes;
217
218 return 0;
219
220 err_remove_nodes:
221 cht_int33fe_remove_nodes(data);
222
223 return ret;
224 }
225
226 static int
227 cht_int33fe_register_max17047(struct device *dev, struct cht_int33fe_data *data)
228 {
229 struct i2c_client *max17047 = NULL;
230 struct i2c_board_info board_info;
231 struct fwnode_handle *fwnode;
232 int ret;
233
234 fwnode = software_node_fwnode(&nodes[INT33FE_NODE_MAX17047]);
235 if (!fwnode)
236 return -ENODEV;
237
238 i2c_for_each_dev(&max17047, cht_int33fe_check_for_max17047);
239 if (max17047) {
240
241 fwnode->secondary = ERR_PTR(-ENODEV);
242 max17047->dev.fwnode->secondary = fwnode;
243
244 ret = device_reprobe(&max17047->dev);
245 if (ret)
246 dev_warn(dev, "Reprobing max17047 error: %d\n", ret);
247 return 0;
248 }
249
250 memset(&board_info, 0, sizeof(board_info));
251 strlcpy(board_info.type, "max17047", I2C_NAME_SIZE);
252 board_info.dev_name = "max17047";
253 board_info.fwnode = fwnode;
254 data->max17047 = i2c_acpi_new_device(dev, 1, &board_info);
255
256 return PTR_ERR_OR_ZERO(data->max17047);
257 }
258
259 static int cht_int33fe_probe(struct platform_device *pdev)
260 {
261 struct device *dev = &pdev->dev;
262 struct i2c_board_info board_info;
263 struct cht_int33fe_data *data;
264 struct fwnode_handle *fwnode;
265 struct regulator *regulator;
266 unsigned long long ptyp;
267 acpi_status status;
268 int fusb302_irq;
269 int ret;
270
271 status = acpi_evaluate_integer(ACPI_HANDLE(dev), "PTYP", NULL, &ptyp);
272 if (ACPI_FAILURE(status)) {
273 dev_err(dev, "Error getting PTYPE\n");
274 return -ENODEV;
275 }
276
277
278
279
280
281 if (ptyp != EXPECTED_PTYPE)
282 return -ENODEV;
283
284
285 if (!acpi_dev_present("INT34D3", "1", 3)) {
286 dev_err(dev, "Error PTYPE == %d, but no INT34D3 device\n",
287 EXPECTED_PTYPE);
288 return -ENODEV;
289 }
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305 regulator = regulator_get_optional(dev, "cht_wc_usb_typec_vbus");
306 if (IS_ERR(regulator)) {
307 ret = PTR_ERR(regulator);
308 return (ret == -ENODEV) ? -EPROBE_DEFER : ret;
309 }
310 regulator_put(regulator);
311
312
313 fusb302_irq = acpi_dev_gpio_irq_get(ACPI_COMPANION(dev), 1);
314 if (fusb302_irq < 0) {
315 if (fusb302_irq != -EPROBE_DEFER)
316 dev_err(dev, "Error getting FUSB302 irq\n");
317 return fusb302_irq;
318 }
319
320 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
321 if (!data)
322 return -ENOMEM;
323
324 ret = cht_int33fe_add_nodes(data);
325 if (ret)
326 return ret;
327
328
329 ret = cht_int33fe_register_max17047(dev, data);
330 if (ret)
331 goto out_remove_nodes;
332
333 fwnode = software_node_fwnode(&nodes[INT33FE_NODE_FUSB302]);
334 if (!fwnode) {
335 ret = -ENODEV;
336 goto out_unregister_max17047;
337 }
338
339 memset(&board_info, 0, sizeof(board_info));
340 strlcpy(board_info.type, "typec_fusb302", I2C_NAME_SIZE);
341 board_info.dev_name = "fusb302";
342 board_info.fwnode = fwnode;
343 board_info.irq = fusb302_irq;
344
345 data->fusb302 = i2c_acpi_new_device(dev, 2, &board_info);
346 if (IS_ERR(data->fusb302)) {
347 ret = PTR_ERR(data->fusb302);
348 goto out_unregister_max17047;
349 }
350
351 fwnode = software_node_fwnode(&nodes[INT33FE_NODE_PI3USB30532]);
352 if (!fwnode) {
353 ret = -ENODEV;
354 goto out_unregister_fusb302;
355 }
356
357 memset(&board_info, 0, sizeof(board_info));
358 board_info.dev_name = "pi3usb30532";
359 board_info.fwnode = fwnode;
360 strlcpy(board_info.type, "pi3usb30532", I2C_NAME_SIZE);
361
362 data->pi3usb30532 = i2c_acpi_new_device(dev, 3, &board_info);
363 if (IS_ERR(data->pi3usb30532)) {
364 ret = PTR_ERR(data->pi3usb30532);
365 goto out_unregister_fusb302;
366 }
367
368 platform_set_drvdata(pdev, data);
369
370 return 0;
371
372 out_unregister_fusb302:
373 i2c_unregister_device(data->fusb302);
374
375 out_unregister_max17047:
376 i2c_unregister_device(data->max17047);
377
378 out_remove_nodes:
379 cht_int33fe_remove_nodes(data);
380
381 return ret;
382 }
383
384 static int cht_int33fe_remove(struct platform_device *pdev)
385 {
386 struct cht_int33fe_data *data = platform_get_drvdata(pdev);
387
388 i2c_unregister_device(data->pi3usb30532);
389 i2c_unregister_device(data->fusb302);
390 i2c_unregister_device(data->max17047);
391
392 cht_int33fe_remove_nodes(data);
393
394 return 0;
395 }
396
397 static const struct acpi_device_id cht_int33fe_acpi_ids[] = {
398 { "INT33FE", },
399 { }
400 };
401 MODULE_DEVICE_TABLE(acpi, cht_int33fe_acpi_ids);
402
403 static struct platform_driver cht_int33fe_driver = {
404 .driver = {
405 .name = "Intel Cherry Trail ACPI INT33FE driver",
406 .acpi_match_table = ACPI_PTR(cht_int33fe_acpi_ids),
407 },
408 .probe = cht_int33fe_probe,
409 .remove = cht_int33fe_remove,
410 };
411
412 module_platform_driver(cht_int33fe_driver);
413
414 MODULE_DESCRIPTION("Intel Cherry Trail ACPI INT33FE pseudo device driver");
415 MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
416 MODULE_LICENSE("GPL v2");