hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/drivers/mmc/host/pxamci.c
....@@ -1,11 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * linux/drivers/mmc/host/pxa.c - PXA MMCI driver
34 *
45 * Copyright (C) 2003 Russell King, All Rights Reserved.
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License version 2 as
8
- * published by the Free Software Foundation.
96 *
107 * This hardware is really sick:
118 * - No way to clear interrupts.
....@@ -30,13 +27,12 @@
3027 #include <linux/mmc/slot-gpio.h>
3128 #include <linux/io.h>
3229 #include <linux/regulator/consumer.h>
33
-#include <linux/gpio.h>
30
+#include <linux/gpio/consumer.h>
3431 #include <linux/gfp.h>
3532 #include <linux/of.h>
36
-#include <linux/of_gpio.h>
3733 #include <linux/of_device.h>
3834
39
-#include <asm/sizes.h>
35
+#include <linux/sizes.h>
4036
4137 #include <mach/hardware.h>
4238 #include <linux/platform_data/mmc-pxamci.h>
....@@ -63,6 +59,8 @@
6359 unsigned int imask;
6460 unsigned int power_mode;
6561 unsigned long detect_delay_ms;
62
+ bool use_ro_gpio;
63
+ struct gpio_desc *power;
6664 struct pxamci_platform_data *pdata;
6765
6866 struct mmc_request *mrq;
....@@ -101,16 +99,13 @@
10199 {
102100 struct mmc_host *mmc = host->mmc;
103101 struct regulator *supply = mmc->supply.vmmc;
104
- int on;
105102
106103 if (!IS_ERR(supply))
107104 return mmc_regulator_set_ocr(mmc, supply, vdd);
108105
109
- if (host->pdata &&
110
- gpio_is_valid(host->pdata->gpio_power)) {
111
- on = ((1 << vdd) & host->pdata->ocr_mask);
112
- gpio_set_value(host->pdata->gpio_power,
113
- !!on ^ host->pdata->gpio_power_invert);
106
+ if (host->power) {
107
+ bool on = !!((1 << vdd) & host->pdata->ocr_mask);
108
+ gpiod_set_value(host->power, on);
114109 }
115110
116111 if (host->pdata && host->pdata->setpower)
....@@ -432,7 +427,7 @@
432427 {
433428 struct pxamci_host *host = mmc_priv(mmc);
434429
435
- if (host->pdata && gpio_is_valid(host->pdata->gpio_card_ro))
430
+ if (host->use_ro_gpio)
436431 return mmc_gpio_get_ro(mmc);
437432 if (host->pdata && host->pdata->get_ro)
438433 return !!host->pdata->get_ro(mmc_dev(mmc));
....@@ -653,7 +648,7 @@
653648
654649 ret = pxamci_of_init(pdev, mmc);
655650 if (ret)
656
- return ret;
651
+ goto out;
657652
658653 host = mmc_priv(mmc);
659654 host->mmc = mmc;
....@@ -677,7 +672,7 @@
677672
678673 ret = pxamci_init_ocr(host);
679674 if (ret < 0)
680
- return ret;
675
+ goto out;
681676
682677 mmc->caps = 0;
683678 host->cmdat = 0;
....@@ -715,67 +710,56 @@
715710
716711 platform_set_drvdata(pdev, mmc);
717712
718
- host->dma_chan_rx = dma_request_slave_channel(dev, "rx");
719
- if (host->dma_chan_rx == NULL) {
713
+ host->dma_chan_rx = dma_request_chan(dev, "rx");
714
+ if (IS_ERR(host->dma_chan_rx)) {
720715 dev_err(dev, "unable to request rx dma channel\n");
721
- ret = -ENODEV;
716
+ ret = PTR_ERR(host->dma_chan_rx);
717
+ host->dma_chan_rx = NULL;
722718 goto out;
723719 }
724720
725
- host->dma_chan_tx = dma_request_slave_channel(dev, "tx");
726
- if (host->dma_chan_tx == NULL) {
721
+ host->dma_chan_tx = dma_request_chan(dev, "tx");
722
+ if (IS_ERR(host->dma_chan_tx)) {
727723 dev_err(dev, "unable to request tx dma channel\n");
728
- ret = -ENODEV;
724
+ ret = PTR_ERR(host->dma_chan_tx);
725
+ host->dma_chan_tx = NULL;
729726 goto out;
730727 }
731728
732729 if (host->pdata) {
733
- int gpio_cd = host->pdata->gpio_card_detect;
734
- int gpio_ro = host->pdata->gpio_card_ro;
735
- int gpio_power = host->pdata->gpio_power;
736
-
737730 host->detect_delay_ms = host->pdata->detect_delay_ms;
738731
739
- if (gpio_is_valid(gpio_power)) {
740
- ret = devm_gpio_request(dev, gpio_power,
741
- "mmc card power");
742
- if (ret) {
743
- dev_err(dev,
744
- "Failed requesting gpio_power %d\n",
745
- gpio_power);
746
- goto out;
747
- }
748
- gpio_direction_output(gpio_power,
749
- host->pdata->gpio_power_invert);
750
- }
751
-
752
- if (gpio_is_valid(gpio_ro)) {
753
- ret = mmc_gpio_request_ro(mmc, gpio_ro);
754
- if (ret) {
755
- dev_err(dev,
756
- "Failed requesting gpio_ro %d\n",
757
- gpio_ro);
758
- goto out;
759
- } else {
760
- mmc->caps2 |= host->pdata->gpio_card_ro_invert ?
761
- 0 : MMC_CAP2_RO_ACTIVE_HIGH;
762
- }
763
- }
764
-
765
- if (gpio_is_valid(gpio_cd))
766
- ret = mmc_gpio_request_cd(mmc, gpio_cd, 0);
767
- if (ret) {
768
- dev_err(dev, "Failed requesting gpio_cd %d\n",
769
- gpio_cd);
732
+ host->power = devm_gpiod_get_optional(dev, "power", GPIOD_OUT_LOW);
733
+ if (IS_ERR(host->power)) {
734
+ ret = PTR_ERR(host->power);
735
+ dev_err(dev, "Failed requesting gpio_power\n");
770736 goto out;
771737 }
738
+
739
+ /* FIXME: should we pass detection delay to debounce? */
740
+ ret = mmc_gpiod_request_cd(mmc, "cd", 0, false, 0);
741
+ if (ret && ret != -ENOENT) {
742
+ dev_err(dev, "Failed requesting gpio_cd\n");
743
+ goto out;
744
+ }
745
+
746
+ if (!host->pdata->gpio_card_ro_invert)
747
+ mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;
748
+
749
+ ret = mmc_gpiod_request_ro(mmc, "wp", 0, 0);
750
+ if (ret && ret != -ENOENT) {
751
+ dev_err(dev, "Failed requesting gpio_ro\n");
752
+ goto out;
753
+ }
754
+ if (!ret)
755
+ host->use_ro_gpio = true;
772756
773757 if (host->pdata->init)
774758 host->pdata->init(dev, pxamci_detect_irq, mmc);
775759
776
- if (gpio_is_valid(gpio_power) && host->pdata->setpower)
760
+ if (host->power && host->pdata->setpower)
777761 dev_warn(dev, "gpio_power and setpower() both defined\n");
778
- if (gpio_is_valid(gpio_ro) && host->pdata->get_ro)
762
+ if (host->use_ro_gpio && host->pdata->get_ro)
779763 dev_warn(dev, "gpio_ro and get_ro() both defined\n");
780764 }
781765
....@@ -828,6 +812,7 @@
828812 .remove = pxamci_remove,
829813 .driver = {
830814 .name = DRIVER_NAME,
815
+ .probe_type = PROBE_PREFER_ASYNCHRONOUS,
831816 .of_match_table = of_match_ptr(pxa_mmc_dt_ids),
832817 },
833818 };