@@ -206,7 +206,6 @@ enum atmci_pdc_buf {
206206 * @bus_width: Number of data lines wired up the slot
207207 * @detect_pin: GPIO pin wired to the card detect switch
208208 * @wp_pin: GPIO pin wired to the write protect sensor
209- * @detect_is_active_high: The state of the detect pin when it is active
210209 * @non_removable: The slot is not removable, only detect once
211210 *
212211 * If a given slot is not present on the board, @bus_width should be
@@ -222,7 +221,6 @@ struct mci_slot_pdata {
222221 unsigned int bus_width ;
223222 struct gpio_desc * detect_pin ;
224223 struct gpio_desc * wp_pin ;
225- bool detect_is_active_high ;
226224 bool non_removable ;
227225};
228226
@@ -405,7 +403,6 @@ struct atmel_mci {
405403 * available.
406404 * @wp_pin: GPIO pin used for card write protect sending, or negative
407405 * if not available.
408- * @detect_is_active_high: The state of the detect pin when it is active.
409406 * @detect_timer: Timer used for debouncing @detect_pin interrupts.
410407 */
411408struct atmel_mci_slot {
@@ -426,7 +423,6 @@ struct atmel_mci_slot {
426423
427424 struct gpio_desc * detect_pin ;
428425 struct gpio_desc * wp_pin ;
429- bool detect_is_active_high ;
430426
431427 struct timer_list detect_timer ;
432428};
@@ -644,6 +640,7 @@ atmci_of_init(struct platform_device *pdev)
644640 struct device_node * cnp ;
645641 struct mci_platform_data * pdata ;
646642 u32 slot_id ;
643+ int err ;
647644
648645 if (!np ) {
649646 dev_err (& pdev -> dev , "device node not found\n" );
@@ -675,20 +672,25 @@ atmci_of_init(struct platform_device *pdev)
675672 pdata -> slot [slot_id ].detect_pin =
676673 devm_fwnode_gpiod_get (& pdev -> dev , of_fwnode_handle (cnp ),
677674 "cd" , GPIOD_IN , "cd-gpios" );
678- if (IS_ERR (pdata -> slot [slot_id ].detect_pin ))
675+ err = PTR_ERR_OR_ZERO (pdata -> slot [slot_id ].detect_pin );
676+ if (err ) {
677+ if (err != - ENOENT )
678+ return ERR_PTR (err );
679679 pdata -> slot [slot_id ].detect_pin = NULL ;
680-
681- pdata -> slot [slot_id ].detect_is_active_high =
682- of_property_read_bool (cnp , "cd-inverted" );
680+ }
683681
684682 pdata -> slot [slot_id ].non_removable =
685683 of_property_read_bool (cnp , "non-removable" );
686684
687685 pdata -> slot [slot_id ].wp_pin =
688686 devm_fwnode_gpiod_get (& pdev -> dev , of_fwnode_handle (cnp ),
689687 "wp" , GPIOD_IN , "wp-gpios" );
690- if (IS_ERR (pdata -> slot [slot_id ].wp_pin ))
688+ err = PTR_ERR_OR_ZERO (pdata -> slot [slot_id ].wp_pin );
689+ if (err ) {
690+ if (err != - ENOENT )
691+ return ERR_PTR (err );
691692 pdata -> slot [slot_id ].wp_pin = NULL ;
693+ }
692694 }
693695
694696 return pdata ;
@@ -1566,8 +1568,7 @@ static int atmci_get_cd(struct mmc_host *mmc)
15661568 struct atmel_mci_slot * slot = mmc_priv (mmc );
15671569
15681570 if (slot -> detect_pin ) {
1569- present = !(gpiod_get_raw_value (slot -> detect_pin ) ^
1570- slot -> detect_is_active_high );
1571+ present = gpiod_get_value_cansleep (slot -> detect_pin );
15711572 dev_dbg (& mmc -> class_dev , "card is %spresent\n" ,
15721573 present ? "" : "not " );
15731574 }
@@ -1680,8 +1681,7 @@ static void atmci_detect_change(struct timer_list *t)
16801681 return ;
16811682
16821683 enable_irq (gpiod_to_irq (slot -> detect_pin ));
1683- present = !(gpiod_get_raw_value (slot -> detect_pin ) ^
1684- slot -> detect_is_active_high );
1684+ present = gpiod_get_value_cansleep (slot -> detect_pin );
16851685 present_old = test_bit (ATMCI_CARD_PRESENT , & slot -> flags );
16861686
16871687 dev_vdbg (& slot -> mmc -> class_dev , "detect change: %d (was %d)\n" ,
@@ -2272,15 +2272,14 @@ static int atmci_init_slot(struct atmel_mci *host,
22722272 slot -> host = host ;
22732273 slot -> detect_pin = slot_data -> detect_pin ;
22742274 slot -> wp_pin = slot_data -> wp_pin ;
2275- slot -> detect_is_active_high = slot_data -> detect_is_active_high ;
22762275 slot -> sdc_reg = sdc_reg ;
22772276 slot -> sdio_irq = sdio_irq ;
22782277
22792278 dev_dbg (& mmc -> class_dev ,
22802279 "slot[%u]: bus_width=%u, detect_pin=%d, "
22812280 "detect_is_active_high=%s, wp_pin=%d\n" ,
22822281 id , slot_data -> bus_width , desc_to_gpio (slot_data -> detect_pin ),
2283- slot_data -> detect_is_active_high ? "true" : "false" ,
2282+ ! gpiod_is_active_low ( slot_data -> detect_pin ) ? "true" : "false" ,
22842283 desc_to_gpio (slot_data -> wp_pin ));
22852284
22862285 mmc -> ops = & atmci_ops ;
@@ -2318,10 +2317,8 @@ static int atmci_init_slot(struct atmel_mci *host,
23182317 /* Assume card is present initially */
23192318 set_bit (ATMCI_CARD_PRESENT , & slot -> flags );
23202319 if (slot -> detect_pin ) {
2321- if (gpiod_get_raw_value (slot -> detect_pin ) ^
2322- slot -> detect_is_active_high ) {
2320+ if (!gpiod_get_value_cansleep (slot -> detect_pin ))
23232321 clear_bit (ATMCI_CARD_PRESENT , & slot -> flags );
2324- }
23252322 } else {
23262323 dev_dbg (& mmc -> class_dev , "no detect pin available\n" );
23272324 }
0 commit comments