.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Atmel MultiMedia Card Interface driver |
---|
3 | 4 | * |
---|
4 | 5 | * 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. |
---|
9 | 6 | */ |
---|
10 | 7 | #include <linux/blkdev.h> |
---|
11 | 8 | #include <linux/clk.h> |
---|
.. | .. |
---|
172 | 169 | #define atmci_writel(port, reg, value) \ |
---|
173 | 170 | __raw_writel((value), (port)->regs + reg) |
---|
174 | 171 | |
---|
| 172 | +#define ATMCI_CMD_TIMEOUT_MS 2000 |
---|
175 | 173 | #define AUTOSUSPEND_DELAY 50 |
---|
176 | 174 | |
---|
177 | 175 | #define ATMCI_DATA_ERROR_FLAGS (ATMCI_DCRCE | ATMCI_DTOE | ATMCI_OVRE | ATMCI_UNRE) |
---|
.. | .. |
---|
227 | 225 | * @lock: Spinlock protecting the queue and associated data. |
---|
228 | 226 | * @regs: Pointer to MMIO registers. |
---|
229 | 227 | * @sg: Scatterlist entry currently being processed by PIO or PDC code. |
---|
| 228 | + * @sg_len: Size of the scatterlist |
---|
230 | 229 | * @pio_offset: Offset into the current scatterlist entry. |
---|
231 | 230 | * @buffer: Buffer used if we don't have the r/w proof capability. We |
---|
232 | 231 | * don't have the time to switch pdc buffers so we have to use only |
---|
233 | 232 | * one buffer for the full transaction. |
---|
234 | 233 | * @buf_size: size of the buffer. |
---|
235 | | - * @phys_buf_addr: buffer address needed for pdc. |
---|
| 234 | + * @buf_phys_addr: buffer address needed for pdc. |
---|
236 | 235 | * @cur_slot: The slot which is currently using the controller. |
---|
237 | 236 | * @mrq: The request currently being processed on @cur_slot, |
---|
238 | 237 | * or NULL if the controller is idle. |
---|
.. | .. |
---|
242 | 241 | * @data_size: just data->blocks * data->blksz. |
---|
243 | 242 | * @dma: DMA client state. |
---|
244 | 243 | * @data_chan: DMA channel being used for the current data transfer. |
---|
| 244 | + * @dma_conf: Configuration for the DMA slave |
---|
245 | 245 | * @cmd_status: Snapshot of SR taken upon completion of the current |
---|
246 | 246 | * command. Only valid when EVENT_CMD_COMPLETE is pending. |
---|
247 | 247 | * @data_status: Snapshot of SR taken upon completion of the current |
---|
.. | .. |
---|
446 | 446 | return 0; |
---|
447 | 447 | } |
---|
448 | 448 | |
---|
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); |
---|
461 | 450 | |
---|
462 | 451 | static void atmci_show_status_reg(struct seq_file *s, |
---|
463 | 452 | const char *regname, u32 value) |
---|
.. | .. |
---|
583 | 572 | return ret; |
---|
584 | 573 | } |
---|
585 | 574 | |
---|
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); |
---|
598 | 576 | |
---|
599 | 577 | static void atmci_init_debugfs(struct atmel_mci_slot *slot) |
---|
600 | 578 | { |
---|
601 | 579 | struct mmc_host *mmc = slot->mmc; |
---|
602 | 580 | struct atmel_mci *host = slot->host; |
---|
603 | 581 | struct dentry *root; |
---|
604 | | - struct dentry *node; |
---|
605 | 582 | |
---|
606 | 583 | root = mmc->debugfs_root; |
---|
607 | 584 | if (!root) |
---|
608 | 585 | return; |
---|
609 | 586 | |
---|
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); |
---|
639 | 594 | } |
---|
640 | 595 | |
---|
641 | 596 | #if defined(CONFIG_OF) |
---|
.. | .. |
---|
856 | 811 | static void atmci_send_command(struct atmel_mci *host, |
---|
857 | 812 | struct mmc_command *cmd, u32 cmd_flags) |
---|
858 | 813 | { |
---|
| 814 | + unsigned int timeout_ms = cmd->busy_timeout ? cmd->busy_timeout : |
---|
| 815 | + ATMCI_CMD_TIMEOUT_MS; |
---|
| 816 | + |
---|
859 | 817 | WARN_ON(host->cmd); |
---|
860 | 818 | host->cmd = cmd; |
---|
861 | 819 | |
---|
.. | .. |
---|
865 | 823 | |
---|
866 | 824 | atmci_writel(host, ATMCI_ARGR, cmd->arg); |
---|
867 | 825 | atmci_writel(host, ATMCI_CMDR, cmd_flags); |
---|
| 826 | + |
---|
| 827 | + mod_timer(&host->timer, jiffies + msecs_to_jiffies(timeout_ms)); |
---|
868 | 828 | } |
---|
869 | 829 | |
---|
870 | 830 | static void atmci_send_stop_cmd(struct atmel_mci *host, struct mmc_data *data) |
---|
.. | .. |
---|
1362 | 1322 | * prepared yet.) |
---|
1363 | 1323 | */ |
---|
1364 | 1324 | atmci_writel(host, ATMCI_IER, iflags); |
---|
1365 | | - |
---|
1366 | | - mod_timer(&host->timer, jiffies + msecs_to_jiffies(2000)); |
---|
1367 | 1325 | } |
---|
1368 | 1326 | |
---|
1369 | 1327 | static void atmci_queue_request(struct atmel_mci *host, |
---|
.. | .. |
---|
1430 | 1388 | break; |
---|
1431 | 1389 | case MMC_BUS_WIDTH_4: |
---|
1432 | 1390 | slot->sdc_reg |= ATMCI_SDCBUS_4BIT; |
---|
| 1391 | + break; |
---|
| 1392 | + case MMC_BUS_WIDTH_8: |
---|
| 1393 | + slot->sdc_reg |= ATMCI_SDCBUS_8BIT; |
---|
1433 | 1394 | break; |
---|
1434 | 1395 | } |
---|
1435 | 1396 | |
---|
.. | .. |
---|
1602 | 1563 | |
---|
1603 | 1564 | WARN_ON(host->cmd || host->data); |
---|
1604 | 1565 | |
---|
| 1566 | + del_timer(&host->timer); |
---|
| 1567 | + |
---|
1605 | 1568 | /* |
---|
1606 | 1569 | * Update the MMC clock rate if necessary. This may be |
---|
1607 | 1570 | * necessary if set_ios() is called when a different slot is |
---|
.. | .. |
---|
1627 | 1590 | dev_vdbg(&host->pdev->dev, "list empty\n"); |
---|
1628 | 1591 | host->state = STATE_IDLE; |
---|
1629 | 1592 | } |
---|
1630 | | - |
---|
1631 | | - del_timer(&host->timer); |
---|
1632 | 1593 | |
---|
1633 | 1594 | spin_unlock(&host->lock); |
---|
1634 | 1595 | mmc_request_done(prev_mmc, mrq); |
---|
.. | .. |
---|
2296 | 2257 | * use only one bit for data to prevent fifo underruns and overruns |
---|
2297 | 2258 | * which will corrupt data. |
---|
2298 | 2259 | */ |
---|
2299 | | - if ((slot_data->bus_width >= 4) && host->caps.has_rwproof) |
---|
| 2260 | + if ((slot_data->bus_width >= 4) && host->caps.has_rwproof) { |
---|
2300 | 2261 | mmc->caps |= MMC_CAP_4_BIT_DATA; |
---|
| 2262 | + if (slot_data->bus_width >= 8) |
---|
| 2263 | + mmc->caps |= MMC_CAP_8_BIT_DATA; |
---|
| 2264 | + } |
---|
2301 | 2265 | |
---|
2302 | 2266 | if (atmci_get_version(host) < 0x200) { |
---|
2303 | 2267 | mmc->max_segs = 256; |
---|
.. | .. |
---|
2389 | 2353 | |
---|
2390 | 2354 | static int atmci_configure_dma(struct atmel_mci *host) |
---|
2391 | 2355 | { |
---|
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"); |
---|
2394 | 2357 | |
---|
2395 | 2358 | if (PTR_ERR(host->dma.chan) == -ENODEV) { |
---|
2396 | 2359 | struct mci_platform_data *pdata = host->pdev->dev.platform_data; |
---|
.. | .. |
---|
2455 | 2418 | case 0x600: |
---|
2456 | 2419 | case 0x500: |
---|
2457 | 2420 | host->caps.has_odd_clk_div = 1; |
---|
| 2421 | + fallthrough; |
---|
2458 | 2422 | case 0x400: |
---|
2459 | 2423 | case 0x300: |
---|
2460 | 2424 | host->caps.has_dma_conf_reg = 1; |
---|
.. | .. |
---|
2462 | 2426 | host->caps.has_cfg_reg = 1; |
---|
2463 | 2427 | host->caps.has_cstor_reg = 1; |
---|
2464 | 2428 | host->caps.has_highspeed = 1; |
---|
| 2429 | + fallthrough; |
---|
2465 | 2430 | case 0x200: |
---|
2466 | 2431 | host->caps.has_rwproof = 1; |
---|
2467 | 2432 | host->caps.need_blksz_mul_4 = 0; |
---|
2468 | 2433 | host->caps.need_notbusy_for_read_ops = 1; |
---|
| 2434 | + fallthrough; |
---|
2469 | 2435 | case 0x100: |
---|
2470 | 2436 | host->caps.has_bad_data_ordering = 0; |
---|
2471 | 2437 | host->caps.need_reset_after_xfer = 0; |
---|
| 2438 | + fallthrough; |
---|
2472 | 2439 | case 0x0: |
---|
2473 | 2440 | break; |
---|
2474 | 2441 | default: |
---|
.. | .. |
---|
2684 | 2651 | { |
---|
2685 | 2652 | struct atmel_mci *host = dev_get_drvdata(dev); |
---|
2686 | 2653 | |
---|
2687 | | - pinctrl_pm_select_default_state(dev); |
---|
| 2654 | + pinctrl_select_default_state(dev); |
---|
2688 | 2655 | |
---|
2689 | 2656 | return clk_prepare_enable(host->mck); |
---|
2690 | 2657 | } |
---|
.. | .. |
---|
2701 | 2668 | .remove = atmci_remove, |
---|
2702 | 2669 | .driver = { |
---|
2703 | 2670 | .name = "atmel_mci", |
---|
| 2671 | + .probe_type = PROBE_PREFER_ASYNCHRONOUS, |
---|
2704 | 2672 | .of_match_table = of_match_ptr(atmci_dt_ids), |
---|
2705 | 2673 | .pm = &atmci_dev_pm_ops, |
---|
2706 | 2674 | }, |
---|