hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/drivers/usb/host/ohci-da8xx.c
....@@ -9,6 +9,7 @@
99 */
1010
1111 #include <linux/clk.h>
12
+#include <linux/gpio/consumer.h>
1213 #include <linux/io.h>
1314 #include <linux/interrupt.h>
1415 #include <linux/jiffies.h>
....@@ -39,7 +40,7 @@
3940 struct phy *usb11_phy;
4041 struct regulator *vbus_reg;
4142 struct notifier_block nb;
42
- unsigned int reg_enabled;
43
+ struct gpio_desc *oc_gpio;
4344 };
4445
4546 #define to_da8xx_ohci(hcd) (struct da8xx_ohci_hcd *)(hcd_to_ohci(hcd)->priv)
....@@ -86,31 +87,24 @@
8687 static int ohci_da8xx_set_power(struct usb_hcd *hcd, int on)
8788 {
8889 struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
89
- struct device *dev = hcd->self.controller;
90
- struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
90
+ struct device *dev = hcd->self.controller;
9191 int ret;
92
-
93
- if (hub && hub->set_power)
94
- return hub->set_power(1, on);
9592
9693 if (!da8xx_ohci->vbus_reg)
9794 return 0;
9895
99
- if (on && !da8xx_ohci->reg_enabled) {
96
+ if (on) {
10097 ret = regulator_enable(da8xx_ohci->vbus_reg);
10198 if (ret) {
10299 dev_err(dev, "Failed to enable regulator: %d\n", ret);
103100 return ret;
104101 }
105
- da8xx_ohci->reg_enabled = 1;
106
-
107
- } else if (!on && da8xx_ohci->reg_enabled) {
102
+ } else {
108103 ret = regulator_disable(da8xx_ohci->vbus_reg);
109104 if (ret) {
110105 dev_err(dev, "Failed to disable regulator: %d\n", ret);
111106 return ret;
112107 }
113
- da8xx_ohci->reg_enabled = 0;
114108 }
115109
116110 return 0;
....@@ -119,11 +113,6 @@
119113 static int ohci_da8xx_get_power(struct usb_hcd *hcd)
120114 {
121115 struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
122
- struct device *dev = hcd->self.controller;
123
- struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
124
-
125
- if (hub && hub->get_power)
126
- return hub->get_power(1);
127116
128117 if (da8xx_ohci->vbus_reg)
129118 return regulator_is_enabled(da8xx_ohci->vbus_reg);
....@@ -134,13 +123,11 @@
134123 static int ohci_da8xx_get_oci(struct usb_hcd *hcd)
135124 {
136125 struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
137
- struct device *dev = hcd->self.controller;
138
- struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
139126 unsigned int flags;
140127 int ret;
141128
142
- if (hub && hub->get_oci)
143
- return hub->get_oci(1);
129
+ if (da8xx_ohci->oc_gpio)
130
+ return gpiod_get_value_cansleep(da8xx_ohci->oc_gpio);
144131
145132 if (!da8xx_ohci->vbus_reg)
146133 return 0;
....@@ -158,11 +145,6 @@
158145 static int ohci_da8xx_has_set_power(struct usb_hcd *hcd)
159146 {
160147 struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
161
- struct device *dev = hcd->self.controller;
162
- struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
163
-
164
- if (hub && hub->set_power)
165
- return 1;
166148
167149 if (da8xx_ohci->vbus_reg)
168150 return 1;
....@@ -173,10 +155,8 @@
173155 static int ohci_da8xx_has_oci(struct usb_hcd *hcd)
174156 {
175157 struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
176
- struct device *dev = hcd->self.controller;
177
- struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
178158
179
- if (hub && hub->get_oci)
159
+ if (da8xx_ohci->oc_gpio)
180160 return 1;
181161
182162 if (da8xx_ohci->vbus_reg)
....@@ -196,19 +176,6 @@
196176 return 0;
197177 }
198178
199
-/*
200
- * Handle the port over-current indicator change.
201
- */
202
-static void ohci_da8xx_ocic_handler(struct da8xx_ohci_root_hub *hub,
203
- unsigned port)
204
-{
205
- ocic_mask |= 1 << port;
206
-
207
- /* Once over-current is detected, the port needs to be powered down */
208
- if (hub->get_oci(port) > 0)
209
- hub->set_power(port, 0);
210
-}
211
-
212179 static int ohci_da8xx_regulator_event(struct notifier_block *nb,
213180 unsigned long event, void *data)
214181 {
....@@ -223,16 +190,29 @@
223190 return 0;
224191 }
225192
193
+static irqreturn_t ohci_da8xx_oc_thread(int irq, void *data)
194
+{
195
+ struct da8xx_ohci_hcd *da8xx_ohci = data;
196
+ struct device *dev = da8xx_ohci->hcd->self.controller;
197
+ int ret;
198
+
199
+ if (gpiod_get_value_cansleep(da8xx_ohci->oc_gpio) &&
200
+ da8xx_ohci->vbus_reg) {
201
+ ret = regulator_disable(da8xx_ohci->vbus_reg);
202
+ if (ret)
203
+ dev_err(dev, "Failed to disable regulator: %d\n", ret);
204
+ }
205
+
206
+ return IRQ_HANDLED;
207
+}
208
+
226209 static int ohci_da8xx_register_notify(struct usb_hcd *hcd)
227210 {
228211 struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
229212 struct device *dev = hcd->self.controller;
230
- struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
231213 int ret = 0;
232214
233
- if (hub && hub->ocic_notify) {
234
- ret = hub->ocic_notify(ohci_da8xx_ocic_handler);
235
- } else if (da8xx_ohci->vbus_reg) {
215
+ if (!da8xx_ohci->oc_gpio && da8xx_ohci->vbus_reg) {
236216 da8xx_ohci->nb.notifier_call = ohci_da8xx_regulator_event;
237217 ret = devm_regulator_register_notifier(da8xx_ohci->vbus_reg,
238218 &da8xx_ohci->nb);
....@@ -242,15 +222,6 @@
242222 dev_err(dev, "Failed to register notifier: %d\n", ret);
243223
244224 return ret;
245
-}
246
-
247
-static void ohci_da8xx_unregister_notify(struct usb_hcd *hcd)
248
-{
249
- struct device *dev = hcd->self.controller;
250
- struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
251
-
252
- if (hub && hub->ocic_notify)
253
- hub->ocic_notify(NULL);
254225 }
255226
256227 static int ohci_da8xx_reset(struct usb_hcd *hcd)
....@@ -402,34 +373,35 @@
402373 static int ohci_da8xx_probe(struct platform_device *pdev)
403374 {
404375 struct da8xx_ohci_hcd *da8xx_ohci;
376
+ struct device *dev = &pdev->dev;
377
+ int error, hcd_irq, oc_irq;
405378 struct usb_hcd *hcd;
406379 struct resource *mem;
407
- int error, irq;
408
- hcd = usb_create_hcd(&ohci_da8xx_hc_driver, &pdev->dev,
409
- dev_name(&pdev->dev));
380
+
381
+ hcd = usb_create_hcd(&ohci_da8xx_hc_driver, dev, dev_name(dev));
410382 if (!hcd)
411383 return -ENOMEM;
412384
413385 da8xx_ohci = to_da8xx_ohci(hcd);
414386 da8xx_ohci->hcd = hcd;
415387
416
- da8xx_ohci->usb11_clk = devm_clk_get(&pdev->dev, NULL);
388
+ da8xx_ohci->usb11_clk = devm_clk_get(dev, NULL);
417389 if (IS_ERR(da8xx_ohci->usb11_clk)) {
418390 error = PTR_ERR(da8xx_ohci->usb11_clk);
419391 if (error != -EPROBE_DEFER)
420
- dev_err(&pdev->dev, "Failed to get clock.\n");
392
+ dev_err(dev, "Failed to get clock.\n");
421393 goto err;
422394 }
423395
424
- da8xx_ohci->usb11_phy = devm_phy_get(&pdev->dev, "usb-phy");
396
+ da8xx_ohci->usb11_phy = devm_phy_get(dev, "usb-phy");
425397 if (IS_ERR(da8xx_ohci->usb11_phy)) {
426398 error = PTR_ERR(da8xx_ohci->usb11_phy);
427399 if (error != -EPROBE_DEFER)
428
- dev_err(&pdev->dev, "Failed to get phy.\n");
400
+ dev_err(dev, "Failed to get phy.\n");
429401 goto err;
430402 }
431403
432
- da8xx_ohci->vbus_reg = devm_regulator_get_optional(&pdev->dev, "vbus");
404
+ da8xx_ohci->vbus_reg = devm_regulator_get_optional(dev, "vbus");
433405 if (IS_ERR(da8xx_ohci->vbus_reg)) {
434406 error = PTR_ERR(da8xx_ohci->vbus_reg);
435407 if (error == -ENODEV) {
....@@ -437,13 +409,34 @@
437409 } else if (error == -EPROBE_DEFER) {
438410 goto err;
439411 } else {
440
- dev_err(&pdev->dev, "Failed to get regulator\n");
412
+ dev_err(dev, "Failed to get regulator\n");
441413 goto err;
442414 }
443415 }
444416
417
+ da8xx_ohci->oc_gpio = devm_gpiod_get_optional(dev, "oc", GPIOD_IN);
418
+ if (IS_ERR(da8xx_ohci->oc_gpio)) {
419
+ error = PTR_ERR(da8xx_ohci->oc_gpio);
420
+ goto err;
421
+ }
422
+
423
+ if (da8xx_ohci->oc_gpio) {
424
+ oc_irq = gpiod_to_irq(da8xx_ohci->oc_gpio);
425
+ if (oc_irq < 0) {
426
+ error = oc_irq;
427
+ goto err;
428
+ }
429
+
430
+ error = devm_request_threaded_irq(dev, oc_irq, NULL,
431
+ ohci_da8xx_oc_thread, IRQF_TRIGGER_RISING |
432
+ IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
433
+ "OHCI over-current indicator", da8xx_ohci);
434
+ if (error)
435
+ goto err;
436
+ }
437
+
445438 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
446
- hcd->regs = devm_ioremap_resource(&pdev->dev, mem);
439
+ hcd->regs = devm_ioremap_resource(dev, mem);
447440 if (IS_ERR(hcd->regs)) {
448441 error = PTR_ERR(hcd->regs);
449442 goto err;
....@@ -451,13 +444,13 @@
451444 hcd->rsrc_start = mem->start;
452445 hcd->rsrc_len = resource_size(mem);
453446
454
- irq = platform_get_irq(pdev, 0);
455
- if (irq < 0) {
447
+ hcd_irq = platform_get_irq(pdev, 0);
448
+ if (hcd_irq < 0) {
456449 error = -ENODEV;
457450 goto err;
458451 }
459452
460
- error = usb_add_hcd(hcd, irq, 0);
453
+ error = usb_add_hcd(hcd, hcd_irq, 0);
461454 if (error)
462455 goto err;
463456
....@@ -480,7 +473,6 @@
480473 {
481474 struct usb_hcd *hcd = platform_get_drvdata(pdev);
482475
483
- ohci_da8xx_unregister_notify(hcd);
484476 usb_remove_hcd(hcd);
485477 usb_put_hcd(hcd);
486478