Skip to content

Commit 98ac9e4

Browse files
bala-gunasundarstorulf
authored andcommitted
mmc: atmel-mci: Move card detect gpio polarity quirk to gpiolib
The polarity of the card detection gpio is handled by the "cd-inverted" property in the device tree. Move this inversion logic to gpiolib to avoid reading the gpio raw value. Signed-off-by: Balamanikandan Gunasundar <balamanikandan.gunasundar@microchip.com> Suggested-by: Linus Walleij <linus.walleij@linaro.org> Link: https://lore.kernel.org/r/20230825095157.76073-4-balamanikandan.gunasundar@microchip.com Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent d2c6d51 commit 98ac9e4

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

drivers/gpio/gpiolib-of.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ static void of_gpio_set_polarity_by_property(const struct device_node *np,
209209
const char *propname,
210210
enum of_gpio_flags *flags)
211211
{
212+
const struct device_node *np_compat = np;
213+
const struct device_node *np_propname = np;
212214
static const struct {
213215
const char *compatible;
214216
const char *gpio_propname;
@@ -252,15 +254,29 @@ static void of_gpio_set_polarity_by_property(const struct device_node *np,
252254
#if IS_ENABLED(CONFIG_REGULATOR_GPIO)
253255
{ "regulator-gpio", "enable-gpio", "enable-active-high" },
254256
{ "regulator-gpio", "enable-gpios", "enable-active-high" },
257+
#endif
258+
#if IS_ENABLED(CONFIG_MMC_ATMELMCI)
259+
{ "atmel,hsmci", "cd-gpios", "cd-inverted" },
255260
#endif
256261
};
257262
unsigned int i;
258263
bool active_high;
259264

265+
#if IS_ENABLED(CONFIG_MMC_ATMELMCI)
266+
/*
267+
* The Atmel HSMCI has compatible property in the parent node and
268+
* gpio property in a child node
269+
*/
270+
if (of_device_is_compatible(np->parent, "atmel,hsmci")) {
271+
np_compat = np->parent;
272+
np_propname = np;
273+
}
274+
#endif
275+
260276
for (i = 0; i < ARRAY_SIZE(gpios); i++) {
261-
if (of_device_is_compatible(np, gpios[i].compatible) &&
277+
if (of_device_is_compatible(np_compat, gpios[i].compatible) &&
262278
!strcmp(propname, gpios[i].gpio_propname)) {
263-
active_high = of_property_read_bool(np,
279+
active_high = of_property_read_bool(np_propname,
264280
gpios[i].polarity_propname);
265281
of_gpio_quirk_polarity(np, active_high, flags);
266282
break;

drivers/mmc/host/atmel-mci.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
411408
struct 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

Comments
 (0)