/* * On some SoCs the syscon area has a feature where the upper 16-bits of * each 32-bit register act as a write mask for the lower 16-bits. This allows * atomic updates of the register without locking. This macro is used on SoCs * that have that feature.
*/ #define HIWORD_UPDATE(val, mask, shift) \
((val) << (shift) | (mask) << ((shift) + 16))
/** * struct sdhci_arasan_soc_ctl_field - Field used in sdhci_arasan_soc_ctl_map * * @reg: Offset within the syscon of the register containing this field * @width: Number of bits for this field * @shift: Bit offset within @reg of this field (or -1 if not avail)
*/ struct sdhci_arasan_soc_ctl_field {
u32 reg;
u16 width;
s16 shift;
};
/** * struct sdhci_arasan_soc_ctl_map - Map in syscon to corecfg registers * * @baseclkfreq: Where to find corecfg_baseclkfreq * @clockmultiplier: Where to find corecfg_clockmultiplier * @support64b: Where to find SUPPORT64B bit * @hiword_update: If true, use HIWORD_UPDATE to access the syscon * * It's up to the licensee of the Arsan IP block to make these available * somewhere if needed. Presumably these will be scattered somewhere that's * accessible via the syscon API.
*/ struct sdhci_arasan_soc_ctl_map { struct sdhci_arasan_soc_ctl_field baseclkfreq; struct sdhci_arasan_soc_ctl_field clockmultiplier; struct sdhci_arasan_soc_ctl_field support64b; bool hiword_update;
};
/** * struct sdhci_arasan_clk_ops - Clock Operations for Arasan SD controller * * @sdcardclk_ops: The output clock related operations * @sampleclk_ops: The sample clock related operations
*/ struct sdhci_arasan_clk_ops { conststruct clk_ops *sdcardclk_ops; conststruct clk_ops *sampleclk_ops;
};
/** * struct sdhci_arasan_clk_data - Arasan Controller Clock Data. * * @sdcardclk_hw: Struct for the clock we might provide to a PHY. * @sdcardclk: Pointer to normal 'struct clock' for sdcardclk_hw. * @sampleclk_hw: Struct for the clock we might provide to a PHY. * @sampleclk: Pointer to normal 'struct clock' for sampleclk_hw. * @clk_phase_in: Array of Input Clock Phase Delays for all speed modes * @clk_phase_out: Array of Output Clock Phase Delays for all speed modes * @set_clk_delays: Function pointer for setting Clock Delays * @clk_of_data: Platform specific runtime clock data storage pointer
*/ struct sdhci_arasan_clk_data { struct clk_hw sdcardclk_hw; struct clk *sdcardclk; struct clk_hw sampleclk_hw; struct clk *sampleclk; int clk_phase_in[MMC_TIMING_MMC_HS400 + 1]; int clk_phase_out[MMC_TIMING_MMC_HS400 + 1]; void (*set_clk_delays)(struct sdhci_host *host); void *clk_of_data;
};
/** * struct sdhci_arasan_data - Arasan Controller Data * * @host: Pointer to the main SDHCI host structure. * @clk_ahb: Pointer to the AHB clock * @phy: Pointer to the generic phy * @is_phy_on: True if the PHY is on; false if not. * @internal_phy_reg: True if the PHY is within the Host controller. * @has_cqe: True if controller has command queuing engine. * @clk_data: Struct for the Arasan Controller Clock Data. * @clk_ops: Struct for the Arasan Controller Clock Operations. * @soc_ctl_base: Pointer to regmap for syscon for soc_ctl registers. * @soc_ctl_map: Map to get offsets into soc_ctl registers. * @quirks: Arasan deviations from spec.
*/ struct sdhci_arasan_data { struct sdhci_host *host; struct clk *clk_ahb; struct phy *phy; bool is_phy_on; bool internal_phy_reg;
/* Controller does not have CD wired and will not function normally without */ #define SDHCI_ARASAN_QUIRK_FORCE_CDTEST BIT(0) /* Controller immediately reports SDHCI_CLOCK_INT_STABLE after enabling the
* internal clock even when the clock isn't stable */ #define SDHCI_ARASAN_QUIRK_CLOCK_UNSTABLE BIT(1) /* * Some of the Arasan variations might not have timing requirements * met at 25MHz for Default Speed mode, those controllers work at * 19MHz instead
*/ #define SDHCI_ARASAN_QUIRK_CLOCK_25_BROKEN BIT(2) /* Enable CD stable check before power-up */ #define SDHCI_ARASAN_QUIRK_ENSURE_CD_STABLE BIT(3)
};
/** * sdhci_arasan_syscon_write - Write to a field in soc_ctl registers * * @host: The sdhci_host * @fld: The field to write to * @val: The value to write * * This function allows writing to fields in sdhci_arasan_soc_ctl_map. * Note that if a field is specified as not available (shift < 0) then * this function will silently return an error code. It will be noisy * and print errors for any other (unexpected) errors. * * Return: 0 on success and error value on error
*/ staticint sdhci_arasan_syscon_write(struct sdhci_host *host, conststruct sdhci_arasan_soc_ctl_field *fld,
u32 val)
{ struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); struct sdhci_arasan_data *sdhci_arasan = sdhci_pltfm_priv(pltfm_host); struct regmap *soc_ctl_base = sdhci_arasan->soc_ctl_base;
u32 reg = fld->reg;
u16 width = fld->width;
s16 shift = fld->shift; int ret;
/* * Silently return errors for shift < 0 so caller doesn't have * to check for fields which are optional. For fields that * are required then caller needs to do something special * anyway.
*/ if (shift < 0) return -EINVAL;
if (sdhci_arasan->soc_ctl_map->hiword_update)
ret = regmap_write(soc_ctl_base, reg,
HIWORD_UPDATE(val, GENMASK(width, 0),
shift)); else
ret = regmap_update_bits(soc_ctl_base, reg,
GENMASK(shift + width, shift),
val << shift);
/* Yell about (unexpected) regmap errors */ if (ret)
pr_warn("%s: Regmap write fail: %d\n",
mmc_hostname(host->mmc), ret);
if (!IS_ERR(sdhci_arasan->phy)) { if (!sdhci_arasan->is_phy_on && clock <= PHY_CLK_TOO_SLOW_HZ) { /* * If PHY off, set clock to max speed and power PHY on. * * Although PHY docs apparently suggest power cycling * when changing the clock the PHY doesn't like to be * powered on while at low speeds like those used in ID * mode. Even worse is powering the PHY on while the * clock is off. * * To workaround the PHY limitations, the best we can * do is to power it on at a faster speed and then slam * through low speeds without power cycling.
*/
sdhci_set_clock(host, host->max_clk); if (phy_power_on(sdhci_arasan->phy)) {
pr_err("%s: Cannot power on phy.\n",
mmc_hostname(host->mmc)); return;
}
sdhci_arasan->is_phy_on = true;
/* * We'll now fall through to the below case with * ctrl_phy = false (so we won't turn off/on). The * sdhci_set_clock() will set the real clock.
*/
} elseif (clock > PHY_CLK_TOO_SLOW_HZ) { /* * At higher clock speeds the PHY is fine being power * cycled and docs say you _should_ power cycle when * changing clock speeds.
*/
ctrl_phy = true;
}
}
if (ctrl_phy && sdhci_arasan->is_phy_on) {
phy_power_off(sdhci_arasan->phy);
sdhci_arasan->is_phy_on = false;
}
if (sdhci_arasan->quirks & SDHCI_ARASAN_QUIRK_CLOCK_25_BROKEN) { /* * Some of the Arasan variations might not have timing * requirements met at 25MHz for Default Speed mode, * those controllers work at 19MHz instead.
*/ if (clock == DEFAULT_SPEED_MAX_DTR)
clock = (DEFAULT_SPEED_MAX_DTR * 19) / 25;
}
/* Set the Input and Output Clock Phase Delays */ if (clk_data->set_clk_delays && clock > PHY_CLK_TOO_SLOW_HZ)
clk_data->set_clk_delays(host);
if (sdhci_arasan->internal_phy_reg && clock >= MIN_PHY_CLK_HZ)
sdhci_arasan_phy_set_dll(host, 1);
if (sdhci_arasan->quirks & SDHCI_ARASAN_QUIRK_CLOCK_UNSTABLE) /* * Some controllers immediately report SDHCI_CLOCK_INT_STABLE * after enabling the clock even though the clock is not * stable. Trying to use a clock without waiting here results * in EILSEQ while detecting some older/slower cards. The * chosen delay is the maximum delay from sdhci_set_clock.
*/
msleep(20);
if (ctrl_phy) { if (phy_power_on(sdhci_arasan->phy)) {
pr_err("%s: Cannot power on phy.\n",
mmc_hostname(host->mmc)); return;
}
reg = sdhci_readb(host, SDHCI_POWER_CONTROL);
reg |= SDHCI_HW_RST_EN;
sdhci_writeb(host, reg, SDHCI_POWER_CONTROL); /* As per eMMC spec, minimum 1us is required but give it 2us for good measure */
usleep_range(2, 5);
reg &= ~SDHCI_HW_RST_EN;
sdhci_writeb(host, reg, SDHCI_POWER_CONTROL); /* As per eMMC spec, minimum 200us is required but give it 300us for good measure */
usleep_range(300, 500);
}
staticint sdhci_arasan_voltage_switch(struct mmc_host *mmc, struct mmc_ios *ios)
{ switch (ios->signal_voltage) { case MMC_SIGNAL_VOLTAGE_180: /* * Plese don't switch to 1V8 as arasan,5.1 doesn't * actually refer to this setting to indicate the * signal voltage and the state machine will be broken * actually if we force to enable 1V8. That's something * like broken quirk but we could work around here.
*/ return 0; case MMC_SIGNAL_VOLTAGE_330: case MMC_SIGNAL_VOLTAGE_120: /* We don't support 3V3 and 1V2 */ break;
}
/* * Ensure that the card detect logic has stabilized before powering up, this is * necessary after a host controller reset.
*/ if (mode == MMC_POWER_UP && sdhci_arasan->quirks & SDHCI_ARASAN_QUIRK_ENSURE_CD_STABLE)
read_poll_timeout(sdhci_readl, reg, reg & SDHCI_CD_STABLE, CD_STABLE_MAX_SLEEP_US,
CD_STABLE_TIMEOUT_US, false, host, SDHCI_PRESENT_STATE);
#ifdef CONFIG_PM_SLEEP /** * sdhci_arasan_suspend - Suspend method for the driver * @dev: Address of the device structure * * Put the device in a low power state. * * Return: 0 on success and error value on error
*/ staticint sdhci_arasan_suspend(struct device *dev)
{ struct sdhci_host *host = dev_get_drvdata(dev); struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); struct sdhci_arasan_data *sdhci_arasan = sdhci_pltfm_priv(pltfm_host); int ret;
if (host->tuning_mode != SDHCI_TUNING_MODE_3)
mmc_retune_needed(host->mmc);
if (sdhci_arasan->has_cqe) {
ret = cqhci_suspend(host->mmc); if (ret) return ret;
}
ret = sdhci_suspend_host(host); if (ret) return ret;
if (!IS_ERR(sdhci_arasan->phy) && sdhci_arasan->is_phy_on) {
ret = phy_power_off(sdhci_arasan->phy); if (ret) {
dev_err(dev, "Cannot power off phy.\n"); if (sdhci_resume_host(host))
dev_err(dev, "Cannot resume host.\n");
/** * sdhci_arasan_resume - Resume method for the driver * @dev: Address of the device structure * * Resume operation after suspend * * Return: 0 on success and error value on error
*/ staticint sdhci_arasan_resume(struct device *dev)
{ struct sdhci_host *host = dev_get_drvdata(dev); struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); struct sdhci_arasan_data *sdhci_arasan = sdhci_pltfm_priv(pltfm_host); int ret;
ret = clk_enable(sdhci_arasan->clk_ahb); if (ret) {
dev_err(dev, "Cannot enable AHB clock.\n"); return ret;
}
ret = clk_enable(pltfm_host->clk); if (ret) {
dev_err(dev, "Cannot enable SD clock.\n"); return ret;
}
if (!IS_ERR(sdhci_arasan->phy) && host->mmc->actual_clock) {
ret = phy_power_on(sdhci_arasan->phy); if (ret) {
dev_err(dev, "Cannot power on phy.\n"); return ret;
}
sdhci_arasan->is_phy_on = true;
}
ret = sdhci_resume_host(host); if (ret) {
dev_err(dev, "Cannot resume host.\n"); return ret;
}
if (sdhci_arasan->has_cqe) return cqhci_resume(host->mmc);
/** * sdhci_arasan_sdcardclk_recalc_rate - Return the card clock rate * * @hw: Pointer to the hardware clock structure. * @parent_rate: The parent rate (should be rate of clk_xin). * * Return the current actual rate of the SD card clock. This can be used * to communicate with out PHY. * * Return: The card clock rate.
*/ staticunsignedlong sdhci_arasan_sdcardclk_recalc_rate(struct clk_hw *hw, unsignedlong parent_rate)
{ struct sdhci_arasan_clk_data *clk_data =
container_of(hw, struct sdhci_arasan_clk_data, sdcardclk_hw); struct sdhci_arasan_data *sdhci_arasan =
container_of(clk_data, struct sdhci_arasan_data, clk_data); struct sdhci_host *host = sdhci_arasan->host;
/** * sdhci_arasan_sampleclk_recalc_rate - Return the sampling clock rate * * @hw: Pointer to the hardware clock structure. * @parent_rate: The parent rate (should be rate of clk_xin). * * Return the current actual rate of the sampling clock. This can be used * to communicate with out PHY. * * Return: The sample clock rate.
*/ staticunsignedlong sdhci_arasan_sampleclk_recalc_rate(struct clk_hw *hw, unsignedlong parent_rate)
{ struct sdhci_arasan_clk_data *clk_data =
container_of(hw, struct sdhci_arasan_clk_data, sampleclk_hw); struct sdhci_arasan_data *sdhci_arasan =
container_of(clk_data, struct sdhci_arasan_data, clk_data); struct sdhci_host *host = sdhci_arasan->host;
/** * sdhci_zynqmp_sdcardclk_set_phase - Set the SD Output Clock Tap Delays * * @hw: Pointer to the hardware clock structure. * @degrees: The clock phase shift between 0 - 359. * * Set the SD Output Clock Tap Delays for Output path * * Return: 0 on success and error value on error
*/ staticint sdhci_zynqmp_sdcardclk_set_phase(struct clk_hw *hw, int degrees)
{ struct sdhci_arasan_clk_data *clk_data =
container_of(hw, struct sdhci_arasan_clk_data, sdcardclk_hw); struct sdhci_arasan_data *sdhci_arasan =
container_of(clk_data, struct sdhci_arasan_data, clk_data); struct sdhci_host *host = sdhci_arasan->host; constchar *clk_name = clk_hw_get_name(hw);
u32 node_id = !strcmp(clk_name, "clk_out_sd0") ? NODE_SD_0 : NODE_SD_1;
u8 tap_delay, tap_max = 0; int ret;
/* This is applicable for SDHCI_SPEC_300 and above */ if (host->version < SDHCI_SPEC_300) return 0;
switch (host->timing) { case MMC_TIMING_MMC_HS: case MMC_TIMING_SD_HS: case MMC_TIMING_UHS_SDR25: case MMC_TIMING_UHS_DDR50: case MMC_TIMING_MMC_DDR52: /* For 50MHz clock, 30 Taps are available */
tap_max = 30; break; case MMC_TIMING_UHS_SDR50: /* For 100MHz clock, 15 Taps are available */
tap_max = 15; break; case MMC_TIMING_UHS_SDR104: case MMC_TIMING_MMC_HS200: /* For 200MHz clock, 8 Taps are available */
tap_max = 8; break; default: break;
}
tap_delay = (degrees * tap_max) / 360;
/* Set the Clock Phase */
ret = zynqmp_pm_set_sd_tapdelay(node_id, PM_TAPDELAY_OUTPUT, tap_delay); if (ret)
pr_err("Error setting Output Tap Delay\n");
switch (host->timing) { case MMC_TIMING_MMC_HS: case MMC_TIMING_SD_HS: case MMC_TIMING_UHS_SDR25: case MMC_TIMING_UHS_DDR50: case MMC_TIMING_MMC_DDR52: /* For 50MHz clock, 120 Taps are available */
tap_max = 120; break; case MMC_TIMING_UHS_SDR50: /* For 100MHz clock, 60 Taps are available */
tap_max = 60; break; case MMC_TIMING_UHS_SDR104: case MMC_TIMING_MMC_HS200: /* For 200MHz clock, 30 Taps are available */
tap_max = 30; break; default: break;
}
tap_delay = (degrees * tap_max) / 360;
/* Set the Clock Phase */
ret = zynqmp_pm_set_sd_tapdelay(node_id, PM_TAPDELAY_INPUT, tap_delay); if (ret)
pr_err("Error setting Input Tap Delay\n");
/** * sdhci_versal_sdcardclk_set_phase - Set the SD Output Clock Tap Delays * * @hw: Pointer to the hardware clock structure. * @degrees: The clock phase shift between 0 - 359. * * Set the SD Output Clock Tap Delays for Output path * * Return: 0 on success and error value on error
*/ staticint sdhci_versal_sdcardclk_set_phase(struct clk_hw *hw, int degrees)
{ struct sdhci_arasan_clk_data *clk_data =
container_of(hw, struct sdhci_arasan_clk_data, sdcardclk_hw); struct sdhci_arasan_data *sdhci_arasan =
container_of(clk_data, struct sdhci_arasan_data, clk_data); struct sdhci_host *host = sdhci_arasan->host;
u8 tap_delay, tap_max = 0;
/* This is applicable for SDHCI_SPEC_300 and above */ if (host->version < SDHCI_SPEC_300) return 0;
switch (host->timing) { case MMC_TIMING_MMC_HS: case MMC_TIMING_SD_HS: case MMC_TIMING_UHS_SDR25: case MMC_TIMING_UHS_DDR50: case MMC_TIMING_MMC_DDR52: /* For 50MHz clock, 30 Taps are available */
tap_max = 30; break; case MMC_TIMING_UHS_SDR50: /* For 100MHz clock, 15 Taps are available */
tap_max = 15; break; case MMC_TIMING_UHS_SDR104: case MMC_TIMING_MMC_HS200: /* For 200MHz clock, 8 Taps are available */
tap_max = 8; break; default: break;
}
tap_delay = (degrees * tap_max) / 360;
/* Set the Clock Phase */ if (tap_delay) {
u32 regval;
/** * sdhci_versal_sampleclk_set_phase - Set the SD Input Clock Tap Delays * * @hw: Pointer to the hardware clock structure. * @degrees: The clock phase shift between 0 - 359. * * Set the SD Input Clock Tap Delays for Input path * * Return: 0 on success and error value on error
*/ staticint sdhci_versal_sampleclk_set_phase(struct clk_hw *hw, int degrees)
{ struct sdhci_arasan_clk_data *clk_data =
container_of(hw, struct sdhci_arasan_clk_data, sampleclk_hw); struct sdhci_arasan_data *sdhci_arasan =
container_of(clk_data, struct sdhci_arasan_data, clk_data); struct sdhci_host *host = sdhci_arasan->host;
u8 tap_delay, tap_max = 0;
/* This is applicable for SDHCI_SPEC_300 and above */ if (host->version < SDHCI_SPEC_300) return 0;
switch (host->timing) { case MMC_TIMING_MMC_HS: case MMC_TIMING_SD_HS: case MMC_TIMING_UHS_SDR25: case MMC_TIMING_UHS_DDR50: case MMC_TIMING_MMC_DDR52: /* For 50MHz clock, 120 Taps are available */
tap_max = 120; break; case MMC_TIMING_UHS_SDR50: /* For 100MHz clock, 60 Taps are available */
tap_max = 60; break; case MMC_TIMING_UHS_SDR104: case MMC_TIMING_MMC_HS200: /* For 200MHz clock, 30 Taps are available */
tap_max = 30; break; default: break;
}
tap_delay = (degrees * tap_max) / 360;
/* Set the Clock Phase */ if (tap_delay) {
u32 regval;
switch (host->timing) { case MMC_TIMING_MMC_HS: case MMC_TIMING_MMC_DDR52:
tap_max = 16; break; case MMC_TIMING_MMC_HS200: case MMC_TIMING_MMC_HS400: /* For 200MHz clock, 32 Taps are available */
tap_max = 32; break; default: break;
}
tap_delay = (degrees * tap_max) / 360;
/* Set the Clock Phase */ if (tap_delay) {
u32 regval;
/* ZynqMP SD controller does not perform auto tuning in DDR50 mode */ if (mmc->ios.timing == MMC_TIMING_UHS_DDR50) return 0;
arasan_zynqmp_dll_reset(host, device_id);
err = sdhci_execute_tuning(mmc, opcode); if (err) return err;
arasan_zynqmp_dll_reset(host, device_id);
return 0;
}
/** * sdhci_arasan_update_clockmultiplier - Set corecfg_clockmultiplier * * @host: The sdhci_host * @value: The value to write * * The corecfg_clockmultiplier is supposed to contain clock multiplier * value of programmable clock generator. * * NOTES: * - Many existing devices don't seem to do this and work fine. To keep * compatibility for old hardware where the device tree doesn't provide a * register map, this function is a noop if a soc_ctl_map hasn't been provided * for this platform. * - The value of corecfg_clockmultiplier should sync with that of corresponding * value reading from sdhci_capability_register. So this function is called * once at probe time and never called again.
*/ staticvoid sdhci_arasan_update_clockmultiplier(struct sdhci_host *host,
u32 value)
{ struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); struct sdhci_arasan_data *sdhci_arasan = sdhci_pltfm_priv(pltfm_host); conststruct sdhci_arasan_soc_ctl_map *soc_ctl_map =
sdhci_arasan->soc_ctl_map;
/* Having a map is optional */ if (!soc_ctl_map) return;
/* If we have a map, we expect to have a syscon */ if (!sdhci_arasan->soc_ctl_base) {
pr_warn("%s: Have regmap, but no soc-ctl-syscon\n",
mmc_hostname(host->mmc)); return;
}
/** * sdhci_arasan_update_baseclkfreq - Set corecfg_baseclkfreq * * @host: The sdhci_host * * The corecfg_baseclkfreq is supposed to contain the MHz of clk_xin. This * function can be used to make that happen. * * NOTES: * - Many existing devices don't seem to do this and work fine. To keep * compatibility for old hardware where the device tree doesn't provide a * register map, this function is a noop if a soc_ctl_map hasn't been provided * for this platform. * - It's assumed that clk_xin is not dynamic and that we use the SDHCI divider * to achieve lower clock rates. That means that this function is called once * at probe time and never called again.
*/ staticvoid sdhci_arasan_update_baseclkfreq(struct sdhci_host *host)
{ struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); struct sdhci_arasan_data *sdhci_arasan = sdhci_pltfm_priv(pltfm_host); conststruct sdhci_arasan_soc_ctl_map *soc_ctl_map =
sdhci_arasan->soc_ctl_map;
u32 mhz = DIV_ROUND_CLOSEST_ULL(clk_get_rate(pltfm_host->clk), 1000000);
/* Having a map is optional */ if (!soc_ctl_map) return;
/* If we have a map, we expect to have a syscon */ if (!sdhci_arasan->soc_ctl_base) {
pr_warn("%s: Have regmap, but no soc-ctl-syscon\n",
mmc_hostname(host->mmc)); return;
}
/* * Read Tap Delay values from DT, if the DT does not contain the * Tap Values then use the pre-defined values.
*/
ret = of_property_read_variable_u32_array(np, prop, &clk_phase[0],
2, 0); if (ret < 0) {
dev_dbg(dev, "Using predefined clock phase for %s = %d %d\n",
prop, clk_data->clk_phase_in[timing],
clk_data->clk_phase_out[timing]); return;
}
/* The values read are Input and Output Clock Delays in order */
clk_data->clk_phase_in[timing] = clk_phase[0];
clk_data->clk_phase_out[timing] = clk_phase[1];
}
/** * arasan_dt_parse_clk_phases - Read Clock Delay values from DT * * @dev: Pointer to our struct device. * @clk_data: Pointer to the Clock Data structure * * Called at initialization to parse the values of Clock Delays.
*/ staticvoid arasan_dt_parse_clk_phases(struct device *dev, struct sdhci_arasan_clk_data *clk_data)
{
u32 mio_bank = 0; int i;
/* * This has been kept as a pointer and is assigned a function here. * So that different controller variants can assign their own handling * function.
*/
clk_data->set_clk_delays = sdhci_arasan_set_clk_delays;
/** * sdhci_arasan_register_sdcardclk - Register the sdcardclk for a PHY to use * * @sdhci_arasan: Our private data structure. * @clk_xin: Pointer to the functional clock * @dev: Pointer to our struct device. * * Some PHY devices need to know what the actual card clock is. In order for * them to find out, we'll provide a clock through the common clock framework * for them to query. * * Return: 0 on success and error value on error
*/ staticint
sdhci_arasan_register_sdcardclk(struct sdhci_arasan_data *sdhci_arasan, struct clk *clk_xin, struct device *dev)
{ struct sdhci_arasan_clk_data *clk_data = &sdhci_arasan->clk_data; struct device_node *np = dev->of_node; struct clk_init_data sdcardclk_init; constchar *parent_clk_name; int ret;
ret = of_property_read_string_index(np, "clock-output-names", 0,
&sdcardclk_init.name); if (ret) {
dev_err(dev, "DT has #clock-cells but no clock-output-names\n"); return ret;
}
ret = of_clk_add_provider(np, of_clk_src_simple_get,
clk_data->sdcardclk); if (ret)
dev_err(dev, "Failed to add sdcard clock provider\n");
return ret;
}
/** * sdhci_arasan_register_sampleclk - Register the sampleclk for a PHY to use * * @sdhci_arasan: Our private data structure. * @clk_xin: Pointer to the functional clock * @dev: Pointer to our struct device. * * Some PHY devices need to know what the actual card clock is. In order for * them to find out, we'll provide a clock through the common clock framework * for them to query. * * Return: 0 on success and error value on error
*/ staticint
sdhci_arasan_register_sampleclk(struct sdhci_arasan_data *sdhci_arasan, struct clk *clk_xin, struct device *dev)
{ struct sdhci_arasan_clk_data *clk_data = &sdhci_arasan->clk_data; struct device_node *np = dev->of_node; struct clk_init_data sampleclk_init; constchar *parent_clk_name; int ret;
ret = of_property_read_string_index(np, "clock-output-names", 1,
&sampleclk_init.name); if (ret) {
dev_err(dev, "DT has #clock-cells but no clock-output-names\n"); return ret;
}
ret = of_clk_add_provider(np, of_clk_src_simple_get,
clk_data->sampleclk); if (ret)
dev_err(dev, "Failed to add sample clock provider\n");
return ret;
}
/** * sdhci_arasan_unregister_sdclk - Undoes sdhci_arasan_register_sdclk() * * @dev: Pointer to our struct device. * * Should be called any time we're exiting and sdhci_arasan_register_sdclk() * returned success.
*/ staticvoid sdhci_arasan_unregister_sdclk(struct device *dev)
{ struct device_node *np = dev->of_node;
if (!of_property_present(np, "#clock-cells")) return;
of_clk_del_provider(dev->of_node);
}
/** * sdhci_arasan_update_support64b - Set SUPPORT_64B (64-bit System Bus Support) * @host: The sdhci_host * @value: The value to write * * This should be set based on the System Address Bus. * 0: the Core supports only 32-bit System Address Bus. * 1: the Core supports 64-bit System Address Bus. * * NOTE: * For Keem Bay, it is required to clear this bit. Its default value is 1'b1. * Keem Bay does not support 64-bit access.
*/ staticvoid sdhci_arasan_update_support64b(struct sdhci_host *host, u32 value)
{ struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); struct sdhci_arasan_data *sdhci_arasan = sdhci_pltfm_priv(pltfm_host); conststruct sdhci_arasan_soc_ctl_map *soc_ctl_map;
/* Having a map is optional */
soc_ctl_map = sdhci_arasan->soc_ctl_map; if (!soc_ctl_map) return;
/* If we have a map, we expect to have a syscon */ if (!sdhci_arasan->soc_ctl_base) {
pr_warn("%s: Have regmap, but no soc-ctl-syscon\n",
mmc_hostname(host->mmc)); return;
}
/** * sdhci_arasan_register_sdclk - Register the sdcardclk for a PHY to use * * @sdhci_arasan: Our private data structure. * @clk_xin: Pointer to the functional clock * @dev: Pointer to our struct device. * * Some PHY devices need to know what the actual card clock is. In order for * them to find out, we'll provide a clock through the common clock framework * for them to query. * * Note: without seriously re-architecting SDHCI's clock code and testing on * all platforms, there's no way to create a totally beautiful clock here * with all clock ops implemented. Instead, we'll just create a clock that can * be queried and set the CLK_GET_RATE_NOCACHE attribute to tell common clock * framework that we're doing things behind its back. This should be sufficient * to create nice clean device tree bindings and later (if needed) we can try * re-architecting SDHCI if we see some benefit to it. * * Return: 0 on success and error value on error
*/ staticint sdhci_arasan_register_sdclk(struct sdhci_arasan_data *sdhci_arasan, struct clk *clk_xin, struct device *dev)
{ struct device_node *np = dev->of_node;
u32 num_clks = 0; int ret;
/* Providing a clock to the PHY is optional; no error if missing */ if (of_property_read_u32(np, "#clock-cells", &num_clks) < 0) return 0;
ret = sdhci_arasan_register_sdcardclk(sdhci_arasan, clk_xin, dev); if (ret) return ret;
if (num_clks) {
ret = sdhci_arasan_register_sampleclk(sdhci_arasan, clk_xin,
dev); if (ret) {
sdhci_arasan_unregister_sdclk(dev); return ret;
}
}
if (IS_ERR(sdhci_arasan->soc_ctl_base)) return dev_err_probe(dev,
PTR_ERR(sdhci_arasan->soc_ctl_base), "Can't get syscon\n");
}
sdhci_get_of_property(pdev);
sdhci_arasan->clk_ahb = devm_clk_get(dev, "clk_ahb"); if (IS_ERR(sdhci_arasan->clk_ahb)) return dev_err_probe(dev, PTR_ERR(sdhci_arasan->clk_ahb), "clk_ahb clock not found.\n");
clk_xin = devm_clk_get(dev, "clk_xin"); if (IS_ERR(clk_xin)) return dev_err_probe(dev, PTR_ERR(clk_xin), "clk_xin clock not found.\n");
ret = clk_prepare_enable(sdhci_arasan->clk_ahb); if (ret) return dev_err_probe(dev, ret, "Unable to enable AHB clock.\n");
/* If clock-frequency property is set, use the provided value */ if (pltfm_host->clock &&
pltfm_host->clock != clk_get_rate(clk_xin)) {
ret = clk_set_rate(clk_xin, pltfm_host->clock); if (ret) {
dev_err(&pdev->dev, "Failed to set SD clock rate\n"); goto clk_dis_ahb;
}
}
ret = clk_prepare_enable(clk_xin); if (ret) {
dev_err(dev, "Unable to enable SD clock.\n"); goto clk_dis_ahb;
}
clk_dll = devm_clk_get_optional_enabled(dev, "gate"); if (IS_ERR(clk_dll)) {
ret = dev_err_probe(dev, PTR_ERR(clk_dll), "failed to get dll clk\n"); goto clk_disable_all;
}
if (of_property_read_bool(np, "xlnx,fails-without-test-cd"))
sdhci_arasan->quirks |= SDHCI_ARASAN_QUIRK_FORCE_CDTEST;
if (of_property_read_bool(np, "xlnx,int-clock-stable-broken"))
sdhci_arasan->quirks |= SDHCI_ARASAN_QUIRK_CLOCK_UNSTABLE;
pltfm_host->clk = clk_xin;
if (of_device_is_compatible(np, "rockchip,rk3399-sdhci-5.1"))
sdhci_arasan_update_clockmultiplier(host, 0x0);
ret = mmc_of_parse(host->mmc); if (ret) {
ret = dev_err_probe(dev, ret, "parsing dt failed.\n"); goto unreg_clk;
}
if (of_device_is_compatible(np, "xlnx,zynqmp-8.9a")) {
ret = zynqmp_pm_is_function_supported(PM_IOCTL, IOCTL_SET_SD_CONFIG); if (!ret) {
ret = sdhci_zynqmp_set_dynamic_config(dev, sdhci_arasan); if (ret) goto unreg_clk;
}
}
sdhci_arasan->phy = ERR_PTR(-ENODEV); if (of_device_is_compatible(np, "arasan,sdhci-5.1")) {
sdhci_arasan->phy = devm_phy_get(dev, "phy_arasan"); if (IS_ERR(sdhci_arasan->phy)) {
ret = dev_err_probe(dev, PTR_ERR(sdhci_arasan->phy), "No phy for arasan,sdhci-5.1.\n"); goto unreg_clk;
}
ret = phy_init(sdhci_arasan->phy); if (ret < 0) {
dev_err(dev, "phy_init err.\n"); goto unreg_clk;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.