aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc/host/omap_hsmmc.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mmc/host/omap_hsmmc.c')
-rw-r--r--drivers/mmc/host/omap_hsmmc.c286
1 files changed, 141 insertions, 145 deletions
diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
index df27bb4fc098..7c71dcdcba8b 100644
--- a/drivers/mmc/host/omap_hsmmc.c
+++ b/drivers/mmc/host/omap_hsmmc.c
@@ -42,7 +42,7 @@
42#include <linux/regulator/consumer.h> 42#include <linux/regulator/consumer.h>
43#include <linux/pinctrl/consumer.h> 43#include <linux/pinctrl/consumer.h>
44#include <linux/pm_runtime.h> 44#include <linux/pm_runtime.h>
45#include <linux/platform_data/mmc-omap.h> 45#include <linux/platform_data/hsmmc-omap.h>
46 46
47/* OMAP HSMMC Host Controller Registers */ 47/* OMAP HSMMC Host Controller Registers */
48#define OMAP_HSMMC_SYSSTATUS 0x0014 48#define OMAP_HSMMC_SYSSTATUS 0x0014
@@ -155,7 +155,7 @@
155 * omap.c controller driver. Luckily this is not currently done on any known 155 * omap.c controller driver. Luckily this is not currently done on any known
156 * omap_hsmmc.c device. 156 * omap_hsmmc.c device.
157 */ 157 */
158#define mmc_slot(host) (host->pdata->slots[host->slot_id]) 158#define mmc_pdata(host) host->pdata
159 159
160/* 160/*
161 * MMC Host controller read/write API's 161 * MMC Host controller read/write API's
@@ -207,7 +207,6 @@ struct omap_hsmmc_host {
207 int use_dma, dma_ch; 207 int use_dma, dma_ch;
208 struct dma_chan *tx_chan; 208 struct dma_chan *tx_chan;
209 struct dma_chan *rx_chan; 209 struct dma_chan *rx_chan;
210 int slot_id;
211 int response_busy; 210 int response_busy;
212 int context_loss; 211 int context_loss;
213 int protect_card; 212 int protect_card;
@@ -220,7 +219,26 @@ struct omap_hsmmc_host {
220#define HSMMC_SDIO_IRQ_ENABLED (1 << 1) /* SDIO irq enabled */ 219#define HSMMC_SDIO_IRQ_ENABLED (1 << 1) /* SDIO irq enabled */
221#define HSMMC_WAKE_IRQ_ENABLED (1 << 2) 220#define HSMMC_WAKE_IRQ_ENABLED (1 << 2)
222 struct omap_hsmmc_next next_data; 221 struct omap_hsmmc_next next_data;
223 struct omap_mmc_platform_data *pdata; 222 struct omap_hsmmc_platform_data *pdata;
223
224 /* To handle board related suspend/resume functionality for MMC */
225 int (*suspend)(struct device *dev);
226 int (*resume)(struct device *dev);
227
228 /* return MMC cover switch state, can be NULL if not supported.
229 *
230 * possible return values:
231 * 0 - closed
232 * 1 - open
233 */
234 int (*get_cover_state)(struct device *dev);
235
236 /* Card detection IRQs */
237 int card_detect_irq;
238
239 int (*card_detect)(struct device *dev);
240 int (*get_ro)(struct device *dev);
241
224}; 242};
225 243
226struct omap_mmc_of_data { 244struct omap_mmc_of_data {
@@ -230,50 +248,48 @@ struct omap_mmc_of_data {
230 248
231static void omap_hsmmc_start_dma_transfer(struct omap_hsmmc_host *host); 249static void omap_hsmmc_start_dma_transfer(struct omap_hsmmc_host *host);
232 250
233static int omap_hsmmc_card_detect(struct device *dev, int slot) 251static int omap_hsmmc_card_detect(struct device *dev)
234{ 252{
235 struct omap_hsmmc_host *host = dev_get_drvdata(dev); 253 struct omap_hsmmc_host *host = dev_get_drvdata(dev);
236 struct omap_mmc_platform_data *mmc = host->pdata; 254 struct omap_hsmmc_platform_data *mmc = host->pdata;
237 255
238 /* NOTE: assumes card detect signal is active-low */ 256 /* NOTE: assumes card detect signal is active-low */
239 return !gpio_get_value_cansleep(mmc->slots[0].switch_pin); 257 return !gpio_get_value_cansleep(mmc->switch_pin);
240} 258}
241 259
242static int omap_hsmmc_get_wp(struct device *dev, int slot) 260static int omap_hsmmc_get_wp(struct device *dev)
243{ 261{
244 struct omap_hsmmc_host *host = dev_get_drvdata(dev); 262 struct omap_hsmmc_host *host = dev_get_drvdata(dev);
245 struct omap_mmc_platform_data *mmc = host->pdata; 263 struct omap_hsmmc_platform_data *mmc = host->pdata;
246 264
247 /* NOTE: assumes write protect signal is active-high */ 265 /* NOTE: assumes write protect signal is active-high */
248 return gpio_get_value_cansleep(mmc->slots[0].gpio_wp); 266 return gpio_get_value_cansleep(mmc->gpio_wp);
249} 267}
250 268
251static int omap_hsmmc_get_cover_state(struct device *dev, int slot) 269static int omap_hsmmc_get_cover_state(struct device *dev)
252{ 270{
253 struct omap_hsmmc_host *host = dev_get_drvdata(dev); 271 struct omap_hsmmc_host *host = dev_get_drvdata(dev);
254 struct omap_mmc_platform_data *mmc = host->pdata; 272 struct omap_hsmmc_platform_data *mmc = host->pdata;
255 273
256 /* NOTE: assumes card detect signal is active-low */ 274 /* NOTE: assumes card detect signal is active-low */
257 return !gpio_get_value_cansleep(mmc->slots[0].switch_pin); 275 return !gpio_get_value_cansleep(mmc->switch_pin);
258} 276}
259 277
260#ifdef CONFIG_PM 278#ifdef CONFIG_PM
261 279
262static int omap_hsmmc_suspend_cdirq(struct device *dev, int slot) 280static int omap_hsmmc_suspend_cdirq(struct device *dev)
263{ 281{
264 struct omap_hsmmc_host *host = dev_get_drvdata(dev); 282 struct omap_hsmmc_host *host = dev_get_drvdata(dev);
265 struct omap_mmc_platform_data *mmc = host->pdata;
266 283
267 disable_irq(mmc->slots[0].card_detect_irq); 284 disable_irq(host->card_detect_irq);
268 return 0; 285 return 0;
269} 286}
270 287
271static int omap_hsmmc_resume_cdirq(struct device *dev, int slot) 288static int omap_hsmmc_resume_cdirq(struct device *dev)
272{ 289{
273 struct omap_hsmmc_host *host = dev_get_drvdata(dev); 290 struct omap_hsmmc_host *host = dev_get_drvdata(dev);
274 struct omap_mmc_platform_data *mmc = host->pdata;
275 291
276 enable_irq(mmc->slots[0].card_detect_irq); 292 enable_irq(host->card_detect_irq);
277 return 0; 293 return 0;
278} 294}
279 295
@@ -286,8 +302,7 @@ static int omap_hsmmc_resume_cdirq(struct device *dev, int slot)
286 302
287#ifdef CONFIG_REGULATOR 303#ifdef CONFIG_REGULATOR
288 304
289static int omap_hsmmc_set_power(struct device *dev, int slot, int power_on, 305static int omap_hsmmc_set_power(struct device *dev, int power_on, int vdd)
290 int vdd)
291{ 306{
292 struct omap_hsmmc_host *host = 307 struct omap_hsmmc_host *host =
293 platform_get_drvdata(to_platform_device(dev)); 308 platform_get_drvdata(to_platform_device(dev));
@@ -300,8 +315,8 @@ static int omap_hsmmc_set_power(struct device *dev, int slot, int power_on,
300 if (!host->vcc) 315 if (!host->vcc)
301 return 0; 316 return 0;
302 317
303 if (mmc_slot(host).before_set_reg) 318 if (mmc_pdata(host)->before_set_reg)
304 mmc_slot(host).before_set_reg(dev, slot, power_on, vdd); 319 mmc_pdata(host)->before_set_reg(dev, power_on, vdd);
305 320
306 if (host->pbias) { 321 if (host->pbias) {
307 if (host->pbias_enabled == 1) { 322 if (host->pbias_enabled == 1) {
@@ -363,8 +378,8 @@ static int omap_hsmmc_set_power(struct device *dev, int slot, int power_on,
363 } 378 }
364 } 379 }
365 380
366 if (mmc_slot(host).after_set_reg) 381 if (mmc_pdata(host)->after_set_reg)
367 mmc_slot(host).after_set_reg(dev, slot, power_on, vdd); 382 mmc_pdata(host)->after_set_reg(dev, power_on, vdd);
368 383
369error_set_power: 384error_set_power:
370 return ret; 385 return ret;
@@ -383,18 +398,18 @@ static int omap_hsmmc_reg_get(struct omap_hsmmc_host *host)
383 } else { 398 } else {
384 host->vcc = reg; 399 host->vcc = reg;
385 ocr_value = mmc_regulator_get_ocrmask(reg); 400 ocr_value = mmc_regulator_get_ocrmask(reg);
386 if (!mmc_slot(host).ocr_mask) { 401 if (!mmc_pdata(host)->ocr_mask) {
387 mmc_slot(host).ocr_mask = ocr_value; 402 mmc_pdata(host)->ocr_mask = ocr_value;
388 } else { 403 } else {
389 if (!(mmc_slot(host).ocr_mask & ocr_value)) { 404 if (!(mmc_pdata(host)->ocr_mask & ocr_value)) {
390 dev_err(host->dev, "ocrmask %x is not supported\n", 405 dev_err(host->dev, "ocrmask %x is not supported\n",
391 mmc_slot(host).ocr_mask); 406 mmc_pdata(host)->ocr_mask);
392 mmc_slot(host).ocr_mask = 0; 407 mmc_pdata(host)->ocr_mask = 0;
393 return -EINVAL; 408 return -EINVAL;
394 } 409 }
395 } 410 }
396 } 411 }
397 mmc_slot(host).set_power = omap_hsmmc_set_power; 412 mmc_pdata(host)->set_power = omap_hsmmc_set_power;
398 413
399 /* Allow an aux regulator */ 414 /* Allow an aux regulator */
400 reg = devm_regulator_get_optional(host->dev, "vmmc_aux"); 415 reg = devm_regulator_get_optional(host->dev, "vmmc_aux");
@@ -404,7 +419,7 @@ static int omap_hsmmc_reg_get(struct omap_hsmmc_host *host)
404 host->pbias = IS_ERR(reg) ? NULL : reg; 419 host->pbias = IS_ERR(reg) ? NULL : reg;
405 420
406 /* For eMMC do not power off when not in sleep state */ 421 /* For eMMC do not power off when not in sleep state */
407 if (mmc_slot(host).no_regulator_off_init) 422 if (mmc_pdata(host)->no_regulator_off_init)
408 return 0; 423 return 0;
409 /* 424 /*
410 * To disable boot_on regulator, enable regulator 425 * To disable boot_on regulator, enable regulator
@@ -412,10 +427,10 @@ static int omap_hsmmc_reg_get(struct omap_hsmmc_host *host)
412 */ 427 */
413 if ((host->vcc && regulator_is_enabled(host->vcc) > 0) || 428 if ((host->vcc && regulator_is_enabled(host->vcc) > 0) ||
414 (host->vcc_aux && regulator_is_enabled(host->vcc_aux))) { 429 (host->vcc_aux && regulator_is_enabled(host->vcc_aux))) {
415 int vdd = ffs(mmc_slot(host).ocr_mask) - 1; 430 int vdd = ffs(mmc_pdata(host)->ocr_mask) - 1;
416 431
417 mmc_slot(host).set_power(host->dev, host->slot_id, 1, vdd); 432 mmc_pdata(host)->set_power(host->dev, 1, vdd);
418 mmc_slot(host).set_power(host->dev, host->slot_id, 0, 0); 433 mmc_pdata(host)->set_power(host->dev, 0, 0);
419 } 434 }
420 435
421 return 0; 436 return 0;
@@ -423,7 +438,7 @@ static int omap_hsmmc_reg_get(struct omap_hsmmc_host *host)
423 438
424static void omap_hsmmc_reg_put(struct omap_hsmmc_host *host) 439static void omap_hsmmc_reg_put(struct omap_hsmmc_host *host)
425{ 440{
426 mmc_slot(host).set_power = NULL; 441 mmc_pdata(host)->set_power = NULL;
427} 442}
428 443
429static inline int omap_hsmmc_have_reg(void) 444static inline int omap_hsmmc_have_reg(void)
@@ -449,55 +464,59 @@ static inline int omap_hsmmc_have_reg(void)
449 464
450#endif 465#endif
451 466
452static int omap_hsmmc_gpio_init(struct omap_mmc_platform_data *pdata) 467static int omap_hsmmc_gpio_init(struct omap_hsmmc_host *host,
468 struct omap_hsmmc_platform_data *pdata)
453{ 469{
454 int ret; 470 int ret;
455 471
456 if (gpio_is_valid(pdata->slots[0].switch_pin)) { 472 if (gpio_is_valid(pdata->switch_pin)) {
457 if (pdata->slots[0].cover) 473 if (pdata->cover)
458 pdata->slots[0].get_cover_state = 474 host->get_cover_state =
459 omap_hsmmc_get_cover_state; 475 omap_hsmmc_get_cover_state;
460 else 476 else
461 pdata->slots[0].card_detect = omap_hsmmc_card_detect; 477 host->card_detect = omap_hsmmc_card_detect;
462 pdata->slots[0].card_detect_irq = 478 host->card_detect_irq =
463 gpio_to_irq(pdata->slots[0].switch_pin); 479 gpio_to_irq(pdata->switch_pin);
464 ret = gpio_request(pdata->slots[0].switch_pin, "mmc_cd"); 480 ret = gpio_request(pdata->switch_pin, "mmc_cd");
465 if (ret) 481 if (ret)
466 return ret; 482 return ret;
467 ret = gpio_direction_input(pdata->slots[0].switch_pin); 483 ret = gpio_direction_input(pdata->switch_pin);
468 if (ret) 484 if (ret)
469 goto err_free_sp; 485 goto err_free_sp;
470 } else 486 } else {
471 pdata->slots[0].switch_pin = -EINVAL; 487 pdata->switch_pin = -EINVAL;
488 }
472 489
473 if (gpio_is_valid(pdata->slots[0].gpio_wp)) { 490 if (gpio_is_valid(pdata->gpio_wp)) {
474 pdata->slots[0].get_ro = omap_hsmmc_get_wp; 491 host->get_ro = omap_hsmmc_get_wp;
475 ret = gpio_request(pdata->slots[0].gpio_wp, "mmc_wp"); 492 ret = gpio_request(pdata->gpio_wp, "mmc_wp");
476 if (ret) 493 if (ret)
477 goto err_free_cd; 494 goto err_free_cd;
478 ret = gpio_direction_input(pdata->slots[0].gpio_wp); 495 ret = gpio_direction_input(pdata->gpio_wp);
479 if (ret) 496 if (ret)
480 goto err_free_wp; 497 goto err_free_wp;
481 } else 498 } else {
482 pdata->slots[0].gpio_wp = -EINVAL; 499 pdata->gpio_wp = -EINVAL;
500 }
483 501
484 return 0; 502 return 0;
485 503
486err_free_wp: 504err_free_wp:
487 gpio_free(pdata->slots[0].gpio_wp); 505 gpio_free(pdata->gpio_wp);
488err_free_cd: 506err_free_cd:
489 if (gpio_is_valid(pdata->slots[0].switch_pin)) 507 if (gpio_is_valid(pdata->switch_pin))
490err_free_sp: 508err_free_sp:
491 gpio_free(pdata->slots[0].switch_pin); 509 gpio_free(pdata->switch_pin);
492 return ret; 510 return ret;
493} 511}
494 512
495static void omap_hsmmc_gpio_free(struct omap_mmc_platform_data *pdata) 513static void omap_hsmmc_gpio_free(struct omap_hsmmc_host *host,
514 struct omap_hsmmc_platform_data *pdata)
496{ 515{
497 if (gpio_is_valid(pdata->slots[0].gpio_wp)) 516 if (gpio_is_valid(pdata->gpio_wp))
498 gpio_free(pdata->slots[0].gpio_wp); 517 gpio_free(pdata->gpio_wp);
499 if (gpio_is_valid(pdata->slots[0].switch_pin)) 518 if (gpio_is_valid(pdata->switch_pin))
500 gpio_free(pdata->slots[0].switch_pin); 519 gpio_free(pdata->switch_pin);
501} 520}
502 521
503/* 522/*
@@ -607,8 +626,9 @@ static void omap_hsmmc_set_clock(struct omap_hsmmc_host *host)
607 * in capabilities register 626 * in capabilities register
608 * - MMC/SD clock coming out of controller > 25MHz 627 * - MMC/SD clock coming out of controller > 25MHz
609 */ 628 */
610 if ((mmc_slot(host).features & HSMMC_HAS_HSPE_SUPPORT) && 629 if ((mmc_pdata(host)->features & HSMMC_HAS_HSPE_SUPPORT) &&
611 (ios->timing != MMC_TIMING_MMC_DDR52) && 630 (ios->timing != MMC_TIMING_MMC_DDR52) &&
631 (ios->timing != MMC_TIMING_UHS_DDR50) &&
612 ((OMAP_HSMMC_READ(host->base, CAPA) & HSS) == HSS)) { 632 ((OMAP_HSMMC_READ(host->base, CAPA) & HSS) == HSS)) {
613 regval = OMAP_HSMMC_READ(host->base, HCTL); 633 regval = OMAP_HSMMC_READ(host->base, HCTL);
614 if (clkdiv && (clk_get_rate(host->fclk)/clkdiv) > 25000000) 634 if (clkdiv && (clk_get_rate(host->fclk)/clkdiv) > 25000000)
@@ -628,7 +648,8 @@ static void omap_hsmmc_set_bus_width(struct omap_hsmmc_host *host)
628 u32 con; 648 u32 con;
629 649
630 con = OMAP_HSMMC_READ(host->base, CON); 650 con = OMAP_HSMMC_READ(host->base, CON);
631 if (ios->timing == MMC_TIMING_MMC_DDR52) 651 if (ios->timing == MMC_TIMING_MMC_DDR52 ||
652 ios->timing == MMC_TIMING_UHS_DDR50)
632 con |= DDR; /* configure in DDR mode */ 653 con |= DDR; /* configure in DDR mode */
633 else 654 else
634 con &= ~DDR; 655 con &= ~DDR;
@@ -791,8 +812,8 @@ int omap_hsmmc_cover_is_closed(struct omap_hsmmc_host *host)
791{ 812{
792 int r = 1; 813 int r = 1;
793 814
794 if (mmc_slot(host).get_cover_state) 815 if (host->get_cover_state)
795 r = mmc_slot(host).get_cover_state(host->dev, host->slot_id); 816 r = host->get_cover_state(host->dev);
796 return r; 817 return r;
797} 818}
798 819
@@ -816,7 +837,7 @@ omap_hsmmc_show_slot_name(struct device *dev, struct device_attribute *attr,
816 struct mmc_host *mmc = container_of(dev, struct mmc_host, class_dev); 837 struct mmc_host *mmc = container_of(dev, struct mmc_host, class_dev);
817 struct omap_hsmmc_host *host = mmc_priv(mmc); 838 struct omap_hsmmc_host *host = mmc_priv(mmc);
818 839
819 return sprintf(buf, "%s\n", mmc_slot(host).name); 840 return sprintf(buf, "%s\n", mmc_pdata(host)->name);
820} 841}
821 842
822static DEVICE_ATTR(slot_name, S_IRUGO, omap_hsmmc_show_slot_name, NULL); 843static DEVICE_ATTR(slot_name, S_IRUGO, omap_hsmmc_show_slot_name, NULL);
@@ -1061,7 +1082,7 @@ static inline void omap_hsmmc_reset_controller_fsm(struct omap_hsmmc_host *host,
1061 * OMAP4 ES2 and greater has an updated reset logic. 1082 * OMAP4 ES2 and greater has an updated reset logic.
1062 * Monitor a 0->1 transition first 1083 * Monitor a 0->1 transition first
1063 */ 1084 */
1064 if (mmc_slot(host).features & HSMMC_HAS_UPDATED_RESET) { 1085 if (mmc_pdata(host)->features & HSMMC_HAS_UPDATED_RESET) {
1065 while ((!(OMAP_HSMMC_READ(host->base, SYSCTL) & bit)) 1086 while ((!(OMAP_HSMMC_READ(host->base, SYSCTL) & bit))
1066 && (i++ < limit)) 1087 && (i++ < limit))
1067 udelay(1); 1088 udelay(1);
@@ -1210,12 +1231,11 @@ static int omap_hsmmc_switch_opcond(struct omap_hsmmc_host *host, int vdd)
1210 clk_disable_unprepare(host->dbclk); 1231 clk_disable_unprepare(host->dbclk);
1211 1232
1212 /* Turn the power off */ 1233 /* Turn the power off */
1213 ret = mmc_slot(host).set_power(host->dev, host->slot_id, 0, 0); 1234 ret = mmc_pdata(host)->set_power(host->dev, 0, 0);
1214 1235
1215 /* Turn the power ON with given VDD 1.8 or 3.0v */ 1236 /* Turn the power ON with given VDD 1.8 or 3.0v */
1216 if (!ret) 1237 if (!ret)
1217 ret = mmc_slot(host).set_power(host->dev, host->slot_id, 1, 1238 ret = mmc_pdata(host)->set_power(host->dev, 1, vdd);
1218 vdd);
1219 pm_runtime_get_sync(host->dev); 1239 pm_runtime_get_sync(host->dev);
1220 if (host->dbclk) 1240 if (host->dbclk)
1221 clk_prepare_enable(host->dbclk); 1241 clk_prepare_enable(host->dbclk);
@@ -1259,11 +1279,11 @@ err:
1259/* Protect the card while the cover is open */ 1279/* Protect the card while the cover is open */
1260static void omap_hsmmc_protect_card(struct omap_hsmmc_host *host) 1280static void omap_hsmmc_protect_card(struct omap_hsmmc_host *host)
1261{ 1281{
1262 if (!mmc_slot(host).get_cover_state) 1282 if (!host->get_cover_state)
1263 return; 1283 return;
1264 1284
1265 host->reqs_blocked = 0; 1285 host->reqs_blocked = 0;
1266 if (mmc_slot(host).get_cover_state(host->dev, host->slot_id)) { 1286 if (host->get_cover_state(host->dev)) {
1267 if (host->protect_card) { 1287 if (host->protect_card) {
1268 dev_info(host->dev, "%s: cover is closed, " 1288 dev_info(host->dev, "%s: cover is closed, "
1269 "card is now accessible\n", 1289 "card is now accessible\n",
@@ -1286,13 +1306,12 @@ static void omap_hsmmc_protect_card(struct omap_hsmmc_host *host)
1286static irqreturn_t omap_hsmmc_detect(int irq, void *dev_id) 1306static irqreturn_t omap_hsmmc_detect(int irq, void *dev_id)
1287{ 1307{
1288 struct omap_hsmmc_host *host = dev_id; 1308 struct omap_hsmmc_host *host = dev_id;
1289 struct omap_mmc_slot_data *slot = &mmc_slot(host);
1290 int carddetect; 1309 int carddetect;
1291 1310
1292 sysfs_notify(&host->mmc->class_dev.kobj, NULL, "cover_switch"); 1311 sysfs_notify(&host->mmc->class_dev.kobj, NULL, "cover_switch");
1293 1312
1294 if (slot->card_detect) 1313 if (host->card_detect)
1295 carddetect = slot->card_detect(host->dev, host->slot_id); 1314 carddetect = host->card_detect(host->dev);
1296 else { 1315 else {
1297 omap_hsmmc_protect_card(host); 1316 omap_hsmmc_protect_card(host);
1298 carddetect = -ENOSYS; 1317 carddetect = -ENOSYS;
@@ -1618,12 +1637,10 @@ static void omap_hsmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1618 if (ios->power_mode != host->power_mode) { 1637 if (ios->power_mode != host->power_mode) {
1619 switch (ios->power_mode) { 1638 switch (ios->power_mode) {
1620 case MMC_POWER_OFF: 1639 case MMC_POWER_OFF:
1621 mmc_slot(host).set_power(host->dev, host->slot_id, 1640 mmc_pdata(host)->set_power(host->dev, 0, 0);
1622 0, 0);
1623 break; 1641 break;
1624 case MMC_POWER_UP: 1642 case MMC_POWER_UP:
1625 mmc_slot(host).set_power(host->dev, host->slot_id, 1643 mmc_pdata(host)->set_power(host->dev, 1, ios->vdd);
1626 1, ios->vdd);
1627 break; 1644 break;
1628 case MMC_POWER_ON: 1645 case MMC_POWER_ON:
1629 do_send_init_stream = 1; 1646 do_send_init_stream = 1;
@@ -1668,26 +1685,26 @@ static int omap_hsmmc_get_cd(struct mmc_host *mmc)
1668{ 1685{
1669 struct omap_hsmmc_host *host = mmc_priv(mmc); 1686 struct omap_hsmmc_host *host = mmc_priv(mmc);
1670 1687
1671 if (!mmc_slot(host).card_detect) 1688 if (!host->card_detect)
1672 return -ENOSYS; 1689 return -ENOSYS;
1673 return mmc_slot(host).card_detect(host->dev, host->slot_id); 1690 return host->card_detect(host->dev);
1674} 1691}
1675 1692
1676static int omap_hsmmc_get_ro(struct mmc_host *mmc) 1693static int omap_hsmmc_get_ro(struct mmc_host *mmc)
1677{ 1694{
1678 struct omap_hsmmc_host *host = mmc_priv(mmc); 1695 struct omap_hsmmc_host *host = mmc_priv(mmc);
1679 1696
1680 if (!mmc_slot(host).get_ro) 1697 if (!host->get_ro)
1681 return -ENOSYS; 1698 return -ENOSYS;
1682 return mmc_slot(host).get_ro(host->dev, 0); 1699 return host->get_ro(host->dev);
1683} 1700}
1684 1701
1685static void omap_hsmmc_init_card(struct mmc_host *mmc, struct mmc_card *card) 1702static void omap_hsmmc_init_card(struct mmc_host *mmc, struct mmc_card *card)
1686{ 1703{
1687 struct omap_hsmmc_host *host = mmc_priv(mmc); 1704 struct omap_hsmmc_host *host = mmc_priv(mmc);
1688 1705
1689 if (mmc_slot(host).init_card) 1706 if (mmc_pdata(host)->init_card)
1690 mmc_slot(host).init_card(card); 1707 mmc_pdata(host)->init_card(card);
1691} 1708}
1692 1709
1693static void omap_hsmmc_enable_sdio_irq(struct mmc_host *mmc, int enable) 1710static void omap_hsmmc_enable_sdio_irq(struct mmc_host *mmc, int enable)
@@ -1957,9 +1974,9 @@ static const struct of_device_id omap_mmc_of_match[] = {
1957}; 1974};
1958MODULE_DEVICE_TABLE(of, omap_mmc_of_match); 1975MODULE_DEVICE_TABLE(of, omap_mmc_of_match);
1959 1976
1960static struct omap_mmc_platform_data *of_get_hsmmc_pdata(struct device *dev) 1977static struct omap_hsmmc_platform_data *of_get_hsmmc_pdata(struct device *dev)
1961{ 1978{
1962 struct omap_mmc_platform_data *pdata; 1979 struct omap_hsmmc_platform_data *pdata;
1963 struct device_node *np = dev->of_node; 1980 struct device_node *np = dev->of_node;
1964 u32 bus_width, max_freq; 1981 u32 bus_width, max_freq;
1965 int cd_gpio, wp_gpio; 1982 int cd_gpio, wp_gpio;
@@ -1976,40 +1993,38 @@ static struct omap_mmc_platform_data *of_get_hsmmc_pdata(struct device *dev)
1976 if (of_find_property(np, "ti,dual-volt", NULL)) 1993 if (of_find_property(np, "ti,dual-volt", NULL))
1977 pdata->controller_flags |= OMAP_HSMMC_SUPPORTS_DUAL_VOLT; 1994 pdata->controller_flags |= OMAP_HSMMC_SUPPORTS_DUAL_VOLT;
1978 1995
1979 /* This driver only supports 1 slot */ 1996 pdata->switch_pin = cd_gpio;
1980 pdata->nr_slots = 1; 1997 pdata->gpio_wp = wp_gpio;
1981 pdata->slots[0].switch_pin = cd_gpio;
1982 pdata->slots[0].gpio_wp = wp_gpio;
1983 1998
1984 if (of_find_property(np, "ti,non-removable", NULL)) { 1999 if (of_find_property(np, "ti,non-removable", NULL)) {
1985 pdata->slots[0].nonremovable = true; 2000 pdata->nonremovable = true;
1986 pdata->slots[0].no_regulator_off_init = true; 2001 pdata->no_regulator_off_init = true;
1987 } 2002 }
1988 of_property_read_u32(np, "bus-width", &bus_width); 2003 of_property_read_u32(np, "bus-width", &bus_width);
1989 if (bus_width == 4) 2004 if (bus_width == 4)
1990 pdata->slots[0].caps |= MMC_CAP_4_BIT_DATA; 2005 pdata->caps |= MMC_CAP_4_BIT_DATA;
1991 else if (bus_width == 8) 2006 else if (bus_width == 8)
1992 pdata->slots[0].caps |= MMC_CAP_8_BIT_DATA; 2007 pdata->caps |= MMC_CAP_8_BIT_DATA;
1993 2008
1994 if (of_find_property(np, "ti,needs-special-reset", NULL)) 2009 if (of_find_property(np, "ti,needs-special-reset", NULL))
1995 pdata->slots[0].features |= HSMMC_HAS_UPDATED_RESET; 2010 pdata->features |= HSMMC_HAS_UPDATED_RESET;
1996 2011
1997 if (!of_property_read_u32(np, "max-frequency", &max_freq)) 2012 if (!of_property_read_u32(np, "max-frequency", &max_freq))
1998 pdata->max_freq = max_freq; 2013 pdata->max_freq = max_freq;
1999 2014
2000 if (of_find_property(np, "ti,needs-special-hs-handling", NULL)) 2015 if (of_find_property(np, "ti,needs-special-hs-handling", NULL))
2001 pdata->slots[0].features |= HSMMC_HAS_HSPE_SUPPORT; 2016 pdata->features |= HSMMC_HAS_HSPE_SUPPORT;
2002 2017
2003 if (of_find_property(np, "keep-power-in-suspend", NULL)) 2018 if (of_find_property(np, "keep-power-in-suspend", NULL))
2004 pdata->slots[0].pm_caps |= MMC_PM_KEEP_POWER; 2019 pdata->pm_caps |= MMC_PM_KEEP_POWER;
2005 2020
2006 if (of_find_property(np, "enable-sdio-wakeup", NULL)) 2021 if (of_find_property(np, "enable-sdio-wakeup", NULL))
2007 pdata->slots[0].pm_caps |= MMC_PM_WAKE_SDIO_IRQ; 2022 pdata->pm_caps |= MMC_PM_WAKE_SDIO_IRQ;
2008 2023
2009 return pdata; 2024 return pdata;
2010} 2025}
2011#else 2026#else
2012static inline struct omap_mmc_platform_data 2027static inline struct omap_hsmmc_platform_data
2013 *of_get_hsmmc_pdata(struct device *dev) 2028 *of_get_hsmmc_pdata(struct device *dev)
2014{ 2029{
2015 return ERR_PTR(-EINVAL); 2030 return ERR_PTR(-EINVAL);
@@ -2018,7 +2033,7 @@ static inline struct omap_mmc_platform_data
2018 2033
2019static int omap_hsmmc_probe(struct platform_device *pdev) 2034static int omap_hsmmc_probe(struct platform_device *pdev)
2020{ 2035{
2021 struct omap_mmc_platform_data *pdata = pdev->dev.platform_data; 2036 struct omap_hsmmc_platform_data *pdata = pdev->dev.platform_data;
2022 struct mmc_host *mmc; 2037 struct mmc_host *mmc;
2023 struct omap_hsmmc_host *host = NULL; 2038 struct omap_hsmmc_host *host = NULL;
2024 struct resource *res; 2039 struct resource *res;
@@ -2048,11 +2063,6 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
2048 return -ENXIO; 2063 return -ENXIO;
2049 } 2064 }
2050 2065
2051 if (pdata->nr_slots == 0) {
2052 dev_err(&pdev->dev, "No Slots\n");
2053 return -ENXIO;
2054 }
2055
2056 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2066 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2057 irq = platform_get_irq(pdev, 0); 2067 irq = platform_get_irq(pdev, 0);
2058 if (res == NULL || irq < 0) 2068 if (res == NULL || irq < 0)
@@ -2062,14 +2072,10 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
2062 if (IS_ERR(base)) 2072 if (IS_ERR(base))
2063 return PTR_ERR(base); 2073 return PTR_ERR(base);
2064 2074
2065 ret = omap_hsmmc_gpio_init(pdata);
2066 if (ret)
2067 goto err;
2068
2069 mmc = mmc_alloc_host(sizeof(struct omap_hsmmc_host), &pdev->dev); 2075 mmc = mmc_alloc_host(sizeof(struct omap_hsmmc_host), &pdev->dev);
2070 if (!mmc) { 2076 if (!mmc) {
2071 ret = -ENOMEM; 2077 ret = -ENOMEM;
2072 goto err_alloc; 2078 goto err;
2073 } 2079 }
2074 2080
2075 host = mmc_priv(mmc); 2081 host = mmc_priv(mmc);
@@ -2079,13 +2085,16 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
2079 host->use_dma = 1; 2085 host->use_dma = 1;
2080 host->dma_ch = -1; 2086 host->dma_ch = -1;
2081 host->irq = irq; 2087 host->irq = irq;
2082 host->slot_id = 0;
2083 host->mapbase = res->start + pdata->reg_offset; 2088 host->mapbase = res->start + pdata->reg_offset;
2084 host->base = base + pdata->reg_offset; 2089 host->base = base + pdata->reg_offset;
2085 host->power_mode = MMC_POWER_OFF; 2090 host->power_mode = MMC_POWER_OFF;
2086 host->next_data.cookie = 1; 2091 host->next_data.cookie = 1;
2087 host->pbias_enabled = 0; 2092 host->pbias_enabled = 0;
2088 2093
2094 ret = omap_hsmmc_gpio_init(host, pdata);
2095 if (ret)
2096 goto err_gpio;
2097
2089 platform_set_drvdata(pdev, host); 2098 platform_set_drvdata(pdev, host);
2090 2099
2091 if (pdev->dev.of_node) 2100 if (pdev->dev.of_node)
@@ -2144,14 +2153,14 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
2144 mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED | 2153 mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED |
2145 MMC_CAP_WAIT_WHILE_BUSY | MMC_CAP_ERASE; 2154 MMC_CAP_WAIT_WHILE_BUSY | MMC_CAP_ERASE;
2146 2155
2147 mmc->caps |= mmc_slot(host).caps; 2156 mmc->caps |= mmc_pdata(host)->caps;
2148 if (mmc->caps & MMC_CAP_8_BIT_DATA) 2157 if (mmc->caps & MMC_CAP_8_BIT_DATA)
2149 mmc->caps |= MMC_CAP_4_BIT_DATA; 2158 mmc->caps |= MMC_CAP_4_BIT_DATA;
2150 2159
2151 if (mmc_slot(host).nonremovable) 2160 if (mmc_pdata(host)->nonremovable)
2152 mmc->caps |= MMC_CAP_NONREMOVABLE; 2161 mmc->caps |= MMC_CAP_NONREMOVABLE;
2153 2162
2154 mmc->pm_caps = mmc_slot(host).pm_caps; 2163 mmc->pm_caps = mmc_pdata(host)->pm_caps;
2155 2164
2156 omap_hsmmc_conf_bus_power(host); 2165 omap_hsmmc_conf_bus_power(host);
2157 2166
@@ -2204,27 +2213,19 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
2204 goto err_irq; 2213 goto err_irq;
2205 } 2214 }
2206 2215
2207 if (pdata->init != NULL) { 2216 if (omap_hsmmc_have_reg() && !mmc_pdata(host)->set_power) {
2208 if (pdata->init(&pdev->dev) != 0) {
2209 dev_err(mmc_dev(host->mmc),
2210 "Unable to configure MMC IRQs\n");
2211 goto err_irq;
2212 }
2213 }
2214
2215 if (omap_hsmmc_have_reg() && !mmc_slot(host).set_power) {
2216 ret = omap_hsmmc_reg_get(host); 2217 ret = omap_hsmmc_reg_get(host);
2217 if (ret) 2218 if (ret)
2218 goto err_reg; 2219 goto err_irq;
2219 host->use_reg = 1; 2220 host->use_reg = 1;
2220 } 2221 }
2221 2222
2222 mmc->ocr_avail = mmc_slot(host).ocr_mask; 2223 mmc->ocr_avail = mmc_pdata(host)->ocr_mask;
2223 2224
2224 /* Request IRQ for card detect */ 2225 /* Request IRQ for card detect */
2225 if ((mmc_slot(host).card_detect_irq)) { 2226 if (host->card_detect_irq) {
2226 ret = devm_request_threaded_irq(&pdev->dev, 2227 ret = devm_request_threaded_irq(&pdev->dev,
2227 mmc_slot(host).card_detect_irq, 2228 host->card_detect_irq,
2228 NULL, omap_hsmmc_detect, 2229 NULL, omap_hsmmc_detect,
2229 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 2230 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
2230 mmc_hostname(mmc), host); 2231 mmc_hostname(mmc), host);
@@ -2233,8 +2234,8 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
2233 "Unable to grab MMC CD IRQ\n"); 2234 "Unable to grab MMC CD IRQ\n");
2234 goto err_irq_cd; 2235 goto err_irq_cd;
2235 } 2236 }
2236 pdata->suspend = omap_hsmmc_suspend_cdirq; 2237 host->suspend = omap_hsmmc_suspend_cdirq;
2237 pdata->resume = omap_hsmmc_resume_cdirq; 2238 host->resume = omap_hsmmc_resume_cdirq;
2238 } 2239 }
2239 2240
2240 omap_hsmmc_disable_irq(host); 2241 omap_hsmmc_disable_irq(host);
@@ -2255,12 +2256,12 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
2255 2256
2256 mmc_add_host(mmc); 2257 mmc_add_host(mmc);
2257 2258
2258 if (mmc_slot(host).name != NULL) { 2259 if (mmc_pdata(host)->name != NULL) {
2259 ret = device_create_file(&mmc->class_dev, &dev_attr_slot_name); 2260 ret = device_create_file(&mmc->class_dev, &dev_attr_slot_name);
2260 if (ret < 0) 2261 if (ret < 0)
2261 goto err_slot_name; 2262 goto err_slot_name;
2262 } 2263 }
2263 if (mmc_slot(host).card_detect_irq && mmc_slot(host).get_cover_state) { 2264 if (host->card_detect_irq && host->get_cover_state) {
2264 ret = device_create_file(&mmc->class_dev, 2265 ret = device_create_file(&mmc->class_dev,
2265 &dev_attr_cover_switch); 2266 &dev_attr_cover_switch);
2266 if (ret < 0) 2267 if (ret < 0)
@@ -2278,9 +2279,6 @@ err_slot_name:
2278err_irq_cd: 2279err_irq_cd:
2279 if (host->use_reg) 2280 if (host->use_reg)
2280 omap_hsmmc_reg_put(host); 2281 omap_hsmmc_reg_put(host);
2281err_reg:
2282 if (host->pdata->cleanup)
2283 host->pdata->cleanup(&pdev->dev);
2284err_irq: 2282err_irq:
2285 if (host->tx_chan) 2283 if (host->tx_chan)
2286 dma_release_channel(host->tx_chan); 2284 dma_release_channel(host->tx_chan);
@@ -2291,9 +2289,9 @@ err_irq:
2291 if (host->dbclk) 2289 if (host->dbclk)
2292 clk_disable_unprepare(host->dbclk); 2290 clk_disable_unprepare(host->dbclk);
2293err1: 2291err1:
2292 omap_hsmmc_gpio_free(host, pdata);
2293err_gpio:
2294 mmc_free_host(mmc); 2294 mmc_free_host(mmc);
2295err_alloc:
2296 omap_hsmmc_gpio_free(pdata);
2297err: 2295err:
2298 return ret; 2296 return ret;
2299} 2297}
@@ -2306,8 +2304,6 @@ static int omap_hsmmc_remove(struct platform_device *pdev)
2306 mmc_remove_host(host->mmc); 2304 mmc_remove_host(host->mmc);
2307 if (host->use_reg) 2305 if (host->use_reg)
2308 omap_hsmmc_reg_put(host); 2306 omap_hsmmc_reg_put(host);
2309 if (host->pdata->cleanup)
2310 host->pdata->cleanup(&pdev->dev);
2311 2307
2312 if (host->tx_chan) 2308 if (host->tx_chan)
2313 dma_release_channel(host->tx_chan); 2309 dma_release_channel(host->tx_chan);
@@ -2319,7 +2315,7 @@ static int omap_hsmmc_remove(struct platform_device *pdev)
2319 if (host->dbclk) 2315 if (host->dbclk)
2320 clk_disable_unprepare(host->dbclk); 2316 clk_disable_unprepare(host->dbclk);
2321 2317
2322 omap_hsmmc_gpio_free(host->pdata); 2318 omap_hsmmc_gpio_free(host, host->pdata);
2323 mmc_free_host(host->mmc); 2319 mmc_free_host(host->mmc);
2324 2320
2325 return 0; 2321 return 0;
@@ -2330,8 +2326,8 @@ static int omap_hsmmc_prepare(struct device *dev)
2330{ 2326{
2331 struct omap_hsmmc_host *host = dev_get_drvdata(dev); 2327 struct omap_hsmmc_host *host = dev_get_drvdata(dev);
2332 2328
2333 if (host->pdata->suspend) 2329 if (host->suspend)
2334 return host->pdata->suspend(dev, host->slot_id); 2330 return host->suspend(dev);
2335 2331
2336 return 0; 2332 return 0;
2337} 2333}
@@ -2340,8 +2336,8 @@ static void omap_hsmmc_complete(struct device *dev)
2340{ 2336{
2341 struct omap_hsmmc_host *host = dev_get_drvdata(dev); 2337 struct omap_hsmmc_host *host = dev_get_drvdata(dev);
2342 2338
2343 if (host->pdata->resume) 2339 if (host->resume)
2344 host->pdata->resume(dev, host->slot_id); 2340 host->resume(dev);
2345 2341
2346} 2342}
2347 2343