aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator/core.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/regulator/core.c')
-rw-r--r--drivers/regulator/core.c341
1 files changed, 0 insertions, 341 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 1034e05fb00a..01d9675b0e83 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1904,77 +1904,6 @@ int regulator_disable_deferred(struct regulator *regulator, int ms)
1904} 1904}
1905EXPORT_SYMBOL_GPL(regulator_disable_deferred); 1905EXPORT_SYMBOL_GPL(regulator_disable_deferred);
1906 1906
1907/**
1908 * regulator_is_enabled_regmap - standard is_enabled() for regmap users
1909 *
1910 * @rdev: regulator to operate on
1911 *
1912 * Regulators that use regmap for their register I/O can set the
1913 * enable_reg and enable_mask fields in their descriptor and then use
1914 * this as their is_enabled operation, saving some code.
1915 */
1916int regulator_is_enabled_regmap(struct regulator_dev *rdev)
1917{
1918 unsigned int val;
1919 int ret;
1920
1921 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
1922 if (ret != 0)
1923 return ret;
1924
1925 if (rdev->desc->enable_is_inverted)
1926 return (val & rdev->desc->enable_mask) == 0;
1927 else
1928 return (val & rdev->desc->enable_mask) != 0;
1929}
1930EXPORT_SYMBOL_GPL(regulator_is_enabled_regmap);
1931
1932/**
1933 * regulator_enable_regmap - standard enable() for regmap users
1934 *
1935 * @rdev: regulator to operate on
1936 *
1937 * Regulators that use regmap for their register I/O can set the
1938 * enable_reg and enable_mask fields in their descriptor and then use
1939 * this as their enable() operation, saving some code.
1940 */
1941int regulator_enable_regmap(struct regulator_dev *rdev)
1942{
1943 unsigned int val;
1944
1945 if (rdev->desc->enable_is_inverted)
1946 val = 0;
1947 else
1948 val = rdev->desc->enable_mask;
1949
1950 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
1951 rdev->desc->enable_mask, val);
1952}
1953EXPORT_SYMBOL_GPL(regulator_enable_regmap);
1954
1955/**
1956 * regulator_disable_regmap - standard disable() for regmap users
1957 *
1958 * @rdev: regulator to operate on
1959 *
1960 * Regulators that use regmap for their register I/O can set the
1961 * enable_reg and enable_mask fields in their descriptor and then use
1962 * this as their disable() operation, saving some code.
1963 */
1964int regulator_disable_regmap(struct regulator_dev *rdev)
1965{
1966 unsigned int val;
1967
1968 if (rdev->desc->enable_is_inverted)
1969 val = rdev->desc->enable_mask;
1970 else
1971 val = 0;
1972
1973 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
1974 rdev->desc->enable_mask, val);
1975}
1976EXPORT_SYMBOL_GPL(regulator_disable_regmap);
1977
1978static int _regulator_is_enabled(struct regulator_dev *rdev) 1907static int _regulator_is_enabled(struct regulator_dev *rdev)
1979{ 1908{
1980 /* A GPIO control always takes precedence */ 1909 /* A GPIO control always takes precedence */
@@ -2239,235 +2168,6 @@ int regulator_is_supported_voltage(struct regulator *regulator,
2239} 2168}
2240EXPORT_SYMBOL_GPL(regulator_is_supported_voltage); 2169EXPORT_SYMBOL_GPL(regulator_is_supported_voltage);
2241 2170
2242/**
2243 * regulator_get_voltage_sel_regmap - standard get_voltage_sel for regmap users
2244 *
2245 * @rdev: regulator to operate on
2246 *
2247 * Regulators that use regmap for their register I/O can set the
2248 * vsel_reg and vsel_mask fields in their descriptor and then use this
2249 * as their get_voltage_vsel operation, saving some code.
2250 */
2251int regulator_get_voltage_sel_regmap(struct regulator_dev *rdev)
2252{
2253 unsigned int val;
2254 int ret;
2255
2256 ret = regmap_read(rdev->regmap, rdev->desc->vsel_reg, &val);
2257 if (ret != 0)
2258 return ret;
2259
2260 val &= rdev->desc->vsel_mask;
2261 val >>= ffs(rdev->desc->vsel_mask) - 1;
2262
2263 return val;
2264}
2265EXPORT_SYMBOL_GPL(regulator_get_voltage_sel_regmap);
2266
2267/**
2268 * regulator_set_voltage_sel_regmap - standard set_voltage_sel for regmap users
2269 *
2270 * @rdev: regulator to operate on
2271 * @sel: Selector to set
2272 *
2273 * Regulators that use regmap for their register I/O can set the
2274 * vsel_reg and vsel_mask fields in their descriptor and then use this
2275 * as their set_voltage_vsel operation, saving some code.
2276 */
2277int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel)
2278{
2279 int ret;
2280
2281 sel <<= ffs(rdev->desc->vsel_mask) - 1;
2282
2283 ret = regmap_update_bits(rdev->regmap, rdev->desc->vsel_reg,
2284 rdev->desc->vsel_mask, sel);
2285 if (ret)
2286 return ret;
2287
2288 if (rdev->desc->apply_bit)
2289 ret = regmap_update_bits(rdev->regmap, rdev->desc->apply_reg,
2290 rdev->desc->apply_bit,
2291 rdev->desc->apply_bit);
2292 return ret;
2293}
2294EXPORT_SYMBOL_GPL(regulator_set_voltage_sel_regmap);
2295
2296/**
2297 * regulator_map_voltage_iterate - map_voltage() based on list_voltage()
2298 *
2299 * @rdev: Regulator to operate on
2300 * @min_uV: Lower bound for voltage
2301 * @max_uV: Upper bound for voltage
2302 *
2303 * Drivers implementing set_voltage_sel() and list_voltage() can use
2304 * this as their map_voltage() operation. It will find a suitable
2305 * voltage by calling list_voltage() until it gets something in bounds
2306 * for the requested voltages.
2307 */
2308int regulator_map_voltage_iterate(struct regulator_dev *rdev,
2309 int min_uV, int max_uV)
2310{
2311 int best_val = INT_MAX;
2312 int selector = 0;
2313 int i, ret;
2314
2315 /* Find the smallest voltage that falls within the specified
2316 * range.
2317 */
2318 for (i = 0; i < rdev->desc->n_voltages; i++) {
2319 ret = rdev->desc->ops->list_voltage(rdev, i);
2320 if (ret < 0)
2321 continue;
2322
2323 if (ret < best_val && ret >= min_uV && ret <= max_uV) {
2324 best_val = ret;
2325 selector = i;
2326 }
2327 }
2328
2329 if (best_val != INT_MAX)
2330 return selector;
2331 else
2332 return -EINVAL;
2333}
2334EXPORT_SYMBOL_GPL(regulator_map_voltage_iterate);
2335
2336/**
2337 * regulator_map_voltage_ascend - map_voltage() for ascendant voltage list
2338 *
2339 * @rdev: Regulator to operate on
2340 * @min_uV: Lower bound for voltage
2341 * @max_uV: Upper bound for voltage
2342 *
2343 * Drivers that have ascendant voltage list can use this as their
2344 * map_voltage() operation.
2345 */
2346int regulator_map_voltage_ascend(struct regulator_dev *rdev,
2347 int min_uV, int max_uV)
2348{
2349 int i, ret;
2350
2351 for (i = 0; i < rdev->desc->n_voltages; i++) {
2352 ret = rdev->desc->ops->list_voltage(rdev, i);
2353 if (ret < 0)
2354 continue;
2355
2356 if (ret > max_uV)
2357 break;
2358
2359 if (ret >= min_uV && ret <= max_uV)
2360 return i;
2361 }
2362
2363 return -EINVAL;
2364}
2365EXPORT_SYMBOL_GPL(regulator_map_voltage_ascend);
2366
2367/**
2368 * regulator_map_voltage_linear - map_voltage() for simple linear mappings
2369 *
2370 * @rdev: Regulator to operate on
2371 * @min_uV: Lower bound for voltage
2372 * @max_uV: Upper bound for voltage
2373 *
2374 * Drivers providing min_uV and uV_step in their regulator_desc can
2375 * use this as their map_voltage() operation.
2376 */
2377int regulator_map_voltage_linear(struct regulator_dev *rdev,
2378 int min_uV, int max_uV)
2379{
2380 int ret, voltage;
2381
2382 /* Allow uV_step to be 0 for fixed voltage */
2383 if (rdev->desc->n_voltages == 1 && rdev->desc->uV_step == 0) {
2384 if (min_uV <= rdev->desc->min_uV && rdev->desc->min_uV <= max_uV)
2385 return 0;
2386 else
2387 return -EINVAL;
2388 }
2389
2390 if (!rdev->desc->uV_step) {
2391 BUG_ON(!rdev->desc->uV_step);
2392 return -EINVAL;
2393 }
2394
2395 if (min_uV < rdev->desc->min_uV)
2396 min_uV = rdev->desc->min_uV;
2397
2398 ret = DIV_ROUND_UP(min_uV - rdev->desc->min_uV, rdev->desc->uV_step);
2399 if (ret < 0)
2400 return ret;
2401
2402 ret += rdev->desc->linear_min_sel;
2403
2404 /* Map back into a voltage to verify we're still in bounds */
2405 voltage = rdev->desc->ops->list_voltage(rdev, ret);
2406 if (voltage < min_uV || voltage > max_uV)
2407 return -EINVAL;
2408
2409 return ret;
2410}
2411EXPORT_SYMBOL_GPL(regulator_map_voltage_linear);
2412
2413/**
2414 * regulator_map_voltage_linear - map_voltage() for multiple linear ranges
2415 *
2416 * @rdev: Regulator to operate on
2417 * @min_uV: Lower bound for voltage
2418 * @max_uV: Upper bound for voltage
2419 *
2420 * Drivers providing linear_ranges in their descriptor can use this as
2421 * their map_voltage() callback.
2422 */
2423int regulator_map_voltage_linear_range(struct regulator_dev *rdev,
2424 int min_uV, int max_uV)
2425{
2426 const struct regulator_linear_range *range;
2427 int ret = -EINVAL;
2428 int voltage, i;
2429
2430 if (!rdev->desc->n_linear_ranges) {
2431 BUG_ON(!rdev->desc->n_linear_ranges);
2432 return -EINVAL;
2433 }
2434
2435 for (i = 0; i < rdev->desc->n_linear_ranges; i++) {
2436 range = &rdev->desc->linear_ranges[i];
2437
2438 if (!(min_uV <= range->max_uV && max_uV >= range->min_uV))
2439 continue;
2440
2441 if (min_uV <= range->min_uV)
2442 min_uV = range->min_uV;
2443
2444 /* range->uV_step == 0 means fixed voltage range */
2445 if (range->uV_step == 0) {
2446 ret = 0;
2447 } else {
2448 ret = DIV_ROUND_UP(min_uV - range->min_uV,
2449 range->uV_step);
2450 if (ret < 0)
2451 return ret;
2452 }
2453
2454 ret += range->min_sel;
2455
2456 break;
2457 }
2458
2459 if (i == rdev->desc->n_linear_ranges)
2460 return -EINVAL;
2461
2462 /* Map back into a voltage to verify we're still in bounds */
2463 voltage = rdev->desc->ops->list_voltage(rdev, ret);
2464 if (voltage < min_uV || voltage > max_uV)
2465 return -EINVAL;
2466
2467 return ret;
2468}
2469EXPORT_SYMBOL_GPL(regulator_map_voltage_linear_range);
2470
2471static int _regulator_do_set_voltage(struct regulator_dev *rdev, 2171static int _regulator_do_set_voltage(struct regulator_dev *rdev,
2472 int min_uV, int max_uV) 2172 int min_uV, int max_uV)
2473{ 2173{
@@ -3071,47 +2771,6 @@ out:
3071EXPORT_SYMBOL_GPL(regulator_set_optimum_mode); 2771EXPORT_SYMBOL_GPL(regulator_set_optimum_mode);
3072 2772
3073/** 2773/**
3074 * regulator_set_bypass_regmap - Default set_bypass() using regmap
3075 *
3076 * @rdev: device to operate on.
3077 * @enable: state to set.
3078 */
3079int regulator_set_bypass_regmap(struct regulator_dev *rdev, bool enable)
3080{
3081 unsigned int val;
3082
3083 if (enable)
3084 val = rdev->desc->bypass_mask;
3085 else
3086 val = 0;
3087
3088 return regmap_update_bits(rdev->regmap, rdev->desc->bypass_reg,
3089 rdev->desc->bypass_mask, val);
3090}
3091EXPORT_SYMBOL_GPL(regulator_set_bypass_regmap);
3092
3093/**
3094 * regulator_get_bypass_regmap - Default get_bypass() using regmap
3095 *
3096 * @rdev: device to operate on.
3097 * @enable: current state.
3098 */
3099int regulator_get_bypass_regmap(struct regulator_dev *rdev, bool *enable)
3100{
3101 unsigned int val;
3102 int ret;
3103
3104 ret = regmap_read(rdev->regmap, rdev->desc->bypass_reg, &val);
3105 if (ret != 0)
3106 return ret;
3107
3108 *enable = val & rdev->desc->bypass_mask;
3109
3110 return 0;
3111}
3112EXPORT_SYMBOL_GPL(regulator_get_bypass_regmap);
3113
3114/**
3115 * regulator_allow_bypass - allow the regulator to go into bypass mode 2774 * regulator_allow_bypass - allow the regulator to go into bypass mode
3116 * 2775 *
3117 * @regulator: Regulator to configure 2776 * @regulator: Regulator to configure