Skip to content

Commit d210a00

Browse files
mchehabgregkh
authored andcommitted
misc: hisi_hikey_usb: add support for Hikey 970
The HiKey 970 board is similar to Hikey 960 with regards to its USB configutation: it also relies on a USB HUB that is used when DWC3 is at host mode. However, it requires a few extra DT settings, as it uses a voltage regulator and GPIO reset pin. Add support for them. Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Link: https://lore.kernel.org/r/62843df9927b4d8dac5dc7c4a189567fa52ab2bb.1599717402.git.mchehab+huawei@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7a6ff4c commit d210a00

2 files changed

Lines changed: 88 additions & 19 deletions

File tree

‎drivers/misc/Kconfig‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,13 +457,13 @@ config PVPANIC
457457
(guest) communicate panic events to the host.
458458

459459
config HISI_HIKEY_USB
460-
tristate "USB GPIO Hub on HiSilicon Hikey960 Platform"
460+
tristate "USB GPIO Hub on HiSilicon Hikey 960/970 Platform"
461461
depends on (OF && GPIOLIB) || COMPILE_TEST
462462
help
463463
If you say yes here this adds support for the on-board USB GPIO hub
464-
found on the HiKey960, which is necessary to support switching
465-
between the dual-role USB-C port and the USB-A host ports using only
466-
one USB controller.
464+
found on HiKey 960/970 boards, which is necessary to support
465+
switching between the dual-role USB-C port and the USB-A host ports
466+
using only one USB controller.
467467

468468
source "drivers/misc/c2port/Kconfig"
469469
source "drivers/misc/eeprom/Kconfig"

‎drivers/misc/hisi_hikey_usb.c‎

Lines changed: 84 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
#include <linux/mod_devicetable.h>
1515
#include <linux/module.h>
1616
#include <linux/notifier.h>
17+
#include <linux/of_gpio.h>
1718
#include <linux/platform_device.h>
1819
#include <linux/property.h>
20+
#include <linux/regulator/consumer.h>
1921
#include <linux/slab.h>
2022
#include <linux/usb/role.h>
2123

@@ -29,9 +31,13 @@
2931
#define TYPEC_VBUS_POWER_OFF 0
3032

3133
struct hisi_hikey_usb {
34+
struct device *dev;
3235
struct gpio_desc *otg_switch;
3336
struct gpio_desc *typec_vbus;
3437
struct gpio_desc *hub_vbus;
38+
struct gpio_desc *reset;
39+
40+
struct regulator *regulator;
3541

3642
struct usb_role_switch *hub_role_sw;
3743

@@ -46,23 +52,47 @@ struct hisi_hikey_usb {
4652

4753
static void hub_power_ctrl(struct hisi_hikey_usb *hisi_hikey_usb, int value)
4854
{
49-
gpiod_set_value_cansleep(hisi_hikey_usb->hub_vbus, value);
55+
int ret, status;
56+
57+
if (hisi_hikey_usb->hub_vbus)
58+
gpiod_set_value_cansleep(hisi_hikey_usb->hub_vbus, value);
59+
60+
if (!hisi_hikey_usb->regulator)
61+
return;
62+
63+
status = regulator_is_enabled(hisi_hikey_usb->regulator);
64+
if (status == !!value)
65+
return;
66+
67+
if (value)
68+
ret = regulator_enable(hisi_hikey_usb->regulator);
69+
else
70+
ret = regulator_disable(hisi_hikey_usb->regulator);
71+
72+
if (ret)
73+
dev_err(hisi_hikey_usb->dev,
74+
"Can't switch regulator state to %s\n",
75+
value ? "enabled" : "disabled");
5076
}
5177

5278
static void usb_switch_ctrl(struct hisi_hikey_usb *hisi_hikey_usb,
5379
int switch_to)
5480
{
81+
if (!hisi_hikey_usb->otg_switch)
82+
return;
83+
5584
gpiod_set_value_cansleep(hisi_hikey_usb->otg_switch, switch_to);
5685
}
5786

5887
static void usb_typec_power_ctrl(struct hisi_hikey_usb *hisi_hikey_usb,
5988
int value)
6089
{
90+
if (!hisi_hikey_usb->typec_vbus)
91+
return;
92+
6193
gpiod_set_value_cansleep(hisi_hikey_usb->typec_vbus, value);
6294
}
6395

64-
65-
6696
static void relay_set_role_switch(struct work_struct *work)
6797
{
6898
struct hisi_hikey_usb *hisi_hikey_usb = container_of(work,
@@ -117,39 +147,77 @@ static int hub_usb_role_switch_set(struct usb_role_switch *sw, enum usb_role rol
117147
return 0;
118148
}
119149

150+
static int hisi_hikey_usb_parse_kirin970(struct platform_device *pdev,
151+
struct hisi_hikey_usb *hisi_hikey_usb)
152+
{
153+
struct regulator *regulator;
154+
int ret;
155+
156+
regulator = devm_regulator_get(&pdev->dev, "hub-vdd");
157+
if (IS_ERR(regulator)) {
158+
if (PTR_ERR(regulator) == -EPROBE_DEFER) {
159+
dev_info(&pdev->dev,
160+
"waiting for hub-vdd-supply to be probed\n");
161+
return PTR_ERR(regulator);
162+
}
163+
dev_err(&pdev->dev,
164+
"get hub-vdd-supply failed with error %ld\n",
165+
PTR_ERR(regulator));
166+
return PTR_ERR(regulator);
167+
}
168+
hisi_hikey_usb->regulator = regulator;
169+
170+
hisi_hikey_usb->reset = devm_gpiod_get(&pdev->dev, "hub_reset_en_gpio",
171+
GPIOD_OUT_HIGH);
172+
if (IS_ERR(hisi_hikey_usb->reset))
173+
return PTR_ERR(hisi_hikey_usb->reset);
174+
175+
return ret;
176+
}
177+
120178
static int hisi_hikey_usb_probe(struct platform_device *pdev)
121179
{
122180
struct device *dev = &pdev->dev;
123181
struct hisi_hikey_usb *hisi_hikey_usb;
124182
struct usb_role_switch_desc hub_role_switch = {NULL};
183+
int ret;
125184

126185
hisi_hikey_usb = devm_kzalloc(dev, sizeof(*hisi_hikey_usb), GFP_KERNEL);
127186
if (!hisi_hikey_usb)
128187
return -ENOMEM;
129188

130-
hisi_hikey_usb->typec_vbus = devm_gpiod_get(dev, "typec-vbus",
131-
GPIOD_OUT_LOW);
132-
if (IS_ERR(hisi_hikey_usb->typec_vbus))
133-
return PTR_ERR(hisi_hikey_usb->typec_vbus);
189+
hisi_hikey_usb->dev = &pdev->dev;
134190

135191
hisi_hikey_usb->otg_switch = devm_gpiod_get(dev, "otg-switch",
136192
GPIOD_OUT_HIGH);
137193
if (IS_ERR(hisi_hikey_usb->otg_switch))
138194
return PTR_ERR(hisi_hikey_usb->otg_switch);
139195

140-
/* hub-vdd33-en is optional */
141-
hisi_hikey_usb->hub_vbus = devm_gpiod_get_optional(dev, "hub-vdd33-en",
142-
GPIOD_OUT_HIGH);
143-
if (IS_ERR(hisi_hikey_usb->hub_vbus))
144-
return PTR_ERR(hisi_hikey_usb->hub_vbus);
196+
hisi_hikey_usb->typec_vbus = devm_gpiod_get(dev, "typec-vbus",
197+
GPIOD_OUT_LOW);
198+
if (IS_ERR(hisi_hikey_usb->typec_vbus))
199+
return PTR_ERR(hisi_hikey_usb->typec_vbus);
200+
201+
/* Parse Kirin 970-specific OF data */
202+
if (of_device_is_compatible(pdev->dev.of_node,
203+
"hisilicon,kirin970_hikey_usbhub")) {
204+
ret = hisi_hikey_usb_parse_kirin970(pdev, hisi_hikey_usb);
205+
if (ret)
206+
return ret;
207+
} else {
208+
/* hub-vdd33-en is optional */
209+
hisi_hikey_usb->hub_vbus = devm_gpiod_get_optional(dev, "hub-vdd33-en",
210+
GPIOD_OUT_HIGH);
211+
if (IS_ERR(hisi_hikey_usb->hub_vbus))
212+
return PTR_ERR(hisi_hikey_usb->hub_vbus);
213+
}
145214

146215
hisi_hikey_usb->dev_role_sw = usb_role_switch_get(dev);
147216
if (!hisi_hikey_usb->dev_role_sw)
148217
return -EPROBE_DEFER;
149218
if (IS_ERR(hisi_hikey_usb->dev_role_sw))
150219
return PTR_ERR(hisi_hikey_usb->dev_role_sw);
151220

152-
153221
INIT_WORK(&hisi_hikey_usb->work, relay_set_role_switch);
154222
mutex_init(&hisi_hikey_usb->lock);
155223

@@ -158,7 +226,7 @@ static int hisi_hikey_usb_probe(struct platform_device *pdev)
158226
hub_role_switch.driver_data = hisi_hikey_usb;
159227

160228
hisi_hikey_usb->hub_role_sw = usb_role_switch_register(dev,
161-
&hub_role_switch);
229+
&hub_role_switch);
162230

163231
if (IS_ERR(hisi_hikey_usb->hub_role_sw)) {
164232
usb_role_switch_put(hisi_hikey_usb->dev_role_sw);
@@ -184,7 +252,8 @@ static int hisi_hikey_usb_remove(struct platform_device *pdev)
184252
}
185253

186254
static const struct of_device_id id_table_hisi_hikey_usb[] = {
187-
{.compatible = "hisilicon,gpio_hubv1"},
255+
{ .compatible = "hisilicon,gpio_hubv1" },
256+
{ .compatible = "hisilicon,kirin970_hikey_usbhub" },
188257
{}
189258
};
190259
MODULE_DEVICE_TABLE(of, id_table_hisi_hikey_usb);

0 commit comments

Comments
 (0)