1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver to power on the Analogix ANX7428 USB Type-C crosspoint switch
4 * on MeeGoPad top-set boxes.
6 * The MeeGoPad T8 and T9 are Cherry Trail top-set boxes which
7 * use an ANX7428 to provide a Type-C port with USB3.1 Gen 1 and
8 * DisplayPort over Type-C alternate mode support.
10 * The ANX7428 has a microcontroller which takes care of the PD
11 * negotiation and automatically sets the builtin Crosspoint Switch
12 * to send the right signal to the 4 highspeed pairs of the Type-C
13 * connector. It also takes care of HPD and AUX channel routing for
16 * IOW the ANX7428 operates fully autonomous and to the x5-Z8350 SoC
17 * things look like there simply is a USB-3 Type-A connector and a
18 * separate DisplayPort connector. Except that the BIOS does not
19 * power on the ANX7428 at boot. This driver takes care of powering
22 * It should be possible to tell the micro-controller which data- and/or
23 * power-role to negotiate and to swap the role(s) after negotiation
24 * but the MeeGoPad top-set boxes always draw their power from a separate
25 * power-connector and they only support USB host-mode. So this functionality
26 * is unnecessary and due to lack of documentation this is tricky to support.
28 * For a more complete ANX7428 driver see drivers/usb/misc/anx7418/ of
29 * the LineageOS kernel for the LG G5 (International) aka the LG H850:
30 * https://github.com/LineageOS/android_kernel_lge_msm8996/
35 #include <linux/acpi.h>
36 #include <linux/bits.h>
37 #include <linux/delay.h>
38 #include <linux/dev_printk.h>
39 #include <linux/dmi.h>
40 #include <linux/err.h>
41 #include <linux/gpio/consumer.h>
42 #include <linux/i2c.h>
43 #include <linux/iopoll.h>
44 #include <linux/module.h>
45 #include <linux/types.h>
47 /* Register addresses and fields */
48 #define VENDOR_ID 0x00
49 #define DEVICE_ID 0x02
51 #define TX_STATUS 0x16
52 #define STATUS_SUCCESS BIT(0)
53 #define STATUS_ERROR BIT(1)
54 #define OCM_STARTUP BIT(7)
57 module_param(force, bool, 0444);
58 MODULE_PARM_DESC(force, "Force the driver to probe on unknown boards");
60 static const struct acpi_gpio_params enable_gpio = { 0, 0, false };
61 static const struct acpi_gpio_params reset_gpio = { 1, 0, true };
63 static const struct acpi_gpio_mapping meegopad_anx7428_gpios[] = {
64 { "enable-gpios", &enable_gpio, 1 },
65 { "reset-gpios", &reset_gpio, 1 },
69 static const struct dmi_system_id meegopad_anx7428_ids[] = {
73 DMI_MATCH(DMI_SYS_VENDOR, "Default string"),
74 DMI_MATCH(DMI_PRODUCT_NAME, "Default string"),
75 DMI_MATCH(DMI_BOARD_NAME, "T3 MRD"),
76 DMI_MATCH(DMI_BOARD_VERSION, "V1.1"),
82 static int anx7428_probe(struct i2c_client *client)
84 struct device *dev = &client->dev;
85 struct gpio_desc *gpio;
88 if (!dmi_check_system(meegopad_anx7428_ids) && !force) {
89 dev_warn(dev, "Not probing unknown board, pass meegopad_anx7428.force=1 to probe");
93 ret = devm_acpi_dev_add_driver_gpios(dev, meegopad_anx7428_gpios);
98 * Set GPIOs to desired values while getting them, they are not needed
99 * afterwards. Ordering and delays come from android_kernel_lge_msm8996.
101 gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_HIGH);
103 return dev_err_probe(dev, PTR_ERR(gpio), "getting enable GPIO\n");
107 gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
109 return dev_err_probe(dev, PTR_ERR(gpio), "getting reset GPIO\n");
111 /* Wait for the OCM (On Chip Microcontroller) to start */
112 ret = read_poll_timeout(i2c_smbus_read_byte_data, val,
113 val >= 0 && (val & OCM_STARTUP),
114 5000, 50000, true, client, TX_STATUS);
116 return dev_err_probe(dev, ret,
117 "On Chip Microcontroller did not start, status: 0x%02x\n",
120 ret = i2c_smbus_read_word_data(client, VENDOR_ID);
122 return dev_err_probe(dev, ret, "reading vendor-id register\n");
125 ret = i2c_smbus_read_word_data(client, DEVICE_ID);
127 return dev_err_probe(dev, ret, "reading device-id register\n");
129 dev_dbg(dev, "Powered on ANX7428 id %04x:%04x\n", val, ret);
133 static const struct acpi_device_id anx7428_acpi_match[] = {
134 { "ANXO7418" }, /* ACPI says 7418 (max 2 DP lanes version) but HW is 7428 */
137 MODULE_DEVICE_TABLE(acpi, anx7428_acpi_match);
139 static struct i2c_driver anx7428_driver = {
141 .name = "meegopad_anx7428",
142 .acpi_match_table = anx7428_acpi_match,
144 .probe = anx7428_probe,
146 module_i2c_driver(anx7428_driver);
149 MODULE_DESCRIPTION("MeeGoPad ANX7428 driver");
150 MODULE_LICENSE("GPL");