14
14
15
15
#include <linux/clk.h>
16
16
#include <linux/dma-mapping.h>
17
+ #include <linux/gpio/consumer.h>
17
18
#include <linux/of_platform.h>
18
- #include <linux/of_gpio.h>
19
19
#include <linux/platform_device.h>
20
20
#include <linux/platform_data/atmel.h>
21
21
#include <linux/io.h>
39
39
40
40
#define AT91_MAX_USBH_PORTS 3
41
41
struct at91_usbh_data {
42
- int vbus_pin [AT91_MAX_USBH_PORTS ]; /* port power-control pin */
43
- int overcurrent_pin [AT91_MAX_USBH_PORTS ];
42
+ struct gpio_desc * vbus_pin [AT91_MAX_USBH_PORTS ];
43
+ struct gpio_desc * overcurrent_pin [AT91_MAX_USBH_PORTS ];
44
44
u8 ports ; /* number of ports on root hub */
45
45
u8 overcurrent_supported ;
46
46
u8 vbus_pin_active_low [AT91_MAX_USBH_PORTS ];
@@ -262,23 +262,17 @@ static void ohci_at91_usb_set_power(struct at91_usbh_data *pdata, int port, int
262
262
if (!valid_port (port ))
263
263
return ;
264
264
265
- if (!gpio_is_valid (pdata -> vbus_pin [port ]))
266
- return ;
267
-
268
- gpio_set_value (pdata -> vbus_pin [port ],
269
- pdata -> vbus_pin_active_low [port ] ^ enable );
265
+ gpiod_set_value (pdata -> vbus_pin [port ],
266
+ pdata -> vbus_pin_active_low [port ] ^ enable );
270
267
}
271
268
272
269
static int ohci_at91_usb_get_power (struct at91_usbh_data * pdata , int port )
273
270
{
274
271
if (!valid_port (port ))
275
272
return - EINVAL ;
276
273
277
- if (!gpio_is_valid (pdata -> vbus_pin [port ]))
278
- return - EINVAL ;
279
-
280
- return gpio_get_value (pdata -> vbus_pin [port ]) ^
281
- pdata -> vbus_pin_active_low [port ];
274
+ return gpiod_get_value (pdata -> vbus_pin [port ]) ^
275
+ pdata -> vbus_pin_active_low [port ];
282
276
}
283
277
284
278
/*
@@ -468,24 +462,21 @@ static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data)
468
462
{
469
463
struct platform_device * pdev = data ;
470
464
struct at91_usbh_data * pdata = dev_get_platdata (& pdev -> dev );
471
- int val , gpio , port ;
465
+ int val , port ;
472
466
473
467
/* From the GPIO notifying the over-current situation, find
474
468
* out the corresponding port */
475
469
at91_for_each_port (port ) {
476
- if (gpio_is_valid (pdata -> overcurrent_pin [port ]) &&
477
- gpio_to_irq (pdata -> overcurrent_pin [port ]) == irq ) {
478
- gpio = pdata -> overcurrent_pin [port ];
470
+ if (gpiod_to_irq (pdata -> overcurrent_pin [port ]) == irq )
479
471
break ;
480
- }
481
472
}
482
473
483
474
if (port == AT91_MAX_USBH_PORTS ) {
484
475
dev_err (& pdev -> dev , "overcurrent interrupt from unknown GPIO\n" );
485
476
return IRQ_HANDLED ;
486
477
}
487
478
488
- val = gpio_get_value ( gpio );
479
+ val = gpiod_get_value ( pdata -> overcurrent_pin [ port ] );
489
480
490
481
/* When notified of an over-current situation, disable power
491
482
on the corresponding port, and mark this port in
@@ -516,9 +507,8 @@ static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
516
507
struct device_node * np = pdev -> dev .of_node ;
517
508
struct at91_usbh_data * pdata ;
518
509
int i ;
519
- int gpio ;
520
510
int ret ;
521
- enum of_gpio_flags flags ;
511
+ int err ;
522
512
u32 ports ;
523
513
524
514
/* Right now device-tree probed devices don't get dma_mask set.
@@ -539,38 +529,16 @@ static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
539
529
pdata -> ports = ports ;
540
530
541
531
at91_for_each_port (i ) {
542
- /*
543
- * do not configure PIO if not in relation with
544
- * real USB port on board
545
- */
546
- if (i >= pdata -> ports ) {
547
- pdata -> vbus_pin [i ] = - EINVAL ;
548
- pdata -> overcurrent_pin [i ] = - EINVAL ;
532
+ pdata -> vbus_pin [i ] = devm_gpiod_get_optional (& pdev -> dev ,
533
+ "atmel,vbus-gpio" ,
534
+ GPIOD_IN );
535
+ if (IS_ERR (pdata -> vbus_pin [i ])) {
536
+ err = PTR_ERR (pdata -> vbus_pin [i ]);
537
+ dev_err (& pdev -> dev , "unable to claim gpio \"vbus\": %d\n" , err );
549
538
continue ;
550
539
}
551
540
552
- gpio = of_get_named_gpio_flags (np , "atmel,vbus-gpio" , i ,
553
- & flags );
554
- pdata -> vbus_pin [i ] = gpio ;
555
- if (!gpio_is_valid (gpio ))
556
- continue ;
557
- pdata -> vbus_pin_active_low [i ] = flags & OF_GPIO_ACTIVE_LOW ;
558
-
559
- ret = gpio_request (gpio , "ohci_vbus" );
560
- if (ret ) {
561
- dev_err (& pdev -> dev ,
562
- "can't request vbus gpio %d\n" , gpio );
563
- continue ;
564
- }
565
- ret = gpio_direction_output (gpio ,
566
- !pdata -> vbus_pin_active_low [i ]);
567
- if (ret ) {
568
- dev_err (& pdev -> dev ,
569
- "can't put vbus gpio %d as output %d\n" ,
570
- gpio , !pdata -> vbus_pin_active_low [i ]);
571
- gpio_free (gpio );
572
- continue ;
573
- }
541
+ pdata -> vbus_pin_active_low [i ] = gpiod_get_value (pdata -> vbus_pin [i ]);
574
542
575
543
ohci_at91_usb_set_power (pdata , i , 1 );
576
544
}
@@ -580,37 +548,21 @@ static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
580
548
break ;
581
549
582
550
pdata -> overcurrent_pin [i ] =
583
- of_get_named_gpio_flags (np , "atmel,oc-gpio" , i , & flags );
584
-
585
- if (!gpio_is_valid (pdata -> overcurrent_pin [i ]))
586
- continue ;
587
- gpio = pdata -> overcurrent_pin [i ];
588
-
589
- ret = gpio_request (gpio , "ohci_overcurrent" );
590
- if (ret ) {
591
- dev_err (& pdev -> dev ,
592
- "can't request overcurrent gpio %d\n" ,
593
- gpio );
551
+ devm_gpiod_get_optional (& pdev -> dev ,
552
+ "atmel,oc-gpio" , GPIOD_IN );
553
+ if (IS_ERR (pdata -> overcurrent_pin [i ])) {
554
+ err = PTR_ERR (pdata -> overcurrent_pin [i ]);
555
+ dev_err (& pdev -> dev , "unable to claim gpio \"overcurrent\": %d\n" , err );
594
556
continue ;
595
557
}
596
558
597
- ret = gpio_direction_input (gpio );
598
- if (ret ) {
599
- dev_err (& pdev -> dev ,
600
- "can't configure overcurrent gpio %d as input\n" ,
601
- gpio );
602
- gpio_free (gpio );
603
- continue ;
604
- }
605
-
606
- ret = request_irq (gpio_to_irq (gpio ),
607
- ohci_hcd_at91_overcurrent_irq ,
608
- IRQF_SHARED , "ohci_overcurrent" , pdev );
609
- if (ret ) {
610
- gpio_free (gpio );
611
- dev_err (& pdev -> dev ,
612
- "can't get gpio IRQ for overcurrent\n" );
613
- }
559
+ ret = devm_request_irq (& pdev -> dev ,
560
+ gpiod_to_irq (pdata -> overcurrent_pin [i ]),
561
+ ohci_hcd_at91_overcurrent_irq ,
562
+ IRQF_SHARED ,
563
+ "ohci_overcurrent" , pdev );
564
+ if (ret )
565
+ dev_info (& pdev -> dev , "failed to request gpio \"overcurrent\" IRQ\n" );
614
566
}
615
567
616
568
device_init_wakeup (& pdev -> dev , 1 );
@@ -623,19 +575,8 @@ static int ohci_hcd_at91_drv_remove(struct platform_device *pdev)
623
575
int i ;
624
576
625
577
if (pdata ) {
626
- at91_for_each_port (i ) {
627
- if (!gpio_is_valid (pdata -> vbus_pin [i ]))
628
- continue ;
578
+ at91_for_each_port (i )
629
579
ohci_at91_usb_set_power (pdata , i , 0 );
630
- gpio_free (pdata -> vbus_pin [i ]);
631
- }
632
-
633
- at91_for_each_port (i ) {
634
- if (!gpio_is_valid (pdata -> overcurrent_pin [i ]))
635
- continue ;
636
- free_irq (gpio_to_irq (pdata -> overcurrent_pin [i ]), pdev );
637
- gpio_free (pdata -> overcurrent_pin [i ]);
638
- }
639
580
}
640
581
641
582
device_init_wakeup (& pdev -> dev , 0 );
0 commit comments