11
11
#include <linux/dmaengine.h>
12
12
#include <linux/dma-mapping.h>
13
13
#include <linux/err.h>
14
- #include <linux/gpio.h>
15
14
#include <linux/init.h>
16
15
#include <linux/interrupt.h>
17
16
#include <linux/io.h>
18
17
#include <linux/ioport.h>
19
18
#include <linux/module.h>
20
19
#include <linux/of.h>
21
- #include <linux/of_gpio.h>
20
+ #include <linux/irq.h>
21
+ #include <linux/gpio/consumer.h>
22
22
#include <linux/platform_device.h>
23
23
#include <linux/scatterlist.h>
24
24
#include <linux/seq_file.h>
@@ -387,8 +387,8 @@ struct atmel_mci_slot {
387
387
#define ATMCI_CARD_NEED_INIT 1
388
388
#define ATMCI_SHUTDOWN 2
389
389
390
- int detect_pin ;
391
- int wp_pin ;
390
+ struct gpio_desc * detect_pin ;
391
+ struct gpio_desc * wp_pin ;
392
392
bool detect_is_active_high ;
393
393
394
394
struct timer_list detect_timer ;
@@ -636,7 +636,10 @@ atmci_of_init(struct platform_device *pdev)
636
636
pdata -> slot [slot_id ].bus_width = 1 ;
637
637
638
638
pdata -> slot [slot_id ].detect_pin =
639
- of_get_named_gpio (cnp , "cd-gpios" , 0 );
639
+ devm_fwnode_gpiod_get (& pdev -> dev , of_fwnode_handle (cnp ),
640
+ "cd" , GPIOD_IN , "cd-gpios" );
641
+ if (IS_ERR (pdata -> slot [slot_id ].detect_pin ))
642
+ pdata -> slot [slot_id ].detect_pin = NULL ;
640
643
641
644
pdata -> slot [slot_id ].detect_is_active_high =
642
645
of_property_read_bool (cnp , "cd-inverted" );
@@ -645,7 +648,10 @@ atmci_of_init(struct platform_device *pdev)
645
648
of_property_read_bool (cnp , "non-removable" );
646
649
647
650
pdata -> slot [slot_id ].wp_pin =
648
- of_get_named_gpio (cnp , "wp-gpios" , 0 );
651
+ devm_fwnode_gpiod_get (& pdev -> dev , of_fwnode_handle (cnp ),
652
+ "wp" , GPIOD_IN , "wp-gpios" );
653
+ if (IS_ERR (pdata -> slot [slot_id ].wp_pin ))
654
+ pdata -> slot [slot_id ].wp_pin = NULL ;
649
655
}
650
656
651
657
return pdata ;
@@ -1508,8 +1514,8 @@ static int atmci_get_ro(struct mmc_host *mmc)
1508
1514
int read_only = - ENOSYS ;
1509
1515
struct atmel_mci_slot * slot = mmc_priv (mmc );
1510
1516
1511
- if (gpio_is_valid ( slot -> wp_pin ) ) {
1512
- read_only = gpio_get_value (slot -> wp_pin );
1517
+ if (slot -> wp_pin ) {
1518
+ read_only = gpiod_get_value (slot -> wp_pin );
1513
1519
dev_dbg (& mmc -> class_dev , "card is %s\n" ,
1514
1520
read_only ? "read-only" : "read-write" );
1515
1521
}
@@ -1522,8 +1528,8 @@ static int atmci_get_cd(struct mmc_host *mmc)
1522
1528
int present = - ENOSYS ;
1523
1529
struct atmel_mci_slot * slot = mmc_priv (mmc );
1524
1530
1525
- if (gpio_is_valid ( slot -> detect_pin ) ) {
1526
- present = !(gpio_get_value (slot -> detect_pin ) ^
1531
+ if (slot -> detect_pin ) {
1532
+ present = !(gpiod_get_raw_value (slot -> detect_pin ) ^
1527
1533
slot -> detect_is_active_high );
1528
1534
dev_dbg (& mmc -> class_dev , "card is %spresent\n" ,
1529
1535
present ? "" : "not " );
@@ -1636,8 +1642,8 @@ static void atmci_detect_change(struct timer_list *t)
1636
1642
if (test_bit (ATMCI_SHUTDOWN , & slot -> flags ))
1637
1643
return ;
1638
1644
1639
- enable_irq (gpio_to_irq (slot -> detect_pin ));
1640
- present = !(gpio_get_value (slot -> detect_pin ) ^
1645
+ enable_irq (gpiod_to_irq (slot -> detect_pin ));
1646
+ present = !(gpiod_get_raw_value (slot -> detect_pin ) ^
1641
1647
slot -> detect_is_active_high );
1642
1648
present_old = test_bit (ATMCI_CARD_PRESENT , & slot -> flags );
1643
1649
@@ -2236,9 +2242,9 @@ static int atmci_init_slot(struct atmel_mci *host,
2236
2242
dev_dbg (& mmc -> class_dev ,
2237
2243
"slot[%u]: bus_width=%u, detect_pin=%d, "
2238
2244
"detect_is_active_high=%s, wp_pin=%d\n" ,
2239
- id , slot_data -> bus_width , slot_data -> detect_pin ,
2245
+ id , slot_data -> bus_width , desc_to_gpio ( slot_data -> detect_pin ) ,
2240
2246
slot_data -> detect_is_active_high ? "true" : "false" ,
2241
- slot_data -> wp_pin );
2247
+ desc_to_gpio ( slot_data -> wp_pin ) );
2242
2248
2243
2249
mmc -> ops = & atmci_ops ;
2244
2250
mmc -> f_min = DIV_ROUND_UP (host -> bus_hz , 512 );
@@ -2274,31 +2280,24 @@ static int atmci_init_slot(struct atmel_mci *host,
2274
2280
2275
2281
/* Assume card is present initially */
2276
2282
set_bit (ATMCI_CARD_PRESENT , & slot -> flags );
2277
- if (gpio_is_valid (slot -> detect_pin )) {
2278
- if (devm_gpio_request (& host -> pdev -> dev , slot -> detect_pin ,
2279
- "mmc_detect" )) {
2280
- dev_dbg (& mmc -> class_dev , "no detect pin available\n" );
2281
- slot -> detect_pin = - EBUSY ;
2282
- } else if (gpio_get_value (slot -> detect_pin ) ^
2283
- slot -> detect_is_active_high ) {
2283
+ if (slot -> detect_pin ) {
2284
+ if (gpiod_get_raw_value (slot -> detect_pin ) ^
2285
+ slot -> detect_is_active_high ) {
2284
2286
clear_bit (ATMCI_CARD_PRESENT , & slot -> flags );
2285
2287
}
2288
+ } else {
2289
+ dev_dbg (& mmc -> class_dev , "no detect pin available\n" );
2286
2290
}
2287
2291
2288
- if (!gpio_is_valid ( slot -> detect_pin ) ) {
2292
+ if (!slot -> detect_pin ) {
2289
2293
if (slot_data -> non_removable )
2290
2294
mmc -> caps |= MMC_CAP_NONREMOVABLE ;
2291
2295
else
2292
2296
mmc -> caps |= MMC_CAP_NEEDS_POLL ;
2293
2297
}
2294
2298
2295
- if (gpio_is_valid (slot -> wp_pin )) {
2296
- if (devm_gpio_request (& host -> pdev -> dev , slot -> wp_pin ,
2297
- "mmc_wp" )) {
2298
- dev_dbg (& mmc -> class_dev , "no WP pin available\n" );
2299
- slot -> wp_pin = - EBUSY ;
2300
- }
2301
- }
2299
+ if (!slot -> wp_pin )
2300
+ dev_dbg (& mmc -> class_dev , "no WP pin available\n" );
2302
2301
2303
2302
host -> slot [id ] = slot ;
2304
2303
mmc_regulator_get_supply (mmc );
@@ -2308,18 +2307,18 @@ static int atmci_init_slot(struct atmel_mci *host,
2308
2307
return ret ;
2309
2308
}
2310
2309
2311
- if (gpio_is_valid ( slot -> detect_pin ) ) {
2310
+ if (slot -> detect_pin ) {
2312
2311
timer_setup (& slot -> detect_timer , atmci_detect_change , 0 );
2313
2312
2314
- ret = request_irq (gpio_to_irq (slot -> detect_pin ),
2315
- atmci_detect_interrupt ,
2316
- IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING ,
2317
- "mmc-detect" , slot );
2313
+ ret = request_irq (gpiod_to_irq (slot -> detect_pin ),
2314
+ atmci_detect_interrupt ,
2315
+ IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING ,
2316
+ "mmc-detect" , slot );
2318
2317
if (ret ) {
2319
2318
dev_dbg (& mmc -> class_dev ,
2320
2319
"could not request IRQ %d for detect pin\n" ,
2321
- gpio_to_irq (slot -> detect_pin ));
2322
- slot -> detect_pin = - EBUSY ;
2320
+ gpiod_to_irq (slot -> detect_pin ));
2321
+ slot -> detect_pin = NULL ;
2323
2322
}
2324
2323
}
2325
2324
@@ -2338,10 +2337,8 @@ static void atmci_cleanup_slot(struct atmel_mci_slot *slot,
2338
2337
2339
2338
mmc_remove_host (slot -> mmc );
2340
2339
2341
- if (gpio_is_valid (slot -> detect_pin )) {
2342
- int pin = slot -> detect_pin ;
2343
-
2344
- free_irq (gpio_to_irq (pin ), slot );
2340
+ if (slot -> detect_pin ) {
2341
+ free_irq (gpiod_to_irq (slot -> detect_pin ), slot );
2345
2342
del_timer_sync (& slot -> detect_timer );
2346
2343
}
2347
2344
0 commit comments