Skip to content

Commit 9d2d243

Browse files
committed
mmc: core: Move mmc_of_parse_voltage() to host.c
MMC OF parsing functions, which parses various host DT properties, should stay close to each other. Therefore, let's move mmc_of_parse_voltage() close to mmc_of_parse() into host.c. Additionally, there is no reason to build the code only when CONFIG_OF is set, as there should be stub functions for the OF helpers that is being used, so let's drop this condition as well. Signed-off-by: Ulf Hansson <[email protected]>
1 parent 3958790 commit 9d2d243

File tree

2 files changed

+44
-48
lines changed

2 files changed

+44
-48
lines changed

drivers/mmc/core/core.c

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,54 +1112,6 @@ u32 mmc_vddrange_to_ocrmask(int vdd_min, int vdd_max)
11121112
return mask;
11131113
}
11141114

1115-
#ifdef CONFIG_OF
1116-
1117-
/**
1118-
* mmc_of_parse_voltage - return mask of supported voltages
1119-
* @np: The device node need to be parsed.
1120-
* @mask: mask of voltages available for MMC/SD/SDIO
1121-
*
1122-
* Parse the "voltage-ranges" DT property, returning zero if it is not
1123-
* found, negative errno if the voltage-range specification is invalid,
1124-
* or one if the voltage-range is specified and successfully parsed.
1125-
*/
1126-
int mmc_of_parse_voltage(struct device_node *np, u32 *mask)
1127-
{
1128-
const u32 *voltage_ranges;
1129-
int num_ranges, i;
1130-
1131-
voltage_ranges = of_get_property(np, "voltage-ranges", &num_ranges);
1132-
num_ranges = num_ranges / sizeof(*voltage_ranges) / 2;
1133-
if (!voltage_ranges) {
1134-
pr_debug("%pOF: voltage-ranges unspecified\n", np);
1135-
return 0;
1136-
}
1137-
if (!num_ranges) {
1138-
pr_err("%pOF: voltage-ranges empty\n", np);
1139-
return -EINVAL;
1140-
}
1141-
1142-
for (i = 0; i < num_ranges; i++) {
1143-
const int j = i * 2;
1144-
u32 ocr_mask;
1145-
1146-
ocr_mask = mmc_vddrange_to_ocrmask(
1147-
be32_to_cpu(voltage_ranges[j]),
1148-
be32_to_cpu(voltage_ranges[j + 1]));
1149-
if (!ocr_mask) {
1150-
pr_err("%pOF: voltage-range #%d is invalid\n",
1151-
np, i);
1152-
return -EINVAL;
1153-
}
1154-
*mask |= ocr_mask;
1155-
}
1156-
1157-
return 1;
1158-
}
1159-
EXPORT_SYMBOL(mmc_of_parse_voltage);
1160-
1161-
#endif /* CONFIG_OF */
1162-
11631115
static int mmc_of_get_func_num(struct device_node *node)
11641116
{
11651117
u32 reg;

drivers/mmc/core/host.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,50 @@ int mmc_of_parse(struct mmc_host *host)
348348

349349
EXPORT_SYMBOL(mmc_of_parse);
350350

351+
/**
352+
* mmc_of_parse_voltage - return mask of supported voltages
353+
* @np: The device node need to be parsed.
354+
* @mask: mask of voltages available for MMC/SD/SDIO
355+
*
356+
* Parse the "voltage-ranges" DT property, returning zero if it is not
357+
* found, negative errno if the voltage-range specification is invalid,
358+
* or one if the voltage-range is specified and successfully parsed.
359+
*/
360+
int mmc_of_parse_voltage(struct device_node *np, u32 *mask)
361+
{
362+
const u32 *voltage_ranges;
363+
int num_ranges, i;
364+
365+
voltage_ranges = of_get_property(np, "voltage-ranges", &num_ranges);
366+
num_ranges = num_ranges / sizeof(*voltage_ranges) / 2;
367+
if (!voltage_ranges) {
368+
pr_debug("%pOF: voltage-ranges unspecified\n", np);
369+
return 0;
370+
}
371+
if (!num_ranges) {
372+
pr_err("%pOF: voltage-ranges empty\n", np);
373+
return -EINVAL;
374+
}
375+
376+
for (i = 0; i < num_ranges; i++) {
377+
const int j = i * 2;
378+
u32 ocr_mask;
379+
380+
ocr_mask = mmc_vddrange_to_ocrmask(
381+
be32_to_cpu(voltage_ranges[j]),
382+
be32_to_cpu(voltage_ranges[j + 1]));
383+
if (!ocr_mask) {
384+
pr_err("%pOF: voltage-range #%d is invalid\n",
385+
np, i);
386+
return -EINVAL;
387+
}
388+
*mask |= ocr_mask;
389+
}
390+
391+
return 1;
392+
}
393+
EXPORT_SYMBOL(mmc_of_parse_voltage);
394+
351395
/**
352396
* mmc_alloc_host - initialise the per-host structure.
353397
* @extra: sizeof private data structure

0 commit comments

Comments
 (0)