blob: 9edd7596d1e71b476076e7ec0e8c61019e91997f [file] [log] [blame]
Tony Lindgren90c62bf2008-12-10 17:37:17 -08001/*
Adrian Hunterd02a900b2010-02-15 10:03:34 -08002 * linux/arch/arm/mach-omap2/hsmmc.c
Tony Lindgren90c62bf2008-12-10 17:37:17 -08003 *
4 * Copyright (C) 2007-2008 Texas Instruments
5 * Copyright (C) 2008 Nokia Corporation
6 * Author: Texas Instruments
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 */
Adrian Hunterdb0fefc2010-02-15 10:03:34 -080012#include <linux/kernel.h>
13#include <linux/slab.h>
14#include <linux/string.h>
Tony Lindgren90c62bf2008-12-10 17:37:17 -080015#include <linux/delay.h>
Silesh C V5e4698f2011-07-04 04:10:00 -070016#include <linux/gpio.h>
Andreas Fenkart826c71a2014-11-08 15:33:08 +010017#include <linux/mmc/host.h>
Tony Lindgren4b254082012-08-30 15:37:24 -070018#include <linux/platform_data/gpio-omap.h>
Andreas Fenkart551434382014-11-08 15:33:09 +010019#include <linux/platform_data/hsmmc-omap.h>
Tony Lindgren4b254082012-08-30 15:37:24 -070020
Tony Lindgrene4c060d2012-10-05 13:25:59 -070021#include "soc.h"
Tony Lindgren25c7d492012-10-02 17:25:48 -070022#include "omap_device.h"
Tony Lindgren1d5aef42012-10-03 16:36:40 -070023#include "omap-pm.h"
Tony Lindgren90c62bf2008-12-10 17:37:17 -080024
Kishore Kadiyalad8d0a612011-02-28 20:48:03 +053025#include "mux.h"
Adrian Hunterd02a900b2010-02-15 10:03:34 -080026#include "hsmmc.h"
Paul Walmsley4814ced2010-10-08 11:40:20 -060027#include "control.h"
Tony Lindgren90c62bf2008-12-10 17:37:17 -080028
Adrian Hunterdb0fefc2010-02-15 10:03:34 -080029#if defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
Tony Lindgren90c62bf2008-12-10 17:37:17 -080030
Tony Lindgren90c62bf2008-12-10 17:37:17 -080031static u16 control_pbias_offset;
32static u16 control_devconf1_offset;
33
34#define HSMMC_NAME_LEN 9
35
Denis Karpov1887bde2009-09-22 16:44:40 -070036#if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM)
37
Adrian Hunter68ff0422010-02-15 10:03:34 -080038static int hsmmc_get_context_loss(struct device *dev)
Denis Karpov1887bde2009-09-22 16:44:40 -070039{
Adrian Huntere3df0fb2010-02-15 10:03:34 -080040 return omap_pm_get_dev_context_loss_count(dev);
Denis Karpov1887bde2009-09-22 16:44:40 -070041}
42
43#else
Adrian Hunter68ff0422010-02-15 10:03:34 -080044#define hsmmc_get_context_loss NULL
Denis Karpov1887bde2009-09-22 16:44:40 -070045#endif
46
kishore kadiyalac83c8e62010-05-15 18:21:25 +000047static void omap_hsmmc1_before_set_reg(struct device *dev, int slot,
Adrian Hunterdb0fefc2010-02-15 10:03:34 -080048 int power_on, int vdd)
Tony Lindgren90c62bf2008-12-10 17:37:17 -080049{
Madhu555d5032009-11-22 10:11:08 -080050 u32 reg, prog_io;
Andreas Fenkart551434382014-11-08 15:33:09 +010051 struct omap_hsmmc_platform_data *mmc = dev->platform_data;
Tony Lindgren90c62bf2008-12-10 17:37:17 -080052
Adrian Hunterce6f0012010-02-15 10:03:34 -080053 if (mmc->slots[0].remux)
54 mmc->slots[0].remux(dev, slot, power_on);
55
David Brownell0329c372009-03-23 18:23:47 -070056 /*
57 * Assume we power both OMAP VMMC1 (for CMD, CLK, DAT0..3) and the
David Brownellb583f262009-05-28 14:04:03 -070058 * card with Vcc regulator (from twl4030 or whatever). OMAP has both
David Brownell0329c372009-03-23 18:23:47 -070059 * 1.8V and 3.0V modes, controlled by the PBIAS register.
60 *
61 * In 8-bit modes, OMAP VMMC1A (for DAT4..7) needs a supply, which
62 * is most naturally TWL VSIM; those pins also use PBIAS.
David Brownellb583f262009-05-28 14:04:03 -070063 *
64 * FIXME handle VMMC1A as needed ...
David Brownell0329c372009-03-23 18:23:47 -070065 */
Tony Lindgren90c62bf2008-12-10 17:37:17 -080066 if (power_on) {
67 if (cpu_is_omap2430()) {
68 reg = omap_ctrl_readl(OMAP243X_CONTROL_DEVCONF1);
69 if ((1 << vdd) >= MMC_VDD_30_31)
70 reg |= OMAP243X_MMC1_ACTIVE_OVERWRITE;
71 else
72 reg &= ~OMAP243X_MMC1_ACTIVE_OVERWRITE;
73 omap_ctrl_writel(reg, OMAP243X_CONTROL_DEVCONF1);
74 }
75
76 if (mmc->slots[0].internal_clock) {
77 reg = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
78 reg |= OMAP2_MMCSDIO1ADPCLKISEL;
79 omap_ctrl_writel(reg, OMAP2_CONTROL_DEVCONF0);
80 }
81
82 reg = omap_ctrl_readl(control_pbias_offset);
Madhu555d5032009-11-22 10:11:08 -080083 if (cpu_is_omap3630()) {
84 /* Set MMC I/O to 52Mhz */
85 prog_io = omap_ctrl_readl(OMAP343X_CONTROL_PROG_IO1);
86 prog_io |= OMAP3630_PRG_SDMMC1_SPEEDCTRL;
87 omap_ctrl_writel(prog_io, OMAP343X_CONTROL_PROG_IO1);
88 } else {
89 reg |= OMAP2_PBIASSPEEDCTRL0;
90 }
Tony Lindgren90c62bf2008-12-10 17:37:17 -080091 reg &= ~OMAP2_PBIASLITEPWRDNZ0;
92 omap_ctrl_writel(reg, control_pbias_offset);
Adrian Hunterdb0fefc2010-02-15 10:03:34 -080093 } else {
94 reg = omap_ctrl_readl(control_pbias_offset);
95 reg &= ~OMAP2_PBIASLITEPWRDNZ0;
96 omap_ctrl_writel(reg, control_pbias_offset);
97 }
98}
Tony Lindgren90c62bf2008-12-10 17:37:17 -080099
kishore kadiyalac83c8e62010-05-15 18:21:25 +0000100static void omap_hsmmc1_after_set_reg(struct device *dev, int slot,
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800101 int power_on, int vdd)
102{
103 u32 reg;
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800104
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800105 /* 100ms delay required for PBIAS configuration */
106 msleep(100);
107
108 if (power_on) {
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800109 reg = omap_ctrl_readl(control_pbias_offset);
110 reg |= (OMAP2_PBIASLITEPWRDNZ0 | OMAP2_PBIASSPEEDCTRL0);
111 if ((1 << vdd) <= MMC_VDD_165_195)
112 reg &= ~OMAP2_PBIASLITEVMODE0;
113 else
114 reg |= OMAP2_PBIASLITEVMODE0;
115 omap_ctrl_writel(reg, control_pbias_offset);
116 } else {
117 reg = omap_ctrl_readl(control_pbias_offset);
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800118 reg |= (OMAP2_PBIASSPEEDCTRL0 | OMAP2_PBIASLITEPWRDNZ0 |
119 OMAP2_PBIASLITEVMODE0);
120 omap_ctrl_writel(reg, control_pbias_offset);
121 }
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800122}
123
Andreas Fenkart551434382014-11-08 15:33:09 +0100124static void hsmmc2_select_input_clk_src(struct omap_hsmmc_platform_data *mmc)
Igor Grinberge62245b2011-11-29 11:37:48 +0200125{
126 u32 reg;
127
Grazvydas Ignotasd82e5192012-01-12 16:26:45 +0200128 reg = omap_ctrl_readl(control_devconf1_offset);
129 if (mmc->slots[0].internal_clock)
Igor Grinberge62245b2011-11-29 11:37:48 +0200130 reg |= OMAP2_MMCSDIO2ADPCLKISEL;
Grazvydas Ignotasd82e5192012-01-12 16:26:45 +0200131 else
132 reg &= ~OMAP2_MMCSDIO2ADPCLKISEL;
133 omap_ctrl_writel(reg, control_devconf1_offset);
Igor Grinberge62245b2011-11-29 11:37:48 +0200134}
135
Grazvydas Ignotasffa1e4e2011-12-18 02:35:47 +0200136static void hsmmc2_before_set_reg(struct device *dev, int slot,
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800137 int power_on, int vdd)
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800138{
Andreas Fenkart551434382014-11-08 15:33:09 +0100139 struct omap_hsmmc_platform_data *mmc = dev->platform_data;
Grazvydas Ignotas762ad3a42009-06-23 13:30:22 +0300140
Adrian Hunterce6f0012010-02-15 10:03:34 -0800141 if (mmc->slots[0].remux)
142 mmc->slots[0].remux(dev, slot, power_on);
143
Igor Grinberge62245b2011-11-29 11:37:48 +0200144 if (power_on)
145 hsmmc2_select_input_clk_src(mmc);
146}
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800147
Igor Grinberge62245b2011-11-29 11:37:48 +0200148static int am35x_hsmmc2_set_power(struct device *dev, int slot,
149 int power_on, int vdd)
150{
Andreas Fenkart551434382014-11-08 15:33:09 +0100151 struct omap_hsmmc_platform_data *mmc = dev->platform_data;
Igor Grinberge62245b2011-11-29 11:37:48 +0200152
153 if (power_on)
154 hsmmc2_select_input_clk_src(mmc);
155
156 return 0;
Adrian Hunter9b7c18e2009-09-22 16:44:50 -0700157}
158
stanley.miao03e7e172010-05-13 12:39:31 +0000159static int nop_mmc_set_power(struct device *dev, int slot, int power_on,
160 int vdd)
161{
162 return 0;
163}
164
Andreas Fenkart551434382014-11-08 15:33:09 +0100165static inline void omap_hsmmc_mux(struct omap_hsmmc_platform_data
166 *mmc_controller, int controller_nr)
Kishore Kadiyalad8d0a612011-02-28 20:48:03 +0530167{
Thomas Webera15164f2011-11-17 22:39:40 +0100168 if (gpio_is_valid(mmc_controller->slots[0].switch_pin) &&
169 (mmc_controller->slots[0].switch_pin < OMAP_MAX_GPIO_LINES))
Kishore Kadiyalad8d0a612011-02-28 20:48:03 +0530170 omap_mux_init_gpio(mmc_controller->slots[0].switch_pin,
171 OMAP_PIN_INPUT_PULLUP);
Thomas Webera15164f2011-11-17 22:39:40 +0100172 if (gpio_is_valid(mmc_controller->slots[0].gpio_wp) &&
173 (mmc_controller->slots[0].gpio_wp < OMAP_MAX_GPIO_LINES))
Kishore Kadiyalad8d0a612011-02-28 20:48:03 +0530174 omap_mux_init_gpio(mmc_controller->slots[0].gpio_wp,
175 OMAP_PIN_INPUT_PULLUP);
176 if (cpu_is_omap34xx()) {
177 if (controller_nr == 0) {
178 omap_mux_init_signal("sdmmc1_clk",
179 OMAP_PIN_INPUT_PULLUP);
180 omap_mux_init_signal("sdmmc1_cmd",
181 OMAP_PIN_INPUT_PULLUP);
182 omap_mux_init_signal("sdmmc1_dat0",
183 OMAP_PIN_INPUT_PULLUP);
184 if (mmc_controller->slots[0].caps &
185 (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)) {
186 omap_mux_init_signal("sdmmc1_dat1",
187 OMAP_PIN_INPUT_PULLUP);
188 omap_mux_init_signal("sdmmc1_dat2",
189 OMAP_PIN_INPUT_PULLUP);
190 omap_mux_init_signal("sdmmc1_dat3",
191 OMAP_PIN_INPUT_PULLUP);
192 }
193 if (mmc_controller->slots[0].caps &
194 MMC_CAP_8_BIT_DATA) {
195 omap_mux_init_signal("sdmmc1_dat4",
196 OMAP_PIN_INPUT_PULLUP);
197 omap_mux_init_signal("sdmmc1_dat5",
198 OMAP_PIN_INPUT_PULLUP);
199 omap_mux_init_signal("sdmmc1_dat6",
200 OMAP_PIN_INPUT_PULLUP);
201 omap_mux_init_signal("sdmmc1_dat7",
202 OMAP_PIN_INPUT_PULLUP);
203 }
204 }
205 if (controller_nr == 1) {
206 /* MMC2 */
207 omap_mux_init_signal("sdmmc2_clk",
208 OMAP_PIN_INPUT_PULLUP);
209 omap_mux_init_signal("sdmmc2_cmd",
210 OMAP_PIN_INPUT_PULLUP);
211 omap_mux_init_signal("sdmmc2_dat0",
212 OMAP_PIN_INPUT_PULLUP);
213
214 /*
215 * For 8 wire configurations, Lines DAT4, 5, 6 and 7
216 * need to be muxed in the board-*.c files
217 */
218 if (mmc_controller->slots[0].caps &
219 (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)) {
220 omap_mux_init_signal("sdmmc2_dat1",
221 OMAP_PIN_INPUT_PULLUP);
222 omap_mux_init_signal("sdmmc2_dat2",
223 OMAP_PIN_INPUT_PULLUP);
224 omap_mux_init_signal("sdmmc2_dat3",
225 OMAP_PIN_INPUT_PULLUP);
226 }
227 if (mmc_controller->slots[0].caps &
228 MMC_CAP_8_BIT_DATA) {
229 omap_mux_init_signal("sdmmc2_dat4.sdmmc2_dat4",
230 OMAP_PIN_INPUT_PULLUP);
231 omap_mux_init_signal("sdmmc2_dat5.sdmmc2_dat5",
232 OMAP_PIN_INPUT_PULLUP);
233 omap_mux_init_signal("sdmmc2_dat6.sdmmc2_dat6",
234 OMAP_PIN_INPUT_PULLUP);
235 omap_mux_init_signal("sdmmc2_dat7.sdmmc2_dat7",
236 OMAP_PIN_INPUT_PULLUP);
237 }
238 }
239
240 /*
241 * For MMC3 the pins need to be muxed in the board-*.c files
242 */
243 }
244}
245
Tony Lindgrend1589f02012-02-20 09:43:30 -0800246static int __init omap_hsmmc_pdata_init(struct omap2_hsmmc_info *c,
Andreas Fenkart551434382014-11-08 15:33:09 +0100247 struct omap_hsmmc_platform_data *mmc)
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530248{
249 char *hc_name;
250
251 hc_name = kzalloc(sizeof(char) * (HSMMC_NAME_LEN + 1), GFP_KERNEL);
252 if (!hc_name) {
253 pr_err("Cannot allocate memory for controller slot name\n");
254 kfree(hc_name);
255 return -ENOMEM;
256 }
257
258 if (c->name)
259 strncpy(hc_name, c->name, HSMMC_NAME_LEN);
260 else
261 snprintf(hc_name, (HSMMC_NAME_LEN + 1), "mmc%islot%i",
262 c->mmc, 1);
263 mmc->slots[0].name = hc_name;
264 mmc->nr_slots = 1;
265 mmc->slots[0].caps = c->caps;
Eliad Peller6fdc75d2011-11-22 16:02:18 +0200266 mmc->slots[0].pm_caps = c->pm_caps;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530267 mmc->slots[0].internal_clock = !c->ext_clock;
Daniel Mackd418ed82012-02-19 13:20:33 +0100268 mmc->max_freq = c->max_freq;
Tony Lindgrenb30e3212013-05-30 12:53:06 -0700269 mmc->reg_offset = 0;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530270 mmc->get_context_loss_count = hsmmc_get_context_loss;
271
272 mmc->slots[0].switch_pin = c->gpio_cd;
273 mmc->slots[0].gpio_wp = c->gpio_wp;
274
275 mmc->slots[0].remux = c->remux;
276 mmc->slots[0].init_card = c->init_card;
277
278 if (c->cover_only)
279 mmc->slots[0].cover = 1;
280
281 if (c->nonremovable)
282 mmc->slots[0].nonremovable = 1;
283
284 if (c->power_saving)
285 mmc->slots[0].power_saving = 1;
286
287 if (c->no_off)
288 mmc->slots[0].no_off = 1;
289
Balaji T Kb1c1df72011-05-30 19:55:34 +0530290 if (c->no_off_init)
291 mmc->slots[0].no_regulator_off_init = c->no_off_init;
292
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530293 if (c->vcc_aux_disable_is_sleep)
294 mmc->slots[0].vcc_aux_disable_is_sleep = 1;
295
296 /*
297 * NOTE: MMC slots should have a Vcc regulator set up.
298 * This may be from a TWL4030-family chip, another
299 * controllable regulator, or a fixed supply.
300 *
301 * temporary HACK: ocr_mask instead of fixed supply
302 */
Kevin Hilman68a88b92012-04-30 16:37:10 -0700303 if (soc_is_am35xx())
Abhilash K Ve89715a2011-12-09 12:27:36 -0800304 mmc->slots[0].ocr_mask = MMC_VDD_165_195 |
305 MMC_VDD_26_27 |
306 MMC_VDD_27_28 |
307 MMC_VDD_29_30 |
308 MMC_VDD_30_31 |
309 MMC_VDD_31_32;
310 else
311 mmc->slots[0].ocr_mask = c->ocr_mask;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530312
Kevin Hilman68a88b92012-04-30 16:37:10 -0700313 if (!soc_is_am35xx())
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530314 mmc->slots[0].features |= HSMMC_HAS_PBIAS;
315
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530316 switch (c->mmc) {
317 case 1:
318 if (mmc->slots[0].features & HSMMC_HAS_PBIAS) {
319 /* on-chip level shifting via PBIAS0/PBIAS1 */
Tony Lindgrenb30e3212013-05-30 12:53:06 -0700320 mmc->slots[0].before_set_reg =
321 omap_hsmmc1_before_set_reg;
322 mmc->slots[0].after_set_reg =
323 omap_hsmmc1_after_set_reg;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530324 }
325
Kevin Hilman68a88b92012-04-30 16:37:10 -0700326 if (soc_is_am35xx())
Igor Grinberge62245b2011-11-29 11:37:48 +0200327 mmc->slots[0].set_power = nop_mmc_set_power;
328
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530329 /* OMAP3630 HSMMC1 supports only 4-bit */
330 if (cpu_is_omap3630() &&
331 (c->caps & MMC_CAP_8_BIT_DATA)) {
332 c->caps &= ~MMC_CAP_8_BIT_DATA;
333 c->caps |= MMC_CAP_4_BIT_DATA;
334 mmc->slots[0].caps = c->caps;
335 }
336 break;
337 case 2:
Kevin Hilman68a88b92012-04-30 16:37:10 -0700338 if (soc_is_am35xx())
Igor Grinberge62245b2011-11-29 11:37:48 +0200339 mmc->slots[0].set_power = am35x_hsmmc2_set_power;
340
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530341 if (c->ext_clock)
342 c->transceiver = 1;
343 if (c->transceiver && (c->caps & MMC_CAP_8_BIT_DATA)) {
344 c->caps &= ~MMC_CAP_8_BIT_DATA;
345 c->caps |= MMC_CAP_4_BIT_DATA;
346 }
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530347 if (mmc->slots[0].features & HSMMC_HAS_PBIAS) {
348 /* off-chip level shifting, or none */
Grazvydas Ignotasffa1e4e2011-12-18 02:35:47 +0200349 mmc->slots[0].before_set_reg = hsmmc2_before_set_reg;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530350 mmc->slots[0].after_set_reg = NULL;
351 }
352 break;
Grazvydas Ignotasffa1e4e2011-12-18 02:35:47 +0200353 case 3:
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530354 case 4:
355 case 5:
356 mmc->slots[0].before_set_reg = NULL;
357 mmc->slots[0].after_set_reg = NULL;
358 break;
359 default:
360 pr_err("MMC%d configuration not supported!\n", c->mmc);
361 kfree(hc_name);
362 return -ENODEV;
363 }
364 return 0;
365}
366
Tony Lindgren97899e52012-02-20 09:43:28 -0800367static int omap_hsmmc_done;
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800368
369void omap_hsmmc_late_init(struct omap2_hsmmc_info *c)
370{
371 struct platform_device *pdev;
Andreas Fenkart551434382014-11-08 15:33:09 +0100372 struct omap_hsmmc_platform_data *mmc_pdata;
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800373 int res;
374
375 if (omap_hsmmc_done != 1)
376 return;
377
378 omap_hsmmc_done++;
379
380 for (; c->mmc; c++) {
381 if (!c->deferred)
382 continue;
383
384 pdev = c->pdev;
385 if (!pdev)
386 continue;
387
388 mmc_pdata = pdev->dev.platform_data;
389 if (!mmc_pdata)
390 continue;
391
392 mmc_pdata->slots[0].switch_pin = c->gpio_cd;
393 mmc_pdata->slots[0].gpio_wp = c->gpio_wp;
394
395 res = omap_device_register(pdev);
396 if (res)
397 pr_err("Could not late init MMC %s\n",
398 c->name);
399 }
400}
401
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530402#define MAX_OMAP_MMC_HWMOD_NAME_LEN 16
403
Tony Lindgren60285052012-03-07 18:54:24 -0800404static void __init omap_hsmmc_init_one(struct omap2_hsmmc_info *hsmmcinfo,
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800405 int ctrl_nr)
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530406{
407 struct omap_hwmod *oh;
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800408 struct omap_hwmod *ohs[1];
409 struct omap_device *od;
Kevin Hilman3528c582011-07-21 13:48:45 -0700410 struct platform_device *pdev;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530411 char oh_name[MAX_OMAP_MMC_HWMOD_NAME_LEN];
Andreas Fenkart551434382014-11-08 15:33:09 +0100412 struct omap_hsmmc_platform_data *mmc_data;
413 struct omap_hsmmc_dev_attr *mmc_dev_attr;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530414 char *name;
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800415 int res;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530416
Andreas Fenkart551434382014-11-08 15:33:09 +0100417 mmc_data = kzalloc(sizeof(*mmc_data), GFP_KERNEL);
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530418 if (!mmc_data) {
419 pr_err("Cannot allocate memory for mmc device!\n");
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800420 return;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530421 }
422
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800423 res = omap_hsmmc_pdata_init(hsmmcinfo, mmc_data);
424 if (res < 0)
425 goto free_mmc;
426
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530427 omap_hsmmc_mux(mmc_data, (ctrl_nr - 1));
428
Kishore Kadiyala0005ae72011-02-28 20:48:05 +0530429 name = "omap_hsmmc";
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800430 res = snprintf(oh_name, MAX_OMAP_MMC_HWMOD_NAME_LEN,
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530431 "mmc%d", ctrl_nr);
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800432 WARN(res >= MAX_OMAP_MMC_HWMOD_NAME_LEN,
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530433 "String buffer overflow in MMC%d device setup\n", ctrl_nr);
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800434
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530435 oh = omap_hwmod_lookup(oh_name);
436 if (!oh) {
437 pr_err("Could not look up %s\n", oh_name);
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800438 goto free_name;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530439 }
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800440 ohs[0] = oh;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530441 if (oh->dev_attr != NULL) {
442 mmc_dev_attr = oh->dev_attr;
443 mmc_data->controller_flags = mmc_dev_attr->flags;
Grazvydas Ignotas26c547f2012-03-16 14:49:54 +0200444 /*
445 * erratum 2.1.1.128 doesn't apply if board has
446 * a transceiver is attached
447 */
448 if (hsmmcinfo->transceiver)
449 mmc_data->controller_flags &=
450 ~OMAP_HSMMC_BROKEN_MULTIBLOCK_READ;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530451 }
452
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800453 pdev = platform_device_alloc(name, ctrl_nr - 1);
454 if (!pdev) {
455 pr_err("Could not allocate pdev for %s\n", name);
456 goto free_name;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530457 }
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800458 dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530459
Paul Walmsleyc1d1cd52013-01-26 00:48:53 -0700460 od = omap_device_alloc(pdev, ohs, 1);
Wei Yongjun64de3a02012-09-21 14:30:50 +0800461 if (IS_ERR(od)) {
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800462 pr_err("Could not allocate od for %s\n", name);
463 goto put_pdev;
464 }
465
466 res = platform_device_add_data(pdev, mmc_data,
Andreas Fenkart551434382014-11-08 15:33:09 +0100467 sizeof(struct omap_hsmmc_platform_data));
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800468 if (res) {
469 pr_err("Could not add pdata for %s\n", name);
470 goto put_pdev;
471 }
472
473 hsmmcinfo->pdev = pdev;
474
475 if (hsmmcinfo->deferred)
476 goto free_mmc;
477
478 res = omap_device_register(pdev);
479 if (res) {
480 pr_err("Could not register od for %s\n", name);
481 goto free_od;
482 }
483
484 goto free_mmc;
485
486free_od:
487 omap_device_delete(od);
488
489put_pdev:
490 platform_device_put(pdev);
491
492free_name:
493 kfree(mmc_data->slots[0].name);
494
495free_mmc:
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530496 kfree(mmc_data);
497}
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800498
Tony Lindgrend1589f02012-02-20 09:43:30 -0800499void __init omap_hsmmc_init(struct omap2_hsmmc_info *controllers)
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800500{
Tony Lindgren97899e52012-02-20 09:43:28 -0800501 if (omap_hsmmc_done)
502 return;
503
504 omap_hsmmc_done = 1;
505
Tony Lindgrenb30e3212013-05-30 12:53:06 -0700506 if (cpu_is_omap2430()) {
507 control_pbias_offset = OMAP243X_CONTROL_PBIAS_LITE;
508 control_devconf1_offset = OMAP243X_CONTROL_DEVCONF1;
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800509 } else {
Tony Lindgrenb30e3212013-05-30 12:53:06 -0700510 control_pbias_offset = OMAP343X_CONTROL_PBIAS_LITE;
511 control_devconf1_offset = OMAP343X_CONTROL_DEVCONF1;
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800512 }
513
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530514 for (; controllers->mmc; controllers++)
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800515 omap_hsmmc_init_one(controllers, controllers->mmc);
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800516
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800517}
518
519#endif