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
= ACPI_COMPANION(dev
);
33 LIST_HEAD(resource_list
);
37 ret
= acpi_dev_get_resources(adev
, &resource_list
,
38 cht_int33fe_i2c_res_filter
, &count
);
39 acpi_dev_free_resource_list(&resource_list
);
46 static int cht_int33fe_check_hw_type(struct device
*dev
)
48 unsigned long long ptyp
;
52 status
= acpi_evaluate_integer(ACPI_HANDLE(dev
), "PTYP", NULL
, &ptyp
);
53 if (ACPI_FAILURE(status
)) {
54 dev_err(dev
, "Error getting PTYPE\n");
59 * The same ACPI HID is used for different configurations check PTYP
60 * to ensure that we are dealing with the expected config.
62 if (ptyp
!= EXPECTED_PTYPE
)
65 /* Check presence of INT34D3 (hardware-rev 3) expected for ptype == 4 */
66 if (!acpi_dev_present("INT34D3", "1", 3)) {
67 dev_err(dev
, "Error PTYPE == %d, but no INT34D3 device\n",
72 ret
= cht_int33fe_count_i2c_clients(dev
);
78 return INT33FE_HW_MICROB
;
80 return INT33FE_HW_TYPEC
;
86 static int cht_int33fe_probe(struct platform_device
*pdev
)
88 struct cht_int33fe_data
*data
;
89 struct device
*dev
= &pdev
->dev
;
92 ret
= cht_int33fe_check_hw_type(dev
);
96 data
= devm_kzalloc(dev
, sizeof(*data
), GFP_KERNEL
);
103 case INT33FE_HW_MICROB
:
104 data
->probe
= cht_int33fe_microb_probe
;
105 data
->remove
= cht_int33fe_microb_remove
;
108 case INT33FE_HW_TYPEC
:
109 data
->probe
= cht_int33fe_typec_probe
;
110 data
->remove
= cht_int33fe_typec_remove
;
114 platform_set_drvdata(pdev
, data
);
116 return data
->probe(data
);
119 static int cht_int33fe_remove(struct platform_device
*pdev
)
121 struct cht_int33fe_data
*data
= platform_get_drvdata(pdev
);
123 return data
->remove(data
);
126 static const struct acpi_device_id cht_int33fe_acpi_ids
[] = {
130 MODULE_DEVICE_TABLE(acpi
, cht_int33fe_acpi_ids
);
132 static struct platform_driver cht_int33fe_driver
= {
134 .name
= "Intel Cherry Trail ACPI INT33FE driver",
135 .acpi_match_table
= ACPI_PTR(cht_int33fe_acpi_ids
),
137 .probe
= cht_int33fe_probe
,
138 .remove
= cht_int33fe_remove
,
141 module_platform_driver(cht_int33fe_driver
);
143 MODULE_DESCRIPTION("Intel Cherry Trail ACPI INT33FE pseudo device driver");
144 MODULE_AUTHOR("Yauhen Kharuzhy <jekhor@gmail.com>");
145 MODULE_LICENSE("GPL v2");