1 /* 2 * Freescale eSDHC controller driver. 3 * 4 * Copyright (c) 2007, 2010 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> 19 #include "sdhci-pltfm.h" 20 #include "sdhci-esdhc.h" 21 22 static u16 esdhc_readw(struct sdhci_host *host, int reg) 23 { 24 u16 ret; 25 int base = reg & ~0x3; 26 int shift = (reg & 0x2) * 8; 27 28 if (unlikely(reg == SDHCI_HOST_VERSION)) 29 ret = in_be32(host->ioaddr + base) & 0xffff; 30 else 31 ret = (in_be32(host->ioaddr + base) >> shift) & 0xffff; 32 return ret; 33 } 34 35 static u8 esdhc_readb(struct sdhci_host *host, int reg) 36 { 37 int base = reg & ~0x3; 38 int shift = (reg & 0x3) * 8; 39 u8 ret = (in_be32(host->ioaddr + base) >> shift) & 0xff; 40 return ret; 41 } 42 43 static void esdhc_writew(struct sdhci_host *host, u16 val, int reg) 44 { 45 if (reg == SDHCI_BLOCK_SIZE) { 46 /* 47 * Two last DMA bits are reserved, and first one is used for 48 * non-standard blksz of 4096 bytes that we don't support 49 * yet. So clear the DMA boundary bits. 50 */ 51 val &= ~SDHCI_MAKE_BLKSZ(0x7, 0); 52 } 53 sdhci_be32bs_writew(host, val, reg); 54 } 55 56 static void esdhc_writeb(struct sdhci_host *host, u8 val, int reg) 57 { 58 /* Prevent SDHCI core from writing reserved bits (e.g. HISPD). */ 59 if (reg == SDHCI_HOST_CONTROL) 60 val &= ~ESDHC_HOST_CONTROL_RES; 61 sdhci_be32bs_writeb(host, val, reg); 62 } 63 64 static int esdhc_of_enable_dma(struct sdhci_host *host) 65 { 66 setbits32(host->ioaddr + ESDHC_DMA_SYSCTL, ESDHC_DMA_SNOOP); 67 return 0; 68 } 69 70 static unsigned int esdhc_of_get_max_clock(struct sdhci_host *host) 71 { 72 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 73 74 return pltfm_host->clock; 75 } 76 77 static unsigned int esdhc_of_get_min_clock(struct sdhci_host *host) 78 { 79 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 80 81 return pltfm_host->clock / 256 / 16; 82 } 83 84 static struct sdhci_ops sdhci_esdhc_ops = { 85 .read_l = sdhci_be32bs_readl, 86 .read_w = esdhc_readw, 87 .read_b = esdhc_readb, 88 .write_l = sdhci_be32bs_writel, 89 .write_w = esdhc_writew, 90 .write_b = esdhc_writeb, 91 .set_clock = esdhc_set_clock, 92 .enable_dma = esdhc_of_enable_dma, 93 .get_max_clock = esdhc_of_get_max_clock, 94 .get_min_clock = esdhc_of_get_min_clock, 95 }; 96 97 static struct sdhci_pltfm_data sdhci_esdhc_pdata = { 98 /* card detection could be handled via GPIO */ 99 .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_BROKEN_CARD_DETECTION 100 | SDHCI_QUIRK_NO_CARD_NO_RESET, 101 .ops = &sdhci_esdhc_ops, 102 }; 103 104 static int __devinit sdhci_esdhc_probe(struct platform_device *pdev) 105 { 106 return sdhci_pltfm_register(pdev, &sdhci_esdhc_pdata); 107 } 108 109 static int __devexit sdhci_esdhc_remove(struct platform_device *pdev) 110 { 111 return sdhci_pltfm_unregister(pdev); 112 } 113 114 static const struct of_device_id sdhci_esdhc_of_match[] = { 115 { .compatible = "fsl,mpc8379-esdhc" }, 116 { .compatible = "fsl,mpc8536-esdhc" }, 117 { .compatible = "fsl,esdhc" }, 118 { } 119 }; 120 MODULE_DEVICE_TABLE(of, sdhci_esdhc_of_match); 121 122 static struct platform_driver sdhci_esdhc_driver = { 123 .driver = { 124 .name = "sdhci-esdhc", 125 .owner = THIS_MODULE, 126 .of_match_table = sdhci_esdhc_of_match, 127 }, 128 .probe = sdhci_esdhc_probe, 129 .remove = __devexit_p(sdhci_esdhc_remove), 130 #ifdef CONFIG_PM 131 .suspend = sdhci_pltfm_suspend, 132 .resume = sdhci_pltfm_resume, 133 #endif 134 }; 135 136 static int __init sdhci_esdhc_init(void) 137 { 138 return platform_driver_register(&sdhci_esdhc_driver); 139 } 140 module_init(sdhci_esdhc_init); 141 142 static void __exit sdhci_esdhc_exit(void) 143 { 144 platform_driver_unregister(&sdhci_esdhc_driver); 145 } 146 module_exit(sdhci_esdhc_exit); 147 148 MODULE_DESCRIPTION("SDHCI OF driver for Freescale MPC eSDHC"); 149 MODULE_AUTHOR("Xiaobo Xie <X.Xie@freescale.com>, " 150 "Anton Vorontsov <avorontsov@ru.mvista.com>"); 151 MODULE_LICENSE("GPL v2"); 152