blob: 782d8cf942a7da4fbb5b1dd03dd69146bd3d0ca1 [file] [log] [blame]
Magnus Damma87d5632009-10-02 02:22:09 +00001/*
2 * SuperH Mobile SDHI
3 *
4 * Copyright (C) 2009 Magnus Damm
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * Based on "Compaq ASIC3 support":
11 *
12 * Copyright 2001 Compaq Computer Corporation.
13 * Copyright 2004-2005 Phil Blundell
14 * Copyright 2007-2008 OpenedHand Ltd.
15 *
16 * Authors: Phil Blundell <pb@handhelds.org>,
17 * Samuel Ortiz <sameo@openedhand.com>
18 *
19 */
20
21#include <linux/kernel.h>
22#include <linux/clk.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090023#include <linux/slab.h>
Guennadi Liakhovetskic7bb4482012-05-01 18:03:43 +020024#include <linux/mod_devicetable.h>
Paul Gortmaker88b47672011-07-03 15:15:51 -040025#include <linux/module.h>
Guennadi Liakhovetski5a00a972013-02-15 16:13:56 +010026#include <linux/of_device.h>
Magnus Damma87d5632009-10-02 02:22:09 +000027#include <linux/platform_device.h>
Magnus Damm3c49e812010-02-22 13:37:09 +090028#include <linux/mmc/host.h>
Guennadi Liakhovetski42051e82011-03-14 09:52:33 +010029#include <linux/mmc/sh_mobile_sdhi.h>
Magnus Damma87d5632009-10-02 02:22:09 +000030#include <linux/mfd/tmio.h>
Guennadi Liakhovetski056676d2010-05-19 18:34:16 +000031#include <linux/sh_dma.h>
Simon Horman973ed3a2011-06-21 08:00:10 +090032#include <linux/delay.h>
Magnus Damma87d5632009-10-02 02:22:09 +000033
Guennadi Liakhovetski42051e82011-03-14 09:52:33 +010034#include "tmio_mmc.h"
35
Kuninori Morimotoe3c418f2013-11-20 00:31:13 -080036#define EXT_ACC 0xe4
37
Guennadi Liakhovetski5a00a972013-02-15 16:13:56 +010038struct sh_mobile_sdhi_of_data {
39 unsigned long tmio_flags;
Kuninori Morimotob3a5d4c2014-02-20 16:54:58 -080040 unsigned long capabilities;
Kuninori Morimoto423f6c22014-02-20 16:55:27 -080041 unsigned long capabilities2;
Kuninori Morimoto384b2cb2014-08-24 19:58:48 -070042 dma_addr_t dma_rx_offset;
Guennadi Liakhovetski5a00a972013-02-15 16:13:56 +010043};
44
45static const struct sh_mobile_sdhi_of_data sh_mobile_sdhi_of_cfg[] = {
46 {
47 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT,
48 },
49};
50
Kuninori Morimotob3a5d4c2014-02-20 16:54:58 -080051static const struct sh_mobile_sdhi_of_data of_rcar_gen1_compatible = {
Shinobu Ueharada29fe22014-08-24 20:03:00 -070052 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT | TMIO_MMC_WRPROTECT_DISABLE |
53 TMIO_MMC_CLK_ACTUAL,
Kuninori Morimotob3a5d4c2014-02-20 16:54:58 -080054 .capabilities = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ,
55};
56
Kuninori Morimoto423f6c22014-02-20 16:55:27 -080057static const struct sh_mobile_sdhi_of_data of_rcar_gen2_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 Morimoto423f6c22014-02-20 16:55:27 -080060 .capabilities = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ,
Kuninori Morimoto384b2cb2014-08-24 19:58:48 -070061 .dma_rx_offset = 0x2000,
Kuninori Morimoto423f6c22014-02-20 16:55:27 -080062};
63
Kuninori Morimoto2772ef32014-02-20 16:54:44 -080064static const struct of_device_id sh_mobile_sdhi_of_match[] = {
65 { .compatible = "renesas,sdhi-shmobile" },
66 { .compatible = "renesas,sdhi-sh7372" },
67 { .compatible = "renesas,sdhi-sh73a0", .data = &sh_mobile_sdhi_of_cfg[0], },
68 { .compatible = "renesas,sdhi-r8a73a4", .data = &sh_mobile_sdhi_of_cfg[0], },
69 { .compatible = "renesas,sdhi-r8a7740", .data = &sh_mobile_sdhi_of_cfg[0], },
Kuninori Morimotob3a5d4c2014-02-20 16:54:58 -080070 { .compatible = "renesas,sdhi-r8a7778", .data = &of_rcar_gen1_compatible, },
Kuninori Morimoto81bbbc72014-02-20 16:55:12 -080071 { .compatible = "renesas,sdhi-r8a7779", .data = &of_rcar_gen1_compatible, },
Kuninori Morimoto423f6c22014-02-20 16:55:27 -080072 { .compatible = "renesas,sdhi-r8a7790", .data = &of_rcar_gen2_compatible, },
Kuninori Morimoto81918d22014-02-20 16:55:40 -080073 { .compatible = "renesas,sdhi-r8a7791", .data = &of_rcar_gen2_compatible, },
Geert Uytterhoevena6386402014-08-28 10:07:19 +020074 { .compatible = "renesas,sdhi-r8a7792", .data = &of_rcar_gen2_compatible, },
75 { .compatible = "renesas,sdhi-r8a7793", .data = &of_rcar_gen2_compatible, },
76 { .compatible = "renesas,sdhi-r8a7794", .data = &of_rcar_gen2_compatible, },
Kuninori Morimoto2772ef32014-02-20 16:54:44 -080077 {},
78};
79MODULE_DEVICE_TABLE(of, sh_mobile_sdhi_of_match);
80
Magnus Damma87d5632009-10-02 02:22:09 +000081struct sh_mobile_sdhi {
82 struct clk *clk;
83 struct tmio_mmc_data mmc_data;
Guennadi Liakhovetski056676d2010-05-19 18:34:16 +000084 struct tmio_mmc_dma dma_priv;
Magnus Damma87d5632009-10-02 02:22:09 +000085};
86
Guennadi Liakhovetski56c49282012-06-20 19:10:32 +020087static int sh_mobile_sdhi_clk_enable(struct platform_device *pdev, unsigned int *f)
88{
Jingoo Han6e2c0f32013-06-03 13:41:03 +090089 struct mmc_host *mmc = platform_get_drvdata(pdev);
Guennadi Liakhovetski56c49282012-06-20 19:10:32 +020090 struct tmio_mmc_host *host = mmc_priv(mmc);
91 struct sh_mobile_sdhi *priv = container_of(host->pdata, struct sh_mobile_sdhi, mmc_data);
Laurent Pinchart00fb3d22013-10-28 23:49:25 +010092 int ret = clk_prepare_enable(priv->clk);
Guennadi Liakhovetski56c49282012-06-20 19:10:32 +020093 if (ret < 0)
94 return ret;
95
96 *f = clk_get_rate(priv->clk);
97 return 0;
98}
99
100static void sh_mobile_sdhi_clk_disable(struct platform_device *pdev)
101{
Jingoo Han6e2c0f32013-06-03 13:41:03 +0900102 struct mmc_host *mmc = platform_get_drvdata(pdev);
Guennadi Liakhovetski56c49282012-06-20 19:10:32 +0200103 struct tmio_mmc_host *host = mmc_priv(mmc);
104 struct sh_mobile_sdhi *priv = container_of(host->pdata, struct sh_mobile_sdhi, mmc_data);
Laurent Pinchart00fb3d22013-10-28 23:49:25 +0100105 clk_disable_unprepare(priv->clk);
Guennadi Liakhovetski56c49282012-06-20 19:10:32 +0200106}
107
Simon Horman973ed3a2011-06-21 08:00:10 +0900108static int sh_mobile_sdhi_wait_idle(struct tmio_mmc_host *host)
109{
110 int timeout = 1000;
111
112 while (--timeout && !(sd_ctrl_read16(host, CTL_STATUS2) & (1 << 13)))
113 udelay(1);
114
115 if (!timeout) {
Kuninori Morimoto94b110a2015-01-13 04:57:22 +0000116 dev_warn(&host->pdev->dev, "timeout waiting for SD bus idle\n");
Simon Horman973ed3a2011-06-21 08:00:10 +0900117 return -EBUSY;
118 }
119
120 return 0;
121}
122
123static int sh_mobile_sdhi_write16_hook(struct tmio_mmc_host *host, int addr)
124{
125 switch (addr)
126 {
127 case CTL_SD_CMD:
128 case CTL_STOP_INTERNAL_ACTION:
129 case CTL_XFER_BLK_COUNT:
130 case CTL_SD_CARD_CLK_CTL:
131 case CTL_SD_XFER_LEN:
132 case CTL_SD_MEM_CARD_OPT:
133 case CTL_TRANSACTION_CTL:
134 case CTL_DMA_ENABLE:
135 return sh_mobile_sdhi_wait_idle(host);
136 }
137
138 return 0;
139}
140
Kuninori Morimoto8b4efe22014-09-08 23:45:46 -0700141static int sh_mobile_sdhi_multi_io_quirk(struct mmc_card *card,
142 unsigned int direction, int blk_size)
143{
144 /*
145 * In Renesas controllers, when performing a
146 * multiple block read of one or two blocks,
147 * depending on the timing with which the
148 * response register is read, the response
149 * value may not be read properly.
150 * Use single block read for this HW bug
151 */
152 if ((direction == MMC_DATA_READ) &&
153 blk_size == 2)
154 return 1;
155
156 return blk_size;
157}
158
Guennadi Liakhovetski7f524212012-03-09 10:16:00 +0100159static void sh_mobile_sdhi_cd_wakeup(const struct platform_device *pdev)
160{
Jingoo Han6e2c0f32013-06-03 13:41:03 +0900161 mmc_detect_change(platform_get_drvdata(pdev), msecs_to_jiffies(100));
Guennadi Liakhovetski7f524212012-03-09 10:16:00 +0100162}
163
164static const struct sh_mobile_sdhi_ops sdhi_ops = {
165 .cd_wakeup = sh_mobile_sdhi_cd_wakeup,
166};
167
Bill Pembertonc3be1ef2012-11-19 13:23:06 -0500168static int sh_mobile_sdhi_probe(struct platform_device *pdev)
Magnus Damma87d5632009-10-02 02:22:09 +0000169{
Guennadi Liakhovetski5a00a972013-02-15 16:13:56 +0100170 const struct of_device_id *of_id =
171 of_match_device(sh_mobile_sdhi_of_match, &pdev->dev);
Magnus Damma87d5632009-10-02 02:22:09 +0000172 struct sh_mobile_sdhi *priv;
Guennadi Liakhovetski056676d2010-05-19 18:34:16 +0000173 struct tmio_mmc_data *mmc_data;
174 struct sh_mobile_sdhi_info *p = pdev->dev.platform_data;
Guennadi Liakhovetski42051e82011-03-14 09:52:33 +0100175 struct tmio_mmc_host *host;
Kuninori Morimoto3b159a62013-11-20 00:30:55 -0800176 struct resource *res;
Simon Hormand5098cb2011-08-26 10:42:39 +0200177 int irq, ret, i = 0;
178 bool multiplexed_isr = true;
Guennadi Liakhovetski87ae7bb2013-04-26 17:47:19 +0200179 struct tmio_mmc_dma *dma_priv;
Kuninori Morimotoe3c418f2013-11-20 00:31:13 -0800180 u16 ver;
Magnus Damma87d5632009-10-02 02:22:09 +0000181
Kuninori Morimoto3b159a62013-11-20 00:30:55 -0800182 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
183 if (!res)
184 return -EINVAL;
185
Guennadi Liakhovetskiac51b962013-02-15 16:13:58 +0100186 priv = devm_kzalloc(&pdev->dev, sizeof(struct sh_mobile_sdhi), GFP_KERNEL);
Magnus Damma87d5632009-10-02 02:22:09 +0000187 if (priv == NULL) {
188 dev_err(&pdev->dev, "kzalloc failed\n");
189 return -ENOMEM;
190 }
191
Guennadi Liakhovetski056676d2010-05-19 18:34:16 +0000192 mmc_data = &priv->mmc_data;
Guennadi Liakhovetski87ae7bb2013-04-26 17:47:19 +0200193 dma_priv = &priv->dma_priv;
Guennadi Liakhovetski056676d2010-05-19 18:34:16 +0000194
Guennadi Liakhovetskic7bb4482012-05-01 18:03:43 +0200195 if (p) {
Guennadi Liakhovetskic7bb4482012-05-01 18:03:43 +0200196 if (p->init) {
197 ret = p->init(pdev, &sdhi_ops);
198 if (ret)
Guennadi Liakhovetskiac51b962013-02-15 16:13:58 +0100199 return ret;
Guennadi Liakhovetskic7bb4482012-05-01 18:03:43 +0200200 }
Bastian Hechte82b4ac2012-03-16 12:19:29 -0400201 }
202
Guennadi Liakhovetskiac51b962013-02-15 16:13:58 +0100203 priv->clk = devm_clk_get(&pdev->dev, NULL);
Magnus Damma87d5632009-10-02 02:22:09 +0000204 if (IS_ERR(priv->clk)) {
Magnus Damma87d5632009-10-02 02:22:09 +0000205 ret = PTR_ERR(priv->clk);
Guennadi Liakhovetski56ae1ad2012-11-28 10:24:21 +0100206 dev_err(&pdev->dev, "cannot get clock: %d\n", ret);
Guennadi Liakhovetski42051e82011-03-14 09:52:33 +0100207 goto eclkget;
Magnus Damma87d5632009-10-02 02:22:09 +0000208 }
209
Kuninori Morimoto94b110a2015-01-13 04:57:22 +0000210 host = tmio_mmc_host_alloc(pdev);
211 if (!host) {
212 ret = -ENOMEM;
213 goto eprobe;
214 }
215
Kuninori Morimoto7ecc09b2015-01-13 04:57:33 +0000216 host->dma = dma_priv;
Kuninori Morimotodfe9a222015-01-13 04:57:42 +0000217 host->write16_hook = sh_mobile_sdhi_write16_hook;
Kuninori Morimoto4fe2ec52015-01-13 04:57:52 +0000218 host->clk_enable = sh_mobile_sdhi_clk_enable;
Kuninori Morimoto00452c12015-01-13 04:58:01 +0000219 host->clk_disable = sh_mobile_sdhi_clk_disable;
Kuninori Morimoto85c02dd2015-01-13 04:58:10 +0000220 host->multi_io_quirk = sh_mobile_sdhi_multi_io_quirk;
Kuninori Morimoto7445bf92015-01-13 04:58:20 +0000221 /* SD control register space size is 0x100, 0x200 for bus_shift=1 */
222 host->bus_shift = resource_size(res) >> 9;
Kuninori Morimoto7ecc09b2015-01-13 04:57:33 +0000223
Guennadi Liakhovetski056676d2010-05-19 18:34:16 +0000224 mmc_data->capabilities = MMC_CAP_MMC_HIGHSPEED;
Guennadi Liakhovetskibb0fe532010-05-19 18:37:36 +0000225 if (p) {
Guennadi Liakhovetskif87c20a2010-05-19 18:36:08 +0000226 mmc_data->flags = p->tmio_flags;
Guennadi Liakhovetskibb0fe532010-05-19 18:37:36 +0000227 mmc_data->ocr_mask = p->tmio_ocr_mask;
Arnd Hannemann998283e2010-08-24 17:27:00 +0200228 mmc_data->capabilities |= p->tmio_caps;
Guennadi Liakhovetskid7d8d502012-05-23 11:05:33 +0200229 mmc_data->capabilities2 |= p->tmio_caps2;
Guennadi Liakhovetski58126c82012-02-09 22:57:10 +0100230 mmc_data->cd_gpio = p->cd_gpio;
Guennadi Liakhovetski42051e82011-03-14 09:52:33 +0100231
Guennadi Liakhovetski3e713372011-05-24 12:24:07 +0200232 if (p->dma_slave_tx > 0 && p->dma_slave_rx > 0) {
Guennadi Liakhovetskieec95ee2013-04-26 17:47:18 +0200233 /*
234 * Yes, we have to provide slave IDs twice to TMIO:
235 * once as a filter parameter and once for channel
236 * configuration as an explicit slave ID
237 */
238 dma_priv->chan_priv_tx = (void *)p->dma_slave_tx;
239 dma_priv->chan_priv_rx = (void *)p->dma_slave_rx;
240 dma_priv->slave_id_tx = p->dma_slave_tx;
241 dma_priv->slave_id_rx = p->dma_slave_rx;
Guennadi Liakhovetski42051e82011-03-14 09:52:33 +0100242 }
Guennadi Liakhovetskibb0fe532010-05-19 18:37:36 +0000243 }
Guennadi Liakhovetski87ae7bb2013-04-26 17:47:19 +0200244 dma_priv->filter = shdma_chan_filter;
245
Kuninori Morimotoe471df02015-01-13 04:58:46 +0000246 mmc_data->alignment_shift = 1; /* 2-byte alignment */
247
Yusuke Godaf1334fb2010-08-30 11:50:19 +0100248 /*
249 * All SDHI blocks support 2-byte and larger block sizes in 4-bit
250 * bus width mode.
251 */
252 mmc_data->flags |= TMIO_MMC_BLKSZ_2BYTES;
253
Arnd Hannemann23b66072010-12-28 23:22:32 +0100254 /*
255 * All SDHI blocks support SDIO IRQ signalling.
256 */
257 mmc_data->flags |= TMIO_MMC_SDIO_IRQ;
258
Shinobu Ueharab8d11962014-08-24 20:00:25 -0700259 /*
260 * All SDHI have CMD12 controll bit
261 */
262 mmc_data->flags |= TMIO_MMC_HAVE_CMD12_CTRL;
263
Shinobu Uehara6b987572014-08-24 20:00:52 -0700264 /*
265 * All SDHI need SDIO_INFO1 reserved bit
266 */
267 mmc_data->flags |= TMIO_MMC_SDIO_STATUS_QUIRK;
268
Kuninori Morimotoe85dd042014-08-24 20:01:54 -0700269 /*
270 * All SDHI have DMA control register
271 */
272 mmc_data->flags |= TMIO_MMC_HAVE_CTL_DMA_REG;
273
Guennadi Liakhovetski5a00a972013-02-15 16:13:56 +0100274 if (of_id && of_id->data) {
275 const struct sh_mobile_sdhi_of_data *of_data = of_id->data;
276 mmc_data->flags |= of_data->tmio_flags;
Kuninori Morimotob3a5d4c2014-02-20 16:54:58 -0800277 mmc_data->capabilities |= of_data->capabilities;
Kuninori Morimoto423f6c22014-02-20 16:55:27 -0800278 mmc_data->capabilities2 |= of_data->capabilities2;
Kuninori Morimoto384b2cb2014-08-24 19:58:48 -0700279 dma_priv->dma_rx_offset = of_data->dma_rx_offset;
Guennadi Liakhovetski5a00a972013-02-15 16:13:56 +0100280 }
281
Kuninori Morimoto94b110a2015-01-13 04:57:22 +0000282 ret = tmio_mmc_host_probe(host, mmc_data);
Guennadi Liakhovetski42051e82011-03-14 09:52:33 +0100283 if (ret < 0)
Kuninori Morimoto94b110a2015-01-13 04:57:22 +0000284 goto efree;
Magnus Damma87d5632009-10-02 02:22:09 +0000285
Simon Hormand5098cb2011-08-26 10:42:39 +0200286 /*
Kuninori Morimotoe3c418f2013-11-20 00:31:13 -0800287 * FIXME:
288 * this Workaround can be more clever method
289 */
290 ver = sd_ctrl_read16(host, CTL_VERSION);
291 if (ver == 0xCB0D)
292 sd_ctrl_write16(host, EXT_ACC, 1);
293
294 /*
Simon Hormand5098cb2011-08-26 10:42:39 +0200295 * Allow one or more specific (named) ISRs or
296 * one or more multiplexed (un-named) ISRs.
297 */
298
299 irq = platform_get_irq_byname(pdev, SH_MOBILE_SDHI_IRQ_CARD_DETECT);
300 if (irq >= 0) {
301 multiplexed_isr = false;
Guennadi Liakhovetskiac51b962013-02-15 16:13:58 +0100302 ret = devm_request_irq(&pdev->dev, irq, tmio_mmc_card_detect_irq, 0,
Magnus Dammd6a1f862011-05-06 11:02:45 +0000303 dev_name(&pdev->dev), host);
Simon Hormand5098cb2011-08-26 10:42:39 +0200304 if (ret)
Guennadi Liakhovetskiac51b962013-02-15 16:13:58 +0100305 goto eirq;
Magnus Damm8e7bfdb2011-05-06 11:02:33 +0000306 }
Simon Hormand5098cb2011-08-26 10:42:39 +0200307
308 irq = platform_get_irq_byname(pdev, SH_MOBILE_SDHI_IRQ_SDIO);
309 if (irq >= 0) {
310 multiplexed_isr = false;
Guennadi Liakhovetskiac51b962013-02-15 16:13:58 +0100311 ret = devm_request_irq(&pdev->dev, irq, tmio_mmc_sdio_irq, 0,
Simon Hormand5098cb2011-08-26 10:42:39 +0200312 dev_name(&pdev->dev), host);
313 if (ret)
Guennadi Liakhovetskiac51b962013-02-15 16:13:58 +0100314 goto eirq;
Simon Hormand5098cb2011-08-26 10:42:39 +0200315 }
316
317 irq = platform_get_irq_byname(pdev, SH_MOBILE_SDHI_IRQ_SDCARD);
318 if (irq >= 0) {
319 multiplexed_isr = false;
Guennadi Liakhovetskiac51b962013-02-15 16:13:58 +0100320 ret = devm_request_irq(&pdev->dev, irq, tmio_mmc_sdcard_irq, 0,
Simon Hormand5098cb2011-08-26 10:42:39 +0200321 dev_name(&pdev->dev), host);
322 if (ret)
Guennadi Liakhovetskiac51b962013-02-15 16:13:58 +0100323 goto eirq;
Simon Hormand5098cb2011-08-26 10:42:39 +0200324 } else if (!multiplexed_isr) {
325 dev_err(&pdev->dev,
326 "Principal SD-card IRQ is missing among named interrupts\n");
327 ret = irq;
Guennadi Liakhovetskiac51b962013-02-15 16:13:58 +0100328 goto eirq;
Simon Hormand5098cb2011-08-26 10:42:39 +0200329 }
330
331 if (multiplexed_isr) {
332 while (1) {
333 irq = platform_get_irq(pdev, i);
334 if (irq < 0)
335 break;
336 i++;
Guennadi Liakhovetskiac51b962013-02-15 16:13:58 +0100337 ret = devm_request_irq(&pdev->dev, irq, tmio_mmc_irq, 0,
Simon Hormand5098cb2011-08-26 10:42:39 +0200338 dev_name(&pdev->dev), host);
339 if (ret)
Guennadi Liakhovetskiac51b962013-02-15 16:13:58 +0100340 goto eirq;
Simon Hormand5098cb2011-08-26 10:42:39 +0200341 }
342
343 /* There must be at least one IRQ source */
Wei Yongjun7913ae72013-05-28 13:26:50 +0800344 if (!i) {
345 ret = irq;
Guennadi Liakhovetskiac51b962013-02-15 16:13:58 +0100346 goto eirq;
Wei Yongjun7913ae72013-05-28 13:26:50 +0800347 }
Simon Hormand5098cb2011-08-26 10:42:39 +0200348 }
349
Magnus Damm1f7d6812011-05-06 11:02:41 +0000350 dev_info(&pdev->dev, "%s base at 0x%08lx clock rate %u MHz\n",
351 mmc_hostname(host->mmc), (unsigned long)
Guennadi Liakhovetski58126c82012-02-09 22:57:10 +0100352 (platform_get_resource(pdev, IORESOURCE_MEM, 0)->start),
Guennadi Liakhovetski369213b2012-11-28 10:24:13 +0100353 host->mmc->f_max / 1000000);
Magnus Damma87d5632009-10-02 02:22:09 +0000354
Guennadi Liakhovetski42051e82011-03-14 09:52:33 +0100355 return ret;
Magnus Damma87d5632009-10-02 02:22:09 +0000356
Guennadi Liakhovetskiac51b962013-02-15 16:13:58 +0100357eirq:
Magnus Damm8e7bfdb2011-05-06 11:02:33 +0000358 tmio_mmc_host_remove(host);
Kuninori Morimoto94b110a2015-01-13 04:57:22 +0000359efree:
360 tmio_mmc_host_free(host);
Guennadi Liakhovetski42051e82011-03-14 09:52:33 +0100361eprobe:
Guennadi Liakhovetski42051e82011-03-14 09:52:33 +0100362eclkget:
Guennadi Liakhovetskic7bb4482012-05-01 18:03:43 +0200363 if (p && p->cleanup)
Bastian Hechte82b4ac2012-03-16 12:19:29 -0400364 p->cleanup(pdev);
Magnus Damma87d5632009-10-02 02:22:09 +0000365 return ret;
366}
367
368static int sh_mobile_sdhi_remove(struct platform_device *pdev)
369{
Guennadi Liakhovetski42051e82011-03-14 09:52:33 +0100370 struct mmc_host *mmc = platform_get_drvdata(pdev);
371 struct tmio_mmc_host *host = mmc_priv(mmc);
Guennadi Liakhovetski25958802011-05-11 16:51:15 +0000372 struct sh_mobile_sdhi_info *p = pdev->dev.platform_data;
Magnus Damma87d5632009-10-02 02:22:09 +0000373
Guennadi Liakhovetski742a0c72011-05-27 16:54:05 +0200374 tmio_mmc_host_remove(host);
375
Guennadi Liakhovetskic7bb4482012-05-01 18:03:43 +0200376 if (p && p->cleanup)
Bastian Hechte82b4ac2012-03-16 12:19:29 -0400377 p->cleanup(pdev);
378
Magnus Damma87d5632009-10-02 02:22:09 +0000379 return 0;
380}
381
Guennadi Liakhovetskie6ee7182011-05-05 16:13:12 +0000382static const struct dev_pm_ops tmio_mmc_dev_pm_ops = {
Ulf Hansson753a6882014-08-25 12:18:26 +0200383 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
384 pm_runtime_force_resume)
Rafael J. Wysocki6ed23b82014-12-04 00:34:11 +0100385 SET_RUNTIME_PM_OPS(tmio_mmc_host_runtime_suspend,
Ulf Hansson4e262d72013-10-23 14:51:31 +0200386 tmio_mmc_host_runtime_resume,
387 NULL)
Guennadi Liakhovetskie6ee7182011-05-05 16:13:12 +0000388};
389
Magnus Damma87d5632009-10-02 02:22:09 +0000390static struct platform_driver sh_mobile_sdhi_driver = {
391 .driver = {
392 .name = "sh_mobile_sdhi",
Guennadi Liakhovetskie6ee7182011-05-05 16:13:12 +0000393 .pm = &tmio_mmc_dev_pm_ops,
Guennadi Liakhovetskic7bb4482012-05-01 18:03:43 +0200394 .of_match_table = sh_mobile_sdhi_of_match,
Magnus Damma87d5632009-10-02 02:22:09 +0000395 },
396 .probe = sh_mobile_sdhi_probe,
Bill Pemberton0433c142012-11-19 13:20:26 -0500397 .remove = sh_mobile_sdhi_remove,
Magnus Damma87d5632009-10-02 02:22:09 +0000398};
399
Axel Lind1f81a62011-11-26 12:55:43 +0800400module_platform_driver(sh_mobile_sdhi_driver);
Magnus Damma87d5632009-10-02 02:22:09 +0000401
402MODULE_DESCRIPTION("SuperH Mobile SDHI driver");
403MODULE_AUTHOR("Magnus Damm");
404MODULE_LICENSE("GPL v2");
Guennadi Liakhovetski42051e82011-03-14 09:52:33 +0100405MODULE_ALIAS("platform:sh_mobile_sdhi");