blob: 19e4c29e4233b04226bec6bf41ec29f2b86e7d62 [file] [log] [blame]
Magnus Damma87d5632009-10-02 02:22:09 +00001/*
2 * SuperH Mobile SDHI
3 *
Wolfram Sanga72e8b12016-02-15 16:01:48 +01004 * Copyright (C) 2016 Sang Engineering, Wolfram Sang
5 * Copyright (C) 2015-16 Renesas Electronics Corporation
Magnus Damma87d5632009-10-02 02:22:09 +00006 * Copyright (C) 2009 Magnus Damm
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * Based on "Compaq ASIC3 support":
13 *
14 * Copyright 2001 Compaq Computer Corporation.
15 * Copyright 2004-2005 Phil Blundell
16 * Copyright 2007-2008 OpenedHand Ltd.
17 *
18 * Authors: Phil Blundell <pb@handhelds.org>,
19 * Samuel Ortiz <sameo@openedhand.com>
20 *
21 */
22
23#include <linux/kernel.h>
24#include <linux/clk.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Guennadi Liakhovetskic7bb4482012-05-01 18:03:43 +020026#include <linux/mod_devicetable.h>
Paul Gortmaker88b47672011-07-03 15:15:51 -040027#include <linux/module.h>
Guennadi Liakhovetski5a00a972013-02-15 16:13:56 +010028#include <linux/of_device.h>
Magnus Damma87d5632009-10-02 02:22:09 +000029#include <linux/platform_device.h>
Magnus Damm3c49e812010-02-22 13:37:09 +090030#include <linux/mmc/host.h>
Magnus Damma87d5632009-10-02 02:22:09 +000031#include <linux/mfd/tmio.h>
Guennadi Liakhovetski056676d2010-05-19 18:34:16 +000032#include <linux/sh_dma.h>
Simon Horman973ed3a2011-06-21 08:00:10 +090033#include <linux/delay.h>
Wolfram Sang057a4592016-04-01 17:44:37 +020034#include <linux/pinctrl/consumer.h>
35#include <linux/pinctrl/pinctrl-state.h>
36#include <linux/regulator/consumer.h>
Magnus Damma87d5632009-10-02 02:22:09 +000037
Guennadi Liakhovetski42051e82011-03-14 09:52:33 +010038#include "tmio_mmc.h"
39
Kuninori Morimotoe3c418f2013-11-20 00:31:13 -080040#define EXT_ACC 0xe4
41
Kuninori Morimoto16935252015-01-13 04:59:43 +000042#define host_to_priv(host) container_of((host)->pdata, struct sh_mobile_sdhi, mmc_data)
43
Guennadi Liakhovetski5a00a972013-02-15 16:13:56 +010044struct sh_mobile_sdhi_of_data {
45 unsigned long tmio_flags;
Kuninori Morimotob3a5d4c2014-02-20 16:54:58 -080046 unsigned long capabilities;
Kuninori Morimoto423f6c22014-02-20 16:55:27 -080047 unsigned long capabilities2;
Kuninori Morimotof45394d2015-01-13 05:00:07 +000048 enum dma_slave_buswidth dma_buswidth;
Kuninori Morimoto384b2cb2014-08-24 19:58:48 -070049 dma_addr_t dma_rx_offset;
Wolfram Sanga72e8b12016-02-15 16:01:48 +010050 unsigned bus_shift;
Guennadi Liakhovetski5a00a972013-02-15 16:13:56 +010051};
52
Wolfram Sang13bbd8a2016-04-26 17:55:22 +020053static const struct sh_mobile_sdhi_of_data of_default_cfg = {
54 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT,
Guennadi Liakhovetski5a00a972013-02-15 16:13:56 +010055};
56
Kuninori Morimotob3a5d4c2014-02-20 16:54:58 -080057static const struct sh_mobile_sdhi_of_data of_rcar_gen1_compatible = {
Shinobu Ueharada29fe22014-08-24 20:03:00 -070058 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT | TMIO_MMC_WRPROTECT_DISABLE |
59 TMIO_MMC_CLK_ACTUAL,
Kuninori Morimotob3a5d4c2014-02-20 16:54:58 -080060 .capabilities = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ,
61};
62
Kuninori Morimoto423f6c22014-02-20 16:55:27 -080063static const struct sh_mobile_sdhi_of_data of_rcar_gen2_compatible = {
Shinobu Ueharada29fe22014-08-24 20:03:00 -070064 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT | TMIO_MMC_WRPROTECT_DISABLE |
Wolfram Sang3d376fb2016-05-02 22:25:40 +020065 TMIO_MMC_CLK_ACTUAL | TMIO_MMC_MIN_RCAR2,
Kuninori Morimoto423f6c22014-02-20 16:55:27 -080066 .capabilities = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ,
Kuninori Morimotof45394d2015-01-13 05:00:07 +000067 .dma_buswidth = DMA_SLAVE_BUSWIDTH_4_BYTES,
Kuninori Morimoto384b2cb2014-08-24 19:58:48 -070068 .dma_rx_offset = 0x2000,
Kuninori Morimoto423f6c22014-02-20 16:55:27 -080069};
70
Wolfram Sanga72e8b12016-02-15 16:01:48 +010071static const struct sh_mobile_sdhi_of_data of_rcar_gen3_compatible = {
72 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT | TMIO_MMC_WRPROTECT_DISABLE |
Wolfram Sang3d376fb2016-05-02 22:25:40 +020073 TMIO_MMC_CLK_ACTUAL | TMIO_MMC_MIN_RCAR2,
Wolfram Sanga72e8b12016-02-15 16:01:48 +010074 .capabilities = MMC_CAP_SD_HIGHSPEED,
75 .bus_shift = 2,
76};
77
Kuninori Morimoto2772ef32014-02-20 16:54:44 -080078static const struct of_device_id sh_mobile_sdhi_of_match[] = {
79 { .compatible = "renesas,sdhi-shmobile" },
Wolfram Sang13bbd8a2016-04-26 17:55:22 +020080 { .compatible = "renesas,sdhi-sh73a0", .data = &of_default_cfg, },
81 { .compatible = "renesas,sdhi-r8a73a4", .data = &of_default_cfg, },
82 { .compatible = "renesas,sdhi-r8a7740", .data = &of_default_cfg, },
Kuninori Morimotob3a5d4c2014-02-20 16:54:58 -080083 { .compatible = "renesas,sdhi-r8a7778", .data = &of_rcar_gen1_compatible, },
Kuninori Morimoto81bbbc72014-02-20 16:55:12 -080084 { .compatible = "renesas,sdhi-r8a7779", .data = &of_rcar_gen1_compatible, },
Kuninori Morimoto423f6c22014-02-20 16:55:27 -080085 { .compatible = "renesas,sdhi-r8a7790", .data = &of_rcar_gen2_compatible, },
Kuninori Morimoto81918d22014-02-20 16:55:40 -080086 { .compatible = "renesas,sdhi-r8a7791", .data = &of_rcar_gen2_compatible, },
Geert Uytterhoevena6386402014-08-28 10:07:19 +020087 { .compatible = "renesas,sdhi-r8a7792", .data = &of_rcar_gen2_compatible, },
88 { .compatible = "renesas,sdhi-r8a7793", .data = &of_rcar_gen2_compatible, },
89 { .compatible = "renesas,sdhi-r8a7794", .data = &of_rcar_gen2_compatible, },
Wolfram Sanga72e8b12016-02-15 16:01:48 +010090 { .compatible = "renesas,sdhi-r8a7795", .data = &of_rcar_gen3_compatible, },
Kuninori Morimoto2772ef32014-02-20 16:54:44 -080091 {},
92};
93MODULE_DEVICE_TABLE(of, sh_mobile_sdhi_of_match);
94
Magnus Damma87d5632009-10-02 02:22:09 +000095struct sh_mobile_sdhi {
96 struct clk *clk;
97 struct tmio_mmc_data mmc_data;
Guennadi Liakhovetski056676d2010-05-19 18:34:16 +000098 struct tmio_mmc_dma dma_priv;
Wolfram Sang057a4592016-04-01 17:44:37 +020099 struct pinctrl *pinctrl;
100 struct pinctrl_state *pins_default, *pins_uhs;
Magnus Damma87d5632009-10-02 02:22:09 +0000101};
102
Kuninori Morimotof45394d2015-01-13 05:00:07 +0000103static void sh_mobile_sdhi_sdbuf_width(struct tmio_mmc_host *host, int width)
104{
105 u32 val;
106
107 /*
108 * see also
109 * sh_mobile_sdhi_of_data :: dma_buswidth
110 */
111 switch (sd_ctrl_read16(host, CTL_VERSION)) {
112 case 0x490C:
113 val = (width == 32) ? 0x0001 : 0x0000;
114 break;
115 case 0xCB0D:
116 val = (width == 32) ? 0x0000 : 0x0001;
117 break;
Wolfram Sanga72e8b12016-02-15 16:01:48 +0100118 case 0xCC10: /* Gen3, SD only */
119 case 0xCD10: /* Gen3, SD + MMC */
120 if (width == 64)
121 val = 0x0000;
122 else if (width == 32)
123 val = 0x0101;
124 else
125 val = 0x0001;
126 break;
Kuninori Morimotof45394d2015-01-13 05:00:07 +0000127 default:
128 /* nothing to do */
129 return;
130 }
131
132 sd_ctrl_write16(host, EXT_ACC, val);
133}
134
Ben Hutchings0ea28212016-04-01 17:44:31 +0200135static int sh_mobile_sdhi_clk_enable(struct tmio_mmc_host *host)
Guennadi Liakhovetski56c49282012-06-20 19:10:32 +0200136{
Ben Hutchings0ea28212016-04-01 17:44:31 +0200137 struct mmc_host *mmc = host->mmc;
Kuninori Morimoto16935252015-01-13 04:59:43 +0000138 struct sh_mobile_sdhi *priv = host_to_priv(host);
Laurent Pinchart00fb3d22013-10-28 23:49:25 +0100139 int ret = clk_prepare_enable(priv->clk);
Guennadi Liakhovetski56c49282012-06-20 19:10:32 +0200140 if (ret < 0)
141 return ret;
142
Ben Hutchings2fb55952016-04-01 17:44:32 +0200143 /*
144 * The clock driver may not know what maximum frequency
145 * actually works, so it should be set with the max-frequency
146 * property which will already have been read to f_max. If it
147 * was missing, assume the current frequency is the maximum.
148 */
149 if (!mmc->f_max)
150 mmc->f_max = clk_get_rate(priv->clk);
151
152 /*
153 * Minimum frequency is the minimum input clock frequency
154 * divided by our maximum divider.
155 */
156 mmc->f_min = max(clk_round_rate(priv->clk, 1) / 512, 1L);
Kuninori Morimotof45394d2015-01-13 05:00:07 +0000157
158 /* enable 16bit data access on SDBUF as default */
159 sh_mobile_sdhi_sdbuf_width(host, 16);
160
Guennadi Liakhovetski56c49282012-06-20 19:10:32 +0200161 return 0;
162}
163
Ben Hutchings2fb55952016-04-01 17:44:32 +0200164static unsigned int sh_mobile_sdhi_clk_update(struct tmio_mmc_host *host,
165 unsigned int new_clock)
166{
167 struct sh_mobile_sdhi *priv = host_to_priv(host);
Wolfram Sang3072ba82016-05-02 22:25:39 +0200168 unsigned int freq, diff, best_freq = 0, diff_min = ~0;
Ben Hutchings2fb55952016-04-01 17:44:32 +0200169 int i;
170
Ben Hutchings2fb55952016-04-01 17:44:32 +0200171 /*
172 * We want the bus clock to be as close as possible to, but no
173 * greater than, new_clock. As we can divide by 1 << i for
174 * any i in [0, 9] we want the input clock to be as close as
175 * possible, but no greater than, new_clock << i.
176 */
177 for (i = min(9, ilog2(UINT_MAX / new_clock)); i >= 0; i--) {
178 freq = clk_round_rate(priv->clk, new_clock << i);
179 if (freq > (new_clock << i)) {
180 /* Too fast; look for a slightly slower option */
181 freq = clk_round_rate(priv->clk,
182 (new_clock << i) / 4 * 3);
183 if (freq > (new_clock << i))
184 continue;
185 }
186
187 diff = new_clock - (freq >> i);
188 if (diff <= diff_min) {
189 best_freq = freq;
190 diff_min = diff;
191 }
192 }
193
194 clk_set_rate(priv->clk, best_freq);
195
196 return best_freq;
197}
198
Ben Hutchings0ea28212016-04-01 17:44:31 +0200199static void sh_mobile_sdhi_clk_disable(struct tmio_mmc_host *host)
Guennadi Liakhovetski56c49282012-06-20 19:10:32 +0200200{
Kuninori Morimoto16935252015-01-13 04:59:43 +0000201 struct sh_mobile_sdhi *priv = host_to_priv(host);
Ben Hutchings0ea28212016-04-01 17:44:31 +0200202
Laurent Pinchart00fb3d22013-10-28 23:49:25 +0100203 clk_disable_unprepare(priv->clk);
Guennadi Liakhovetski56c49282012-06-20 19:10:32 +0200204}
205
Wolfram Sang057a4592016-04-01 17:44:37 +0200206static int sh_mobile_sdhi_start_signal_voltage_switch(struct mmc_host *mmc,
207 struct mmc_ios *ios)
208{
209 struct tmio_mmc_host *host = mmc_priv(mmc);
210 struct sh_mobile_sdhi *priv = host_to_priv(host);
211 struct pinctrl_state *pin_state;
212 int ret;
213
214 switch (ios->signal_voltage) {
215 case MMC_SIGNAL_VOLTAGE_330:
216 pin_state = priv->pins_default;
217 break;
218 case MMC_SIGNAL_VOLTAGE_180:
219 pin_state = priv->pins_uhs;
220 break;
221 default:
222 return -EINVAL;
223 }
224
225 /*
226 * If anything is missing, assume signal voltage is fixed at
227 * 3.3V and succeed/fail accordingly.
228 */
229 if (IS_ERR(priv->pinctrl) || IS_ERR(pin_state))
230 return ios->signal_voltage ==
231 MMC_SIGNAL_VOLTAGE_330 ? 0 : -EINVAL;
232
233 ret = mmc_regulator_set_vqmmc(host->mmc, ios);
234 if (ret)
235 return ret;
236
Wolfram Sang2272c842016-04-26 17:55:27 +0200237 return pinctrl_select_state(priv->pinctrl, pin_state);
Wolfram Sang057a4592016-04-01 17:44:37 +0200238}
239
Simon Horman973ed3a2011-06-21 08:00:10 +0900240static int sh_mobile_sdhi_wait_idle(struct tmio_mmc_host *host)
241{
242 int timeout = 1000;
243
Wolfram Sanga21553c2016-04-27 18:51:26 +0200244 while (--timeout && !(sd_ctrl_read16_and_16_as_32(host, CTL_STATUS)
245 & TMIO_STAT_SCLKDIVEN))
Simon Horman973ed3a2011-06-21 08:00:10 +0900246 udelay(1);
247
248 if (!timeout) {
Kuninori Morimoto94b110a2015-01-13 04:57:22 +0000249 dev_warn(&host->pdev->dev, "timeout waiting for SD bus idle\n");
Simon Horman973ed3a2011-06-21 08:00:10 +0900250 return -EBUSY;
251 }
252
253 return 0;
254}
255
256static int sh_mobile_sdhi_write16_hook(struct tmio_mmc_host *host, int addr)
257{
258 switch (addr)
259 {
260 case CTL_SD_CMD:
261 case CTL_STOP_INTERNAL_ACTION:
262 case CTL_XFER_BLK_COUNT:
263 case CTL_SD_CARD_CLK_CTL:
264 case CTL_SD_XFER_LEN:
265 case CTL_SD_MEM_CARD_OPT:
266 case CTL_TRANSACTION_CTL:
267 case CTL_DMA_ENABLE:
Shinobu Ueharaff741cf2014-04-25 18:14:17 +0900268 case EXT_ACC:
Simon Horman973ed3a2011-06-21 08:00:10 +0900269 return sh_mobile_sdhi_wait_idle(host);
270 }
271
272 return 0;
273}
274
Kuninori Morimoto8b4efe22014-09-08 23:45:46 -0700275static int sh_mobile_sdhi_multi_io_quirk(struct mmc_card *card,
276 unsigned int direction, int blk_size)
277{
278 /*
279 * In Renesas controllers, when performing a
280 * multiple block read of one or two blocks,
281 * depending on the timing with which the
282 * response register is read, the response
283 * value may not be read properly.
284 * Use single block read for this HW bug
285 */
286 if ((direction == MMC_DATA_READ) &&
287 blk_size == 2)
288 return 1;
289
290 return blk_size;
291}
292
Kuninori Morimoto0c47f6a2015-01-13 04:59:56 +0000293static void sh_mobile_sdhi_enable_dma(struct tmio_mmc_host *host, bool enable)
294{
295 sd_ctrl_write16(host, CTL_DMA_ENABLE, enable ? 2 : 0);
Kuninori Morimotof45394d2015-01-13 05:00:07 +0000296
297 /* enable 32bit access if DMA mode if possibile */
298 sh_mobile_sdhi_sdbuf_width(host, enable ? 32 : 16);
Kuninori Morimoto0c47f6a2015-01-13 04:59:56 +0000299}
300
Bill Pembertonc3be1ef2012-11-19 13:23:06 -0500301static int sh_mobile_sdhi_probe(struct platform_device *pdev)
Magnus Damma87d5632009-10-02 02:22:09 +0000302{
Guennadi Liakhovetski5a00a972013-02-15 16:13:56 +0100303 const struct of_device_id *of_id =
304 of_match_device(sh_mobile_sdhi_of_match, &pdev->dev);
Magnus Damma87d5632009-10-02 02:22:09 +0000305 struct sh_mobile_sdhi *priv;
Guennadi Liakhovetski056676d2010-05-19 18:34:16 +0000306 struct tmio_mmc_data *mmc_data;
Kuninori Morimotof33c9d62015-02-24 02:06:43 +0000307 struct tmio_mmc_data *mmd = pdev->dev.platform_data;
Guennadi Liakhovetski42051e82011-03-14 09:52:33 +0100308 struct tmio_mmc_host *host;
Kuninori Morimoto3b159a62013-11-20 00:30:55 -0800309 struct resource *res;
Simon Hormand5098cb2011-08-26 10:42:39 +0200310 int irq, ret, i = 0;
Guennadi Liakhovetski87ae7bb2013-04-26 17:47:19 +0200311 struct tmio_mmc_dma *dma_priv;
Magnus Damma87d5632009-10-02 02:22:09 +0000312
Kuninori Morimoto3b159a62013-11-20 00:30:55 -0800313 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
314 if (!res)
315 return -EINVAL;
316
Guennadi Liakhovetskiac51b962013-02-15 16:13:58 +0100317 priv = devm_kzalloc(&pdev->dev, sizeof(struct sh_mobile_sdhi), GFP_KERNEL);
Wolfram Sang2bf8ab62016-01-19 11:42:22 +0100318 if (!priv)
Magnus Damma87d5632009-10-02 02:22:09 +0000319 return -ENOMEM;
Magnus Damma87d5632009-10-02 02:22:09 +0000320
Guennadi Liakhovetski056676d2010-05-19 18:34:16 +0000321 mmc_data = &priv->mmc_data;
Guennadi Liakhovetski87ae7bb2013-04-26 17:47:19 +0200322 dma_priv = &priv->dma_priv;
Guennadi Liakhovetski056676d2010-05-19 18:34:16 +0000323
Guennadi Liakhovetskiac51b962013-02-15 16:13:58 +0100324 priv->clk = devm_clk_get(&pdev->dev, NULL);
Magnus Damma87d5632009-10-02 02:22:09 +0000325 if (IS_ERR(priv->clk)) {
Magnus Damma87d5632009-10-02 02:22:09 +0000326 ret = PTR_ERR(priv->clk);
Guennadi Liakhovetski56ae1ad2012-11-28 10:24:21 +0100327 dev_err(&pdev->dev, "cannot get clock: %d\n", ret);
Kuninori Morimoto010f4aa2015-01-13 04:59:24 +0000328 goto eprobe;
Magnus Damma87d5632009-10-02 02:22:09 +0000329 }
330
Wolfram Sang057a4592016-04-01 17:44:37 +0200331 priv->pinctrl = devm_pinctrl_get(&pdev->dev);
332 if (!IS_ERR(priv->pinctrl)) {
333 priv->pins_default = pinctrl_lookup_state(priv->pinctrl,
334 PINCTRL_STATE_DEFAULT);
335 priv->pins_uhs = pinctrl_lookup_state(priv->pinctrl,
336 "state_uhs");
337 }
338
Kuninori Morimoto94b110a2015-01-13 04:57:22 +0000339 host = tmio_mmc_host_alloc(pdev);
340 if (!host) {
341 ret = -ENOMEM;
342 goto eprobe;
343 }
344
Wolfram Sanga72e8b12016-02-15 16:01:48 +0100345 if (of_id && of_id->data) {
346 const struct sh_mobile_sdhi_of_data *of_data = of_id->data;
347
348 mmc_data->flags |= of_data->tmio_flags;
349 mmc_data->capabilities |= of_data->capabilities;
350 mmc_data->capabilities2 |= of_data->capabilities2;
351 mmc_data->dma_rx_offset = of_data->dma_rx_offset;
352 dma_priv->dma_buswidth = of_data->dma_buswidth;
353 host->bus_shift = of_data->bus_shift;
354 }
355
Kuninori Morimoto7ecc09b2015-01-13 04:57:33 +0000356 host->dma = dma_priv;
Kuninori Morimotodfe9a222015-01-13 04:57:42 +0000357 host->write16_hook = sh_mobile_sdhi_write16_hook;
Kuninori Morimoto4fe2ec52015-01-13 04:57:52 +0000358 host->clk_enable = sh_mobile_sdhi_clk_enable;
Ben Hutchings2fb55952016-04-01 17:44:32 +0200359 host->clk_update = sh_mobile_sdhi_clk_update;
Kuninori Morimoto00452c12015-01-13 04:58:01 +0000360 host->clk_disable = sh_mobile_sdhi_clk_disable;
Kuninori Morimoto85c02dd2015-01-13 04:58:10 +0000361 host->multi_io_quirk = sh_mobile_sdhi_multi_io_quirk;
Wolfram Sang057a4592016-04-01 17:44:37 +0200362 host->start_signal_voltage_switch = sh_mobile_sdhi_start_signal_voltage_switch;
Wolfram Sanga72e8b12016-02-15 16:01:48 +0100363
364 /* Orginally registers were 16 bit apart, could be 32 or 64 nowadays */
365 if (!host->bus_shift && resource_size(res) > 0x100) /* old way to determine the shift */
Kuninori Morimoto95a7dc32015-01-13 04:59:33 +0000366 host->bus_shift = 1;
Kuninori Morimoto7ecc09b2015-01-13 04:57:33 +0000367
Kuninori Morimoto84f11d52015-02-24 02:07:07 +0000368 if (mmd)
Kuninori Morimotof33c9d62015-02-24 02:06:43 +0000369 *mmc_data = *mmd;
Kuninori Morimoto84f11d52015-02-24 02:07:07 +0000370
Guennadi Liakhovetski87ae7bb2013-04-26 17:47:19 +0200371 dma_priv->filter = shdma_chan_filter;
Kuninori Morimoto0c47f6a2015-01-13 04:59:56 +0000372 dma_priv->enable = sh_mobile_sdhi_enable_dma;
Guennadi Liakhovetski87ae7bb2013-04-26 17:47:19 +0200373
Kuninori Morimotoe471df02015-01-13 04:58:46 +0000374 mmc_data->alignment_shift = 1; /* 2-byte alignment */
Kuninori Morimotof33c9d62015-02-24 02:06:43 +0000375 mmc_data->capabilities |= MMC_CAP_MMC_HIGHSPEED;
Kuninori Morimotoe471df02015-01-13 04:58:46 +0000376
Yusuke Godaf1334fb2010-08-30 11:50:19 +0100377 /*
378 * All SDHI blocks support 2-byte and larger block sizes in 4-bit
379 * bus width mode.
380 */
381 mmc_data->flags |= TMIO_MMC_BLKSZ_2BYTES;
382
Arnd Hannemann23b66072010-12-28 23:22:32 +0100383 /*
384 * All SDHI blocks support SDIO IRQ signalling.
385 */
386 mmc_data->flags |= TMIO_MMC_SDIO_IRQ;
387
Shinobu Ueharab8d11962014-08-24 20:00:25 -0700388 /*
389 * All SDHI have CMD12 controll bit
390 */
391 mmc_data->flags |= TMIO_MMC_HAVE_CMD12_CTRL;
392
Shinobu Uehara6b987572014-08-24 20:00:52 -0700393 /*
394 * All SDHI need SDIO_INFO1 reserved bit
395 */
396 mmc_data->flags |= TMIO_MMC_SDIO_STATUS_QUIRK;
397
Kuninori Morimoto94b110a2015-01-13 04:57:22 +0000398 ret = tmio_mmc_host_probe(host, mmc_data);
Guennadi Liakhovetski42051e82011-03-14 09:52:33 +0100399 if (ret < 0)
Kuninori Morimoto94b110a2015-01-13 04:57:22 +0000400 goto efree;
Magnus Damma87d5632009-10-02 02:22:09 +0000401
Wolfram Sangadcbc942016-04-26 17:55:23 +0200402 while (1) {
403 irq = platform_get_irq(pdev, i);
404 if (irq < 0)
405 break;
406 i++;
407 ret = devm_request_irq(&pdev->dev, irq, tmio_mmc_irq, 0,
Magnus Dammd6a1f862011-05-06 11:02:45 +0000408 dev_name(&pdev->dev), host);
Simon Hormand5098cb2011-08-26 10:42:39 +0200409 if (ret)
Guennadi Liakhovetskiac51b962013-02-15 16:13:58 +0100410 goto eirq;
Magnus Damm8e7bfdb2011-05-06 11:02:33 +0000411 }
Simon Hormand5098cb2011-08-26 10:42:39 +0200412
Wolfram Sangadcbc942016-04-26 17:55:23 +0200413 /* There must be at least one IRQ source */
414 if (!i) {
Simon Hormand5098cb2011-08-26 10:42:39 +0200415 ret = irq;
Guennadi Liakhovetskiac51b962013-02-15 16:13:58 +0100416 goto eirq;
Simon Hormand5098cb2011-08-26 10:42:39 +0200417 }
418
Ben Hutchings2fb55952016-04-01 17:44:32 +0200419 dev_info(&pdev->dev, "%s base at 0x%08lx max clock rate %u MHz\n",
Magnus Damm1f7d6812011-05-06 11:02:41 +0000420 mmc_hostname(host->mmc), (unsigned long)
Guennadi Liakhovetski58126c82012-02-09 22:57:10 +0100421 (platform_get_resource(pdev, IORESOURCE_MEM, 0)->start),
Guennadi Liakhovetski369213b2012-11-28 10:24:13 +0100422 host->mmc->f_max / 1000000);
Magnus Damma87d5632009-10-02 02:22:09 +0000423
Guennadi Liakhovetski42051e82011-03-14 09:52:33 +0100424 return ret;
Magnus Damma87d5632009-10-02 02:22:09 +0000425
Guennadi Liakhovetskiac51b962013-02-15 16:13:58 +0100426eirq:
Magnus Damm8e7bfdb2011-05-06 11:02:33 +0000427 tmio_mmc_host_remove(host);
Kuninori Morimoto94b110a2015-01-13 04:57:22 +0000428efree:
429 tmio_mmc_host_free(host);
Guennadi Liakhovetski42051e82011-03-14 09:52:33 +0100430eprobe:
Magnus Damma87d5632009-10-02 02:22:09 +0000431 return ret;
432}
433
434static int sh_mobile_sdhi_remove(struct platform_device *pdev)
435{
Guennadi Liakhovetski42051e82011-03-14 09:52:33 +0100436 struct mmc_host *mmc = platform_get_drvdata(pdev);
437 struct tmio_mmc_host *host = mmc_priv(mmc);
Magnus Damma87d5632009-10-02 02:22:09 +0000438
Guennadi Liakhovetski742a0c72011-05-27 16:54:05 +0200439 tmio_mmc_host_remove(host);
440
Magnus Damma87d5632009-10-02 02:22:09 +0000441 return 0;
442}
443
Guennadi Liakhovetskie6ee7182011-05-05 16:13:12 +0000444static const struct dev_pm_ops tmio_mmc_dev_pm_ops = {
Ulf Hansson753a6882014-08-25 12:18:26 +0200445 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
446 pm_runtime_force_resume)
Rafael J. Wysocki6ed23b82014-12-04 00:34:11 +0100447 SET_RUNTIME_PM_OPS(tmio_mmc_host_runtime_suspend,
Ulf Hansson4e262d72013-10-23 14:51:31 +0200448 tmio_mmc_host_runtime_resume,
449 NULL)
Guennadi Liakhovetskie6ee7182011-05-05 16:13:12 +0000450};
451
Magnus Damma87d5632009-10-02 02:22:09 +0000452static struct platform_driver sh_mobile_sdhi_driver = {
453 .driver = {
454 .name = "sh_mobile_sdhi",
Guennadi Liakhovetskie6ee7182011-05-05 16:13:12 +0000455 .pm = &tmio_mmc_dev_pm_ops,
Guennadi Liakhovetskic7bb4482012-05-01 18:03:43 +0200456 .of_match_table = sh_mobile_sdhi_of_match,
Magnus Damma87d5632009-10-02 02:22:09 +0000457 },
458 .probe = sh_mobile_sdhi_probe,
Bill Pemberton0433c142012-11-19 13:20:26 -0500459 .remove = sh_mobile_sdhi_remove,
Magnus Damma87d5632009-10-02 02:22:09 +0000460};
461
Axel Lind1f81a62011-11-26 12:55:43 +0800462module_platform_driver(sh_mobile_sdhi_driver);
Magnus Damma87d5632009-10-02 02:22:09 +0000463
464MODULE_DESCRIPTION("SuperH Mobile SDHI driver");
465MODULE_AUTHOR("Magnus Damm");
466MODULE_LICENSE("GPL v2");
Guennadi Liakhovetski42051e82011-03-14 09:52:33 +0100467MODULE_ALIAS("platform:sh_mobile_sdhi");