1ae707d0eSHans de Goede // SPDX-License-Identifier: GPL-2.0
2ae707d0eSHans de Goede /*
3ae707d0eSHans de Goede * Intel Cherry Trail ACPI INT33FE pseudo device driver
4ae707d0eSHans de Goede *
5ae707d0eSHans de Goede * Copyright (C) 2017 Hans de Goede <hdegoede@redhat.com>
6ae707d0eSHans de Goede *
7ae707d0eSHans de Goede * Some Intel Cherry Trail based device which ship with Windows 10, have
8ae707d0eSHans de Goede * this weird INT33FE ACPI device with a CRS table with 4 I2cSerialBusV2
9ae707d0eSHans de Goede * resources, for 4 different chips attached to various I²C buses:
10ae707d0eSHans de Goede * 1. The Whiskey Cove PMIC, which is also described by the INT34D3 ACPI device
11ae707d0eSHans de Goede * 2. Maxim MAX17047 Fuel Gauge Controller
12ae707d0eSHans de Goede * 3. FUSB302 USB Type-C Controller
13ae707d0eSHans de Goede * 4. PI3USB30532 USB switch
14ae707d0eSHans de Goede *
15ae707d0eSHans de Goede * So this driver is a stub / pseudo driver whose only purpose is to
16ae707d0eSHans de Goede * instantiate I²C clients for chips 2 - 4, so that standard I²C drivers
17ae707d0eSHans de Goede * for these chips can bind to the them.
18ae707d0eSHans de Goede */
19ae707d0eSHans de Goede
20ae707d0eSHans de Goede #include <linux/dmi.h>
21ae707d0eSHans de Goede #include <linux/i2c.h>
22ae707d0eSHans de Goede #include <linux/interrupt.h>
23ae707d0eSHans de Goede #include <linux/pci.h>
24ae707d0eSHans de Goede #include <linux/platform_device.h>
25ae707d0eSHans de Goede #include <linux/property.h>
26ae707d0eSHans de Goede #include <linux/regulator/consumer.h>
27ae707d0eSHans de Goede #include <linux/slab.h>
28ae707d0eSHans de Goede #include <linux/usb/pd.h>
29ae707d0eSHans de Goede
30ae707d0eSHans de Goede struct cht_int33fe_data {
31ae707d0eSHans de Goede struct i2c_client *battery_fg;
32ae707d0eSHans de Goede struct i2c_client *fusb302;
33ae707d0eSHans de Goede struct i2c_client *pi3usb30532;
34ae707d0eSHans de Goede struct fwnode_handle *dp;
35ae707d0eSHans de Goede };
36ae707d0eSHans de Goede
37ae707d0eSHans de Goede /*
38ae707d0eSHans de Goede * Grrr, I severely dislike buggy BIOS-es. At least one BIOS enumerates
39ae707d0eSHans de Goede * the max17047 both through the INT33FE ACPI device (it is right there
40ae707d0eSHans de Goede * in the resources table) as well as through a separate MAX17047 device.
41ae707d0eSHans de Goede *
42ae707d0eSHans de Goede * These helpers are used to work around this by checking if an I²C client
43ae707d0eSHans de Goede * for the max17047 has already been registered.
44ae707d0eSHans de Goede */
cht_int33fe_check_for_max17047(struct device * dev,void * data)45ae707d0eSHans de Goede static int cht_int33fe_check_for_max17047(struct device *dev, void *data)
46ae707d0eSHans de Goede {
47ae707d0eSHans de Goede struct i2c_client **max17047 = data;
48ae707d0eSHans de Goede struct acpi_device *adev;
49ae707d0eSHans de Goede
50ae707d0eSHans de Goede adev = ACPI_COMPANION(dev);
51ae707d0eSHans de Goede if (!adev)
52ae707d0eSHans de Goede return 0;
53ae707d0eSHans de Goede
54ae707d0eSHans de Goede /* The MAX17047 ACPI node doesn't have an UID, so we don't check that */
55ae707d0eSHans de Goede if (!acpi_dev_hid_uid_match(adev, "MAX17047", NULL))
56ae707d0eSHans de Goede return 0;
57ae707d0eSHans de Goede
58ae707d0eSHans de Goede *max17047 = to_i2c_client(dev);
59ae707d0eSHans de Goede return 1;
60ae707d0eSHans de Goede }
61ae707d0eSHans de Goede
62ae707d0eSHans de Goede static const char * const max17047_suppliers[] = { "bq24190-charger" };
63ae707d0eSHans de Goede
64ae707d0eSHans de Goede static const struct property_entry max17047_properties[] = {
65ae707d0eSHans de Goede PROPERTY_ENTRY_STRING_ARRAY("supplied-from", max17047_suppliers),
66ae707d0eSHans de Goede { }
67ae707d0eSHans de Goede };
68ae707d0eSHans de Goede
69ae707d0eSHans de Goede static const struct software_node max17047_node = {
70ae707d0eSHans de Goede .name = "max17047",
71ae707d0eSHans de Goede .properties = max17047_properties,
72ae707d0eSHans de Goede };
73ae707d0eSHans de Goede
74ae707d0eSHans de Goede /*
75ae707d0eSHans de Goede * We are not using inline property here because those are constant,
76ae707d0eSHans de Goede * and we need to adjust this one at runtime to point to real
77ae707d0eSHans de Goede * software node.
78ae707d0eSHans de Goede */
79ae707d0eSHans de Goede static struct software_node_ref_args fusb302_mux_refs[] = {
80ae707d0eSHans de Goede { .node = NULL },
81ae707d0eSHans de Goede };
82ae707d0eSHans de Goede
83ae707d0eSHans de Goede static const struct property_entry fusb302_properties[] = {
84ae707d0eSHans de Goede PROPERTY_ENTRY_STRING("linux,extcon-name", "cht_wcove_pwrsrc"),
85ae707d0eSHans de Goede PROPERTY_ENTRY_REF_ARRAY("usb-role-switch", fusb302_mux_refs),
86ae707d0eSHans de Goede { }
87ae707d0eSHans de Goede };
88ae707d0eSHans de Goede
89ae707d0eSHans de Goede static const struct software_node fusb302_node = {
90ae707d0eSHans de Goede .name = "fusb302",
91ae707d0eSHans de Goede .properties = fusb302_properties,
92ae707d0eSHans de Goede };
93ae707d0eSHans de Goede
94ae707d0eSHans de Goede #define PDO_FIXED_FLAGS \
95ae707d0eSHans de Goede (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP | PDO_FIXED_USB_COMM)
96ae707d0eSHans de Goede
97ae707d0eSHans de Goede static const u32 src_pdo[] = {
98ae707d0eSHans de Goede PDO_FIXED(5000, 1500, PDO_FIXED_FLAGS),
99ae707d0eSHans de Goede };
100ae707d0eSHans de Goede
101ae707d0eSHans de Goede static const u32 snk_pdo[] = {
102ae707d0eSHans de Goede PDO_FIXED(5000, 400, PDO_FIXED_FLAGS),
103ae707d0eSHans de Goede PDO_VAR(5000, 12000, 3000),
104ae707d0eSHans de Goede };
105ae707d0eSHans de Goede
106ae707d0eSHans de Goede static const struct software_node pi3usb30532_node = {
107ae707d0eSHans de Goede .name = "pi3usb30532",
108ae707d0eSHans de Goede };
109ae707d0eSHans de Goede
110ae707d0eSHans de Goede static const struct software_node displayport_node = {
111ae707d0eSHans de Goede .name = "displayport",
112ae707d0eSHans de Goede };
113ae707d0eSHans de Goede
114ae707d0eSHans de Goede static const struct property_entry usb_connector_properties[] = {
115ae707d0eSHans de Goede PROPERTY_ENTRY_STRING("data-role", "dual"),
116ae707d0eSHans de Goede PROPERTY_ENTRY_STRING("power-role", "dual"),
117ae707d0eSHans de Goede PROPERTY_ENTRY_STRING("try-power-role", "sink"),
118ae707d0eSHans de Goede PROPERTY_ENTRY_U32_ARRAY("source-pdos", src_pdo),
119ae707d0eSHans de Goede PROPERTY_ENTRY_U32_ARRAY("sink-pdos", snk_pdo),
120ae707d0eSHans de Goede PROPERTY_ENTRY_U32("op-sink-microwatt", 2500000),
121ae707d0eSHans de Goede PROPERTY_ENTRY_REF("orientation-switch", &pi3usb30532_node),
122ae707d0eSHans de Goede PROPERTY_ENTRY_REF("mode-switch", &pi3usb30532_node),
123ae707d0eSHans de Goede PROPERTY_ENTRY_REF("displayport", &displayport_node),
124ae707d0eSHans de Goede { }
125ae707d0eSHans de Goede };
126ae707d0eSHans de Goede
127ae707d0eSHans de Goede static const struct software_node usb_connector_node = {
128ae707d0eSHans de Goede .name = "connector",
129ae707d0eSHans de Goede .parent = &fusb302_node,
130ae707d0eSHans de Goede .properties = usb_connector_properties,
131ae707d0eSHans de Goede };
132ae707d0eSHans de Goede
133ae707d0eSHans de Goede static const struct software_node altmodes_node = {
134ae707d0eSHans de Goede .name = "altmodes",
135ae707d0eSHans de Goede .parent = &usb_connector_node,
136ae707d0eSHans de Goede };
137ae707d0eSHans de Goede
138ae707d0eSHans de Goede static const struct property_entry dp_altmode_properties[] = {
1390dbda971SDmitry Baryshkov PROPERTY_ENTRY_U16("svid", 0xff01),
140ae707d0eSHans de Goede PROPERTY_ENTRY_U32("vdo", 0x0c0086),
141ae707d0eSHans de Goede { }
142ae707d0eSHans de Goede };
143ae707d0eSHans de Goede
144ae707d0eSHans de Goede static const struct software_node dp_altmode_node = {
145ae707d0eSHans de Goede .name = "displayport-altmode",
146ae707d0eSHans de Goede .parent = &altmodes_node,
147ae707d0eSHans de Goede .properties = dp_altmode_properties,
148ae707d0eSHans de Goede };
149ae707d0eSHans de Goede
150ae707d0eSHans de Goede static const struct software_node *node_group[] = {
151ae707d0eSHans de Goede &fusb302_node,
152ae707d0eSHans de Goede &max17047_node,
153ae707d0eSHans de Goede &pi3usb30532_node,
154ae707d0eSHans de Goede &displayport_node,
155ae707d0eSHans de Goede &usb_connector_node,
156ae707d0eSHans de Goede &altmodes_node,
157ae707d0eSHans de Goede &dp_altmode_node,
158ae707d0eSHans de Goede NULL
159ae707d0eSHans de Goede };
160ae707d0eSHans de Goede
cht_int33fe_setup_dp(struct cht_int33fe_data * data)161ae707d0eSHans de Goede static int cht_int33fe_setup_dp(struct cht_int33fe_data *data)
162ae707d0eSHans de Goede {
163ae707d0eSHans de Goede struct fwnode_handle *fwnode;
164ae707d0eSHans de Goede struct pci_dev *pdev;
165ae707d0eSHans de Goede
166ae707d0eSHans de Goede fwnode = software_node_fwnode(&displayport_node);
167ae707d0eSHans de Goede if (!fwnode)
168ae707d0eSHans de Goede return -ENODEV;
169ae707d0eSHans de Goede
170ae707d0eSHans de Goede /* First let's find the GPU PCI device */
171ae707d0eSHans de Goede pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, NULL);
172ae707d0eSHans de Goede if (!pdev || pdev->vendor != PCI_VENDOR_ID_INTEL) {
173ae707d0eSHans de Goede pci_dev_put(pdev);
174ae707d0eSHans de Goede return -ENODEV;
175ae707d0eSHans de Goede }
176ae707d0eSHans de Goede
177ae707d0eSHans de Goede /* Then the DP-2 child device node */
178ae707d0eSHans de Goede data->dp = device_get_named_child_node(&pdev->dev, "DD04");
179ae707d0eSHans de Goede pci_dev_put(pdev);
180ae707d0eSHans de Goede if (!data->dp)
181ae707d0eSHans de Goede return -ENODEV;
182ae707d0eSHans de Goede
183ae707d0eSHans de Goede fwnode->secondary = ERR_PTR(-ENODEV);
184ae707d0eSHans de Goede data->dp->secondary = fwnode;
185ae707d0eSHans de Goede
186ae707d0eSHans de Goede return 0;
187ae707d0eSHans de Goede }
188ae707d0eSHans de Goede
cht_int33fe_remove_nodes(struct cht_int33fe_data * data)189ae707d0eSHans de Goede static void cht_int33fe_remove_nodes(struct cht_int33fe_data *data)
190ae707d0eSHans de Goede {
191ae707d0eSHans de Goede software_node_unregister_node_group(node_group);
192ae707d0eSHans de Goede
193ae707d0eSHans de Goede if (fusb302_mux_refs[0].node) {
194ae707d0eSHans de Goede fwnode_handle_put(software_node_fwnode(fusb302_mux_refs[0].node));
195ae707d0eSHans de Goede fusb302_mux_refs[0].node = NULL;
196ae707d0eSHans de Goede }
197ae707d0eSHans de Goede
198ae707d0eSHans de Goede if (data->dp) {
199ae707d0eSHans de Goede data->dp->secondary = NULL;
200ae707d0eSHans de Goede fwnode_handle_put(data->dp);
201ae707d0eSHans de Goede data->dp = NULL;
202ae707d0eSHans de Goede }
203ae707d0eSHans de Goede }
204ae707d0eSHans de Goede
cht_int33fe_add_nodes(struct cht_int33fe_data * data)205ae707d0eSHans de Goede static int cht_int33fe_add_nodes(struct cht_int33fe_data *data)
206ae707d0eSHans de Goede {
207ae707d0eSHans de Goede const struct software_node *mux_ref_node;
208ae707d0eSHans de Goede int ret;
209ae707d0eSHans de Goede
210ae707d0eSHans de Goede /*
211ae707d0eSHans de Goede * There is no ACPI device node for the USB role mux, so we need to wait
212ae707d0eSHans de Goede * until the mux driver has created software node for the mux device.
213ae707d0eSHans de Goede * It means we depend on the mux driver. This function will return
214ae707d0eSHans de Goede * -EPROBE_DEFER until the mux device is registered.
215ae707d0eSHans de Goede */
216ae707d0eSHans de Goede mux_ref_node = software_node_find_by_name(NULL, "intel-xhci-usb-sw");
217ae707d0eSHans de Goede if (!mux_ref_node)
218ae707d0eSHans de Goede return -EPROBE_DEFER;
219ae707d0eSHans de Goede
220ae707d0eSHans de Goede /*
221ae707d0eSHans de Goede * Update node used in "usb-role-switch" property. Note that we
222f81fead0SAndy Shevchenko * rely on software_node_register_node_group() to use the original
223ae707d0eSHans de Goede * instance of properties instead of copying them.
224ae707d0eSHans de Goede */
225ae707d0eSHans de Goede fusb302_mux_refs[0].node = mux_ref_node;
226ae707d0eSHans de Goede
227ae707d0eSHans de Goede ret = software_node_register_node_group(node_group);
228ae707d0eSHans de Goede if (ret)
229ae707d0eSHans de Goede return ret;
230ae707d0eSHans de Goede
231ae707d0eSHans de Goede /* The devices that are not created in this driver need extra steps. */
232ae707d0eSHans de Goede
233ae707d0eSHans de Goede /*
234ae707d0eSHans de Goede * The DP connector does have ACPI device node. In this case we can just
235ae707d0eSHans de Goede * find that ACPI node and assign our node as the secondary node to it.
236ae707d0eSHans de Goede */
237ae707d0eSHans de Goede ret = cht_int33fe_setup_dp(data);
238ae707d0eSHans de Goede if (ret)
239ae707d0eSHans de Goede goto err_remove_nodes;
240ae707d0eSHans de Goede
241ae707d0eSHans de Goede return 0;
242ae707d0eSHans de Goede
243ae707d0eSHans de Goede err_remove_nodes:
244ae707d0eSHans de Goede cht_int33fe_remove_nodes(data);
245ae707d0eSHans de Goede
246ae707d0eSHans de Goede return ret;
247ae707d0eSHans de Goede }
248ae707d0eSHans de Goede
249ae707d0eSHans de Goede static int
cht_int33fe_register_max17047(struct device * dev,struct cht_int33fe_data * data)250ae707d0eSHans de Goede cht_int33fe_register_max17047(struct device *dev, struct cht_int33fe_data *data)
251ae707d0eSHans de Goede {
252ae707d0eSHans de Goede struct i2c_client *max17047 = NULL;
253ae707d0eSHans de Goede struct i2c_board_info board_info;
254ae707d0eSHans de Goede struct fwnode_handle *fwnode;
255ae707d0eSHans de Goede int ret;
256ae707d0eSHans de Goede
257ae707d0eSHans de Goede fwnode = software_node_fwnode(&max17047_node);
258ae707d0eSHans de Goede if (!fwnode)
259ae707d0eSHans de Goede return -ENODEV;
260ae707d0eSHans de Goede
261ae707d0eSHans de Goede i2c_for_each_dev(&max17047, cht_int33fe_check_for_max17047);
262ae707d0eSHans de Goede if (max17047) {
263ae707d0eSHans de Goede /* Pre-existing I²C client for the max17047, add device properties */
264ae707d0eSHans de Goede set_secondary_fwnode(&max17047->dev, fwnode);
265ae707d0eSHans de Goede /* And re-probe to get the new device properties applied */
266ae707d0eSHans de Goede ret = device_reprobe(&max17047->dev);
267ae707d0eSHans de Goede if (ret)
268ae707d0eSHans de Goede dev_warn(dev, "Reprobing max17047 error: %d\n", ret);
269ae707d0eSHans de Goede return 0;
270ae707d0eSHans de Goede }
271ae707d0eSHans de Goede
272ae707d0eSHans de Goede memset(&board_info, 0, sizeof(board_info));
273*914d906aSAndy Shevchenko strscpy(board_info.type, "max17047");
274ae707d0eSHans de Goede board_info.dev_name = "max17047";
275ae707d0eSHans de Goede board_info.fwnode = fwnode;
276ae707d0eSHans de Goede data->battery_fg = i2c_acpi_new_device(dev, 1, &board_info);
277ae707d0eSHans de Goede
278ae707d0eSHans de Goede return PTR_ERR_OR_ZERO(data->battery_fg);
279ae707d0eSHans de Goede }
280ae707d0eSHans de Goede
281ae707d0eSHans de Goede static const struct dmi_system_id cht_int33fe_typec_ids[] = {
282ae707d0eSHans de Goede {
283ae707d0eSHans de Goede /*
284ae707d0eSHans de Goede * GPD win / GPD pocket mini laptops
285ae707d0eSHans de Goede *
286ae707d0eSHans de Goede * This DMI match may not seem unique, but it is. In the 67000+
287ae707d0eSHans de Goede * DMI decode dumps from linux-hardware.org only 116 have
288ae707d0eSHans de Goede * board_vendor set to "AMI Corporation" and of those 116 only
289ae707d0eSHans de Goede * the GPD win's and pocket's board_name is "Default string".
290ae707d0eSHans de Goede */
291ae707d0eSHans de Goede .matches = {
292ae707d0eSHans de Goede DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
293ae707d0eSHans de Goede DMI_EXACT_MATCH(DMI_BOARD_NAME, "Default string"),
294ae707d0eSHans de Goede DMI_EXACT_MATCH(DMI_BOARD_SERIAL, "Default string"),
295ae707d0eSHans de Goede DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Default string"),
296ae707d0eSHans de Goede },
297ae707d0eSHans de Goede },
298ae707d0eSHans de Goede { }
299ae707d0eSHans de Goede };
300ae707d0eSHans de Goede MODULE_DEVICE_TABLE(dmi, cht_int33fe_typec_ids);
301ae707d0eSHans de Goede
cht_int33fe_typec_probe(struct platform_device * pdev)302ae707d0eSHans de Goede static int cht_int33fe_typec_probe(struct platform_device *pdev)
303ae707d0eSHans de Goede {
304ae707d0eSHans de Goede struct i2c_board_info board_info;
305ae707d0eSHans de Goede struct device *dev = &pdev->dev;
306ae707d0eSHans de Goede struct cht_int33fe_data *data;
307ae707d0eSHans de Goede struct fwnode_handle *fwnode;
308ae707d0eSHans de Goede struct regulator *regulator;
309ae707d0eSHans de Goede int fusb302_irq;
310ae707d0eSHans de Goede int ret;
311ae707d0eSHans de Goede
312ae707d0eSHans de Goede if (!dmi_check_system(cht_int33fe_typec_ids))
313ae707d0eSHans de Goede return -ENODEV;
314ae707d0eSHans de Goede
315ae707d0eSHans de Goede data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
316ae707d0eSHans de Goede if (!data)
317ae707d0eSHans de Goede return -ENOMEM;
318ae707d0eSHans de Goede
319ae707d0eSHans de Goede /*
320ae707d0eSHans de Goede * We expect the WC PMIC to be paired with a TI bq24292i charger-IC.
321ae707d0eSHans de Goede * We check for the bq24292i vbus regulator here, this has 2 purposes:
322ae707d0eSHans de Goede * 1) The bq24292i allows charging with up to 12V, setting the fusb302's
323ae707d0eSHans de Goede * max-snk voltage to 12V with another charger-IC is not good.
324ae707d0eSHans de Goede * 2) For the fusb302 driver to get the bq24292i vbus regulator, the
325ae707d0eSHans de Goede * regulator-map, which is part of the bq24292i regulator_init_data,
326ae707d0eSHans de Goede * must be registered before the fusb302 is instantiated, otherwise
327ae707d0eSHans de Goede * it will end up with a dummy-regulator.
328ae707d0eSHans de Goede * Note "cht_wc_usb_typec_vbus" comes from the regulator_init_data
329ae707d0eSHans de Goede * which is defined in i2c-cht-wc.c from where the bq24292i I²C client
330ae707d0eSHans de Goede * gets instantiated. We use regulator_get_optional here so that we
331ae707d0eSHans de Goede * don't end up getting a dummy-regulator ourselves.
332ae707d0eSHans de Goede */
333ae707d0eSHans de Goede regulator = regulator_get_optional(dev, "cht_wc_usb_typec_vbus");
334ae707d0eSHans de Goede if (IS_ERR(regulator)) {
335ae707d0eSHans de Goede ret = PTR_ERR(regulator);
336ae707d0eSHans de Goede return (ret == -ENODEV) ? -EPROBE_DEFER : ret;
337ae707d0eSHans de Goede }
338ae707d0eSHans de Goede regulator_put(regulator);
339ae707d0eSHans de Goede
340ae707d0eSHans de Goede /* The FUSB302 uses the IRQ at index 1 and is the only IRQ user */
341ae707d0eSHans de Goede fusb302_irq = acpi_dev_gpio_irq_get(ACPI_COMPANION(dev), 1);
342ae707d0eSHans de Goede if (fusb302_irq < 0) {
343ae707d0eSHans de Goede if (fusb302_irq != -EPROBE_DEFER)
344ae707d0eSHans de Goede dev_err(dev, "Error getting FUSB302 irq\n");
345ae707d0eSHans de Goede return fusb302_irq;
346ae707d0eSHans de Goede }
347ae707d0eSHans de Goede
348ae707d0eSHans de Goede ret = cht_int33fe_add_nodes(data);
349ae707d0eSHans de Goede if (ret)
350ae707d0eSHans de Goede return ret;
351ae707d0eSHans de Goede
352ae707d0eSHans de Goede /* Work around BIOS bug, see comment on cht_int33fe_check_for_max17047() */
353ae707d0eSHans de Goede ret = cht_int33fe_register_max17047(dev, data);
354ae707d0eSHans de Goede if (ret)
355ae707d0eSHans de Goede goto out_remove_nodes;
356ae707d0eSHans de Goede
357ae707d0eSHans de Goede fwnode = software_node_fwnode(&fusb302_node);
358ae707d0eSHans de Goede if (!fwnode) {
359ae707d0eSHans de Goede ret = -ENODEV;
360ae707d0eSHans de Goede goto out_unregister_max17047;
361ae707d0eSHans de Goede }
362ae707d0eSHans de Goede
363ae707d0eSHans de Goede memset(&board_info, 0, sizeof(board_info));
364*914d906aSAndy Shevchenko strscpy(board_info.type, "typec_fusb302");
365ae707d0eSHans de Goede board_info.dev_name = "fusb302";
366ae707d0eSHans de Goede board_info.fwnode = fwnode;
367ae707d0eSHans de Goede board_info.irq = fusb302_irq;
368ae707d0eSHans de Goede
369ae707d0eSHans de Goede data->fusb302 = i2c_acpi_new_device(dev, 2, &board_info);
370ae707d0eSHans de Goede if (IS_ERR(data->fusb302)) {
371ae707d0eSHans de Goede ret = PTR_ERR(data->fusb302);
372ae707d0eSHans de Goede goto out_unregister_max17047;
373ae707d0eSHans de Goede }
374ae707d0eSHans de Goede
375ae707d0eSHans de Goede fwnode = software_node_fwnode(&pi3usb30532_node);
376ae707d0eSHans de Goede if (!fwnode) {
377ae707d0eSHans de Goede ret = -ENODEV;
378ae707d0eSHans de Goede goto out_unregister_fusb302;
379ae707d0eSHans de Goede }
380ae707d0eSHans de Goede
381ae707d0eSHans de Goede memset(&board_info, 0, sizeof(board_info));
382ae707d0eSHans de Goede board_info.dev_name = "pi3usb30532";
383ae707d0eSHans de Goede board_info.fwnode = fwnode;
384*914d906aSAndy Shevchenko strscpy(board_info.type, "pi3usb30532");
385ae707d0eSHans de Goede
386ae707d0eSHans de Goede data->pi3usb30532 = i2c_acpi_new_device(dev, 3, &board_info);
387ae707d0eSHans de Goede if (IS_ERR(data->pi3usb30532)) {
388ae707d0eSHans de Goede ret = PTR_ERR(data->pi3usb30532);
389ae707d0eSHans de Goede goto out_unregister_fusb302;
390ae707d0eSHans de Goede }
391ae707d0eSHans de Goede
3923ce827bfSHeikki Krogerus platform_set_drvdata(pdev, data);
3933ce827bfSHeikki Krogerus
394ae707d0eSHans de Goede return 0;
395ae707d0eSHans de Goede
396ae707d0eSHans de Goede out_unregister_fusb302:
397ae707d0eSHans de Goede i2c_unregister_device(data->fusb302);
398ae707d0eSHans de Goede
399ae707d0eSHans de Goede out_unregister_max17047:
400ae707d0eSHans de Goede i2c_unregister_device(data->battery_fg);
401ae707d0eSHans de Goede
402ae707d0eSHans de Goede out_remove_nodes:
403ae707d0eSHans de Goede cht_int33fe_remove_nodes(data);
404ae707d0eSHans de Goede
405ae707d0eSHans de Goede return ret;
406ae707d0eSHans de Goede }
407ae707d0eSHans de Goede
cht_int33fe_typec_remove(struct platform_device * pdev)408fba53497SUwe Kleine-König static void cht_int33fe_typec_remove(struct platform_device *pdev)
409ae707d0eSHans de Goede {
410ae707d0eSHans de Goede struct cht_int33fe_data *data = platform_get_drvdata(pdev);
411ae707d0eSHans de Goede
412ae707d0eSHans de Goede i2c_unregister_device(data->pi3usb30532);
413ae707d0eSHans de Goede i2c_unregister_device(data->fusb302);
414ae707d0eSHans de Goede i2c_unregister_device(data->battery_fg);
415ae707d0eSHans de Goede
416ae707d0eSHans de Goede cht_int33fe_remove_nodes(data);
417ae707d0eSHans de Goede }
418ae707d0eSHans de Goede
419ae707d0eSHans de Goede static const struct acpi_device_id cht_int33fe_acpi_ids[] = {
420ae707d0eSHans de Goede { "INT33FE", },
421ae707d0eSHans de Goede { }
422ae707d0eSHans de Goede };
423ae707d0eSHans de Goede
424ae707d0eSHans de Goede static struct platform_driver cht_int33fe_typec_driver = {
425ae707d0eSHans de Goede .driver = {
426ae707d0eSHans de Goede .name = "Intel Cherry Trail ACPI INT33FE Type-C driver",
427ae707d0eSHans de Goede .acpi_match_table = ACPI_PTR(cht_int33fe_acpi_ids),
428ae707d0eSHans de Goede },
429ae707d0eSHans de Goede .probe = cht_int33fe_typec_probe,
430fba53497SUwe Kleine-König .remove_new = cht_int33fe_typec_remove,
431ae707d0eSHans de Goede };
432ae707d0eSHans de Goede
433ae707d0eSHans de Goede module_platform_driver(cht_int33fe_typec_driver);
434ae707d0eSHans de Goede
435ae707d0eSHans de Goede MODULE_DESCRIPTION("Intel Cherry Trail ACPI INT33FE Type-C pseudo device driver");
436ae707d0eSHans de Goede MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
437ae707d0eSHans de Goede MODULE_LICENSE("GPL v2");
438