Mike Rapoport | 985b1aa | 2010-11-07 16:57:12 -0500 | [diff] [blame] | 1 | /* |
| 2 | * sdhci-dove.c Support for SDHCI on Marvell's Dove SoC |
| 3 | * |
| 4 | * Author: Saeed Bishara <saeed@marvell.com> |
| 5 | * Mike Rapoport <mike@compulab.co.il> |
| 6 | * Based on sdhci-cns3xxx.c |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | */ |
| 21 | |
| 22 | #include <linux/io.h> |
Sebastian Hesselbarth | 30b87c6 | 2012-07-05 12:14:01 +0200 | [diff] [blame] | 23 | #include <linux/clk.h> |
| 24 | #include <linux/err.h> |
Alf Høgemark | 8c2fc8e | 2012-04-04 12:27:09 -0400 | [diff] [blame] | 25 | #include <linux/module.h> |
Mike Rapoport | 985b1aa | 2010-11-07 16:57:12 -0500 | [diff] [blame] | 26 | #include <linux/mmc/host.h> |
Sebastian Hesselbarth | 4ee7ed0 | 2012-07-31 10:12:59 +0200 | [diff] [blame^] | 27 | #include <linux/of.h> |
Mike Rapoport | 985b1aa | 2010-11-07 16:57:12 -0500 | [diff] [blame] | 28 | |
Mike Rapoport | 985b1aa | 2010-11-07 16:57:12 -0500 | [diff] [blame] | 29 | #include "sdhci-pltfm.h" |
| 30 | |
Sebastian Hesselbarth | 30b87c6 | 2012-07-05 12:14:01 +0200 | [diff] [blame] | 31 | struct sdhci_dove_priv { |
| 32 | struct clk *clk; |
| 33 | }; |
| 34 | |
Mike Rapoport | 985b1aa | 2010-11-07 16:57:12 -0500 | [diff] [blame] | 35 | static u16 sdhci_dove_readw(struct sdhci_host *host, int reg) |
| 36 | { |
| 37 | u16 ret; |
| 38 | |
| 39 | switch (reg) { |
| 40 | case SDHCI_HOST_VERSION: |
| 41 | case SDHCI_SLOT_INT_STATUS: |
| 42 | /* those registers don't exist */ |
| 43 | return 0; |
| 44 | default: |
| 45 | ret = readw(host->ioaddr + reg); |
| 46 | } |
| 47 | return ret; |
| 48 | } |
| 49 | |
| 50 | static u32 sdhci_dove_readl(struct sdhci_host *host, int reg) |
| 51 | { |
| 52 | u32 ret; |
| 53 | |
| 54 | switch (reg) { |
| 55 | case SDHCI_CAPABILITIES: |
| 56 | ret = readl(host->ioaddr + reg); |
| 57 | /* Mask the support for 3.0V */ |
| 58 | ret &= ~SDHCI_CAN_VDD_300; |
| 59 | break; |
| 60 | default: |
| 61 | ret = readl(host->ioaddr + reg); |
| 62 | } |
| 63 | return ret; |
| 64 | } |
| 65 | |
| 66 | static struct sdhci_ops sdhci_dove_ops = { |
| 67 | .read_w = sdhci_dove_readw, |
| 68 | .read_l = sdhci_dove_readl, |
| 69 | }; |
| 70 | |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 71 | static struct sdhci_pltfm_data sdhci_dove_pdata = { |
Mike Rapoport | 985b1aa | 2010-11-07 16:57:12 -0500 | [diff] [blame] | 72 | .ops = &sdhci_dove_ops, |
| 73 | .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER | |
| 74 | SDHCI_QUIRK_NO_BUSY_IRQ | |
| 75 | SDHCI_QUIRK_BROKEN_TIMEOUT_VAL | |
Sebastian Hesselbarth | a9ca1d5 | 2012-07-21 19:26:19 -0400 | [diff] [blame] | 76 | SDHCI_QUIRK_FORCE_DMA | |
| 77 | SDHCI_QUIRK_NO_HISPD_BIT, |
Mike Rapoport | 985b1aa | 2010-11-07 16:57:12 -0500 | [diff] [blame] | 78 | }; |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 79 | |
| 80 | static int __devinit sdhci_dove_probe(struct platform_device *pdev) |
| 81 | { |
Sebastian Hesselbarth | 30b87c6 | 2012-07-05 12:14:01 +0200 | [diff] [blame] | 82 | struct sdhci_host *host; |
| 83 | struct sdhci_pltfm_host *pltfm_host; |
| 84 | struct sdhci_dove_priv *priv; |
| 85 | int ret; |
| 86 | |
| 87 | ret = sdhci_pltfm_register(pdev, &sdhci_dove_pdata); |
| 88 | if (ret) |
| 89 | goto sdhci_dove_register_fail; |
| 90 | |
| 91 | priv = devm_kzalloc(&pdev->dev, sizeof(struct sdhci_dove_priv), |
| 92 | GFP_KERNEL); |
| 93 | if (!priv) { |
| 94 | dev_err(&pdev->dev, "unable to allocate private data"); |
| 95 | ret = -ENOMEM; |
| 96 | goto sdhci_dove_allocate_fail; |
| 97 | } |
| 98 | |
| 99 | host = platform_get_drvdata(pdev); |
| 100 | pltfm_host = sdhci_priv(host); |
| 101 | pltfm_host->priv = priv; |
| 102 | |
| 103 | priv->clk = clk_get(&pdev->dev, NULL); |
| 104 | if (!IS_ERR(priv->clk)) |
| 105 | clk_prepare_enable(priv->clk); |
| 106 | return 0; |
| 107 | |
| 108 | sdhci_dove_allocate_fail: |
| 109 | sdhci_pltfm_unregister(pdev); |
| 110 | sdhci_dove_register_fail: |
| 111 | return ret; |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | static int __devexit sdhci_dove_remove(struct platform_device *pdev) |
| 115 | { |
Sebastian Hesselbarth | 30b87c6 | 2012-07-05 12:14:01 +0200 | [diff] [blame] | 116 | struct sdhci_host *host = platform_get_drvdata(pdev); |
| 117 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 118 | struct sdhci_dove_priv *priv = pltfm_host->priv; |
| 119 | |
| 120 | if (priv->clk) { |
| 121 | if (!IS_ERR(priv->clk)) { |
| 122 | clk_disable_unprepare(priv->clk); |
| 123 | clk_put(priv->clk); |
| 124 | } |
| 125 | devm_kfree(&pdev->dev, priv->clk); |
| 126 | } |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 127 | return sdhci_pltfm_unregister(pdev); |
| 128 | } |
| 129 | |
Sebastian Hesselbarth | 4ee7ed0 | 2012-07-31 10:12:59 +0200 | [diff] [blame^] | 130 | static const struct of_device_id sdhci_dove_of_match_table[] __devinitdata = { |
| 131 | { .compatible = "marvell,dove-sdhci", }, |
| 132 | {} |
| 133 | }; |
| 134 | MODULE_DEVICE_TABLE(of, sdhci_dove_of_match_table); |
| 135 | |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 136 | static struct platform_driver sdhci_dove_driver = { |
| 137 | .driver = { |
| 138 | .name = "sdhci-dove", |
| 139 | .owner = THIS_MODULE, |
Manuel Lauss | 29495aa | 2011-11-03 11:09:45 +0100 | [diff] [blame] | 140 | .pm = SDHCI_PLTFM_PMOPS, |
Sebastian Hesselbarth | 4ee7ed0 | 2012-07-31 10:12:59 +0200 | [diff] [blame^] | 141 | .of_match_table = of_match_ptr(sdhci_dove_of_match_table), |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 142 | }, |
| 143 | .probe = sdhci_dove_probe, |
| 144 | .remove = __devexit_p(sdhci_dove_remove), |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 145 | }; |
| 146 | |
Axel Lin | d1f81a6 | 2011-11-26 12:55:43 +0800 | [diff] [blame] | 147 | module_platform_driver(sdhci_dove_driver); |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 148 | |
| 149 | MODULE_DESCRIPTION("SDHCI driver for Dove"); |
| 150 | MODULE_AUTHOR("Saeed Bishara <saeed@marvell.com>, " |
| 151 | "Mike Rapoport <mike@compulab.co.il>"); |
| 152 | MODULE_LICENSE("GPL v2"); |