Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Arasan Secure Digital Host Controller Interface. |
| 3 | * Copyright (C) 2011 - 2012 Michal Simek <monstr@monstr.eu> |
| 4 | * Copyright (c) 2012 Wind River Systems, Inc. |
| 5 | * Copyright (C) 2013 Pengutronix e.K. |
| 6 | * Copyright (C) 2013 Xilinx Inc. |
| 7 | * |
| 8 | * Based on sdhci-of-esdhc.c |
| 9 | * |
| 10 | * Copyright (c) 2007 Freescale Semiconductor, Inc. |
| 11 | * Copyright (c) 2009 MontaVista Software, Inc. |
| 12 | * |
| 13 | * Authors: Xiaobo Xie <X.Xie@freescale.com> |
| 14 | * Anton Vorontsov <avorontsov@ru.mvista.com> |
| 15 | * |
| 16 | * This program is free software; you can redistribute it and/or modify |
| 17 | * it under the terms of the GNU General Public License as published by |
| 18 | * the Free Software Foundation; either version 2 of the License, or (at |
| 19 | * your option) any later version. |
| 20 | */ |
| 21 | |
Douglas Anderson | c390f21 | 2016-06-20 10:56:50 -0700 | [diff] [blame] | 22 | #include <linux/clk-provider.h> |
Douglas Anderson | 3ea4666e | 2016-06-20 10:56:47 -0700 | [diff] [blame] | 23 | #include <linux/mfd/syscon.h> |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 24 | #include <linux/module.h> |
Suman Tripathi | 308f3f8 | 2015-05-04 19:09:51 +0530 | [diff] [blame] | 25 | #include <linux/of_device.h> |
Shawn Lin | 91aa366 | 2016-03-07 23:39:19 +0800 | [diff] [blame] | 26 | #include <linux/phy/phy.h> |
Douglas Anderson | 3ea4666e | 2016-06-20 10:56:47 -0700 | [diff] [blame] | 27 | #include <linux/regmap.h> |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 28 | #include "sdhci-pltfm.h" |
Zach Brown | 3794c54 | 2016-09-16 10:01:42 -0500 | [diff] [blame] | 29 | #include <linux/of.h> |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 30 | |
Shawn Lin | a05c846 | 2016-05-26 09:56:43 +0800 | [diff] [blame] | 31 | #define SDHCI_ARASAN_VENDOR_REGISTER 0x78 |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 32 | |
Shawn Lin | a05c846 | 2016-05-26 09:56:43 +0800 | [diff] [blame] | 33 | #define VENDOR_ENHANCED_STROBE BIT(0) |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 34 | |
Douglas Anderson | b2db9c6 | 2016-08-18 10:26:38 -0700 | [diff] [blame] | 35 | #define PHY_CLK_TOO_SLOW_HZ 400000 |
| 36 | |
Douglas Anderson | 3ea4666e | 2016-06-20 10:56:47 -0700 | [diff] [blame] | 37 | /* |
| 38 | * On some SoCs the syscon area has a feature where the upper 16-bits of |
| 39 | * each 32-bit register act as a write mask for the lower 16-bits. This allows |
| 40 | * atomic updates of the register without locking. This macro is used on SoCs |
| 41 | * that have that feature. |
| 42 | */ |
| 43 | #define HIWORD_UPDATE(val, mask, shift) \ |
| 44 | ((val) << (shift) | (mask) << ((shift) + 16)) |
| 45 | |
| 46 | /** |
| 47 | * struct sdhci_arasan_soc_ctl_field - Field used in sdhci_arasan_soc_ctl_map |
| 48 | * |
| 49 | * @reg: Offset within the syscon of the register containing this field |
| 50 | * @width: Number of bits for this field |
| 51 | * @shift: Bit offset within @reg of this field (or -1 if not avail) |
| 52 | */ |
| 53 | struct sdhci_arasan_soc_ctl_field { |
| 54 | u32 reg; |
| 55 | u16 width; |
| 56 | s16 shift; |
| 57 | }; |
| 58 | |
| 59 | /** |
| 60 | * struct sdhci_arasan_soc_ctl_map - Map in syscon to corecfg registers |
| 61 | * |
| 62 | * It's up to the licensee of the Arsan IP block to make these available |
| 63 | * somewhere if needed. Presumably these will be scattered somewhere that's |
| 64 | * accessible via the syscon API. |
| 65 | * |
| 66 | * @baseclkfreq: Where to find corecfg_baseclkfreq |
Shawn Lin | b2ca77c | 2016-08-26 16:51:15 +0800 | [diff] [blame] | 67 | * @clockmultiplier: Where to find corecfg_clockmultiplier |
Douglas Anderson | 3ea4666e | 2016-06-20 10:56:47 -0700 | [diff] [blame] | 68 | * @hiword_update: If true, use HIWORD_UPDATE to access the syscon |
| 69 | */ |
| 70 | struct sdhci_arasan_soc_ctl_map { |
| 71 | struct sdhci_arasan_soc_ctl_field baseclkfreq; |
Shawn Lin | b2ca77c | 2016-08-26 16:51:15 +0800 | [diff] [blame] | 72 | struct sdhci_arasan_soc_ctl_field clockmultiplier; |
Douglas Anderson | 3ea4666e | 2016-06-20 10:56:47 -0700 | [diff] [blame] | 73 | bool hiword_update; |
| 74 | }; |
| 75 | |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 76 | /** |
| 77 | * struct sdhci_arasan_data |
Douglas Anderson | c390f21 | 2016-06-20 10:56:50 -0700 | [diff] [blame] | 78 | * @host: Pointer to the main SDHCI host structure. |
Douglas Anderson | 3ea4666e | 2016-06-20 10:56:47 -0700 | [diff] [blame] | 79 | * @clk_ahb: Pointer to the AHB clock |
| 80 | * @phy: Pointer to the generic phy |
Douglas Anderson | b2db9c6 | 2016-08-18 10:26:38 -0700 | [diff] [blame] | 81 | * @is_phy_on: True if the PHY is on; false if not. |
Douglas Anderson | c390f21 | 2016-06-20 10:56:50 -0700 | [diff] [blame] | 82 | * @sdcardclk_hw: Struct for the clock we might provide to a PHY. |
| 83 | * @sdcardclk: Pointer to normal 'struct clock' for sdcardclk_hw. |
Douglas Anderson | 3ea4666e | 2016-06-20 10:56:47 -0700 | [diff] [blame] | 84 | * @soc_ctl_base: Pointer to regmap for syscon for soc_ctl registers. |
| 85 | * @soc_ctl_map: Map to get offsets into soc_ctl registers. |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 86 | */ |
| 87 | struct sdhci_arasan_data { |
Douglas Anderson | c390f21 | 2016-06-20 10:56:50 -0700 | [diff] [blame] | 88 | struct sdhci_host *host; |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 89 | struct clk *clk_ahb; |
Shawn Lin | 91aa366 | 2016-03-07 23:39:19 +0800 | [diff] [blame] | 90 | struct phy *phy; |
Douglas Anderson | b2db9c6 | 2016-08-18 10:26:38 -0700 | [diff] [blame] | 91 | bool is_phy_on; |
Douglas Anderson | 3ea4666e | 2016-06-20 10:56:47 -0700 | [diff] [blame] | 92 | |
Douglas Anderson | c390f21 | 2016-06-20 10:56:50 -0700 | [diff] [blame] | 93 | struct clk_hw sdcardclk_hw; |
| 94 | struct clk *sdcardclk; |
| 95 | |
Douglas Anderson | 3ea4666e | 2016-06-20 10:56:47 -0700 | [diff] [blame] | 96 | struct regmap *soc_ctl_base; |
| 97 | const struct sdhci_arasan_soc_ctl_map *soc_ctl_map; |
Zach Brown | 3794c54 | 2016-09-16 10:01:42 -0500 | [diff] [blame] | 98 | unsigned int quirks; /* Arasan deviations from spec */ |
| 99 | |
| 100 | /* Controller does not have CD wired and will not function normally without */ |
| 101 | #define SDHCI_ARASAN_QUIRK_FORCE_CDTEST BIT(0) |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 102 | }; |
| 103 | |
Douglas Anderson | 3ea4666e | 2016-06-20 10:56:47 -0700 | [diff] [blame] | 104 | static const struct sdhci_arasan_soc_ctl_map rk3399_soc_ctl_map = { |
| 105 | .baseclkfreq = { .reg = 0xf000, .width = 8, .shift = 8 }, |
Shawn Lin | b2ca77c | 2016-08-26 16:51:15 +0800 | [diff] [blame] | 106 | .clockmultiplier = { .reg = 0xf02c, .width = 8, .shift = 0}, |
Douglas Anderson | 3ea4666e | 2016-06-20 10:56:47 -0700 | [diff] [blame] | 107 | .hiword_update = true, |
| 108 | }; |
| 109 | |
| 110 | /** |
| 111 | * sdhci_arasan_syscon_write - Write to a field in soc_ctl registers |
| 112 | * |
| 113 | * This function allows writing to fields in sdhci_arasan_soc_ctl_map. |
| 114 | * Note that if a field is specified as not available (shift < 0) then |
| 115 | * this function will silently return an error code. It will be noisy |
| 116 | * and print errors for any other (unexpected) errors. |
| 117 | * |
| 118 | * @host: The sdhci_host |
| 119 | * @fld: The field to write to |
| 120 | * @val: The value to write |
| 121 | */ |
| 122 | static int sdhci_arasan_syscon_write(struct sdhci_host *host, |
| 123 | const struct sdhci_arasan_soc_ctl_field *fld, |
| 124 | u32 val) |
| 125 | { |
| 126 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 127 | struct sdhci_arasan_data *sdhci_arasan = sdhci_pltfm_priv(pltfm_host); |
| 128 | struct regmap *soc_ctl_base = sdhci_arasan->soc_ctl_base; |
| 129 | u32 reg = fld->reg; |
| 130 | u16 width = fld->width; |
| 131 | s16 shift = fld->shift; |
| 132 | int ret; |
| 133 | |
| 134 | /* |
| 135 | * Silently return errors for shift < 0 so caller doesn't have |
| 136 | * to check for fields which are optional. For fields that |
| 137 | * are required then caller needs to do something special |
| 138 | * anyway. |
| 139 | */ |
| 140 | if (shift < 0) |
| 141 | return -EINVAL; |
| 142 | |
| 143 | if (sdhci_arasan->soc_ctl_map->hiword_update) |
| 144 | ret = regmap_write(soc_ctl_base, reg, |
| 145 | HIWORD_UPDATE(val, GENMASK(width, 0), |
| 146 | shift)); |
| 147 | else |
| 148 | ret = regmap_update_bits(soc_ctl_base, reg, |
| 149 | GENMASK(shift + width, shift), |
| 150 | val << shift); |
| 151 | |
| 152 | /* Yell about (unexpected) regmap errors */ |
| 153 | if (ret) |
| 154 | pr_warn("%s: Regmap write fail: %d\n", |
| 155 | mmc_hostname(host->mmc), ret); |
| 156 | |
| 157 | return ret; |
| 158 | } |
| 159 | |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 160 | static unsigned int sdhci_arasan_get_timeout_clock(struct sdhci_host *host) |
| 161 | { |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 162 | unsigned long freq; |
| 163 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 164 | |
Anssi Hannula | 1668103 | 2017-02-13 14:06:10 +0200 | [diff] [blame] | 165 | /* SDHCI timeout clock is in kHz */ |
| 166 | freq = DIV_ROUND_UP(clk_get_rate(pltfm_host->clk), 1000); |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 167 | |
Anssi Hannula | 1668103 | 2017-02-13 14:06:10 +0200 | [diff] [blame] | 168 | /* or in MHz */ |
| 169 | if (host->caps & SDHCI_TIMEOUT_CLK_UNIT) |
| 170 | freq = DIV_ROUND_UP(freq, 1000); |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 171 | |
| 172 | return freq; |
| 173 | } |
| 174 | |
Shawn Lin | 802ac39 | 2016-05-04 09:43:24 +0800 | [diff] [blame] | 175 | static void sdhci_arasan_set_clock(struct sdhci_host *host, unsigned int clock) |
| 176 | { |
| 177 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 178 | struct sdhci_arasan_data *sdhci_arasan = sdhci_pltfm_priv(pltfm_host); |
Douglas Anderson | 6fc0924 | 2016-06-27 10:39:25 -0700 | [diff] [blame] | 179 | bool ctrl_phy = false; |
Shawn Lin | 802ac39 | 2016-05-04 09:43:24 +0800 | [diff] [blame] | 180 | |
Douglas Anderson | b2db9c6 | 2016-08-18 10:26:38 -0700 | [diff] [blame] | 181 | if (!IS_ERR(sdhci_arasan->phy)) { |
| 182 | if (!sdhci_arasan->is_phy_on && clock <= PHY_CLK_TOO_SLOW_HZ) { |
| 183 | /* |
| 184 | * If PHY off, set clock to max speed and power PHY on. |
| 185 | * |
| 186 | * Although PHY docs apparently suggest power cycling |
| 187 | * when changing the clock the PHY doesn't like to be |
| 188 | * powered on while at low speeds like those used in ID |
| 189 | * mode. Even worse is powering the PHY on while the |
| 190 | * clock is off. |
| 191 | * |
| 192 | * To workaround the PHY limitations, the best we can |
| 193 | * do is to power it on at a faster speed and then slam |
| 194 | * through low speeds without power cycling. |
| 195 | */ |
| 196 | sdhci_set_clock(host, host->max_clk); |
| 197 | spin_unlock_irq(&host->lock); |
| 198 | phy_power_on(sdhci_arasan->phy); |
| 199 | spin_lock_irq(&host->lock); |
| 200 | sdhci_arasan->is_phy_on = true; |
Shawn Lin | 802ac39 | 2016-05-04 09:43:24 +0800 | [diff] [blame] | 201 | |
Douglas Anderson | b2db9c6 | 2016-08-18 10:26:38 -0700 | [diff] [blame] | 202 | /* |
| 203 | * We'll now fall through to the below case with |
| 204 | * ctrl_phy = false (so we won't turn off/on). The |
| 205 | * sdhci_set_clock() will set the real clock. |
| 206 | */ |
| 207 | } else if (clock > PHY_CLK_TOO_SLOW_HZ) { |
| 208 | /* |
| 209 | * At higher clock speeds the PHY is fine being power |
| 210 | * cycled and docs say you _should_ power cycle when |
| 211 | * changing clock speeds. |
| 212 | */ |
| 213 | ctrl_phy = true; |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | if (ctrl_phy && sdhci_arasan->is_phy_on) { |
Shawn Lin | 802ac39 | 2016-05-04 09:43:24 +0800 | [diff] [blame] | 218 | spin_unlock_irq(&host->lock); |
| 219 | phy_power_off(sdhci_arasan->phy); |
| 220 | spin_lock_irq(&host->lock); |
Douglas Anderson | b2db9c6 | 2016-08-18 10:26:38 -0700 | [diff] [blame] | 221 | sdhci_arasan->is_phy_on = false; |
Shawn Lin | 802ac39 | 2016-05-04 09:43:24 +0800 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | sdhci_set_clock(host, clock); |
| 225 | |
Douglas Anderson | 6fc0924 | 2016-06-27 10:39:25 -0700 | [diff] [blame] | 226 | if (ctrl_phy) { |
Shawn Lin | 802ac39 | 2016-05-04 09:43:24 +0800 | [diff] [blame] | 227 | spin_unlock_irq(&host->lock); |
| 228 | phy_power_on(sdhci_arasan->phy); |
| 229 | spin_lock_irq(&host->lock); |
Douglas Anderson | b2db9c6 | 2016-08-18 10:26:38 -0700 | [diff] [blame] | 230 | sdhci_arasan->is_phy_on = true; |
Shawn Lin | 802ac39 | 2016-05-04 09:43:24 +0800 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | |
Shawn Lin | a05c846 | 2016-05-26 09:56:43 +0800 | [diff] [blame] | 234 | static void sdhci_arasan_hs400_enhanced_strobe(struct mmc_host *mmc, |
| 235 | struct mmc_ios *ios) |
| 236 | { |
| 237 | u32 vendor; |
| 238 | struct sdhci_host *host = mmc_priv(mmc); |
| 239 | |
| 240 | vendor = readl(host->ioaddr + SDHCI_ARASAN_VENDOR_REGISTER); |
| 241 | if (ios->enhanced_strobe) |
| 242 | vendor |= VENDOR_ENHANCED_STROBE; |
| 243 | else |
| 244 | vendor &= ~VENDOR_ENHANCED_STROBE; |
| 245 | |
| 246 | writel(vendor, host->ioaddr + SDHCI_ARASAN_VENDOR_REGISTER); |
| 247 | } |
| 248 | |
Wei Yongjun | 13d62fd | 2016-09-25 15:44:03 +0000 | [diff] [blame] | 249 | static void sdhci_arasan_reset(struct sdhci_host *host, u8 mask) |
Zach Brown | 3794c54 | 2016-09-16 10:01:42 -0500 | [diff] [blame] | 250 | { |
| 251 | u8 ctrl; |
| 252 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 253 | struct sdhci_arasan_data *sdhci_arasan = sdhci_pltfm_priv(pltfm_host); |
| 254 | |
| 255 | sdhci_reset(host, mask); |
| 256 | |
| 257 | if (sdhci_arasan->quirks & SDHCI_ARASAN_QUIRK_FORCE_CDTEST) { |
| 258 | ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); |
| 259 | ctrl |= SDHCI_CTRL_CDTEST_INS | SDHCI_CTRL_CDTEST_EN; |
| 260 | sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); |
| 261 | } |
| 262 | } |
| 263 | |
Shawn Lin | 8a3bee9 | 2016-09-30 14:19:00 +0800 | [diff] [blame] | 264 | static int sdhci_arasan_voltage_switch(struct mmc_host *mmc, |
| 265 | struct mmc_ios *ios) |
| 266 | { |
| 267 | switch (ios->signal_voltage) { |
| 268 | case MMC_SIGNAL_VOLTAGE_180: |
| 269 | /* |
| 270 | * Plese don't switch to 1V8 as arasan,5.1 doesn't |
| 271 | * actually refer to this setting to indicate the |
| 272 | * signal voltage and the state machine will be broken |
| 273 | * actually if we force to enable 1V8. That's something |
| 274 | * like broken quirk but we could work around here. |
| 275 | */ |
| 276 | return 0; |
| 277 | case MMC_SIGNAL_VOLTAGE_330: |
| 278 | case MMC_SIGNAL_VOLTAGE_120: |
| 279 | /* We don't support 3V3 and 1V2 */ |
| 280 | break; |
| 281 | } |
| 282 | |
| 283 | return -EINVAL; |
| 284 | } |
| 285 | |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 286 | static struct sdhci_ops sdhci_arasan_ops = { |
Shawn Lin | 802ac39 | 2016-05-04 09:43:24 +0800 | [diff] [blame] | 287 | .set_clock = sdhci_arasan_set_clock, |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 288 | .get_max_clock = sdhci_pltfm_clk_get_max_clock, |
| 289 | .get_timeout_clock = sdhci_arasan_get_timeout_clock, |
Russell King | 2317f56 | 2014-04-25 12:57:07 +0100 | [diff] [blame] | 290 | .set_bus_width = sdhci_set_bus_width, |
Zach Brown | 3794c54 | 2016-09-16 10:01:42 -0500 | [diff] [blame] | 291 | .reset = sdhci_arasan_reset, |
Russell King | 96d7b78 | 2014-04-25 12:59:26 +0100 | [diff] [blame] | 292 | .set_uhs_signaling = sdhci_set_uhs_signaling, |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 293 | }; |
| 294 | |
| 295 | static struct sdhci_pltfm_data sdhci_arasan_pdata = { |
| 296 | .ops = &sdhci_arasan_ops, |
Suneel Garapati | 2d532d4 | 2015-06-09 13:01:51 +0530 | [diff] [blame] | 297 | .quirks = SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN, |
| 298 | .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN | |
| 299 | SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN, |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 300 | }; |
| 301 | |
| 302 | #ifdef CONFIG_PM_SLEEP |
| 303 | /** |
| 304 | * sdhci_arasan_suspend - Suspend method for the driver |
| 305 | * @dev: Address of the device structure |
| 306 | * Returns 0 on success and error value on error |
| 307 | * |
| 308 | * Put the device in a low power state. |
| 309 | */ |
| 310 | static int sdhci_arasan_suspend(struct device *dev) |
| 311 | { |
| 312 | struct platform_device *pdev = to_platform_device(dev); |
| 313 | struct sdhci_host *host = platform_get_drvdata(pdev); |
| 314 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
Jisheng Zhang | 8921141 | 2016-02-16 21:08:24 +0800 | [diff] [blame] | 315 | struct sdhci_arasan_data *sdhci_arasan = sdhci_pltfm_priv(pltfm_host); |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 316 | int ret; |
| 317 | |
| 318 | ret = sdhci_suspend_host(host); |
| 319 | if (ret) |
| 320 | return ret; |
| 321 | |
Douglas Anderson | b2db9c6 | 2016-08-18 10:26:38 -0700 | [diff] [blame] | 322 | if (!IS_ERR(sdhci_arasan->phy) && sdhci_arasan->is_phy_on) { |
Shawn Lin | 91aa366 | 2016-03-07 23:39:19 +0800 | [diff] [blame] | 323 | ret = phy_power_off(sdhci_arasan->phy); |
| 324 | if (ret) { |
| 325 | dev_err(dev, "Cannot power off phy.\n"); |
| 326 | sdhci_resume_host(host); |
| 327 | return ret; |
| 328 | } |
Douglas Anderson | b2db9c6 | 2016-08-18 10:26:38 -0700 | [diff] [blame] | 329 | sdhci_arasan->is_phy_on = false; |
Shawn Lin | 91aa366 | 2016-03-07 23:39:19 +0800 | [diff] [blame] | 330 | } |
| 331 | |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 332 | clk_disable(pltfm_host->clk); |
| 333 | clk_disable(sdhci_arasan->clk_ahb); |
| 334 | |
| 335 | return 0; |
| 336 | } |
| 337 | |
| 338 | /** |
| 339 | * sdhci_arasan_resume - Resume method for the driver |
| 340 | * @dev: Address of the device structure |
| 341 | * Returns 0 on success and error value on error |
| 342 | * |
| 343 | * Resume operation after suspend |
| 344 | */ |
| 345 | static int sdhci_arasan_resume(struct device *dev) |
| 346 | { |
| 347 | struct platform_device *pdev = to_platform_device(dev); |
| 348 | struct sdhci_host *host = platform_get_drvdata(pdev); |
| 349 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
Jisheng Zhang | 8921141 | 2016-02-16 21:08:24 +0800 | [diff] [blame] | 350 | struct sdhci_arasan_data *sdhci_arasan = sdhci_pltfm_priv(pltfm_host); |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 351 | int ret; |
| 352 | |
| 353 | ret = clk_enable(sdhci_arasan->clk_ahb); |
| 354 | if (ret) { |
| 355 | dev_err(dev, "Cannot enable AHB clock.\n"); |
| 356 | return ret; |
| 357 | } |
| 358 | |
| 359 | ret = clk_enable(pltfm_host->clk); |
| 360 | if (ret) { |
| 361 | dev_err(dev, "Cannot enable SD clock.\n"); |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 362 | return ret; |
| 363 | } |
| 364 | |
Douglas Anderson | b2db9c6 | 2016-08-18 10:26:38 -0700 | [diff] [blame] | 365 | if (!IS_ERR(sdhci_arasan->phy) && host->mmc->actual_clock) { |
Shawn Lin | 91aa366 | 2016-03-07 23:39:19 +0800 | [diff] [blame] | 366 | ret = phy_power_on(sdhci_arasan->phy); |
| 367 | if (ret) { |
| 368 | dev_err(dev, "Cannot power on phy.\n"); |
| 369 | return ret; |
| 370 | } |
Douglas Anderson | b2db9c6 | 2016-08-18 10:26:38 -0700 | [diff] [blame] | 371 | sdhci_arasan->is_phy_on = true; |
Shawn Lin | 91aa366 | 2016-03-07 23:39:19 +0800 | [diff] [blame] | 372 | } |
| 373 | |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 374 | return sdhci_resume_host(host); |
| 375 | } |
| 376 | #endif /* ! CONFIG_PM_SLEEP */ |
| 377 | |
| 378 | static SIMPLE_DEV_PM_OPS(sdhci_arasan_dev_pm_ops, sdhci_arasan_suspend, |
| 379 | sdhci_arasan_resume); |
| 380 | |
Douglas Anderson | 3ea4666e | 2016-06-20 10:56:47 -0700 | [diff] [blame] | 381 | static const struct of_device_id sdhci_arasan_of_match[] = { |
| 382 | /* SoC-specific compatible strings w/ soc_ctl_map */ |
| 383 | { |
| 384 | .compatible = "rockchip,rk3399-sdhci-5.1", |
| 385 | .data = &rk3399_soc_ctl_map, |
| 386 | }, |
| 387 | |
| 388 | /* Generic compatible below here */ |
| 389 | { .compatible = "arasan,sdhci-8.9a" }, |
| 390 | { .compatible = "arasan,sdhci-5.1" }, |
| 391 | { .compatible = "arasan,sdhci-4.9a" }, |
| 392 | |
| 393 | { /* sentinel */ } |
| 394 | }; |
| 395 | MODULE_DEVICE_TABLE(of, sdhci_arasan_of_match); |
| 396 | |
| 397 | /** |
Douglas Anderson | c390f21 | 2016-06-20 10:56:50 -0700 | [diff] [blame] | 398 | * sdhci_arasan_sdcardclk_recalc_rate - Return the card clock rate |
| 399 | * |
| 400 | * Return the current actual rate of the SD card clock. This can be used |
| 401 | * to communicate with out PHY. |
| 402 | * |
| 403 | * @hw: Pointer to the hardware clock structure. |
| 404 | * @parent_rate The parent rate (should be rate of clk_xin). |
| 405 | * Returns the card clock rate. |
| 406 | */ |
| 407 | static unsigned long sdhci_arasan_sdcardclk_recalc_rate(struct clk_hw *hw, |
| 408 | unsigned long parent_rate) |
| 409 | |
| 410 | { |
| 411 | struct sdhci_arasan_data *sdhci_arasan = |
| 412 | container_of(hw, struct sdhci_arasan_data, sdcardclk_hw); |
| 413 | struct sdhci_host *host = sdhci_arasan->host; |
| 414 | |
| 415 | return host->mmc->actual_clock; |
| 416 | } |
| 417 | |
| 418 | static const struct clk_ops arasan_sdcardclk_ops = { |
| 419 | .recalc_rate = sdhci_arasan_sdcardclk_recalc_rate, |
| 420 | }; |
| 421 | |
| 422 | /** |
Shawn Lin | b2ca77c | 2016-08-26 16:51:15 +0800 | [diff] [blame] | 423 | * sdhci_arasan_update_clockmultiplier - Set corecfg_clockmultiplier |
| 424 | * |
| 425 | * The corecfg_clockmultiplier is supposed to contain clock multiplier |
| 426 | * value of programmable clock generator. |
| 427 | * |
| 428 | * NOTES: |
| 429 | * - Many existing devices don't seem to do this and work fine. To keep |
| 430 | * compatibility for old hardware where the device tree doesn't provide a |
| 431 | * register map, this function is a noop if a soc_ctl_map hasn't been provided |
| 432 | * for this platform. |
| 433 | * - The value of corecfg_clockmultiplier should sync with that of corresponding |
| 434 | * value reading from sdhci_capability_register. So this function is called |
| 435 | * once at probe time and never called again. |
| 436 | * |
| 437 | * @host: The sdhci_host |
| 438 | */ |
| 439 | static void sdhci_arasan_update_clockmultiplier(struct sdhci_host *host, |
| 440 | u32 value) |
| 441 | { |
| 442 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 443 | struct sdhci_arasan_data *sdhci_arasan = sdhci_pltfm_priv(pltfm_host); |
| 444 | const struct sdhci_arasan_soc_ctl_map *soc_ctl_map = |
| 445 | sdhci_arasan->soc_ctl_map; |
| 446 | |
| 447 | /* Having a map is optional */ |
| 448 | if (!soc_ctl_map) |
| 449 | return; |
| 450 | |
| 451 | /* If we have a map, we expect to have a syscon */ |
| 452 | if (!sdhci_arasan->soc_ctl_base) { |
| 453 | pr_warn("%s: Have regmap, but no soc-ctl-syscon\n", |
| 454 | mmc_hostname(host->mmc)); |
| 455 | return; |
| 456 | } |
| 457 | |
| 458 | sdhci_arasan_syscon_write(host, &soc_ctl_map->clockmultiplier, value); |
| 459 | } |
| 460 | |
| 461 | /** |
Douglas Anderson | 3ea4666e | 2016-06-20 10:56:47 -0700 | [diff] [blame] | 462 | * sdhci_arasan_update_baseclkfreq - Set corecfg_baseclkfreq |
| 463 | * |
| 464 | * The corecfg_baseclkfreq is supposed to contain the MHz of clk_xin. This |
| 465 | * function can be used to make that happen. |
| 466 | * |
| 467 | * NOTES: |
| 468 | * - Many existing devices don't seem to do this and work fine. To keep |
| 469 | * compatibility for old hardware where the device tree doesn't provide a |
| 470 | * register map, this function is a noop if a soc_ctl_map hasn't been provided |
| 471 | * for this platform. |
| 472 | * - It's assumed that clk_xin is not dynamic and that we use the SDHCI divider |
| 473 | * to achieve lower clock rates. That means that this function is called once |
| 474 | * at probe time and never called again. |
| 475 | * |
| 476 | * @host: The sdhci_host |
| 477 | */ |
| 478 | static void sdhci_arasan_update_baseclkfreq(struct sdhci_host *host) |
| 479 | { |
| 480 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 481 | struct sdhci_arasan_data *sdhci_arasan = sdhci_pltfm_priv(pltfm_host); |
| 482 | const struct sdhci_arasan_soc_ctl_map *soc_ctl_map = |
| 483 | sdhci_arasan->soc_ctl_map; |
| 484 | u32 mhz = DIV_ROUND_CLOSEST(clk_get_rate(pltfm_host->clk), 1000000); |
| 485 | |
| 486 | /* Having a map is optional */ |
| 487 | if (!soc_ctl_map) |
| 488 | return; |
| 489 | |
| 490 | /* If we have a map, we expect to have a syscon */ |
| 491 | if (!sdhci_arasan->soc_ctl_base) { |
| 492 | pr_warn("%s: Have regmap, but no soc-ctl-syscon\n", |
| 493 | mmc_hostname(host->mmc)); |
| 494 | return; |
| 495 | } |
| 496 | |
| 497 | sdhci_arasan_syscon_write(host, &soc_ctl_map->baseclkfreq, mhz); |
| 498 | } |
| 499 | |
Douglas Anderson | c390f21 | 2016-06-20 10:56:50 -0700 | [diff] [blame] | 500 | /** |
| 501 | * sdhci_arasan_register_sdclk - Register the sdclk for a PHY to use |
| 502 | * |
| 503 | * Some PHY devices need to know what the actual card clock is. In order for |
| 504 | * them to find out, we'll provide a clock through the common clock framework |
| 505 | * for them to query. |
| 506 | * |
| 507 | * Note: without seriously re-architecting SDHCI's clock code and testing on |
| 508 | * all platforms, there's no way to create a totally beautiful clock here |
| 509 | * with all clock ops implemented. Instead, we'll just create a clock that can |
| 510 | * be queried and set the CLK_GET_RATE_NOCACHE attribute to tell common clock |
| 511 | * framework that we're doing things behind its back. This should be sufficient |
| 512 | * to create nice clean device tree bindings and later (if needed) we can try |
| 513 | * re-architecting SDHCI if we see some benefit to it. |
| 514 | * |
| 515 | * @sdhci_arasan: Our private data structure. |
| 516 | * @clk_xin: Pointer to the functional clock |
| 517 | * @dev: Pointer to our struct device. |
| 518 | * Returns 0 on success and error value on error |
| 519 | */ |
| 520 | static int sdhci_arasan_register_sdclk(struct sdhci_arasan_data *sdhci_arasan, |
| 521 | struct clk *clk_xin, |
| 522 | struct device *dev) |
| 523 | { |
| 524 | struct device_node *np = dev->of_node; |
| 525 | struct clk_init_data sdcardclk_init; |
| 526 | const char *parent_clk_name; |
| 527 | int ret; |
| 528 | |
| 529 | /* Providing a clock to the PHY is optional; no error if missing */ |
| 530 | if (!of_find_property(np, "#clock-cells", NULL)) |
| 531 | return 0; |
| 532 | |
| 533 | ret = of_property_read_string_index(np, "clock-output-names", 0, |
| 534 | &sdcardclk_init.name); |
| 535 | if (ret) { |
| 536 | dev_err(dev, "DT has #clock-cells but no clock-output-names\n"); |
| 537 | return ret; |
| 538 | } |
| 539 | |
| 540 | parent_clk_name = __clk_get_name(clk_xin); |
| 541 | sdcardclk_init.parent_names = &parent_clk_name; |
| 542 | sdcardclk_init.num_parents = 1; |
| 543 | sdcardclk_init.flags = CLK_GET_RATE_NOCACHE; |
| 544 | sdcardclk_init.ops = &arasan_sdcardclk_ops; |
| 545 | |
| 546 | sdhci_arasan->sdcardclk_hw.init = &sdcardclk_init; |
| 547 | sdhci_arasan->sdcardclk = |
| 548 | devm_clk_register(dev, &sdhci_arasan->sdcardclk_hw); |
| 549 | sdhci_arasan->sdcardclk_hw.init = NULL; |
| 550 | |
| 551 | ret = of_clk_add_provider(np, of_clk_src_simple_get, |
| 552 | sdhci_arasan->sdcardclk); |
| 553 | if (ret) |
| 554 | dev_err(dev, "Failed to add clock provider\n"); |
| 555 | |
| 556 | return ret; |
| 557 | } |
| 558 | |
| 559 | /** |
| 560 | * sdhci_arasan_unregister_sdclk - Undoes sdhci_arasan_register_sdclk() |
| 561 | * |
| 562 | * Should be called any time we're exiting and sdhci_arasan_register_sdclk() |
| 563 | * returned success. |
| 564 | * |
| 565 | * @dev: Pointer to our struct device. |
| 566 | */ |
| 567 | static void sdhci_arasan_unregister_sdclk(struct device *dev) |
| 568 | { |
| 569 | struct device_node *np = dev->of_node; |
| 570 | |
| 571 | if (!of_find_property(np, "#clock-cells", NULL)) |
| 572 | return; |
| 573 | |
| 574 | of_clk_del_provider(dev->of_node); |
| 575 | } |
| 576 | |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 577 | static int sdhci_arasan_probe(struct platform_device *pdev) |
| 578 | { |
| 579 | int ret; |
Douglas Anderson | 3ea4666e | 2016-06-20 10:56:47 -0700 | [diff] [blame] | 580 | const struct of_device_id *match; |
| 581 | struct device_node *node; |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 582 | struct clk *clk_xin; |
| 583 | struct sdhci_host *host; |
| 584 | struct sdhci_pltfm_host *pltfm_host; |
| 585 | struct sdhci_arasan_data *sdhci_arasan; |
Zach Brown | 3794c54 | 2016-09-16 10:01:42 -0500 | [diff] [blame] | 586 | struct device_node *np = pdev->dev.of_node; |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 587 | |
Jisheng Zhang | 8921141 | 2016-02-16 21:08:24 +0800 | [diff] [blame] | 588 | host = sdhci_pltfm_init(pdev, &sdhci_arasan_pdata, |
| 589 | sizeof(*sdhci_arasan)); |
| 590 | if (IS_ERR(host)) |
| 591 | return PTR_ERR(host); |
| 592 | |
| 593 | pltfm_host = sdhci_priv(host); |
| 594 | sdhci_arasan = sdhci_pltfm_priv(pltfm_host); |
Douglas Anderson | c390f21 | 2016-06-20 10:56:50 -0700 | [diff] [blame] | 595 | sdhci_arasan->host = host; |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 596 | |
Douglas Anderson | 3ea4666e | 2016-06-20 10:56:47 -0700 | [diff] [blame] | 597 | match = of_match_node(sdhci_arasan_of_match, pdev->dev.of_node); |
| 598 | sdhci_arasan->soc_ctl_map = match->data; |
| 599 | |
| 600 | node = of_parse_phandle(pdev->dev.of_node, "arasan,soc-ctl-syscon", 0); |
| 601 | if (node) { |
| 602 | sdhci_arasan->soc_ctl_base = syscon_node_to_regmap(node); |
| 603 | of_node_put(node); |
| 604 | |
| 605 | if (IS_ERR(sdhci_arasan->soc_ctl_base)) { |
| 606 | ret = PTR_ERR(sdhci_arasan->soc_ctl_base); |
| 607 | if (ret != -EPROBE_DEFER) |
| 608 | dev_err(&pdev->dev, "Can't get syscon: %d\n", |
| 609 | ret); |
| 610 | goto err_pltfm_free; |
| 611 | } |
| 612 | } |
| 613 | |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 614 | sdhci_arasan->clk_ahb = devm_clk_get(&pdev->dev, "clk_ahb"); |
| 615 | if (IS_ERR(sdhci_arasan->clk_ahb)) { |
| 616 | dev_err(&pdev->dev, "clk_ahb clock not found.\n"); |
Shawn Lin | 278d096 | 2016-03-07 23:39:08 +0800 | [diff] [blame] | 617 | ret = PTR_ERR(sdhci_arasan->clk_ahb); |
| 618 | goto err_pltfm_free; |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | clk_xin = devm_clk_get(&pdev->dev, "clk_xin"); |
| 622 | if (IS_ERR(clk_xin)) { |
| 623 | dev_err(&pdev->dev, "clk_xin clock not found.\n"); |
Shawn Lin | 278d096 | 2016-03-07 23:39:08 +0800 | [diff] [blame] | 624 | ret = PTR_ERR(clk_xin); |
| 625 | goto err_pltfm_free; |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | ret = clk_prepare_enable(sdhci_arasan->clk_ahb); |
| 629 | if (ret) { |
| 630 | dev_err(&pdev->dev, "Unable to enable AHB clock.\n"); |
Shawn Lin | 278d096 | 2016-03-07 23:39:08 +0800 | [diff] [blame] | 631 | goto err_pltfm_free; |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | ret = clk_prepare_enable(clk_xin); |
| 635 | if (ret) { |
| 636 | dev_err(&pdev->dev, "Unable to enable SD clock.\n"); |
| 637 | goto clk_dis_ahb; |
| 638 | } |
| 639 | |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 640 | sdhci_get_of_property(pdev); |
Zach Brown | 3794c54 | 2016-09-16 10:01:42 -0500 | [diff] [blame] | 641 | |
| 642 | if (of_property_read_bool(np, "xlnx,fails-without-test-cd")) |
| 643 | sdhci_arasan->quirks |= SDHCI_ARASAN_QUIRK_FORCE_CDTEST; |
| 644 | |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 645 | pltfm_host->clk = clk_xin; |
| 646 | |
Shawn Lin | b2ca77c | 2016-08-26 16:51:15 +0800 | [diff] [blame] | 647 | if (of_device_is_compatible(pdev->dev.of_node, |
| 648 | "rockchip,rk3399-sdhci-5.1")) |
| 649 | sdhci_arasan_update_clockmultiplier(host, 0x0); |
| 650 | |
Douglas Anderson | 3ea4666e | 2016-06-20 10:56:47 -0700 | [diff] [blame] | 651 | sdhci_arasan_update_baseclkfreq(host); |
| 652 | |
Douglas Anderson | c390f21 | 2016-06-20 10:56:50 -0700 | [diff] [blame] | 653 | ret = sdhci_arasan_register_sdclk(sdhci_arasan, clk_xin, &pdev->dev); |
| 654 | if (ret) |
| 655 | goto clk_disable_all; |
| 656 | |
Michal Simek | 16b2378 | 2015-04-07 07:57:32 +0200 | [diff] [blame] | 657 | ret = mmc_of_parse(host->mmc); |
| 658 | if (ret) { |
| 659 | dev_err(&pdev->dev, "parsing dt failed (%u)\n", ret); |
Douglas Anderson | c390f21 | 2016-06-20 10:56:50 -0700 | [diff] [blame] | 660 | goto unreg_clk; |
Michal Simek | 16b2378 | 2015-04-07 07:57:32 +0200 | [diff] [blame] | 661 | } |
| 662 | |
Shawn Lin | 91aa366 | 2016-03-07 23:39:19 +0800 | [diff] [blame] | 663 | sdhci_arasan->phy = ERR_PTR(-ENODEV); |
| 664 | if (of_device_is_compatible(pdev->dev.of_node, |
| 665 | "arasan,sdhci-5.1")) { |
| 666 | sdhci_arasan->phy = devm_phy_get(&pdev->dev, |
| 667 | "phy_arasan"); |
| 668 | if (IS_ERR(sdhci_arasan->phy)) { |
| 669 | ret = PTR_ERR(sdhci_arasan->phy); |
| 670 | dev_err(&pdev->dev, "No phy for arasan,sdhci-5.1.\n"); |
Douglas Anderson | c390f21 | 2016-06-20 10:56:50 -0700 | [diff] [blame] | 671 | goto unreg_clk; |
Shawn Lin | 91aa366 | 2016-03-07 23:39:19 +0800 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | ret = phy_init(sdhci_arasan->phy); |
| 675 | if (ret < 0) { |
| 676 | dev_err(&pdev->dev, "phy_init err.\n"); |
Douglas Anderson | c390f21 | 2016-06-20 10:56:50 -0700 | [diff] [blame] | 677 | goto unreg_clk; |
Shawn Lin | 91aa366 | 2016-03-07 23:39:19 +0800 | [diff] [blame] | 678 | } |
| 679 | |
Shawn Lin | a05c846 | 2016-05-26 09:56:43 +0800 | [diff] [blame] | 680 | host->mmc_host_ops.hs400_enhanced_strobe = |
| 681 | sdhci_arasan_hs400_enhanced_strobe; |
Shawn Lin | 8a3bee9 | 2016-09-30 14:19:00 +0800 | [diff] [blame] | 682 | host->mmc_host_ops.start_signal_voltage_switch = |
| 683 | sdhci_arasan_voltage_switch; |
Shawn Lin | 91aa366 | 2016-03-07 23:39:19 +0800 | [diff] [blame] | 684 | } |
| 685 | |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 686 | ret = sdhci_add_host(host); |
Mike Looijmans | b1df9de | 2014-10-28 08:53:21 +0100 | [diff] [blame] | 687 | if (ret) |
Shawn Lin | 91aa366 | 2016-03-07 23:39:19 +0800 | [diff] [blame] | 688 | goto err_add_host; |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 689 | |
| 690 | return 0; |
| 691 | |
Shawn Lin | 91aa366 | 2016-03-07 23:39:19 +0800 | [diff] [blame] | 692 | err_add_host: |
| 693 | if (!IS_ERR(sdhci_arasan->phy)) |
Shawn Lin | 91aa366 | 2016-03-07 23:39:19 +0800 | [diff] [blame] | 694 | phy_exit(sdhci_arasan->phy); |
Douglas Anderson | c390f21 | 2016-06-20 10:56:50 -0700 | [diff] [blame] | 695 | unreg_clk: |
| 696 | sdhci_arasan_unregister_sdclk(&pdev->dev); |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 697 | clk_disable_all: |
| 698 | clk_disable_unprepare(clk_xin); |
| 699 | clk_dis_ahb: |
| 700 | clk_disable_unprepare(sdhci_arasan->clk_ahb); |
Shawn Lin | 278d096 | 2016-03-07 23:39:08 +0800 | [diff] [blame] | 701 | err_pltfm_free: |
| 702 | sdhci_pltfm_free(pdev); |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 703 | return ret; |
| 704 | } |
| 705 | |
| 706 | static int sdhci_arasan_remove(struct platform_device *pdev) |
| 707 | { |
Jisheng Zhang | 0c7fe32 | 2016-02-16 21:08:23 +0800 | [diff] [blame] | 708 | int ret; |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 709 | struct sdhci_host *host = platform_get_drvdata(pdev); |
| 710 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
Jisheng Zhang | 8921141 | 2016-02-16 21:08:24 +0800 | [diff] [blame] | 711 | struct sdhci_arasan_data *sdhci_arasan = sdhci_pltfm_priv(pltfm_host); |
| 712 | struct clk *clk_ahb = sdhci_arasan->clk_ahb; |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 713 | |
Shawn Lin | 91aa366 | 2016-03-07 23:39:19 +0800 | [diff] [blame] | 714 | if (!IS_ERR(sdhci_arasan->phy)) { |
Douglas Anderson | b2db9c6 | 2016-08-18 10:26:38 -0700 | [diff] [blame] | 715 | if (sdhci_arasan->is_phy_on) |
| 716 | phy_power_off(sdhci_arasan->phy); |
Shawn Lin | 91aa366 | 2016-03-07 23:39:19 +0800 | [diff] [blame] | 717 | phy_exit(sdhci_arasan->phy); |
| 718 | } |
| 719 | |
Douglas Anderson | c390f21 | 2016-06-20 10:56:50 -0700 | [diff] [blame] | 720 | sdhci_arasan_unregister_sdclk(&pdev->dev); |
| 721 | |
Jisheng Zhang | 0c7fe32 | 2016-02-16 21:08:23 +0800 | [diff] [blame] | 722 | ret = sdhci_pltfm_unregister(pdev); |
| 723 | |
Jisheng Zhang | 8921141 | 2016-02-16 21:08:24 +0800 | [diff] [blame] | 724 | clk_disable_unprepare(clk_ahb); |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 725 | |
Jisheng Zhang | 0c7fe32 | 2016-02-16 21:08:23 +0800 | [diff] [blame] | 726 | return ret; |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 727 | } |
| 728 | |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 729 | static struct platform_driver sdhci_arasan_driver = { |
| 730 | .driver = { |
| 731 | .name = "sdhci-arasan", |
Soren Brinkmann | e3ec3a3 | 2013-12-02 10:02:36 -0800 | [diff] [blame] | 732 | .of_match_table = sdhci_arasan_of_match, |
| 733 | .pm = &sdhci_arasan_dev_pm_ops, |
| 734 | }, |
| 735 | .probe = sdhci_arasan_probe, |
| 736 | .remove = sdhci_arasan_remove, |
| 737 | }; |
| 738 | |
| 739 | module_platform_driver(sdhci_arasan_driver); |
| 740 | |
| 741 | MODULE_DESCRIPTION("Driver for the Arasan SDHCI Controller"); |
| 742 | MODULE_AUTHOR("Soeren Brinkmann <soren.brinkmann@xilinx.com>"); |
| 743 | MODULE_LICENSE("GPL"); |