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 | |
Sebastian Hesselbarth | 30b87c6 | 2012-07-05 12:14:01 +0200 | [diff] [blame] | 22 | #include <linux/clk.h> |
| 23 | #include <linux/err.h> |
Russell King | f8ec589 | 2012-11-22 23:55:51 +0000 | [diff] [blame] | 24 | #include <linux/io.h> |
Mike Rapoport | 985b1aa | 2010-11-07 16:57:12 -0500 | [diff] [blame] | 25 | #include <linux/mmc/host.h> |
Russell King | f8ec589 | 2012-11-22 23:55:51 +0000 | [diff] [blame] | 26 | #include <linux/module.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 | |
Russell King | f8ec589 | 2012-11-22 23:55:51 +0000 | [diff] [blame] | 54 | ret = readl(host->ioaddr + reg); |
| 55 | |
Mike Rapoport | 985b1aa | 2010-11-07 16:57:12 -0500 | [diff] [blame] | 56 | switch (reg) { |
| 57 | case SDHCI_CAPABILITIES: |
Mike Rapoport | 985b1aa | 2010-11-07 16:57:12 -0500 | [diff] [blame] | 58 | /* Mask the support for 3.0V */ |
| 59 | ret &= ~SDHCI_CAN_VDD_300; |
| 60 | break; |
Mike Rapoport | 985b1aa | 2010-11-07 16:57:12 -0500 | [diff] [blame] | 61 | } |
| 62 | return ret; |
| 63 | } |
| 64 | |
Lars-Peter Clausen | c915568 | 2013-03-13 19:26:05 +0100 | [diff] [blame] | 65 | static const struct sdhci_ops sdhci_dove_ops = { |
Mike Rapoport | 985b1aa | 2010-11-07 16:57:12 -0500 | [diff] [blame] | 66 | .read_w = sdhci_dove_readw, |
| 67 | .read_l = sdhci_dove_readl, |
Russell King | 1771059 | 2014-04-25 12:58:55 +0100 | [diff] [blame] | 68 | .set_clock = sdhci_set_clock, |
Russell King | 2317f56 | 2014-04-25 12:57:07 +0100 | [diff] [blame] | 69 | .set_bus_width = sdhci_set_bus_width, |
Russell King | 03231f9 | 2014-04-25 12:57:12 +0100 | [diff] [blame] | 70 | .reset = sdhci_reset, |
Russell King | 96d7b78 | 2014-04-25 12:59:26 +0100 | [diff] [blame] | 71 | .set_uhs_signaling = sdhci_set_uhs_signaling, |
Mike Rapoport | 985b1aa | 2010-11-07 16:57:12 -0500 | [diff] [blame] | 72 | }; |
| 73 | |
Lars-Peter Clausen | 1db5eeb | 2013-03-13 19:26:03 +0100 | [diff] [blame] | 74 | static const struct sdhci_pltfm_data sdhci_dove_pdata = { |
Mike Rapoport | 985b1aa | 2010-11-07 16:57:12 -0500 | [diff] [blame] | 75 | .ops = &sdhci_dove_ops, |
| 76 | .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER | |
| 77 | SDHCI_QUIRK_NO_BUSY_IRQ | |
| 78 | SDHCI_QUIRK_BROKEN_TIMEOUT_VAL | |
Sebastian Hesselbarth | a9ca1d5 | 2012-07-21 19:26:19 -0400 | [diff] [blame] | 79 | SDHCI_QUIRK_FORCE_DMA | |
| 80 | SDHCI_QUIRK_NO_HISPD_BIT, |
Mike Rapoport | 985b1aa | 2010-11-07 16:57:12 -0500 | [diff] [blame] | 81 | }; |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 82 | |
Bill Pemberton | c3be1ef | 2012-11-19 13:23:06 -0500 | [diff] [blame] | 83 | static int sdhci_dove_probe(struct platform_device *pdev) |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 84 | { |
Sebastian Hesselbarth | 30b87c6 | 2012-07-05 12:14:01 +0200 | [diff] [blame] | 85 | struct sdhci_host *host; |
| 86 | struct sdhci_pltfm_host *pltfm_host; |
| 87 | struct sdhci_dove_priv *priv; |
| 88 | int ret; |
| 89 | |
Sebastian Hesselbarth | 30b87c6 | 2012-07-05 12:14:01 +0200 | [diff] [blame] | 90 | priv = devm_kzalloc(&pdev->dev, sizeof(struct sdhci_dove_priv), |
| 91 | GFP_KERNEL); |
| 92 | if (!priv) { |
| 93 | dev_err(&pdev->dev, "unable to allocate private data"); |
Russell King - ARM Linux | ee3298a | 2012-10-29 21:43:07 +0000 | [diff] [blame] | 94 | return -ENOMEM; |
Sebastian Hesselbarth | 30b87c6 | 2012-07-05 12:14:01 +0200 | [diff] [blame] | 95 | } |
| 96 | |
Russell King | 7430e77 | 2012-11-22 23:55:10 +0000 | [diff] [blame] | 97 | priv->clk = devm_clk_get(&pdev->dev, NULL); |
Russell King - ARM Linux | ee3298a | 2012-10-29 21:43:07 +0000 | [diff] [blame] | 98 | |
Christian Daudt | 0e74823 | 2013-05-29 13:50:05 -0700 | [diff] [blame] | 99 | host = sdhci_pltfm_init(pdev, &sdhci_dove_pdata, 0); |
Sebastian Hesselbarth | c5ee249 | 2014-05-23 00:16:52 +0200 | [diff] [blame] | 100 | if (IS_ERR(host)) |
| 101 | return PTR_ERR(host); |
Russell King - ARM Linux | ee3298a | 2012-10-29 21:43:07 +0000 | [diff] [blame] | 102 | |
Sebastian Hesselbarth | 30b87c6 | 2012-07-05 12:14:01 +0200 | [diff] [blame] | 103 | pltfm_host = sdhci_priv(host); |
| 104 | pltfm_host->priv = priv; |
| 105 | |
Russell King | c430689 | 2012-11-22 23:55:30 +0000 | [diff] [blame] | 106 | if (!IS_ERR(priv->clk)) |
| 107 | clk_prepare_enable(priv->clk); |
| 108 | |
Sebastian Hesselbarth | c5ee249 | 2014-05-23 00:16:52 +0200 | [diff] [blame] | 109 | ret = mmc_of_parse(host->mmc); |
| 110 | if (ret) |
| 111 | goto err_sdhci_add; |
Russell King | c430689 | 2012-11-22 23:55:30 +0000 | [diff] [blame] | 112 | |
| 113 | ret = sdhci_add_host(host); |
| 114 | if (ret) |
| 115 | goto err_sdhci_add; |
| 116 | |
Sebastian Hesselbarth | 30b87c6 | 2012-07-05 12:14:01 +0200 | [diff] [blame] | 117 | return 0; |
| 118 | |
Russell King | c430689 | 2012-11-22 23:55:30 +0000 | [diff] [blame] | 119 | err_sdhci_add: |
Russell King | 7430e77 | 2012-11-22 23:55:10 +0000 | [diff] [blame] | 120 | if (!IS_ERR(priv->clk)) |
Russell King - ARM Linux | ee3298a | 2012-10-29 21:43:07 +0000 | [diff] [blame] | 121 | clk_disable_unprepare(priv->clk); |
Russell King | c430689 | 2012-11-22 23:55:30 +0000 | [diff] [blame] | 122 | sdhci_pltfm_free(pdev); |
Sebastian Hesselbarth | 30b87c6 | 2012-07-05 12:14:01 +0200 | [diff] [blame] | 123 | return ret; |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 124 | } |
| 125 | |
Bill Pemberton | 6e0ee71 | 2012-11-19 13:26:03 -0500 | [diff] [blame] | 126 | static int sdhci_dove_remove(struct platform_device *pdev) |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 127 | { |
Sebastian Hesselbarth | 30b87c6 | 2012-07-05 12:14:01 +0200 | [diff] [blame] | 128 | struct sdhci_host *host = platform_get_drvdata(pdev); |
| 129 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 130 | struct sdhci_dove_priv *priv = pltfm_host->priv; |
| 131 | |
Russell King - ARM Linux | ee3298a | 2012-10-29 21:43:07 +0000 | [diff] [blame] | 132 | sdhci_pltfm_unregister(pdev); |
| 133 | |
Russell King | 7430e77 | 2012-11-22 23:55:10 +0000 | [diff] [blame] | 134 | if (!IS_ERR(priv->clk)) |
Russell King - ARM Linux | ee3298a | 2012-10-29 21:43:07 +0000 | [diff] [blame] | 135 | clk_disable_unprepare(priv->clk); |
Russell King | 7430e77 | 2012-11-22 23:55:10 +0000 | [diff] [blame] | 136 | |
Russell King - ARM Linux | ee3298a | 2012-10-29 21:43:07 +0000 | [diff] [blame] | 137 | return 0; |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 138 | } |
| 139 | |
Bill Pemberton | 498d83e | 2012-11-19 13:24:22 -0500 | [diff] [blame] | 140 | static const struct of_device_id sdhci_dove_of_match_table[] = { |
Sebastian Hesselbarth | 4ee7ed0 | 2012-07-31 10:12:59 +0200 | [diff] [blame] | 141 | { .compatible = "marvell,dove-sdhci", }, |
| 142 | {} |
| 143 | }; |
| 144 | MODULE_DEVICE_TABLE(of, sdhci_dove_of_match_table); |
| 145 | |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 146 | static struct platform_driver sdhci_dove_driver = { |
| 147 | .driver = { |
| 148 | .name = "sdhci-dove", |
Manuel Lauss | 29495aa | 2011-11-03 11:09:45 +0100 | [diff] [blame] | 149 | .pm = SDHCI_PLTFM_PMOPS, |
Sachin Kamat | 5941fd0 | 2014-02-25 15:18:24 +0530 | [diff] [blame] | 150 | .of_match_table = sdhci_dove_of_match_table, |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 151 | }, |
| 152 | .probe = sdhci_dove_probe, |
Bill Pemberton | 0433c14 | 2012-11-19 13:20:26 -0500 | [diff] [blame] | 153 | .remove = sdhci_dove_remove, |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 154 | }; |
| 155 | |
Axel Lin | d1f81a6 | 2011-11-26 12:55:43 +0800 | [diff] [blame] | 156 | module_platform_driver(sdhci_dove_driver); |
Shawn Guo | 85d6509 | 2011-05-27 23:48:12 +0800 | [diff] [blame] | 157 | |
| 158 | MODULE_DESCRIPTION("SDHCI driver for Dove"); |
| 159 | MODULE_AUTHOR("Saeed Bishara <saeed@marvell.com>, " |
| 160 | "Mike Rapoport <mike@compulab.co.il>"); |
| 161 | MODULE_LICENSE("GPL v2"); |