Skip to content

Commit e4c0277

Browse files
krzkstorulf
authored andcommitted
mmc: sdhci-s3c: Choose sdhci_ops based on variant
The difference between old S3C64xx and newer Exynos4 SDHCI controller variants is in clock handling (the "no_divider" field in drvdata). Choose the proper sdhci_ops based on the variant instead of patching ops in probe, if Exynos4 is used. This allows making struct sdhci_ops const for code safety and probably opens further options in the future, as the dynamic pointer ops table is not anymore that dynamic. Signed-off-by: Krzysztof Kozlowski <[email protected]> Acked-by: Adrian Hunter <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ulf Hansson <[email protected]>
1 parent 24922c1 commit e4c0277

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

drivers/mmc/host/sdhci-s3c.c

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,16 @@ struct sdhci_s3c {
130130
* struct sdhci_s3c_drv_data - S3C SDHCI platform specific driver data
131131
* @sdhci_quirks: sdhci host specific quirks.
132132
* @no_divider: no or non-standard internal clock divider.
133+
* @ops: sdhci_ops to use for this variant
133134
*
134135
* Specifies platform specific configuration of sdhci controller.
135136
* Note: A structure for driver specific platform data is used for future
136137
* expansion of its usage.
137138
*/
138139
struct sdhci_s3c_drv_data {
139-
unsigned int sdhci_quirks;
140-
bool no_divider;
140+
unsigned int sdhci_quirks;
141+
bool no_divider;
142+
const struct sdhci_ops *ops;
141143
};
142144

143145
static inline struct sdhci_s3c *to_s3c(struct sdhci_host *host)
@@ -412,7 +414,7 @@ static void sdhci_cmu_set_clock(struct sdhci_host *host, unsigned int clock)
412414
sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
413415
}
414416

415-
static struct sdhci_ops sdhci_s3c_ops = {
417+
static const struct sdhci_ops sdhci_s3c_ops_s3c6410 = {
416418
.get_max_clock = sdhci_s3c_get_max_clk,
417419
.set_clock = sdhci_s3c_set_clock,
418420
.get_min_clock = sdhci_s3c_get_min_clock,
@@ -421,6 +423,15 @@ static struct sdhci_ops sdhci_s3c_ops = {
421423
.set_uhs_signaling = sdhci_set_uhs_signaling,
422424
};
423425

426+
static const struct sdhci_ops sdhci_s3c_ops_exynos4 __maybe_unused = {
427+
.get_max_clock = sdhci_cmu_get_max_clock,
428+
.set_clock = sdhci_cmu_set_clock,
429+
.get_min_clock = sdhci_cmu_get_min_clock,
430+
.set_bus_width = sdhci_set_bus_width,
431+
.reset = sdhci_reset,
432+
.set_uhs_signaling = sdhci_set_uhs_signaling,
433+
};
434+
424435
#ifdef CONFIG_OF
425436
static int sdhci_s3c_parse_dt(struct device *dev,
426437
struct sdhci_host *host, struct s3c_sdhci_platdata *pdata)
@@ -560,7 +571,7 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
560571
pdata->cfg_gpio(pdev, pdata->max_width);
561572

562573
host->hw_name = "samsung-hsmmc";
563-
host->ops = &sdhci_s3c_ops;
574+
host->ops = &sdhci_s3c_ops_s3c6410;
564575
host->quirks = 0;
565576
host->quirks2 = 0;
566577
host->irq = irq;
@@ -570,6 +581,7 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
570581
host->quirks |= SDHCI_QUIRK_NO_HISPD_BIT;
571582
if (drv_data) {
572583
host->quirks |= drv_data->sdhci_quirks;
584+
host->ops = drv_data->ops;
573585
sc->no_divider = drv_data->no_divider;
574586
}
575587

@@ -617,16 +629,6 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
617629
/* HSMMC on Samsung SoCs uses SDCLK as timeout clock */
618630
host->quirks |= SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK;
619631

620-
/*
621-
* If controller does not have internal clock divider,
622-
* we can use overriding functions instead of default.
623-
*/
624-
if (sc->no_divider) {
625-
sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
626-
sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
627-
sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
628-
}
629-
630632
/* It supports additional host capabilities if needed */
631633
if (pdata->host_caps)
632634
host->mmc->caps |= pdata->host_caps;
@@ -758,6 +760,7 @@ MODULE_DEVICE_TABLE(platform, sdhci_s3c_driver_ids);
758760
#ifdef CONFIG_OF
759761
static const struct sdhci_s3c_drv_data exynos4_sdhci_drv_data = {
760762
.no_divider = true,
763+
.ops = &sdhci_s3c_ops_exynos4,
761764
};
762765

763766
static const struct of_device_id sdhci_s3c_dt_match[] = {

0 commit comments

Comments
 (0)