hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/mmc/host/s3cmci.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * linux/drivers/mmc/s3cmci.h - Samsung S3C MCI driver
34 *
....@@ -5,10 +6,6 @@
56 *
67 * Current driver maintained by Ben Dooks and Simtec Electronics
78 * Copyright (C) 2008 Simtec Electronics <ben-linux@fluff.org>
8
- *
9
- * This program is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License version 2 as
11
- * published by the Free Software Foundation.
129 */
1310
1411 #include <linux/module.h>
....@@ -26,13 +23,7 @@
2623 #include <linux/io.h>
2724 #include <linux/of.h>
2825 #include <linux/of_device.h>
29
-#include <linux/of_gpio.h>
3026 #include <linux/mmc/slot-gpio.h>
31
-
32
-#include <plat/gpio-cfg.h>
33
-#include <mach/dma.h>
34
-#include <mach/gpio-samsung.h>
35
-
3627 #include <linux/platform_data/mmc-s3cmci.h>
3728
3829 #include "s3cmci.h"
....@@ -154,8 +145,8 @@
154145
155146 static void dbg_dumpregs(struct s3cmci_host *host, char *prefix)
156147 {
157
- u32 con, pre, cmdarg, cmdcon, cmdsta, r0, r1, r2, r3, timer, bsize;
158
- u32 datcon, datcnt, datsta, fsta, imask;
148
+ u32 con, pre, cmdarg, cmdcon, cmdsta, r0, r1, r2, r3, timer;
149
+ u32 datcon, datcnt, datsta, fsta;
159150
160151 con = readl(host->base + S3C2410_SDICON);
161152 pre = readl(host->base + S3C2410_SDIPRE);
....@@ -167,12 +158,10 @@
167158 r2 = readl(host->base + S3C2410_SDIRSP2);
168159 r3 = readl(host->base + S3C2410_SDIRSP3);
169160 timer = readl(host->base + S3C2410_SDITIMER);
170
- bsize = readl(host->base + S3C2410_SDIBSIZE);
171161 datcon = readl(host->base + S3C2410_SDIDCON);
172162 datcnt = readl(host->base + S3C2410_SDIDCNT);
173163 datsta = readl(host->base + S3C2410_SDIDSTA);
174164 fsta = readl(host->base + S3C2410_SDIFSTA);
175
- imask = readl(host->base + host->sdiimsk);
176165
177166 dbg(host, dbg_debug, "%s CON:[%08x] PRE:[%08x] TMR:[%08x]\n",
178167 prefix, con, pre, timer);
....@@ -311,7 +300,8 @@
311300 static void s3cmci_check_sdio_irq(struct s3cmci_host *host)
312301 {
313302 if (host->sdio_irqen) {
314
- if (gpio_get_value(S3C2410_GPE(8)) == 0) {
303
+ if (host->pdata->bus[3] &&
304
+ gpiod_get_value(host->pdata->bus[3]) == 0) {
315305 pr_debug("%s: signalling irq\n", __func__);
316306 mmc_signal_sdio_irq(host->mmc);
317307 }
....@@ -400,9 +390,6 @@
400390 local_irq_restore(flags);
401391 }
402392
403
-/**
404
- *
405
- */
406393 static void s3cmci_disable_irq(struct s3cmci_host *host, bool transfer)
407394 {
408395 unsigned long flags;
....@@ -962,13 +949,6 @@
962949 {
963950 u32 dcon, imsk, stoptries = 3;
964951
965
- /* write DCON register */
966
-
967
- if (!data) {
968
- writel(0, host->base + S3C2410_SDIDCON);
969
- return 0;
970
- }
971
-
972952 if ((data->blksz & 3) != 0) {
973953 /* We cannot deal with unaligned blocks with more than
974954 * one block being transferred. */
....@@ -1217,32 +1197,19 @@
12171197 switch (ios->power_mode) {
12181198 case MMC_POWER_ON:
12191199 case MMC_POWER_UP:
1220
- /* Configure GPE5...GPE10 pins in SD mode */
1221
- if (!host->pdev->dev.of_node)
1222
- s3c_gpio_cfgall_range(S3C2410_GPE(5), 6, S3C_GPIO_SFN(2),
1223
- S3C_GPIO_PULL_NONE);
1224
-
1225
- if (host->pdata->set_power)
1226
- host->pdata->set_power(ios->power_mode, ios->vdd);
1227
-
12281200 if (!host->is2440)
12291201 mci_con |= S3C2410_SDICON_FIFORESET;
1230
-
12311202 break;
12321203
12331204 case MMC_POWER_OFF:
12341205 default:
1235
- if (!host->pdev->dev.of_node)
1236
- gpio_direction_output(S3C2410_GPE(5), 0);
1237
-
12381206 if (host->is2440)
12391207 mci_con |= S3C2440_SDICON_SDRESET;
1240
-
1241
- if (host->pdata->set_power)
1242
- host->pdata->set_power(ios->power_mode, ios->vdd);
1243
-
12441208 break;
12451209 }
1210
+
1211
+ if (host->pdata->set_power)
1212
+ host->pdata->set_power(ios->power_mode, ios->vdd);
12461213
12471214 s3cmci_set_clk(host, ios);
12481215
....@@ -1321,13 +1288,6 @@
13211288 .enable_sdio_irq = s3cmci_enable_sdio_irq,
13221289 };
13231290
1324
-static struct s3c24xx_mci_pdata s3cmci_def_pdata = {
1325
- /* This is currently here to avoid a number of if (host->pdata)
1326
- * checks. Any zero fields to ensure reasonable defaults are picked. */
1327
- .no_wprotect = 1,
1328
- .no_detect = 1,
1329
-};
1330
-
13311291 #ifdef CONFIG_ARM_S3C24XX_CPUFREQ
13321292
13331293 static int s3cmci_cpufreq_transition(struct notifier_block *nb,
....@@ -1390,7 +1350,7 @@
13901350 {
13911351 struct s3cmci_host *host = seq->private;
13921352
1393
- seq_printf(seq, "Register base = 0x%08x\n", (u32)host->base);
1353
+ seq_printf(seq, "Register base = 0x%p\n", host->base);
13941354 seq_printf(seq, "Clock rate = %ld\n", host->clk_rate);
13951355 seq_printf(seq, "Prescale = %d\n", host->prescaler);
13961356 seq_printf(seq, "is2440 = %d\n", host->is2440);
....@@ -1406,18 +1366,7 @@
14061366 return 0;
14071367 }
14081368
1409
-static int s3cmci_state_open(struct inode *inode, struct file *file)
1410
-{
1411
- return single_open(file, s3cmci_state_show, inode->i_private);
1412
-}
1413
-
1414
-static const struct file_operations s3cmci_fops_state = {
1415
- .owner = THIS_MODULE,
1416
- .open = s3cmci_state_open,
1417
- .read = seq_read,
1418
- .llseek = seq_lseek,
1419
- .release = single_release,
1420
-};
1369
+DEFINE_SHOW_ATTRIBUTE(s3cmci_state);
14211370
14221371 #define DBG_REG(_r) { .addr = S3C2410_SDI##_r, .name = #_r }
14231372
....@@ -1459,49 +1408,23 @@
14591408 return 0;
14601409 }
14611410
1462
-static int s3cmci_regs_open(struct inode *inode, struct file *file)
1463
-{
1464
- return single_open(file, s3cmci_regs_show, inode->i_private);
1465
-}
1466
-
1467
-static const struct file_operations s3cmci_fops_regs = {
1468
- .owner = THIS_MODULE,
1469
- .open = s3cmci_regs_open,
1470
- .read = seq_read,
1471
- .llseek = seq_lseek,
1472
- .release = single_release,
1473
-};
1411
+DEFINE_SHOW_ATTRIBUTE(s3cmci_regs);
14741412
14751413 static void s3cmci_debugfs_attach(struct s3cmci_host *host)
14761414 {
14771415 struct device *dev = &host->pdev->dev;
1416
+ struct dentry *root;
14781417
1479
- host->debug_root = debugfs_create_dir(dev_name(dev), NULL);
1480
- if (IS_ERR(host->debug_root)) {
1481
- dev_err(dev, "failed to create debugfs root\n");
1482
- return;
1483
- }
1418
+ root = debugfs_create_dir(dev_name(dev), NULL);
1419
+ host->debug_root = root;
14841420
1485
- host->debug_state = debugfs_create_file("state", 0444,
1486
- host->debug_root, host,
1487
- &s3cmci_fops_state);
1488
-
1489
- if (IS_ERR(host->debug_state))
1490
- dev_err(dev, "failed to create debug state file\n");
1491
-
1492
- host->debug_regs = debugfs_create_file("regs", 0444,
1493
- host->debug_root, host,
1494
- &s3cmci_fops_regs);
1495
-
1496
- if (IS_ERR(host->debug_regs))
1497
- dev_err(dev, "failed to create debug regs file\n");
1421
+ debugfs_create_file("state", 0444, root, host, &s3cmci_state_fops);
1422
+ debugfs_create_file("regs", 0444, root, host, &s3cmci_regs_fops);
14981423 }
14991424
15001425 static void s3cmci_debugfs_remove(struct s3cmci_host *host)
15011426 {
1502
- debugfs_remove(host->debug_regs);
1503
- debugfs_remove(host->debug_state);
1504
- debugfs_remove(host->debug_root);
1427
+ debugfs_remove_recursive(host->debug_root);
15051428 }
15061429
15071430 #else
....@@ -1518,23 +1441,20 @@
15181441 int i, ret;
15191442
15201443 host->is2440 = platform_get_device_id(pdev)->driver_data;
1521
-
1522
- for (i = S3C2410_GPE(5); i <= S3C2410_GPE(10); i++) {
1523
- ret = gpio_request(i, dev_name(&pdev->dev));
1524
- if (ret) {
1525
- dev_err(&pdev->dev, "failed to get gpio %d\n", i);
1526
-
1527
- for (i--; i >= S3C2410_GPE(5); i--)
1528
- gpio_free(i);
1529
-
1530
- return ret;
1531
- }
1444
+ pdata = pdev->dev.platform_data;
1445
+ if (!pdata) {
1446
+ dev_err(&pdev->dev, "need platform data");
1447
+ return -ENXIO;
15321448 }
15331449
1534
- if (!pdev->dev.platform_data)
1535
- pdev->dev.platform_data = &s3cmci_def_pdata;
1536
-
1537
- pdata = pdev->dev.platform_data;
1450
+ for (i = 0; i < 6; i++) {
1451
+ pdata->bus[i] = devm_gpiod_get_index(&pdev->dev, "bus", i,
1452
+ GPIOD_OUT_LOW);
1453
+ if (IS_ERR(pdata->bus[i])) {
1454
+ dev_err(&pdev->dev, "failed to get gpio %d\n", i);
1455
+ return PTR_ERR(pdata->bus[i]);
1456
+ }
1457
+ }
15381458
15391459 if (pdata->no_wprotect)
15401460 mmc->caps2 |= MMC_CAP2_NO_WRITE_PROTECT;
....@@ -1545,25 +1465,19 @@
15451465 if (pdata->wprotect_invert)
15461466 mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;
15471467
1548
- if (pdata->detect_invert)
1549
- mmc->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH;
1550
-
1551
- if (gpio_is_valid(pdata->gpio_detect)) {
1552
- ret = mmc_gpio_request_cd(mmc, pdata->gpio_detect, 0);
1553
- if (ret) {
1554
- dev_err(&pdev->dev, "error requesting GPIO for CD %d\n",
1555
- ret);
1556
- return ret;
1557
- }
1468
+ /* If we get -ENOENT we have no card detect GPIO line */
1469
+ ret = mmc_gpiod_request_cd(mmc, "cd", 0, false, 0);
1470
+ if (ret != -ENOENT) {
1471
+ dev_err(&pdev->dev, "error requesting GPIO for CD %d\n",
1472
+ ret);
1473
+ return ret;
15581474 }
15591475
1560
- if (gpio_is_valid(pdata->gpio_wprotect)) {
1561
- ret = mmc_gpio_request_ro(mmc, pdata->gpio_wprotect);
1562
- if (ret) {
1563
- dev_err(&pdev->dev, "error requesting GPIO for WP %d\n",
1564
- ret);
1565
- return ret;
1566
- }
1476
+ ret = mmc_gpiod_request_ro(host->mmc, "wp", 0, 0);
1477
+ if (ret != -ENOENT) {
1478
+ dev_err(&pdev->dev, "error requesting GPIO for WP %d\n",
1479
+ ret);
1480
+ return ret;
15671481 }
15681482
15691483 return 0;
....@@ -1576,7 +1490,7 @@
15761490 struct mmc_host *mmc = host->mmc;
15771491 int ret;
15781492
1579
- host->is2440 = (int) of_device_get_match_data(&pdev->dev);
1493
+ host->is2440 = (long) of_device_get_match_data(&pdev->dev);
15801494
15811495 ret = mmc_of_parse(mmc);
15821496 if (ret)
....@@ -1596,7 +1510,6 @@
15961510 struct s3cmci_host *host;
15971511 struct mmc_host *mmc;
15981512 int ret;
1599
- int i;
16001513
16011514 mmc = mmc_alloc_host(sizeof(struct s3cmci_host), &pdev->dev);
16021515 if (!mmc) {
....@@ -1640,7 +1553,7 @@
16401553 "failed to get io memory region resource.\n");
16411554
16421555 ret = -ENOENT;
1643
- goto probe_free_gpio;
1556
+ goto probe_free_host;
16441557 }
16451558
16461559 host->mem = request_mem_region(host->mem->start,
....@@ -1649,7 +1562,7 @@
16491562 if (!host->mem) {
16501563 dev_err(&pdev->dev, "failed to request io memory region.\n");
16511564 ret = -ENOENT;
1652
- goto probe_free_gpio;
1565
+ goto probe_free_host;
16531566 }
16541567
16551568 host->base = ioremap(host->mem->start, resource_size(host->mem));
....@@ -1661,7 +1574,6 @@
16611574
16621575 host->irq = platform_get_irq(pdev, 0);
16631576 if (host->irq <= 0) {
1664
- dev_err(&pdev->dev, "failed to get interrupt resource.\n");
16651577 ret = -EINVAL;
16661578 goto probe_iounmap;
16671579 }
....@@ -1774,11 +1686,6 @@
17741686 probe_free_mem_region:
17751687 release_mem_region(host->mem->start, resource_size(host->mem));
17761688
1777
- probe_free_gpio:
1778
- if (!pdev->dev.of_node)
1779
- for (i = S3C2410_GPE(5); i <= S3C2410_GPE(10); i++)
1780
- gpio_free(i);
1781
-
17821689 probe_free_host:
17831690 mmc_free_host(mmc);
17841691
....@@ -1804,7 +1711,6 @@
18041711 {
18051712 struct mmc_host *mmc = platform_get_drvdata(pdev);
18061713 struct s3cmci_host *host = mmc_priv(mmc);
1807
- int i;
18081714
18091715 s3cmci_shutdown(pdev);
18101716
....@@ -1816,10 +1722,6 @@
18161722 dma_release_channel(host->dma);
18171723
18181724 free_irq(host->irq, host);
1819
-
1820
- if (!pdev->dev.of_node)
1821
- for (i = S3C2410_GPE(5); i <= S3C2410_GPE(10); i++)
1822
- gpio_free(i);
18231725
18241726 iounmap(host->base);
18251727 release_mem_region(host->mem->start, resource_size(host->mem));