blob: bc7669d50c38afeabaee4b287f72463b2887b40a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Pierre Ossman70f10482007-07-11 20:04:50 +02002 * linux/drivers/mmc/host/mmci.c - ARM PrimeCell MMCI PL180/1 driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Copyright (C) 2003 Deep Blue Solutions, Ltd, All Rights Reserved.
Russell Kingc8ebae32011-01-11 19:35:53 +00005 * Copyright (C) 2010 ST-Ericsson SA
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/module.h>
12#include <linux/moduleparam.h>
13#include <linux/init.h>
14#include <linux/ioport.h>
15#include <linux/device.h>
Ulf Hanssonef289982014-03-17 13:56:32 +010016#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/interrupt.h>
Russell King613b1522011-01-30 21:06:53 +000018#include <linux/kernel.h>
Lee Jones000bc9d2012-04-16 10:18:43 +010019#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/delay.h>
21#include <linux/err.h>
22#include <linux/highmem.h>
Nicolas Pitre019a5f52007-10-11 01:06:03 -040023#include <linux/log2.h>
Ulf Hansson70be2082013-01-07 15:35:06 +010024#include <linux/mmc/pm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/mmc/host.h>
Linus Walleij34177802010-10-19 12:43:58 +010026#include <linux/mmc/card.h>
Ulf Hanssond2762092014-03-17 13:56:19 +010027#include <linux/mmc/slot-gpio.h>
Russell Kinga62c80e2006-01-07 13:52:45 +000028#include <linux/amba/bus.h>
Russell Kingf8ce2542006-01-07 16:15:52 +000029#include <linux/clk.h>
Jens Axboebd6dee62007-10-24 09:01:09 +020030#include <linux/scatterlist.h>
Russell King89001442009-07-09 15:16:07 +010031#include <linux/gpio.h>
Lee Jones9a597012012-04-12 16:51:13 +010032#include <linux/of_gpio.h>
Linus Walleij34e84f32009-09-22 14:41:40 +010033#include <linux/regulator/consumer.h>
Russell Kingc8ebae32011-01-11 19:35:53 +000034#include <linux/dmaengine.h>
35#include <linux/dma-mapping.h>
36#include <linux/amba/mmci.h>
Russell King1c3be362011-08-14 09:17:05 +010037#include <linux/pm_runtime.h>
Viresh Kumar258aea72012-02-01 16:12:19 +053038#include <linux/types.h>
Linus Walleija9a83782012-10-29 14:39:30 +010039#include <linux/pinctrl/consumer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Russell King7b09cda2005-07-01 12:02:59 +010041#include <asm/div64.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44#include "mmci.h"
Srinivas Kandagatla9cb15142014-07-29 03:50:30 +010045#include "mmci_qcom_dml.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47#define DRIVER_NAME "mmci-pl18x"
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049static unsigned int fmax = 515633;
50
Rabin Vincent4956e102010-07-21 12:54:40 +010051/**
52 * struct variant_data - MMCI variant-specific quirks
53 * @clkreg: default value for MCICLOCK register
Rabin Vincent4380c142010-07-21 12:55:18 +010054 * @clkreg_enable: enable value for MMCICLOCK register
Srinivas Kandagatlae1412d82014-06-02 10:09:23 +010055 * @clkreg_8bit_bus_enable: enable value for 8 bit bus
Srinivas Kandagatlae8740642014-06-02 10:09:30 +010056 * @clkreg_neg_edge_enable: enable value for inverted data/cmd output
Rabin Vincent08458ef2010-07-21 12:55:59 +010057 * @datalength_bits: number of bits in the MMCIDATALENGTH register
Rabin Vincent8301bb62010-08-09 12:57:30 +010058 * @fifosize: number of bytes that can be written when MMCI_TXFIFOEMPTY
59 * is asserted (likewise for RX)
60 * @fifohalfsize: number of bytes that can be written when MCI_TXFIFOHALFEMPTY
61 * is asserted (likewise for RX)
Srinivas Kandagatlaae7b0062014-06-02 10:09:39 +010062 * @data_cmd_enable: enable value for data commands.
Srinivas Kandagatlac7354132014-08-22 05:55:16 +010063 * @st_sdio: enable ST specific SDIO logic
Linus Walleijb70a67f2010-12-06 09:24:14 +010064 * @st_clkdiv: true if using a ST-specific clock divider algorithm
Srinivas Kandagatlae17dca22014-06-02 10:09:15 +010065 * @datactrl_mask_ddrmode: ddr mode mask in datactrl register.
Philippe Langlais1784b152011-03-25 08:51:52 +010066 * @blksz_datactrl16: true if Block size is at b16..b30 position in datactrl register
Srinivas Kandagatlaff783232014-06-02 10:09:06 +010067 * @blksz_datactrl4: true if Block size is at b4..b16 position in datactrl
68 * register
Srinivas Kandagatla5df014d2014-08-22 05:54:55 +010069 * @datactrl_mask_sdio: SDIO enable mask in datactrl register
Ulf Hansson7d72a1d2011-12-13 16:54:55 +010070 * @pwrreg_powerup: power up value for MMCIPOWER register
Srinivas Kandagatladc6500b2014-06-02 10:09:47 +010071 * @f_max: maximum clk frequency supported by the controller.
Ulf Hansson4d1a3a02011-12-13 16:57:07 +010072 * @signal_direction: input/out direction of bus signals can be indicated
Ulf Hanssonf4670da2013-01-09 17:19:54 +010073 * @pwrreg_clkgate: MMCIPOWER register must be used to gate the clock
Linus Walleij49adc0c2016-10-25 11:06:06 +020074 * @busy_detect: true if the variant supports busy detection on DAT0.
75 * @busy_dpsm_flag: bitmask enabling busy detection in the DPSM
76 * @busy_detect_flag: bitmask identifying the bit in the MMCISTATUS register
77 * indicating that the card is busy
78 * @busy_detect_mask: bitmask identifying the bit in the MMCIMASK0 to mask for
79 * getting busy end detection interrupts
Ulf Hansson1ff44432013-09-04 09:05:17 +010080 * @pwrreg_nopower: bits in MMCIPOWER don't controls ext. power supply
Srinivas Kandagatla3f4e6f72014-06-02 10:09:55 +010081 * @explicit_mclk_control: enable explicit mclk control in driver.
Srinivas Kandagatla9c34b732014-06-02 10:10:04 +010082 * @qcom_fifo: enables qcom specific fifo pio read logic.
Srinivas Kandagatla9cb15142014-07-29 03:50:30 +010083 * @qcom_dml: enables qcom specific dma glue for dma transfers.
Ulf Hansson78782892014-06-13 13:21:38 +020084 * @reversed_irq_handling: handle data irq before cmd irq.
Patrice Chotard6ea9cdf2018-01-18 15:34:17 +010085 * @mmcimask1: true if variant have a MMCIMASK1 register.
Rabin Vincent4956e102010-07-21 12:54:40 +010086 */
87struct variant_data {
88 unsigned int clkreg;
Rabin Vincent4380c142010-07-21 12:55:18 +010089 unsigned int clkreg_enable;
Srinivas Kandagatlae1412d82014-06-02 10:09:23 +010090 unsigned int clkreg_8bit_bus_enable;
Srinivas Kandagatlae8740642014-06-02 10:09:30 +010091 unsigned int clkreg_neg_edge_enable;
Rabin Vincent08458ef2010-07-21 12:55:59 +010092 unsigned int datalength_bits;
Rabin Vincent8301bb62010-08-09 12:57:30 +010093 unsigned int fifosize;
94 unsigned int fifohalfsize;
Srinivas Kandagatlaae7b0062014-06-02 10:09:39 +010095 unsigned int data_cmd_enable;
Srinivas Kandagatlae17dca22014-06-02 10:09:15 +010096 unsigned int datactrl_mask_ddrmode;
Srinivas Kandagatla5df014d2014-08-22 05:54:55 +010097 unsigned int datactrl_mask_sdio;
Srinivas Kandagatlac7354132014-08-22 05:55:16 +010098 bool st_sdio;
Linus Walleijb70a67f2010-12-06 09:24:14 +010099 bool st_clkdiv;
Philippe Langlais1784b152011-03-25 08:51:52 +0100100 bool blksz_datactrl16;
Srinivas Kandagatlaff783232014-06-02 10:09:06 +0100101 bool blksz_datactrl4;
Ulf Hansson7d72a1d2011-12-13 16:54:55 +0100102 u32 pwrreg_powerup;
Srinivas Kandagatladc6500b2014-06-02 10:09:47 +0100103 u32 f_max;
Ulf Hansson4d1a3a02011-12-13 16:57:07 +0100104 bool signal_direction;
Ulf Hanssonf4670da2013-01-09 17:19:54 +0100105 bool pwrreg_clkgate;
Ulf Hansson01259622013-05-15 20:53:22 +0100106 bool busy_detect;
Linus Walleij49adc0c2016-10-25 11:06:06 +0200107 u32 busy_dpsm_flag;
108 u32 busy_detect_flag;
109 u32 busy_detect_mask;
Ulf Hansson1ff44432013-09-04 09:05:17 +0100110 bool pwrreg_nopower;
Srinivas Kandagatla3f4e6f72014-06-02 10:09:55 +0100111 bool explicit_mclk_control;
Srinivas Kandagatla9c34b732014-06-02 10:10:04 +0100112 bool qcom_fifo;
Srinivas Kandagatla9cb15142014-07-29 03:50:30 +0100113 bool qcom_dml;
Ulf Hansson78782892014-06-13 13:21:38 +0200114 bool reversed_irq_handling;
Patrice Chotard6ea9cdf2018-01-18 15:34:17 +0100115 bool mmcimask1;
Rabin Vincent4956e102010-07-21 12:54:40 +0100116};
117
118static struct variant_data variant_arm = {
Rabin Vincent8301bb62010-08-09 12:57:30 +0100119 .fifosize = 16 * 4,
120 .fifohalfsize = 8 * 4,
Rabin Vincent08458ef2010-07-21 12:55:59 +0100121 .datalength_bits = 16,
Ulf Hansson7d72a1d2011-12-13 16:54:55 +0100122 .pwrreg_powerup = MCI_PWR_UP,
Srinivas Kandagatladc6500b2014-06-02 10:09:47 +0100123 .f_max = 100000000,
Ulf Hansson78782892014-06-13 13:21:38 +0200124 .reversed_irq_handling = true,
Patrice Chotard6ea9cdf2018-01-18 15:34:17 +0100125 .mmcimask1 = true,
Rabin Vincent4956e102010-07-21 12:54:40 +0100126};
127
Pawel Moll768fbc12011-03-11 17:18:07 +0000128static struct variant_data variant_arm_extended_fifo = {
129 .fifosize = 128 * 4,
130 .fifohalfsize = 64 * 4,
131 .datalength_bits = 16,
Ulf Hansson7d72a1d2011-12-13 16:54:55 +0100132 .pwrreg_powerup = MCI_PWR_UP,
Srinivas Kandagatladc6500b2014-06-02 10:09:47 +0100133 .f_max = 100000000,
Patrice Chotard6ea9cdf2018-01-18 15:34:17 +0100134 .mmcimask1 = true,
Pawel Moll768fbc12011-03-11 17:18:07 +0000135};
136
Pawel Moll3a372982013-01-24 14:12:45 +0100137static struct variant_data variant_arm_extended_fifo_hwfc = {
138 .fifosize = 128 * 4,
139 .fifohalfsize = 64 * 4,
140 .clkreg_enable = MCI_ARM_HWFCEN,
141 .datalength_bits = 16,
142 .pwrreg_powerup = MCI_PWR_UP,
Srinivas Kandagatladc6500b2014-06-02 10:09:47 +0100143 .f_max = 100000000,
Patrice Chotard6ea9cdf2018-01-18 15:34:17 +0100144 .mmcimask1 = true,
Pawel Moll3a372982013-01-24 14:12:45 +0100145};
146
Rabin Vincent4956e102010-07-21 12:54:40 +0100147static struct variant_data variant_u300 = {
Rabin Vincent8301bb62010-08-09 12:57:30 +0100148 .fifosize = 16 * 4,
149 .fifohalfsize = 8 * 4,
Linus Walleij49ac2152011-03-04 14:54:16 +0100150 .clkreg_enable = MCI_ST_U300_HWFCEN,
Srinivas Kandagatlae1412d82014-06-02 10:09:23 +0100151 .clkreg_8bit_bus_enable = MCI_ST_8BIT_BUS,
Rabin Vincent08458ef2010-07-21 12:55:59 +0100152 .datalength_bits = 16,
Linus Walleij5db3eee2016-10-25 11:06:05 +0200153 .datactrl_mask_sdio = MCI_DPSM_ST_SDIOEN,
Srinivas Kandagatlac7354132014-08-22 05:55:16 +0100154 .st_sdio = true,
Ulf Hansson7d72a1d2011-12-13 16:54:55 +0100155 .pwrreg_powerup = MCI_PWR_ON,
Srinivas Kandagatladc6500b2014-06-02 10:09:47 +0100156 .f_max = 100000000,
Ulf Hansson4d1a3a02011-12-13 16:57:07 +0100157 .signal_direction = true,
Ulf Hanssonf4670da2013-01-09 17:19:54 +0100158 .pwrreg_clkgate = true,
Ulf Hansson1ff44432013-09-04 09:05:17 +0100159 .pwrreg_nopower = true,
Patrice Chotard6ea9cdf2018-01-18 15:34:17 +0100160 .mmcimask1 = true,
Rabin Vincent4956e102010-07-21 12:54:40 +0100161};
162
Linus Walleij34fd4212012-04-10 17:43:59 +0100163static struct variant_data variant_nomadik = {
164 .fifosize = 16 * 4,
165 .fifohalfsize = 8 * 4,
166 .clkreg = MCI_CLK_ENABLE,
Linus Walleijf5abc762016-01-04 02:22:08 +0100167 .clkreg_8bit_bus_enable = MCI_ST_8BIT_BUS,
Linus Walleij34fd4212012-04-10 17:43:59 +0100168 .datalength_bits = 24,
Linus Walleij5db3eee2016-10-25 11:06:05 +0200169 .datactrl_mask_sdio = MCI_DPSM_ST_SDIOEN,
Srinivas Kandagatlac7354132014-08-22 05:55:16 +0100170 .st_sdio = true,
Linus Walleij34fd4212012-04-10 17:43:59 +0100171 .st_clkdiv = true,
172 .pwrreg_powerup = MCI_PWR_ON,
Srinivas Kandagatladc6500b2014-06-02 10:09:47 +0100173 .f_max = 100000000,
Linus Walleij34fd4212012-04-10 17:43:59 +0100174 .signal_direction = true,
Ulf Hanssonf4670da2013-01-09 17:19:54 +0100175 .pwrreg_clkgate = true,
Ulf Hansson1ff44432013-09-04 09:05:17 +0100176 .pwrreg_nopower = true,
Patrice Chotard6ea9cdf2018-01-18 15:34:17 +0100177 .mmcimask1 = true,
Linus Walleij34fd4212012-04-10 17:43:59 +0100178};
179
Rabin Vincent4956e102010-07-21 12:54:40 +0100180static struct variant_data variant_ux500 = {
Rabin Vincent8301bb62010-08-09 12:57:30 +0100181 .fifosize = 30 * 4,
182 .fifohalfsize = 8 * 4,
Rabin Vincent4956e102010-07-21 12:54:40 +0100183 .clkreg = MCI_CLK_ENABLE,
Linus Walleij49ac2152011-03-04 14:54:16 +0100184 .clkreg_enable = MCI_ST_UX500_HWFCEN,
Srinivas Kandagatlae1412d82014-06-02 10:09:23 +0100185 .clkreg_8bit_bus_enable = MCI_ST_8BIT_BUS,
Srinivas Kandagatlae8740642014-06-02 10:09:30 +0100186 .clkreg_neg_edge_enable = MCI_ST_UX500_NEG_EDGE,
Rabin Vincent08458ef2010-07-21 12:55:59 +0100187 .datalength_bits = 24,
Linus Walleij5db3eee2016-10-25 11:06:05 +0200188 .datactrl_mask_sdio = MCI_DPSM_ST_SDIOEN,
Srinivas Kandagatlac7354132014-08-22 05:55:16 +0100189 .st_sdio = true,
Linus Walleijb70a67f2010-12-06 09:24:14 +0100190 .st_clkdiv = true,
Ulf Hansson7d72a1d2011-12-13 16:54:55 +0100191 .pwrreg_powerup = MCI_PWR_ON,
Srinivas Kandagatladc6500b2014-06-02 10:09:47 +0100192 .f_max = 100000000,
Ulf Hansson4d1a3a02011-12-13 16:57:07 +0100193 .signal_direction = true,
Ulf Hanssonf4670da2013-01-09 17:19:54 +0100194 .pwrreg_clkgate = true,
Ulf Hansson01259622013-05-15 20:53:22 +0100195 .busy_detect = true,
Linus Walleij49adc0c2016-10-25 11:06:06 +0200196 .busy_dpsm_flag = MCI_DPSM_ST_BUSYMODE,
197 .busy_detect_flag = MCI_ST_CARDBUSY,
198 .busy_detect_mask = MCI_ST_BUSYENDMASK,
Ulf Hansson1ff44432013-09-04 09:05:17 +0100199 .pwrreg_nopower = true,
Patrice Chotard6ea9cdf2018-01-18 15:34:17 +0100200 .mmcimask1 = true,
Rabin Vincent4956e102010-07-21 12:54:40 +0100201};
Linus Walleijb70a67f2010-12-06 09:24:14 +0100202
Philippe Langlais1784b152011-03-25 08:51:52 +0100203static struct variant_data variant_ux500v2 = {
204 .fifosize = 30 * 4,
205 .fifohalfsize = 8 * 4,
206 .clkreg = MCI_CLK_ENABLE,
207 .clkreg_enable = MCI_ST_UX500_HWFCEN,
Srinivas Kandagatlae1412d82014-06-02 10:09:23 +0100208 .clkreg_8bit_bus_enable = MCI_ST_8BIT_BUS,
Srinivas Kandagatlae8740642014-06-02 10:09:30 +0100209 .clkreg_neg_edge_enable = MCI_ST_UX500_NEG_EDGE,
Linus Walleij5db3eee2016-10-25 11:06:05 +0200210 .datactrl_mask_ddrmode = MCI_DPSM_ST_DDRMODE,
Philippe Langlais1784b152011-03-25 08:51:52 +0100211 .datalength_bits = 24,
Linus Walleij5db3eee2016-10-25 11:06:05 +0200212 .datactrl_mask_sdio = MCI_DPSM_ST_SDIOEN,
Srinivas Kandagatlac7354132014-08-22 05:55:16 +0100213 .st_sdio = true,
Philippe Langlais1784b152011-03-25 08:51:52 +0100214 .st_clkdiv = true,
215 .blksz_datactrl16 = true,
Ulf Hansson7d72a1d2011-12-13 16:54:55 +0100216 .pwrreg_powerup = MCI_PWR_ON,
Srinivas Kandagatladc6500b2014-06-02 10:09:47 +0100217 .f_max = 100000000,
Ulf Hansson4d1a3a02011-12-13 16:57:07 +0100218 .signal_direction = true,
Ulf Hanssonf4670da2013-01-09 17:19:54 +0100219 .pwrreg_clkgate = true,
Ulf Hansson01259622013-05-15 20:53:22 +0100220 .busy_detect = true,
Linus Walleij49adc0c2016-10-25 11:06:06 +0200221 .busy_dpsm_flag = MCI_DPSM_ST_BUSYMODE,
222 .busy_detect_flag = MCI_ST_CARDBUSY,
223 .busy_detect_mask = MCI_ST_BUSYENDMASK,
Ulf Hansson1ff44432013-09-04 09:05:17 +0100224 .pwrreg_nopower = true,
Patrice Chotard6ea9cdf2018-01-18 15:34:17 +0100225 .mmcimask1 = true,
Philippe Langlais1784b152011-03-25 08:51:52 +0100226};
227
Srinivas Kandagatla55b604a2014-06-02 10:10:13 +0100228static struct variant_data variant_qcom = {
229 .fifosize = 16 * 4,
230 .fifohalfsize = 8 * 4,
231 .clkreg = MCI_CLK_ENABLE,
232 .clkreg_enable = MCI_QCOM_CLK_FLOWENA |
233 MCI_QCOM_CLK_SELECT_IN_FBCLK,
234 .clkreg_8bit_bus_enable = MCI_QCOM_CLK_WIDEBUS_8,
235 .datactrl_mask_ddrmode = MCI_QCOM_CLK_SELECT_IN_DDR_MODE,
Linus Walleij5db3eee2016-10-25 11:06:05 +0200236 .data_cmd_enable = MCI_CPSM_QCOM_DATCMD,
Srinivas Kandagatla55b604a2014-06-02 10:10:13 +0100237 .blksz_datactrl4 = true,
238 .datalength_bits = 24,
239 .pwrreg_powerup = MCI_PWR_UP,
240 .f_max = 208000000,
241 .explicit_mclk_control = true,
242 .qcom_fifo = true,
Srinivas Kandagatla9cb15142014-07-29 03:50:30 +0100243 .qcom_dml = true,
Patrice Chotard6ea9cdf2018-01-18 15:34:17 +0100244 .mmcimask1 = true,
Srinivas Kandagatla55b604a2014-06-02 10:10:13 +0100245};
246
Linus Walleij49adc0c2016-10-25 11:06:06 +0200247/* Busy detection for the ST Micro variant */
Ulf Hansson01259622013-05-15 20:53:22 +0100248static int mmci_card_busy(struct mmc_host *mmc)
249{
250 struct mmci_host *host = mmc_priv(mmc);
251 unsigned long flags;
252 int busy = 0;
253
Ulf Hansson01259622013-05-15 20:53:22 +0100254 spin_lock_irqsave(&host->lock, flags);
Linus Walleij49adc0c2016-10-25 11:06:06 +0200255 if (readl(host->base + MMCISTATUS) & host->variant->busy_detect_flag)
Ulf Hansson01259622013-05-15 20:53:22 +0100256 busy = 1;
257 spin_unlock_irqrestore(&host->lock, flags);
258
Ulf Hansson01259622013-05-15 20:53:22 +0100259 return busy;
260}
261
Linus Walleija6a64642009-09-14 12:56:14 +0100262/*
Ulf Hansson653a7612013-01-21 21:29:34 +0100263 * Validate mmc prerequisites
264 */
265static int mmci_validate_data(struct mmci_host *host,
266 struct mmc_data *data)
267{
268 if (!data)
269 return 0;
270
271 if (!is_power_of_2(data->blksz)) {
272 dev_err(mmc_dev(host->mmc),
273 "unsupported block size (%d bytes)\n", data->blksz);
274 return -EINVAL;
275 }
276
277 return 0;
278}
279
Ulf Hanssonf829c042013-09-04 09:01:15 +0100280static void mmci_reg_delay(struct mmci_host *host)
281{
282 /*
283 * According to the spec, at least three feedback clock cycles
284 * of max 52 MHz must pass between two writes to the MMCICLOCK reg.
285 * Three MCLK clock cycles must pass between two MMCIPOWER reg writes.
286 * Worst delay time during card init is at 100 kHz => 30 us.
287 * Worst delay time when up and running is at 25 MHz => 120 ns.
288 */
289 if (host->cclk < 25000000)
290 udelay(30);
291 else
292 ndelay(120);
293}
294
Ulf Hansson653a7612013-01-21 21:29:34 +0100295/*
Linus Walleija6a64642009-09-14 12:56:14 +0100296 * This must be called with host->lock held
297 */
Ulf Hansson7437cfa2012-01-18 09:17:27 +0100298static void mmci_write_clkreg(struct mmci_host *host, u32 clk)
299{
300 if (host->clk_reg != clk) {
301 host->clk_reg = clk;
302 writel(clk, host->base + MMCICLOCK);
303 }
304}
305
306/*
307 * This must be called with host->lock held
308 */
309static void mmci_write_pwrreg(struct mmci_host *host, u32 pwr)
310{
311 if (host->pwr_reg != pwr) {
312 host->pwr_reg = pwr;
313 writel(pwr, host->base + MMCIPOWER);
314 }
315}
316
317/*
318 * This must be called with host->lock held
319 */
Ulf Hansson9cc639a2013-05-15 20:48:23 +0100320static void mmci_write_datactrlreg(struct mmci_host *host, u32 datactrl)
321{
Linus Walleij49adc0c2016-10-25 11:06:06 +0200322 /* Keep busy mode in DPSM if enabled */
323 datactrl |= host->datactrl_reg & host->variant->busy_dpsm_flag;
Ulf Hansson01259622013-05-15 20:53:22 +0100324
Ulf Hansson9cc639a2013-05-15 20:48:23 +0100325 if (host->datactrl_reg != datactrl) {
326 host->datactrl_reg = datactrl;
327 writel(datactrl, host->base + MMCIDATACTRL);
328 }
329}
330
331/*
332 * This must be called with host->lock held
333 */
Linus Walleija6a64642009-09-14 12:56:14 +0100334static void mmci_set_clkreg(struct mmci_host *host, unsigned int desired)
335{
Rabin Vincent4956e102010-07-21 12:54:40 +0100336 struct variant_data *variant = host->variant;
337 u32 clk = variant->clkreg;
Linus Walleija6a64642009-09-14 12:56:14 +0100338
Ulf Hanssonc58a8502013-05-13 15:40:03 +0100339 /* Make sure cclk reflects the current calculated clock */
340 host->cclk = 0;
341
Linus Walleija6a64642009-09-14 12:56:14 +0100342 if (desired) {
Srinivas Kandagatla3f4e6f72014-06-02 10:09:55 +0100343 if (variant->explicit_mclk_control) {
344 host->cclk = host->mclk;
345 } else if (desired >= host->mclk) {
Linus Walleij991a86e2010-12-10 09:35:53 +0100346 clk = MCI_CLK_BYPASS;
Linus Walleij399bc482011-04-01 07:59:17 +0100347 if (variant->st_clkdiv)
348 clk |= MCI_ST_UX500_NEG_EDGE;
Linus Walleija6a64642009-09-14 12:56:14 +0100349 host->cclk = host->mclk;
Linus Walleijb70a67f2010-12-06 09:24:14 +0100350 } else if (variant->st_clkdiv) {
351 /*
352 * DB8500 TRM says f = mclk / (clkdiv + 2)
353 * => clkdiv = (mclk / f) - 2
354 * Round the divider up so we don't exceed the max
355 * frequency
356 */
357 clk = DIV_ROUND_UP(host->mclk, desired) - 2;
358 if (clk >= 256)
359 clk = 255;
360 host->cclk = host->mclk / (clk + 2);
Linus Walleija6a64642009-09-14 12:56:14 +0100361 } else {
Linus Walleijb70a67f2010-12-06 09:24:14 +0100362 /*
363 * PL180 TRM says f = mclk / (2 * (clkdiv + 1))
364 * => clkdiv = mclk / (2 * f) - 1
365 */
Linus Walleija6a64642009-09-14 12:56:14 +0100366 clk = host->mclk / (2 * desired) - 1;
367 if (clk >= 256)
368 clk = 255;
369 host->cclk = host->mclk / (2 * (clk + 1));
370 }
Rabin Vincent4380c142010-07-21 12:55:18 +0100371
372 clk |= variant->clkreg_enable;
Linus Walleija6a64642009-09-14 12:56:14 +0100373 clk |= MCI_CLK_ENABLE;
374 /* This hasn't proven to be worthwhile */
375 /* clk |= MCI_CLK_PWRSAVE; */
376 }
377
Ulf Hanssonc58a8502013-05-13 15:40:03 +0100378 /* Set actual clock for debug */
379 host->mmc->actual_clock = host->cclk;
380
Linus Walleij9e6c82c2009-09-14 12:57:11 +0100381 if (host->mmc->ios.bus_width == MMC_BUS_WIDTH_4)
Linus Walleij771dc152010-04-08 07:38:52 +0100382 clk |= MCI_4BIT_BUS;
383 if (host->mmc->ios.bus_width == MMC_BUS_WIDTH_8)
Srinivas Kandagatlae1412d82014-06-02 10:09:23 +0100384 clk |= variant->clkreg_8bit_bus_enable;
Linus Walleij9e6c82c2009-09-14 12:57:11 +0100385
Seungwon Jeon6dad6c92014-03-14 21:12:13 +0900386 if (host->mmc->ios.timing == MMC_TIMING_UHS_DDR50 ||
387 host->mmc->ios.timing == MMC_TIMING_MMC_DDR52)
Srinivas Kandagatlae8740642014-06-02 10:09:30 +0100388 clk |= variant->clkreg_neg_edge_enable;
Ulf Hansson6dbb6ee2013-01-07 15:30:44 +0100389
Ulf Hansson7437cfa2012-01-18 09:17:27 +0100390 mmci_write_clkreg(host, clk);
Linus Walleija6a64642009-09-14 12:56:14 +0100391}
392
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393static void
394mmci_request_end(struct mmci_host *host, struct mmc_request *mrq)
395{
396 writel(0, host->base + MMCICOMMAND);
397
Russell Kinge47c2222007-01-08 16:42:51 +0000398 BUG_ON(host->data);
399
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 host->mrq = NULL;
401 host->cmd = NULL;
402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 mmc_request_done(host->mmc, mrq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404}
405
Linus Walleij2686b4b2010-10-19 12:39:48 +0100406static void mmci_set_mask1(struct mmci_host *host, unsigned int mask)
407{
408 void __iomem *base = host->base;
Patrice Chotard6ea9cdf2018-01-18 15:34:17 +0100409 struct variant_data *variant = host->variant;
Linus Walleij2686b4b2010-10-19 12:39:48 +0100410
411 if (host->singleirq) {
412 unsigned int mask0 = readl(base + MMCIMASK0);
413
414 mask0 &= ~MCI_IRQ1MASK;
415 mask0 |= mask;
416
417 writel(mask0, base + MMCIMASK0);
418 }
419
Patrice Chotard6ea9cdf2018-01-18 15:34:17 +0100420 if (variant->mmcimask1)
421 writel(mask, base + MMCIMASK1);
422
423 host->mask1_reg = mask;
Linus Walleij2686b4b2010-10-19 12:39:48 +0100424}
425
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426static void mmci_stop_data(struct mmci_host *host)
427{
Ulf Hansson9cc639a2013-05-15 20:48:23 +0100428 mmci_write_datactrlreg(host, 0);
Linus Walleij2686b4b2010-10-19 12:39:48 +0100429 mmci_set_mask1(host, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 host->data = NULL;
431}
432
Rabin Vincent4ce1d6c2010-07-21 12:44:58 +0100433static void mmci_init_sg(struct mmci_host *host, struct mmc_data *data)
434{
435 unsigned int flags = SG_MITER_ATOMIC;
436
437 if (data->flags & MMC_DATA_READ)
438 flags |= SG_MITER_TO_SG;
439 else
440 flags |= SG_MITER_FROM_SG;
441
442 sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags);
443}
444
Russell Kingc8ebae32011-01-11 19:35:53 +0000445/*
446 * All the DMA operation mode stuff goes inside this ifdef.
447 * This assumes that you have a generic DMA device interface,
448 * no custom DMA interfaces are supported.
449 */
450#ifdef CONFIG_DMA_ENGINE
Bill Pembertonc3be1ef2012-11-19 13:23:06 -0500451static void mmci_dma_setup(struct mmci_host *host)
Russell Kingc8ebae32011-01-11 19:35:53 +0000452{
Russell Kingc8ebae32011-01-11 19:35:53 +0000453 const char *rxname, *txname;
Srinivas Kandagatla9cb15142014-07-29 03:50:30 +0100454 struct variant_data *variant = host->variant;
Russell Kingc8ebae32011-01-11 19:35:53 +0000455
Lee Jones1fd83f02013-05-03 12:51:17 +0100456 host->dma_rx_channel = dma_request_slave_channel(mmc_dev(host->mmc), "rx");
457 host->dma_tx_channel = dma_request_slave_channel(mmc_dev(host->mmc), "tx");
Russell Kingc8ebae32011-01-11 19:35:53 +0000458
Per Forlin58c7ccb2011-07-01 18:55:24 +0200459 /* initialize pre request cookie */
460 host->next_data.cookie = 1;
461
Russell Kingc8ebae32011-01-11 19:35:53 +0000462 /*
463 * If only an RX channel is specified, the driver will
464 * attempt to use it bidirectionally, however if it is
465 * is specified but cannot be located, DMA will be disabled.
466 */
Lee Jones1fd83f02013-05-03 12:51:17 +0100467 if (host->dma_rx_channel && !host->dma_tx_channel)
Russell Kingc8ebae32011-01-11 19:35:53 +0000468 host->dma_tx_channel = host->dma_rx_channel;
Russell Kingc8ebae32011-01-11 19:35:53 +0000469
470 if (host->dma_rx_channel)
471 rxname = dma_chan_name(host->dma_rx_channel);
472 else
473 rxname = "none";
474
475 if (host->dma_tx_channel)
476 txname = dma_chan_name(host->dma_tx_channel);
477 else
478 txname = "none";
479
480 dev_info(mmc_dev(host->mmc), "DMA channels RX %s, TX %s\n",
481 rxname, txname);
482
483 /*
484 * Limit the maximum segment size in any SG entry according to
485 * the parameters of the DMA engine device.
486 */
487 if (host->dma_tx_channel) {
488 struct device *dev = host->dma_tx_channel->device->dev;
489 unsigned int max_seg_size = dma_get_max_seg_size(dev);
490
491 if (max_seg_size < host->mmc->max_seg_size)
492 host->mmc->max_seg_size = max_seg_size;
493 }
494 if (host->dma_rx_channel) {
495 struct device *dev = host->dma_rx_channel->device->dev;
496 unsigned int max_seg_size = dma_get_max_seg_size(dev);
497
498 if (max_seg_size < host->mmc->max_seg_size)
499 host->mmc->max_seg_size = max_seg_size;
500 }
Srinivas Kandagatla9cb15142014-07-29 03:50:30 +0100501
502 if (variant->qcom_dml && host->dma_rx_channel && host->dma_tx_channel)
503 if (dml_hw_init(host, host->mmc->parent->of_node))
504 variant->qcom_dml = false;
Russell Kingc8ebae32011-01-11 19:35:53 +0000505}
506
507/*
Bill Pemberton6e0ee712012-11-19 13:26:03 -0500508 * This is used in or so inline it
Russell Kingc8ebae32011-01-11 19:35:53 +0000509 * so it can be discarded.
510 */
511static inline void mmci_dma_release(struct mmci_host *host)
512{
Russell Kingc8ebae32011-01-11 19:35:53 +0000513 if (host->dma_rx_channel)
514 dma_release_channel(host->dma_rx_channel);
Ulf Hansson8c3a05b2014-05-20 06:45:54 +0200515 if (host->dma_tx_channel)
Russell Kingc8ebae32011-01-11 19:35:53 +0000516 dma_release_channel(host->dma_tx_channel);
517 host->dma_rx_channel = host->dma_tx_channel = NULL;
518}
519
Ulf Hansson653a7612013-01-21 21:29:34 +0100520static void mmci_dma_data_error(struct mmci_host *host)
521{
522 dev_err(mmc_dev(host->mmc), "error during DMA transfer!\n");
523 dmaengine_terminate_all(host->dma_current);
Linus Walleije13934b2017-01-27 15:04:54 +0100524 host->dma_in_progress = false;
Ulf Hansson653a7612013-01-21 21:29:34 +0100525 host->dma_current = NULL;
526 host->dma_desc_current = NULL;
527 host->data->host_cookie = 0;
528}
529
Russell Kingc8ebae32011-01-11 19:35:53 +0000530static void mmci_dma_unmap(struct mmci_host *host, struct mmc_data *data)
531{
Ulf Hansson653a7612013-01-21 21:29:34 +0100532 struct dma_chan *chan;
Ulf Hansson653a7612013-01-21 21:29:34 +0100533
Heiner Kallweitfeeef092017-03-26 20:45:56 +0200534 if (data->flags & MMC_DATA_READ)
Ulf Hansson653a7612013-01-21 21:29:34 +0100535 chan = host->dma_rx_channel;
Heiner Kallweitfeeef092017-03-26 20:45:56 +0200536 else
Ulf Hansson653a7612013-01-21 21:29:34 +0100537 chan = host->dma_tx_channel;
Ulf Hansson653a7612013-01-21 21:29:34 +0100538
Heiner Kallweitfeeef092017-03-26 20:45:56 +0200539 dma_unmap_sg(chan->device->dev, data->sg, data->sg_len,
540 mmc_get_dma_dir(data));
Ulf Hansson653a7612013-01-21 21:29:34 +0100541}
542
543static void mmci_dma_finalize(struct mmci_host *host, struct mmc_data *data)
544{
Russell Kingc8ebae32011-01-11 19:35:53 +0000545 u32 status;
546 int i;
547
548 /* Wait up to 1ms for the DMA to complete */
549 for (i = 0; ; i++) {
550 status = readl(host->base + MMCISTATUS);
551 if (!(status & MCI_RXDATAAVLBLMASK) || i >= 100)
552 break;
553 udelay(10);
554 }
555
556 /*
557 * Check to see whether we still have some data left in the FIFO -
558 * this catches DMA controllers which are unable to monitor the
559 * DMALBREQ and DMALSREQ signals while allowing us to DMA to non-
560 * contiguous buffers. On TX, we'll get a FIFO underrun error.
561 */
562 if (status & MCI_RXDATAAVLBLMASK) {
Ulf Hansson653a7612013-01-21 21:29:34 +0100563 mmci_dma_data_error(host);
Russell Kingc8ebae32011-01-11 19:35:53 +0000564 if (!data->error)
565 data->error = -EIO;
566 }
567
Per Forlin58c7ccb2011-07-01 18:55:24 +0200568 if (!data->host_cookie)
Ulf Hansson653a7612013-01-21 21:29:34 +0100569 mmci_dma_unmap(host, data);
Russell Kingc8ebae32011-01-11 19:35:53 +0000570
571 /*
572 * Use of DMA with scatter-gather is impossible.
573 * Give up with DMA and switch back to PIO mode.
574 */
575 if (status & MCI_RXDATAAVLBLMASK) {
576 dev_err(mmc_dev(host->mmc), "buggy DMA detected. Taking evasive action.\n");
577 mmci_dma_release(host);
578 }
Ulf Hansson653a7612013-01-21 21:29:34 +0100579
Linus Walleije13934b2017-01-27 15:04:54 +0100580 host->dma_in_progress = false;
Ulf Hansson653a7612013-01-21 21:29:34 +0100581 host->dma_current = NULL;
582 host->dma_desc_current = NULL;
Russell Kingc8ebae32011-01-11 19:35:53 +0000583}
584
Ulf Hansson653a7612013-01-21 21:29:34 +0100585/* prepares DMA channel and DMA descriptor, returns non-zero on failure */
586static int __mmci_dma_prep_data(struct mmci_host *host, struct mmc_data *data,
587 struct dma_chan **dma_chan,
588 struct dma_async_tx_descriptor **dma_desc)
Russell Kingc8ebae32011-01-11 19:35:53 +0000589{
590 struct variant_data *variant = host->variant;
591 struct dma_slave_config conf = {
592 .src_addr = host->phybase + MMCIFIFO,
593 .dst_addr = host->phybase + MMCIFIFO,
594 .src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
595 .dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
596 .src_maxburst = variant->fifohalfsize >> 2, /* # of words */
597 .dst_maxburst = variant->fifohalfsize >> 2, /* # of words */
Viresh Kumar258aea72012-02-01 16:12:19 +0530598 .device_fc = false,
Russell Kingc8ebae32011-01-11 19:35:53 +0000599 };
Russell Kingc8ebae32011-01-11 19:35:53 +0000600 struct dma_chan *chan;
601 struct dma_device *device;
602 struct dma_async_tx_descriptor *desc;
603 int nr_sg;
Srinivas Kandagatla9cb15142014-07-29 03:50:30 +0100604 unsigned long flags = DMA_CTRL_ACK;
Russell Kingc8ebae32011-01-11 19:35:53 +0000605
Russell Kingc8ebae32011-01-11 19:35:53 +0000606 if (data->flags & MMC_DATA_READ) {
Vinod Koul05f57992011-10-14 10:45:11 +0530607 conf.direction = DMA_DEV_TO_MEM;
Russell Kingc8ebae32011-01-11 19:35:53 +0000608 chan = host->dma_rx_channel;
609 } else {
Vinod Koul05f57992011-10-14 10:45:11 +0530610 conf.direction = DMA_MEM_TO_DEV;
Russell Kingc8ebae32011-01-11 19:35:53 +0000611 chan = host->dma_tx_channel;
612 }
613
614 /* If there's no DMA channel, fall back to PIO */
615 if (!chan)
616 return -EINVAL;
617
618 /* If less than or equal to the fifo size, don't bother with DMA */
Per Forlin58c7ccb2011-07-01 18:55:24 +0200619 if (data->blksz * data->blocks <= variant->fifosize)
Russell Kingc8ebae32011-01-11 19:35:53 +0000620 return -EINVAL;
621
622 device = chan->device;
Heiner Kallweitfeeef092017-03-26 20:45:56 +0200623 nr_sg = dma_map_sg(device->dev, data->sg, data->sg_len,
624 mmc_get_dma_dir(data));
Russell Kingc8ebae32011-01-11 19:35:53 +0000625 if (nr_sg == 0)
626 return -EINVAL;
627
Srinivas Kandagatla9cb15142014-07-29 03:50:30 +0100628 if (host->variant->qcom_dml)
629 flags |= DMA_PREP_INTERRUPT;
630
Russell Kingc8ebae32011-01-11 19:35:53 +0000631 dmaengine_slave_config(chan, &conf);
Alexandre Bounine16052822012-03-08 16:11:18 -0500632 desc = dmaengine_prep_slave_sg(chan, data->sg, nr_sg,
Srinivas Kandagatla9cb15142014-07-29 03:50:30 +0100633 conf.direction, flags);
Russell Kingc8ebae32011-01-11 19:35:53 +0000634 if (!desc)
635 goto unmap_exit;
636
Ulf Hansson653a7612013-01-21 21:29:34 +0100637 *dma_chan = chan;
638 *dma_desc = desc;
Russell Kingc8ebae32011-01-11 19:35:53 +0000639
Per Forlin58c7ccb2011-07-01 18:55:24 +0200640 return 0;
641
642 unmap_exit:
Heiner Kallweitfeeef092017-03-26 20:45:56 +0200643 dma_unmap_sg(device->dev, data->sg, data->sg_len,
644 mmc_get_dma_dir(data));
Per Forlin58c7ccb2011-07-01 18:55:24 +0200645 return -ENOMEM;
646}
647
Ulf Hansson653a7612013-01-21 21:29:34 +0100648static inline int mmci_dma_prep_data(struct mmci_host *host,
649 struct mmc_data *data)
650{
651 /* Check if next job is already prepared. */
652 if (host->dma_current && host->dma_desc_current)
653 return 0;
654
655 /* No job were prepared thus do it now. */
656 return __mmci_dma_prep_data(host, data, &host->dma_current,
657 &host->dma_desc_current);
658}
659
660static inline int mmci_dma_prep_next(struct mmci_host *host,
661 struct mmc_data *data)
662{
663 struct mmci_host_next *nd = &host->next_data;
664 return __mmci_dma_prep_data(host, data, &nd->dma_chan, &nd->dma_desc);
665}
666
Per Forlin58c7ccb2011-07-01 18:55:24 +0200667static int mmci_dma_start_data(struct mmci_host *host, unsigned int datactrl)
668{
669 int ret;
670 struct mmc_data *data = host->data;
671
Ulf Hansson653a7612013-01-21 21:29:34 +0100672 ret = mmci_dma_prep_data(host, host->data);
Per Forlin58c7ccb2011-07-01 18:55:24 +0200673 if (ret)
674 return ret;
675
676 /* Okay, go for it. */
Russell Kingc8ebae32011-01-11 19:35:53 +0000677 dev_vdbg(mmc_dev(host->mmc),
678 "Submit MMCI DMA job, sglen %d blksz %04x blks %04x flags %08x\n",
679 data->sg_len, data->blksz, data->blocks, data->flags);
Linus Walleije13934b2017-01-27 15:04:54 +0100680 host->dma_in_progress = true;
Per Forlin58c7ccb2011-07-01 18:55:24 +0200681 dmaengine_submit(host->dma_desc_current);
682 dma_async_issue_pending(host->dma_current);
Russell Kingc8ebae32011-01-11 19:35:53 +0000683
Srinivas Kandagatla9cb15142014-07-29 03:50:30 +0100684 if (host->variant->qcom_dml)
685 dml_start_xfer(host, data);
686
Russell Kingc8ebae32011-01-11 19:35:53 +0000687 datactrl |= MCI_DPSM_DMAENABLE;
688
689 /* Trigger the DMA transfer */
Ulf Hansson9cc639a2013-05-15 20:48:23 +0100690 mmci_write_datactrlreg(host, datactrl);
Russell Kingc8ebae32011-01-11 19:35:53 +0000691
692 /*
693 * Let the MMCI say when the data is ended and it's time
694 * to fire next DMA request. When that happens, MMCI will
695 * call mmci_data_end()
696 */
697 writel(readl(host->base + MMCIMASK0) | MCI_DATAENDMASK,
698 host->base + MMCIMASK0);
699 return 0;
Russell Kingc8ebae32011-01-11 19:35:53 +0000700}
Per Forlin58c7ccb2011-07-01 18:55:24 +0200701
702static void mmci_get_next_data(struct mmci_host *host, struct mmc_data *data)
703{
704 struct mmci_host_next *next = &host->next_data;
705
Ulf Hansson653a7612013-01-21 21:29:34 +0100706 WARN_ON(data->host_cookie && data->host_cookie != next->cookie);
707 WARN_ON(!data->host_cookie && (next->dma_desc || next->dma_chan));
Per Forlin58c7ccb2011-07-01 18:55:24 +0200708
709 host->dma_desc_current = next->dma_desc;
710 host->dma_current = next->dma_chan;
Per Forlin58c7ccb2011-07-01 18:55:24 +0200711 next->dma_desc = NULL;
712 next->dma_chan = NULL;
713}
714
Linus Walleijd3c6aac2016-11-23 11:02:24 +0100715static void mmci_pre_request(struct mmc_host *mmc, struct mmc_request *mrq)
Per Forlin58c7ccb2011-07-01 18:55:24 +0200716{
717 struct mmci_host *host = mmc_priv(mmc);
718 struct mmc_data *data = mrq->data;
719 struct mmci_host_next *nd = &host->next_data;
720
721 if (!data)
722 return;
723
Ulf Hansson653a7612013-01-21 21:29:34 +0100724 BUG_ON(data->host_cookie);
Per Forlin58c7ccb2011-07-01 18:55:24 +0200725
Ulf Hansson653a7612013-01-21 21:29:34 +0100726 if (mmci_validate_data(host, data))
727 return;
728
729 if (!mmci_dma_prep_next(host, data))
730 data->host_cookie = ++nd->cookie < 0 ? 1 : nd->cookie;
Per Forlin58c7ccb2011-07-01 18:55:24 +0200731}
732
733static void mmci_post_request(struct mmc_host *mmc, struct mmc_request *mrq,
734 int err)
735{
736 struct mmci_host *host = mmc_priv(mmc);
737 struct mmc_data *data = mrq->data;
Per Forlin58c7ccb2011-07-01 18:55:24 +0200738
Ulf Hansson653a7612013-01-21 21:29:34 +0100739 if (!data || !data->host_cookie)
Per Forlin58c7ccb2011-07-01 18:55:24 +0200740 return;
741
Ulf Hansson653a7612013-01-21 21:29:34 +0100742 mmci_dma_unmap(host, data);
Per Forlin58c7ccb2011-07-01 18:55:24 +0200743
Ulf Hansson653a7612013-01-21 21:29:34 +0100744 if (err) {
745 struct mmci_host_next *next = &host->next_data;
746 struct dma_chan *chan;
747 if (data->flags & MMC_DATA_READ)
748 chan = host->dma_rx_channel;
749 else
750 chan = host->dma_tx_channel;
751 dmaengine_terminate_all(chan);
Per Forlin58c7ccb2011-07-01 18:55:24 +0200752
Srinivas Kandagatlab5c16a62014-10-08 12:25:17 +0100753 if (host->dma_desc_current == next->dma_desc)
754 host->dma_desc_current = NULL;
755
Linus Walleije13934b2017-01-27 15:04:54 +0100756 if (host->dma_current == next->dma_chan) {
757 host->dma_in_progress = false;
Srinivas Kandagatlab5c16a62014-10-08 12:25:17 +0100758 host->dma_current = NULL;
Linus Walleije13934b2017-01-27 15:04:54 +0100759 }
Srinivas Kandagatlab5c16a62014-10-08 12:25:17 +0100760
Ulf Hansson653a7612013-01-21 21:29:34 +0100761 next->dma_desc = NULL;
762 next->dma_chan = NULL;
Srinivas Kandagatlab5c16a62014-10-08 12:25:17 +0100763 data->host_cookie = 0;
Per Forlin58c7ccb2011-07-01 18:55:24 +0200764 }
765}
766
Russell Kingc8ebae32011-01-11 19:35:53 +0000767#else
768/* Blank functions if the DMA engine is not available */
Per Forlin58c7ccb2011-07-01 18:55:24 +0200769static void mmci_get_next_data(struct mmci_host *host, struct mmc_data *data)
770{
771}
Russell Kingc8ebae32011-01-11 19:35:53 +0000772static inline void mmci_dma_setup(struct mmci_host *host)
773{
774}
775
776static inline void mmci_dma_release(struct mmci_host *host)
777{
778}
779
780static inline void mmci_dma_unmap(struct mmci_host *host, struct mmc_data *data)
781{
782}
783
Ulf Hansson653a7612013-01-21 21:29:34 +0100784static inline void mmci_dma_finalize(struct mmci_host *host,
785 struct mmc_data *data)
786{
787}
788
Russell Kingc8ebae32011-01-11 19:35:53 +0000789static inline void mmci_dma_data_error(struct mmci_host *host)
790{
791}
792
793static inline int mmci_dma_start_data(struct mmci_host *host, unsigned int datactrl)
794{
795 return -ENOSYS;
796}
Per Forlin58c7ccb2011-07-01 18:55:24 +0200797
798#define mmci_pre_request NULL
799#define mmci_post_request NULL
800
Russell Kingc8ebae32011-01-11 19:35:53 +0000801#endif
802
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803static void mmci_start_data(struct mmci_host *host, struct mmc_data *data)
804{
Rabin Vincent8301bb62010-08-09 12:57:30 +0100805 struct variant_data *variant = host->variant;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 unsigned int datactrl, timeout, irqmask;
Russell King7b09cda2005-07-01 12:02:59 +0100807 unsigned long long clks;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 void __iomem *base;
Russell King3bc87f22006-08-27 13:51:28 +0100809 int blksz_bits;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810
Linus Walleij64de0282010-02-19 01:09:10 +0100811 dev_dbg(mmc_dev(host->mmc), "blksz %04x blks %04x flags %08x\n",
812 data->blksz, data->blocks, data->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
814 host->data = data;
Rabin Vincent528320d2010-07-21 12:49:49 +0100815 host->size = data->blksz * data->blocks;
Russell King51d43752011-01-27 10:56:52 +0000816 data->bytes_xfered = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
Russell King7b09cda2005-07-01 12:02:59 +0100818 clks = (unsigned long long)data->timeout_ns * host->cclk;
Srinivas Kandagatlac4a35762014-06-02 10:08:39 +0100819 do_div(clks, NSEC_PER_SEC);
Russell King7b09cda2005-07-01 12:02:59 +0100820
821 timeout = data->timeout_clks + (unsigned int)clks;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
823 base = host->base;
824 writel(timeout, base + MMCIDATATIMER);
825 writel(host->size, base + MMCIDATALENGTH);
826
Russell King3bc87f22006-08-27 13:51:28 +0100827 blksz_bits = ffs(data->blksz) - 1;
828 BUG_ON(1 << blksz_bits != data->blksz);
829
Philippe Langlais1784b152011-03-25 08:51:52 +0100830 if (variant->blksz_datactrl16)
831 datactrl = MCI_DPSM_ENABLE | (data->blksz << 16);
Srinivas Kandagatlaff783232014-06-02 10:09:06 +0100832 else if (variant->blksz_datactrl4)
833 datactrl = MCI_DPSM_ENABLE | (data->blksz << 4);
Philippe Langlais1784b152011-03-25 08:51:52 +0100834 else
835 datactrl = MCI_DPSM_ENABLE | blksz_bits << 4;
Russell Kingc8ebae32011-01-11 19:35:53 +0000836
837 if (data->flags & MMC_DATA_READ)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 datactrl |= MCI_DPSM_DIRECTION;
Russell Kingc8ebae32011-01-11 19:35:53 +0000839
Srinivas Kandagatlac7354132014-08-22 05:55:16 +0100840 if (host->mmc->card && mmc_card_sdio(host->mmc->card)) {
841 u32 clk;
Ulf Hansson7258db72011-12-13 17:05:28 +0100842
Srinivas Kandagatlac7354132014-08-22 05:55:16 +0100843 datactrl |= variant->datactrl_mask_sdio;
Ulf Hansson06c1a122012-10-12 14:01:50 +0100844
Srinivas Kandagatlac7354132014-08-22 05:55:16 +0100845 /*
846 * The ST Micro variant for SDIO small write transfers
847 * needs to have clock H/W flow control disabled,
848 * otherwise the transfer will not start. The threshold
849 * depends on the rate of MCLK.
850 */
851 if (variant->st_sdio && data->flags & MMC_DATA_WRITE &&
852 (host->size < 8 ||
853 (host->size <= 8 && host->mclk > 50000000)))
854 clk = host->clk_reg & ~variant->clkreg_enable;
855 else
856 clk = host->clk_reg | variant->clkreg_enable;
857
858 mmci_write_clkreg(host, clk);
859 }
Ulf Hansson06c1a122012-10-12 14:01:50 +0100860
Seungwon Jeon6dad6c92014-03-14 21:12:13 +0900861 if (host->mmc->ios.timing == MMC_TIMING_UHS_DDR50 ||
862 host->mmc->ios.timing == MMC_TIMING_MMC_DDR52)
Srinivas Kandagatlae17dca22014-06-02 10:09:15 +0100863 datactrl |= variant->datactrl_mask_ddrmode;
Ulf Hansson6dbb6ee2013-01-07 15:30:44 +0100864
Russell Kingc8ebae32011-01-11 19:35:53 +0000865 /*
866 * Attempt to use DMA operation mode, if this
867 * should fail, fall back to PIO mode
868 */
869 if (!mmci_dma_start_data(host, datactrl))
870 return;
871
872 /* IRQ mode, map the SG list for CPU reading/writing */
873 mmci_init_sg(host, data);
874
875 if (data->flags & MMC_DATA_READ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 irqmask = MCI_RXFIFOHALFFULLMASK;
Russell King0425a142006-02-16 16:48:31 +0000877
878 /*
Russell Kingc4d877c2011-01-27 09:50:13 +0000879 * If we have less than the fifo 'half-full' threshold to
880 * transfer, trigger a PIO interrupt as soon as any data
881 * is available.
Russell King0425a142006-02-16 16:48:31 +0000882 */
Russell Kingc4d877c2011-01-27 09:50:13 +0000883 if (host->size < variant->fifohalfsize)
Russell King0425a142006-02-16 16:48:31 +0000884 irqmask |= MCI_RXDATAAVLBLMASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 } else {
886 /*
887 * We don't actually need to include "FIFO empty" here
888 * since its implicit in "FIFO half empty".
889 */
890 irqmask = MCI_TXFIFOHALFEMPTYMASK;
891 }
892
Ulf Hansson9cc639a2013-05-15 20:48:23 +0100893 mmci_write_datactrlreg(host, datactrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 writel(readl(base + MMCIMASK0) & ~MCI_DATAENDMASK, base + MMCIMASK0);
Linus Walleij2686b4b2010-10-19 12:39:48 +0100895 mmci_set_mask1(host, irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896}
897
898static void
899mmci_start_command(struct mmci_host *host, struct mmc_command *cmd, u32 c)
900{
901 void __iomem *base = host->base;
902
Linus Walleij64de0282010-02-19 01:09:10 +0100903 dev_dbg(mmc_dev(host->mmc), "op %02x arg %08x flags %08x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 cmd->opcode, cmd->arg, cmd->flags);
905
906 if (readl(base + MMCICOMMAND) & MCI_CPSM_ENABLE) {
907 writel(0, base + MMCICOMMAND);
Srinivas Kandagatla6adb2a82014-06-02 10:08:57 +0100908 mmci_reg_delay(host);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 }
910
911 c |= cmd->opcode | MCI_CPSM_ENABLE;
Russell Kinge9225172006-02-02 12:23:12 +0000912 if (cmd->flags & MMC_RSP_PRESENT) {
913 if (cmd->flags & MMC_RSP_136)
914 c |= MCI_CPSM_LONGRSP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 c |= MCI_CPSM_RESPONSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 }
917 if (/*interrupt*/0)
918 c |= MCI_CPSM_INTERRUPT;
919
Srinivas Kandagatlaae7b0062014-06-02 10:09:39 +0100920 if (mmc_cmd_type(cmd) == MMC_CMD_ADTC)
921 c |= host->variant->data_cmd_enable;
922
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 host->cmd = cmd;
924
925 writel(cmd->arg, base + MMCIARGUMENT);
926 writel(c, base + MMCICOMMAND);
927}
928
929static void
930mmci_data_irq(struct mmci_host *host, struct mmc_data *data,
931 unsigned int status)
932{
Ulf Hansson1cb9da52014-06-12 14:42:23 +0200933 /* Make sure we have data to handle */
934 if (!data)
935 return;
936
Linus Walleijf20f8f212010-10-19 13:41:24 +0100937 /* First check for errors */
Ulf Hanssonb63038d2011-12-13 16:51:04 +0100938 if (status & (MCI_DATACRCFAIL|MCI_DATATIMEOUT|MCI_STARTBITERR|
939 MCI_TXUNDERRUN|MCI_RXOVERRUN)) {
Linus Walleij8cb28152011-01-24 15:22:13 +0100940 u32 remain, success;
Linus Walleijf20f8f212010-10-19 13:41:24 +0100941
Russell Kingc8ebae32011-01-11 19:35:53 +0000942 /* Terminate the DMA transfer */
Ulf Hansson653a7612013-01-21 21:29:34 +0100943 if (dma_inprogress(host)) {
Russell Kingc8ebae32011-01-11 19:35:53 +0000944 mmci_dma_data_error(host);
Ulf Hansson653a7612013-01-21 21:29:34 +0100945 mmci_dma_unmap(host, data);
946 }
Russell Kingc8ebae32011-01-11 19:35:53 +0000947
Russell Kingc8afc9d2011-02-04 09:19:46 +0000948 /*
949 * Calculate how far we are into the transfer. Note that
950 * the data counter gives the number of bytes transferred
951 * on the MMC bus, not on the host side. On reads, this
952 * can be as much as a FIFO-worth of data ahead. This
953 * matters for FIFO overruns only.
954 */
Linus Walleijf5a106d2011-01-27 17:44:34 +0100955 remain = readl(host->base + MMCIDATACNT);
Linus Walleij8cb28152011-01-24 15:22:13 +0100956 success = data->blksz * data->blocks - remain;
957
Russell Kingc8afc9d2011-02-04 09:19:46 +0000958 dev_dbg(mmc_dev(host->mmc), "MCI ERROR IRQ, status 0x%08x at 0x%08x\n",
959 status, success);
Linus Walleij8cb28152011-01-24 15:22:13 +0100960 if (status & MCI_DATACRCFAIL) {
961 /* Last block was not successful */
Russell Kingc8afc9d2011-02-04 09:19:46 +0000962 success -= 1;
Pierre Ossman17b04292007-07-22 22:18:46 +0200963 data->error = -EILSEQ;
Linus Walleij8cb28152011-01-24 15:22:13 +0100964 } else if (status & MCI_DATATIMEOUT) {
Pierre Ossman17b04292007-07-22 22:18:46 +0200965 data->error = -ETIMEDOUT;
Linus Walleij757df742011-06-30 15:10:21 +0100966 } else if (status & MCI_STARTBITERR) {
967 data->error = -ECOMM;
Russell Kingc8afc9d2011-02-04 09:19:46 +0000968 } else if (status & MCI_TXUNDERRUN) {
Pierre Ossman17b04292007-07-22 22:18:46 +0200969 data->error = -EIO;
Russell Kingc8afc9d2011-02-04 09:19:46 +0000970 } else if (status & MCI_RXOVERRUN) {
971 if (success > host->variant->fifosize)
972 success -= host->variant->fifosize;
973 else
974 success = 0;
Linus Walleij8cb28152011-01-24 15:22:13 +0100975 data->error = -EIO;
Rabin Vincent4ce1d6c2010-07-21 12:44:58 +0100976 }
Russell King51d43752011-01-27 10:56:52 +0000977 data->bytes_xfered = round_down(success, data->blksz);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 }
Linus Walleijf20f8f212010-10-19 13:41:24 +0100979
Linus Walleij8cb28152011-01-24 15:22:13 +0100980 if (status & MCI_DATABLOCKEND)
981 dev_err(mmc_dev(host->mmc), "stray MCI_DATABLOCKEND interrupt\n");
Linus Walleijf20f8f212010-10-19 13:41:24 +0100982
Russell Kingccff9b52011-01-30 21:03:50 +0000983 if (status & MCI_DATAEND || data->error) {
Russell Kingc8ebae32011-01-11 19:35:53 +0000984 if (dma_inprogress(host))
Ulf Hansson653a7612013-01-21 21:29:34 +0100985 mmci_dma_finalize(host, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 mmci_stop_data(host);
987
Linus Walleij8cb28152011-01-24 15:22:13 +0100988 if (!data->error)
989 /* The error clause is handled above, success! */
Russell King51d43752011-01-27 10:56:52 +0000990 data->bytes_xfered = data->blksz * data->blocks;
Linus Walleijf20f8f212010-10-19 13:41:24 +0100991
Ulf Hansson024629c2013-05-13 15:40:56 +0100992 if (!data->stop || host->mrq->sbc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 mmci_request_end(host, data->mrq);
994 } else {
995 mmci_start_command(host, data->stop, 0);
996 }
997 }
998}
999
1000static void
1001mmci_cmd_irq(struct mmci_host *host, struct mmc_command *cmd,
1002 unsigned int status)
1003{
1004 void __iomem *base = host->base;
Linus Walleij49adc0c2016-10-25 11:06:06 +02001005 bool sbc;
Ulf Hanssonad82bfe2014-06-12 15:01:57 +02001006
1007 if (!cmd)
1008 return;
1009
1010 sbc = (cmd == host->mrq->sbc);
Ulf Hanssonad82bfe2014-06-12 15:01:57 +02001011
Linus Walleij49adc0c2016-10-25 11:06:06 +02001012 /*
1013 * We need to be one of these interrupts to be considered worth
1014 * handling. Note that we tag on any latent IRQs postponed
1015 * due to waiting for busy status.
1016 */
1017 if (!((status|host->busy_status) &
1018 (MCI_CMDCRCFAIL|MCI_CMDTIMEOUT|MCI_CMDSENT|MCI_CMDRESPEND)))
Ulf Hanssonad82bfe2014-06-12 15:01:57 +02001019 return;
Ulf Hansson8d94b542014-01-13 16:49:31 +01001020
Linus Walleij49adc0c2016-10-25 11:06:06 +02001021 /*
1022 * ST Micro variant: handle busy detection.
1023 */
1024 if (host->variant->busy_detect) {
1025 bool busy_resp = !!(cmd->flags & MMC_RSP_BUSY);
Ulf Hansson8d94b542014-01-13 16:49:31 +01001026
Linus Walleij49adc0c2016-10-25 11:06:06 +02001027 /* We are busy with a command, return */
1028 if (host->busy_status &&
1029 (status & host->variant->busy_detect_flag))
1030 return;
Ulf Hansson8d94b542014-01-13 16:49:31 +01001031
Linus Walleij49adc0c2016-10-25 11:06:06 +02001032 /*
1033 * We were not busy, but we now got a busy response on
1034 * something that was not an error, and we double-check
1035 * that the special busy status bit is still set before
1036 * proceeding.
1037 */
1038 if (!host->busy_status && busy_resp &&
1039 !(status & (MCI_CMDCRCFAIL|MCI_CMDTIMEOUT)) &&
1040 (readl(base + MMCISTATUS) & host->variant->busy_detect_flag)) {
Jean-Nicolas Graux5cad24d2017-02-07 12:12:41 +01001041
1042 /* Clear the busy start IRQ */
1043 writel(host->variant->busy_detect_mask,
1044 host->base + MMCICLEAR);
1045
1046 /* Unmask the busy end IRQ */
Linus Walleij49adc0c2016-10-25 11:06:06 +02001047 writel(readl(base + MMCIMASK0) |
1048 host->variant->busy_detect_mask,
1049 base + MMCIMASK0);
1050 /*
1051 * Now cache the last response status code (until
1052 * the busy bit goes low), and return.
1053 */
1054 host->busy_status =
1055 status & (MCI_CMDSENT|MCI_CMDRESPEND);
1056 return;
1057 }
1058
1059 /*
1060 * At this point we are not busy with a command, we have
Jean-Nicolas Graux5cad24d2017-02-07 12:12:41 +01001061 * not received a new busy request, clear and mask the busy
1062 * end IRQ and fall through to process the IRQ.
Linus Walleij49adc0c2016-10-25 11:06:06 +02001063 */
1064 if (host->busy_status) {
Jean-Nicolas Graux5cad24d2017-02-07 12:12:41 +01001065
1066 writel(host->variant->busy_detect_mask,
1067 host->base + MMCICLEAR);
1068
Linus Walleij49adc0c2016-10-25 11:06:06 +02001069 writel(readl(base + MMCIMASK0) &
1070 ~host->variant->busy_detect_mask,
1071 base + MMCIMASK0);
1072 host->busy_status = 0;
1073 }
Ulf Hansson8d94b542014-01-13 16:49:31 +01001074 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075
1076 host->cmd = NULL;
1077
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 if (status & MCI_CMDTIMEOUT) {
Pierre Ossman17b04292007-07-22 22:18:46 +02001079 cmd->error = -ETIMEDOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 } else if (status & MCI_CMDCRCFAIL && cmd->flags & MMC_RSP_CRC) {
Pierre Ossman17b04292007-07-22 22:18:46 +02001081 cmd->error = -EILSEQ;
Russell King - ARM Linux9047b432011-01-11 16:35:56 +00001082 } else {
1083 cmd->resp[0] = readl(base + MMCIRESPONSE0);
1084 cmd->resp[1] = readl(base + MMCIRESPONSE1);
1085 cmd->resp[2] = readl(base + MMCIRESPONSE2);
1086 cmd->resp[3] = readl(base + MMCIRESPONSE3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 }
1088
Ulf Hansson024629c2013-05-13 15:40:56 +01001089 if ((!sbc && !cmd->data) || cmd->error) {
Ulf Hansson3b6e3c72011-12-13 16:58:43 +01001090 if (host->data) {
1091 /* Terminate the DMA transfer */
Ulf Hansson653a7612013-01-21 21:29:34 +01001092 if (dma_inprogress(host)) {
Ulf Hansson3b6e3c72011-12-13 16:58:43 +01001093 mmci_dma_data_error(host);
Ulf Hansson653a7612013-01-21 21:29:34 +01001094 mmci_dma_unmap(host, host->data);
1095 }
Russell Kinge47c2222007-01-08 16:42:51 +00001096 mmci_stop_data(host);
Ulf Hansson3b6e3c72011-12-13 16:58:43 +01001097 }
Ulf Hansson024629c2013-05-13 15:40:56 +01001098 mmci_request_end(host, host->mrq);
1099 } else if (sbc) {
1100 mmci_start_command(host, host->mrq->cmd, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 } else if (!(cmd->data->flags & MMC_DATA_READ)) {
1102 mmci_start_data(host, cmd->data);
1103 }
1104}
1105
Srinivas Kandagatla9c34b732014-06-02 10:10:04 +01001106static int mmci_get_rx_fifocnt(struct mmci_host *host, u32 status, int remain)
1107{
1108 return remain - (readl(host->base + MMCIFIFOCNT) << 2);
1109}
1110
1111static int mmci_qcom_get_rx_fifocnt(struct mmci_host *host, u32 status, int r)
1112{
1113 /*
1114 * on qcom SDCC4 only 8 words are used in each burst so only 8 addresses
1115 * from the fifo range should be used
1116 */
1117 if (status & MCI_RXFIFOHALFFULL)
1118 return host->variant->fifohalfsize;
1119 else if (status & MCI_RXDATAAVLBL)
1120 return 4;
1121
1122 return 0;
1123}
1124
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125static int mmci_pio_read(struct mmci_host *host, char *buffer, unsigned int remain)
1126{
1127 void __iomem *base = host->base;
1128 char *ptr = buffer;
Srinivas Kandagatla9c34b732014-06-02 10:10:04 +01001129 u32 status = readl(host->base + MMCISTATUS);
Linus Walleij26eed9a2008-04-26 23:39:44 +01001130 int host_remain = host->size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131
1132 do {
Srinivas Kandagatla9c34b732014-06-02 10:10:04 +01001133 int count = host->get_rx_fifocnt(host, status, host_remain);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134
1135 if (count > remain)
1136 count = remain;
1137
1138 if (count <= 0)
1139 break;
1140
Ulf Hansson393e5e22011-12-13 17:08:04 +01001141 /*
1142 * SDIO especially may want to send something that is
1143 * not divisible by 4 (as opposed to card sectors
1144 * etc). Therefore make sure to always read the last bytes
1145 * while only doing full 32-bit reads towards the FIFO.
1146 */
1147 if (unlikely(count & 0x3)) {
1148 if (count < 4) {
1149 unsigned char buf[4];
Davide Ciminaghi4b85da02012-12-10 14:47:21 +01001150 ioread32_rep(base + MMCIFIFO, buf, 1);
Ulf Hansson393e5e22011-12-13 17:08:04 +01001151 memcpy(ptr, buf, count);
1152 } else {
Davide Ciminaghi4b85da02012-12-10 14:47:21 +01001153 ioread32_rep(base + MMCIFIFO, ptr, count >> 2);
Ulf Hansson393e5e22011-12-13 17:08:04 +01001154 count &= ~0x3;
1155 }
1156 } else {
Davide Ciminaghi4b85da02012-12-10 14:47:21 +01001157 ioread32_rep(base + MMCIFIFO, ptr, count >> 2);
Ulf Hansson393e5e22011-12-13 17:08:04 +01001158 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159
1160 ptr += count;
1161 remain -= count;
Linus Walleij26eed9a2008-04-26 23:39:44 +01001162 host_remain -= count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163
1164 if (remain == 0)
1165 break;
1166
1167 status = readl(base + MMCISTATUS);
1168 } while (status & MCI_RXDATAAVLBL);
1169
1170 return ptr - buffer;
1171}
1172
1173static int mmci_pio_write(struct mmci_host *host, char *buffer, unsigned int remain, u32 status)
1174{
Rabin Vincent8301bb62010-08-09 12:57:30 +01001175 struct variant_data *variant = host->variant;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 void __iomem *base = host->base;
1177 char *ptr = buffer;
1178
1179 do {
1180 unsigned int count, maxcnt;
1181
Rabin Vincent8301bb62010-08-09 12:57:30 +01001182 maxcnt = status & MCI_TXFIFOEMPTY ?
1183 variant->fifosize : variant->fifohalfsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 count = min(remain, maxcnt);
1185
Linus Walleij34177802010-10-19 12:43:58 +01001186 /*
Linus Walleij34177802010-10-19 12:43:58 +01001187 * SDIO especially may want to send something that is
1188 * not divisible by 4 (as opposed to card sectors
1189 * etc), and the FIFO only accept full 32-bit writes.
1190 * So compensate by adding +3 on the count, a single
1191 * byte become a 32bit write, 7 bytes will be two
1192 * 32bit writes etc.
1193 */
Davide Ciminaghi4b85da02012-12-10 14:47:21 +01001194 iowrite32_rep(base + MMCIFIFO, ptr, (count + 3) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195
1196 ptr += count;
1197 remain -= count;
1198
1199 if (remain == 0)
1200 break;
1201
1202 status = readl(base + MMCISTATUS);
1203 } while (status & MCI_TXFIFOHALFEMPTY);
1204
1205 return ptr - buffer;
1206}
1207
1208/*
1209 * PIO data transfer IRQ handler.
1210 */
David Howells7d12e782006-10-05 14:55:46 +01001211static irqreturn_t mmci_pio_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212{
1213 struct mmci_host *host = dev_id;
Rabin Vincent4ce1d6c2010-07-21 12:44:58 +01001214 struct sg_mapping_iter *sg_miter = &host->sg_miter;
Rabin Vincent8301bb62010-08-09 12:57:30 +01001215 struct variant_data *variant = host->variant;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 void __iomem *base = host->base;
Rabin Vincent4ce1d6c2010-07-21 12:44:58 +01001217 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 u32 status;
1219
1220 status = readl(base + MMCISTATUS);
1221
Linus Walleij64de0282010-02-19 01:09:10 +01001222 dev_dbg(mmc_dev(host->mmc), "irq1 (pio) %08x\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223
Rabin Vincent4ce1d6c2010-07-21 12:44:58 +01001224 local_irq_save(flags);
1225
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 do {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 unsigned int remain, len;
1228 char *buffer;
1229
1230 /*
1231 * For write, we only need to test the half-empty flag
1232 * here - if the FIFO is completely empty, then by
1233 * definition it is more than half empty.
1234 *
1235 * For read, check for data available.
1236 */
1237 if (!(status & (MCI_TXFIFOHALFEMPTY|MCI_RXDATAAVLBL)))
1238 break;
1239
Rabin Vincent4ce1d6c2010-07-21 12:44:58 +01001240 if (!sg_miter_next(sg_miter))
1241 break;
1242
1243 buffer = sg_miter->addr;
1244 remain = sg_miter->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245
1246 len = 0;
1247 if (status & MCI_RXACTIVE)
1248 len = mmci_pio_read(host, buffer, remain);
1249 if (status & MCI_TXACTIVE)
1250 len = mmci_pio_write(host, buffer, remain, status);
1251
Rabin Vincent4ce1d6c2010-07-21 12:44:58 +01001252 sg_miter->consumed = len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 host->size -= len;
1255 remain -= len;
1256
1257 if (remain)
1258 break;
1259
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 status = readl(base + MMCISTATUS);
1261 } while (1);
1262
Rabin Vincent4ce1d6c2010-07-21 12:44:58 +01001263 sg_miter_stop(sg_miter);
1264
1265 local_irq_restore(flags);
1266
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 /*
Russell Kingc4d877c2011-01-27 09:50:13 +00001268 * If we have less than the fifo 'half-full' threshold to transfer,
1269 * trigger a PIO interrupt as soon as any data is available.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 */
Russell Kingc4d877c2011-01-27 09:50:13 +00001271 if (status & MCI_RXACTIVE && host->size < variant->fifohalfsize)
Linus Walleij2686b4b2010-10-19 12:39:48 +01001272 mmci_set_mask1(host, MCI_RXDATAAVLBLMASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273
1274 /*
1275 * If we run out of data, disable the data IRQs; this
1276 * prevents a race where the FIFO becomes empty before
1277 * the chip itself has disabled the data path, and
1278 * stops us racing with our data end IRQ.
1279 */
1280 if (host->size == 0) {
Linus Walleij2686b4b2010-10-19 12:39:48 +01001281 mmci_set_mask1(host, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 writel(readl(base + MMCIMASK0) | MCI_DATAENDMASK, base + MMCIMASK0);
1283 }
1284
1285 return IRQ_HANDLED;
1286}
1287
1288/*
1289 * Handle completion of command and data transfers.
1290 */
David Howells7d12e782006-10-05 14:55:46 +01001291static irqreturn_t mmci_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292{
1293 struct mmci_host *host = dev_id;
1294 u32 status;
1295 int ret = 0;
1296
1297 spin_lock(&host->lock);
1298
1299 do {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 status = readl(host->base + MMCISTATUS);
Linus Walleij2686b4b2010-10-19 12:39:48 +01001301
1302 if (host->singleirq) {
Patrice Chotard6ea9cdf2018-01-18 15:34:17 +01001303 if (status & host->mask1_reg)
Linus Walleij2686b4b2010-10-19 12:39:48 +01001304 mmci_pio_irq(irq, dev_id);
1305
1306 status &= ~MCI_IRQ1MASK;
1307 }
1308
Ulf Hansson8d94b542014-01-13 16:49:31 +01001309 /*
Jean-Nicolas Graux5cad24d2017-02-07 12:12:41 +01001310 * We intentionally clear the MCI_ST_CARDBUSY IRQ (if it's
1311 * enabled) in mmci_cmd_irq() function where ST Micro busy
1312 * detection variant is handled. Considering the HW seems to be
1313 * triggering the IRQ on both edges while monitoring DAT0 for
1314 * busy completion and that same status bit is used to monitor
1315 * start and end of busy detection, special care must be taken
1316 * to make sure that both start and end interrupts are always
1317 * cleared one after the other.
Ulf Hansson8d94b542014-01-13 16:49:31 +01001318 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 status &= readl(host->base + MMCIMASK0);
Jean-Nicolas Graux5cad24d2017-02-07 12:12:41 +01001320 if (host->variant->busy_detect)
1321 writel(status & ~host->variant->busy_detect_mask,
1322 host->base + MMCICLEAR);
1323 else
1324 writel(status, host->base + MMCICLEAR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325
Linus Walleij64de0282010-02-19 01:09:10 +01001326 dev_dbg(mmc_dev(host->mmc), "irq0 (data+cmd) %08x\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327
Ulf Hansson78782892014-06-13 13:21:38 +02001328 if (host->variant->reversed_irq_handling) {
1329 mmci_data_irq(host, host->data, status);
1330 mmci_cmd_irq(host, host->cmd, status);
1331 } else {
1332 mmci_cmd_irq(host, host->cmd, status);
1333 mmci_data_irq(host, host->data, status);
1334 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335
Linus Walleij49adc0c2016-10-25 11:06:06 +02001336 /*
1337 * Don't poll for busy completion in irq context.
1338 */
1339 if (host->variant->busy_detect && host->busy_status)
1340 status &= ~host->variant->busy_detect_flag;
Ulf Hansson8d94b542014-01-13 16:49:31 +01001341
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 ret = 1;
1343 } while (status);
1344
1345 spin_unlock(&host->lock);
1346
1347 return IRQ_RETVAL(ret);
1348}
1349
1350static void mmci_request(struct mmc_host *mmc, struct mmc_request *mrq)
1351{
1352 struct mmci_host *host = mmc_priv(mmc);
Linus Walleij9e943022008-10-24 21:17:50 +01001353 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354
1355 WARN_ON(host->mrq != NULL);
1356
Ulf Hansson653a7612013-01-21 21:29:34 +01001357 mrq->cmd->error = mmci_validate_data(host, mrq->data);
1358 if (mrq->cmd->error) {
Pierre Ossman255d01a2007-07-24 20:38:53 +02001359 mmc_request_done(mmc, mrq);
1360 return;
1361 }
1362
Linus Walleij9e943022008-10-24 21:17:50 +01001363 spin_lock_irqsave(&host->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364
1365 host->mrq = mrq;
1366
Per Forlin58c7ccb2011-07-01 18:55:24 +02001367 if (mrq->data)
1368 mmci_get_next_data(host, mrq->data);
1369
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 if (mrq->data && mrq->data->flags & MMC_DATA_READ)
1371 mmci_start_data(host, mrq->data);
1372
Ulf Hansson024629c2013-05-13 15:40:56 +01001373 if (mrq->sbc)
1374 mmci_start_command(host, mrq->sbc, 0);
1375 else
1376 mmci_start_command(host, mrq->cmd, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377
Linus Walleij9e943022008-10-24 21:17:50 +01001378 spin_unlock_irqrestore(&host->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379}
1380
1381static void mmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1382{
1383 struct mmci_host *host = mmc_priv(mmc);
Ulf Hansson7d72a1d2011-12-13 16:54:55 +01001384 struct variant_data *variant = host->variant;
Linus Walleija6a64642009-09-14 12:56:14 +01001385 u32 pwr = 0;
1386 unsigned long flags;
Lee Jonesdb90f912013-05-03 12:52:12 +01001387 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388
Ulf Hanssonbc521812011-12-13 16:57:55 +01001389 if (host->plat->ios_handler &&
1390 host->plat->ios_handler(mmc_dev(mmc), ios))
1391 dev_err(mmc_dev(mmc), "platform ios_handler failed\n");
1392
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 switch (ios->power_mode) {
1394 case MMC_POWER_OFF:
Ulf Hansson599c1d52013-01-07 16:22:50 +01001395 if (!IS_ERR(mmc->supply.vmmc))
1396 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
Lee Jones237fb5e2013-01-31 11:27:52 +00001397
Ulf Hansson7c0136e2013-05-14 13:53:10 +01001398 if (!IS_ERR(mmc->supply.vqmmc) && host->vqmmc_enabled) {
Lee Jones237fb5e2013-01-31 11:27:52 +00001399 regulator_disable(mmc->supply.vqmmc);
Ulf Hansson7c0136e2013-05-14 13:53:10 +01001400 host->vqmmc_enabled = false;
1401 }
Lee Jones237fb5e2013-01-31 11:27:52 +00001402
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 break;
1404 case MMC_POWER_UP:
Ulf Hansson599c1d52013-01-07 16:22:50 +01001405 if (!IS_ERR(mmc->supply.vmmc))
1406 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, ios->vdd);
1407
Ulf Hansson7d72a1d2011-12-13 16:54:55 +01001408 /*
1409 * The ST Micro variant doesn't have the PL180s MCI_PWR_UP
1410 * and instead uses MCI_PWR_ON so apply whatever value is
1411 * configured in the variant data.
1412 */
1413 pwr |= variant->pwrreg_powerup;
1414
1415 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 case MMC_POWER_ON:
Ulf Hansson7c0136e2013-05-14 13:53:10 +01001417 if (!IS_ERR(mmc->supply.vqmmc) && !host->vqmmc_enabled) {
Lee Jonesdb90f912013-05-03 12:52:12 +01001418 ret = regulator_enable(mmc->supply.vqmmc);
1419 if (ret < 0)
1420 dev_err(mmc_dev(mmc),
1421 "failed to enable vqmmc regulator\n");
Ulf Hansson7c0136e2013-05-14 13:53:10 +01001422 else
1423 host->vqmmc_enabled = true;
Lee Jonesdb90f912013-05-03 12:52:12 +01001424 }
Lee Jones237fb5e2013-01-31 11:27:52 +00001425
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 pwr |= MCI_PWR_ON;
1427 break;
1428 }
1429
Ulf Hansson4d1a3a02011-12-13 16:57:07 +01001430 if (variant->signal_direction && ios->power_mode != MMC_POWER_OFF) {
1431 /*
1432 * The ST Micro variant has some additional bits
1433 * indicating signal direction for the signals in
1434 * the SD/MMC bus and feedback-clock usage.
1435 */
Ulf Hansson4593df22014-03-21 10:13:05 +01001436 pwr |= host->pwr_reg_add;
Ulf Hansson4d1a3a02011-12-13 16:57:07 +01001437
1438 if (ios->bus_width == MMC_BUS_WIDTH_4)
1439 pwr &= ~MCI_ST_DATA74DIREN;
1440 else if (ios->bus_width == MMC_BUS_WIDTH_1)
1441 pwr &= (~MCI_ST_DATA74DIREN &
1442 ~MCI_ST_DATA31DIREN &
1443 ~MCI_ST_DATA2DIREN);
1444 }
1445
Linus Walleijcc30d602009-01-04 15:18:54 +01001446 if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN) {
Linus Walleijf17a1f02009-08-04 01:01:02 +01001447 if (host->hw_designer != AMBA_VENDOR_ST)
Linus Walleijcc30d602009-01-04 15:18:54 +01001448 pwr |= MCI_ROD;
1449 else {
1450 /*
1451 * The ST Micro variant use the ROD bit for something
1452 * else and only has OD (Open Drain).
1453 */
1454 pwr |= MCI_OD;
1455 }
1456 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457
Ulf Hanssonf4670da2013-01-09 17:19:54 +01001458 /*
1459 * If clock = 0 and the variant requires the MMCIPOWER to be used for
1460 * gating the clock, the MCI_PWR_ON bit is cleared.
1461 */
1462 if (!ios->clock && variant->pwrreg_clkgate)
1463 pwr &= ~MCI_PWR_ON;
1464
Srinivas Kandagatla3f4e6f72014-06-02 10:09:55 +01001465 if (host->variant->explicit_mclk_control &&
1466 ios->clock != host->clock_cache) {
1467 ret = clk_set_rate(host->clk, ios->clock);
1468 if (ret < 0)
1469 dev_err(mmc_dev(host->mmc),
1470 "Error setting clock rate (%d)\n", ret);
1471 else
1472 host->mclk = clk_get_rate(host->clk);
1473 }
1474 host->clock_cache = ios->clock;
1475
Linus Walleija6a64642009-09-14 12:56:14 +01001476 spin_lock_irqsave(&host->lock, flags);
1477
1478 mmci_set_clkreg(host, ios->clock);
Ulf Hansson7437cfa2012-01-18 09:17:27 +01001479 mmci_write_pwrreg(host, pwr);
Ulf Hanssonf829c042013-09-04 09:01:15 +01001480 mmci_reg_delay(host);
Linus Walleija6a64642009-09-14 12:56:14 +01001481
1482 spin_unlock_irqrestore(&host->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483}
1484
Russell King89001442009-07-09 15:16:07 +01001485static int mmci_get_cd(struct mmc_host *mmc)
1486{
1487 struct mmci_host *host = mmc_priv(mmc);
Rabin Vincent29719442010-08-09 12:54:43 +01001488 struct mmci_platform_data *plat = host->plat;
Ulf Hanssond2762092014-03-17 13:56:19 +01001489 unsigned int status = mmc_gpio_get_cd(mmc);
Russell King89001442009-07-09 15:16:07 +01001490
Ulf Hanssond2762092014-03-17 13:56:19 +01001491 if (status == -ENOSYS) {
Rabin Vincent4b8caec2010-08-09 12:56:40 +01001492 if (!plat->status)
1493 return 1; /* Assume always present */
1494
Rabin Vincent29719442010-08-09 12:54:43 +01001495 status = plat->status(mmc_dev(host->mmc));
Ulf Hanssond2762092014-03-17 13:56:19 +01001496 }
Russell King74bc8092010-07-29 15:58:59 +01001497 return status;
Russell King89001442009-07-09 15:16:07 +01001498}
1499
Ulf Hansson0f3ed7f2013-05-15 20:47:33 +01001500static int mmci_sig_volt_switch(struct mmc_host *mmc, struct mmc_ios *ios)
1501{
1502 int ret = 0;
1503
1504 if (!IS_ERR(mmc->supply.vqmmc)) {
1505
Ulf Hansson0f3ed7f2013-05-15 20:47:33 +01001506 switch (ios->signal_voltage) {
1507 case MMC_SIGNAL_VOLTAGE_330:
1508 ret = regulator_set_voltage(mmc->supply.vqmmc,
1509 2700000, 3600000);
1510 break;
1511 case MMC_SIGNAL_VOLTAGE_180:
1512 ret = regulator_set_voltage(mmc->supply.vqmmc,
1513 1700000, 1950000);
1514 break;
1515 case MMC_SIGNAL_VOLTAGE_120:
1516 ret = regulator_set_voltage(mmc->supply.vqmmc,
1517 1100000, 1300000);
1518 break;
1519 }
1520
1521 if (ret)
1522 dev_warn(mmc_dev(mmc), "Voltage switch failed\n");
Ulf Hansson0f3ed7f2013-05-15 20:47:33 +01001523 }
1524
1525 return ret;
1526}
1527
Ulf Hansson01259622013-05-15 20:53:22 +01001528static struct mmc_host_ops mmci_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 .request = mmci_request,
Per Forlin58c7ccb2011-07-01 18:55:24 +02001530 .pre_req = mmci_pre_request,
1531 .post_req = mmci_post_request,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 .set_ios = mmci_set_ios,
Ulf Hanssond2762092014-03-17 13:56:19 +01001533 .get_ro = mmc_gpio_get_ro,
Russell King89001442009-07-09 15:16:07 +01001534 .get_cd = mmci_get_cd,
Ulf Hansson0f3ed7f2013-05-15 20:47:33 +01001535 .start_signal_voltage_switch = mmci_sig_volt_switch,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536};
1537
Ulf Hansson78f87df2014-03-17 15:53:07 +01001538static int mmci_of_parse(struct device_node *np, struct mmc_host *mmc)
1539{
Ulf Hansson4593df22014-03-21 10:13:05 +01001540 struct mmci_host *host = mmc_priv(mmc);
Ulf Hansson78f87df2014-03-17 15:53:07 +01001541 int ret = mmc_of_parse(mmc);
Lee Jones000bc9d2012-04-16 10:18:43 +01001542
Ulf Hansson78f87df2014-03-17 15:53:07 +01001543 if (ret)
1544 return ret;
Lee Jones000bc9d2012-04-16 10:18:43 +01001545
Ulf Hansson4593df22014-03-21 10:13:05 +01001546 if (of_get_property(np, "st,sig-dir-dat0", NULL))
1547 host->pwr_reg_add |= MCI_ST_DATA0DIREN;
1548 if (of_get_property(np, "st,sig-dir-dat2", NULL))
1549 host->pwr_reg_add |= MCI_ST_DATA2DIREN;
1550 if (of_get_property(np, "st,sig-dir-dat31", NULL))
1551 host->pwr_reg_add |= MCI_ST_DATA31DIREN;
1552 if (of_get_property(np, "st,sig-dir-dat74", NULL))
1553 host->pwr_reg_add |= MCI_ST_DATA74DIREN;
1554 if (of_get_property(np, "st,sig-dir-cmd", NULL))
1555 host->pwr_reg_add |= MCI_ST_CMDDIREN;
1556 if (of_get_property(np, "st,sig-pin-fbclk", NULL))
1557 host->pwr_reg_add |= MCI_ST_FBCLKEN;
1558
Lee Jones000bc9d2012-04-16 10:18:43 +01001559 if (of_get_property(np, "mmc-cap-mmc-highspeed", NULL))
Ulf Hansson78f87df2014-03-17 15:53:07 +01001560 mmc->caps |= MMC_CAP_MMC_HIGHSPEED;
Lee Jones000bc9d2012-04-16 10:18:43 +01001561 if (of_get_property(np, "mmc-cap-sd-highspeed", NULL))
Ulf Hansson78f87df2014-03-17 15:53:07 +01001562 mmc->caps |= MMC_CAP_SD_HIGHSPEED;
Lee Jones000bc9d2012-04-16 10:18:43 +01001563
Ulf Hansson78f87df2014-03-17 15:53:07 +01001564 return 0;
Lee Jones000bc9d2012-04-16 10:18:43 +01001565}
Lee Jones000bc9d2012-04-16 10:18:43 +01001566
Bill Pembertonc3be1ef2012-11-19 13:23:06 -05001567static int mmci_probe(struct amba_device *dev,
Russell Kingaa25afa2011-02-19 15:55:00 +00001568 const struct amba_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569{
Linus Walleij6ef297f2009-09-22 14:29:36 +01001570 struct mmci_platform_data *plat = dev->dev.platform_data;
Lee Jones000bc9d2012-04-16 10:18:43 +01001571 struct device_node *np = dev->dev.of_node;
Rabin Vincent4956e102010-07-21 12:54:40 +01001572 struct variant_data *variant = id->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 struct mmci_host *host;
1574 struct mmc_host *mmc;
1575 int ret;
1576
Lee Jones000bc9d2012-04-16 10:18:43 +01001577 /* Must have platform data or Device Tree. */
1578 if (!plat && !np) {
1579 dev_err(&dev->dev, "No plat data or DT found\n");
1580 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 }
1582
Lee Jonesb9b52912012-06-12 10:49:51 +01001583 if (!plat) {
1584 plat = devm_kzalloc(&dev->dev, sizeof(*plat), GFP_KERNEL);
1585 if (!plat)
1586 return -ENOMEM;
1587 }
1588
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 mmc = mmc_alloc_host(sizeof(struct mmci_host), &dev->dev);
Ulf Hanssonef289982014-03-17 13:56:32 +01001590 if (!mmc)
1591 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592
Ulf Hansson78f87df2014-03-17 15:53:07 +01001593 ret = mmci_of_parse(np, mmc);
1594 if (ret)
1595 goto host_free;
1596
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 host = mmc_priv(mmc);
Rabin Vincent4ea580f2009-04-17 08:44:19 +05301598 host->mmc = mmc;
Russell King012b7d32009-07-09 15:13:56 +01001599
1600 host->hw_designer = amba_manf(dev);
1601 host->hw_revision = amba_rev(dev);
Linus Walleij64de0282010-02-19 01:09:10 +01001602 dev_dbg(mmc_dev(mmc), "designer ID = 0x%02x\n", host->hw_designer);
1603 dev_dbg(mmc_dev(mmc), "revision = 0x%01x\n", host->hw_revision);
Russell King012b7d32009-07-09 15:13:56 +01001604
Ulf Hansson665ba562013-05-13 15:39:17 +01001605 host->clk = devm_clk_get(&dev->dev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 if (IS_ERR(host->clk)) {
1607 ret = PTR_ERR(host->clk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 goto host_free;
1609 }
1610
Julia Lawallac940932012-08-26 16:00:59 +00001611 ret = clk_prepare_enable(host->clk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 if (ret)
Ulf Hansson665ba562013-05-13 15:39:17 +01001613 goto host_free;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614
Srinivas Kandagatla9c34b732014-06-02 10:10:04 +01001615 if (variant->qcom_fifo)
1616 host->get_rx_fifocnt = mmci_qcom_get_rx_fifocnt;
1617 else
1618 host->get_rx_fifocnt = mmci_get_rx_fifocnt;
1619
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 host->plat = plat;
Rabin Vincent4956e102010-07-21 12:54:40 +01001621 host->variant = variant;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 host->mclk = clk_get_rate(host->clk);
Linus Walleijc8df9a52008-04-29 09:34:07 +01001623 /*
1624 * According to the spec, mclk is max 100 MHz,
1625 * so we try to adjust the clock down to this,
1626 * (if possible).
1627 */
Srinivas Kandagatladc6500b2014-06-02 10:09:47 +01001628 if (host->mclk > variant->f_max) {
1629 ret = clk_set_rate(host->clk, variant->f_max);
Linus Walleijc8df9a52008-04-29 09:34:07 +01001630 if (ret < 0)
1631 goto clk_disable;
1632 host->mclk = clk_get_rate(host->clk);
Linus Walleij64de0282010-02-19 01:09:10 +01001633 dev_dbg(mmc_dev(mmc), "eventual mclk rate: %u Hz\n",
1634 host->mclk);
Linus Walleijc8df9a52008-04-29 09:34:07 +01001635 }
Ulf Hanssonef289982014-03-17 13:56:32 +01001636
Russell Kingc8ebae32011-01-11 19:35:53 +00001637 host->phybase = dev->res.start;
Ulf Hanssonef289982014-03-17 13:56:32 +01001638 host->base = devm_ioremap_resource(&dev->dev, &dev->res);
1639 if (IS_ERR(host->base)) {
1640 ret = PTR_ERR(host->base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 goto clk_disable;
1642 }
1643
Linus Walleij7f294e42011-07-08 09:57:15 +01001644 /*
1645 * The ARM and ST versions of the block have slightly different
1646 * clock divider equations which means that the minimum divider
1647 * differs too.
Srinivas Kandagatla3f4e6f72014-06-02 10:09:55 +01001648 * on Qualcomm like controllers get the nearest minimum clock to 100Khz
Linus Walleij7f294e42011-07-08 09:57:15 +01001649 */
1650 if (variant->st_clkdiv)
1651 mmc->f_min = DIV_ROUND_UP(host->mclk, 257);
Srinivas Kandagatla3f4e6f72014-06-02 10:09:55 +01001652 else if (variant->explicit_mclk_control)
1653 mmc->f_min = clk_round_rate(host->clk, 100000);
Linus Walleij7f294e42011-07-08 09:57:15 +01001654 else
1655 mmc->f_min = DIV_ROUND_UP(host->mclk, 512);
Linus Walleij808d97c2010-04-08 07:39:38 +01001656 /*
Ulf Hansson78f87df2014-03-17 15:53:07 +01001657 * If no maximum operating frequency is supplied, fall back to use
1658 * the module parameter, which has a (low) default value in case it
1659 * is not specified. Either value must not exceed the clock rate into
Ulf Hansson5080a082014-03-21 10:46:39 +01001660 * the block, of course.
Linus Walleij808d97c2010-04-08 07:39:38 +01001661 */
Ulf Hansson78f87df2014-03-17 15:53:07 +01001662 if (mmc->f_max)
Srinivas Kandagatla3f4e6f72014-06-02 10:09:55 +01001663 mmc->f_max = variant->explicit_mclk_control ?
1664 min(variant->f_max, mmc->f_max) :
1665 min(host->mclk, mmc->f_max);
Linus Walleij808d97c2010-04-08 07:39:38 +01001666 else
Srinivas Kandagatla3f4e6f72014-06-02 10:09:55 +01001667 mmc->f_max = variant->explicit_mclk_control ?
1668 fmax : min(host->mclk, fmax);
1669
1670
Linus Walleij64de0282010-02-19 01:09:10 +01001671 dev_dbg(mmc_dev(mmc), "clocking block at %u Hz\n", mmc->f_max);
1672
Ulf Hansson599c1d52013-01-07 16:22:50 +01001673 /* Get regulators and the supported OCR mask */
Bjorn Andersson9369c972015-03-24 18:39:49 -07001674 ret = mmc_regulator_get_supply(mmc);
Wolfram Sang510069522017-10-14 21:17:14 +02001675 if (ret)
Bjorn Andersson9369c972015-03-24 18:39:49 -07001676 goto clk_disable;
1677
Ulf Hansson599c1d52013-01-07 16:22:50 +01001678 if (!mmc->ocr_avail)
Linus Walleij34e84f32009-09-22 14:41:40 +01001679 mmc->ocr_avail = plat->ocr_mask;
Ulf Hansson599c1d52013-01-07 16:22:50 +01001680 else if (plat->ocr_mask)
1681 dev_warn(mmc_dev(mmc), "Platform OCR mask is ignored\n");
1682
Ulf Hansson78f87df2014-03-17 15:53:07 +01001683 /* DT takes precedence over platform data. */
Ulf Hansson78f87df2014-03-17 15:53:07 +01001684 if (!np) {
1685 if (!plat->cd_invert)
1686 mmc->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH;
1687 mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;
1688 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689
Ulf Hansson9dd8a8b2014-03-19 13:54:18 +01001690 /* We support these capabilities. */
1691 mmc->caps |= MMC_CAP_CMD23;
1692
Linus Walleij49adc0c2016-10-25 11:06:06 +02001693 /*
1694 * Enable busy detection.
1695 */
Ulf Hansson8d94b542014-01-13 16:49:31 +01001696 if (variant->busy_detect) {
1697 mmci_ops.card_busy = mmci_card_busy;
Linus Walleij49adc0c2016-10-25 11:06:06 +02001698 /*
1699 * Not all variants have a flag to enable busy detection
1700 * in the DPSM, but if they do, set it here.
1701 */
1702 if (variant->busy_dpsm_flag)
1703 mmci_write_datactrlreg(host,
1704 host->variant->busy_dpsm_flag);
Ulf Hansson8d94b542014-01-13 16:49:31 +01001705 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
1706 mmc->max_busy_timeout = 0;
1707 }
1708
1709 mmc->ops = &mmci_ops;
1710
Ulf Hansson70be2082013-01-07 15:35:06 +01001711 /* We support these PM capabilities. */
Ulf Hansson78f87df2014-03-17 15:53:07 +01001712 mmc->pm_caps |= MMC_PM_KEEP_POWER;
Ulf Hansson70be2082013-01-07 15:35:06 +01001713
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 /*
1715 * We can do SGIO
1716 */
Martin K. Petersena36274e2010-09-10 01:33:59 -04001717 mmc->max_segs = NR_SG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718
1719 /*
Rabin Vincent08458ef2010-07-21 12:55:59 +01001720 * Since only a certain number of bits are valid in the data length
1721 * register, we must ensure that we don't exceed 2^num-1 bytes in a
1722 * single request.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 */
Rabin Vincent08458ef2010-07-21 12:55:59 +01001724 mmc->max_req_size = (1 << variant->datalength_bits) - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725
1726 /*
1727 * Set the maximum segment size. Since we aren't doing DMA
1728 * (yet) we are only limited by the data length register.
1729 */
Pierre Ossman55db8902006-11-21 17:55:45 +01001730 mmc->max_seg_size = mmc->max_req_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731
Pierre Ossmanfe4a3c72006-11-21 17:54:23 +01001732 /*
1733 * Block size can be up to 2048 bytes, but must be a power of two.
1734 */
Will Deacon8f7f6b7e2012-02-24 11:25:21 +00001735 mmc->max_blk_size = 1 << 11;
Pierre Ossmanfe4a3c72006-11-21 17:54:23 +01001736
Pierre Ossman55db8902006-11-21 17:55:45 +01001737 /*
Will Deacon8f7f6b7e2012-02-24 11:25:21 +00001738 * Limit the number of blocks transferred so that we don't overflow
1739 * the maximum request size.
Pierre Ossman55db8902006-11-21 17:55:45 +01001740 */
Will Deacon8f7f6b7e2012-02-24 11:25:21 +00001741 mmc->max_blk_count = mmc->max_req_size >> 11;
Pierre Ossman55db8902006-11-21 17:55:45 +01001742
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 spin_lock_init(&host->lock);
1744
1745 writel(0, host->base + MMCIMASK0);
Patrice Chotard6ea9cdf2018-01-18 15:34:17 +01001746
1747 if (variant->mmcimask1)
1748 writel(0, host->base + MMCIMASK1);
1749
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 writel(0xfff, host->base + MMCICLEAR);
1751
Linus Walleijce437aa2014-08-27 15:13:54 +02001752 /*
1753 * If:
1754 * - not using DT but using a descriptor table, or
1755 * - using a table of descriptors ALONGSIDE DT, or
1756 * look up these descriptors named "cd" and "wp" right here, fail
1757 * silently of these do not exist and proceed to try platform data
1758 */
1759 if (!np) {
Linus Walleij89168b42014-10-02 09:08:46 +02001760 ret = mmc_gpiod_request_cd(mmc, "cd", 0, false, 0, NULL);
Linus Walleijce437aa2014-08-27 15:13:54 +02001761 if (ret < 0) {
1762 if (ret == -EPROBE_DEFER)
1763 goto clk_disable;
1764 else if (gpio_is_valid(plat->gpio_cd)) {
1765 ret = mmc_gpio_request_cd(mmc, plat->gpio_cd, 0);
1766 if (ret)
1767 goto clk_disable;
1768 }
1769 }
1770
Linus Walleij89168b42014-10-02 09:08:46 +02001771 ret = mmc_gpiod_request_ro(mmc, "wp", 0, false, 0, NULL);
Linus Walleijce437aa2014-08-27 15:13:54 +02001772 if (ret < 0) {
1773 if (ret == -EPROBE_DEFER)
1774 goto clk_disable;
1775 else if (gpio_is_valid(plat->gpio_wp)) {
1776 ret = mmc_gpio_request_ro(mmc, plat->gpio_wp);
1777 if (ret)
1778 goto clk_disable;
1779 }
1780 }
Russell King89001442009-07-09 15:16:07 +01001781 }
1782
Ulf Hanssonef289982014-03-17 13:56:32 +01001783 ret = devm_request_irq(&dev->dev, dev->irq[0], mmci_irq, IRQF_SHARED,
1784 DRIVER_NAME " (cmd)", host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 if (ret)
Ulf Hanssonef289982014-03-17 13:56:32 +01001786 goto clk_disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787
Russell Kingdfb85182012-05-03 11:33:15 +01001788 if (!dev->irq[1])
Linus Walleij2686b4b2010-10-19 12:39:48 +01001789 host->singleirq = true;
1790 else {
Ulf Hanssonef289982014-03-17 13:56:32 +01001791 ret = devm_request_irq(&dev->dev, dev->irq[1], mmci_pio_irq,
1792 IRQF_SHARED, DRIVER_NAME " (pio)", host);
Linus Walleij2686b4b2010-10-19 12:39:48 +01001793 if (ret)
Ulf Hanssonef289982014-03-17 13:56:32 +01001794 goto clk_disable;
Linus Walleij2686b4b2010-10-19 12:39:48 +01001795 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796
Linus Walleij8cb28152011-01-24 15:22:13 +01001797 writel(MCI_IRQENABLE, host->base + MMCIMASK0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798
1799 amba_set_drvdata(dev, mmc);
1800
Russell Kingc8ebae32011-01-11 19:35:53 +00001801 dev_info(&dev->dev, "%s: PL%03x manf %x rev%u at 0x%08llx irq %d,%d (pio)\n",
1802 mmc_hostname(mmc), amba_part(dev), amba_manf(dev),
1803 amba_rev(dev), (unsigned long long)dev->res.start,
1804 dev->irq[0], dev->irq[1]);
1805
1806 mmci_dma_setup(host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807
Ulf Hansson2cd976c2011-12-13 17:01:11 +01001808 pm_runtime_set_autosuspend_delay(&dev->dev, 50);
1809 pm_runtime_use_autosuspend(&dev->dev);
Russell King1c3be362011-08-14 09:17:05 +01001810
Russell King8c11a942010-12-28 19:40:40 +00001811 mmc_add_host(mmc);
1812
Ulf Hansson6f2d3c82014-12-11 14:35:55 +01001813 pm_runtime_put(&dev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 return 0;
1815
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 clk_disable:
Julia Lawallac940932012-08-26 16:00:59 +00001817 clk_disable_unprepare(host->clk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 host_free:
1819 mmc_free_host(mmc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 return ret;
1821}
1822
Bill Pemberton6e0ee712012-11-19 13:26:03 -05001823static int mmci_remove(struct amba_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824{
1825 struct mmc_host *mmc = amba_get_drvdata(dev);
1826
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 if (mmc) {
1828 struct mmci_host *host = mmc_priv(mmc);
Patrice Chotard6ea9cdf2018-01-18 15:34:17 +01001829 struct variant_data *variant = host->variant;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830
Russell King1c3be362011-08-14 09:17:05 +01001831 /*
1832 * Undo pm_runtime_put() in probe. We use the _sync
1833 * version here so that we can access the primecell.
1834 */
1835 pm_runtime_get_sync(&dev->dev);
1836
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 mmc_remove_host(mmc);
1838
1839 writel(0, host->base + MMCIMASK0);
Patrice Chotard6ea9cdf2018-01-18 15:34:17 +01001840
1841 if (variant->mmcimask1)
1842 writel(0, host->base + MMCIMASK1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843
1844 writel(0, host->base + MMCICOMMAND);
1845 writel(0, host->base + MMCIDATACTRL);
1846
Russell Kingc8ebae32011-01-11 19:35:53 +00001847 mmci_dma_release(host);
Julia Lawallac940932012-08-26 16:00:59 +00001848 clk_disable_unprepare(host->clk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 mmc_free_host(mmc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 }
1851
1852 return 0;
1853}
1854
Ulf Hansson571dce42014-01-23 00:38:00 +01001855#ifdef CONFIG_PM
Ulf Hansson1ff44432013-09-04 09:05:17 +01001856static void mmci_save(struct mmci_host *host)
1857{
1858 unsigned long flags;
1859
Ulf Hansson42dcc89a2014-01-23 00:19:38 +01001860 spin_lock_irqsave(&host->lock, flags);
Ulf Hansson1ff44432013-09-04 09:05:17 +01001861
Ulf Hansson42dcc89a2014-01-23 00:19:38 +01001862 writel(0, host->base + MMCIMASK0);
1863 if (host->variant->pwrreg_nopower) {
Ulf Hansson1ff44432013-09-04 09:05:17 +01001864 writel(0, host->base + MMCIDATACTRL);
1865 writel(0, host->base + MMCIPOWER);
1866 writel(0, host->base + MMCICLOCK);
Ulf Hansson1ff44432013-09-04 09:05:17 +01001867 }
Ulf Hansson42dcc89a2014-01-23 00:19:38 +01001868 mmci_reg_delay(host);
Ulf Hansson1ff44432013-09-04 09:05:17 +01001869
Ulf Hansson42dcc89a2014-01-23 00:19:38 +01001870 spin_unlock_irqrestore(&host->lock, flags);
Ulf Hansson1ff44432013-09-04 09:05:17 +01001871}
1872
1873static void mmci_restore(struct mmci_host *host)
1874{
1875 unsigned long flags;
1876
Ulf Hansson42dcc89a2014-01-23 00:19:38 +01001877 spin_lock_irqsave(&host->lock, flags);
Ulf Hansson1ff44432013-09-04 09:05:17 +01001878
Ulf Hansson42dcc89a2014-01-23 00:19:38 +01001879 if (host->variant->pwrreg_nopower) {
Ulf Hansson1ff44432013-09-04 09:05:17 +01001880 writel(host->clk_reg, host->base + MMCICLOCK);
1881 writel(host->datactrl_reg, host->base + MMCIDATACTRL);
1882 writel(host->pwr_reg, host->base + MMCIPOWER);
Ulf Hansson1ff44432013-09-04 09:05:17 +01001883 }
Ulf Hansson42dcc89a2014-01-23 00:19:38 +01001884 writel(MCI_IRQENABLE, host->base + MMCIMASK0);
1885 mmci_reg_delay(host);
1886
1887 spin_unlock_irqrestore(&host->lock, flags);
Ulf Hansson1ff44432013-09-04 09:05:17 +01001888}
1889
Ulf Hansson82592932013-01-09 11:15:26 +01001890static int mmci_runtime_suspend(struct device *dev)
1891{
1892 struct amba_device *adev = to_amba_device(dev);
1893 struct mmc_host *mmc = amba_get_drvdata(adev);
1894
1895 if (mmc) {
1896 struct mmci_host *host = mmc_priv(mmc);
Ulf Hanssone36bd9c62013-09-04 09:00:37 +01001897 pinctrl_pm_select_sleep_state(dev);
Ulf Hansson1ff44432013-09-04 09:05:17 +01001898 mmci_save(host);
Ulf Hansson82592932013-01-09 11:15:26 +01001899 clk_disable_unprepare(host->clk);
1900 }
1901
1902 return 0;
1903}
1904
1905static int mmci_runtime_resume(struct device *dev)
1906{
1907 struct amba_device *adev = to_amba_device(dev);
1908 struct mmc_host *mmc = amba_get_drvdata(adev);
1909
1910 if (mmc) {
1911 struct mmci_host *host = mmc_priv(mmc);
1912 clk_prepare_enable(host->clk);
Ulf Hansson1ff44432013-09-04 09:05:17 +01001913 mmci_restore(host);
Ulf Hanssone36bd9c62013-09-04 09:00:37 +01001914 pinctrl_pm_select_default_state(dev);
Ulf Hansson82592932013-01-09 11:15:26 +01001915 }
1916
1917 return 0;
1918}
1919#endif
1920
Ulf Hansson48fa7002011-12-13 16:59:34 +01001921static const struct dev_pm_ops mmci_dev_pm_ops = {
Ulf Hanssonf3737fa2014-01-23 01:11:33 +01001922 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
1923 pm_runtime_force_resume)
Rafael J. Wysocki6ed23b82014-12-04 00:34:11 +01001924 SET_RUNTIME_PM_OPS(mmci_runtime_suspend, mmci_runtime_resume, NULL)
Ulf Hansson48fa7002011-12-13 16:59:34 +01001925};
1926
Arvind Yadav88411de2017-08-23 22:00:49 +05301927static const struct amba_id mmci_ids[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 {
1929 .id = 0x00041180,
Pawel Moll768fbc12011-03-11 17:18:07 +00001930 .mask = 0xff0fffff,
Rabin Vincent4956e102010-07-21 12:54:40 +01001931 .data = &variant_arm,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 },
1933 {
Pawel Moll768fbc12011-03-11 17:18:07 +00001934 .id = 0x01041180,
1935 .mask = 0xff0fffff,
1936 .data = &variant_arm_extended_fifo,
1937 },
1938 {
Pawel Moll3a372982013-01-24 14:12:45 +01001939 .id = 0x02041180,
1940 .mask = 0xff0fffff,
1941 .data = &variant_arm_extended_fifo_hwfc,
1942 },
1943 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 .id = 0x00041181,
1945 .mask = 0x000fffff,
Rabin Vincent4956e102010-07-21 12:54:40 +01001946 .data = &variant_arm,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 },
Linus Walleijcc30d602009-01-04 15:18:54 +01001948 /* ST Micro variants */
1949 {
1950 .id = 0x00180180,
1951 .mask = 0x00ffffff,
Rabin Vincent4956e102010-07-21 12:54:40 +01001952 .data = &variant_u300,
Linus Walleijcc30d602009-01-04 15:18:54 +01001953 },
1954 {
Linus Walleij34fd4212012-04-10 17:43:59 +01001955 .id = 0x10180180,
1956 .mask = 0xf0ffffff,
1957 .data = &variant_nomadik,
1958 },
1959 {
Linus Walleijcc30d602009-01-04 15:18:54 +01001960 .id = 0x00280180,
1961 .mask = 0x00ffffff,
Linus Walleij0bcb7ef2016-01-04 02:21:55 +01001962 .data = &variant_nomadik,
Rabin Vincent4956e102010-07-21 12:54:40 +01001963 },
1964 {
1965 .id = 0x00480180,
Philippe Langlais1784b152011-03-25 08:51:52 +01001966 .mask = 0xf0ffffff,
Rabin Vincent4956e102010-07-21 12:54:40 +01001967 .data = &variant_ux500,
Linus Walleijcc30d602009-01-04 15:18:54 +01001968 },
Philippe Langlais1784b152011-03-25 08:51:52 +01001969 {
1970 .id = 0x10480180,
1971 .mask = 0xf0ffffff,
1972 .data = &variant_ux500v2,
1973 },
Srinivas Kandagatla55b604a2014-06-02 10:10:13 +01001974 /* Qualcomm variants */
1975 {
1976 .id = 0x00051180,
1977 .mask = 0x000fffff,
1978 .data = &variant_qcom,
1979 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 { 0, 0 },
1981};
1982
Dave Martin9f998352011-10-05 15:15:21 +01001983MODULE_DEVICE_TABLE(amba, mmci_ids);
1984
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985static struct amba_driver mmci_driver = {
1986 .drv = {
1987 .name = DRIVER_NAME,
Ulf Hansson48fa7002011-12-13 16:59:34 +01001988 .pm = &mmci_dev_pm_ops,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 },
1990 .probe = mmci_probe,
Bill Pemberton0433c142012-11-19 13:20:26 -05001991 .remove = mmci_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 .id_table = mmci_ids,
1993};
1994
viresh kumar9e5ed092012-03-15 10:40:38 +01001995module_amba_driver(mmci_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997module_param(fmax, uint, 0444);
1998
1999MODULE_DESCRIPTION("ARM PrimeCell PL180/181 Multimedia Card Interface driver");
2000MODULE_LICENSE("GPL");