forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/mmc/host/omap_hsmmc.c
....@@ -30,7 +30,6 @@
3030 #include <linux/clk.h>
3131 #include <linux/of.h>
3232 #include <linux/of_irq.h>
33
-#include <linux/of_gpio.h>
3433 #include <linux/of_device.h>
3534 #include <linux/mmc/host.h>
3635 #include <linux/mmc/core.h>
....@@ -38,7 +37,6 @@
3837 #include <linux/mmc/slot-gpio.h>
3938 #include <linux/io.h>
4039 #include <linux/irq.h>
41
-#include <linux/gpio.h>
4240 #include <linux/regulator/consumer.h>
4341 #include <linux/pinctrl/consumer.h>
4442 #include <linux/pm_runtime.h>
....@@ -198,7 +196,6 @@
198196 struct dma_chan *rx_chan;
199197 int response_busy;
200198 int context_loss;
201
- int protect_card;
202199 int reqs_blocked;
203200 int req_in_progress;
204201 unsigned long clk_rate;
....@@ -207,16 +204,6 @@
207204 #define HSMMC_SDIO_IRQ_ENABLED (1 << 1) /* SDIO irq enabled */
208205 struct omap_hsmmc_next next_data;
209206 struct omap_hsmmc_platform_data *pdata;
210
-
211
- /* return MMC cover switch state, can be NULL if not supported.
212
- *
213
- * possible return values:
214
- * 0 - closed
215
- * 1 - open
216
- */
217
- int (*get_cover_state)(struct device *dev);
218
-
219
- int (*card_detect)(struct device *dev);
220207 };
221208
222209 struct omap_mmc_of_data {
....@@ -225,20 +212,6 @@
225212 };
226213
227214 static void omap_hsmmc_start_dma_transfer(struct omap_hsmmc_host *host);
228
-
229
-static int omap_hsmmc_card_detect(struct device *dev)
230
-{
231
- struct omap_hsmmc_host *host = dev_get_drvdata(dev);
232
-
233
- return mmc_gpio_get_cd(host->mmc);
234
-}
235
-
236
-static int omap_hsmmc_get_cover_state(struct device *dev)
237
-{
238
- struct omap_hsmmc_host *host = dev_get_drvdata(dev);
239
-
240
- return mmc_gpio_get_cd(host->mmc);
241
-}
242215
243216 static int omap_hsmmc_enable_supply(struct mmc_host *mmc)
244217 {
....@@ -480,38 +453,6 @@
480453 ret = omap_hsmmc_disable_boot_regulators(host);
481454 if (ret)
482455 return ret;
483
-
484
- return 0;
485
-}
486
-
487
-static irqreturn_t omap_hsmmc_cover_irq(int irq, void *dev_id);
488
-
489
-static int omap_hsmmc_gpio_init(struct mmc_host *mmc,
490
- struct omap_hsmmc_host *host,
491
- struct omap_hsmmc_platform_data *pdata)
492
-{
493
- int ret;
494
-
495
- if (gpio_is_valid(pdata->gpio_cod)) {
496
- ret = mmc_gpio_request_cd(mmc, pdata->gpio_cod, 0);
497
- if (ret)
498
- return ret;
499
-
500
- host->get_cover_state = omap_hsmmc_get_cover_state;
501
- mmc_gpio_set_cd_isr(mmc, omap_hsmmc_cover_irq);
502
- } else if (gpio_is_valid(pdata->gpio_cd)) {
503
- ret = mmc_gpio_request_cd(mmc, pdata->gpio_cd, 0);
504
- if (ret)
505
- return ret;
506
-
507
- host->card_detect = omap_hsmmc_card_detect;
508
- }
509
-
510
- if (gpio_is_valid(pdata->gpio_wp)) {
511
- ret = mmc_gpio_request_ro(mmc, pdata->gpio_wp);
512
- if (ret)
513
- return ret;
514
- }
515456
516457 return 0;
517458 }
....@@ -781,9 +722,6 @@
781722 int reg = 0;
782723 unsigned long timeout;
783724
784
- if (host->protect_card)
785
- return;
786
-
787725 disable_irq(host->irq);
788726
789727 OMAP_HSMMC_WRITE(host->base, IE, INT_EN_MASK);
....@@ -803,29 +741,6 @@
803741
804742 enable_irq(host->irq);
805743 }
806
-
807
-static inline
808
-int omap_hsmmc_cover_is_closed(struct omap_hsmmc_host *host)
809
-{
810
- int r = 1;
811
-
812
- if (host->get_cover_state)
813
- r = host->get_cover_state(host->dev);
814
- return r;
815
-}
816
-
817
-static ssize_t
818
-omap_hsmmc_show_cover_switch(struct device *dev, struct device_attribute *attr,
819
- char *buf)
820
-{
821
- struct mmc_host *mmc = container_of(dev, struct mmc_host, class_dev);
822
- struct omap_hsmmc_host *host = mmc_priv(mmc);
823
-
824
- return sprintf(buf, "%s\n",
825
- omap_hsmmc_cover_is_closed(host) ? "closed" : "open");
826
-}
827
-
828
-static DEVICE_ATTR(cover_switch, S_IRUGO, omap_hsmmc_show_cover_switch, NULL);
829744
830745 static ssize_t
831746 omap_hsmmc_show_slot_name(struct device *dev, struct device_attribute *attr,
....@@ -1199,8 +1114,7 @@
11991114 int ret;
12001115
12011116 /* Disable the clocks */
1202
- if (host->dbclk)
1203
- clk_disable_unprepare(host->dbclk);
1117
+ clk_disable_unprepare(host->dbclk);
12041118
12051119 /* Turn the power off */
12061120 ret = omap_hsmmc_set_power(host, 0);
....@@ -1208,8 +1122,7 @@
12081122 /* Turn the power ON with given VDD 1.8 or 3.0v */
12091123 if (!ret)
12101124 ret = omap_hsmmc_set_power(host, 1);
1211
- if (host->dbclk)
1212
- clk_prepare_enable(host->dbclk);
1125
+ clk_prepare_enable(host->dbclk);
12131126
12141127 if (ret != 0)
12151128 goto err;
....@@ -1245,44 +1158,6 @@
12451158 err:
12461159 dev_err(mmc_dev(host->mmc), "Unable to switch operating voltage\n");
12471160 return ret;
1248
-}
1249
-
1250
-/* Protect the card while the cover is open */
1251
-static void omap_hsmmc_protect_card(struct omap_hsmmc_host *host)
1252
-{
1253
- if (!host->get_cover_state)
1254
- return;
1255
-
1256
- host->reqs_blocked = 0;
1257
- if (host->get_cover_state(host->dev)) {
1258
- if (host->protect_card) {
1259
- dev_info(host->dev, "%s: cover is closed, "
1260
- "card is now accessible\n",
1261
- mmc_hostname(host->mmc));
1262
- host->protect_card = 0;
1263
- }
1264
- } else {
1265
- if (!host->protect_card) {
1266
- dev_info(host->dev, "%s: cover is open, "
1267
- "card is now inaccessible\n",
1268
- mmc_hostname(host->mmc));
1269
- host->protect_card = 1;
1270
- }
1271
- }
1272
-}
1273
-
1274
-/*
1275
- * irq handler when (cell-phone) cover is mounted/removed
1276
- */
1277
-static irqreturn_t omap_hsmmc_cover_irq(int irq, void *dev_id)
1278
-{
1279
- struct omap_hsmmc_host *host = dev_id;
1280
-
1281
- sysfs_notify(&host->mmc->class_dev.kobj, NULL, "cover_switch");
1282
-
1283
- omap_hsmmc_protect_card(host);
1284
- mmc_detect_change(host->mmc, (HZ * 200) / 1000);
1285
- return IRQ_HANDLED;
12861161 }
12871162
12881163 static void omap_hsmmc_dma_callback(void *param)
....@@ -1555,24 +1430,7 @@
15551430
15561431 BUG_ON(host->req_in_progress);
15571432 BUG_ON(host->dma_ch != -1);
1558
- if (host->protect_card) {
1559
- if (host->reqs_blocked < 3) {
1560
- /*
1561
- * Ensure the controller is left in a consistent
1562
- * state by resetting the command and data state
1563
- * machines.
1564
- */
1565
- omap_hsmmc_reset_controller_fsm(host, SRD);
1566
- omap_hsmmc_reset_controller_fsm(host, SRC);
1567
- host->reqs_blocked += 1;
1568
- }
1569
- req->cmd->error = -EBADF;
1570
- if (req->data)
1571
- req->data->error = -EBADF;
1572
- req->cmd->retries = 0;
1573
- mmc_request_done(mmc, req);
1574
- return;
1575
- } else if (host->reqs_blocked)
1433
+ if (host->reqs_blocked)
15761434 host->reqs_blocked = 0;
15771435 WARN_ON(host->mrq != NULL);
15781436 host->mrq = req;
....@@ -1646,23 +1504,11 @@
16461504 omap_hsmmc_set_bus_mode(host);
16471505 }
16481506
1649
-static int omap_hsmmc_get_cd(struct mmc_host *mmc)
1650
-{
1651
- struct omap_hsmmc_host *host = mmc_priv(mmc);
1652
-
1653
- if (!host->card_detect)
1654
- return -ENOSYS;
1655
- return host->card_detect(host->dev);
1656
-}
1657
-
16581507 static void omap_hsmmc_init_card(struct mmc_host *mmc, struct mmc_card *card)
16591508 {
16601509 struct omap_hsmmc_host *host = mmc_priv(mmc);
16611510
1662
- if (mmc_pdata(host)->init_card)
1663
- mmc_pdata(host)->init_card(card);
1664
- else if (card->type == MMC_TYPE_SDIO ||
1665
- card->type == MMC_TYPE_SD_COMBO) {
1511
+ if (card->type == MMC_TYPE_SDIO || card->type == MMC_TYPE_SD_COMBO) {
16661512 struct device_node *np = mmc_dev(mmc)->of_node;
16671513
16681514 /*
....@@ -1757,12 +1603,6 @@
17571603 ret = PTR_ERR(p);
17581604 goto err_free_irq;
17591605 }
1760
- if (IS_ERR(pinctrl_lookup_state(p, PINCTRL_STATE_DEFAULT))) {
1761
- dev_info(host->dev, "missing default pinctrl state\n");
1762
- devm_pinctrl_put(p);
1763
- ret = -EINVAL;
1764
- goto err_free_irq;
1765
- }
17661606
17671607 if (IS_ERR(pinctrl_lookup_state(p, PINCTRL_STATE_IDLE))) {
17681608 dev_info(host->dev, "missing idle pinctrl state\n");
....@@ -1823,7 +1663,7 @@
18231663 .pre_req = omap_hsmmc_pre_req,
18241664 .request = omap_hsmmc_request,
18251665 .set_ios = omap_hsmmc_set_ios,
1826
- .get_cd = omap_hsmmc_get_cd,
1666
+ .get_cd = mmc_gpio_get_cd,
18271667 .get_ro = mmc_gpio_get_ro,
18281668 .init_card = omap_hsmmc_init_card,
18291669 .enable_sdio_irq = omap_hsmmc_enable_sdio_irq,
....@@ -1831,7 +1671,7 @@
18311671
18321672 #ifdef CONFIG_DEBUG_FS
18331673
1834
-static int omap_hsmmc_regs_show(struct seq_file *s, void *data)
1674
+static int mmc_regs_show(struct seq_file *s, void *data)
18351675 {
18361676 struct mmc_host *mmc = s->private;
18371677 struct omap_hsmmc_host *host = mmc_priv(mmc);
....@@ -1870,17 +1710,7 @@
18701710 return 0;
18711711 }
18721712
1873
-static int omap_hsmmc_regs_open(struct inode *inode, struct file *file)
1874
-{
1875
- return single_open(file, omap_hsmmc_regs_show, inode->i_private);
1876
-}
1877
-
1878
-static const struct file_operations mmc_regs_fops = {
1879
- .open = omap_hsmmc_regs_open,
1880
- .read = seq_read,
1881
- .llseek = seq_lseek,
1882
- .release = single_release,
1883
-};
1713
+DEFINE_SHOW_ATTRIBUTE(mmc_regs);
18841714
18851715 static void omap_hsmmc_debugfs(struct mmc_host *mmc)
18861716 {
....@@ -1950,10 +1780,6 @@
19501780 if (of_find_property(np, "ti,dual-volt", NULL))
19511781 pdata->controller_flags |= OMAP_HSMMC_SUPPORTS_DUAL_VOLT;
19521782
1953
- pdata->gpio_cd = -EINVAL;
1954
- pdata->gpio_cod = -EINVAL;
1955
- pdata->gpio_wp = -EINVAL;
1956
-
19571783 if (of_find_property(np, "ti,non-removable", NULL)) {
19581784 pdata->nonremovable = true;
19591785 pdata->no_regulator_off_init = true;
....@@ -2006,9 +1832,11 @@
20061832 }
20071833
20081834 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2009
- irq = platform_get_irq(pdev, 0);
2010
- if (res == NULL || irq < 0)
1835
+ if (!res)
20111836 return -ENXIO;
1837
+ irq = platform_get_irq(pdev, 0);
1838
+ if (irq < 0)
1839
+ return irq;
20121840
20131841 base = devm_ioremap_resource(&pdev->dev, res);
20141842 if (IS_ERR(base))
....@@ -2037,10 +1865,6 @@
20371865 host->next_data.cookie = 1;
20381866 host->pbias_enabled = 0;
20391867 host->vqmmc_enabled = 0;
2040
-
2041
- ret = omap_hsmmc_gpio_init(mmc, host, pdata);
2042
- if (ret)
2043
- goto err_gpio;
20441868
20451869 platform_set_drvdata(pdev, host);
20461870
....@@ -2098,7 +1922,7 @@
20981922 mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count;
20991923
21001924 mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED |
2101
- MMC_CAP_WAIT_WHILE_BUSY | MMC_CAP_ERASE | MMC_CAP_CMD23;
1925
+ MMC_CAP_WAIT_WHILE_BUSY | MMC_CAP_CMD23;
21021926
21031927 mmc->caps |= mmc_pdata(host)->caps;
21041928 if (mmc->caps & MMC_CAP_8_BIT_DATA)
....@@ -2165,18 +1989,12 @@
21651989 if (!ret)
21661990 mmc->caps |= MMC_CAP_SDIO_IRQ;
21671991
2168
- omap_hsmmc_protect_card(host);
2169
-
2170
- mmc_add_host(mmc);
1992
+ ret = mmc_add_host(mmc);
1993
+ if (ret)
1994
+ goto err_irq;
21711995
21721996 if (mmc_pdata(host)->name != NULL) {
21731997 ret = device_create_file(&mmc->class_dev, &dev_attr_slot_name);
2174
- if (ret < 0)
2175
- goto err_slot_name;
2176
- }
2177
- if (host->get_cover_state) {
2178
- ret = device_create_file(&mmc->class_dev,
2179
- &dev_attr_cover_switch);
21801998 if (ret < 0)
21811999 goto err_slot_name;
21822000 }
....@@ -2198,10 +2016,8 @@
21982016 pm_runtime_dont_use_autosuspend(host->dev);
21992017 pm_runtime_put_sync(host->dev);
22002018 pm_runtime_disable(host->dev);
2201
- if (host->dbclk)
2202
- clk_disable_unprepare(host->dbclk);
2019
+ clk_disable_unprepare(host->dbclk);
22032020 err1:
2204
-err_gpio:
22052021 mmc_free_host(mmc);
22062022 err:
22072023 return ret;
....@@ -2222,8 +2038,7 @@
22222038 pm_runtime_put_sync(host->dev);
22232039 pm_runtime_disable(host->dev);
22242040 device_init_wakeup(&pdev->dev, false);
2225
- if (host->dbclk)
2226
- clk_disable_unprepare(host->dbclk);
2041
+ clk_disable_unprepare(host->dbclk);
22272042
22282043 mmc_free_host(host->mmc);
22292044
....@@ -2248,8 +2063,7 @@
22482063 OMAP_HSMMC_READ(host->base, HCTL) & ~SDBP);
22492064 }
22502065
2251
- if (host->dbclk)
2252
- clk_disable_unprepare(host->dbclk);
2066
+ clk_disable_unprepare(host->dbclk);
22532067
22542068 pm_runtime_put_sync(host->dev);
22552069 return 0;
....@@ -2265,13 +2079,11 @@
22652079
22662080 pm_runtime_get_sync(host->dev);
22672081
2268
- if (host->dbclk)
2269
- clk_prepare_enable(host->dbclk);
2082
+ clk_prepare_enable(host->dbclk);
22702083
22712084 if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER))
22722085 omap_hsmmc_conf_bus_power(host);
22732086
2274
- omap_hsmmc_protect_card(host);
22752087 pm_runtime_mark_last_busy(host->dev);
22762088 pm_runtime_put_autosuspend(host->dev);
22772089 return 0;
....@@ -2284,7 +2096,7 @@
22842096 unsigned long flags;
22852097 int ret = 0;
22862098
2287
- host = platform_get_drvdata(to_platform_device(dev));
2099
+ host = dev_get_drvdata(dev);
22882100 omap_hsmmc_context_save(host);
22892101 dev_dbg(dev, "disabled\n");
22902102
....@@ -2325,7 +2137,7 @@
23252137 struct omap_hsmmc_host *host;
23262138 unsigned long flags;
23272139
2328
- host = platform_get_drvdata(to_platform_device(dev));
2140
+ host = dev_get_drvdata(dev);
23292141 omap_hsmmc_context_restore(host);
23302142 dev_dbg(dev, "enabled\n");
23312143
....@@ -2333,14 +2145,14 @@
23332145 if ((host->mmc->caps & MMC_CAP_SDIO_IRQ) &&
23342146 (host->flags & HSMMC_SDIO_IRQ_ENABLED)) {
23352147
2336
- pinctrl_pm_select_default_state(host->dev);
2148
+ pinctrl_select_default_state(host->dev);
23372149
23382150 /* irq lost, if pinmux incorrect */
23392151 OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
23402152 OMAP_HSMMC_WRITE(host->base, ISE, CIRQ_EN);
23412153 OMAP_HSMMC_WRITE(host->base, IE, CIRQ_EN);
23422154 } else {
2343
- pinctrl_pm_select_default_state(host->dev);
2155
+ pinctrl_select_default_state(host->dev);
23442156 }
23452157 spin_unlock_irqrestore(&host->irq_lock, flags);
23462158 return 0;