^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Support for usb functionality of Hikey series boards
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * based on Hisilicon Kirin Soc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2017-2018 Hilisicon Electronics Co., Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * http://www.huawei.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Authors: Yu Chen <chenyu56@huawei.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/gpio/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/mod_devicetable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/of_gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/property.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/regulator/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/usb/role.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define DEVICE_DRIVER_NAME "hisi_hikey_usb"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define HUB_VBUS_POWER_ON 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define HUB_VBUS_POWER_OFF 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define USB_SWITCH_TO_HUB 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define USB_SWITCH_TO_TYPEC 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define TYPEC_VBUS_POWER_ON 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define TYPEC_VBUS_POWER_OFF 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct hisi_hikey_usb {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct gpio_desc *otg_switch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct gpio_desc *typec_vbus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct gpio_desc *hub_vbus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct gpio_desc *reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct regulator *regulator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct usb_role_switch *hub_role_sw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct usb_role_switch *dev_role_sw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) enum usb_role role;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct mutex lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct work_struct work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct notifier_block nb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static void hub_power_ctrl(struct hisi_hikey_usb *hisi_hikey_usb, int value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) int ret, status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) if (hisi_hikey_usb->hub_vbus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) gpiod_set_value_cansleep(hisi_hikey_usb->hub_vbus, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) if (!hisi_hikey_usb->regulator)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) status = regulator_is_enabled(hisi_hikey_usb->regulator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) if (status == !!value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) if (value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) ret = regulator_enable(hisi_hikey_usb->regulator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) ret = regulator_disable(hisi_hikey_usb->regulator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) dev_err(hisi_hikey_usb->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) "Can't switch regulator state to %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) value ? "enabled" : "disabled");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) static void usb_switch_ctrl(struct hisi_hikey_usb *hisi_hikey_usb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) int switch_to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if (!hisi_hikey_usb->otg_switch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) gpiod_set_value_cansleep(hisi_hikey_usb->otg_switch, switch_to);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) static void usb_typec_power_ctrl(struct hisi_hikey_usb *hisi_hikey_usb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) int value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (!hisi_hikey_usb->typec_vbus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) gpiod_set_value_cansleep(hisi_hikey_usb->typec_vbus, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) static void relay_set_role_switch(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) struct hisi_hikey_usb *hisi_hikey_usb = container_of(work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) struct hisi_hikey_usb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct usb_role_switch *sw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) enum usb_role role;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if (!hisi_hikey_usb || !hisi_hikey_usb->dev_role_sw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) mutex_lock(&hisi_hikey_usb->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) switch (hisi_hikey_usb->role) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) case USB_ROLE_NONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) usb_typec_power_ctrl(hisi_hikey_usb, TYPEC_VBUS_POWER_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) usb_switch_ctrl(hisi_hikey_usb, USB_SWITCH_TO_HUB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) hub_power_ctrl(hisi_hikey_usb, HUB_VBUS_POWER_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) case USB_ROLE_HOST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) hub_power_ctrl(hisi_hikey_usb, HUB_VBUS_POWER_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) usb_switch_ctrl(hisi_hikey_usb, USB_SWITCH_TO_TYPEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) usb_typec_power_ctrl(hisi_hikey_usb, TYPEC_VBUS_POWER_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) case USB_ROLE_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) hub_power_ctrl(hisi_hikey_usb, HUB_VBUS_POWER_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) usb_typec_power_ctrl(hisi_hikey_usb, TYPEC_VBUS_POWER_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) usb_switch_ctrl(hisi_hikey_usb, USB_SWITCH_TO_TYPEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) sw = hisi_hikey_usb->dev_role_sw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) role = hisi_hikey_usb->role;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) mutex_unlock(&hisi_hikey_usb->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) usb_role_switch_set_role(sw, role);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static int hub_usb_role_switch_set(struct usb_role_switch *sw, enum usb_role role)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) struct hisi_hikey_usb *hisi_hikey_usb = usb_role_switch_get_drvdata(sw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (!hisi_hikey_usb || !hisi_hikey_usb->dev_role_sw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) mutex_lock(&hisi_hikey_usb->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) hisi_hikey_usb->role = role;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) mutex_unlock(&hisi_hikey_usb->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) schedule_work(&hisi_hikey_usb->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static int hisi_hikey_usb_parse_kirin970(struct platform_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct hisi_hikey_usb *hisi_hikey_usb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) struct regulator *regulator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) regulator = devm_regulator_get(&pdev->dev, "hub-vdd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (IS_ERR(regulator)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (PTR_ERR(regulator) == -EPROBE_DEFER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) dev_info(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) "waiting for hub-vdd-supply to be probed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return PTR_ERR(regulator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) "get hub-vdd-supply failed with error %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) PTR_ERR(regulator));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) return PTR_ERR(regulator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) hisi_hikey_usb->regulator = regulator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) hisi_hikey_usb->reset = devm_gpiod_get(&pdev->dev, "hub_reset_en_gpio",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) GPIOD_OUT_HIGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) if (IS_ERR(hisi_hikey_usb->reset))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) return PTR_ERR(hisi_hikey_usb->reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static int hisi_hikey_usb_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) struct hisi_hikey_usb *hisi_hikey_usb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) struct usb_role_switch_desc hub_role_switch = {NULL};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) hisi_hikey_usb = devm_kzalloc(dev, sizeof(*hisi_hikey_usb), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (!hisi_hikey_usb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) hisi_hikey_usb->dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) hisi_hikey_usb->otg_switch = devm_gpiod_get(dev, "otg-switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) GPIOD_OUT_HIGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) if (IS_ERR(hisi_hikey_usb->otg_switch))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) return PTR_ERR(hisi_hikey_usb->otg_switch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) hisi_hikey_usb->typec_vbus = devm_gpiod_get(dev, "typec-vbus",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) GPIOD_OUT_LOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (IS_ERR(hisi_hikey_usb->typec_vbus))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) return PTR_ERR(hisi_hikey_usb->typec_vbus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) /* Parse Kirin 970-specific OF data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (of_device_is_compatible(pdev->dev.of_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) "hisilicon,kirin970_hikey_usbhub")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) ret = hisi_hikey_usb_parse_kirin970(pdev, hisi_hikey_usb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) /* hub-vdd33-en is optional */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) hisi_hikey_usb->hub_vbus = devm_gpiod_get_optional(dev, "hub-vdd33-en",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) GPIOD_OUT_HIGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (IS_ERR(hisi_hikey_usb->hub_vbus))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) return PTR_ERR(hisi_hikey_usb->hub_vbus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) hisi_hikey_usb->dev_role_sw = usb_role_switch_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (!hisi_hikey_usb->dev_role_sw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) return -EPROBE_DEFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if (IS_ERR(hisi_hikey_usb->dev_role_sw))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) return PTR_ERR(hisi_hikey_usb->dev_role_sw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) INIT_WORK(&hisi_hikey_usb->work, relay_set_role_switch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) mutex_init(&hisi_hikey_usb->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) hub_role_switch.fwnode = dev_fwnode(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) hub_role_switch.set = hub_usb_role_switch_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) hub_role_switch.driver_data = hisi_hikey_usb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) hisi_hikey_usb->hub_role_sw = usb_role_switch_register(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) &hub_role_switch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (IS_ERR(hisi_hikey_usb->hub_role_sw)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) usb_role_switch_put(hisi_hikey_usb->dev_role_sw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return PTR_ERR(hisi_hikey_usb->hub_role_sw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) platform_set_drvdata(pdev, hisi_hikey_usb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) static int hisi_hikey_usb_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct hisi_hikey_usb *hisi_hikey_usb = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) if (hisi_hikey_usb->hub_role_sw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) usb_role_switch_unregister(hisi_hikey_usb->hub_role_sw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) if (hisi_hikey_usb->dev_role_sw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) usb_role_switch_put(hisi_hikey_usb->dev_role_sw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static const struct of_device_id id_table_hisi_hikey_usb[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) { .compatible = "hisilicon,gpio_hubv1" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) { .compatible = "hisilicon,kirin970_hikey_usbhub" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) MODULE_DEVICE_TABLE(of, id_table_hisi_hikey_usb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) static struct platform_driver hisi_hikey_usb_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) .probe = hisi_hikey_usb_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) .remove = hisi_hikey_usb_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) .name = DEVICE_DRIVER_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) .of_match_table = id_table_hisi_hikey_usb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) module_platform_driver(hisi_hikey_usb_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) MODULE_AUTHOR("Yu Chen <chenyu56@huawei.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) MODULE_DESCRIPTION("Driver Support for USB functionality of Hikey");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) MODULE_LICENSE("GPL v2");