aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc/core/core.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mmc/core/core.c')
-rw-r--r--drivers/mmc/core/core.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 5d088551196b..bf18b6bfce48 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -27,6 +27,7 @@
27#include <linux/fault-inject.h> 27#include <linux/fault-inject.h>
28#include <linux/random.h> 28#include <linux/random.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/of.h>
30 31
31#include <linux/mmc/card.h> 32#include <linux/mmc/card.h>
32#include <linux/mmc/host.h> 33#include <linux/mmc/host.h>
@@ -1196,6 +1197,49 @@ u32 mmc_vddrange_to_ocrmask(int vdd_min, int vdd_max)
1196} 1197}
1197EXPORT_SYMBOL(mmc_vddrange_to_ocrmask); 1198EXPORT_SYMBOL(mmc_vddrange_to_ocrmask);
1198 1199
1200#ifdef CONFIG_OF
1201
1202/**
1203 * mmc_of_parse_voltage - return mask of supported voltages
1204 * @np: The device node need to be parsed.
1205 * @mask: mask of voltages available for MMC/SD/SDIO
1206 *
1207 * 1. Return zero on success.
1208 * 2. Return negative errno: voltage-range is invalid.
1209 */
1210int mmc_of_parse_voltage(struct device_node *np, u32 *mask)
1211{
1212 const u32 *voltage_ranges;
1213 int num_ranges, i;
1214
1215 voltage_ranges = of_get_property(np, "voltage-ranges", &num_ranges);
1216 num_ranges = num_ranges / sizeof(*voltage_ranges) / 2;
1217 if (!voltage_ranges || !num_ranges) {
1218 pr_info("%s: voltage-ranges unspecified\n", np->full_name);
1219 return -EINVAL;
1220 }
1221
1222 for (i = 0; i < num_ranges; i++) {
1223 const int j = i * 2;
1224 u32 ocr_mask;
1225
1226 ocr_mask = mmc_vddrange_to_ocrmask(
1227 be32_to_cpu(voltage_ranges[j]),
1228 be32_to_cpu(voltage_ranges[j + 1]));
1229 if (!ocr_mask) {
1230 pr_err("%s: voltage-range #%d is invalid\n",
1231 np->full_name, i);
1232 return -EINVAL;
1233 }
1234 *mask |= ocr_mask;
1235 }
1236
1237 return 0;
1238}
1239EXPORT_SYMBOL(mmc_of_parse_voltage);
1240
1241#endif /* CONFIG_OF */
1242
1199#ifdef CONFIG_REGULATOR 1243#ifdef CONFIG_REGULATOR
1200 1244
1201/** 1245/**