blob: 2db6a455d839a67a33f907d5547fc20cd865e7e1 [file] [log] [blame]
Albert Herranz7657c3a2009-12-17 15:27:20 -08001/*
2 * Freescale eSDHC controller driver.
3 *
4 * Copyright (c) 2007 Freescale Semiconductor, Inc.
5 * Copyright (c) 2009 MontaVista Software, Inc.
6 *
7 * Authors: Xiaobo Xie <X.Xie@freescale.com>
8 * Anton Vorontsov <avorontsov@ru.mvista.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or (at
13 * your option) any later version.
14 */
15
16#include <linux/io.h>
17#include <linux/delay.h>
18#include <linux/mmc/host.h>
Shawn Guo38576af2011-05-27 23:48:14 +080019#include "sdhci-pltfm.h"
Albert Herranz7657c3a2009-12-17 15:27:20 -080020#include "sdhci.h"
Wolfram Sang80872e22010-10-15 12:21:03 +020021#include "sdhci-esdhc.h"
Albert Herranz7657c3a2009-12-17 15:27:20 -080022
23static u16 esdhc_readw(struct sdhci_host *host, int reg)
24{
25 u16 ret;
26
27 if (unlikely(reg == SDHCI_HOST_VERSION))
28 ret = in_be16(host->ioaddr + reg);
29 else
30 ret = sdhci_be32bs_readw(host, reg);
31 return ret;
32}
33
34static void esdhc_writew(struct sdhci_host *host, u16 val, int reg)
35{
36 if (reg == SDHCI_BLOCK_SIZE) {
37 /*
38 * Two last DMA bits are reserved, and first one is used for
39 * non-standard blksz of 4096 bytes that we don't support
40 * yet. So clear the DMA boundary bits.
41 */
42 val &= ~SDHCI_MAKE_BLKSZ(0x7, 0);
43 }
44 sdhci_be32bs_writew(host, val, reg);
45}
46
47static void esdhc_writeb(struct sdhci_host *host, u8 val, int reg)
48{
49 /* Prevent SDHCI core from writing reserved bits (e.g. HISPD). */
50 if (reg == SDHCI_HOST_CONTROL)
51 val &= ~ESDHC_HOST_CONTROL_RES;
52 sdhci_be32bs_writeb(host, val, reg);
53}
54
Wolfram Sang80872e22010-10-15 12:21:03 +020055static int esdhc_of_enable_dma(struct sdhci_host *host)
Albert Herranz7657c3a2009-12-17 15:27:20 -080056{
57 setbits32(host->ioaddr + ESDHC_DMA_SYSCTL, ESDHC_DMA_SNOOP);
58 return 0;
59}
60
Wolfram Sang80872e22010-10-15 12:21:03 +020061static unsigned int esdhc_of_get_max_clock(struct sdhci_host *host)
Albert Herranz7657c3a2009-12-17 15:27:20 -080062{
Shawn Guoe3071482011-07-20 17:13:36 -040063 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
Albert Herranz7657c3a2009-12-17 15:27:20 -080064
Shawn Guoe3071482011-07-20 17:13:36 -040065 return pltfm_host->clock;
Albert Herranz7657c3a2009-12-17 15:27:20 -080066}
67
Wolfram Sang80872e22010-10-15 12:21:03 +020068static unsigned int esdhc_of_get_min_clock(struct sdhci_host *host)
Albert Herranz7657c3a2009-12-17 15:27:20 -080069{
Shawn Guoe3071482011-07-20 17:13:36 -040070 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
Albert Herranz7657c3a2009-12-17 15:27:20 -080071
Shawn Guoe3071482011-07-20 17:13:36 -040072 return pltfm_host->clock / 256 / 16;
Albert Herranz7657c3a2009-12-17 15:27:20 -080073}
74
Shawn Guoe3071482011-07-20 17:13:36 -040075static struct sdhci_ops sdhci_esdhc_ops = {
76 .read_l = sdhci_be32bs_readl,
77 .read_w = esdhc_readw,
78 .read_b = sdhci_be32bs_readb,
79 .write_l = sdhci_be32bs_writel,
80 .write_w = esdhc_writew,
81 .write_b = esdhc_writeb,
82 .set_clock = esdhc_set_clock,
83 .enable_dma = esdhc_of_enable_dma,
84 .get_max_clock = esdhc_of_get_max_clock,
85 .get_min_clock = esdhc_of_get_min_clock,
86};
87
Shawn Guo38576af2011-05-27 23:48:14 +080088static struct sdhci_pltfm_data sdhci_esdhc_pdata = {
Wolfram Sang3bb2a9f2011-02-26 14:44:40 +010089 /* card detection could be handled via GPIO */
Richard Zhue481e452011-03-21 13:22:13 +080090 .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_BROKEN_CARD_DETECTION
91 | SDHCI_QUIRK_NO_CARD_NO_RESET,
Shawn Guoe3071482011-07-20 17:13:36 -040092 .ops = &sdhci_esdhc_ops,
Albert Herranz7657c3a2009-12-17 15:27:20 -080093};
Shawn Guo38576af2011-05-27 23:48:14 +080094
95static int __devinit sdhci_esdhc_probe(struct platform_device *pdev)
96{
97 return sdhci_pltfm_register(pdev, &sdhci_esdhc_pdata);
98}
99
100static int __devexit sdhci_esdhc_remove(struct platform_device *pdev)
101{
102 return sdhci_pltfm_unregister(pdev);
103}
104
105static const struct of_device_id sdhci_esdhc_of_match[] = {
106 { .compatible = "fsl,mpc8379-esdhc" },
107 { .compatible = "fsl,mpc8536-esdhc" },
108 { .compatible = "fsl,esdhc" },
109 { }
110};
111MODULE_DEVICE_TABLE(of, sdhci_esdhc_of_match);
112
113static struct platform_driver sdhci_esdhc_driver = {
114 .driver = {
115 .name = "sdhci-esdhc",
116 .owner = THIS_MODULE,
117 .of_match_table = sdhci_esdhc_of_match,
118 },
119 .probe = sdhci_esdhc_probe,
120 .remove = __devexit_p(sdhci_esdhc_remove),
121#ifdef CONFIG_PM
122 .suspend = sdhci_pltfm_suspend,
123 .resume = sdhci_pltfm_resume,
124#endif
125};
126
127static int __init sdhci_esdhc_init(void)
128{
129 return platform_driver_register(&sdhci_esdhc_driver);
130}
131module_init(sdhci_esdhc_init);
132
133static void __exit sdhci_esdhc_exit(void)
134{
135 platform_driver_unregister(&sdhci_esdhc_driver);
136}
137module_exit(sdhci_esdhc_exit);
138
139MODULE_DESCRIPTION("SDHCI OF driver for Freescale MPC eSDHC");
140MODULE_AUTHOR("Xiaobo Xie <X.Xie@freescale.com>, "
141 "Anton Vorontsov <avorontsov@ru.mvista.com>");
142MODULE_LICENSE("GPL v2");