1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Arasan Secure Digital Host Controller Interface.
4 * Copyright (C) 2011 - 2012 Michal Simek <monstr@monstr.eu>
5 * Copyright (c) 2012 Wind River Systems, Inc.
6 * Copyright (C) 2013 Pengutronix e.K.
7 * Copyright (C) 2013 Xilinx Inc.
9 * Based on sdhci-of-esdhc.c
11 * Copyright (c) 2007 Freescale Semiconductor, Inc.
12 * Copyright (c) 2009 MontaVista Software, Inc.
14 * Authors: Xiaobo Xie <X.Xie@freescale.com>
15 * Anton Vorontsov <avorontsov@ru.mvista.com>
18 #include <linux/clk-provider.h>
19 #include <linux/mfd/syscon.h>
20 #include <linux/module.h>
21 #include <linux/of_device.h>
22 #include <linux/phy/phy.h>
23 #include <linux/regmap.h>
25 #include <linux/firmware/xlnx-zynqmp.h>
28 #include "sdhci-pltfm.h"
30 #define SDHCI_ARASAN_VENDOR_REGISTER 0x78
31 #define SDHCI_ARASAN_CQE_BASE_ADDR 0x200
32 #define VENDOR_ENHANCED_STROBE BIT(0)
34 #define PHY_CLK_TOO_SLOW_HZ 400000
36 /* Default settings for ZynqMP Clock Phases */
37 #define ZYNQMP_ICLK_PHASE {0, 63, 63, 0, 63, 0, 0, 183, 54, 0, 0}
38 #define ZYNQMP_OCLK_PHASE {0, 72, 60, 0, 60, 72, 135, 48, 72, 135, 0}
41 * On some SoCs the syscon area has a feature where the upper 16-bits of
42 * each 32-bit register act as a write mask for the lower 16-bits. This allows
43 * atomic updates of the register without locking. This macro is used on SoCs
44 * that have that feature.
46 #define HIWORD_UPDATE(val, mask, shift) \
47 ((val) << (shift) | (mask) << ((shift) + 16))
50 * struct sdhci_arasan_soc_ctl_field - Field used in sdhci_arasan_soc_ctl_map
52 * @reg: Offset within the syscon of the register containing this field
53 * @width: Number of bits for this field
54 * @shift: Bit offset within @reg of this field (or -1 if not avail)
56 struct sdhci_arasan_soc_ctl_field
{
63 * struct sdhci_arasan_soc_ctl_map - Map in syscon to corecfg registers
65 * It's up to the licensee of the Arsan IP block to make these available
66 * somewhere if needed. Presumably these will be scattered somewhere that's
67 * accessible via the syscon API.
69 * @baseclkfreq: Where to find corecfg_baseclkfreq
70 * @clockmultiplier: Where to find corecfg_clockmultiplier
71 * @hiword_update: If true, use HIWORD_UPDATE to access the syscon
73 struct sdhci_arasan_soc_ctl_map
{
74 struct sdhci_arasan_soc_ctl_field baseclkfreq
;
75 struct sdhci_arasan_soc_ctl_field clockmultiplier
;
80 * struct sdhci_arasan_clk_data
81 * @sdcardclk_hw: Struct for the clock we might provide to a PHY.
82 * @sdcardclk: Pointer to normal 'struct clock' for sdcardclk_hw.
83 * @sampleclk_hw: Struct for the clock we might provide to a PHY.
84 * @sampleclk: Pointer to normal 'struct clock' for sampleclk_hw.
85 * @clk_phase_in: Array of Input Clock Phase Delays for all speed modes
86 * @clk_phase_out: Array of Output Clock Phase Delays for all speed modes
87 * @set_clk_delays: Function pointer for setting Clock Delays
88 * @clk_of_data: Platform specific runtime clock data storage pointer
90 struct sdhci_arasan_clk_data
{
91 struct clk_hw sdcardclk_hw
;
92 struct clk
*sdcardclk
;
93 struct clk_hw sampleclk_hw
;
94 struct clk
*sampleclk
;
95 int clk_phase_in
[MMC_TIMING_MMC_HS400
+ 1];
96 int clk_phase_out
[MMC_TIMING_MMC_HS400
+ 1];
97 void (*set_clk_delays
)(struct sdhci_host
*host
);
101 struct sdhci_arasan_zynqmp_clk_data
{
102 const struct zynqmp_eemi_ops
*eemi_ops
;
106 * struct sdhci_arasan_data
107 * @host: Pointer to the main SDHCI host structure.
108 * @clk_ahb: Pointer to the AHB clock
109 * @phy: Pointer to the generic phy
110 * @is_phy_on: True if the PHY is on; false if not.
111 * @clk_data: Struct for the Arasan Controller Clock Data.
112 * @soc_ctl_base: Pointer to regmap for syscon for soc_ctl registers.
113 * @soc_ctl_map: Map to get offsets into soc_ctl registers.
115 struct sdhci_arasan_data
{
116 struct sdhci_host
*host
;
122 struct sdhci_arasan_clk_data clk_data
;
124 struct regmap
*soc_ctl_base
;
125 const struct sdhci_arasan_soc_ctl_map
*soc_ctl_map
;
126 unsigned int quirks
; /* Arasan deviations from spec */
128 /* Controller does not have CD wired and will not function normally without */
129 #define SDHCI_ARASAN_QUIRK_FORCE_CDTEST BIT(0)
130 /* Controller immediately reports SDHCI_CLOCK_INT_STABLE after enabling the
131 * internal clock even when the clock isn't stable */
132 #define SDHCI_ARASAN_QUIRK_CLOCK_UNSTABLE BIT(1)
135 struct sdhci_arasan_of_data
{
136 const struct sdhci_arasan_soc_ctl_map
*soc_ctl_map
;
137 const struct sdhci_pltfm_data
*pdata
;
140 static const struct sdhci_arasan_soc_ctl_map rk3399_soc_ctl_map
= {
141 .baseclkfreq
= { .reg
= 0xf000, .width
= 8, .shift
= 8 },
142 .clockmultiplier
= { .reg
= 0xf02c, .width
= 8, .shift
= 0},
143 .hiword_update
= true,
146 static const struct sdhci_arasan_soc_ctl_map intel_lgm_emmc_soc_ctl_map
= {
147 .baseclkfreq
= { .reg
= 0xa0, .width
= 8, .shift
= 2 },
148 .clockmultiplier
= { .reg
= 0, .width
= -1, .shift
= -1 },
149 .hiword_update
= false,
152 static const struct sdhci_arasan_soc_ctl_map intel_lgm_sdxc_soc_ctl_map
= {
153 .baseclkfreq
= { .reg
= 0x80, .width
= 8, .shift
= 2 },
154 .clockmultiplier
= { .reg
= 0, .width
= -1, .shift
= -1 },
155 .hiword_update
= false,
159 * sdhci_arasan_syscon_write - Write to a field in soc_ctl registers
161 * This function allows writing to fields in sdhci_arasan_soc_ctl_map.
162 * Note that if a field is specified as not available (shift < 0) then
163 * this function will silently return an error code. It will be noisy
164 * and print errors for any other (unexpected) errors.
166 * @host: The sdhci_host
167 * @fld: The field to write to
168 * @val: The value to write
170 static int sdhci_arasan_syscon_write(struct sdhci_host
*host
,
171 const struct sdhci_arasan_soc_ctl_field
*fld
,
174 struct sdhci_pltfm_host
*pltfm_host
= sdhci_priv(host
);
175 struct sdhci_arasan_data
*sdhci_arasan
= sdhci_pltfm_priv(pltfm_host
);
176 struct regmap
*soc_ctl_base
= sdhci_arasan
->soc_ctl_base
;
178 u16 width
= fld
->width
;
179 s16 shift
= fld
->shift
;
183 * Silently return errors for shift < 0 so caller doesn't have
184 * to check for fields which are optional. For fields that
185 * are required then caller needs to do something special
191 if (sdhci_arasan
->soc_ctl_map
->hiword_update
)
192 ret
= regmap_write(soc_ctl_base
, reg
,
193 HIWORD_UPDATE(val
, GENMASK(width
, 0),
196 ret
= regmap_update_bits(soc_ctl_base
, reg
,
197 GENMASK(shift
+ width
, shift
),
200 /* Yell about (unexpected) regmap errors */
202 pr_warn("%s: Regmap write fail: %d\n",
203 mmc_hostname(host
->mmc
), ret
);
208 static void sdhci_arasan_set_clock(struct sdhci_host
*host
, unsigned int clock
)
210 struct sdhci_pltfm_host
*pltfm_host
= sdhci_priv(host
);
211 struct sdhci_arasan_data
*sdhci_arasan
= sdhci_pltfm_priv(pltfm_host
);
212 struct sdhci_arasan_clk_data
*clk_data
= &sdhci_arasan
->clk_data
;
213 bool ctrl_phy
= false;
215 if (!IS_ERR(sdhci_arasan
->phy
)) {
216 if (!sdhci_arasan
->is_phy_on
&& clock
<= PHY_CLK_TOO_SLOW_HZ
) {
218 * If PHY off, set clock to max speed and power PHY on.
220 * Although PHY docs apparently suggest power cycling
221 * when changing the clock the PHY doesn't like to be
222 * powered on while at low speeds like those used in ID
223 * mode. Even worse is powering the PHY on while the
226 * To workaround the PHY limitations, the best we can
227 * do is to power it on at a faster speed and then slam
228 * through low speeds without power cycling.
230 sdhci_set_clock(host
, host
->max_clk
);
231 phy_power_on(sdhci_arasan
->phy
);
232 sdhci_arasan
->is_phy_on
= true;
235 * We'll now fall through to the below case with
236 * ctrl_phy = false (so we won't turn off/on). The
237 * sdhci_set_clock() will set the real clock.
239 } else if (clock
> PHY_CLK_TOO_SLOW_HZ
) {
241 * At higher clock speeds the PHY is fine being power
242 * cycled and docs say you _should_ power cycle when
243 * changing clock speeds.
249 if (ctrl_phy
&& sdhci_arasan
->is_phy_on
) {
250 phy_power_off(sdhci_arasan
->phy
);
251 sdhci_arasan
->is_phy_on
= false;
254 /* Set the Input and Output Clock Phase Delays */
255 if (clk_data
->set_clk_delays
)
256 clk_data
->set_clk_delays(host
);
258 sdhci_set_clock(host
, clock
);
260 if (sdhci_arasan
->quirks
& SDHCI_ARASAN_QUIRK_CLOCK_UNSTABLE
)
262 * Some controllers immediately report SDHCI_CLOCK_INT_STABLE
263 * after enabling the clock even though the clock is not
264 * stable. Trying to use a clock without waiting here results
265 * in EILSEQ while detecting some older/slower cards. The
266 * chosen delay is the maximum delay from sdhci_set_clock.
271 phy_power_on(sdhci_arasan
->phy
);
272 sdhci_arasan
->is_phy_on
= true;
276 static void sdhci_arasan_hs400_enhanced_strobe(struct mmc_host
*mmc
,
280 struct sdhci_host
*host
= mmc_priv(mmc
);
282 vendor
= sdhci_readl(host
, SDHCI_ARASAN_VENDOR_REGISTER
);
283 if (ios
->enhanced_strobe
)
284 vendor
|= VENDOR_ENHANCED_STROBE
;
286 vendor
&= ~VENDOR_ENHANCED_STROBE
;
288 sdhci_writel(host
, vendor
, SDHCI_ARASAN_VENDOR_REGISTER
);
291 static void sdhci_arasan_reset(struct sdhci_host
*host
, u8 mask
)
294 struct sdhci_pltfm_host
*pltfm_host
= sdhci_priv(host
);
295 struct sdhci_arasan_data
*sdhci_arasan
= sdhci_pltfm_priv(pltfm_host
);
297 sdhci_reset(host
, mask
);
299 if (sdhci_arasan
->quirks
& SDHCI_ARASAN_QUIRK_FORCE_CDTEST
) {
300 ctrl
= sdhci_readb(host
, SDHCI_HOST_CONTROL
);
301 ctrl
|= SDHCI_CTRL_CDTEST_INS
| SDHCI_CTRL_CDTEST_EN
;
302 sdhci_writeb(host
, ctrl
, SDHCI_HOST_CONTROL
);
306 static int sdhci_arasan_voltage_switch(struct mmc_host
*mmc
,
309 switch (ios
->signal_voltage
) {
310 case MMC_SIGNAL_VOLTAGE_180
:
312 * Plese don't switch to 1V8 as arasan,5.1 doesn't
313 * actually refer to this setting to indicate the
314 * signal voltage and the state machine will be broken
315 * actually if we force to enable 1V8. That's something
316 * like broken quirk but we could work around here.
319 case MMC_SIGNAL_VOLTAGE_330
:
320 case MMC_SIGNAL_VOLTAGE_120
:
321 /* We don't support 3V3 and 1V2 */
328 static void sdhci_arasan_set_power(struct sdhci_host
*host
, unsigned char mode
,
331 if (!IS_ERR(host
->mmc
->supply
.vmmc
)) {
332 struct mmc_host
*mmc
= host
->mmc
;
334 mmc_regulator_set_ocr(mmc
, mmc
->supply
.vmmc
, vdd
);
336 sdhci_set_power_noreg(host
, mode
, vdd
);
339 static const struct sdhci_ops sdhci_arasan_ops
= {
340 .set_clock
= sdhci_arasan_set_clock
,
341 .get_max_clock
= sdhci_pltfm_clk_get_max_clock
,
342 .get_timeout_clock
= sdhci_pltfm_clk_get_max_clock
,
343 .set_bus_width
= sdhci_set_bus_width
,
344 .reset
= sdhci_arasan_reset
,
345 .set_uhs_signaling
= sdhci_set_uhs_signaling
,
346 .set_power
= sdhci_arasan_set_power
,
349 static const struct sdhci_pltfm_data sdhci_arasan_pdata
= {
350 .ops
= &sdhci_arasan_ops
,
351 .quirks
= SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN
,
352 .quirks2
= SDHCI_QUIRK2_PRESET_VALUE_BROKEN
|
353 SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN
|
354 SDHCI_QUIRK2_STOP_WITH_TC
,
357 static struct sdhci_arasan_of_data sdhci_arasan_data
= {
358 .pdata
= &sdhci_arasan_pdata
,
361 static u32
sdhci_arasan_cqhci_irq(struct sdhci_host
*host
, u32 intmask
)
366 if (!sdhci_cqe_irq(host
, intmask
, &cmd_error
, &data_error
))
369 cqhci_irq(host
->mmc
, intmask
, cmd_error
, data_error
);
374 static void sdhci_arasan_dumpregs(struct mmc_host
*mmc
)
376 sdhci_dumpregs(mmc_priv(mmc
));
379 static void sdhci_arasan_cqe_enable(struct mmc_host
*mmc
)
381 struct sdhci_host
*host
= mmc_priv(mmc
);
384 reg
= sdhci_readl(host
, SDHCI_PRESENT_STATE
);
385 while (reg
& SDHCI_DATA_AVAILABLE
) {
386 sdhci_readl(host
, SDHCI_BUFFER
);
387 reg
= sdhci_readl(host
, SDHCI_PRESENT_STATE
);
390 sdhci_cqe_enable(mmc
);
393 static const struct cqhci_host_ops sdhci_arasan_cqhci_ops
= {
394 .enable
= sdhci_arasan_cqe_enable
,
395 .disable
= sdhci_cqe_disable
,
396 .dumpregs
= sdhci_arasan_dumpregs
,
399 static const struct sdhci_ops sdhci_arasan_cqe_ops
= {
400 .set_clock
= sdhci_arasan_set_clock
,
401 .get_max_clock
= sdhci_pltfm_clk_get_max_clock
,
402 .get_timeout_clock
= sdhci_pltfm_clk_get_max_clock
,
403 .set_bus_width
= sdhci_set_bus_width
,
404 .reset
= sdhci_arasan_reset
,
405 .set_uhs_signaling
= sdhci_set_uhs_signaling
,
406 .set_power
= sdhci_arasan_set_power
,
407 .irq
= sdhci_arasan_cqhci_irq
,
410 static const struct sdhci_pltfm_data sdhci_arasan_cqe_pdata
= {
411 .ops
= &sdhci_arasan_cqe_ops
,
412 .quirks
= SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN
,
413 .quirks2
= SDHCI_QUIRK2_PRESET_VALUE_BROKEN
|
414 SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN
,
417 static struct sdhci_arasan_of_data sdhci_arasan_rk3399_data
= {
418 .soc_ctl_map
= &rk3399_soc_ctl_map
,
419 .pdata
= &sdhci_arasan_cqe_pdata
,
422 static struct sdhci_arasan_of_data intel_lgm_emmc_data
= {
423 .soc_ctl_map
= &intel_lgm_emmc_soc_ctl_map
,
424 .pdata
= &sdhci_arasan_cqe_pdata
,
427 static struct sdhci_arasan_of_data intel_lgm_sdxc_data
= {
428 .soc_ctl_map
= &intel_lgm_sdxc_soc_ctl_map
,
429 .pdata
= &sdhci_arasan_cqe_pdata
,
432 #ifdef CONFIG_PM_SLEEP
434 * sdhci_arasan_suspend - Suspend method for the driver
435 * @dev: Address of the device structure
436 * Returns 0 on success and error value on error
438 * Put the device in a low power state.
440 static int sdhci_arasan_suspend(struct device
*dev
)
442 struct sdhci_host
*host
= dev_get_drvdata(dev
);
443 struct sdhci_pltfm_host
*pltfm_host
= sdhci_priv(host
);
444 struct sdhci_arasan_data
*sdhci_arasan
= sdhci_pltfm_priv(pltfm_host
);
447 if (host
->tuning_mode
!= SDHCI_TUNING_MODE_3
)
448 mmc_retune_needed(host
->mmc
);
450 if (sdhci_arasan
->has_cqe
) {
451 ret
= cqhci_suspend(host
->mmc
);
456 ret
= sdhci_suspend_host(host
);
460 if (!IS_ERR(sdhci_arasan
->phy
) && sdhci_arasan
->is_phy_on
) {
461 ret
= phy_power_off(sdhci_arasan
->phy
);
463 dev_err(dev
, "Cannot power off phy.\n");
464 sdhci_resume_host(host
);
467 sdhci_arasan
->is_phy_on
= false;
470 clk_disable(pltfm_host
->clk
);
471 clk_disable(sdhci_arasan
->clk_ahb
);
477 * sdhci_arasan_resume - Resume method for the driver
478 * @dev: Address of the device structure
479 * Returns 0 on success and error value on error
481 * Resume operation after suspend
483 static int sdhci_arasan_resume(struct device
*dev
)
485 struct sdhci_host
*host
= dev_get_drvdata(dev
);
486 struct sdhci_pltfm_host
*pltfm_host
= sdhci_priv(host
);
487 struct sdhci_arasan_data
*sdhci_arasan
= sdhci_pltfm_priv(pltfm_host
);
490 ret
= clk_enable(sdhci_arasan
->clk_ahb
);
492 dev_err(dev
, "Cannot enable AHB clock.\n");
496 ret
= clk_enable(pltfm_host
->clk
);
498 dev_err(dev
, "Cannot enable SD clock.\n");
502 if (!IS_ERR(sdhci_arasan
->phy
) && host
->mmc
->actual_clock
) {
503 ret
= phy_power_on(sdhci_arasan
->phy
);
505 dev_err(dev
, "Cannot power on phy.\n");
508 sdhci_arasan
->is_phy_on
= true;
511 ret
= sdhci_resume_host(host
);
513 dev_err(dev
, "Cannot resume host.\n");
517 if (sdhci_arasan
->has_cqe
)
518 return cqhci_resume(host
->mmc
);
522 #endif /* ! CONFIG_PM_SLEEP */
524 static SIMPLE_DEV_PM_OPS(sdhci_arasan_dev_pm_ops
, sdhci_arasan_suspend
,
525 sdhci_arasan_resume
);
527 static const struct of_device_id sdhci_arasan_of_match
[] = {
528 /* SoC-specific compatible strings w/ soc_ctl_map */
530 .compatible
= "rockchip,rk3399-sdhci-5.1",
531 .data
= &sdhci_arasan_rk3399_data
,
534 .compatible
= "intel,lgm-sdhci-5.1-emmc",
535 .data
= &intel_lgm_emmc_data
,
538 .compatible
= "intel,lgm-sdhci-5.1-sdxc",
539 .data
= &intel_lgm_sdxc_data
,
541 /* Generic compatible below here */
543 .compatible
= "arasan,sdhci-8.9a",
544 .data
= &sdhci_arasan_data
,
547 .compatible
= "arasan,sdhci-5.1",
548 .data
= &sdhci_arasan_data
,
551 .compatible
= "arasan,sdhci-4.9a",
552 .data
= &sdhci_arasan_data
,
555 .compatible
= "xlnx,zynqmp-8.9a",
556 .data
= &sdhci_arasan_data
,
560 MODULE_DEVICE_TABLE(of
, sdhci_arasan_of_match
);
563 * sdhci_arasan_sdcardclk_recalc_rate - Return the card clock rate
565 * Return the current actual rate of the SD card clock. This can be used
566 * to communicate with out PHY.
568 * @hw: Pointer to the hardware clock structure.
569 * @parent_rate The parent rate (should be rate of clk_xin).
570 * Returns the card clock rate.
572 static unsigned long sdhci_arasan_sdcardclk_recalc_rate(struct clk_hw
*hw
,
573 unsigned long parent_rate
)
576 struct sdhci_arasan_clk_data
*clk_data
=
577 container_of(hw
, struct sdhci_arasan_clk_data
, sdcardclk_hw
);
578 struct sdhci_arasan_data
*sdhci_arasan
=
579 container_of(clk_data
, struct sdhci_arasan_data
, clk_data
);
580 struct sdhci_host
*host
= sdhci_arasan
->host
;
582 return host
->mmc
->actual_clock
;
585 static const struct clk_ops arasan_sdcardclk_ops
= {
586 .recalc_rate
= sdhci_arasan_sdcardclk_recalc_rate
,
590 * sdhci_arasan_sampleclk_recalc_rate - Return the sampling clock rate
592 * Return the current actual rate of the sampling clock. This can be used
593 * to communicate with out PHY.
595 * @hw: Pointer to the hardware clock structure.
596 * @parent_rate The parent rate (should be rate of clk_xin).
597 * Returns the sample clock rate.
599 static unsigned long sdhci_arasan_sampleclk_recalc_rate(struct clk_hw
*hw
,
600 unsigned long parent_rate
)
603 struct sdhci_arasan_clk_data
*clk_data
=
604 container_of(hw
, struct sdhci_arasan_clk_data
, sampleclk_hw
);
605 struct sdhci_arasan_data
*sdhci_arasan
=
606 container_of(clk_data
, struct sdhci_arasan_data
, clk_data
);
607 struct sdhci_host
*host
= sdhci_arasan
->host
;
609 return host
->mmc
->actual_clock
;
612 static const struct clk_ops arasan_sampleclk_ops
= {
613 .recalc_rate
= sdhci_arasan_sampleclk_recalc_rate
,
617 * sdhci_zynqmp_sdcardclk_set_phase - Set the SD Output Clock Tap Delays
619 * Set the SD Output Clock Tap Delays for Output path
621 * @hw: Pointer to the hardware clock structure.
622 * @degrees The clock phase shift between 0 - 359.
623 * Return: 0 on success and error value on error
625 static int sdhci_zynqmp_sdcardclk_set_phase(struct clk_hw
*hw
, int degrees
)
628 struct sdhci_arasan_clk_data
*clk_data
=
629 container_of(hw
, struct sdhci_arasan_clk_data
, sdcardclk_hw
);
630 struct sdhci_arasan_data
*sdhci_arasan
=
631 container_of(clk_data
, struct sdhci_arasan_data
, clk_data
);
632 struct sdhci_host
*host
= sdhci_arasan
->host
;
633 struct sdhci_arasan_zynqmp_clk_data
*zynqmp_clk_data
=
634 clk_data
->clk_of_data
;
635 const struct zynqmp_eemi_ops
*eemi_ops
= zynqmp_clk_data
->eemi_ops
;
636 const char *clk_name
= clk_hw_get_name(hw
);
637 u32 node_id
= !strcmp(clk_name
, "clk_out_sd0") ? NODE_SD_0
: NODE_SD_1
;
638 u8 tap_delay
, tap_max
= 0;
642 * This is applicable for SDHCI_SPEC_300 and above
643 * ZynqMP does not set phase for <=25MHz clock.
644 * If degrees is zero, no need to do anything.
646 if (host
->version
< SDHCI_SPEC_300
||
647 host
->timing
== MMC_TIMING_LEGACY
||
648 host
->timing
== MMC_TIMING_UHS_SDR12
|| !degrees
)
651 switch (host
->timing
) {
652 case MMC_TIMING_MMC_HS
:
653 case MMC_TIMING_SD_HS
:
654 case MMC_TIMING_UHS_SDR25
:
655 case MMC_TIMING_UHS_DDR50
:
656 case MMC_TIMING_MMC_DDR52
:
657 /* For 50MHz clock, 30 Taps are available */
660 case MMC_TIMING_UHS_SDR50
:
661 /* For 100MHz clock, 15 Taps are available */
664 case MMC_TIMING_UHS_SDR104
:
665 case MMC_TIMING_MMC_HS200
:
666 /* For 200MHz clock, 8 Taps are available */
672 tap_delay
= (degrees
* tap_max
) / 360;
674 /* Set the Clock Phase */
675 ret
= eemi_ops
->ioctl(node_id
, IOCTL_SET_SD_TAPDELAY
,
676 PM_TAPDELAY_OUTPUT
, tap_delay
, NULL
);
678 pr_err("Error setting Output Tap Delay\n");
683 static const struct clk_ops zynqmp_sdcardclk_ops
= {
684 .recalc_rate
= sdhci_arasan_sdcardclk_recalc_rate
,
685 .set_phase
= sdhci_zynqmp_sdcardclk_set_phase
,
689 * sdhci_zynqmp_sampleclk_set_phase - Set the SD Input Clock Tap Delays
691 * Set the SD Input Clock Tap Delays for Input path
693 * @hw: Pointer to the hardware clock structure.
694 * @degrees The clock phase shift between 0 - 359.
695 * Return: 0 on success and error value on error
697 static int sdhci_zynqmp_sampleclk_set_phase(struct clk_hw
*hw
, int degrees
)
700 struct sdhci_arasan_clk_data
*clk_data
=
701 container_of(hw
, struct sdhci_arasan_clk_data
, sampleclk_hw
);
702 struct sdhci_arasan_data
*sdhci_arasan
=
703 container_of(clk_data
, struct sdhci_arasan_data
, clk_data
);
704 struct sdhci_host
*host
= sdhci_arasan
->host
;
705 struct sdhci_arasan_zynqmp_clk_data
*zynqmp_clk_data
=
706 clk_data
->clk_of_data
;
707 const struct zynqmp_eemi_ops
*eemi_ops
= zynqmp_clk_data
->eemi_ops
;
708 const char *clk_name
= clk_hw_get_name(hw
);
709 u32 node_id
= !strcmp(clk_name
, "clk_in_sd0") ? NODE_SD_0
: NODE_SD_1
;
710 u8 tap_delay
, tap_max
= 0;
714 * This is applicable for SDHCI_SPEC_300 and above
715 * ZynqMP does not set phase for <=25MHz clock.
716 * If degrees is zero, no need to do anything.
718 if (host
->version
< SDHCI_SPEC_300
||
719 host
->timing
== MMC_TIMING_LEGACY
||
720 host
->timing
== MMC_TIMING_UHS_SDR12
|| !degrees
)
723 switch (host
->timing
) {
724 case MMC_TIMING_MMC_HS
:
725 case MMC_TIMING_SD_HS
:
726 case MMC_TIMING_UHS_SDR25
:
727 case MMC_TIMING_UHS_DDR50
:
728 case MMC_TIMING_MMC_DDR52
:
729 /* For 50MHz clock, 120 Taps are available */
732 case MMC_TIMING_UHS_SDR50
:
733 /* For 100MHz clock, 60 Taps are available */
736 case MMC_TIMING_UHS_SDR104
:
737 case MMC_TIMING_MMC_HS200
:
738 /* For 200MHz clock, 30 Taps are available */
744 tap_delay
= (degrees
* tap_max
) / 360;
746 /* Set the Clock Phase */
747 ret
= eemi_ops
->ioctl(node_id
, IOCTL_SET_SD_TAPDELAY
,
748 PM_TAPDELAY_INPUT
, tap_delay
, NULL
);
750 pr_err("Error setting Input Tap Delay\n");
755 static const struct clk_ops zynqmp_sampleclk_ops
= {
756 .recalc_rate
= sdhci_arasan_sampleclk_recalc_rate
,
757 .set_phase
= sdhci_zynqmp_sampleclk_set_phase
,
761 * sdhci_arasan_update_clockmultiplier - Set corecfg_clockmultiplier
763 * The corecfg_clockmultiplier is supposed to contain clock multiplier
764 * value of programmable clock generator.
767 * - Many existing devices don't seem to do this and work fine. To keep
768 * compatibility for old hardware where the device tree doesn't provide a
769 * register map, this function is a noop if a soc_ctl_map hasn't been provided
771 * - The value of corecfg_clockmultiplier should sync with that of corresponding
772 * value reading from sdhci_capability_register. So this function is called
773 * once at probe time and never called again.
775 * @host: The sdhci_host
777 static void sdhci_arasan_update_clockmultiplier(struct sdhci_host
*host
,
780 struct sdhci_pltfm_host
*pltfm_host
= sdhci_priv(host
);
781 struct sdhci_arasan_data
*sdhci_arasan
= sdhci_pltfm_priv(pltfm_host
);
782 const struct sdhci_arasan_soc_ctl_map
*soc_ctl_map
=
783 sdhci_arasan
->soc_ctl_map
;
785 /* Having a map is optional */
789 /* If we have a map, we expect to have a syscon */
790 if (!sdhci_arasan
->soc_ctl_base
) {
791 pr_warn("%s: Have regmap, but no soc-ctl-syscon\n",
792 mmc_hostname(host
->mmc
));
796 sdhci_arasan_syscon_write(host
, &soc_ctl_map
->clockmultiplier
, value
);
800 * sdhci_arasan_update_baseclkfreq - Set corecfg_baseclkfreq
802 * The corecfg_baseclkfreq is supposed to contain the MHz of clk_xin. This
803 * function can be used to make that happen.
806 * - Many existing devices don't seem to do this and work fine. To keep
807 * compatibility for old hardware where the device tree doesn't provide a
808 * register map, this function is a noop if a soc_ctl_map hasn't been provided
810 * - It's assumed that clk_xin is not dynamic and that we use the SDHCI divider
811 * to achieve lower clock rates. That means that this function is called once
812 * at probe time and never called again.
814 * @host: The sdhci_host
816 static void sdhci_arasan_update_baseclkfreq(struct sdhci_host
*host
)
818 struct sdhci_pltfm_host
*pltfm_host
= sdhci_priv(host
);
819 struct sdhci_arasan_data
*sdhci_arasan
= sdhci_pltfm_priv(pltfm_host
);
820 const struct sdhci_arasan_soc_ctl_map
*soc_ctl_map
=
821 sdhci_arasan
->soc_ctl_map
;
822 u32 mhz
= DIV_ROUND_CLOSEST(clk_get_rate(pltfm_host
->clk
), 1000000);
824 /* Having a map is optional */
828 /* If we have a map, we expect to have a syscon */
829 if (!sdhci_arasan
->soc_ctl_base
) {
830 pr_warn("%s: Have regmap, but no soc-ctl-syscon\n",
831 mmc_hostname(host
->mmc
));
835 sdhci_arasan_syscon_write(host
, &soc_ctl_map
->baseclkfreq
, mhz
);
838 static void sdhci_arasan_set_clk_delays(struct sdhci_host
*host
)
840 struct sdhci_pltfm_host
*pltfm_host
= sdhci_priv(host
);
841 struct sdhci_arasan_data
*sdhci_arasan
= sdhci_pltfm_priv(pltfm_host
);
842 struct sdhci_arasan_clk_data
*clk_data
= &sdhci_arasan
->clk_data
;
844 clk_set_phase(clk_data
->sampleclk
,
845 clk_data
->clk_phase_in
[host
->timing
]);
846 clk_set_phase(clk_data
->sdcardclk
,
847 clk_data
->clk_phase_out
[host
->timing
]);
850 static void arasan_dt_read_clk_phase(struct device
*dev
,
851 struct sdhci_arasan_clk_data
*clk_data
,
852 unsigned int timing
, const char *prop
)
854 struct device_node
*np
= dev
->of_node
;
856 int clk_phase
[2] = {0};
859 * Read Tap Delay values from DT, if the DT does not contain the
860 * Tap Values then use the pre-defined values.
862 if (of_property_read_variable_u32_array(np
, prop
, &clk_phase
[0],
864 dev_dbg(dev
, "Using predefined clock phase for %s = %d %d\n",
865 prop
, clk_data
->clk_phase_in
[timing
],
866 clk_data
->clk_phase_out
[timing
]);
870 /* The values read are Input and Output Clock Delays in order */
871 clk_data
->clk_phase_in
[timing
] = clk_phase
[0];
872 clk_data
->clk_phase_out
[timing
] = clk_phase
[1];
876 * arasan_dt_parse_clk_phases - Read Clock Delay values from DT
878 * Called at initialization to parse the values of Clock Delays.
880 * @dev: Pointer to our struct device.
881 * @clk_data: Pointer to the Clock Data structure
883 static void arasan_dt_parse_clk_phases(struct device
*dev
,
884 struct sdhci_arasan_clk_data
*clk_data
)
886 int *iclk_phase
, *oclk_phase
;
891 * This has been kept as a pointer and is assigned a function here.
892 * So that different controller variants can assign their own handling
895 clk_data
->set_clk_delays
= sdhci_arasan_set_clk_delays
;
897 if (of_device_is_compatible(dev
->of_node
, "xlnx,zynqmp-8.9a")) {
898 iclk_phase
= (int [MMC_TIMING_MMC_HS400
+ 1]) ZYNQMP_ICLK_PHASE
;
899 oclk_phase
= (int [MMC_TIMING_MMC_HS400
+ 1]) ZYNQMP_OCLK_PHASE
;
901 of_property_read_u32(dev
->of_node
, "xlnx,mio-bank", &mio_bank
);
903 oclk_phase
[MMC_TIMING_UHS_SDR104
] = 90;
904 oclk_phase
[MMC_TIMING_MMC_HS200
] = 90;
907 for (i
= 0; i
<= MMC_TIMING_MMC_HS400
; i
++) {
908 clk_data
->clk_phase_in
[i
] = iclk_phase
[i
];
909 clk_data
->clk_phase_out
[i
] = oclk_phase
[i
];
913 arasan_dt_read_clk_phase(dev
, clk_data
, MMC_TIMING_LEGACY
,
915 arasan_dt_read_clk_phase(dev
, clk_data
, MMC_TIMING_MMC_HS
,
917 arasan_dt_read_clk_phase(dev
, clk_data
, MMC_TIMING_SD_HS
,
919 arasan_dt_read_clk_phase(dev
, clk_data
, MMC_TIMING_UHS_SDR12
,
920 "clk-phase-uhs-sdr12");
921 arasan_dt_read_clk_phase(dev
, clk_data
, MMC_TIMING_UHS_SDR25
,
922 "clk-phase-uhs-sdr25");
923 arasan_dt_read_clk_phase(dev
, clk_data
, MMC_TIMING_UHS_SDR50
,
924 "clk-phase-uhs-sdr50");
925 arasan_dt_read_clk_phase(dev
, clk_data
, MMC_TIMING_UHS_SDR104
,
926 "clk-phase-uhs-sdr104");
927 arasan_dt_read_clk_phase(dev
, clk_data
, MMC_TIMING_UHS_DDR50
,
928 "clk-phase-uhs-ddr50");
929 arasan_dt_read_clk_phase(dev
, clk_data
, MMC_TIMING_MMC_DDR52
,
930 "clk-phase-mmc-ddr52");
931 arasan_dt_read_clk_phase(dev
, clk_data
, MMC_TIMING_MMC_HS200
,
932 "clk-phase-mmc-hs200");
933 arasan_dt_read_clk_phase(dev
, clk_data
, MMC_TIMING_MMC_HS400
,
934 "clk-phase-mmc-hs400");
938 * sdhci_arasan_register_sdcardclk - Register the sdcardclk for a PHY to use
940 * Some PHY devices need to know what the actual card clock is. In order for
941 * them to find out, we'll provide a clock through the common clock framework
944 * @sdhci_arasan: Our private data structure.
945 * @clk_xin: Pointer to the functional clock
946 * @dev: Pointer to our struct device.
947 * Returns 0 on success and error value on error
950 sdhci_arasan_register_sdcardclk(struct sdhci_arasan_data
*sdhci_arasan
,
954 struct sdhci_arasan_clk_data
*clk_data
= &sdhci_arasan
->clk_data
;
955 struct device_node
*np
= dev
->of_node
;
956 struct clk_init_data sdcardclk_init
;
957 const char *parent_clk_name
;
960 ret
= of_property_read_string_index(np
, "clock-output-names", 0,
961 &sdcardclk_init
.name
);
963 dev_err(dev
, "DT has #clock-cells but no clock-output-names\n");
967 parent_clk_name
= __clk_get_name(clk_xin
);
968 sdcardclk_init
.parent_names
= &parent_clk_name
;
969 sdcardclk_init
.num_parents
= 1;
970 sdcardclk_init
.flags
= CLK_GET_RATE_NOCACHE
;
971 if (of_device_is_compatible(np
, "xlnx,zynqmp-8.9a"))
972 sdcardclk_init
.ops
= &zynqmp_sdcardclk_ops
;
974 sdcardclk_init
.ops
= &arasan_sdcardclk_ops
;
976 clk_data
->sdcardclk_hw
.init
= &sdcardclk_init
;
977 clk_data
->sdcardclk
=
978 devm_clk_register(dev
, &clk_data
->sdcardclk_hw
);
979 clk_data
->sdcardclk_hw
.init
= NULL
;
981 ret
= of_clk_add_provider(np
, of_clk_src_simple_get
,
982 clk_data
->sdcardclk
);
984 dev_err(dev
, "Failed to add sdcard clock provider\n");
990 * sdhci_arasan_register_sampleclk - Register the sampleclk for a PHY to use
992 * Some PHY devices need to know what the actual card clock is. In order for
993 * them to find out, we'll provide a clock through the common clock framework
996 * @sdhci_arasan: Our private data structure.
997 * @clk_xin: Pointer to the functional clock
998 * @dev: Pointer to our struct device.
999 * Returns 0 on success and error value on error
1002 sdhci_arasan_register_sampleclk(struct sdhci_arasan_data
*sdhci_arasan
,
1003 struct clk
*clk_xin
,
1006 struct sdhci_arasan_clk_data
*clk_data
= &sdhci_arasan
->clk_data
;
1007 struct device_node
*np
= dev
->of_node
;
1008 struct clk_init_data sampleclk_init
;
1009 const char *parent_clk_name
;
1012 ret
= of_property_read_string_index(np
, "clock-output-names", 1,
1013 &sampleclk_init
.name
);
1015 dev_err(dev
, "DT has #clock-cells but no clock-output-names\n");
1019 parent_clk_name
= __clk_get_name(clk_xin
);
1020 sampleclk_init
.parent_names
= &parent_clk_name
;
1021 sampleclk_init
.num_parents
= 1;
1022 sampleclk_init
.flags
= CLK_GET_RATE_NOCACHE
;
1023 if (of_device_is_compatible(np
, "xlnx,zynqmp-8.9a"))
1024 sampleclk_init
.ops
= &zynqmp_sampleclk_ops
;
1026 sampleclk_init
.ops
= &arasan_sampleclk_ops
;
1028 clk_data
->sampleclk_hw
.init
= &sampleclk_init
;
1029 clk_data
->sampleclk
=
1030 devm_clk_register(dev
, &clk_data
->sampleclk_hw
);
1031 clk_data
->sampleclk_hw
.init
= NULL
;
1033 ret
= of_clk_add_provider(np
, of_clk_src_simple_get
,
1034 clk_data
->sampleclk
);
1036 dev_err(dev
, "Failed to add sample clock provider\n");
1042 * sdhci_arasan_unregister_sdclk - Undoes sdhci_arasan_register_sdclk()
1044 * Should be called any time we're exiting and sdhci_arasan_register_sdclk()
1047 * @dev: Pointer to our struct device.
1049 static void sdhci_arasan_unregister_sdclk(struct device
*dev
)
1051 struct device_node
*np
= dev
->of_node
;
1053 if (!of_find_property(np
, "#clock-cells", NULL
))
1056 of_clk_del_provider(dev
->of_node
);
1060 * sdhci_arasan_register_sdclk - Register the sdcardclk for a PHY to use
1062 * Some PHY devices need to know what the actual card clock is. In order for
1063 * them to find out, we'll provide a clock through the common clock framework
1064 * for them to query.
1066 * Note: without seriously re-architecting SDHCI's clock code and testing on
1067 * all platforms, there's no way to create a totally beautiful clock here
1068 * with all clock ops implemented. Instead, we'll just create a clock that can
1069 * be queried and set the CLK_GET_RATE_NOCACHE attribute to tell common clock
1070 * framework that we're doing things behind its back. This should be sufficient
1071 * to create nice clean device tree bindings and later (if needed) we can try
1072 * re-architecting SDHCI if we see some benefit to it.
1074 * @sdhci_arasan: Our private data structure.
1075 * @clk_xin: Pointer to the functional clock
1076 * @dev: Pointer to our struct device.
1077 * Returns 0 on success and error value on error
1079 static int sdhci_arasan_register_sdclk(struct sdhci_arasan_data
*sdhci_arasan
,
1080 struct clk
*clk_xin
,
1083 struct device_node
*np
= dev
->of_node
;
1087 /* Providing a clock to the PHY is optional; no error if missing */
1088 if (of_property_read_u32(np
, "#clock-cells", &num_clks
) < 0)
1091 ret
= sdhci_arasan_register_sdcardclk(sdhci_arasan
, clk_xin
, dev
);
1096 ret
= sdhci_arasan_register_sampleclk(sdhci_arasan
, clk_xin
,
1099 sdhci_arasan_unregister_sdclk(dev
);
1107 static int sdhci_arasan_add_host(struct sdhci_arasan_data
*sdhci_arasan
)
1109 struct sdhci_host
*host
= sdhci_arasan
->host
;
1110 struct cqhci_host
*cq_host
;
1114 if (!sdhci_arasan
->has_cqe
)
1115 return sdhci_add_host(host
);
1117 ret
= sdhci_setup_host(host
);
1121 cq_host
= devm_kzalloc(host
->mmc
->parent
,
1122 sizeof(*cq_host
), GFP_KERNEL
);
1128 cq_host
->mmio
= host
->ioaddr
+ SDHCI_ARASAN_CQE_BASE_ADDR
;
1129 cq_host
->ops
= &sdhci_arasan_cqhci_ops
;
1131 dma64
= host
->flags
& SDHCI_USE_64_BIT_DMA
;
1133 cq_host
->caps
|= CQHCI_TASK_DESC_SZ_128
;
1135 ret
= cqhci_init(cq_host
, host
->mmc
, dma64
);
1139 ret
= __sdhci_add_host(host
);
1146 sdhci_cleanup_host(host
);
1150 static int sdhci_arasan_probe(struct platform_device
*pdev
)
1153 const struct of_device_id
*match
;
1154 struct device_node
*node
;
1155 struct clk
*clk_xin
;
1156 struct sdhci_host
*host
;
1157 struct sdhci_pltfm_host
*pltfm_host
;
1158 struct sdhci_arasan_data
*sdhci_arasan
;
1159 struct device_node
*np
= pdev
->dev
.of_node
;
1160 const struct sdhci_arasan_of_data
*data
;
1162 match
= of_match_node(sdhci_arasan_of_match
, pdev
->dev
.of_node
);
1164 host
= sdhci_pltfm_init(pdev
, data
->pdata
, sizeof(*sdhci_arasan
));
1167 return PTR_ERR(host
);
1169 pltfm_host
= sdhci_priv(host
);
1170 sdhci_arasan
= sdhci_pltfm_priv(pltfm_host
);
1171 sdhci_arasan
->host
= host
;
1173 sdhci_arasan
->soc_ctl_map
= data
->soc_ctl_map
;
1175 node
= of_parse_phandle(pdev
->dev
.of_node
, "arasan,soc-ctl-syscon", 0);
1177 sdhci_arasan
->soc_ctl_base
= syscon_node_to_regmap(node
);
1180 if (IS_ERR(sdhci_arasan
->soc_ctl_base
)) {
1181 ret
= PTR_ERR(sdhci_arasan
->soc_ctl_base
);
1182 if (ret
!= -EPROBE_DEFER
)
1183 dev_err(&pdev
->dev
, "Can't get syscon: %d\n",
1185 goto err_pltfm_free
;
1189 sdhci_arasan
->clk_ahb
= devm_clk_get(&pdev
->dev
, "clk_ahb");
1190 if (IS_ERR(sdhci_arasan
->clk_ahb
)) {
1191 dev_err(&pdev
->dev
, "clk_ahb clock not found.\n");
1192 ret
= PTR_ERR(sdhci_arasan
->clk_ahb
);
1193 goto err_pltfm_free
;
1196 clk_xin
= devm_clk_get(&pdev
->dev
, "clk_xin");
1197 if (IS_ERR(clk_xin
)) {
1198 dev_err(&pdev
->dev
, "clk_xin clock not found.\n");
1199 ret
= PTR_ERR(clk_xin
);
1200 goto err_pltfm_free
;
1203 ret
= clk_prepare_enable(sdhci_arasan
->clk_ahb
);
1205 dev_err(&pdev
->dev
, "Unable to enable AHB clock.\n");
1206 goto err_pltfm_free
;
1209 ret
= clk_prepare_enable(clk_xin
);
1211 dev_err(&pdev
->dev
, "Unable to enable SD clock.\n");
1215 sdhci_get_of_property(pdev
);
1217 if (of_property_read_bool(np
, "xlnx,fails-without-test-cd"))
1218 sdhci_arasan
->quirks
|= SDHCI_ARASAN_QUIRK_FORCE_CDTEST
;
1220 if (of_property_read_bool(np
, "xlnx,int-clock-stable-broken"))
1221 sdhci_arasan
->quirks
|= SDHCI_ARASAN_QUIRK_CLOCK_UNSTABLE
;
1223 pltfm_host
->clk
= clk_xin
;
1225 if (of_device_is_compatible(pdev
->dev
.of_node
,
1226 "rockchip,rk3399-sdhci-5.1"))
1227 sdhci_arasan_update_clockmultiplier(host
, 0x0);
1229 sdhci_arasan_update_baseclkfreq(host
);
1231 ret
= sdhci_arasan_register_sdclk(sdhci_arasan
, clk_xin
, &pdev
->dev
);
1233 goto clk_disable_all
;
1235 if (of_device_is_compatible(np
, "xlnx,zynqmp-8.9a")) {
1236 struct sdhci_arasan_zynqmp_clk_data
*zynqmp_clk_data
;
1237 const struct zynqmp_eemi_ops
*eemi_ops
;
1239 zynqmp_clk_data
= devm_kzalloc(&pdev
->dev
,
1240 sizeof(*zynqmp_clk_data
),
1242 eemi_ops
= zynqmp_pm_get_eemi_ops();
1243 if (IS_ERR(eemi_ops
)) {
1244 ret
= PTR_ERR(eemi_ops
);
1248 zynqmp_clk_data
->eemi_ops
= eemi_ops
;
1249 sdhci_arasan
->clk_data
.clk_of_data
= zynqmp_clk_data
;
1252 arasan_dt_parse_clk_phases(&pdev
->dev
, &sdhci_arasan
->clk_data
);
1254 ret
= mmc_of_parse(host
->mmc
);
1256 if (ret
!= -EPROBE_DEFER
)
1257 dev_err(&pdev
->dev
, "parsing dt failed (%d)\n", ret
);
1261 sdhci_arasan
->phy
= ERR_PTR(-ENODEV
);
1262 if (of_device_is_compatible(pdev
->dev
.of_node
,
1263 "arasan,sdhci-5.1")) {
1264 sdhci_arasan
->phy
= devm_phy_get(&pdev
->dev
,
1266 if (IS_ERR(sdhci_arasan
->phy
)) {
1267 ret
= PTR_ERR(sdhci_arasan
->phy
);
1268 dev_err(&pdev
->dev
, "No phy for arasan,sdhci-5.1.\n");
1272 ret
= phy_init(sdhci_arasan
->phy
);
1274 dev_err(&pdev
->dev
, "phy_init err.\n");
1278 host
->mmc_host_ops
.hs400_enhanced_strobe
=
1279 sdhci_arasan_hs400_enhanced_strobe
;
1280 host
->mmc_host_ops
.start_signal_voltage_switch
=
1281 sdhci_arasan_voltage_switch
;
1282 sdhci_arasan
->has_cqe
= true;
1283 host
->mmc
->caps2
|= MMC_CAP2_CQE
;
1285 if (!of_property_read_bool(np
, "disable-cqe-dcmd"))
1286 host
->mmc
->caps2
|= MMC_CAP2_CQE_DCMD
;
1289 ret
= sdhci_arasan_add_host(sdhci_arasan
);
1296 if (!IS_ERR(sdhci_arasan
->phy
))
1297 phy_exit(sdhci_arasan
->phy
);
1299 sdhci_arasan_unregister_sdclk(&pdev
->dev
);
1301 clk_disable_unprepare(clk_xin
);
1303 clk_disable_unprepare(sdhci_arasan
->clk_ahb
);
1305 sdhci_pltfm_free(pdev
);
1309 static int sdhci_arasan_remove(struct platform_device
*pdev
)
1312 struct sdhci_host
*host
= platform_get_drvdata(pdev
);
1313 struct sdhci_pltfm_host
*pltfm_host
= sdhci_priv(host
);
1314 struct sdhci_arasan_data
*sdhci_arasan
= sdhci_pltfm_priv(pltfm_host
);
1315 struct clk
*clk_ahb
= sdhci_arasan
->clk_ahb
;
1317 if (!IS_ERR(sdhci_arasan
->phy
)) {
1318 if (sdhci_arasan
->is_phy_on
)
1319 phy_power_off(sdhci_arasan
->phy
);
1320 phy_exit(sdhci_arasan
->phy
);
1323 sdhci_arasan_unregister_sdclk(&pdev
->dev
);
1325 ret
= sdhci_pltfm_unregister(pdev
);
1327 clk_disable_unprepare(clk_ahb
);
1332 static struct platform_driver sdhci_arasan_driver
= {
1334 .name
= "sdhci-arasan",
1335 .of_match_table
= sdhci_arasan_of_match
,
1336 .pm
= &sdhci_arasan_dev_pm_ops
,
1338 .probe
= sdhci_arasan_probe
,
1339 .remove
= sdhci_arasan_remove
,
1342 module_platform_driver(sdhci_arasan_driver
);
1344 MODULE_DESCRIPTION("Driver for the Arasan SDHCI Controller");
1345 MODULE_AUTHOR("Soeren Brinkmann <soren.brinkmann@xilinx.com>");
1346 MODULE_LICENSE("GPL");