blob: 2ba0d55c323d60ed3f22b207603171d36a3de7b4 [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/control.h>
18#include <plat/mmc.h>
Tony Lindgren90c62bf2008-12-10 17:37:17 -080019
Adrian Hunterd02a900b2010-02-15 10:03:34 -080020#include "hsmmc.h"
Tony Lindgren90c62bf2008-12-10 17:37:17 -080021
Adrian Hunterdb0fefc2010-02-15 10:03:34 -080022#if defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE)
Tony Lindgren90c62bf2008-12-10 17:37:17 -080023
Tony Lindgren90c62bf2008-12-10 17:37:17 -080024static u16 control_pbias_offset;
25static u16 control_devconf1_offset;
26
27#define HSMMC_NAME_LEN 9
28
Adrian Hunter68ff0422010-02-15 10:03:34 -080029static struct hsmmc_controller {
David Brownellb583f262009-05-28 14:04:03 -070030 char name[HSMMC_NAME_LEN + 1];
31} hsmmc[OMAP34XX_NR_MMC];
Tony Lindgren90c62bf2008-12-10 17:37:17 -080032
Denis Karpov1887bde2009-09-22 16:44:40 -070033#if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM)
34
Adrian Hunter68ff0422010-02-15 10:03:34 -080035static int hsmmc_get_context_loss(struct device *dev)
Denis Karpov1887bde2009-09-22 16:44:40 -070036{
37 /* FIXME: PM DPS not implemented yet */
38 return 0;
39}
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
Adrian Hunterdb0fefc2010-02-15 10:03:34 -080045static void hsmmc1_before_set_reg(struct device *dev, int slot,
46 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
David Brownell0329c372009-03-23 18:23:47 -070051 /*
52 * Assume we power both OMAP VMMC1 (for CMD, CLK, DAT0..3) and the
David Brownellb583f262009-05-28 14:04:03 -070053 * card with Vcc regulator (from twl4030 or whatever). OMAP has both
David Brownell0329c372009-03-23 18:23:47 -070054 * 1.8V and 3.0V modes, controlled by the PBIAS register.
55 *
56 * In 8-bit modes, OMAP VMMC1A (for DAT4..7) needs a supply, which
57 * is most naturally TWL VSIM; those pins also use PBIAS.
David Brownellb583f262009-05-28 14:04:03 -070058 *
59 * FIXME handle VMMC1A as needed ...
David Brownell0329c372009-03-23 18:23:47 -070060 */
Tony Lindgren90c62bf2008-12-10 17:37:17 -080061 if (power_on) {
62 if (cpu_is_omap2430()) {
63 reg = omap_ctrl_readl(OMAP243X_CONTROL_DEVCONF1);
64 if ((1 << vdd) >= MMC_VDD_30_31)
65 reg |= OMAP243X_MMC1_ACTIVE_OVERWRITE;
66 else
67 reg &= ~OMAP243X_MMC1_ACTIVE_OVERWRITE;
68 omap_ctrl_writel(reg, OMAP243X_CONTROL_DEVCONF1);
69 }
70
71 if (mmc->slots[0].internal_clock) {
72 reg = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
73 reg |= OMAP2_MMCSDIO1ADPCLKISEL;
74 omap_ctrl_writel(reg, OMAP2_CONTROL_DEVCONF0);
75 }
76
77 reg = omap_ctrl_readl(control_pbias_offset);
Madhu555d5032009-11-22 10:11:08 -080078 if (cpu_is_omap3630()) {
79 /* Set MMC I/O to 52Mhz */
80 prog_io = omap_ctrl_readl(OMAP343X_CONTROL_PROG_IO1);
81 prog_io |= OMAP3630_PRG_SDMMC1_SPEEDCTRL;
82 omap_ctrl_writel(prog_io, OMAP343X_CONTROL_PROG_IO1);
83 } else {
84 reg |= OMAP2_PBIASSPEEDCTRL0;
85 }
Tony Lindgren90c62bf2008-12-10 17:37:17 -080086 reg &= ~OMAP2_PBIASLITEPWRDNZ0;
87 omap_ctrl_writel(reg, control_pbias_offset);
Adrian Hunterdb0fefc2010-02-15 10:03:34 -080088 } else {
89 reg = omap_ctrl_readl(control_pbias_offset);
90 reg &= ~OMAP2_PBIASLITEPWRDNZ0;
91 omap_ctrl_writel(reg, control_pbias_offset);
92 }
93}
Tony Lindgren90c62bf2008-12-10 17:37:17 -080094
Adrian Hunterdb0fefc2010-02-15 10:03:34 -080095static void hsmmc1_after_set_reg(struct device *dev, int slot,
96 int power_on, int vdd)
97{
98 u32 reg;
Tony Lindgren90c62bf2008-12-10 17:37:17 -080099
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800100 /* 100ms delay required for PBIAS configuration */
101 msleep(100);
102
103 if (power_on) {
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800104 reg = omap_ctrl_readl(control_pbias_offset);
105 reg |= (OMAP2_PBIASLITEPWRDNZ0 | OMAP2_PBIASSPEEDCTRL0);
106 if ((1 << vdd) <= MMC_VDD_165_195)
107 reg &= ~OMAP2_PBIASLITEVMODE0;
108 else
109 reg |= OMAP2_PBIASLITEVMODE0;
110 omap_ctrl_writel(reg, control_pbias_offset);
111 } else {
112 reg = omap_ctrl_readl(control_pbias_offset);
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800113 reg |= (OMAP2_PBIASSPEEDCTRL0 | OMAP2_PBIASLITEPWRDNZ0 |
114 OMAP2_PBIASLITEVMODE0);
115 omap_ctrl_writel(reg, control_pbias_offset);
116 }
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800117}
118
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800119static void hsmmc23_before_set_reg(struct device *dev, int slot,
120 int power_on, int vdd)
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800121{
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800122 struct omap_mmc_platform_data *mmc = dev->platform_data;
Grazvydas Ignotas762ad3a42009-06-23 13:30:22 +0300123
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800124 if (power_on) {
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800125 /* Only MMC2 supports a CLKIN */
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800126 if (mmc->slots[0].internal_clock) {
127 u32 reg;
128
129 reg = omap_ctrl_readl(control_devconf1_offset);
130 reg |= OMAP2_MMCSDIO2ADPCLKISEL;
131 omap_ctrl_writel(reg, control_devconf1_offset);
132 }
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800133 }
Adrian Hunter9b7c18e2009-09-22 16:44:50 -0700134}
135
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800136static struct omap_mmc_platform_data *hsmmc_data[OMAP34XX_NR_MMC] __initdata;
137
Adrian Hunter68ff0422010-02-15 10:03:34 -0800138void __init omap2_hsmmc_init(struct omap2_hsmmc_info *controllers)
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800139{
Adrian Hunter68ff0422010-02-15 10:03:34 -0800140 struct omap2_hsmmc_info *c;
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800141 int nr_hsmmc = ARRAY_SIZE(hsmmc_data);
Aaro Koskinena6c7fdd2010-02-04 13:06:59 +0200142 int i;
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800143
144 if (cpu_is_omap2430()) {
145 control_pbias_offset = OMAP243X_CONTROL_PBIAS_LITE;
146 control_devconf1_offset = OMAP243X_CONTROL_DEVCONF1;
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800147 } else {
148 control_pbias_offset = OMAP343X_CONTROL_PBIAS_LITE;
149 control_devconf1_offset = OMAP343X_CONTROL_DEVCONF1;
150 }
151
152 for (c = controllers; c->mmc; c++) {
Adrian Hunter68ff0422010-02-15 10:03:34 -0800153 struct hsmmc_controller *hc = hsmmc + c->mmc - 1;
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800154 struct omap_mmc_platform_data *mmc = hsmmc_data[c->mmc - 1];
155
156 if (!c->mmc || c->mmc > nr_hsmmc) {
157 pr_debug("MMC%d: no such controller\n", c->mmc);
158 continue;
159 }
160 if (mmc) {
161 pr_debug("MMC%d: already configured\n", c->mmc);
162 continue;
163 }
164
Adrian Hunter68ff0422010-02-15 10:03:34 -0800165 mmc = kzalloc(sizeof(struct omap_mmc_platform_data),
166 GFP_KERNEL);
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800167 if (!mmc) {
168 pr_err("Cannot allocate memory for mmc device!\n");
Aaro Koskinena6c7fdd2010-02-04 13:06:59 +0200169 goto done;
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800170 }
171
Adrian Huntere51151a2009-03-23 18:23:48 -0700172 if (c->name)
Adrian Hunter68ff0422010-02-15 10:03:34 -0800173 strncpy(hc->name, c->name, HSMMC_NAME_LEN);
Adrian Huntere51151a2009-03-23 18:23:48 -0700174 else
Adrian Hunter68ff0422010-02-15 10:03:34 -0800175 snprintf(hc->name, ARRAY_SIZE(hc->name),
Adrian Huntere51151a2009-03-23 18:23:48 -0700176 "mmc%islot%i", c->mmc, 1);
Adrian Hunter68ff0422010-02-15 10:03:34 -0800177 mmc->slots[0].name = hc->name;
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800178 mmc->nr_slots = 1;
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800179 mmc->slots[0].wires = c->wires;
180 mmc->slots[0].internal_clock = !c->ext_clock;
181 mmc->dma_mask = 0xffffffff;
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800182
Adrian Hunter68ff0422010-02-15 10:03:34 -0800183 mmc->get_context_loss_count = hsmmc_get_context_loss;
Denis Karpov1887bde2009-09-22 16:44:40 -0700184
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800185 mmc->slots[0].switch_pin = c->gpio_cd;
186 mmc->slots[0].gpio_wp = c->gpio_wp;
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800187
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800188 if (c->cover_only)
189 mmc->slots[0].cover = 1;
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800190
Adrian Hunter23d99bb2009-09-22 16:44:48 -0700191 if (c->nonremovable)
192 mmc->slots[0].nonremovable = 1;
193
Denis Karpovdd498ef2009-09-22 16:44:49 -0700194 if (c->power_saving)
195 mmc->slots[0].power_saving = 1;
196
David Brownellb583f262009-05-28 14:04:03 -0700197 /* NOTE: MMC slots should have a Vcc regulator set up.
198 * This may be from a TWL4030-family chip, another
199 * controllable regulator, or a fixed supply.
200 *
201 * temporary HACK: ocr_mask instead of fixed supply
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800202 */
David Brownellb583f262009-05-28 14:04:03 -0700203 mmc->slots[0].ocr_mask = c->ocr_mask;
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800204
205 switch (c->mmc) {
206 case 1:
David Brownellb583f262009-05-28 14:04:03 -0700207 /* on-chip level shifting via PBIAS0/PBIAS1 */
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800208 mmc->slots[0].before_set_reg = hsmmc1_before_set_reg;
209 mmc->slots[0].after_set_reg = hsmmc1_after_set_reg;
Madhu41fd03d2009-11-22 10:11:07 -0800210
211 /* Omap3630 HSMMC1 supports only 4-bit */
212 if (cpu_is_omap3630() && c->wires > 4) {
213 c->wires = 4;
214 mmc->slots[0].wires = c->wires;
215 }
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800216 break;
217 case 2:
David Brownellb583f262009-05-28 14:04:03 -0700218 if (c->ext_clock)
219 c->transceiver = 1;
220 if (c->transceiver && c->wires > 4)
221 c->wires = 4;
222 /* FALLTHROUGH */
Grazvydas Ignotas07d83cc2009-03-23 18:23:47 -0700223 case 3:
David Brownellb583f262009-05-28 14:04:03 -0700224 /* off-chip level shifting, or none */
Adrian Hunterdb0fefc2010-02-15 10:03:34 -0800225 mmc->slots[0].before_set_reg = hsmmc23_before_set_reg;
226 mmc->slots[0].after_set_reg = NULL;
Grazvydas Ignotas07d83cc2009-03-23 18:23:47 -0700227 break;
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800228 default:
229 pr_err("MMC%d configuration not supported!\n", c->mmc);
Grazvydas Ignotas07d83cc2009-03-23 18:23:47 -0700230 kfree(mmc);
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800231 continue;
232 }
233 hsmmc_data[c->mmc - 1] = mmc;
234 }
235
236 omap2_init_mmc(hsmmc_data, OMAP34XX_NR_MMC);
David Brownell01971f62009-03-23 18:23:47 -0700237
238 /* pass the device nodes back to board setup code */
239 for (c = controllers; c->mmc; c++) {
240 struct omap_mmc_platform_data *mmc = hsmmc_data[c->mmc - 1];
241
242 if (!c->mmc || c->mmc > nr_hsmmc)
243 continue;
244 c->dev = mmc->dev;
245 }
Aaro Koskinena6c7fdd2010-02-04 13:06:59 +0200246
247done:
248 for (i = 0; i < nr_hsmmc; i++)
249 kfree(hsmmc_data[i]);
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800250}
251
252#endif