Skip to content

Commit 3561afa

Browse files
amboarUlf Hansson
authored andcommitted
mmc: core: Add helper for parsing clock phase properties
Drivers for MMC hosts that accept phase corrections can take advantage of the helper by embedding an instance of struct mmc_clk_phase_map in their private data and invoking mmc_of_parse_clk_phase() to extract phase parameters. It is the responsibility of the host driver to translate and apply the extracted values to hardware as required. Signed-off-by: Andrew Jeffery <andrew@aj.id.au> Link: https://lore.kernel.org/r/20210114031433.2388532-2-andrew@aj.id.au Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent 7c7905d commit 3561afa

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

‎drivers/mmc/core/host.c‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,50 @@ static void mmc_retune_timer(struct timer_list *t)
163163
mmc_retune_needed(host);
164164
}
165165

166+
static void mmc_of_parse_timing_phase(struct device *dev, const char *prop,
167+
struct mmc_clk_phase *phase)
168+
{
169+
int degrees[2] = {0};
170+
int rc;
171+
172+
rc = device_property_read_u32_array(dev, prop, degrees, 2);
173+
phase->valid = !rc;
174+
if (phase->valid) {
175+
phase->in_deg = degrees[0];
176+
phase->out_deg = degrees[1];
177+
}
178+
}
179+
180+
void
181+
mmc_of_parse_clk_phase(struct mmc_host *host, struct mmc_clk_phase_map *map)
182+
{
183+
struct device *dev = host->parent;
184+
185+
mmc_of_parse_timing_phase(dev, "clk-phase-legacy",
186+
&map->phase[MMC_TIMING_LEGACY]);
187+
mmc_of_parse_timing_phase(dev, "clk-phase-mmc-hs",
188+
&map->phase[MMC_TIMING_MMC_HS]);
189+
mmc_of_parse_timing_phase(dev, "clk-phase-sd-hs",
190+
&map->phase[MMC_TIMING_SD_HS]);
191+
mmc_of_parse_timing_phase(dev, "clk-phase-uhs-sdr12",
192+
&map->phase[MMC_TIMING_UHS_SDR12]);
193+
mmc_of_parse_timing_phase(dev, "clk-phase-uhs-sdr25",
194+
&map->phase[MMC_TIMING_UHS_SDR25]);
195+
mmc_of_parse_timing_phase(dev, "clk-phase-uhs-sdr50",
196+
&map->phase[MMC_TIMING_UHS_SDR50]);
197+
mmc_of_parse_timing_phase(dev, "clk-phase-uhs-sdr104",
198+
&map->phase[MMC_TIMING_UHS_SDR104]);
199+
mmc_of_parse_timing_phase(dev, "clk-phase-uhs-ddr50",
200+
&map->phase[MMC_TIMING_UHS_DDR50]);
201+
mmc_of_parse_timing_phase(dev, "clk-phase-mmc-ddr52",
202+
&map->phase[MMC_TIMING_MMC_DDR52]);
203+
mmc_of_parse_timing_phase(dev, "clk-phase-mmc-hs200",
204+
&map->phase[MMC_TIMING_MMC_HS200]);
205+
mmc_of_parse_timing_phase(dev, "clk-phase-mmc-hs400",
206+
&map->phase[MMC_TIMING_MMC_HS400]);
207+
}
208+
EXPORT_SYMBOL(mmc_of_parse_clk_phase);
209+
166210
/**
167211
* mmc_of_parse() - parse host's device-tree node
168212
* @host: host whose node should be parsed.

‎include/linux/mmc/host.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ struct mmc_ios {
7979
bool enhanced_strobe; /* hs400es selection */
8080
};
8181

82+
struct mmc_clk_phase {
83+
bool valid;
84+
u16 in_deg;
85+
u16 out_deg;
86+
};
87+
88+
#define MMC_NUM_CLK_PHASES (MMC_TIMING_MMC_HS400 + 1)
89+
struct mmc_clk_phase_map {
90+
struct mmc_clk_phase phase[MMC_NUM_CLK_PHASES];
91+
};
92+
8293
struct mmc_host;
8394

8495
struct mmc_host_ops {
@@ -490,6 +501,8 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *);
490501
int mmc_add_host(struct mmc_host *);
491502
void mmc_remove_host(struct mmc_host *);
492503
void mmc_free_host(struct mmc_host *);
504+
void mmc_of_parse_clk_phase(struct mmc_host *host,
505+
struct mmc_clk_phase_map *map);
493506
int mmc_of_parse(struct mmc_host *host);
494507
int mmc_of_parse_voltage(struct device_node *np, u32 *mask);
495508

0 commit comments

Comments
 (0)