blob: 07d4c7b357544b461e7979620d7f00de8968f734 [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>
Tony Lindgren4b254082012-08-30 15:37:24 -070017#include <linux/platform_data/gpio-omap.h>
18
Tony Lindgrene4c060d2012-10-05 13:25:59 -070019#include "soc.h"
Tony Lindgren25c7d492012-10-02 17:25:48 -070020#include "omap_device.h"
Tony Lindgren1d5aef42012-10-03 16:36:40 -070021#include "omap-pm.h"
Tony Lindgren90c62bf2008-12-10 17:37:17 -080022
Kishore Kadiyalad8d0a612011-02-28 20:48:03 +053023#include "mux.h"
Tony Lindgren68f39e72012-10-15 12:09:43 -070024#include "mmc.h"
Adrian Hunterd02a900b2010-02-15 10:03:34 -080025#include "hsmmc.h"
Paul Walmsley4814ced2010-10-08 11:40:20 -060026#include "control.h"
Tony Lindgren90c62bf2008-12-10 17:37:17 -080027
Adrian Hunterdb0fefc2010-02-15 10:03:34 -080028#if defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
Tony Lindgren90c62bf2008-12-10 17:37:17 -080029
Tony Lindgren90c62bf2008-12-10 17:37:17 -080030static u16 control_pbias_offset;
31static u16 control_devconf1_offset;
32
33#define HSMMC_NAME_LEN 9
34
Denis Karpov1887bde2009-09-22 16:44:40 -070035#if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM)
36
Adrian Hunter68ff0422010-02-15 10:03:34 -080037static int hsmmc_get_context_loss(struct device *dev)
Denis Karpov1887bde2009-09-22 16:44:40 -070038{
Adrian Huntere3df0fb2010-02-15 10:03:34 -080039 return omap_pm_get_dev_context_loss_count(dev);
Denis Karpov1887bde2009-09-22 16:44:40 -070040}
41
42#else
Adrian Hunter68ff0422010-02-15 10:03:34 -080043#define hsmmc_get_context_loss NULL
Denis Karpov1887bde2009-09-22 16:44:40 -070044#endif
45
kishore kadiyalac83c8e62010-05-15 18:21:25 +000046static void omap_hsmmc1_before_set_reg(struct device *dev, int slot,
Adrian Hunterdb0fefc2010-02-15 10:03:34 -080047 int power_on, int vdd)
Tony Lindgren90c62bf2008-12-10 17:37:17 -080048{
Madhu555d5032009-11-22 10:11:08 -080049 u32 reg, prog_io;
Tony Lindgren90c62bf2008-12-10 17:37:17 -080050 struct omap_mmc_platform_data *mmc = dev->platform_data;
51
Adrian Hunterce6f0012010-02-15 10:03:34 -080052 if (mmc->slots[0].remux)
53 mmc->slots[0].remux(dev, slot, power_on);
54
David Brownell0329c372009-03-23 18:23:47 -070055 /*
56 * Assume we power both OMAP VMMC1 (for CMD, CLK, DAT0..3) and the
David Brownellb583f262009-05-28 14:04:03 -070057 * card with Vcc regulator (from twl4030 or whatever). OMAP has both
David Brownell0329c372009-03-23 18:23:47 -070058 * 1.8V and 3.0V modes, controlled by the PBIAS register.
59 *
60 * In 8-bit modes, OMAP VMMC1A (for DAT4..7) needs a supply, which
61 * is most naturally TWL VSIM; those pins also use PBIAS.
David Brownellb583f262009-05-28 14:04:03 -070062 *
63 * FIXME handle VMMC1A as needed ...
David Brownell0329c372009-03-23 18:23:47 -070064 */
Tony Lindgren90c62bf2008-12-10 17:37:17 -080065 if (power_on) {
66 if (cpu_is_omap2430()) {
67 reg = omap_ctrl_readl(OMAP243X_CONTROL_DEVCONF1);
68 if ((1 << vdd) >= MMC_VDD_30_31)
69 reg |= OMAP243X_MMC1_ACTIVE_OVERWRITE;
70 else
71 reg &= ~OMAP243X_MMC1_ACTIVE_OVERWRITE;
72 omap_ctrl_writel(reg, OMAP243X_CONTROL_DEVCONF1);
73 }
74
75 if (mmc->slots[0].internal_clock) {
76 reg = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
77 reg |= OMAP2_MMCSDIO1ADPCLKISEL;
78 omap_ctrl_writel(reg, OMAP2_CONTROL_DEVCONF0);
79 }
80
81 reg = omap_ctrl_readl(control_pbias_offset);
Madhu555d5032009-11-22 10:11:08 -080082 if (cpu_is_omap3630()) {
83 /* Set MMC I/O to 52Mhz */
84 prog_io = omap_ctrl_readl(OMAP343X_CONTROL_PROG_IO1);
85 prog_io |= OMAP3630_PRG_SDMMC1_SPEEDCTRL;
86 omap_ctrl_writel(prog_io, OMAP343X_CONTROL_PROG_IO1);
87 } else {
88 reg |= OMAP2_PBIASSPEEDCTRL0;
89 }
Tony Lindgren90c62bf2008-12-10 17:37:17 -080090 reg &= ~OMAP2_PBIASLITEPWRDNZ0;
91 omap_ctrl_writel(reg, control_pbias_offset);
Adrian Hunterdb0fefc2010-02-15 10:03:34 -080092 } else {
93 reg = omap_ctrl_readl(control_pbias_offset);
94 reg &= ~OMAP2_PBIASLITEPWRDNZ0;
95 omap_ctrl_writel(reg, control_pbias_offset);
96 }
97}
Tony Lindgren90c62bf2008-12-10 17:37:17 -080098
kishore kadiyalac83c8e62010-05-15 18:21:25 +000099static void omap_hsmmc1_after_set_reg(struct device *dev, int slot,
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800100 int power_on, int vdd)
101{
102 u32 reg;
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800103
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800104 /* 100ms delay required for PBIAS configuration */
105 msleep(100);
106
107 if (power_on) {
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800108 reg = omap_ctrl_readl(control_pbias_offset);
109 reg |= (OMAP2_PBIASLITEPWRDNZ0 | OMAP2_PBIASSPEEDCTRL0);
110 if ((1 << vdd) <= MMC_VDD_165_195)
111 reg &= ~OMAP2_PBIASLITEVMODE0;
112 else
113 reg |= OMAP2_PBIASLITEVMODE0;
114 omap_ctrl_writel(reg, control_pbias_offset);
115 } else {
116 reg = omap_ctrl_readl(control_pbias_offset);
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800117 reg |= (OMAP2_PBIASSPEEDCTRL0 | OMAP2_PBIASLITEPWRDNZ0 |
118 OMAP2_PBIASLITEVMODE0);
119 omap_ctrl_writel(reg, control_pbias_offset);
120 }
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800121}
122
Igor Grinberge62245b2011-11-29 11:37:48 +0200123static void hsmmc2_select_input_clk_src(struct omap_mmc_platform_data *mmc)
124{
125 u32 reg;
126
Grazvydas Ignotasd82e5192012-01-12 16:26:45 +0200127 reg = omap_ctrl_readl(control_devconf1_offset);
128 if (mmc->slots[0].internal_clock)
Igor Grinberge62245b2011-11-29 11:37:48 +0200129 reg |= OMAP2_MMCSDIO2ADPCLKISEL;
Grazvydas Ignotasd82e5192012-01-12 16:26:45 +0200130 else
131 reg &= ~OMAP2_MMCSDIO2ADPCLKISEL;
132 omap_ctrl_writel(reg, control_devconf1_offset);
Igor Grinberge62245b2011-11-29 11:37:48 +0200133}
134
Grazvydas Ignotasffa1e4e2011-12-18 02:35:47 +0200135static void hsmmc2_before_set_reg(struct device *dev, int slot,
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800136 int power_on, int vdd)
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800137{
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800138 struct omap_mmc_platform_data *mmc = dev->platform_data;
Grazvydas Ignotas762ad3a42009-06-23 13:30:22 +0300139
Adrian Hunterce6f0012010-02-15 10:03:34 -0800140 if (mmc->slots[0].remux)
141 mmc->slots[0].remux(dev, slot, power_on);
142
Igor Grinberge62245b2011-11-29 11:37:48 +0200143 if (power_on)
144 hsmmc2_select_input_clk_src(mmc);
145}
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800146
Igor Grinberge62245b2011-11-29 11:37:48 +0200147static int am35x_hsmmc2_set_power(struct device *dev, int slot,
148 int power_on, int vdd)
149{
150 struct omap_mmc_platform_data *mmc = dev->platform_data;
151
152 if (power_on)
153 hsmmc2_select_input_clk_src(mmc);
154
155 return 0;
Adrian Hunter9b7c18e2009-09-22 16:44:50 -0700156}
157
stanley.miao03e7e172010-05-13 12:39:31 +0000158static int nop_mmc_set_power(struct device *dev, int slot, int power_on,
159 int vdd)
160{
161 return 0;
162}
163
Kishore Kadiyalad8d0a612011-02-28 20:48:03 +0530164static inline void omap_hsmmc_mux(struct omap_mmc_platform_data *mmc_controller,
165 int controller_nr)
166{
Thomas Webera15164f2011-11-17 22:39:40 +0100167 if (gpio_is_valid(mmc_controller->slots[0].switch_pin) &&
168 (mmc_controller->slots[0].switch_pin < OMAP_MAX_GPIO_LINES))
Kishore Kadiyalad8d0a612011-02-28 20:48:03 +0530169 omap_mux_init_gpio(mmc_controller->slots[0].switch_pin,
170 OMAP_PIN_INPUT_PULLUP);
Thomas Webera15164f2011-11-17 22:39:40 +0100171 if (gpio_is_valid(mmc_controller->slots[0].gpio_wp) &&
172 (mmc_controller->slots[0].gpio_wp < OMAP_MAX_GPIO_LINES))
Kishore Kadiyalad8d0a612011-02-28 20:48:03 +0530173 omap_mux_init_gpio(mmc_controller->slots[0].gpio_wp,
174 OMAP_PIN_INPUT_PULLUP);
175 if (cpu_is_omap34xx()) {
176 if (controller_nr == 0) {
177 omap_mux_init_signal("sdmmc1_clk",
178 OMAP_PIN_INPUT_PULLUP);
179 omap_mux_init_signal("sdmmc1_cmd",
180 OMAP_PIN_INPUT_PULLUP);
181 omap_mux_init_signal("sdmmc1_dat0",
182 OMAP_PIN_INPUT_PULLUP);
183 if (mmc_controller->slots[0].caps &
184 (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)) {
185 omap_mux_init_signal("sdmmc1_dat1",
186 OMAP_PIN_INPUT_PULLUP);
187 omap_mux_init_signal("sdmmc1_dat2",
188 OMAP_PIN_INPUT_PULLUP);
189 omap_mux_init_signal("sdmmc1_dat3",
190 OMAP_PIN_INPUT_PULLUP);
191 }
192 if (mmc_controller->slots[0].caps &
193 MMC_CAP_8_BIT_DATA) {
194 omap_mux_init_signal("sdmmc1_dat4",
195 OMAP_PIN_INPUT_PULLUP);
196 omap_mux_init_signal("sdmmc1_dat5",
197 OMAP_PIN_INPUT_PULLUP);
198 omap_mux_init_signal("sdmmc1_dat6",
199 OMAP_PIN_INPUT_PULLUP);
200 omap_mux_init_signal("sdmmc1_dat7",
201 OMAP_PIN_INPUT_PULLUP);
202 }
203 }
204 if (controller_nr == 1) {
205 /* MMC2 */
206 omap_mux_init_signal("sdmmc2_clk",
207 OMAP_PIN_INPUT_PULLUP);
208 omap_mux_init_signal("sdmmc2_cmd",
209 OMAP_PIN_INPUT_PULLUP);
210 omap_mux_init_signal("sdmmc2_dat0",
211 OMAP_PIN_INPUT_PULLUP);
212
213 /*
214 * For 8 wire configurations, Lines DAT4, 5, 6 and 7
215 * need to be muxed in the board-*.c files
216 */
217 if (mmc_controller->slots[0].caps &
218 (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)) {
219 omap_mux_init_signal("sdmmc2_dat1",
220 OMAP_PIN_INPUT_PULLUP);
221 omap_mux_init_signal("sdmmc2_dat2",
222 OMAP_PIN_INPUT_PULLUP);
223 omap_mux_init_signal("sdmmc2_dat3",
224 OMAP_PIN_INPUT_PULLUP);
225 }
226 if (mmc_controller->slots[0].caps &
227 MMC_CAP_8_BIT_DATA) {
228 omap_mux_init_signal("sdmmc2_dat4.sdmmc2_dat4",
229 OMAP_PIN_INPUT_PULLUP);
230 omap_mux_init_signal("sdmmc2_dat5.sdmmc2_dat5",
231 OMAP_PIN_INPUT_PULLUP);
232 omap_mux_init_signal("sdmmc2_dat6.sdmmc2_dat6",
233 OMAP_PIN_INPUT_PULLUP);
234 omap_mux_init_signal("sdmmc2_dat7.sdmmc2_dat7",
235 OMAP_PIN_INPUT_PULLUP);
236 }
237 }
238
239 /*
240 * For MMC3 the pins need to be muxed in the board-*.c files
241 */
242 }
243}
244
Tony Lindgrend1589f02012-02-20 09:43:30 -0800245static int __init omap_hsmmc_pdata_init(struct omap2_hsmmc_info *c,
246 struct omap_mmc_platform_data *mmc)
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530247{
248 char *hc_name;
249
250 hc_name = kzalloc(sizeof(char) * (HSMMC_NAME_LEN + 1), GFP_KERNEL);
251 if (!hc_name) {
252 pr_err("Cannot allocate memory for controller slot name\n");
253 kfree(hc_name);
254 return -ENOMEM;
255 }
256
257 if (c->name)
258 strncpy(hc_name, c->name, HSMMC_NAME_LEN);
259 else
260 snprintf(hc_name, (HSMMC_NAME_LEN + 1), "mmc%islot%i",
261 c->mmc, 1);
262 mmc->slots[0].name = hc_name;
263 mmc->nr_slots = 1;
264 mmc->slots[0].caps = c->caps;
Eliad Peller6fdc75d2011-11-22 16:02:18 +0200265 mmc->slots[0].pm_caps = c->pm_caps;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530266 mmc->slots[0].internal_clock = !c->ext_clock;
Daniel Mackd418ed82012-02-19 13:20:33 +0100267 mmc->max_freq = c->max_freq;
Tony Lindgrenb30e3212013-05-30 12:53:06 -0700268 mmc->reg_offset = 0;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530269 mmc->get_context_loss_count = hsmmc_get_context_loss;
270
271 mmc->slots[0].switch_pin = c->gpio_cd;
272 mmc->slots[0].gpio_wp = c->gpio_wp;
273
274 mmc->slots[0].remux = c->remux;
275 mmc->slots[0].init_card = c->init_card;
276
277 if (c->cover_only)
278 mmc->slots[0].cover = 1;
279
280 if (c->nonremovable)
281 mmc->slots[0].nonremovable = 1;
282
283 if (c->power_saving)
284 mmc->slots[0].power_saving = 1;
285
286 if (c->no_off)
287 mmc->slots[0].no_off = 1;
288
Balaji T Kb1c1df72011-05-30 19:55:34 +0530289 if (c->no_off_init)
290 mmc->slots[0].no_regulator_off_init = c->no_off_init;
291
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530292 if (c->vcc_aux_disable_is_sleep)
293 mmc->slots[0].vcc_aux_disable_is_sleep = 1;
294
295 /*
296 * NOTE: MMC slots should have a Vcc regulator set up.
297 * This may be from a TWL4030-family chip, another
298 * controllable regulator, or a fixed supply.
299 *
300 * temporary HACK: ocr_mask instead of fixed supply
301 */
Kevin Hilman68a88b92012-04-30 16:37:10 -0700302 if (soc_is_am35xx())
Abhilash K Ve89715a2011-12-09 12:27:36 -0800303 mmc->slots[0].ocr_mask = MMC_VDD_165_195 |
304 MMC_VDD_26_27 |
305 MMC_VDD_27_28 |
306 MMC_VDD_29_30 |
307 MMC_VDD_30_31 |
308 MMC_VDD_31_32;
309 else
310 mmc->slots[0].ocr_mask = c->ocr_mask;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530311
Kevin Hilman68a88b92012-04-30 16:37:10 -0700312 if (!soc_is_am35xx())
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530313 mmc->slots[0].features |= HSMMC_HAS_PBIAS;
314
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530315 switch (c->mmc) {
316 case 1:
317 if (mmc->slots[0].features & HSMMC_HAS_PBIAS) {
318 /* on-chip level shifting via PBIAS0/PBIAS1 */
Tony Lindgrenb30e3212013-05-30 12:53:06 -0700319 mmc->slots[0].before_set_reg =
320 omap_hsmmc1_before_set_reg;
321 mmc->slots[0].after_set_reg =
322 omap_hsmmc1_after_set_reg;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530323 }
324
Kevin Hilman68a88b92012-04-30 16:37:10 -0700325 if (soc_is_am35xx())
Igor Grinberge62245b2011-11-29 11:37:48 +0200326 mmc->slots[0].set_power = nop_mmc_set_power;
327
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530328 /* OMAP3630 HSMMC1 supports only 4-bit */
329 if (cpu_is_omap3630() &&
330 (c->caps & MMC_CAP_8_BIT_DATA)) {
331 c->caps &= ~MMC_CAP_8_BIT_DATA;
332 c->caps |= MMC_CAP_4_BIT_DATA;
333 mmc->slots[0].caps = c->caps;
334 }
335 break;
336 case 2:
Kevin Hilman68a88b92012-04-30 16:37:10 -0700337 if (soc_is_am35xx())
Igor Grinberge62245b2011-11-29 11:37:48 +0200338 mmc->slots[0].set_power = am35x_hsmmc2_set_power;
339
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530340 if (c->ext_clock)
341 c->transceiver = 1;
342 if (c->transceiver && (c->caps & MMC_CAP_8_BIT_DATA)) {
343 c->caps &= ~MMC_CAP_8_BIT_DATA;
344 c->caps |= MMC_CAP_4_BIT_DATA;
345 }
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530346 if (mmc->slots[0].features & HSMMC_HAS_PBIAS) {
347 /* off-chip level shifting, or none */
Grazvydas Ignotasffa1e4e2011-12-18 02:35:47 +0200348 mmc->slots[0].before_set_reg = hsmmc2_before_set_reg;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530349 mmc->slots[0].after_set_reg = NULL;
350 }
351 break;
Grazvydas Ignotasffa1e4e2011-12-18 02:35:47 +0200352 case 3:
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530353 case 4:
354 case 5:
355 mmc->slots[0].before_set_reg = NULL;
356 mmc->slots[0].after_set_reg = NULL;
357 break;
358 default:
359 pr_err("MMC%d configuration not supported!\n", c->mmc);
360 kfree(hc_name);
361 return -ENODEV;
362 }
363 return 0;
364}
365
Tony Lindgren97899e52012-02-20 09:43:28 -0800366static int omap_hsmmc_done;
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800367
368void omap_hsmmc_late_init(struct omap2_hsmmc_info *c)
369{
370 struct platform_device *pdev;
371 struct omap_mmc_platform_data *mmc_pdata;
372 int res;
373
374 if (omap_hsmmc_done != 1)
375 return;
376
377 omap_hsmmc_done++;
378
379 for (; c->mmc; c++) {
380 if (!c->deferred)
381 continue;
382
383 pdev = c->pdev;
384 if (!pdev)
385 continue;
386
387 mmc_pdata = pdev->dev.platform_data;
388 if (!mmc_pdata)
389 continue;
390
391 mmc_pdata->slots[0].switch_pin = c->gpio_cd;
392 mmc_pdata->slots[0].gpio_wp = c->gpio_wp;
393
394 res = omap_device_register(pdev);
395 if (res)
396 pr_err("Could not late init MMC %s\n",
397 c->name);
398 }
399}
400
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530401#define MAX_OMAP_MMC_HWMOD_NAME_LEN 16
402
Tony Lindgren60285052012-03-07 18:54:24 -0800403static void __init omap_hsmmc_init_one(struct omap2_hsmmc_info *hsmmcinfo,
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800404 int ctrl_nr)
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530405{
406 struct omap_hwmod *oh;
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800407 struct omap_hwmod *ohs[1];
408 struct omap_device *od;
Kevin Hilman3528c582011-07-21 13:48:45 -0700409 struct platform_device *pdev;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530410 char oh_name[MAX_OMAP_MMC_HWMOD_NAME_LEN];
411 struct omap_mmc_platform_data *mmc_data;
412 struct omap_mmc_dev_attr *mmc_dev_attr;
413 char *name;
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800414 int res;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530415
416 mmc_data = kzalloc(sizeof(struct omap_mmc_platform_data), GFP_KERNEL);
417 if (!mmc_data) {
418 pr_err("Cannot allocate memory for mmc device!\n");
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800419 return;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530420 }
421
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800422 res = omap_hsmmc_pdata_init(hsmmcinfo, mmc_data);
423 if (res < 0)
424 goto free_mmc;
425
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530426 omap_hsmmc_mux(mmc_data, (ctrl_nr - 1));
427
Kishore Kadiyala0005ae72011-02-28 20:48:05 +0530428 name = "omap_hsmmc";
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800429 res = snprintf(oh_name, MAX_OMAP_MMC_HWMOD_NAME_LEN,
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530430 "mmc%d", ctrl_nr);
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800431 WARN(res >= MAX_OMAP_MMC_HWMOD_NAME_LEN,
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530432 "String buffer overflow in MMC%d device setup\n", ctrl_nr);
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800433
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530434 oh = omap_hwmod_lookup(oh_name);
435 if (!oh) {
436 pr_err("Could not look up %s\n", oh_name);
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800437 goto free_name;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530438 }
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800439 ohs[0] = oh;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530440 if (oh->dev_attr != NULL) {
441 mmc_dev_attr = oh->dev_attr;
442 mmc_data->controller_flags = mmc_dev_attr->flags;
Grazvydas Ignotas26c547f2012-03-16 14:49:54 +0200443 /*
444 * erratum 2.1.1.128 doesn't apply if board has
445 * a transceiver is attached
446 */
447 if (hsmmcinfo->transceiver)
448 mmc_data->controller_flags &=
449 ~OMAP_HSMMC_BROKEN_MULTIBLOCK_READ;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530450 }
451
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800452 pdev = platform_device_alloc(name, ctrl_nr - 1);
453 if (!pdev) {
454 pr_err("Could not allocate pdev for %s\n", name);
455 goto free_name;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530456 }
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800457 dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530458
Paul Walmsleyc1d1cd52013-01-26 00:48:53 -0700459 od = omap_device_alloc(pdev, ohs, 1);
Wei Yongjun64de3a02012-09-21 14:30:50 +0800460 if (IS_ERR(od)) {
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800461 pr_err("Could not allocate od for %s\n", name);
462 goto put_pdev;
463 }
464
465 res = platform_device_add_data(pdev, mmc_data,
466 sizeof(struct omap_mmc_platform_data));
467 if (res) {
468 pr_err("Could not add pdata for %s\n", name);
469 goto put_pdev;
470 }
471
472 hsmmcinfo->pdev = pdev;
473
474 if (hsmmcinfo->deferred)
475 goto free_mmc;
476
477 res = omap_device_register(pdev);
478 if (res) {
479 pr_err("Could not register od for %s\n", name);
480 goto free_od;
481 }
482
483 goto free_mmc;
484
485free_od:
486 omap_device_delete(od);
487
488put_pdev:
489 platform_device_put(pdev);
490
491free_name:
492 kfree(mmc_data->slots[0].name);
493
494free_mmc:
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530495 kfree(mmc_data);
496}
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800497
Tony Lindgrend1589f02012-02-20 09:43:30 -0800498void __init omap_hsmmc_init(struct omap2_hsmmc_info *controllers)
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800499{
Tony Lindgren97899e52012-02-20 09:43:28 -0800500 if (omap_hsmmc_done)
501 return;
502
503 omap_hsmmc_done = 1;
504
Tony Lindgrenb30e3212013-05-30 12:53:06 -0700505 if (cpu_is_omap2430()) {
506 control_pbias_offset = OMAP243X_CONTROL_PBIAS_LITE;
507 control_devconf1_offset = OMAP243X_CONTROL_DEVCONF1;
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800508 } else {
Tony Lindgrenb30e3212013-05-30 12:53:06 -0700509 control_pbias_offset = OMAP343X_CONTROL_PBIAS_LITE;
510 control_devconf1_offset = OMAP343X_CONTROL_DEVCONF1;
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800511 }
512
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530513 for (; controllers->mmc; controllers++)
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800514 omap_hsmmc_init_one(controllers, controllers->mmc);
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800515
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800516}
517
518#endif