blob: 857f7daa3286b234956bd1767e3738cc6d44a964 [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>
Tony Lindgren90c62bf2008-12-10 17:37:17 -080016#include <mach/hardware.h>
Tony Lindgrence491cf2009-10-20 09:40:47 -070017#include <plat/mmc.h>
Adrian Huntere3df0fb2010-02-15 10:03:34 -080018#include <plat/omap-pm.h>
Kishore Kadiyalad8d0a612011-02-28 20:48:03 +053019#include <plat/mux.h>
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +053020#include <plat/omap_device.h>
Tony Lindgren90c62bf2008-12-10 17:37:17 -080021
Kishore Kadiyalad8d0a612011-02-28 20:48:03 +053022#include "mux.h"
Adrian Hunterd02a900b2010-02-15 10:03:34 -080023#include "hsmmc.h"
Paul Walmsley4814ced2010-10-08 11:40:20 -060024#include "control.h"
Tony Lindgren90c62bf2008-12-10 17:37:17 -080025
Adrian Hunterdb0fefc2010-02-15 10:03:34 -080026#if defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
Tony Lindgren90c62bf2008-12-10 17:37:17 -080027
Tony Lindgren90c62bf2008-12-10 17:37:17 -080028static u16 control_pbias_offset;
29static u16 control_devconf1_offset;
kishore kadiyalac83c8e62010-05-15 18:21:25 +000030static u16 control_mmc1;
Tony Lindgren90c62bf2008-12-10 17:37:17 -080031
32#define HSMMC_NAME_LEN 9
33
Denis Karpov1887bde2009-09-22 16:44:40 -070034#if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM)
35
Adrian Hunter68ff0422010-02-15 10:03:34 -080036static int hsmmc_get_context_loss(struct device *dev)
Denis Karpov1887bde2009-09-22 16:44:40 -070037{
Adrian Huntere3df0fb2010-02-15 10:03:34 -080038 return omap_pm_get_dev_context_loss_count(dev);
Denis Karpov1887bde2009-09-22 16:44:40 -070039}
40
41#else
Adrian Hunter68ff0422010-02-15 10:03:34 -080042#define hsmmc_get_context_loss NULL
Denis Karpov1887bde2009-09-22 16:44:40 -070043#endif
44
kishore kadiyalac83c8e62010-05-15 18:21:25 +000045static void omap_hsmmc1_before_set_reg(struct device *dev, int slot,
Adrian Hunterdb0fefc2010-02-15 10:03:34 -080046 int power_on, int vdd)
Tony Lindgren90c62bf2008-12-10 17:37:17 -080047{
Madhu555d5032009-11-22 10:11:08 -080048 u32 reg, prog_io;
Tony Lindgren90c62bf2008-12-10 17:37:17 -080049 struct omap_mmc_platform_data *mmc = dev->platform_data;
50
Adrian Hunterce6f0012010-02-15 10:03:34 -080051 if (mmc->slots[0].remux)
52 mmc->slots[0].remux(dev, slot, power_on);
53
David Brownell0329c372009-03-23 18:23:47 -070054 /*
55 * Assume we power both OMAP VMMC1 (for CMD, CLK, DAT0..3) and the
David Brownellb583f262009-05-28 14:04:03 -070056 * card with Vcc regulator (from twl4030 or whatever). OMAP has both
David Brownell0329c372009-03-23 18:23:47 -070057 * 1.8V and 3.0V modes, controlled by the PBIAS register.
58 *
59 * In 8-bit modes, OMAP VMMC1A (for DAT4..7) needs a supply, which
60 * is most naturally TWL VSIM; those pins also use PBIAS.
David Brownellb583f262009-05-28 14:04:03 -070061 *
62 * FIXME handle VMMC1A as needed ...
David Brownell0329c372009-03-23 18:23:47 -070063 */
Tony Lindgren90c62bf2008-12-10 17:37:17 -080064 if (power_on) {
65 if (cpu_is_omap2430()) {
66 reg = omap_ctrl_readl(OMAP243X_CONTROL_DEVCONF1);
67 if ((1 << vdd) >= MMC_VDD_30_31)
68 reg |= OMAP243X_MMC1_ACTIVE_OVERWRITE;
69 else
70 reg &= ~OMAP243X_MMC1_ACTIVE_OVERWRITE;
71 omap_ctrl_writel(reg, OMAP243X_CONTROL_DEVCONF1);
72 }
73
74 if (mmc->slots[0].internal_clock) {
75 reg = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
76 reg |= OMAP2_MMCSDIO1ADPCLKISEL;
77 omap_ctrl_writel(reg, OMAP2_CONTROL_DEVCONF0);
78 }
79
80 reg = omap_ctrl_readl(control_pbias_offset);
Madhu555d5032009-11-22 10:11:08 -080081 if (cpu_is_omap3630()) {
82 /* Set MMC I/O to 52Mhz */
83 prog_io = omap_ctrl_readl(OMAP343X_CONTROL_PROG_IO1);
84 prog_io |= OMAP3630_PRG_SDMMC1_SPEEDCTRL;
85 omap_ctrl_writel(prog_io, OMAP343X_CONTROL_PROG_IO1);
86 } else {
87 reg |= OMAP2_PBIASSPEEDCTRL0;
88 }
Tony Lindgren90c62bf2008-12-10 17:37:17 -080089 reg &= ~OMAP2_PBIASLITEPWRDNZ0;
90 omap_ctrl_writel(reg, control_pbias_offset);
Adrian Hunterdb0fefc2010-02-15 10:03:34 -080091 } else {
92 reg = omap_ctrl_readl(control_pbias_offset);
93 reg &= ~OMAP2_PBIASLITEPWRDNZ0;
94 omap_ctrl_writel(reg, control_pbias_offset);
95 }
96}
Tony Lindgren90c62bf2008-12-10 17:37:17 -080097
kishore kadiyalac83c8e62010-05-15 18:21:25 +000098static void omap_hsmmc1_after_set_reg(struct device *dev, int slot,
Adrian Hunterdb0fefc2010-02-15 10:03:34 -080099 int power_on, int vdd)
100{
101 u32 reg;
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800102
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800103 /* 100ms delay required for PBIAS configuration */
104 msleep(100);
105
106 if (power_on) {
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800107 reg = omap_ctrl_readl(control_pbias_offset);
108 reg |= (OMAP2_PBIASLITEPWRDNZ0 | OMAP2_PBIASSPEEDCTRL0);
109 if ((1 << vdd) <= MMC_VDD_165_195)
110 reg &= ~OMAP2_PBIASLITEVMODE0;
111 else
112 reg |= OMAP2_PBIASLITEVMODE0;
113 omap_ctrl_writel(reg, control_pbias_offset);
114 } else {
115 reg = omap_ctrl_readl(control_pbias_offset);
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800116 reg |= (OMAP2_PBIASSPEEDCTRL0 | OMAP2_PBIASLITEPWRDNZ0 |
117 OMAP2_PBIASLITEVMODE0);
118 omap_ctrl_writel(reg, control_pbias_offset);
119 }
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800120}
121
kishore kadiyalac83c8e62010-05-15 18:21:25 +0000122static void omap4_hsmmc1_before_set_reg(struct device *dev, int slot,
123 int power_on, int vdd)
124{
125 u32 reg;
126
127 /*
128 * Assume we power both OMAP VMMC1 (for CMD, CLK, DAT0..3) and the
129 * card with Vcc regulator (from twl4030 or whatever). OMAP has both
130 * 1.8V and 3.0V modes, controlled by the PBIAS register.
131 *
132 * In 8-bit modes, OMAP VMMC1A (for DAT4..7) needs a supply, which
133 * is most naturally TWL VSIM; those pins also use PBIAS.
134 *
135 * FIXME handle VMMC1A as needed ...
136 */
Santosh Shilimkardcf5ef32010-09-27 14:02:58 -0600137 reg = omap4_ctrl_pad_readl(control_pbias_offset);
138 reg &= ~(OMAP4_MMC1_PBIASLITE_PWRDNZ_MASK |
139 OMAP4_MMC1_PWRDNZ_MASK |
140 OMAP4_USBC1_ICUSB_PWRDNZ_MASK);
141 omap4_ctrl_pad_writel(reg, control_pbias_offset);
kishore kadiyalac83c8e62010-05-15 18:21:25 +0000142}
143
144static void omap4_hsmmc1_after_set_reg(struct device *dev, int slot,
145 int power_on, int vdd)
146{
147 u32 reg;
148
149 if (power_on) {
Santosh Shilimkardcf5ef32010-09-27 14:02:58 -0600150 reg = omap4_ctrl_pad_readl(control_pbias_offset);
151 reg |= OMAP4_MMC1_PBIASLITE_PWRDNZ_MASK;
kishore kadiyalac83c8e62010-05-15 18:21:25 +0000152 if ((1 << vdd) <= MMC_VDD_165_195)
Santosh Shilimkardcf5ef32010-09-27 14:02:58 -0600153 reg &= ~OMAP4_MMC1_PBIASLITE_VMODE_MASK;
kishore kadiyalac83c8e62010-05-15 18:21:25 +0000154 else
Santosh Shilimkardcf5ef32010-09-27 14:02:58 -0600155 reg |= OMAP4_MMC1_PBIASLITE_VMODE_MASK;
156 reg |= (OMAP4_MMC1_PBIASLITE_PWRDNZ_MASK |
157 OMAP4_MMC1_PWRDNZ_MASK |
158 OMAP4_USBC1_ICUSB_PWRDNZ_MASK);
159 omap4_ctrl_pad_writel(reg, control_pbias_offset);
kishore kadiyalac83c8e62010-05-15 18:21:25 +0000160 /* 4 microsec delay for comparator to generate an error*/
161 udelay(4);
Santosh Shilimkardcf5ef32010-09-27 14:02:58 -0600162 reg = omap4_ctrl_pad_readl(control_pbias_offset);
163 if (reg & OMAP4_MMC1_PBIASLITE_VMODE_ERROR_MASK) {
kishore kadiyalac83c8e62010-05-15 18:21:25 +0000164 pr_err("Pbias Voltage is not same as LDO\n");
165 /* Caution : On VMODE_ERROR Power Down MMC IO */
Santosh Shilimkardcf5ef32010-09-27 14:02:58 -0600166 reg &= ~(OMAP4_MMC1_PWRDNZ_MASK |
167 OMAP4_USBC1_ICUSB_PWRDNZ_MASK);
168 omap4_ctrl_pad_writel(reg, control_pbias_offset);
kishore kadiyalac83c8e62010-05-15 18:21:25 +0000169 }
170 } else {
Santosh Shilimkardcf5ef32010-09-27 14:02:58 -0600171 reg = omap4_ctrl_pad_readl(control_pbias_offset);
172 reg |= (OMAP4_MMC1_PBIASLITE_PWRDNZ_MASK |
173 OMAP4_MMC1_PWRDNZ_MASK |
174 OMAP4_MMC1_PBIASLITE_VMODE_MASK |
175 OMAP4_USBC1_ICUSB_PWRDNZ_MASK);
176 omap4_ctrl_pad_writel(reg, control_pbias_offset);
kishore kadiyalac83c8e62010-05-15 18:21:25 +0000177 }
178}
179
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800180static void hsmmc23_before_set_reg(struct device *dev, int slot,
181 int power_on, int vdd)
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800182{
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800183 struct omap_mmc_platform_data *mmc = dev->platform_data;
Grazvydas Ignotas762ad3a42009-06-23 13:30:22 +0300184
Adrian Hunterce6f0012010-02-15 10:03:34 -0800185 if (mmc->slots[0].remux)
186 mmc->slots[0].remux(dev, slot, power_on);
187
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800188 if (power_on) {
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800189 /* Only MMC2 supports a CLKIN */
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800190 if (mmc->slots[0].internal_clock) {
191 u32 reg;
192
193 reg = omap_ctrl_readl(control_devconf1_offset);
194 reg |= OMAP2_MMCSDIO2ADPCLKISEL;
195 omap_ctrl_writel(reg, control_devconf1_offset);
196 }
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800197 }
Adrian Hunter9b7c18e2009-09-22 16:44:50 -0700198}
199
stanley.miao03e7e172010-05-13 12:39:31 +0000200static int nop_mmc_set_power(struct device *dev, int slot, int power_on,
201 int vdd)
202{
203 return 0;
204}
205
Kishore Kadiyalad8d0a612011-02-28 20:48:03 +0530206static inline void omap_hsmmc_mux(struct omap_mmc_platform_data *mmc_controller,
207 int controller_nr)
208{
209 if ((mmc_controller->slots[0].switch_pin > 0) && \
210 (mmc_controller->slots[0].switch_pin < OMAP_MAX_GPIO_LINES))
211 omap_mux_init_gpio(mmc_controller->slots[0].switch_pin,
212 OMAP_PIN_INPUT_PULLUP);
213 if ((mmc_controller->slots[0].gpio_wp > 0) && \
214 (mmc_controller->slots[0].gpio_wp < OMAP_MAX_GPIO_LINES))
215 omap_mux_init_gpio(mmc_controller->slots[0].gpio_wp,
216 OMAP_PIN_INPUT_PULLUP);
217 if (cpu_is_omap34xx()) {
218 if (controller_nr == 0) {
219 omap_mux_init_signal("sdmmc1_clk",
220 OMAP_PIN_INPUT_PULLUP);
221 omap_mux_init_signal("sdmmc1_cmd",
222 OMAP_PIN_INPUT_PULLUP);
223 omap_mux_init_signal("sdmmc1_dat0",
224 OMAP_PIN_INPUT_PULLUP);
225 if (mmc_controller->slots[0].caps &
226 (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)) {
227 omap_mux_init_signal("sdmmc1_dat1",
228 OMAP_PIN_INPUT_PULLUP);
229 omap_mux_init_signal("sdmmc1_dat2",
230 OMAP_PIN_INPUT_PULLUP);
231 omap_mux_init_signal("sdmmc1_dat3",
232 OMAP_PIN_INPUT_PULLUP);
233 }
234 if (mmc_controller->slots[0].caps &
235 MMC_CAP_8_BIT_DATA) {
236 omap_mux_init_signal("sdmmc1_dat4",
237 OMAP_PIN_INPUT_PULLUP);
238 omap_mux_init_signal("sdmmc1_dat5",
239 OMAP_PIN_INPUT_PULLUP);
240 omap_mux_init_signal("sdmmc1_dat6",
241 OMAP_PIN_INPUT_PULLUP);
242 omap_mux_init_signal("sdmmc1_dat7",
243 OMAP_PIN_INPUT_PULLUP);
244 }
245 }
246 if (controller_nr == 1) {
247 /* MMC2 */
248 omap_mux_init_signal("sdmmc2_clk",
249 OMAP_PIN_INPUT_PULLUP);
250 omap_mux_init_signal("sdmmc2_cmd",
251 OMAP_PIN_INPUT_PULLUP);
252 omap_mux_init_signal("sdmmc2_dat0",
253 OMAP_PIN_INPUT_PULLUP);
254
255 /*
256 * For 8 wire configurations, Lines DAT4, 5, 6 and 7
257 * need to be muxed in the board-*.c files
258 */
259 if (mmc_controller->slots[0].caps &
260 (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)) {
261 omap_mux_init_signal("sdmmc2_dat1",
262 OMAP_PIN_INPUT_PULLUP);
263 omap_mux_init_signal("sdmmc2_dat2",
264 OMAP_PIN_INPUT_PULLUP);
265 omap_mux_init_signal("sdmmc2_dat3",
266 OMAP_PIN_INPUT_PULLUP);
267 }
268 if (mmc_controller->slots[0].caps &
269 MMC_CAP_8_BIT_DATA) {
270 omap_mux_init_signal("sdmmc2_dat4.sdmmc2_dat4",
271 OMAP_PIN_INPUT_PULLUP);
272 omap_mux_init_signal("sdmmc2_dat5.sdmmc2_dat5",
273 OMAP_PIN_INPUT_PULLUP);
274 omap_mux_init_signal("sdmmc2_dat6.sdmmc2_dat6",
275 OMAP_PIN_INPUT_PULLUP);
276 omap_mux_init_signal("sdmmc2_dat7.sdmmc2_dat7",
277 OMAP_PIN_INPUT_PULLUP);
278 }
279 }
280
281 /*
282 * For MMC3 the pins need to be muxed in the board-*.c files
283 */
284 }
285}
286
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530287static int __init omap_hsmmc_pdata_init(struct omap2_hsmmc_info *c,
288 struct omap_mmc_platform_data *mmc)
289{
290 char *hc_name;
291
292 hc_name = kzalloc(sizeof(char) * (HSMMC_NAME_LEN + 1), GFP_KERNEL);
293 if (!hc_name) {
294 pr_err("Cannot allocate memory for controller slot name\n");
295 kfree(hc_name);
296 return -ENOMEM;
297 }
298
299 if (c->name)
300 strncpy(hc_name, c->name, HSMMC_NAME_LEN);
301 else
302 snprintf(hc_name, (HSMMC_NAME_LEN + 1), "mmc%islot%i",
303 c->mmc, 1);
304 mmc->slots[0].name = hc_name;
305 mmc->nr_slots = 1;
306 mmc->slots[0].caps = c->caps;
307 mmc->slots[0].internal_clock = !c->ext_clock;
308 mmc->dma_mask = 0xffffffff;
309 if (cpu_is_omap44xx())
310 mmc->reg_offset = OMAP4_MMC_REG_OFFSET;
311 else
312 mmc->reg_offset = 0;
313
314 mmc->get_context_loss_count = hsmmc_get_context_loss;
315
316 mmc->slots[0].switch_pin = c->gpio_cd;
317 mmc->slots[0].gpio_wp = c->gpio_wp;
318
319 mmc->slots[0].remux = c->remux;
320 mmc->slots[0].init_card = c->init_card;
321
322 if (c->cover_only)
323 mmc->slots[0].cover = 1;
324
325 if (c->nonremovable)
326 mmc->slots[0].nonremovable = 1;
327
328 if (c->power_saving)
329 mmc->slots[0].power_saving = 1;
330
331 if (c->no_off)
332 mmc->slots[0].no_off = 1;
333
Balaji T Kb1c1df72011-05-30 19:55:34 +0530334 if (c->no_off_init)
335 mmc->slots[0].no_regulator_off_init = c->no_off_init;
336
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530337 if (c->vcc_aux_disable_is_sleep)
338 mmc->slots[0].vcc_aux_disable_is_sleep = 1;
339
340 /*
341 * NOTE: MMC slots should have a Vcc regulator set up.
342 * This may be from a TWL4030-family chip, another
343 * controllable regulator, or a fixed supply.
344 *
345 * temporary HACK: ocr_mask instead of fixed supply
346 */
347 mmc->slots[0].ocr_mask = c->ocr_mask;
348
349 if (cpu_is_omap3517() || cpu_is_omap3505())
350 mmc->slots[0].set_power = nop_mmc_set_power;
351 else
352 mmc->slots[0].features |= HSMMC_HAS_PBIAS;
353
354 if (cpu_is_omap44xx() && (omap_rev() > OMAP4430_REV_ES1_0))
355 mmc->slots[0].features |= HSMMC_HAS_UPDATED_RESET;
356
357 switch (c->mmc) {
358 case 1:
359 if (mmc->slots[0].features & HSMMC_HAS_PBIAS) {
360 /* on-chip level shifting via PBIAS0/PBIAS1 */
361 if (cpu_is_omap44xx()) {
362 mmc->slots[0].before_set_reg =
363 omap4_hsmmc1_before_set_reg;
364 mmc->slots[0].after_set_reg =
365 omap4_hsmmc1_after_set_reg;
366 } else {
367 mmc->slots[0].before_set_reg =
368 omap_hsmmc1_before_set_reg;
369 mmc->slots[0].after_set_reg =
370 omap_hsmmc1_after_set_reg;
371 }
372 }
373
374 /* OMAP3630 HSMMC1 supports only 4-bit */
375 if (cpu_is_omap3630() &&
376 (c->caps & MMC_CAP_8_BIT_DATA)) {
377 c->caps &= ~MMC_CAP_8_BIT_DATA;
378 c->caps |= MMC_CAP_4_BIT_DATA;
379 mmc->slots[0].caps = c->caps;
380 }
381 break;
382 case 2:
383 if (c->ext_clock)
384 c->transceiver = 1;
385 if (c->transceiver && (c->caps & MMC_CAP_8_BIT_DATA)) {
386 c->caps &= ~MMC_CAP_8_BIT_DATA;
387 c->caps |= MMC_CAP_4_BIT_DATA;
388 }
389 /* FALLTHROUGH */
390 case 3:
391 if (mmc->slots[0].features & HSMMC_HAS_PBIAS) {
392 /* off-chip level shifting, or none */
393 mmc->slots[0].before_set_reg = hsmmc23_before_set_reg;
394 mmc->slots[0].after_set_reg = NULL;
395 }
396 break;
397 case 4:
398 case 5:
399 mmc->slots[0].before_set_reg = NULL;
400 mmc->slots[0].after_set_reg = NULL;
401 break;
402 default:
403 pr_err("MMC%d configuration not supported!\n", c->mmc);
404 kfree(hc_name);
405 return -ENODEV;
406 }
407 return 0;
408}
409
410static struct omap_device_pm_latency omap_hsmmc_latency[] = {
411 [0] = {
412 .deactivate_func = omap_device_idle_hwmods,
413 .activate_func = omap_device_enable_hwmods,
414 .flags = OMAP_DEVICE_LATENCY_AUTO_ADJUST,
415 },
416 /*
417 * XXX There should also be an entry here to power off/on the
418 * MMC regulators/PBIAS cells, etc.
419 */
420};
421
422#define MAX_OMAP_MMC_HWMOD_NAME_LEN 16
423
424void __init omap_init_hsmmc(struct omap2_hsmmc_info *hsmmcinfo, int ctrl_nr)
425{
426 struct omap_hwmod *oh;
427 struct omap_device *od;
428 struct omap_device_pm_latency *ohl;
429 char oh_name[MAX_OMAP_MMC_HWMOD_NAME_LEN];
430 struct omap_mmc_platform_data *mmc_data;
431 struct omap_mmc_dev_attr *mmc_dev_attr;
432 char *name;
433 int l;
434 int ohl_cnt = 0;
435
436 mmc_data = kzalloc(sizeof(struct omap_mmc_platform_data), GFP_KERNEL);
437 if (!mmc_data) {
438 pr_err("Cannot allocate memory for mmc device!\n");
439 goto done;
440 }
441
442 if (omap_hsmmc_pdata_init(hsmmcinfo, mmc_data) < 0) {
443 pr_err("%s fails!\n", __func__);
444 goto done;
445 }
446 omap_hsmmc_mux(mmc_data, (ctrl_nr - 1));
447
Kishore Kadiyala0005ae72011-02-28 20:48:05 +0530448 name = "omap_hsmmc";
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530449 ohl = omap_hsmmc_latency;
450 ohl_cnt = ARRAY_SIZE(omap_hsmmc_latency);
451
452 l = snprintf(oh_name, MAX_OMAP_MMC_HWMOD_NAME_LEN,
453 "mmc%d", ctrl_nr);
454 WARN(l >= MAX_OMAP_MMC_HWMOD_NAME_LEN,
455 "String buffer overflow in MMC%d device setup\n", ctrl_nr);
456 oh = omap_hwmod_lookup(oh_name);
457 if (!oh) {
458 pr_err("Could not look up %s\n", oh_name);
459 kfree(mmc_data->slots[0].name);
460 goto done;
461 }
462
463 if (oh->dev_attr != NULL) {
464 mmc_dev_attr = oh->dev_attr;
465 mmc_data->controller_flags = mmc_dev_attr->flags;
466 }
467
468 od = omap_device_build(name, ctrl_nr - 1, oh, mmc_data,
469 sizeof(struct omap_mmc_platform_data), ohl, ohl_cnt, false);
470 if (IS_ERR(od)) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300471 WARN(1, "Can't build omap_device for %s:%s.\n", name, oh->name);
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530472 kfree(mmc_data->slots[0].name);
473 goto done;
474 }
475 /*
476 * return device handle to board setup code
477 * required to populate for regulator framework structure
478 */
479 hsmmcinfo->dev = &od->pdev.dev;
480
481done:
482 kfree(mmc_data);
483}
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800484
Adrian Hunter68ff0422010-02-15 10:03:34 -0800485void __init omap2_hsmmc_init(struct omap2_hsmmc_info *controllers)
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800486{
kishore kadiyalac83c8e62010-05-15 18:21:25 +0000487 u32 reg;
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800488
kishore kadiyalac83c8e62010-05-15 18:21:25 +0000489 if (!cpu_is_omap44xx()) {
490 if (cpu_is_omap2430()) {
491 control_pbias_offset = OMAP243X_CONTROL_PBIAS_LITE;
492 control_devconf1_offset = OMAP243X_CONTROL_DEVCONF1;
493 } else {
494 control_pbias_offset = OMAP343X_CONTROL_PBIAS_LITE;
495 control_devconf1_offset = OMAP343X_CONTROL_DEVCONF1;
496 }
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800497 } else {
Santosh Shilimkardcf5ef32010-09-27 14:02:58 -0600498 control_pbias_offset =
499 OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_PBIASLITE;
500 control_mmc1 = OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_MMC1;
501 reg = omap4_ctrl_pad_readl(control_mmc1);
502 reg |= (OMAP4_SDMMC1_PUSTRENGTH_GRP0_MASK |
503 OMAP4_SDMMC1_PUSTRENGTH_GRP1_MASK);
504 reg &= ~(OMAP4_SDMMC1_PUSTRENGTH_GRP2_MASK |
505 OMAP4_SDMMC1_PUSTRENGTH_GRP3_MASK);
506 reg |= (OMAP4_USBC1_DR0_SPEEDCTRL_MASK|
507 OMAP4_SDMMC1_DR1_SPEEDCTRL_MASK |
508 OMAP4_SDMMC1_DR2_SPEEDCTRL_MASK);
509 omap4_ctrl_pad_writel(reg, control_mmc1);
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800510 }
511
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530512 for (; controllers->mmc; controllers++)
513 omap_init_hsmmc(controllers, controllers->mmc);
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800514
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800515}
516
517#endif