blob: e3406dce59beacb155777857aade449e60d79d37 [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 Lindgren90c62bf2008-12-10 17:37:17 -080017#include <mach/hardware.h>
Tony Lindgren4b254082012-08-30 15:37:24 -070018#include <linux/platform_data/gpio-omap.h>
19
Tony Lindgrene4c060d2012-10-05 13:25:59 -070020#include "soc.h"
Tony Lindgren25c7d492012-10-02 17:25:48 -070021#include "omap_device.h"
Tony Lindgren1d5aef42012-10-03 16:36:40 -070022#include "omap-pm.h"
Tony Lindgren90c62bf2008-12-10 17:37:17 -080023
Kishore Kadiyalad8d0a612011-02-28 20:48:03 +053024#include "mux.h"
Tony Lindgren68f39e72012-10-15 12:09:43 -070025#include "mmc.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;
kishore kadiyalac83c8e62010-05-15 18:21:25 +000033static u16 control_mmc1;
Tony Lindgren90c62bf2008-12-10 17:37:17 -080034
35#define HSMMC_NAME_LEN 9
36
Denis Karpov1887bde2009-09-22 16:44:40 -070037#if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM)
38
Adrian Hunter68ff0422010-02-15 10:03:34 -080039static int hsmmc_get_context_loss(struct device *dev)
Denis Karpov1887bde2009-09-22 16:44:40 -070040{
Adrian Huntere3df0fb2010-02-15 10:03:34 -080041 return omap_pm_get_dev_context_loss_count(dev);
Denis Karpov1887bde2009-09-22 16:44:40 -070042}
43
44#else
Adrian Hunter68ff0422010-02-15 10:03:34 -080045#define hsmmc_get_context_loss NULL
Denis Karpov1887bde2009-09-22 16:44:40 -070046#endif
47
kishore kadiyalac83c8e62010-05-15 18:21:25 +000048static void omap_hsmmc1_before_set_reg(struct device *dev, int slot,
Adrian Hunterdb0fefc2010-02-15 10:03:34 -080049 int power_on, int vdd)
Tony Lindgren90c62bf2008-12-10 17:37:17 -080050{
Madhu555d5032009-11-22 10:11:08 -080051 u32 reg, prog_io;
Tony Lindgren90c62bf2008-12-10 17:37:17 -080052 struct omap_mmc_platform_data *mmc = dev->platform_data;
53
Adrian Hunterce6f0012010-02-15 10:03:34 -080054 if (mmc->slots[0].remux)
55 mmc->slots[0].remux(dev, slot, power_on);
56
David Brownell0329c372009-03-23 18:23:47 -070057 /*
58 * Assume we power both OMAP VMMC1 (for CMD, CLK, DAT0..3) and the
David Brownellb583f262009-05-28 14:04:03 -070059 * card with Vcc regulator (from twl4030 or whatever). OMAP has both
David Brownell0329c372009-03-23 18:23:47 -070060 * 1.8V and 3.0V modes, controlled by the PBIAS register.
61 *
62 * In 8-bit modes, OMAP VMMC1A (for DAT4..7) needs a supply, which
63 * is most naturally TWL VSIM; those pins also use PBIAS.
David Brownellb583f262009-05-28 14:04:03 -070064 *
65 * FIXME handle VMMC1A as needed ...
David Brownell0329c372009-03-23 18:23:47 -070066 */
Tony Lindgren90c62bf2008-12-10 17:37:17 -080067 if (power_on) {
68 if (cpu_is_omap2430()) {
69 reg = omap_ctrl_readl(OMAP243X_CONTROL_DEVCONF1);
70 if ((1 << vdd) >= MMC_VDD_30_31)
71 reg |= OMAP243X_MMC1_ACTIVE_OVERWRITE;
72 else
73 reg &= ~OMAP243X_MMC1_ACTIVE_OVERWRITE;
74 omap_ctrl_writel(reg, OMAP243X_CONTROL_DEVCONF1);
75 }
76
77 if (mmc->slots[0].internal_clock) {
78 reg = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
79 reg |= OMAP2_MMCSDIO1ADPCLKISEL;
80 omap_ctrl_writel(reg, OMAP2_CONTROL_DEVCONF0);
81 }
82
83 reg = omap_ctrl_readl(control_pbias_offset);
Madhu555d5032009-11-22 10:11:08 -080084 if (cpu_is_omap3630()) {
85 /* Set MMC I/O to 52Mhz */
86 prog_io = omap_ctrl_readl(OMAP343X_CONTROL_PROG_IO1);
87 prog_io |= OMAP3630_PRG_SDMMC1_SPEEDCTRL;
88 omap_ctrl_writel(prog_io, OMAP343X_CONTROL_PROG_IO1);
89 } else {
90 reg |= OMAP2_PBIASSPEEDCTRL0;
91 }
Tony Lindgren90c62bf2008-12-10 17:37:17 -080092 reg &= ~OMAP2_PBIASLITEPWRDNZ0;
93 omap_ctrl_writel(reg, control_pbias_offset);
Adrian Hunterdb0fefc2010-02-15 10:03:34 -080094 } else {
95 reg = omap_ctrl_readl(control_pbias_offset);
96 reg &= ~OMAP2_PBIASLITEPWRDNZ0;
97 omap_ctrl_writel(reg, control_pbias_offset);
98 }
99}
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800100
kishore kadiyalac83c8e62010-05-15 18:21:25 +0000101static void omap_hsmmc1_after_set_reg(struct device *dev, int slot,
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800102 int power_on, int vdd)
103{
104 u32 reg;
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800105
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800106 /* 100ms delay required for PBIAS configuration */
107 msleep(100);
108
109 if (power_on) {
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800110 reg = omap_ctrl_readl(control_pbias_offset);
111 reg |= (OMAP2_PBIASLITEPWRDNZ0 | OMAP2_PBIASSPEEDCTRL0);
112 if ((1 << vdd) <= MMC_VDD_165_195)
113 reg &= ~OMAP2_PBIASLITEVMODE0;
114 else
115 reg |= OMAP2_PBIASLITEVMODE0;
116 omap_ctrl_writel(reg, control_pbias_offset);
117 } else {
118 reg = omap_ctrl_readl(control_pbias_offset);
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800119 reg |= (OMAP2_PBIASSPEEDCTRL0 | OMAP2_PBIASLITEPWRDNZ0 |
120 OMAP2_PBIASLITEVMODE0);
121 omap_ctrl_writel(reg, control_pbias_offset);
122 }
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800123}
124
kishore kadiyalac83c8e62010-05-15 18:21:25 +0000125static void omap4_hsmmc1_before_set_reg(struct device *dev, int slot,
126 int power_on, int vdd)
127{
128 u32 reg;
129
130 /*
131 * Assume we power both OMAP VMMC1 (for CMD, CLK, DAT0..3) and the
132 * card with Vcc regulator (from twl4030 or whatever). OMAP has both
133 * 1.8V and 3.0V modes, controlled by the PBIAS register.
kishore kadiyalac83c8e62010-05-15 18:21:25 +0000134 */
Santosh Shilimkardcf5ef32010-09-27 14:02:58 -0600135 reg = omap4_ctrl_pad_readl(control_pbias_offset);
136 reg &= ~(OMAP4_MMC1_PBIASLITE_PWRDNZ_MASK |
Balaji T Kff2beb12011-10-03 17:52:50 +0530137 OMAP4_MMC1_PWRDNZ_MASK |
138 OMAP4_MMC1_PBIASLITE_VMODE_MASK);
Santosh Shilimkardcf5ef32010-09-27 14:02:58 -0600139 omap4_ctrl_pad_writel(reg, control_pbias_offset);
kishore kadiyalac83c8e62010-05-15 18:21:25 +0000140}
141
142static void omap4_hsmmc1_after_set_reg(struct device *dev, int slot,
143 int power_on, int vdd)
144{
145 u32 reg;
Balaji T K1fcecf22011-06-01 16:45:22 +0530146 unsigned long timeout;
kishore kadiyalac83c8e62010-05-15 18:21:25 +0000147
148 if (power_on) {
Santosh Shilimkardcf5ef32010-09-27 14:02:58 -0600149 reg = omap4_ctrl_pad_readl(control_pbias_offset);
150 reg |= OMAP4_MMC1_PBIASLITE_PWRDNZ_MASK;
kishore kadiyalac83c8e62010-05-15 18:21:25 +0000151 if ((1 << vdd) <= MMC_VDD_165_195)
Santosh Shilimkardcf5ef32010-09-27 14:02:58 -0600152 reg &= ~OMAP4_MMC1_PBIASLITE_VMODE_MASK;
kishore kadiyalac83c8e62010-05-15 18:21:25 +0000153 else
Santosh Shilimkardcf5ef32010-09-27 14:02:58 -0600154 reg |= OMAP4_MMC1_PBIASLITE_VMODE_MASK;
155 reg |= (OMAP4_MMC1_PBIASLITE_PWRDNZ_MASK |
Bryan Buckley3696d302011-09-30 11:05:55 -0700156 OMAP4_MMC1_PWRDNZ_MASK);
Santosh Shilimkardcf5ef32010-09-27 14:02:58 -0600157 omap4_ctrl_pad_writel(reg, control_pbias_offset);
Balaji T K1fcecf22011-06-01 16:45:22 +0530158
159 timeout = jiffies + msecs_to_jiffies(5);
160 do {
161 reg = omap4_ctrl_pad_readl(control_pbias_offset);
162 if (!(reg & OMAP4_MMC1_PBIASLITE_VMODE_ERROR_MASK))
163 break;
164 usleep_range(100, 200);
165 } while (!time_after(jiffies, timeout));
166
Santosh Shilimkardcf5ef32010-09-27 14:02:58 -0600167 if (reg & OMAP4_MMC1_PBIASLITE_VMODE_ERROR_MASK) {
kishore kadiyalac83c8e62010-05-15 18:21:25 +0000168 pr_err("Pbias Voltage is not same as LDO\n");
169 /* Caution : On VMODE_ERROR Power Down MMC IO */
Bryan Buckley3696d302011-09-30 11:05:55 -0700170 reg &= ~(OMAP4_MMC1_PWRDNZ_MASK);
Santosh Shilimkardcf5ef32010-09-27 14:02:58 -0600171 omap4_ctrl_pad_writel(reg, control_pbias_offset);
kishore kadiyalac83c8e62010-05-15 18:21:25 +0000172 }
kishore kadiyalac83c8e62010-05-15 18:21:25 +0000173 }
174}
175
Igor Grinberge62245b2011-11-29 11:37:48 +0200176static void hsmmc2_select_input_clk_src(struct omap_mmc_platform_data *mmc)
177{
178 u32 reg;
179
Grazvydas Ignotasd82e5192012-01-12 16:26:45 +0200180 reg = omap_ctrl_readl(control_devconf1_offset);
181 if (mmc->slots[0].internal_clock)
Igor Grinberge62245b2011-11-29 11:37:48 +0200182 reg |= OMAP2_MMCSDIO2ADPCLKISEL;
Grazvydas Ignotasd82e5192012-01-12 16:26:45 +0200183 else
184 reg &= ~OMAP2_MMCSDIO2ADPCLKISEL;
185 omap_ctrl_writel(reg, control_devconf1_offset);
Igor Grinberge62245b2011-11-29 11:37:48 +0200186}
187
Grazvydas Ignotasffa1e4e2011-12-18 02:35:47 +0200188static void hsmmc2_before_set_reg(struct device *dev, int slot,
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800189 int power_on, int vdd)
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800190{
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800191 struct omap_mmc_platform_data *mmc = dev->platform_data;
Grazvydas Ignotas762ad3a42009-06-23 13:30:22 +0300192
Adrian Hunterce6f0012010-02-15 10:03:34 -0800193 if (mmc->slots[0].remux)
194 mmc->slots[0].remux(dev, slot, power_on);
195
Igor Grinberge62245b2011-11-29 11:37:48 +0200196 if (power_on)
197 hsmmc2_select_input_clk_src(mmc);
198}
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800199
Igor Grinberge62245b2011-11-29 11:37:48 +0200200static int am35x_hsmmc2_set_power(struct device *dev, int slot,
201 int power_on, int vdd)
202{
203 struct omap_mmc_platform_data *mmc = dev->platform_data;
204
205 if (power_on)
206 hsmmc2_select_input_clk_src(mmc);
207
208 return 0;
Adrian Hunter9b7c18e2009-09-22 16:44:50 -0700209}
210
stanley.miao03e7e172010-05-13 12:39:31 +0000211static int nop_mmc_set_power(struct device *dev, int slot, int power_on,
212 int vdd)
213{
214 return 0;
215}
216
Kishore Kadiyalad8d0a612011-02-28 20:48:03 +0530217static inline void omap_hsmmc_mux(struct omap_mmc_platform_data *mmc_controller,
218 int controller_nr)
219{
Thomas Webera15164f2011-11-17 22:39:40 +0100220 if (gpio_is_valid(mmc_controller->slots[0].switch_pin) &&
221 (mmc_controller->slots[0].switch_pin < OMAP_MAX_GPIO_LINES))
Kishore Kadiyalad8d0a612011-02-28 20:48:03 +0530222 omap_mux_init_gpio(mmc_controller->slots[0].switch_pin,
223 OMAP_PIN_INPUT_PULLUP);
Thomas Webera15164f2011-11-17 22:39:40 +0100224 if (gpio_is_valid(mmc_controller->slots[0].gpio_wp) &&
225 (mmc_controller->slots[0].gpio_wp < OMAP_MAX_GPIO_LINES))
Kishore Kadiyalad8d0a612011-02-28 20:48:03 +0530226 omap_mux_init_gpio(mmc_controller->slots[0].gpio_wp,
227 OMAP_PIN_INPUT_PULLUP);
228 if (cpu_is_omap34xx()) {
229 if (controller_nr == 0) {
230 omap_mux_init_signal("sdmmc1_clk",
231 OMAP_PIN_INPUT_PULLUP);
232 omap_mux_init_signal("sdmmc1_cmd",
233 OMAP_PIN_INPUT_PULLUP);
234 omap_mux_init_signal("sdmmc1_dat0",
235 OMAP_PIN_INPUT_PULLUP);
236 if (mmc_controller->slots[0].caps &
237 (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)) {
238 omap_mux_init_signal("sdmmc1_dat1",
239 OMAP_PIN_INPUT_PULLUP);
240 omap_mux_init_signal("sdmmc1_dat2",
241 OMAP_PIN_INPUT_PULLUP);
242 omap_mux_init_signal("sdmmc1_dat3",
243 OMAP_PIN_INPUT_PULLUP);
244 }
245 if (mmc_controller->slots[0].caps &
246 MMC_CAP_8_BIT_DATA) {
247 omap_mux_init_signal("sdmmc1_dat4",
248 OMAP_PIN_INPUT_PULLUP);
249 omap_mux_init_signal("sdmmc1_dat5",
250 OMAP_PIN_INPUT_PULLUP);
251 omap_mux_init_signal("sdmmc1_dat6",
252 OMAP_PIN_INPUT_PULLUP);
253 omap_mux_init_signal("sdmmc1_dat7",
254 OMAP_PIN_INPUT_PULLUP);
255 }
256 }
257 if (controller_nr == 1) {
258 /* MMC2 */
259 omap_mux_init_signal("sdmmc2_clk",
260 OMAP_PIN_INPUT_PULLUP);
261 omap_mux_init_signal("sdmmc2_cmd",
262 OMAP_PIN_INPUT_PULLUP);
263 omap_mux_init_signal("sdmmc2_dat0",
264 OMAP_PIN_INPUT_PULLUP);
265
266 /*
267 * For 8 wire configurations, Lines DAT4, 5, 6 and 7
268 * need to be muxed in the board-*.c files
269 */
270 if (mmc_controller->slots[0].caps &
271 (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)) {
272 omap_mux_init_signal("sdmmc2_dat1",
273 OMAP_PIN_INPUT_PULLUP);
274 omap_mux_init_signal("sdmmc2_dat2",
275 OMAP_PIN_INPUT_PULLUP);
276 omap_mux_init_signal("sdmmc2_dat3",
277 OMAP_PIN_INPUT_PULLUP);
278 }
279 if (mmc_controller->slots[0].caps &
280 MMC_CAP_8_BIT_DATA) {
281 omap_mux_init_signal("sdmmc2_dat4.sdmmc2_dat4",
282 OMAP_PIN_INPUT_PULLUP);
283 omap_mux_init_signal("sdmmc2_dat5.sdmmc2_dat5",
284 OMAP_PIN_INPUT_PULLUP);
285 omap_mux_init_signal("sdmmc2_dat6.sdmmc2_dat6",
286 OMAP_PIN_INPUT_PULLUP);
287 omap_mux_init_signal("sdmmc2_dat7.sdmmc2_dat7",
288 OMAP_PIN_INPUT_PULLUP);
289 }
290 }
291
292 /*
293 * For MMC3 the pins need to be muxed in the board-*.c files
294 */
295 }
296}
297
Tony Lindgrend1589f02012-02-20 09:43:30 -0800298static int __init omap_hsmmc_pdata_init(struct omap2_hsmmc_info *c,
299 struct omap_mmc_platform_data *mmc)
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530300{
301 char *hc_name;
302
303 hc_name = kzalloc(sizeof(char) * (HSMMC_NAME_LEN + 1), GFP_KERNEL);
304 if (!hc_name) {
305 pr_err("Cannot allocate memory for controller slot name\n");
306 kfree(hc_name);
307 return -ENOMEM;
308 }
309
310 if (c->name)
311 strncpy(hc_name, c->name, HSMMC_NAME_LEN);
312 else
313 snprintf(hc_name, (HSMMC_NAME_LEN + 1), "mmc%islot%i",
314 c->mmc, 1);
315 mmc->slots[0].name = hc_name;
316 mmc->nr_slots = 1;
317 mmc->slots[0].caps = c->caps;
Eliad Peller6fdc75d2011-11-22 16:02:18 +0200318 mmc->slots[0].pm_caps = c->pm_caps;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530319 mmc->slots[0].internal_clock = !c->ext_clock;
Daniel Mackd418ed82012-02-19 13:20:33 +0100320 mmc->max_freq = c->max_freq;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530321 if (cpu_is_omap44xx())
322 mmc->reg_offset = OMAP4_MMC_REG_OFFSET;
323 else
324 mmc->reg_offset = 0;
325
326 mmc->get_context_loss_count = hsmmc_get_context_loss;
327
328 mmc->slots[0].switch_pin = c->gpio_cd;
329 mmc->slots[0].gpio_wp = c->gpio_wp;
330
331 mmc->slots[0].remux = c->remux;
332 mmc->slots[0].init_card = c->init_card;
333
334 if (c->cover_only)
335 mmc->slots[0].cover = 1;
336
337 if (c->nonremovable)
338 mmc->slots[0].nonremovable = 1;
339
340 if (c->power_saving)
341 mmc->slots[0].power_saving = 1;
342
343 if (c->no_off)
344 mmc->slots[0].no_off = 1;
345
Balaji T Kb1c1df72011-05-30 19:55:34 +0530346 if (c->no_off_init)
347 mmc->slots[0].no_regulator_off_init = c->no_off_init;
348
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530349 if (c->vcc_aux_disable_is_sleep)
350 mmc->slots[0].vcc_aux_disable_is_sleep = 1;
351
352 /*
353 * NOTE: MMC slots should have a Vcc regulator set up.
354 * This may be from a TWL4030-family chip, another
355 * controllable regulator, or a fixed supply.
356 *
357 * temporary HACK: ocr_mask instead of fixed supply
358 */
Kevin Hilman68a88b92012-04-30 16:37:10 -0700359 if (soc_is_am35xx())
Abhilash K Ve89715a2011-12-09 12:27:36 -0800360 mmc->slots[0].ocr_mask = MMC_VDD_165_195 |
361 MMC_VDD_26_27 |
362 MMC_VDD_27_28 |
363 MMC_VDD_29_30 |
364 MMC_VDD_30_31 |
365 MMC_VDD_31_32;
366 else
367 mmc->slots[0].ocr_mask = c->ocr_mask;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530368
Kevin Hilman68a88b92012-04-30 16:37:10 -0700369 if (!soc_is_am35xx())
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530370 mmc->slots[0].features |= HSMMC_HAS_PBIAS;
371
372 if (cpu_is_omap44xx() && (omap_rev() > OMAP4430_REV_ES1_0))
373 mmc->slots[0].features |= HSMMC_HAS_UPDATED_RESET;
374
375 switch (c->mmc) {
376 case 1:
377 if (mmc->slots[0].features & HSMMC_HAS_PBIAS) {
378 /* on-chip level shifting via PBIAS0/PBIAS1 */
379 if (cpu_is_omap44xx()) {
380 mmc->slots[0].before_set_reg =
381 omap4_hsmmc1_before_set_reg;
382 mmc->slots[0].after_set_reg =
383 omap4_hsmmc1_after_set_reg;
384 } else {
385 mmc->slots[0].before_set_reg =
386 omap_hsmmc1_before_set_reg;
387 mmc->slots[0].after_set_reg =
388 omap_hsmmc1_after_set_reg;
389 }
390 }
391
Kevin Hilman68a88b92012-04-30 16:37:10 -0700392 if (soc_is_am35xx())
Igor Grinberge62245b2011-11-29 11:37:48 +0200393 mmc->slots[0].set_power = nop_mmc_set_power;
394
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530395 /* OMAP3630 HSMMC1 supports only 4-bit */
396 if (cpu_is_omap3630() &&
397 (c->caps & MMC_CAP_8_BIT_DATA)) {
398 c->caps &= ~MMC_CAP_8_BIT_DATA;
399 c->caps |= MMC_CAP_4_BIT_DATA;
400 mmc->slots[0].caps = c->caps;
401 }
402 break;
403 case 2:
Kevin Hilman68a88b92012-04-30 16:37:10 -0700404 if (soc_is_am35xx())
Igor Grinberge62245b2011-11-29 11:37:48 +0200405 mmc->slots[0].set_power = am35x_hsmmc2_set_power;
406
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530407 if (c->ext_clock)
408 c->transceiver = 1;
409 if (c->transceiver && (c->caps & MMC_CAP_8_BIT_DATA)) {
410 c->caps &= ~MMC_CAP_8_BIT_DATA;
411 c->caps |= MMC_CAP_4_BIT_DATA;
412 }
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530413 if (mmc->slots[0].features & HSMMC_HAS_PBIAS) {
414 /* off-chip level shifting, or none */
Grazvydas Ignotasffa1e4e2011-12-18 02:35:47 +0200415 mmc->slots[0].before_set_reg = hsmmc2_before_set_reg;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530416 mmc->slots[0].after_set_reg = NULL;
417 }
418 break;
Grazvydas Ignotasffa1e4e2011-12-18 02:35:47 +0200419 case 3:
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530420 case 4:
421 case 5:
422 mmc->slots[0].before_set_reg = NULL;
423 mmc->slots[0].after_set_reg = NULL;
424 break;
425 default:
426 pr_err("MMC%d configuration not supported!\n", c->mmc);
427 kfree(hc_name);
428 return -ENODEV;
429 }
430 return 0;
431}
432
Tony Lindgren97899e52012-02-20 09:43:28 -0800433static int omap_hsmmc_done;
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800434
435void omap_hsmmc_late_init(struct omap2_hsmmc_info *c)
436{
437 struct platform_device *pdev;
438 struct omap_mmc_platform_data *mmc_pdata;
439 int res;
440
441 if (omap_hsmmc_done != 1)
442 return;
443
444 omap_hsmmc_done++;
445
446 for (; c->mmc; c++) {
447 if (!c->deferred)
448 continue;
449
450 pdev = c->pdev;
451 if (!pdev)
452 continue;
453
454 mmc_pdata = pdev->dev.platform_data;
455 if (!mmc_pdata)
456 continue;
457
458 mmc_pdata->slots[0].switch_pin = c->gpio_cd;
459 mmc_pdata->slots[0].gpio_wp = c->gpio_wp;
460
461 res = omap_device_register(pdev);
462 if (res)
463 pr_err("Could not late init MMC %s\n",
464 c->name);
465 }
466}
467
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530468#define MAX_OMAP_MMC_HWMOD_NAME_LEN 16
469
Tony Lindgren60285052012-03-07 18:54:24 -0800470static void __init omap_hsmmc_init_one(struct omap2_hsmmc_info *hsmmcinfo,
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800471 int ctrl_nr)
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530472{
473 struct omap_hwmod *oh;
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800474 struct omap_hwmod *ohs[1];
475 struct omap_device *od;
Kevin Hilman3528c582011-07-21 13:48:45 -0700476 struct platform_device *pdev;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530477 char oh_name[MAX_OMAP_MMC_HWMOD_NAME_LEN];
478 struct omap_mmc_platform_data *mmc_data;
479 struct omap_mmc_dev_attr *mmc_dev_attr;
480 char *name;
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800481 int res;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530482
483 mmc_data = kzalloc(sizeof(struct omap_mmc_platform_data), GFP_KERNEL);
484 if (!mmc_data) {
485 pr_err("Cannot allocate memory for mmc device!\n");
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800486 return;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530487 }
488
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800489 res = omap_hsmmc_pdata_init(hsmmcinfo, mmc_data);
490 if (res < 0)
491 goto free_mmc;
492
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530493 omap_hsmmc_mux(mmc_data, (ctrl_nr - 1));
494
Kishore Kadiyala0005ae72011-02-28 20:48:05 +0530495 name = "omap_hsmmc";
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800496 res = snprintf(oh_name, MAX_OMAP_MMC_HWMOD_NAME_LEN,
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530497 "mmc%d", ctrl_nr);
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800498 WARN(res >= MAX_OMAP_MMC_HWMOD_NAME_LEN,
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530499 "String buffer overflow in MMC%d device setup\n", ctrl_nr);
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800500
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530501 oh = omap_hwmod_lookup(oh_name);
502 if (!oh) {
503 pr_err("Could not look up %s\n", oh_name);
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800504 goto free_name;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530505 }
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800506 ohs[0] = oh;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530507 if (oh->dev_attr != NULL) {
508 mmc_dev_attr = oh->dev_attr;
509 mmc_data->controller_flags = mmc_dev_attr->flags;
Grazvydas Ignotas26c547f2012-03-16 14:49:54 +0200510 /*
511 * erratum 2.1.1.128 doesn't apply if board has
512 * a transceiver is attached
513 */
514 if (hsmmcinfo->transceiver)
515 mmc_data->controller_flags &=
516 ~OMAP_HSMMC_BROKEN_MULTIBLOCK_READ;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530517 }
518
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800519 pdev = platform_device_alloc(name, ctrl_nr - 1);
520 if (!pdev) {
521 pr_err("Could not allocate pdev for %s\n", name);
522 goto free_name;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530523 }
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800524 dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530525
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800526 od = omap_device_alloc(pdev, ohs, 1, NULL, 0);
Wei Yongjun64de3a02012-09-21 14:30:50 +0800527 if (IS_ERR(od)) {
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800528 pr_err("Could not allocate od for %s\n", name);
529 goto put_pdev;
530 }
531
532 res = platform_device_add_data(pdev, mmc_data,
533 sizeof(struct omap_mmc_platform_data));
534 if (res) {
535 pr_err("Could not add pdata for %s\n", name);
536 goto put_pdev;
537 }
538
539 hsmmcinfo->pdev = pdev;
540
541 if (hsmmcinfo->deferred)
542 goto free_mmc;
543
544 res = omap_device_register(pdev);
545 if (res) {
546 pr_err("Could not register od for %s\n", name);
547 goto free_od;
548 }
549
550 goto free_mmc;
551
552free_od:
553 omap_device_delete(od);
554
555put_pdev:
556 platform_device_put(pdev);
557
558free_name:
559 kfree(mmc_data->slots[0].name);
560
561free_mmc:
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530562 kfree(mmc_data);
563}
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800564
Tony Lindgrend1589f02012-02-20 09:43:30 -0800565void __init omap_hsmmc_init(struct omap2_hsmmc_info *controllers)
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800566{
kishore kadiyalac83c8e62010-05-15 18:21:25 +0000567 u32 reg;
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800568
Tony Lindgren97899e52012-02-20 09:43:28 -0800569 if (omap_hsmmc_done)
570 return;
571
572 omap_hsmmc_done = 1;
573
kishore kadiyalac83c8e62010-05-15 18:21:25 +0000574 if (!cpu_is_omap44xx()) {
575 if (cpu_is_omap2430()) {
576 control_pbias_offset = OMAP243X_CONTROL_PBIAS_LITE;
577 control_devconf1_offset = OMAP243X_CONTROL_DEVCONF1;
578 } else {
579 control_pbias_offset = OMAP343X_CONTROL_PBIAS_LITE;
580 control_devconf1_offset = OMAP343X_CONTROL_DEVCONF1;
581 }
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800582 } else {
Santosh Shilimkardcf5ef32010-09-27 14:02:58 -0600583 control_pbias_offset =
584 OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_PBIASLITE;
585 control_mmc1 = OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_MMC1;
586 reg = omap4_ctrl_pad_readl(control_mmc1);
587 reg |= (OMAP4_SDMMC1_PUSTRENGTH_GRP0_MASK |
588 OMAP4_SDMMC1_PUSTRENGTH_GRP1_MASK);
589 reg &= ~(OMAP4_SDMMC1_PUSTRENGTH_GRP2_MASK |
590 OMAP4_SDMMC1_PUSTRENGTH_GRP3_MASK);
Balaji T Kc862dd72011-10-03 17:52:51 +0530591 reg |= (OMAP4_SDMMC1_DR0_SPEEDCTRL_MASK |
Santosh Shilimkardcf5ef32010-09-27 14:02:58 -0600592 OMAP4_SDMMC1_DR1_SPEEDCTRL_MASK |
593 OMAP4_SDMMC1_DR2_SPEEDCTRL_MASK);
594 omap4_ctrl_pad_writel(reg, control_mmc1);
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800595 }
596
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530597 for (; controllers->mmc; controllers++)
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800598 omap_hsmmc_init_one(controllers, controllers->mmc);
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800599
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800600}
601
602#endif