xref: /openbmc/linux/drivers/mmc/host/sdhci-of-esdhc.c (revision 38576af1f8cad48446df47dcf404b197c9206dba)
17657c3a7SAlbert Herranz /*
27657c3a7SAlbert Herranz  * Freescale eSDHC controller driver.
37657c3a7SAlbert Herranz  *
47657c3a7SAlbert Herranz  * Copyright (c) 2007 Freescale Semiconductor, Inc.
57657c3a7SAlbert Herranz  * Copyright (c) 2009 MontaVista Software, Inc.
67657c3a7SAlbert Herranz  *
77657c3a7SAlbert Herranz  * Authors: Xiaobo Xie <X.Xie@freescale.com>
87657c3a7SAlbert Herranz  *	    Anton Vorontsov <avorontsov@ru.mvista.com>
97657c3a7SAlbert Herranz  *
107657c3a7SAlbert Herranz  * This program is free software; you can redistribute it and/or modify
117657c3a7SAlbert Herranz  * it under the terms of the GNU General Public License as published by
127657c3a7SAlbert Herranz  * the Free Software Foundation; either version 2 of the License, or (at
137657c3a7SAlbert Herranz  * your option) any later version.
147657c3a7SAlbert Herranz  */
157657c3a7SAlbert Herranz 
167657c3a7SAlbert Herranz #include <linux/io.h>
177657c3a7SAlbert Herranz #include <linux/delay.h>
187657c3a7SAlbert Herranz #include <linux/mmc/host.h>
19*38576af1SShawn Guo #include "sdhci-pltfm.h"
207657c3a7SAlbert Herranz #include "sdhci.h"
2180872e21SWolfram Sang #include "sdhci-esdhc.h"
227657c3a7SAlbert Herranz 
237657c3a7SAlbert Herranz static u16 esdhc_readw(struct sdhci_host *host, int reg)
247657c3a7SAlbert Herranz {
257657c3a7SAlbert Herranz 	u16 ret;
267657c3a7SAlbert Herranz 
277657c3a7SAlbert Herranz 	if (unlikely(reg == SDHCI_HOST_VERSION))
287657c3a7SAlbert Herranz 		ret = in_be16(host->ioaddr + reg);
297657c3a7SAlbert Herranz 	else
307657c3a7SAlbert Herranz 		ret = sdhci_be32bs_readw(host, reg);
317657c3a7SAlbert Herranz 	return ret;
327657c3a7SAlbert Herranz }
337657c3a7SAlbert Herranz 
347657c3a7SAlbert Herranz static void esdhc_writew(struct sdhci_host *host, u16 val, int reg)
357657c3a7SAlbert Herranz {
367657c3a7SAlbert Herranz 	if (reg == SDHCI_BLOCK_SIZE) {
377657c3a7SAlbert Herranz 		/*
387657c3a7SAlbert Herranz 		 * Two last DMA bits are reserved, and first one is used for
397657c3a7SAlbert Herranz 		 * non-standard blksz of 4096 bytes that we don't support
407657c3a7SAlbert Herranz 		 * yet. So clear the DMA boundary bits.
417657c3a7SAlbert Herranz 		 */
427657c3a7SAlbert Herranz 		val &= ~SDHCI_MAKE_BLKSZ(0x7, 0);
437657c3a7SAlbert Herranz 	}
447657c3a7SAlbert Herranz 	sdhci_be32bs_writew(host, val, reg);
457657c3a7SAlbert Herranz }
467657c3a7SAlbert Herranz 
477657c3a7SAlbert Herranz static void esdhc_writeb(struct sdhci_host *host, u8 val, int reg)
487657c3a7SAlbert Herranz {
497657c3a7SAlbert Herranz 	/* Prevent SDHCI core from writing reserved bits (e.g. HISPD). */
507657c3a7SAlbert Herranz 	if (reg == SDHCI_HOST_CONTROL)
517657c3a7SAlbert Herranz 		val &= ~ESDHC_HOST_CONTROL_RES;
527657c3a7SAlbert Herranz 	sdhci_be32bs_writeb(host, val, reg);
537657c3a7SAlbert Herranz }
547657c3a7SAlbert Herranz 
5580872e21SWolfram Sang static int esdhc_of_enable_dma(struct sdhci_host *host)
567657c3a7SAlbert Herranz {
577657c3a7SAlbert Herranz 	setbits32(host->ioaddr + ESDHC_DMA_SYSCTL, ESDHC_DMA_SNOOP);
587657c3a7SAlbert Herranz 	return 0;
597657c3a7SAlbert Herranz }
607657c3a7SAlbert Herranz 
6180872e21SWolfram Sang static unsigned int esdhc_of_get_max_clock(struct sdhci_host *host)
627657c3a7SAlbert Herranz {
63e307148fSShawn Guo 	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
647657c3a7SAlbert Herranz 
65e307148fSShawn Guo 	return pltfm_host->clock;
667657c3a7SAlbert Herranz }
677657c3a7SAlbert Herranz 
6880872e21SWolfram Sang static unsigned int esdhc_of_get_min_clock(struct sdhci_host *host)
697657c3a7SAlbert Herranz {
70e307148fSShawn Guo 	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
717657c3a7SAlbert Herranz 
72e307148fSShawn Guo 	return pltfm_host->clock / 256 / 16;
737657c3a7SAlbert Herranz }
747657c3a7SAlbert Herranz 
75e307148fSShawn Guo static struct sdhci_ops sdhci_esdhc_ops = {
76dc297c92SMatt Fleming 	.read_l = sdhci_be32bs_readl,
77dc297c92SMatt Fleming 	.read_w = esdhc_readw,
78dc297c92SMatt Fleming 	.read_b = sdhci_be32bs_readb,
79dc297c92SMatt Fleming 	.write_l = sdhci_be32bs_writel,
80dc297c92SMatt Fleming 	.write_w = esdhc_writew,
81dc297c92SMatt Fleming 	.write_b = esdhc_writeb,
827657c3a7SAlbert Herranz 	.set_clock = esdhc_set_clock,
8380872e21SWolfram Sang 	.enable_dma = esdhc_of_enable_dma,
8480872e21SWolfram Sang 	.get_max_clock = esdhc_of_get_max_clock,
8580872e21SWolfram Sang 	.get_min_clock = esdhc_of_get_min_clock,
86e307148fSShawn Guo };
87e307148fSShawn Guo 
88*38576af1SShawn Guo static struct sdhci_pltfm_data sdhci_esdhc_pdata = {
89e307148fSShawn Guo 	/* card detection could be handled via GPIO */
90e307148fSShawn Guo 	.quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_BROKEN_CARD_DETECTION
91e307148fSShawn Guo 		| SDHCI_QUIRK_NO_CARD_NO_RESET,
92e307148fSShawn Guo 	.ops = &sdhci_esdhc_ops,
937657c3a7SAlbert Herranz };
94*38576af1SShawn Guo 
95*38576af1SShawn Guo static int __devinit sdhci_esdhc_probe(struct platform_device *pdev)
96*38576af1SShawn Guo {
97*38576af1SShawn Guo 	return sdhci_pltfm_register(pdev, &sdhci_esdhc_pdata);
98*38576af1SShawn Guo }
99*38576af1SShawn Guo 
100*38576af1SShawn Guo static int __devexit sdhci_esdhc_remove(struct platform_device *pdev)
101*38576af1SShawn Guo {
102*38576af1SShawn Guo 	return sdhci_pltfm_unregister(pdev);
103*38576af1SShawn Guo }
104*38576af1SShawn Guo 
105*38576af1SShawn Guo static const struct of_device_id sdhci_esdhc_of_match[] = {
106*38576af1SShawn Guo 	{ .compatible = "fsl,mpc8379-esdhc" },
107*38576af1SShawn Guo 	{ .compatible = "fsl,mpc8536-esdhc" },
108*38576af1SShawn Guo 	{ .compatible = "fsl,esdhc" },
109*38576af1SShawn Guo 	{ }
110*38576af1SShawn Guo };
111*38576af1SShawn Guo MODULE_DEVICE_TABLE(of, sdhci_esdhc_of_match);
112*38576af1SShawn Guo 
113*38576af1SShawn Guo static struct platform_driver sdhci_esdhc_driver = {
114*38576af1SShawn Guo 	.driver = {
115*38576af1SShawn Guo 		.name = "sdhci-esdhc",
116*38576af1SShawn Guo 		.owner = THIS_MODULE,
117*38576af1SShawn Guo 		.of_match_table = sdhci_esdhc_of_match,
118*38576af1SShawn Guo 	},
119*38576af1SShawn Guo 	.probe = sdhci_esdhc_probe,
120*38576af1SShawn Guo 	.remove = __devexit_p(sdhci_esdhc_remove),
121*38576af1SShawn Guo #ifdef CONFIG_PM
122*38576af1SShawn Guo 	.suspend = sdhci_pltfm_suspend,
123*38576af1SShawn Guo 	.resume = sdhci_pltfm_resume,
124*38576af1SShawn Guo #endif
125*38576af1SShawn Guo };
126*38576af1SShawn Guo 
127*38576af1SShawn Guo static int __init sdhci_esdhc_init(void)
128*38576af1SShawn Guo {
129*38576af1SShawn Guo 	return platform_driver_register(&sdhci_esdhc_driver);
130*38576af1SShawn Guo }
131*38576af1SShawn Guo module_init(sdhci_esdhc_init);
132*38576af1SShawn Guo 
133*38576af1SShawn Guo static void __exit sdhci_esdhc_exit(void)
134*38576af1SShawn Guo {
135*38576af1SShawn Guo 	platform_driver_unregister(&sdhci_esdhc_driver);
136*38576af1SShawn Guo }
137*38576af1SShawn Guo module_exit(sdhci_esdhc_exit);
138*38576af1SShawn Guo 
139*38576af1SShawn Guo MODULE_DESCRIPTION("SDHCI OF driver for Freescale MPC eSDHC");
140*38576af1SShawn Guo MODULE_AUTHOR("Xiaobo Xie <X.Xie@freescale.com>, "
141*38576af1SShawn Guo 	      "Anton Vorontsov <avorontsov@ru.mvista.com>");
142*38576af1SShawn Guo MODULE_LICENSE("GPL v2");
143