hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/drivers/mmc/host/atmel-mci.c
....@@ -1,11 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Atmel MultiMedia Card Interface driver
34 *
45 * Copyright (C) 2004-2008 Atmel Corporation
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 #include <linux/blkdev.h>
118 #include <linux/clk.h>
....@@ -172,6 +169,7 @@
172169 #define atmci_writel(port, reg, value) \
173170 __raw_writel((value), (port)->regs + reg)
174171
172
+#define ATMCI_CMD_TIMEOUT_MS 2000
175173 #define AUTOSUSPEND_DELAY 50
176174
177175 #define ATMCI_DATA_ERROR_FLAGS (ATMCI_DCRCE | ATMCI_DTOE | ATMCI_OVRE | ATMCI_UNRE)
....@@ -227,12 +225,13 @@
227225 * @lock: Spinlock protecting the queue and associated data.
228226 * @regs: Pointer to MMIO registers.
229227 * @sg: Scatterlist entry currently being processed by PIO or PDC code.
228
+ * @sg_len: Size of the scatterlist
230229 * @pio_offset: Offset into the current scatterlist entry.
231230 * @buffer: Buffer used if we don't have the r/w proof capability. We
232231 * don't have the time to switch pdc buffers so we have to use only
233232 * one buffer for the full transaction.
234233 * @buf_size: size of the buffer.
235
- * @phys_buf_addr: buffer address needed for pdc.
234
+ * @buf_phys_addr: buffer address needed for pdc.
236235 * @cur_slot: The slot which is currently using the controller.
237236 * @mrq: The request currently being processed on @cur_slot,
238237 * or NULL if the controller is idle.
....@@ -242,6 +241,7 @@
242241 * @data_size: just data->blocks * data->blksz.
243242 * @dma: DMA client state.
244243 * @data_chan: DMA channel being used for the current data transfer.
244
+ * @dma_conf: Configuration for the DMA slave
245245 * @cmd_status: Snapshot of SR taken upon completion of the current
246246 * command. Only valid when EVENT_CMD_COMPLETE is pending.
247247 * @data_status: Snapshot of SR taken upon completion of the current
....@@ -446,18 +446,7 @@
446446 return 0;
447447 }
448448
449
-static int atmci_req_open(struct inode *inode, struct file *file)
450
-{
451
- return single_open(file, atmci_req_show, inode->i_private);
452
-}
453
-
454
-static const struct file_operations atmci_req_fops = {
455
- .owner = THIS_MODULE,
456
- .open = atmci_req_open,
457
- .read = seq_read,
458
- .llseek = seq_lseek,
459
- .release = single_release,
460
-};
449
+DEFINE_SHOW_ATTRIBUTE(atmci_req);
461450
462451 static void atmci_show_status_reg(struct seq_file *s,
463452 const char *regname, u32 value)
....@@ -583,59 +572,25 @@
583572 return ret;
584573 }
585574
586
-static int atmci_regs_open(struct inode *inode, struct file *file)
587
-{
588
- return single_open(file, atmci_regs_show, inode->i_private);
589
-}
590
-
591
-static const struct file_operations atmci_regs_fops = {
592
- .owner = THIS_MODULE,
593
- .open = atmci_regs_open,
594
- .read = seq_read,
595
- .llseek = seq_lseek,
596
- .release = single_release,
597
-};
575
+DEFINE_SHOW_ATTRIBUTE(atmci_regs);
598576
599577 static void atmci_init_debugfs(struct atmel_mci_slot *slot)
600578 {
601579 struct mmc_host *mmc = slot->mmc;
602580 struct atmel_mci *host = slot->host;
603581 struct dentry *root;
604
- struct dentry *node;
605582
606583 root = mmc->debugfs_root;
607584 if (!root)
608585 return;
609586
610
- node = debugfs_create_file("regs", S_IRUSR, root, host,
611
- &atmci_regs_fops);
612
- if (IS_ERR(node))
613
- return;
614
- if (!node)
615
- goto err;
616
-
617
- node = debugfs_create_file("req", S_IRUSR, root, slot, &atmci_req_fops);
618
- if (!node)
619
- goto err;
620
-
621
- node = debugfs_create_u32("state", S_IRUSR, root, (u32 *)&host->state);
622
- if (!node)
623
- goto err;
624
-
625
- node = debugfs_create_x32("pending_events", S_IRUSR, root,
626
- (u32 *)&host->pending_events);
627
- if (!node)
628
- goto err;
629
-
630
- node = debugfs_create_x32("completed_events", S_IRUSR, root,
631
- (u32 *)&host->completed_events);
632
- if (!node)
633
- goto err;
634
-
635
- return;
636
-
637
-err:
638
- dev_err(&mmc->class_dev, "failed to initialize debugfs for slot\n");
587
+ debugfs_create_file("regs", S_IRUSR, root, host, &atmci_regs_fops);
588
+ debugfs_create_file("req", S_IRUSR, root, slot, &atmci_req_fops);
589
+ debugfs_create_u32("state", S_IRUSR, root, &host->state);
590
+ debugfs_create_xul("pending_events", S_IRUSR, root,
591
+ &host->pending_events);
592
+ debugfs_create_xul("completed_events", S_IRUSR, root,
593
+ &host->completed_events);
639594 }
640595
641596 #if defined(CONFIG_OF)
....@@ -856,6 +811,9 @@
856811 static void atmci_send_command(struct atmel_mci *host,
857812 struct mmc_command *cmd, u32 cmd_flags)
858813 {
814
+ unsigned int timeout_ms = cmd->busy_timeout ? cmd->busy_timeout :
815
+ ATMCI_CMD_TIMEOUT_MS;
816
+
859817 WARN_ON(host->cmd);
860818 host->cmd = cmd;
861819
....@@ -865,6 +823,8 @@
865823
866824 atmci_writel(host, ATMCI_ARGR, cmd->arg);
867825 atmci_writel(host, ATMCI_CMDR, cmd_flags);
826
+
827
+ mod_timer(&host->timer, jiffies + msecs_to_jiffies(timeout_ms));
868828 }
869829
870830 static void atmci_send_stop_cmd(struct atmel_mci *host, struct mmc_data *data)
....@@ -1362,8 +1322,6 @@
13621322 * prepared yet.)
13631323 */
13641324 atmci_writel(host, ATMCI_IER, iflags);
1365
-
1366
- mod_timer(&host->timer, jiffies + msecs_to_jiffies(2000));
13671325 }
13681326
13691327 static void atmci_queue_request(struct atmel_mci *host,
....@@ -1430,6 +1388,9 @@
14301388 break;
14311389 case MMC_BUS_WIDTH_4:
14321390 slot->sdc_reg |= ATMCI_SDCBUS_4BIT;
1391
+ break;
1392
+ case MMC_BUS_WIDTH_8:
1393
+ slot->sdc_reg |= ATMCI_SDCBUS_8BIT;
14331394 break;
14341395 }
14351396
....@@ -1602,6 +1563,8 @@
16021563
16031564 WARN_ON(host->cmd || host->data);
16041565
1566
+ del_timer(&host->timer);
1567
+
16051568 /*
16061569 * Update the MMC clock rate if necessary. This may be
16071570 * necessary if set_ios() is called when a different slot is
....@@ -1627,8 +1590,6 @@
16271590 dev_vdbg(&host->pdev->dev, "list empty\n");
16281591 host->state = STATE_IDLE;
16291592 }
1630
-
1631
- del_timer(&host->timer);
16321593
16331594 spin_unlock(&host->lock);
16341595 mmc_request_done(prev_mmc, mrq);
....@@ -2296,8 +2257,11 @@
22962257 * use only one bit for data to prevent fifo underruns and overruns
22972258 * which will corrupt data.
22982259 */
2299
- if ((slot_data->bus_width >= 4) && host->caps.has_rwproof)
2260
+ if ((slot_data->bus_width >= 4) && host->caps.has_rwproof) {
23002261 mmc->caps |= MMC_CAP_4_BIT_DATA;
2262
+ if (slot_data->bus_width >= 8)
2263
+ mmc->caps |= MMC_CAP_8_BIT_DATA;
2264
+ }
23012265
23022266 if (atmci_get_version(host) < 0x200) {
23032267 mmc->max_segs = 256;
....@@ -2389,8 +2353,7 @@
23892353
23902354 static int atmci_configure_dma(struct atmel_mci *host)
23912355 {
2392
- host->dma.chan = dma_request_slave_channel_reason(&host->pdev->dev,
2393
- "rxtx");
2356
+ host->dma.chan = dma_request_chan(&host->pdev->dev, "rxtx");
23942357
23952358 if (PTR_ERR(host->dma.chan) == -ENODEV) {
23962359 struct mci_platform_data *pdata = host->pdev->dev.platform_data;
....@@ -2455,6 +2418,7 @@
24552418 case 0x600:
24562419 case 0x500:
24572420 host->caps.has_odd_clk_div = 1;
2421
+ fallthrough;
24582422 case 0x400:
24592423 case 0x300:
24602424 host->caps.has_dma_conf_reg = 1;
....@@ -2462,13 +2426,16 @@
24622426 host->caps.has_cfg_reg = 1;
24632427 host->caps.has_cstor_reg = 1;
24642428 host->caps.has_highspeed = 1;
2429
+ fallthrough;
24652430 case 0x200:
24662431 host->caps.has_rwproof = 1;
24672432 host->caps.need_blksz_mul_4 = 0;
24682433 host->caps.need_notbusy_for_read_ops = 1;
2434
+ fallthrough;
24692435 case 0x100:
24702436 host->caps.has_bad_data_ordering = 0;
24712437 host->caps.need_reset_after_xfer = 0;
2438
+ fallthrough;
24722439 case 0x0:
24732440 break;
24742441 default:
....@@ -2684,7 +2651,7 @@
26842651 {
26852652 struct atmel_mci *host = dev_get_drvdata(dev);
26862653
2687
- pinctrl_pm_select_default_state(dev);
2654
+ pinctrl_select_default_state(dev);
26882655
26892656 return clk_prepare_enable(host->mck);
26902657 }
....@@ -2701,6 +2668,7 @@
27012668 .remove = atmci_remove,
27022669 .driver = {
27032670 .name = "atmel_mci",
2671
+ .probe_type = PROBE_PREFER_ASYNCHRONOUS,
27042672 .of_match_table = of_match_ptr(atmci_dt_ids),
27052673 .pm = &atmci_dev_pm_ops,
27062674 },