core.c revision 69279fb9a95051971ac03e558c4d46e7ba84ab3a
1414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/* 2414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * core.c -- Voltage/Current Regulator framework. 3414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 4414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Copyright 2007, 2008 Wolfson Microelectronics PLC. 5a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * Copyright 2008 SlimLogic Ltd. 6414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 7a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * Author: Liam Girdwood <lrg@slimlogic.co.uk> 8414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 9414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * This program is free software; you can redistribute it and/or modify it 10414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * under the terms of the GNU General Public License as published by the 11414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Free Software Foundation; either version 2 of the License, or (at your 12414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * option) any later version. 13414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 14414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 15414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 16414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood#include <linux/kernel.h> 17414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood#include <linux/init.h> 18414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood#include <linux/device.h> 19414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood#include <linux/err.h> 20414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood#include <linux/mutex.h> 21414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood#include <linux/suspend.h> 22414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood#include <linux/regulator/consumer.h> 23414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood#include <linux/regulator/driver.h> 24414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood#include <linux/regulator/machine.h> 25414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 26414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood#define REGULATOR_VERSION "0.5" 27414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 28414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic DEFINE_MUTEX(regulator_list_mutex); 29414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic LIST_HEAD(regulator_list); 30414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic LIST_HEAD(regulator_map_list); 31414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 328dc5390d4f3fd8acc73773a56fea13544e7924dcMark Brown/* 33414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * struct regulator_dev 34414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 35414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Voltage / Current regulator class device. One for each regulator. 36414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 37414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstruct regulator_dev { 38414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_desc *desc; 39414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int use_count; 40414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 41414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* lists we belong to */ 42414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct list_head list; /* list of all regulators */ 43414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct list_head slist; /* list of supplied regulators */ 44414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 45414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* lists we own */ 46414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct list_head consumer_list; /* consumers we supply */ 47414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct list_head supply_list; /* regulators we supply */ 48414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 49414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct blocking_notifier_head notifier; 50414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct mutex mutex; /* consumer lock */ 51414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct module *owner; 52414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct device dev; 53414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulation_constraints *constraints; 54414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_dev *supply; /* for tree */ 55414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 56414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood void *reg_data; /* regulator_dev data */ 57414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood}; 58414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 598dc5390d4f3fd8acc73773a56fea13544e7924dcMark Brown/* 60414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * struct regulator_map 61414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 62414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Used to provide symbolic supply names to devices. 63414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 64414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstruct regulator_map { 65414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct list_head list; 66414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct device *dev; 67414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood const char *supply; 68a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulator_dev *regulator; 69414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood}; 70414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 71414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/* 72414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * struct regulator 73414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 74414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * One for each consumer device. 75414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 76414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstruct regulator { 77414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct device *dev; 78414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct list_head list; 79414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int uA_load; 80414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int min_uV; 81414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int max_uV; 82412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell int enabled; /* count of client enables */ 83414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood char *supply_name; 84414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct device_attribute dev_attr; 85414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_dev *rdev; 86414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood}; 87414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 88414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic int _regulator_is_enabled(struct regulator_dev *rdev); 89414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic int _regulator_disable(struct regulator_dev *rdev); 90414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic int _regulator_get_voltage(struct regulator_dev *rdev); 91414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic int _regulator_get_current_limit(struct regulator_dev *rdev); 92414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic unsigned int _regulator_get_mode(struct regulator_dev *rdev); 93414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic void _notifier_call_chain(struct regulator_dev *rdev, 94414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood unsigned long event, void *data); 95414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 96414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/* gets the regulator for a given consumer device */ 97414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic struct regulator *get_device_regulator(struct device *dev) 98414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 99414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator *regulator = NULL; 100414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_dev *rdev; 101414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 102414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(®ulator_list_mutex); 103414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood list_for_each_entry(rdev, ®ulator_list, list) { 104414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(&rdev->mutex); 105414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood list_for_each_entry(regulator, &rdev->consumer_list, list) { 106414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (regulator->dev == dev) { 107414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(&rdev->mutex); 108414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(®ulator_list_mutex); 109414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return regulator; 110414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 111414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 112414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(&rdev->mutex); 113414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 114414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(®ulator_list_mutex); 115414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return NULL; 116414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 117414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 118414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/* Platform voltage constraint check */ 119414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic int regulator_check_voltage(struct regulator_dev *rdev, 120414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int *min_uV, int *max_uV) 121414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 122414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood BUG_ON(*min_uV > *max_uV); 123414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 124414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!rdev->constraints) { 125414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: no constraints for %s\n", __func__, 126414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood rdev->desc->name); 127414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return -ENODEV; 128414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 129414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) { 130414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: operation not allowed for %s\n", 131414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood __func__, rdev->desc->name); 132414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return -EPERM; 133414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 134414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 135414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (*max_uV > rdev->constraints->max_uV) 136414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood *max_uV = rdev->constraints->max_uV; 137414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (*min_uV < rdev->constraints->min_uV) 138414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood *min_uV = rdev->constraints->min_uV; 139414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 140414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (*min_uV > *max_uV) 141414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return -EINVAL; 142414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 143414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return 0; 144414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 145414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 146414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/* current constraint check */ 147414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic int regulator_check_current_limit(struct regulator_dev *rdev, 148414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int *min_uA, int *max_uA) 149414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 150414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood BUG_ON(*min_uA > *max_uA); 151414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 152414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!rdev->constraints) { 153414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: no constraints for %s\n", __func__, 154414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood rdev->desc->name); 155414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return -ENODEV; 156414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 157414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_CURRENT)) { 158414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: operation not allowed for %s\n", 159414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood __func__, rdev->desc->name); 160414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return -EPERM; 161414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 162414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 163414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (*max_uA > rdev->constraints->max_uA) 164414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood *max_uA = rdev->constraints->max_uA; 165414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (*min_uA < rdev->constraints->min_uA) 166414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood *min_uA = rdev->constraints->min_uA; 167414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 168414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (*min_uA > *max_uA) 169414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return -EINVAL; 170414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 171414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return 0; 172414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 173414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 174414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/* operating mode constraint check */ 175414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic int regulator_check_mode(struct regulator_dev *rdev, int mode) 176414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 177e573520b171095c106ffbbbf4f9cbed6d9bff576David Brownell switch (mode) { 178e573520b171095c106ffbbbf4f9cbed6d9bff576David Brownell case REGULATOR_MODE_FAST: 179e573520b171095c106ffbbbf4f9cbed6d9bff576David Brownell case REGULATOR_MODE_NORMAL: 180e573520b171095c106ffbbbf4f9cbed6d9bff576David Brownell case REGULATOR_MODE_IDLE: 181e573520b171095c106ffbbbf4f9cbed6d9bff576David Brownell case REGULATOR_MODE_STANDBY: 182e573520b171095c106ffbbbf4f9cbed6d9bff576David Brownell break; 183e573520b171095c106ffbbbf4f9cbed6d9bff576David Brownell default: 184e573520b171095c106ffbbbf4f9cbed6d9bff576David Brownell return -EINVAL; 185e573520b171095c106ffbbbf4f9cbed6d9bff576David Brownell } 186e573520b171095c106ffbbbf4f9cbed6d9bff576David Brownell 187414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!rdev->constraints) { 188414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: no constraints for %s\n", __func__, 189414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood rdev->desc->name); 190414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return -ENODEV; 191414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 192414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_MODE)) { 193414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: operation not allowed for %s\n", 194414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood __func__, rdev->desc->name); 195414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return -EPERM; 196414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 197414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!(rdev->constraints->valid_modes_mask & mode)) { 198414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: invalid mode %x for %s\n", 199414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood __func__, mode, rdev->desc->name); 200414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return -EINVAL; 201414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 202414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return 0; 203414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 204414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 205414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/* dynamic regulator mode switching constraint check */ 206414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic int regulator_check_drms(struct regulator_dev *rdev) 207414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 208414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!rdev->constraints) { 209414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: no constraints for %s\n", __func__, 210414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood rdev->desc->name); 211414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return -ENODEV; 212414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 213414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) { 214414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: operation not allowed for %s\n", 215414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood __func__, rdev->desc->name); 216414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return -EPERM; 217414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 218414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return 0; 219414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 220414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 221414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic ssize_t device_requested_uA_show(struct device *dev, 222414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct device_attribute *attr, char *buf) 223414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 224414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator *regulator; 225414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 226414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator = get_device_regulator(dev); 227414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (regulator == NULL) 228414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return 0; 229414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 230414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return sprintf(buf, "%d\n", regulator->uA_load); 231414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 232414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 233414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic ssize_t regulator_uV_show(struct device *dev, 234414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct device_attribute *attr, char *buf) 235414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 236a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulator_dev *rdev = dev_get_drvdata(dev); 237414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ssize_t ret; 238414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 239414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(&rdev->mutex); 240414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = sprintf(buf, "%d\n", _regulator_get_voltage(rdev)); 241414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(&rdev->mutex); 242414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 243414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 244414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 2457ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownellstatic DEVICE_ATTR(microvolts, 0444, regulator_uV_show, NULL); 246414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 247414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic ssize_t regulator_uA_show(struct device *dev, 248414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct device_attribute *attr, char *buf) 249414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 250a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulator_dev *rdev = dev_get_drvdata(dev); 251414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 252414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return sprintf(buf, "%d\n", _regulator_get_current_limit(rdev)); 253414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 2547ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownellstatic DEVICE_ATTR(microamps, 0444, regulator_uA_show, NULL); 255414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 256bc558a60b58f638ee0188affb627d4894a97b1c7Mark Brownstatic ssize_t regulator_name_show(struct device *dev, 257bc558a60b58f638ee0188affb627d4894a97b1c7Mark Brown struct device_attribute *attr, char *buf) 258bc558a60b58f638ee0188affb627d4894a97b1c7Mark Brown{ 259bc558a60b58f638ee0188affb627d4894a97b1c7Mark Brown struct regulator_dev *rdev = dev_get_drvdata(dev); 260bc558a60b58f638ee0188affb627d4894a97b1c7Mark Brown const char *name; 261bc558a60b58f638ee0188affb627d4894a97b1c7Mark Brown 262bc558a60b58f638ee0188affb627d4894a97b1c7Mark Brown if (rdev->constraints->name) 263bc558a60b58f638ee0188affb627d4894a97b1c7Mark Brown name = rdev->constraints->name; 264bc558a60b58f638ee0188affb627d4894a97b1c7Mark Brown else if (rdev->desc->name) 265bc558a60b58f638ee0188affb627d4894a97b1c7Mark Brown name = rdev->desc->name; 266bc558a60b58f638ee0188affb627d4894a97b1c7Mark Brown else 267bc558a60b58f638ee0188affb627d4894a97b1c7Mark Brown name = ""; 268bc558a60b58f638ee0188affb627d4894a97b1c7Mark Brown 269bc558a60b58f638ee0188affb627d4894a97b1c7Mark Brown return sprintf(buf, "%s\n", name); 270bc558a60b58f638ee0188affb627d4894a97b1c7Mark Brown} 271bc558a60b58f638ee0188affb627d4894a97b1c7Mark Brown 2724fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownellstatic ssize_t regulator_print_opmode(char *buf, int mode) 273414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 274414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood switch (mode) { 275414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood case REGULATOR_MODE_FAST: 276414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return sprintf(buf, "fast\n"); 277414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood case REGULATOR_MODE_NORMAL: 278414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return sprintf(buf, "normal\n"); 279414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood case REGULATOR_MODE_IDLE: 280414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return sprintf(buf, "idle\n"); 281414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood case REGULATOR_MODE_STANDBY: 282414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return sprintf(buf, "standby\n"); 283414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 284414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return sprintf(buf, "unknown\n"); 285414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 286414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 2874fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownellstatic ssize_t regulator_opmode_show(struct device *dev, 2884fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell struct device_attribute *attr, char *buf) 289414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 290a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulator_dev *rdev = dev_get_drvdata(dev); 291414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 2924fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell return regulator_print_opmode(buf, _regulator_get_mode(rdev)); 2934fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell} 2947ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownellstatic DEVICE_ATTR(opmode, 0444, regulator_opmode_show, NULL); 2954fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell 2964fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownellstatic ssize_t regulator_print_state(char *buf, int state) 2974fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell{ 298414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (state > 0) 299414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return sprintf(buf, "enabled\n"); 300414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood else if (state == 0) 301414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return sprintf(buf, "disabled\n"); 302414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood else 303414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return sprintf(buf, "unknown\n"); 304414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 305414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 3064fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownellstatic ssize_t regulator_state_show(struct device *dev, 3074fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell struct device_attribute *attr, char *buf) 3084fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell{ 3094fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell struct regulator_dev *rdev = dev_get_drvdata(dev); 3104fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell 3114fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell return regulator_print_state(buf, _regulator_is_enabled(rdev)); 3124fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell} 3137ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownellstatic DEVICE_ATTR(state, 0444, regulator_state_show, NULL); 3144fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell 315414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic ssize_t regulator_min_uA_show(struct device *dev, 316414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct device_attribute *attr, char *buf) 317414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 318a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulator_dev *rdev = dev_get_drvdata(dev); 319414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 320414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!rdev->constraints) 321414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return sprintf(buf, "constraint not defined\n"); 322414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 323414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return sprintf(buf, "%d\n", rdev->constraints->min_uA); 324414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 3257ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownellstatic DEVICE_ATTR(min_microamps, 0444, regulator_min_uA_show, NULL); 326414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 327414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic ssize_t regulator_max_uA_show(struct device *dev, 328414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct device_attribute *attr, char *buf) 329414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 330a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulator_dev *rdev = dev_get_drvdata(dev); 331414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 332414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!rdev->constraints) 333414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return sprintf(buf, "constraint not defined\n"); 334414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 335414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return sprintf(buf, "%d\n", rdev->constraints->max_uA); 336414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 3377ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownellstatic DEVICE_ATTR(max_microamps, 0444, regulator_max_uA_show, NULL); 338414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 339414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic ssize_t regulator_min_uV_show(struct device *dev, 340414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct device_attribute *attr, char *buf) 341414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 342a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulator_dev *rdev = dev_get_drvdata(dev); 343414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 344414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!rdev->constraints) 345414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return sprintf(buf, "constraint not defined\n"); 346414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 347414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return sprintf(buf, "%d\n", rdev->constraints->min_uV); 348414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 3497ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownellstatic DEVICE_ATTR(min_microvolts, 0444, regulator_min_uV_show, NULL); 350414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 351414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic ssize_t regulator_max_uV_show(struct device *dev, 352414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct device_attribute *attr, char *buf) 353414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 354a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulator_dev *rdev = dev_get_drvdata(dev); 355414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 356414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!rdev->constraints) 357414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return sprintf(buf, "constraint not defined\n"); 358414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 359414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return sprintf(buf, "%d\n", rdev->constraints->max_uV); 360414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 3617ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownellstatic DEVICE_ATTR(max_microvolts, 0444, regulator_max_uV_show, NULL); 362414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 363414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic ssize_t regulator_total_uA_show(struct device *dev, 364414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct device_attribute *attr, char *buf) 365414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 366a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulator_dev *rdev = dev_get_drvdata(dev); 367414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator *regulator; 368414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int uA = 0; 369414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 370414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(&rdev->mutex); 371414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood list_for_each_entry(regulator, &rdev->consumer_list, list) 372414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood uA += regulator->uA_load; 373414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(&rdev->mutex); 374414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return sprintf(buf, "%d\n", uA); 375414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 3767ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownellstatic DEVICE_ATTR(requested_microamps, 0444, regulator_total_uA_show, NULL); 377414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 378414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic ssize_t regulator_num_users_show(struct device *dev, 379414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct device_attribute *attr, char *buf) 380414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 381a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulator_dev *rdev = dev_get_drvdata(dev); 382414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return sprintf(buf, "%d\n", rdev->use_count); 383414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 384414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 385414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic ssize_t regulator_type_show(struct device *dev, 386414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct device_attribute *attr, char *buf) 387414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 388a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulator_dev *rdev = dev_get_drvdata(dev); 389414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 390414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood switch (rdev->desc->type) { 391414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood case REGULATOR_VOLTAGE: 392414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return sprintf(buf, "voltage\n"); 393414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood case REGULATOR_CURRENT: 394414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return sprintf(buf, "current\n"); 395414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 396414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return sprintf(buf, "unknown\n"); 397414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 398414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 399414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic ssize_t regulator_suspend_mem_uV_show(struct device *dev, 400414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct device_attribute *attr, char *buf) 401414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 402a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulator_dev *rdev = dev_get_drvdata(dev); 403414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 404414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return sprintf(buf, "%d\n", rdev->constraints->state_mem.uV); 405414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 4067ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownellstatic DEVICE_ATTR(suspend_mem_microvolts, 0444, 4077ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell regulator_suspend_mem_uV_show, NULL); 408414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 409414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic ssize_t regulator_suspend_disk_uV_show(struct device *dev, 410414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct device_attribute *attr, char *buf) 411414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 412a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulator_dev *rdev = dev_get_drvdata(dev); 413414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 414414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return sprintf(buf, "%d\n", rdev->constraints->state_disk.uV); 415414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 4167ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownellstatic DEVICE_ATTR(suspend_disk_microvolts, 0444, 4177ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell regulator_suspend_disk_uV_show, NULL); 418414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 419414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic ssize_t regulator_suspend_standby_uV_show(struct device *dev, 420414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct device_attribute *attr, char *buf) 421414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 422a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulator_dev *rdev = dev_get_drvdata(dev); 423414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 424414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return sprintf(buf, "%d\n", rdev->constraints->state_standby.uV); 425414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 4267ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownellstatic DEVICE_ATTR(suspend_standby_microvolts, 0444, 4277ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell regulator_suspend_standby_uV_show, NULL); 428414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 429414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic ssize_t regulator_suspend_mem_mode_show(struct device *dev, 430414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct device_attribute *attr, char *buf) 431414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 432a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulator_dev *rdev = dev_get_drvdata(dev); 433414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 4344fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell return regulator_print_opmode(buf, 4354fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell rdev->constraints->state_mem.mode); 436414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 4377ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownellstatic DEVICE_ATTR(suspend_mem_mode, 0444, 4387ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell regulator_suspend_mem_mode_show, NULL); 439414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 440414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic ssize_t regulator_suspend_disk_mode_show(struct device *dev, 441414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct device_attribute *attr, char *buf) 442414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 443a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulator_dev *rdev = dev_get_drvdata(dev); 444414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 4454fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell return regulator_print_opmode(buf, 4464fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell rdev->constraints->state_disk.mode); 447414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 4487ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownellstatic DEVICE_ATTR(suspend_disk_mode, 0444, 4497ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell regulator_suspend_disk_mode_show, NULL); 450414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 451414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic ssize_t regulator_suspend_standby_mode_show(struct device *dev, 452414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct device_attribute *attr, char *buf) 453414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 454a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulator_dev *rdev = dev_get_drvdata(dev); 455414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 4564fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell return regulator_print_opmode(buf, 4574fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell rdev->constraints->state_standby.mode); 458414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 4597ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownellstatic DEVICE_ATTR(suspend_standby_mode, 0444, 4607ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell regulator_suspend_standby_mode_show, NULL); 461414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 462414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic ssize_t regulator_suspend_mem_state_show(struct device *dev, 463414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct device_attribute *attr, char *buf) 464414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 465a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulator_dev *rdev = dev_get_drvdata(dev); 466414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 4674fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell return regulator_print_state(buf, 4684fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell rdev->constraints->state_mem.enabled); 469414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 4707ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownellstatic DEVICE_ATTR(suspend_mem_state, 0444, 4717ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell regulator_suspend_mem_state_show, NULL); 472414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 473414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic ssize_t regulator_suspend_disk_state_show(struct device *dev, 474414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct device_attribute *attr, char *buf) 475414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 476a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulator_dev *rdev = dev_get_drvdata(dev); 477414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 4784fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell return regulator_print_state(buf, 4794fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell rdev->constraints->state_disk.enabled); 480414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 4817ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownellstatic DEVICE_ATTR(suspend_disk_state, 0444, 4827ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell regulator_suspend_disk_state_show, NULL); 483414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 484414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic ssize_t regulator_suspend_standby_state_show(struct device *dev, 485414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct device_attribute *attr, char *buf) 486414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 487a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulator_dev *rdev = dev_get_drvdata(dev); 488414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 4894fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell return regulator_print_state(buf, 4904fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell rdev->constraints->state_standby.enabled); 491414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 4927ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownellstatic DEVICE_ATTR(suspend_standby_state, 0444, 4937ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell regulator_suspend_standby_state_show, NULL); 4947ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell 495bc558a60b58f638ee0188affb627d4894a97b1c7Mark Brown 4967ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell/* 4977ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell * These are the only attributes are present for all regulators. 4987ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell * Other attributes are a function of regulator functionality. 4997ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell */ 500414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic struct device_attribute regulator_dev_attrs[] = { 501bc558a60b58f638ee0188affb627d4894a97b1c7Mark Brown __ATTR(name, 0444, regulator_name_show, NULL), 502414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood __ATTR(num_users, 0444, regulator_num_users_show, NULL), 503414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood __ATTR(type, 0444, regulator_type_show, NULL), 504414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood __ATTR_NULL, 505414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood}; 506414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 507414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic void regulator_dev_release(struct device *dev) 508414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 509a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulator_dev *rdev = dev_get_drvdata(dev); 510414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood kfree(rdev); 511414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 512414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 513414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic struct class regulator_class = { 514414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood .name = "regulator", 515414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood .dev_release = regulator_dev_release, 516414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood .dev_attrs = regulator_dev_attrs, 517414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood}; 518414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 519414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/* Calculate the new optimum regulator operating mode based on the new total 520414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * consumer load. All locks held by caller */ 521414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic void drms_uA_update(struct regulator_dev *rdev) 522414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 523414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator *sibling; 524414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int current_uA = 0, output_uV, input_uV, err; 525414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood unsigned int mode; 526414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 527414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood err = regulator_check_drms(rdev); 528414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (err < 0 || !rdev->desc->ops->get_optimum_mode || 529414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood !rdev->desc->ops->get_voltage || !rdev->desc->ops->set_mode); 530414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return; 531414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 532414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* get output voltage */ 533414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood output_uV = rdev->desc->ops->get_voltage(rdev); 534414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (output_uV <= 0) 535414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return; 536414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 537414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* get input voltage */ 538414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev->supply && rdev->supply->desc->ops->get_voltage) 539414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood input_uV = rdev->supply->desc->ops->get_voltage(rdev->supply); 540414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood else 541414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood input_uV = rdev->constraints->input_uV; 542414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (input_uV <= 0) 543414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return; 544414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 545414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* calc total requested load */ 546414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood list_for_each_entry(sibling, &rdev->consumer_list, list) 547414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood current_uA += sibling->uA_load; 548414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 549414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* now get the optimum mode for our new total regulator load */ 550414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mode = rdev->desc->ops->get_optimum_mode(rdev, input_uV, 551414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood output_uV, current_uA); 552414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 553414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* check the new mode is allowed */ 554414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood err = regulator_check_mode(rdev, mode); 555414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (err == 0) 556414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood rdev->desc->ops->set_mode(rdev, mode); 557414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 558414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 559414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic int suspend_set_state(struct regulator_dev *rdev, 560414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_state *rstate) 561414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 562414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret = 0; 563414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 564414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* enable & disable are mandatory for suspend control */ 565414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!rdev->desc->ops->set_suspend_enable || 566a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood !rdev->desc->ops->set_suspend_disable) { 567a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood printk(KERN_ERR "%s: no way to set suspend state\n", 568a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood __func__); 569414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return -EINVAL; 570a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood } 571414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 572414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rstate->enabled) 573414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = rdev->desc->ops->set_suspend_enable(rdev); 574414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood else 575414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = rdev->desc->ops->set_suspend_disable(rdev); 576414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (ret < 0) { 577414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: failed to enabled/disable\n", __func__); 578414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 579414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 580414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 581414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev->desc->ops->set_suspend_voltage && rstate->uV > 0) { 582414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = rdev->desc->ops->set_suspend_voltage(rdev, rstate->uV); 583414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (ret < 0) { 584414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: failed to set voltage\n", 585414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood __func__); 586414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 587414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 588414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 589414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 590414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev->desc->ops->set_suspend_mode && rstate->mode > 0) { 591414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = rdev->desc->ops->set_suspend_mode(rdev, rstate->mode); 592414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (ret < 0) { 593414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: failed to set mode\n", __func__); 594414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 595414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 596414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 597414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 598414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 599414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 600414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/* locks held by caller */ 601414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic int suspend_prepare(struct regulator_dev *rdev, suspend_state_t state) 602414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 603414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!rdev->constraints) 604414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return -EINVAL; 605414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 606414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood switch (state) { 607414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood case PM_SUSPEND_STANDBY: 608414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return suspend_set_state(rdev, 609414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood &rdev->constraints->state_standby); 610414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood case PM_SUSPEND_MEM: 611414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return suspend_set_state(rdev, 612414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood &rdev->constraints->state_mem); 613414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood case PM_SUSPEND_MAX: 614414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return suspend_set_state(rdev, 615414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood &rdev->constraints->state_disk); 616414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood default: 617414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return -EINVAL; 618414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 619414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 620414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 621414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic void print_constraints(struct regulator_dev *rdev) 622414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 623414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulation_constraints *constraints = rdev->constraints; 624414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood char buf[80]; 625414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int count; 626414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 627414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev->desc->type == REGULATOR_VOLTAGE) { 628414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (constraints->min_uV == constraints->max_uV) 629414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood count = sprintf(buf, "%d mV ", 630414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood constraints->min_uV / 1000); 631414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood else 632414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood count = sprintf(buf, "%d <--> %d mV ", 633414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood constraints->min_uV / 1000, 634414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood constraints->max_uV / 1000); 635414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } else { 636414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (constraints->min_uA == constraints->max_uA) 637414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood count = sprintf(buf, "%d mA ", 638414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood constraints->min_uA / 1000); 639414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood else 640414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood count = sprintf(buf, "%d <--> %d mA ", 641414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood constraints->min_uA / 1000, 642414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood constraints->max_uA / 1000); 643414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 644414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (constraints->valid_modes_mask & REGULATOR_MODE_FAST) 645414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood count += sprintf(buf + count, "fast "); 646414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (constraints->valid_modes_mask & REGULATOR_MODE_NORMAL) 647414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood count += sprintf(buf + count, "normal "); 648414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (constraints->valid_modes_mask & REGULATOR_MODE_IDLE) 649414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood count += sprintf(buf + count, "idle "); 650414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY) 651414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood count += sprintf(buf + count, "standby"); 652414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 653414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_INFO "regulator: %s: %s\n", rdev->desc->name, buf); 654414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 655414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 656a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood/** 657a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * set_machine_constraints - sets regulator constraints 65869279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @rdev: regulator source 659a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * 660a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * Allows platform initialisation code to define and constrain 661a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * regulator circuits e.g. valid voltage/current ranges, etc. NOTE: 662a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * Constraints *must* be set by platform code in order for some 663a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * regulator operations to proceed i.e. set_voltage, set_current_limit, 664a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * set_mode. 665a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood */ 666a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwoodstatic int set_machine_constraints(struct regulator_dev *rdev, 667a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulation_constraints *constraints) 668a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood{ 669a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood int ret = 0; 670e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown const char *name; 671e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown struct regulator_ops *ops = rdev->desc->ops; 672e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown 673e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown if (constraints->name) 674e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown name = constraints->name; 675e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown else if (rdev->desc->name) 676e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown name = rdev->desc->name; 677e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown else 678e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown name = "regulator"; 679a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 680a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood rdev->constraints = constraints; 681a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 682a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood /* do we need to apply the constraint voltage */ 683a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood if (rdev->constraints->apply_uV && 684a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood rdev->constraints->min_uV == rdev->constraints->max_uV && 685e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown ops->set_voltage) { 686e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown ret = ops->set_voltage(rdev, 687a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood rdev->constraints->min_uV, rdev->constraints->max_uV); 688a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood if (ret < 0) { 689e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown printk(KERN_ERR "%s: failed to apply %duV constraint to %s\n", 690e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown __func__, 691e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown rdev->constraints->min_uV, name); 692a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood rdev->constraints = NULL; 693a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood goto out; 694a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood } 695a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood } 696a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 697a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood /* are we enabled at boot time by firmware / bootloader */ 698a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood if (rdev->constraints->boot_on) 699a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood rdev->use_count = 1; 700a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 701a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood /* do we need to setup our suspend state */ 702e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown if (constraints->initial_state) { 703a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood ret = suspend_prepare(rdev, constraints->initial_state); 704e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown if (ret < 0) { 705e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown printk(KERN_ERR "%s: failed to set suspend state for %s\n", 706e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown __func__, name); 707e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown rdev->constraints = NULL; 708e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown goto out; 709e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown } 710e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown } 711a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 712e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown /* if always_on is set then turn the regulator on if it's not 713e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown * already on. */ 714e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown if (constraints->always_on && ops->enable && 715e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown ((ops->is_enabled && !ops->is_enabled(rdev)) || 716e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown (!ops->is_enabled && !constraints->boot_on))) { 717e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown ret = ops->enable(rdev); 718e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown if (ret < 0) { 719e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown printk(KERN_ERR "%s: failed to enable %s\n", 720e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown __func__, name); 721e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown rdev->constraints = NULL; 722e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown goto out; 723e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown } 724e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown } 725e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown 726a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood print_constraints(rdev); 727a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwoodout: 728a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood return ret; 729a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood} 730a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 731a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood/** 732a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * set_supply - set regulator supply regulator 73369279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @rdev: regulator name 73469279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @supply_rdev: supply regulator name 735a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * 736a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * Called by platform initialisation code to set the supply regulator for this 737a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * regulator. This ensures that a regulators supply will also be enabled by the 738a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * core if it's child is enabled. 739a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood */ 740a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwoodstatic int set_supply(struct regulator_dev *rdev, 741a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulator_dev *supply_rdev) 742a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood{ 743a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood int err; 744a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 745a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood err = sysfs_create_link(&rdev->dev.kobj, &supply_rdev->dev.kobj, 746a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood "supply"); 747a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood if (err) { 748a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood printk(KERN_ERR 749a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood "%s: could not add device link %s err %d\n", 750a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood __func__, supply_rdev->dev.kobj.name, err); 751a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood goto out; 752a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood } 753a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood rdev->supply = supply_rdev; 754a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood list_add(&rdev->slist, &supply_rdev->supply_list); 755a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwoodout: 756a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood return err; 757a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood} 758a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 759a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood/** 760a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * set_consumer_device_supply: Bind a regulator to a symbolic supply 76169279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @rdev: regulator source 76269279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @consumer_dev: device the supply applies to 76369279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @supply: symbolic name for supply 764a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * 765a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * Allows platform initialisation code to map physical regulator 766a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * sources to symbolic names for supplies for use by devices. Devices 767a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * should use these symbolic names to request regulators, avoiding the 768a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * need to provide board-specific regulator names as platform data. 769a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood */ 770a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwoodstatic int set_consumer_device_supply(struct regulator_dev *rdev, 771a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct device *consumer_dev, const char *supply) 772a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood{ 773a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulator_map *node; 774a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 775a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood if (supply == NULL) 776a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood return -EINVAL; 777a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 778a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood node = kmalloc(sizeof(struct regulator_map), GFP_KERNEL); 779a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood if (node == NULL) 780a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood return -ENOMEM; 781a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 782a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood node->regulator = rdev; 783a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood node->dev = consumer_dev; 784a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood node->supply = supply; 785a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 786a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood list_add(&node->list, ®ulator_map_list); 787a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood return 0; 788a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood} 789a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 790a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwoodstatic void unset_consumer_device_supply(struct regulator_dev *rdev, 791a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct device *consumer_dev) 792a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood{ 793a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulator_map *node, *n; 794a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 795a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood list_for_each_entry_safe(node, n, ®ulator_map_list, list) { 796a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood if (rdev == node->regulator && 797a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood consumer_dev == node->dev) { 798a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood list_del(&node->list); 799a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood kfree(node); 800a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood return; 801a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood } 802a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood } 803a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood} 804a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 805414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood#define REG_STR_SIZE 32 806414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 807414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic struct regulator *create_regulator(struct regulator_dev *rdev, 808414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct device *dev, 809414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood const char *supply_name) 810414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 811414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator *regulator; 812414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood char buf[REG_STR_SIZE]; 813414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int err, size; 814414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 815414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator = kzalloc(sizeof(*regulator), GFP_KERNEL); 816414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (regulator == NULL) 817414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return NULL; 818414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 819414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(&rdev->mutex); 820414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator->rdev = rdev; 821414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood list_add(®ulator->list, &rdev->consumer_list); 822414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 823414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (dev) { 824414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* create a 'requested_microamps_name' sysfs entry */ 825414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood size = scnprintf(buf, REG_STR_SIZE, "microamps_requested_%s", 826414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood supply_name); 827414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (size >= REG_STR_SIZE) 828414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto overflow_err; 829414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 830414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator->dev = dev; 831414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator->dev_attr.attr.name = kstrdup(buf, GFP_KERNEL); 832414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (regulator->dev_attr.attr.name == NULL) 833414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto attr_name_err; 834414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 835414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator->dev_attr.attr.owner = THIS_MODULE; 836414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator->dev_attr.attr.mode = 0444; 837414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator->dev_attr.show = device_requested_uA_show; 838414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood err = device_create_file(dev, ®ulator->dev_attr); 839414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (err < 0) { 840414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_WARNING "%s: could not add regulator_dev" 841414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood " load sysfs\n", __func__); 842414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto attr_name_err; 843414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 844414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 845414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* also add a link to the device sysfs entry */ 846414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood size = scnprintf(buf, REG_STR_SIZE, "%s-%s", 847414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood dev->kobj.name, supply_name); 848414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (size >= REG_STR_SIZE) 849414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto attr_err; 850414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 851414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator->supply_name = kstrdup(buf, GFP_KERNEL); 852414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (regulator->supply_name == NULL) 853414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto attr_err; 854414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 855414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood err = sysfs_create_link(&rdev->dev.kobj, &dev->kobj, 856414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood buf); 857414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (err) { 858414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_WARNING 859414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood "%s: could not add device link %s err %d\n", 860414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood __func__, dev->kobj.name, err); 861414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood device_remove_file(dev, ®ulator->dev_attr); 862414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto link_name_err; 863414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 864414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 865414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(&rdev->mutex); 866414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return regulator; 867414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodlink_name_err: 868414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood kfree(regulator->supply_name); 869414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodattr_err: 870414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood device_remove_file(regulator->dev, ®ulator->dev_attr); 871414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodattr_name_err: 872414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood kfree(regulator->dev_attr.attr.name); 873414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodoverflow_err: 874414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood list_del(®ulator->list); 875414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood kfree(regulator); 876414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(&rdev->mutex); 877414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return NULL; 878414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 879414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 880414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 881414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_get - lookup and obtain a reference to a regulator. 882414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @dev: device for regulator "consumer" 883414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @id: Supply name or regulator ID. 884414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 885414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Returns a struct regulator corresponding to the regulator producer, 886414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * or IS_ERR() condition containing errno. Use of supply names 887414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * configured via regulator_set_device_supply() is strongly 888414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * encouraged. 889414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 890414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstruct regulator *regulator_get(struct device *dev, const char *id) 891414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 892414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_dev *rdev; 893414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_map *map; 894414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator *regulator = ERR_PTR(-ENODEV); 895414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 896414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (id == NULL) { 897414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "regulator: get() with no identifier\n"); 898414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return regulator; 899414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 900414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 901414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(®ulator_list_mutex); 902414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 903414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood list_for_each_entry(map, ®ulator_map_list, list) { 904414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (dev == map->dev && 905414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood strcmp(map->supply, id) == 0) { 906a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood rdev = map->regulator; 907414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto found; 908a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood } 909414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 910414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "regulator: Unable to get requested regulator: %s\n", 911414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood id); 912414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(®ulator_list_mutex); 913414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return regulator; 914414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 915414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodfound: 916a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood if (!try_module_get(rdev->owner)) 917a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood goto out; 918a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 919414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator = create_regulator(rdev, dev, id); 920414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (regulator == NULL) { 921414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator = ERR_PTR(-ENOMEM); 922414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood module_put(rdev->owner); 923414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 924414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 925a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwoodout: 926414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(®ulator_list_mutex); 927414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return regulator; 928414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 929414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_get); 930414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 931414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 932414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_put - "free" the regulator source 933414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator source 934414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 935414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Note: drivers must ensure that all regulator_enable calls made on this 936414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator source are balanced by regulator_disable calls prior to calling 937414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * this function. 938414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 939414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodvoid regulator_put(struct regulator *regulator) 940414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 941414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_dev *rdev; 942414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 943414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (regulator == NULL || IS_ERR(regulator)) 944414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return; 945414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 946414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(®ulator_list_mutex); 947414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood rdev = regulator->rdev; 948414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 949412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell if (WARN(regulator->enabled, "Releasing supply %s while enabled\n", 950412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell regulator->supply_name)) 951412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell _regulator_disable(rdev); 952412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell 953414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* remove any sysfs entries */ 954414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (regulator->dev) { 955414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood sysfs_remove_link(&rdev->dev.kobj, regulator->supply_name); 956414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood kfree(regulator->supply_name); 957414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood device_remove_file(regulator->dev, ®ulator->dev_attr); 958414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood kfree(regulator->dev_attr.attr.name); 959414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 960414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood list_del(®ulator->list); 961414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood kfree(regulator); 962414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 963414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood module_put(rdev->owner); 964414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(®ulator_list_mutex); 965414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 966414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_put); 967414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 968414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/* locks held by regulator_enable() */ 969414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic int _regulator_enable(struct regulator_dev *rdev) 970414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 971414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret = -EINVAL; 972414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 973414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!rdev->constraints) { 974414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: %s has no constraints\n", 975414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood __func__, rdev->desc->name); 976414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 977414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 978414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 979414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* do we need to enable the supply regulator first */ 980414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev->supply) { 981414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = _regulator_enable(rdev->supply); 982414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (ret < 0) { 983414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: failed to enable %s: %d\n", 984414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood __func__, rdev->desc->name, ret); 985414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 986414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 987414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 988414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 989414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* check voltage and requested load before enabling */ 990414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev->desc->ops->enable) { 991414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 992414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev->constraints && 993414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood (rdev->constraints->valid_ops_mask & 994414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood REGULATOR_CHANGE_DRMS)) 995414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood drms_uA_update(rdev); 996414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 997414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = rdev->desc->ops->enable(rdev); 998414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (ret < 0) { 999414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: failed to enable %s: %d\n", 1000414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood __func__, rdev->desc->name, ret); 1001414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1002414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1003414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood rdev->use_count++; 1004414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1005414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1006414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1007414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1008414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1009414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1010414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1011414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_enable - enable regulator output 1012414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator source 1013414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1014414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Enable the regulator output at the predefined voltage or current value. 1015414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * NOTE: the output value can be set by other drivers, boot loader or may be 101669279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * hardwired in the regulator. Calls to regulator_enable() must be balanced 101769279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * with calls to regulator_disable(). 1018414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1019414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_enable(struct regulator *regulator) 1020414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1021412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell struct regulator_dev *rdev = regulator->rdev; 1022412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell int ret = 0; 1023414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1024412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell mutex_lock(&rdev->mutex); 1025412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell if (regulator->enabled == 0) 1026412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell ret = _regulator_enable(rdev); 1027412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell else if (regulator->enabled < 0) 1028412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell ret = -EIO; 1029412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell if (ret == 0) 1030412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell regulator->enabled++; 1031412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell mutex_unlock(&rdev->mutex); 1032414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1033414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1034414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_enable); 1035414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1036414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/* locks held by regulator_disable() */ 1037414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic int _regulator_disable(struct regulator_dev *rdev) 1038414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1039414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret = 0; 1040414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1041414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* are we the last user and permitted to disable ? */ 1042414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev->use_count == 1 && !rdev->constraints->always_on) { 1043414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1044414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* we are last user */ 1045414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev->desc->ops->disable) { 1046414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = rdev->desc->ops->disable(rdev); 1047414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (ret < 0) { 1048414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: failed to disable %s\n", 1049414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood __func__, rdev->desc->name); 1050414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1051414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1052414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1053414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1054414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* decrease our supplies ref count and disable if required */ 1055414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev->supply) 1056414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood _regulator_disable(rdev->supply); 1057414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1058414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood rdev->use_count = 0; 1059414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } else if (rdev->use_count > 1) { 1060414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1061414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev->constraints && 1062414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood (rdev->constraints->valid_ops_mask & 1063414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood REGULATOR_CHANGE_DRMS)) 1064414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood drms_uA_update(rdev); 1065414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1066414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood rdev->use_count--; 1067414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1068414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1069414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1070414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1071414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1072414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_disable - disable regulator output 1073414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator source 1074414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1075414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Disable the regulator output voltage or current. 107669279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * 1077414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * NOTE: this will only disable the regulator output if no other consumer 107869279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * devices have it enabled. Calls to regulator_enable() must be balanced with 107969279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * calls to regulator_disable(). 1080414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1081414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_disable(struct regulator *regulator) 1082414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1083412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell struct regulator_dev *rdev = regulator->rdev; 1084412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell int ret = 0; 1085414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1086412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell mutex_lock(&rdev->mutex); 1087412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell if (regulator->enabled == 1) { 1088412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell ret = _regulator_disable(rdev); 1089412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell if (ret == 0) 1090412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell regulator->uA_load = 0; 1091412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell } else if (WARN(regulator->enabled <= 0, 1092412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell "unbalanced disables for supply %s\n", 1093412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell regulator->supply_name)) 1094412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell ret = -EIO; 1095412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell if (ret == 0) 1096412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell regulator->enabled--; 1097412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell mutex_unlock(&rdev->mutex); 1098414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1099414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1100414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_disable); 1101414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1102414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/* locks held by regulator_force_disable() */ 1103414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic int _regulator_force_disable(struct regulator_dev *rdev) 1104414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1105414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret = 0; 1106414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1107414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* force disable */ 1108414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev->desc->ops->disable) { 1109414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* ah well, who wants to live forever... */ 1110414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = rdev->desc->ops->disable(rdev); 1111414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (ret < 0) { 1112414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: failed to force disable %s\n", 1113414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood __func__, rdev->desc->name); 1114414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1115414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1116414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* notify other consumers that power has been forced off */ 1117414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE, 1118414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood NULL); 1119414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1120414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1121414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* decrease our supplies ref count and disable if required */ 1122414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev->supply) 1123414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood _regulator_disable(rdev->supply); 1124414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1125414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood rdev->use_count = 0; 1126414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1127414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1128414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1129414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1130414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_force_disable - force disable regulator output 1131414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator source 1132414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1133414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Forcibly disable the regulator output voltage or current. 1134414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * NOTE: this *will* disable the regulator output even if other consumer 1135414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * devices have it enabled. This should be used for situations when device 1136414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * damage will likely occur if the regulator is not disabled (e.g. over temp). 1137414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1138414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_force_disable(struct regulator *regulator) 1139414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1140414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret; 1141414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1142414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(®ulator->rdev->mutex); 1143414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator->enabled = 0; 1144414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator->uA_load = 0; 1145414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = _regulator_force_disable(regulator->rdev); 1146414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(®ulator->rdev->mutex); 1147414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1148414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1149414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_force_disable); 1150414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1151414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic int _regulator_is_enabled(struct regulator_dev *rdev) 1152414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1153414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret; 1154414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1155414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(&rdev->mutex); 1156414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1157414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* sanity check */ 1158414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!rdev->desc->ops->is_enabled) { 1159414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = -EINVAL; 1160414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1161414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1162414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1163414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = rdev->desc->ops->is_enabled(rdev); 1164414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodout: 1165414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(&rdev->mutex); 1166414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1167414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1168414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1169414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1170414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_is_enabled - is the regulator output enabled 1171414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator source 1172414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1173412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell * Returns positive if the regulator driver backing the source/client 1174412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell * has requested that the device be enabled, zero if it hasn't, else a 1175412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell * negative errno code. 1176412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell * 1177412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell * Note that the device backing this regulator handle can have multiple 1178412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell * users, so it might be enabled even if regulator_enable() was never 1179412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell * called for this particular source. 1180414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1181414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_is_enabled(struct regulator *regulator) 1182414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1183414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return _regulator_is_enabled(regulator->rdev); 1184414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1185414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_is_enabled); 1186414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1187414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1188414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_set_voltage - set regulator output voltage 1189414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator source 1190414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @min_uV: Minimum required voltage in uV 1191414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @max_uV: Maximum acceptable voltage in uV 1192414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1193414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Sets a voltage regulator to the desired output voltage. This can be set 1194414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * during any regulator state. IOW, regulator can be disabled or enabled. 1195414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1196414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * If the regulator is enabled then the voltage will change to the new value 1197414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * immediately otherwise if the regulator is disabled the regulator will 1198414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * output at the new voltage when enabled. 1199414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1200414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * NOTE: If the regulator is shared between several devices then the lowest 1201414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * request voltage that meets the system constraints will be used. 120269279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * Regulator system constraints must be set for this regulator before 1203414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * calling this function otherwise this call will fail. 1204414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1205414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV) 1206414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1207414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_dev *rdev = regulator->rdev; 1208414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret; 1209414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1210414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(&rdev->mutex); 1211414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1212414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* sanity check */ 1213414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!rdev->desc->ops->set_voltage) { 1214414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = -EINVAL; 1215414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1216414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1217414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1218414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* constraints check */ 1219414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = regulator_check_voltage(rdev, &min_uV, &max_uV); 1220414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (ret < 0) 1221414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1222414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator->min_uV = min_uV; 1223414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator->max_uV = max_uV; 1224414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV); 1225414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1226414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodout: 1227414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(&rdev->mutex); 1228414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1229414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1230414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_set_voltage); 1231414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1232414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic int _regulator_get_voltage(struct regulator_dev *rdev) 1233414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1234414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* sanity check */ 1235414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev->desc->ops->get_voltage) 1236414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return rdev->desc->ops->get_voltage(rdev); 1237414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood else 1238414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return -EINVAL; 1239414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1240414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1241414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1242414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_get_voltage - get regulator output voltage 1243414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator source 1244414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1245414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * This returns the current regulator voltage in uV. 1246414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1247414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * NOTE: If the regulator is disabled it will return the voltage value. This 1248414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * function should not be used to determine regulator state. 1249414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1250414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_get_voltage(struct regulator *regulator) 1251414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1252414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret; 1253414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1254414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(®ulator->rdev->mutex); 1255414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1256414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = _regulator_get_voltage(regulator->rdev); 1257414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1258414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(®ulator->rdev->mutex); 1259414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1260414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1261414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1262414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_get_voltage); 1263414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1264414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1265414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_set_current_limit - set regulator output current limit 1266414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator source 1267414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @min_uA: Minimuum supported current in uA 1268414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @max_uA: Maximum supported current in uA 1269414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1270414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Sets current sink to the desired output current. This can be set during 1271414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * any regulator state. IOW, regulator can be disabled or enabled. 1272414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1273414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * If the regulator is enabled then the current will change to the new value 1274414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * immediately otherwise if the regulator is disabled the regulator will 1275414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * output at the new current when enabled. 1276414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1277414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * NOTE: Regulator system constraints must be set for this regulator before 1278414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * calling this function otherwise this call will fail. 1279414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1280414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_set_current_limit(struct regulator *regulator, 1281414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int min_uA, int max_uA) 1282414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1283414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_dev *rdev = regulator->rdev; 1284414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret; 1285414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1286414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(&rdev->mutex); 1287414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1288414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* sanity check */ 1289414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!rdev->desc->ops->set_current_limit) { 1290414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = -EINVAL; 1291414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1292414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1293414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1294414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* constraints check */ 1295414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = regulator_check_current_limit(rdev, &min_uA, &max_uA); 1296414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (ret < 0) 1297414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1298414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1299414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = rdev->desc->ops->set_current_limit(rdev, min_uA, max_uA); 1300414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodout: 1301414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(&rdev->mutex); 1302414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1303414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1304414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_set_current_limit); 1305414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1306414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic int _regulator_get_current_limit(struct regulator_dev *rdev) 1307414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1308414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret; 1309414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1310414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(&rdev->mutex); 1311414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1312414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* sanity check */ 1313414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!rdev->desc->ops->get_current_limit) { 1314414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = -EINVAL; 1315414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1316414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1317414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1318414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = rdev->desc->ops->get_current_limit(rdev); 1319414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodout: 1320414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(&rdev->mutex); 1321414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1322414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1323414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1324414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1325414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_get_current_limit - get regulator output current 1326414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator source 1327414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1328414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * This returns the current supplied by the specified current sink in uA. 1329414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1330414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * NOTE: If the regulator is disabled it will return the current value. This 1331414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * function should not be used to determine regulator state. 1332414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1333414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_get_current_limit(struct regulator *regulator) 1334414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1335414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return _regulator_get_current_limit(regulator->rdev); 1336414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1337414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_get_current_limit); 1338414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1339414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1340414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_set_mode - set regulator operating mode 1341414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator source 1342414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @mode: operating mode - one of the REGULATOR_MODE constants 1343414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1344414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Set regulator operating mode to increase regulator efficiency or improve 1345414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulation performance. 1346414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1347414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * NOTE: Regulator system constraints must be set for this regulator before 1348414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * calling this function otherwise this call will fail. 1349414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1350414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_set_mode(struct regulator *regulator, unsigned int mode) 1351414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1352414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_dev *rdev = regulator->rdev; 1353414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret; 1354414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1355414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(&rdev->mutex); 1356414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1357414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* sanity check */ 1358414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!rdev->desc->ops->set_mode) { 1359414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = -EINVAL; 1360414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1361414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1362414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1363414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* constraints check */ 1364414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = regulator_check_mode(rdev, mode); 1365414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (ret < 0) 1366414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1367414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1368414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = rdev->desc->ops->set_mode(rdev, mode); 1369414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodout: 1370414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(&rdev->mutex); 1371414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1372414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1373414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_set_mode); 1374414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1375414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic unsigned int _regulator_get_mode(struct regulator_dev *rdev) 1376414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1377414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret; 1378414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1379414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(&rdev->mutex); 1380414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1381414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* sanity check */ 1382414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!rdev->desc->ops->get_mode) { 1383414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = -EINVAL; 1384414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1385414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1386414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1387414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = rdev->desc->ops->get_mode(rdev); 1388414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodout: 1389414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(&rdev->mutex); 1390414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1391414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1392414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1393414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1394414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_get_mode - get regulator operating mode 1395414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator source 1396414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1397414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Get the current regulator operating mode. 1398414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1399414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodunsigned int regulator_get_mode(struct regulator *regulator) 1400414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1401414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return _regulator_get_mode(regulator->rdev); 1402414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1403414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_get_mode); 1404414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1405414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1406414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_set_optimum_mode - set regulator optimum operating mode 1407414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator source 1408414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @uA_load: load current 1409414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1410414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Notifies the regulator core of a new device load. This is then used by 1411414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * DRMS (if enabled by constraints) to set the most efficient regulator 1412414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * operating mode for the new regulator loading. 1413414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1414414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Consumer devices notify their supply regulator of the maximum power 1415414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * they will require (can be taken from device datasheet in the power 1416414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * consumption tables) when they change operational status and hence power 1417414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * state. Examples of operational state changes that can affect power 1418414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * consumption are :- 1419414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1420414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * o Device is opened / closed. 1421414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * o Device I/O is about to begin or has just finished. 1422414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * o Device is idling in between work. 1423414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1424414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * This information is also exported via sysfs to userspace. 1425414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1426414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * DRMS will sum the total requested load on the regulator and change 1427414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * to the most efficient operating mode if platform constraints allow. 1428414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1429414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Returns the new regulator mode or error. 1430414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1431414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_set_optimum_mode(struct regulator *regulator, int uA_load) 1432414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1433414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_dev *rdev = regulator->rdev; 1434414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator *consumer; 1435414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret, output_uV, input_uV, total_uA_load = 0; 1436414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood unsigned int mode; 1437414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1438414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(&rdev->mutex); 1439414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1440414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator->uA_load = uA_load; 1441414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = regulator_check_drms(rdev); 1442414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (ret < 0) 1443414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1444414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = -EINVAL; 1445414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1446414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* sanity check */ 1447414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!rdev->desc->ops->get_optimum_mode) 1448414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1449414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1450414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* get output voltage */ 1451414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood output_uV = rdev->desc->ops->get_voltage(rdev); 1452414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (output_uV <= 0) { 1453414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: invalid output voltage found for %s\n", 1454414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood __func__, rdev->desc->name); 1455414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1456414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1457414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1458414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* get input voltage */ 1459414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev->supply && rdev->supply->desc->ops->get_voltage) 1460414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood input_uV = rdev->supply->desc->ops->get_voltage(rdev->supply); 1461414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood else 1462414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood input_uV = rdev->constraints->input_uV; 1463414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (input_uV <= 0) { 1464414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: invalid input voltage found for %s\n", 1465414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood __func__, rdev->desc->name); 1466414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1467414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1468414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1469414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* calc total requested load for this regulator */ 1470414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood list_for_each_entry(consumer, &rdev->consumer_list, list) 1471414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood total_uA_load += consumer->uA_load; 1472414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1473414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mode = rdev->desc->ops->get_optimum_mode(rdev, 1474414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood input_uV, output_uV, 1475414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood total_uA_load); 1476e573520b171095c106ffbbbf4f9cbed6d9bff576David Brownell ret = regulator_check_mode(rdev, mode); 1477e573520b171095c106ffbbbf4f9cbed6d9bff576David Brownell if (ret < 0) { 1478414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: failed to get optimum mode for %s @" 1479414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood " %d uA %d -> %d uV\n", __func__, rdev->desc->name, 1480414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood total_uA_load, input_uV, output_uV); 1481414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1482414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1483414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1484414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = rdev->desc->ops->set_mode(rdev, mode); 1485e573520b171095c106ffbbbf4f9cbed6d9bff576David Brownell if (ret < 0) { 1486414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: failed to set optimum mode %x for %s\n", 1487414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood __func__, mode, rdev->desc->name); 1488414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1489414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1490414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = mode; 1491414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodout: 1492414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(&rdev->mutex); 1493414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1494414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1495414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_set_optimum_mode); 1496414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1497414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1498414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_register_notifier - register regulator event notifier 1499414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator source 150069279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @nb: notifier block 1501414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1502414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Register notifier block to receive regulator events. 1503414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1504414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_register_notifier(struct regulator *regulator, 1505414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct notifier_block *nb) 1506414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1507414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return blocking_notifier_chain_register(®ulator->rdev->notifier, 1508414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood nb); 1509414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1510414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_register_notifier); 1511414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1512414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1513414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_unregister_notifier - unregister regulator event notifier 1514414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator source 151569279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @nb: notifier block 1516414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1517414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Unregister regulator event notifier block. 1518414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1519414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_unregister_notifier(struct regulator *regulator, 1520414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct notifier_block *nb) 1521414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1522414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return blocking_notifier_chain_unregister(®ulator->rdev->notifier, 1523414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood nb); 1524414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1525414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_unregister_notifier); 1526414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1527414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/* notify regulator consumers and downstream regulator consumers */ 1528414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic void _notifier_call_chain(struct regulator_dev *rdev, 1529414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood unsigned long event, void *data) 1530414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1531414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_dev *_rdev; 1532414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1533414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* call rdev chain first */ 1534414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(&rdev->mutex); 1535414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood blocking_notifier_call_chain(&rdev->notifier, event, NULL); 1536414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(&rdev->mutex); 1537414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1538414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* now notify regulator we supply */ 1539414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood list_for_each_entry(_rdev, &rdev->supply_list, slist) 1540414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood _notifier_call_chain(_rdev, event, data); 1541414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1542414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1543414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1544414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_bulk_get - get multiple regulator consumers 1545414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1546414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @dev: Device to supply 1547414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @num_consumers: Number of consumers to register 1548414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @consumers: Configuration of consumers; clients are stored here. 1549414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1550414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @return 0 on success, an errno on failure. 1551414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1552414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * This helper function allows drivers to get several regulator 1553414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * consumers in one operation. If any of the regulators cannot be 1554414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * acquired then any regulators that were allocated will be freed 1555414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * before returning to the caller. 1556414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1557414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_bulk_get(struct device *dev, int num_consumers, 1558414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_bulk_data *consumers) 1559414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1560414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int i; 1561414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret; 1562414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1563414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood for (i = 0; i < num_consumers; i++) 1564414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood consumers[i].consumer = NULL; 1565414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1566414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood for (i = 0; i < num_consumers; i++) { 1567414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood consumers[i].consumer = regulator_get(dev, 1568414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood consumers[i].supply); 1569414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (IS_ERR(consumers[i].consumer)) { 1570414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood dev_err(dev, "Failed to get supply '%s'\n", 1571414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood consumers[i].supply); 1572414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = PTR_ERR(consumers[i].consumer); 1573414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood consumers[i].consumer = NULL; 1574414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto err; 1575414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1576414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1577414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1578414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return 0; 1579414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1580414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwooderr: 1581414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood for (i = 0; i < num_consumers && consumers[i].consumer; i++) 1582414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator_put(consumers[i].consumer); 1583414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1584414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1585414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1586414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_bulk_get); 1587414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1588414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1589414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_bulk_enable - enable multiple regulator consumers 1590414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1591414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @num_consumers: Number of consumers 1592414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @consumers: Consumer data; clients are stored here. 1593414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @return 0 on success, an errno on failure 1594414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1595414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * This convenience API allows consumers to enable multiple regulator 1596414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * clients in a single API call. If any consumers cannot be enabled 1597414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * then any others that were enabled will be disabled again prior to 1598414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * return. 1599414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1600414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_bulk_enable(int num_consumers, 1601414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_bulk_data *consumers) 1602414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1603414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int i; 1604414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret; 1605414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1606414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood for (i = 0; i < num_consumers; i++) { 1607414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = regulator_enable(consumers[i].consumer); 1608414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (ret != 0) 1609414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto err; 1610414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1611414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1612414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return 0; 1613414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1614414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwooderr: 1615414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "Failed to enable %s\n", consumers[i].supply); 1616414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood for (i = 0; i < num_consumers; i++) 1617414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator_disable(consumers[i].consumer); 1618414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1619414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1620414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1621414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_bulk_enable); 1622414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1623414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1624414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_bulk_disable - disable multiple regulator consumers 1625414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1626414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @num_consumers: Number of consumers 1627414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @consumers: Consumer data; clients are stored here. 1628414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @return 0 on success, an errno on failure 1629414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1630414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * This convenience API allows consumers to disable multiple regulator 1631414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * clients in a single API call. If any consumers cannot be enabled 1632414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * then any others that were disabled will be disabled again prior to 1633414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * return. 1634414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1635414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_bulk_disable(int num_consumers, 1636414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_bulk_data *consumers) 1637414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1638414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int i; 1639414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret; 1640414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1641414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood for (i = 0; i < num_consumers; i++) { 1642414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = regulator_disable(consumers[i].consumer); 1643414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (ret != 0) 1644414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto err; 1645414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1646414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1647414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return 0; 1648414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1649414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwooderr: 1650414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "Failed to disable %s\n", consumers[i].supply); 1651414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood for (i = 0; i < num_consumers; i++) 1652414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator_enable(consumers[i].consumer); 1653414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1654414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1655414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1656414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_bulk_disable); 1657414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1658414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1659414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_bulk_free - free multiple regulator consumers 1660414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1661414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @num_consumers: Number of consumers 1662414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @consumers: Consumer data; clients are stored here. 1663414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1664414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * This convenience API allows consumers to free multiple regulator 1665414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * clients in a single API call. 1666414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1667414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodvoid regulator_bulk_free(int num_consumers, 1668414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_bulk_data *consumers) 1669414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1670414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int i; 1671414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1672414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood for (i = 0; i < num_consumers; i++) { 1673414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator_put(consumers[i].consumer); 1674414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood consumers[i].consumer = NULL; 1675414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1676414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1677414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_bulk_free); 1678414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1679414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1680414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_notifier_call_chain - call regulator event notifier 168169279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @rdev: regulator source 1682414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @event: notifier block 168369279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @data: callback-specific data. 1684414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1685414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Called by regulator drivers to notify clients a regulator event has 1686414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * occurred. We also notify regulator clients downstream. 1687414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1688414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_notifier_call_chain(struct regulator_dev *rdev, 1689414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood unsigned long event, void *data) 1690414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1691414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood _notifier_call_chain(rdev, event, data); 1692414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return NOTIFY_DONE; 1693414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1694414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1695414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_notifier_call_chain); 1696414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 16977ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell/* 16987ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell * To avoid cluttering sysfs (and memory) with useless state, only 16997ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell * create attributes that can be meaningfully displayed. 17007ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell */ 17017ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownellstatic int add_regulator_attributes(struct regulator_dev *rdev) 17027ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell{ 17037ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell struct device *dev = &rdev->dev; 17047ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell struct regulator_ops *ops = rdev->desc->ops; 17057ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell int status = 0; 17067ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell 17077ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell /* some attributes need specific methods to be displayed */ 17087ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (ops->get_voltage) { 17097ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, &dev_attr_microvolts); 17107ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17117ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17127ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell } 17137ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (ops->get_current_limit) { 17147ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, &dev_attr_microamps); 17157ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17167ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17177ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell } 17187ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (ops->get_mode) { 17197ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, &dev_attr_opmode); 17207ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17217ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17227ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell } 17237ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (ops->is_enabled) { 17247ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, &dev_attr_state); 17257ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17267ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17277ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell } 17287ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell 17297ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell /* some attributes are type-specific */ 17307ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (rdev->desc->type == REGULATOR_CURRENT) { 17317ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, &dev_attr_requested_microamps); 17327ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17337ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17347ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell } 17357ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell 17367ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell /* all the other attributes exist to support constraints; 17377ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell * don't show them if there are no constraints, or if the 17387ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell * relevant supporting methods are missing. 17397ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell */ 17407ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (!rdev->constraints) 17417ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17427ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell 17437ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell /* constraints need specific supporting methods */ 17447ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (ops->set_voltage) { 17457ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, &dev_attr_min_microvolts); 17467ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17477ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17487ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, &dev_attr_max_microvolts); 17497ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17507ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17517ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell } 17527ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (ops->set_current_limit) { 17537ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, &dev_attr_min_microamps); 17547ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17557ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17567ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, &dev_attr_max_microamps); 17577ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17587ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17597ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell } 17607ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell 17617ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell /* suspend mode constraints need multiple supporting methods */ 17627ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (!(ops->set_suspend_enable && ops->set_suspend_disable)) 17637ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17647ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell 17657ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, &dev_attr_suspend_standby_state); 17667ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17677ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17687ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, &dev_attr_suspend_mem_state); 17697ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17707ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17717ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, &dev_attr_suspend_disk_state); 17727ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17737ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17747ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell 17757ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (ops->set_suspend_voltage) { 17767ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, 17777ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell &dev_attr_suspend_standby_microvolts); 17787ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17797ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17807ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, 17817ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell &dev_attr_suspend_mem_microvolts); 17827ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17837ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17847ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, 17857ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell &dev_attr_suspend_disk_microvolts); 17867ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17877ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17887ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell } 17897ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell 17907ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (ops->set_suspend_mode) { 17917ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, 17927ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell &dev_attr_suspend_standby_mode); 17937ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17947ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17957ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, 17967ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell &dev_attr_suspend_mem_mode); 17977ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17987ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17997ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, 18007ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell &dev_attr_suspend_disk_mode); 18017ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 18027ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 18037ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell } 18047ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell 18057ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 18067ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell} 18077ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell 1808414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1809414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_register - register regulator 181069279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @regulator_desc: regulator to register 181169279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @dev: struct device for the regulator 181269279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @driver_data: private regulator data 1813414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1814414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Called by regulator drivers to register a regulator. 1815414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Returns 0 on success. 1816414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1817414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstruct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, 1818a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct device *dev, void *driver_data) 1819414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1820414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood static atomic_t regulator_no = ATOMIC_INIT(0); 1821414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_dev *rdev; 1822a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulator_init_data *init_data = dev->platform_data; 1823a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood int ret, i; 1824414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1825414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (regulator_desc == NULL) 1826414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ERR_PTR(-EINVAL); 1827414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1828414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (regulator_desc->name == NULL || regulator_desc->ops == NULL) 1829414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ERR_PTR(-EINVAL); 1830414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1831414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!regulator_desc->type == REGULATOR_VOLTAGE && 1832414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood !regulator_desc->type == REGULATOR_CURRENT) 1833414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ERR_PTR(-EINVAL); 1834414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 183546fabe1edd44a8893d88d7982f88d01ccf77f0bbMark Brown if (!init_data) 183646fabe1edd44a8893d88d7982f88d01ccf77f0bbMark Brown return ERR_PTR(-EINVAL); 183746fabe1edd44a8893d88d7982f88d01ccf77f0bbMark Brown 1838414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL); 1839414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev == NULL) 1840414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ERR_PTR(-ENOMEM); 1841414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1842414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(®ulator_list_mutex); 1843414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1844414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_init(&rdev->mutex); 1845a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood rdev->reg_data = driver_data; 1846414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood rdev->owner = regulator_desc->owner; 1847414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood rdev->desc = regulator_desc; 1848414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood INIT_LIST_HEAD(&rdev->consumer_list); 1849414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood INIT_LIST_HEAD(&rdev->supply_list); 1850414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood INIT_LIST_HEAD(&rdev->list); 1851414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood INIT_LIST_HEAD(&rdev->slist); 1852414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier); 1853414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1854a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood /* preform any regulator specific init */ 1855a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood if (init_data->regulator_init) { 1856a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood ret = init_data->regulator_init(rdev->reg_data); 18574fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell if (ret < 0) 18584fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell goto clean; 1859a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood } 1860a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 1861a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood /* register with sysfs */ 1862414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood rdev->dev.class = ®ulator_class; 1863a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood rdev->dev.parent = dev; 1864812460a927c1d0dc1fbdbec9aa07de1b04043d83Kay Sievers dev_set_name(&rdev->dev, "regulator.%d", 1865812460a927c1d0dc1fbdbec9aa07de1b04043d83Kay Sievers atomic_inc_return(®ulator_no) - 1); 1866a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood ret = device_register(&rdev->dev); 18674fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell if (ret != 0) 18684fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell goto clean; 1869a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 1870a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood dev_set_drvdata(&rdev->dev, rdev); 1871a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 187274f544c1fc0339acf6f66ff438b8543b1f9faf10Mike Rapoport /* set regulator constraints */ 187374f544c1fc0339acf6f66ff438b8543b1f9faf10Mike Rapoport ret = set_machine_constraints(rdev, &init_data->constraints); 187474f544c1fc0339acf6f66ff438b8543b1f9faf10Mike Rapoport if (ret < 0) 187574f544c1fc0339acf6f66ff438b8543b1f9faf10Mike Rapoport goto scrub; 187674f544c1fc0339acf6f66ff438b8543b1f9faf10Mike Rapoport 18777ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell /* add attributes supported by this regulator */ 18787ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell ret = add_regulator_attributes(rdev); 18797ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (ret < 0) 18807ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell goto scrub; 18817ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell 1882a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood /* set supply regulator if it exists */ 1883a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood if (init_data->supply_regulator_dev) { 1884a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood ret = set_supply(rdev, 1885a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood dev_get_drvdata(init_data->supply_regulator_dev)); 18864fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell if (ret < 0) 18874fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell goto scrub; 1888a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood } 1889a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 1890a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood /* add consumers devices */ 1891a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood for (i = 0; i < init_data->num_consumer_supplies; i++) { 1892a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood ret = set_consumer_device_supply(rdev, 1893a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood init_data->consumer_supplies[i].dev, 1894a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood init_data->consumer_supplies[i].supply); 1895a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood if (ret < 0) { 1896a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood for (--i; i >= 0; i--) 1897a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood unset_consumer_device_supply(rdev, 1898a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood init_data->consumer_supplies[i].dev); 18994fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell goto scrub; 1900a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood } 1901414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1902a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 1903a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood list_add(&rdev->list, ®ulator_list); 1904a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwoodout: 1905414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(®ulator_list_mutex); 1906414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return rdev; 19074fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell 19084fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownellscrub: 19094fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell device_unregister(&rdev->dev); 19104fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownellclean: 19114fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell kfree(rdev); 19124fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell rdev = ERR_PTR(ret); 19134fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell goto out; 1914414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1915414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_register); 1916414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1917414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1918414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_unregister - unregister regulator 191969279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @rdev: regulator to unregister 1920414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1921414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Called by regulator drivers to unregister a regulator. 1922414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1923414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodvoid regulator_unregister(struct regulator_dev *rdev) 1924414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1925414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev == NULL) 1926414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return; 1927414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1928414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(®ulator_list_mutex); 1929414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood list_del(&rdev->list); 1930414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev->supply) 1931414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood sysfs_remove_link(&rdev->dev.kobj, "supply"); 1932414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood device_unregister(&rdev->dev); 1933414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(®ulator_list_mutex); 1934414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1935414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_unregister); 1936414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1937414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1938414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_suspend_prepare: prepare regulators for system wide suspend 1939414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @state: system suspend state 1940414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1941414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Configure each regulator with it's suspend operating parameters for state. 1942414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * This will usually be called by machine suspend code prior to supending. 1943414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1944414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_suspend_prepare(suspend_state_t state) 1945414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1946414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_dev *rdev; 1947414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret = 0; 1948414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1949414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* ON is handled by regulator active state */ 1950414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (state == PM_SUSPEND_ON) 1951414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return -EINVAL; 1952414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1953414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(®ulator_list_mutex); 1954414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood list_for_each_entry(rdev, ®ulator_list, list) { 1955414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1956414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(&rdev->mutex); 1957414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = suspend_prepare(rdev, state); 1958414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(&rdev->mutex); 1959414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1960414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (ret < 0) { 1961414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: failed to prepare %s\n", 1962414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood __func__, rdev->desc->name); 1963414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1964414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1965414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1966414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodout: 1967414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(®ulator_list_mutex); 1968414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1969414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1970414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_suspend_prepare); 1971414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1972414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1973414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * rdev_get_drvdata - get rdev regulator driver data 197469279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @rdev: regulator 1975414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1976414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Get rdev regulator driver private data. This call can be used in the 1977414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator driver context. 1978414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1979414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodvoid *rdev_get_drvdata(struct regulator_dev *rdev) 1980414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1981414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return rdev->reg_data; 1982414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1983414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(rdev_get_drvdata); 1984414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1985414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1986414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_get_drvdata - get regulator driver data 1987414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator 1988414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1989414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Get regulator driver private data. This call can be used in the consumer 1990414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * driver context when non API regulator specific functions need to be called. 1991414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1992414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodvoid *regulator_get_drvdata(struct regulator *regulator) 1993414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1994414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return regulator->rdev->reg_data; 1995414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1996414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_get_drvdata); 1997414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1998414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1999414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_set_drvdata - set regulator driver data 2000414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator 2001414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @data: data 2002414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 2003414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodvoid regulator_set_drvdata(struct regulator *regulator, void *data) 2004414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 2005414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator->rdev->reg_data = data; 2006414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 2007414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_set_drvdata); 2008414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 2009414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 2010414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_get_id - get regulator ID 201169279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @rdev: regulator 2012414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 2013414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint rdev_get_id(struct regulator_dev *rdev) 2014414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 2015414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return rdev->desc->id; 2016414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 2017414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(rdev_get_id); 2018414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 2019a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwoodstruct device *rdev_get_dev(struct regulator_dev *rdev) 2020a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood{ 2021a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood return &rdev->dev; 2022a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood} 2023a5766f11cfd3a0c03450d99c8fe548c2940be884Liam GirdwoodEXPORT_SYMBOL_GPL(rdev_get_dev); 2024a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 2025a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwoodvoid *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data) 2026a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood{ 2027a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood return reg_init_data->driver_data; 2028a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood} 2029a5766f11cfd3a0c03450d99c8fe548c2940be884Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_get_init_drvdata); 2030a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 2031414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic int __init regulator_init(void) 2032414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 2033414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_INFO "regulator: core version %s\n", REGULATOR_VERSION); 2034414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return class_register(®ulator_class); 2035414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 2036414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 2037414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/* init early to allow our consumers to complete system booting */ 2038414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodcore_initcall(regulator_init); 2039