1 // SPDX-License-Identifier: GPL-2.0
3 * Common code for Intel Cherry Trail ACPI INT33FE pseudo device drivers
4 * (USB Micro-B and Type-C connector variants).
6 * Copyright (c) 2019 Yauhen Kharuzhy <jekhor@gmail.com>
9 #include <linux/acpi.h>
10 #include <linux/i2c.h>
11 #include <linux/module.h>
12 #include <linux/platform_device.h>
13 #include <linux/slab.h>
15 #include "intel_cht_int33fe_common.h"
17 #define EXPECTED_PTYPE 4
19 static int cht_int33fe_i2c_res_filter(struct acpi_resource *ares, void *data)
21 struct acpi_resource_i2c_serialbus *sb;
24 if (i2c_acpi_get_i2c_resource(ares, &sb))
30 static int cht_int33fe_count_i2c_clients(struct device *dev)
32 struct acpi_device *adev;
33 LIST_HEAD(resource_list);
36 adev = ACPI_COMPANION(dev);
40 acpi_dev_get_resources(adev, &resource_list,
41 cht_int33fe_i2c_res_filter, &count);
43 acpi_dev_free_resource_list(&resource_list);
48 static int cht_int33fe_check_hw_type(struct device *dev)
50 unsigned long long ptyp;
54 status = acpi_evaluate_integer(ACPI_HANDLE(dev), "PTYP", NULL, &ptyp);
55 if (ACPI_FAILURE(status)) {
56 dev_err(dev, "Error getting PTYPE\n");
61 * The same ACPI HID is used for different configurations check PTYP
62 * to ensure that we are dealing with the expected config.
64 if (ptyp != EXPECTED_PTYPE)
67 /* Check presence of INT34D3 (hardware-rev 3) expected for ptype == 4 */
68 if (!acpi_dev_present("INT34D3", "1", 3)) {
69 dev_err(dev, "Error PTYPE == %d, but no INT34D3 device\n",
74 ret = cht_int33fe_count_i2c_clients(dev);
80 return INT33FE_HW_MICROB;
82 return INT33FE_HW_TYPEC;
88 static int cht_int33fe_probe(struct platform_device *pdev)
90 struct cht_int33fe_data *data;
91 struct device *dev = &pdev->dev;
94 ret = cht_int33fe_check_hw_type(dev);
98 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
105 case INT33FE_HW_MICROB:
106 data->probe = cht_int33fe_microb_probe;
107 data->remove = cht_int33fe_microb_remove;
110 case INT33FE_HW_TYPEC:
111 data->probe = cht_int33fe_typec_probe;
112 data->remove = cht_int33fe_typec_remove;
116 platform_set_drvdata(pdev, data);
118 return data->probe(data);
121 static int cht_int33fe_remove(struct platform_device *pdev)
123 struct cht_int33fe_data *data = platform_get_drvdata(pdev);
125 return data->remove(data);
128 static const struct acpi_device_id cht_int33fe_acpi_ids[] = {
132 MODULE_DEVICE_TABLE(acpi, cht_int33fe_acpi_ids);
134 static struct platform_driver cht_int33fe_driver = {
136 .name = "Intel Cherry Trail ACPI INT33FE driver",
137 .acpi_match_table = ACPI_PTR(cht_int33fe_acpi_ids),
139 .probe = cht_int33fe_probe,
140 .remove = cht_int33fe_remove,
143 module_platform_driver(cht_int33fe_driver);
145 MODULE_DESCRIPTION("Intel Cherry Trail ACPI INT33FE pseudo device driver");
146 MODULE_AUTHOR("Yauhen Kharuzhy <jekhor@gmail.com>");
147 MODULE_LICENSE("GPL v2");