blob: 5d876ff86f377b5ec5b1a77a6cfcafc1ffca59e3 [file] [log] [blame]
Albert Herranz7657c3a2009-12-17 15:27:20 -08001/*
2 * Freescale eSDHC controller driver.
3 *
Xu leie51cbc92011-09-09 20:05:46 +08004 * Copyright (c) 2007, 2010 Freescale Semiconductor, Inc.
Albert Herranz7657c3a2009-12-17 15:27:20 -08005 * 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>
Paul Gortmaker88b47672011-07-03 15:15:51 -040018#include <linux/module.h>
Albert Herranz7657c3a2009-12-17 15:27:20 -080019#include <linux/mmc/host.h>
Shawn Guo38576af2011-05-27 23:48:14 +080020#include "sdhci-pltfm.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;
Xu leie51cbc92011-09-09 20:05:46 +080026 int base = reg & ~0x3;
27 int shift = (reg & 0x2) * 8;
Albert Herranz7657c3a2009-12-17 15:27:20 -080028
29 if (unlikely(reg == SDHCI_HOST_VERSION))
Xu leie51cbc92011-09-09 20:05:46 +080030 ret = in_be32(host->ioaddr + base) & 0xffff;
Albert Herranz7657c3a2009-12-17 15:27:20 -080031 else
Xu leie51cbc92011-09-09 20:05:46 +080032 ret = (in_be32(host->ioaddr + base) >> shift) & 0xffff;
33 return ret;
34}
35
36static u8 esdhc_readb(struct sdhci_host *host, int reg)
37{
38 int base = reg & ~0x3;
39 int shift = (reg & 0x3) * 8;
40 u8 ret = (in_be32(host->ioaddr + base) >> shift) & 0xff;
Roy Zangba8c4dc2012-01-13 15:02:01 +080041
42 /*
43 * "DMA select" locates at offset 0x28 in SD specification, but on
44 * P5020 or P3041, it locates at 0x29.
45 */
46 if (reg == SDHCI_HOST_CONTROL) {
47 u32 dma_bits;
48
49 dma_bits = in_be32(host->ioaddr + reg);
50 /* DMA select is 22,23 bits in Protocol Control Register */
51 dma_bits = (dma_bits >> 5) & SDHCI_CTRL_DMA_MASK;
52
53 /* fixup the result */
54 ret &= ~SDHCI_CTRL_DMA_MASK;
55 ret |= dma_bits;
56 }
57
Albert Herranz7657c3a2009-12-17 15:27:20 -080058 return ret;
59}
60
61static void esdhc_writew(struct sdhci_host *host, u16 val, int reg)
62{
63 if (reg == SDHCI_BLOCK_SIZE) {
64 /*
65 * Two last DMA bits are reserved, and first one is used for
66 * non-standard blksz of 4096 bytes that we don't support
67 * yet. So clear the DMA boundary bits.
68 */
69 val &= ~SDHCI_MAKE_BLKSZ(0x7, 0);
70 }
71 sdhci_be32bs_writew(host, val, reg);
72}
73
74static void esdhc_writeb(struct sdhci_host *host, u8 val, int reg)
75{
Roy Zangba8c4dc2012-01-13 15:02:01 +080076 /*
77 * "DMA select" location is offset 0x28 in SD specification, but on
78 * P5020 or P3041, it's located at 0x29.
79 */
80 if (reg == SDHCI_HOST_CONTROL) {
81 u32 dma_bits;
82
83 /* DMA select is 22,23 bits in Protocol Control Register */
84 dma_bits = (val & SDHCI_CTRL_DMA_MASK) << 5;
85 clrsetbits_be32(host->ioaddr + reg , SDHCI_CTRL_DMA_MASK << 5,
86 dma_bits);
87 val &= ~SDHCI_CTRL_DMA_MASK;
88 val |= in_be32(host->ioaddr + reg) & SDHCI_CTRL_DMA_MASK;
89 }
90
Albert Herranz7657c3a2009-12-17 15:27:20 -080091 /* Prevent SDHCI core from writing reserved bits (e.g. HISPD). */
92 if (reg == SDHCI_HOST_CONTROL)
93 val &= ~ESDHC_HOST_CONTROL_RES;
94 sdhci_be32bs_writeb(host, val, reg);
95}
96
Wolfram Sang80872e22010-10-15 12:21:03 +020097static int esdhc_of_enable_dma(struct sdhci_host *host)
Albert Herranz7657c3a2009-12-17 15:27:20 -080098{
99 setbits32(host->ioaddr + ESDHC_DMA_SYSCTL, ESDHC_DMA_SNOOP);
100 return 0;
101}
102
Wolfram Sang80872e22010-10-15 12:21:03 +0200103static unsigned int esdhc_of_get_max_clock(struct sdhci_host *host)
Albert Herranz7657c3a2009-12-17 15:27:20 -0800104{
Shawn Guoe3071482011-07-20 17:13:36 -0400105 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
Albert Herranz7657c3a2009-12-17 15:27:20 -0800106
Shawn Guoe3071482011-07-20 17:13:36 -0400107 return pltfm_host->clock;
Albert Herranz7657c3a2009-12-17 15:27:20 -0800108}
109
Wolfram Sang80872e22010-10-15 12:21:03 +0200110static unsigned int esdhc_of_get_min_clock(struct sdhci_host *host)
Albert Herranz7657c3a2009-12-17 15:27:20 -0800111{
Shawn Guoe3071482011-07-20 17:13:36 -0400112 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
Albert Herranz7657c3a2009-12-17 15:27:20 -0800113
Shawn Guoe3071482011-07-20 17:13:36 -0400114 return pltfm_host->clock / 256 / 16;
Albert Herranz7657c3a2009-12-17 15:27:20 -0800115}
116
Shawn Guoe3071482011-07-20 17:13:36 -0400117static struct sdhci_ops sdhci_esdhc_ops = {
118 .read_l = sdhci_be32bs_readl,
119 .read_w = esdhc_readw,
Xu leie51cbc92011-09-09 20:05:46 +0800120 .read_b = esdhc_readb,
Shawn Guoe3071482011-07-20 17:13:36 -0400121 .write_l = sdhci_be32bs_writel,
122 .write_w = esdhc_writew,
123 .write_b = esdhc_writeb,
124 .set_clock = esdhc_set_clock,
125 .enable_dma = esdhc_of_enable_dma,
126 .get_max_clock = esdhc_of_get_max_clock,
127 .get_min_clock = esdhc_of_get_min_clock,
128};
129
Shawn Guo38576af2011-05-27 23:48:14 +0800130static struct sdhci_pltfm_data sdhci_esdhc_pdata = {
Wolfram Sang3bb2a9f2011-02-26 14:44:40 +0100131 /* card detection could be handled via GPIO */
Richard Zhue481e452011-03-21 13:22:13 +0800132 .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_BROKEN_CARD_DETECTION
133 | SDHCI_QUIRK_NO_CARD_NO_RESET,
Shawn Guoe3071482011-07-20 17:13:36 -0400134 .ops = &sdhci_esdhc_ops,
Albert Herranz7657c3a2009-12-17 15:27:20 -0800135};
Shawn Guo38576af2011-05-27 23:48:14 +0800136
137static int __devinit sdhci_esdhc_probe(struct platform_device *pdev)
138{
139 return sdhci_pltfm_register(pdev, &sdhci_esdhc_pdata);
140}
141
142static int __devexit sdhci_esdhc_remove(struct platform_device *pdev)
143{
144 return sdhci_pltfm_unregister(pdev);
145}
146
147static const struct of_device_id sdhci_esdhc_of_match[] = {
148 { .compatible = "fsl,mpc8379-esdhc" },
149 { .compatible = "fsl,mpc8536-esdhc" },
150 { .compatible = "fsl,esdhc" },
151 { }
152};
153MODULE_DEVICE_TABLE(of, sdhci_esdhc_of_match);
154
155static struct platform_driver sdhci_esdhc_driver = {
156 .driver = {
157 .name = "sdhci-esdhc",
158 .owner = THIS_MODULE,
159 .of_match_table = sdhci_esdhc_of_match,
Manuel Lauss29495aa2011-11-03 11:09:45 +0100160 .pm = SDHCI_PLTFM_PMOPS,
Shawn Guo38576af2011-05-27 23:48:14 +0800161 },
162 .probe = sdhci_esdhc_probe,
163 .remove = __devexit_p(sdhci_esdhc_remove),
Shawn Guo38576af2011-05-27 23:48:14 +0800164};
165
Axel Lind1f81a62011-11-26 12:55:43 +0800166module_platform_driver(sdhci_esdhc_driver);
Shawn Guo38576af2011-05-27 23:48:14 +0800167
168MODULE_DESCRIPTION("SDHCI OF driver for Freescale MPC eSDHC");
169MODULE_AUTHOR("Xiaobo Xie <X.Xie@freescale.com>, "
170 "Anton Vorontsov <avorontsov@ru.mvista.com>");
171MODULE_LICENSE("GPL v2");