core.c revision cf7bbcdf4d267eff580cb7ce6cf4fe16a940a005
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 659c8e7e4640facbe99d10a6e262523b25be129b9b9Mark Brown * @constraints: constraints to apply 660a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * 661a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * Allows platform initialisation code to define and constrain 662a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * regulator circuits e.g. valid voltage/current ranges, etc. NOTE: 663a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * Constraints *must* be set by platform code in order for some 664a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * regulator operations to proceed i.e. set_voltage, set_current_limit, 665a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * set_mode. 666a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood */ 667a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwoodstatic int set_machine_constraints(struct regulator_dev *rdev, 668a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulation_constraints *constraints) 669a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood{ 670a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood int ret = 0; 671e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown const char *name; 672e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown struct regulator_ops *ops = rdev->desc->ops; 673e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown 674e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown if (constraints->name) 675e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown name = constraints->name; 676e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown else if (rdev->desc->name) 677e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown name = rdev->desc->name; 678e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown else 679e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown name = "regulator"; 680a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 681a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood rdev->constraints = constraints; 682a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 683a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood /* do we need to apply the constraint voltage */ 684a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood if (rdev->constraints->apply_uV && 685a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood rdev->constraints->min_uV == rdev->constraints->max_uV && 686e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown ops->set_voltage) { 687e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown ret = ops->set_voltage(rdev, 688a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood rdev->constraints->min_uV, rdev->constraints->max_uV); 689a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood if (ret < 0) { 690e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown printk(KERN_ERR "%s: failed to apply %duV constraint to %s\n", 691e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown __func__, 692e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown rdev->constraints->min_uV, name); 693a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood rdev->constraints = NULL; 694a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood goto out; 695a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood } 696a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood } 697a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 698a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood /* are we enabled at boot time by firmware / bootloader */ 699a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood if (rdev->constraints->boot_on) 700a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood rdev->use_count = 1; 701a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 702a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood /* do we need to setup our suspend state */ 703e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown if (constraints->initial_state) { 704a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood ret = suspend_prepare(rdev, constraints->initial_state); 705e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown if (ret < 0) { 706e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown printk(KERN_ERR "%s: failed to set suspend state for %s\n", 707e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown __func__, name); 708e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown rdev->constraints = NULL; 709e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown goto out; 710e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown } 711e06f5b4fea243b152c79fe5d9552a852069de483Mark Brown } 712a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 713e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown /* if always_on is set then turn the regulator on if it's not 714e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown * already on. */ 715e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown if (constraints->always_on && ops->enable && 716e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown ((ops->is_enabled && !ops->is_enabled(rdev)) || 717e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown (!ops->is_enabled && !constraints->boot_on))) { 718e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown ret = ops->enable(rdev); 719e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown if (ret < 0) { 720e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown printk(KERN_ERR "%s: failed to enable %s\n", 721e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown __func__, name); 722e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown rdev->constraints = NULL; 723e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown goto out; 724e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown } 725e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown } 726e5fda26c7ea9430d7d953364f900bafdce2be67bMark Brown 727a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood print_constraints(rdev); 728a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwoodout: 729a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood return ret; 730a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood} 731a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 732a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood/** 733a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * set_supply - set regulator supply regulator 73469279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @rdev: regulator name 73569279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @supply_rdev: supply regulator name 736a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * 737a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * Called by platform initialisation code to set the supply regulator for this 738a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * regulator. This ensures that a regulators supply will also be enabled by the 739a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * core if it's child is enabled. 740a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood */ 741a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwoodstatic int set_supply(struct regulator_dev *rdev, 742a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulator_dev *supply_rdev) 743a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood{ 744a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood int err; 745a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 746a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood err = sysfs_create_link(&rdev->dev.kobj, &supply_rdev->dev.kobj, 747a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood "supply"); 748a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood if (err) { 749a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood printk(KERN_ERR 750a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood "%s: could not add device link %s err %d\n", 751a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood __func__, supply_rdev->dev.kobj.name, err); 752a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood goto out; 753a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood } 754a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood rdev->supply = supply_rdev; 755a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood list_add(&rdev->slist, &supply_rdev->supply_list); 756a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwoodout: 757a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood return err; 758a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood} 759a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 760a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood/** 761a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * set_consumer_device_supply: Bind a regulator to a symbolic supply 76269279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @rdev: regulator source 76369279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @consumer_dev: device the supply applies to 76469279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @supply: symbolic name for supply 765a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * 766a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * Allows platform initialisation code to map physical regulator 767a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * sources to symbolic names for supplies for use by devices. Devices 768a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * should use these symbolic names to request regulators, avoiding the 769a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood * need to provide board-specific regulator names as platform data. 770a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood */ 771a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwoodstatic int set_consumer_device_supply(struct regulator_dev *rdev, 772a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct device *consumer_dev, const char *supply) 773a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood{ 774a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulator_map *node; 775a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 776a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood if (supply == NULL) 777a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood return -EINVAL; 778a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 779a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood node = kmalloc(sizeof(struct regulator_map), GFP_KERNEL); 780a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood if (node == NULL) 781a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood return -ENOMEM; 782a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 783a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood node->regulator = rdev; 784a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood node->dev = consumer_dev; 785a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood node->supply = supply; 786a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 787a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood list_add(&node->list, ®ulator_map_list); 788a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood return 0; 789a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood} 790a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 791a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwoodstatic void unset_consumer_device_supply(struct regulator_dev *rdev, 792a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct device *consumer_dev) 793a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood{ 794a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulator_map *node, *n; 795a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 796a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood list_for_each_entry_safe(node, n, ®ulator_map_list, list) { 797a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood if (rdev == node->regulator && 798a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood consumer_dev == node->dev) { 799a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood list_del(&node->list); 800a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood kfree(node); 801a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood return; 802a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood } 803a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood } 804a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood} 805a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 806414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood#define REG_STR_SIZE 32 807414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 808414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic struct regulator *create_regulator(struct regulator_dev *rdev, 809414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct device *dev, 810414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood const char *supply_name) 811414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 812414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator *regulator; 813414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood char buf[REG_STR_SIZE]; 814414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int err, size; 815414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 816414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator = kzalloc(sizeof(*regulator), GFP_KERNEL); 817414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (regulator == NULL) 818414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return NULL; 819414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 820414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(&rdev->mutex); 821414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator->rdev = rdev; 822414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood list_add(®ulator->list, &rdev->consumer_list); 823414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 824414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (dev) { 825414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* create a 'requested_microamps_name' sysfs entry */ 826414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood size = scnprintf(buf, REG_STR_SIZE, "microamps_requested_%s", 827414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood supply_name); 828414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (size >= REG_STR_SIZE) 829414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto overflow_err; 830414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 831414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator->dev = dev; 832414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator->dev_attr.attr.name = kstrdup(buf, GFP_KERNEL); 833414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (regulator->dev_attr.attr.name == NULL) 834414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto attr_name_err; 835414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 836414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator->dev_attr.attr.owner = THIS_MODULE; 837414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator->dev_attr.attr.mode = 0444; 838414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator->dev_attr.show = device_requested_uA_show; 839414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood err = device_create_file(dev, ®ulator->dev_attr); 840414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (err < 0) { 841414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_WARNING "%s: could not add regulator_dev" 842414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood " load sysfs\n", __func__); 843414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto attr_name_err; 844414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 845414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 846414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* also add a link to the device sysfs entry */ 847414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood size = scnprintf(buf, REG_STR_SIZE, "%s-%s", 848414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood dev->kobj.name, supply_name); 849414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (size >= REG_STR_SIZE) 850414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto attr_err; 851414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 852414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator->supply_name = kstrdup(buf, GFP_KERNEL); 853414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (regulator->supply_name == NULL) 854414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto attr_err; 855414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 856414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood err = sysfs_create_link(&rdev->dev.kobj, &dev->kobj, 857414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood buf); 858414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (err) { 859414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_WARNING 860414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood "%s: could not add device link %s err %d\n", 861414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood __func__, dev->kobj.name, err); 862414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood device_remove_file(dev, ®ulator->dev_attr); 863414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto link_name_err; 864414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 865414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 866414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(&rdev->mutex); 867414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return regulator; 868414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodlink_name_err: 869414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood kfree(regulator->supply_name); 870414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodattr_err: 871414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood device_remove_file(regulator->dev, ®ulator->dev_attr); 872414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodattr_name_err: 873414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood kfree(regulator->dev_attr.attr.name); 874414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodoverflow_err: 875414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood list_del(®ulator->list); 876414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood kfree(regulator); 877414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(&rdev->mutex); 878414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return NULL; 879414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 880414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 881414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 882414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_get - lookup and obtain a reference to a regulator. 883414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @dev: device for regulator "consumer" 884414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @id: Supply name or regulator ID. 885414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 886414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Returns a struct regulator corresponding to the regulator producer, 887414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * or IS_ERR() condition containing errno. Use of supply names 888414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * configured via regulator_set_device_supply() is strongly 889414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * encouraged. 890414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 891414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstruct regulator *regulator_get(struct device *dev, const char *id) 892414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 893414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_dev *rdev; 894414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_map *map; 895414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator *regulator = ERR_PTR(-ENODEV); 896414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 897414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (id == NULL) { 898414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "regulator: get() with no identifier\n"); 899414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return regulator; 900414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 901414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 902414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(®ulator_list_mutex); 903414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 904414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood list_for_each_entry(map, ®ulator_map_list, list) { 905414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (dev == map->dev && 906414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood strcmp(map->supply, id) == 0) { 907a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood rdev = map->regulator; 908414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto found; 909a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood } 910414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 911414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "regulator: Unable to get requested regulator: %s\n", 912414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood id); 913414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(®ulator_list_mutex); 914414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return regulator; 915414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 916414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodfound: 917a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood if (!try_module_get(rdev->owner)) 918a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood goto out; 919a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 920414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator = create_regulator(rdev, dev, id); 921414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (regulator == NULL) { 922414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator = ERR_PTR(-ENOMEM); 923414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood module_put(rdev->owner); 924414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 925414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 926a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwoodout: 927414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(®ulator_list_mutex); 928414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return regulator; 929414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 930414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_get); 931414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 932414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 933414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_put - "free" the regulator source 934414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator source 935414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 936414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Note: drivers must ensure that all regulator_enable calls made on this 937414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator source are balanced by regulator_disable calls prior to calling 938414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * this function. 939414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 940414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodvoid regulator_put(struct regulator *regulator) 941414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 942414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_dev *rdev; 943414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 944414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (regulator == NULL || IS_ERR(regulator)) 945414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return; 946414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 947414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(®ulator_list_mutex); 948414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood rdev = regulator->rdev; 949414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 950412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell if (WARN(regulator->enabled, "Releasing supply %s while enabled\n", 951412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell regulator->supply_name)) 952412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell _regulator_disable(rdev); 953412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell 954414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* remove any sysfs entries */ 955414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (regulator->dev) { 956414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood sysfs_remove_link(&rdev->dev.kobj, regulator->supply_name); 957414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood kfree(regulator->supply_name); 958414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood device_remove_file(regulator->dev, ®ulator->dev_attr); 959414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood kfree(regulator->dev_attr.attr.name); 960414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 961414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood list_del(®ulator->list); 962414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood kfree(regulator); 963414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 964414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood module_put(rdev->owner); 965414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(®ulator_list_mutex); 966414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 967414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_put); 968414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 969414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/* locks held by regulator_enable() */ 970414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic int _regulator_enable(struct regulator_dev *rdev) 971414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 972414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret = -EINVAL; 973414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 974414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!rdev->constraints) { 975414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: %s has no constraints\n", 976414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood __func__, rdev->desc->name); 977414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 978414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 979414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 980414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* do we need to enable the supply regulator first */ 981414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev->supply) { 982414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = _regulator_enable(rdev->supply); 983414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (ret < 0) { 984414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: failed to enable %s: %d\n", 985414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood __func__, rdev->desc->name, ret); 986414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 987414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 988414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 989414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 990414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* check voltage and requested load before enabling */ 991414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev->desc->ops->enable) { 992414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 993414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev->constraints && 994414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood (rdev->constraints->valid_ops_mask & 995414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood REGULATOR_CHANGE_DRMS)) 996414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood drms_uA_update(rdev); 997414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 998414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = rdev->desc->ops->enable(rdev); 999414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (ret < 0) { 1000414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: failed to enable %s: %d\n", 1001414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood __func__, rdev->desc->name, ret); 1002414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1003414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1004414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood rdev->use_count++; 1005414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1006414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1007414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1008414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1009414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1010414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1011414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1012414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_enable - enable regulator output 1013414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator source 1014414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1015cf7bbcdf4d267eff580cb7ce6cf4fe16a940a005Mark Brown * Request that the regulator be enabled with the regulator output at 1016cf7bbcdf4d267eff580cb7ce6cf4fe16a940a005Mark Brown * the predefined voltage or current value. Calls to regulator_enable() 1017cf7bbcdf4d267eff580cb7ce6cf4fe16a940a005Mark Brown * must be balanced with calls to regulator_disable(). 1018cf7bbcdf4d267eff580cb7ce6cf4fe16a940a005Mark Brown * 1019414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * NOTE: the output value can be set by other drivers, boot loader or may be 1020cf7bbcdf4d267eff580cb7ce6cf4fe16a940a005Mark Brown * hardwired in the regulator. 1021414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1022414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_enable(struct regulator *regulator) 1023414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1024412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell struct regulator_dev *rdev = regulator->rdev; 1025412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell int ret = 0; 1026414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1027412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell mutex_lock(&rdev->mutex); 1028412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell if (regulator->enabled == 0) 1029412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell ret = _regulator_enable(rdev); 1030412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell else if (regulator->enabled < 0) 1031412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell ret = -EIO; 1032412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell if (ret == 0) 1033412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell regulator->enabled++; 1034412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell mutex_unlock(&rdev->mutex); 1035414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1036414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1037414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_enable); 1038414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1039414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/* locks held by regulator_disable() */ 1040414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic int _regulator_disable(struct regulator_dev *rdev) 1041414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1042414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret = 0; 1043414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1044414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* are we the last user and permitted to disable ? */ 1045414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev->use_count == 1 && !rdev->constraints->always_on) { 1046414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1047414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* we are last user */ 1048414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev->desc->ops->disable) { 1049414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = rdev->desc->ops->disable(rdev); 1050414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (ret < 0) { 1051414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: failed to disable %s\n", 1052414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood __func__, rdev->desc->name); 1053414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1054414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1055414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1056414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1057414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* decrease our supplies ref count and disable if required */ 1058414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev->supply) 1059414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood _regulator_disable(rdev->supply); 1060414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1061414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood rdev->use_count = 0; 1062414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } else if (rdev->use_count > 1) { 1063414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1064414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev->constraints && 1065414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood (rdev->constraints->valid_ops_mask & 1066414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood REGULATOR_CHANGE_DRMS)) 1067414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood drms_uA_update(rdev); 1068414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1069414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood rdev->use_count--; 1070414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1071414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1072414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1073414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1074414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1075414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_disable - disable regulator output 1076414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator source 1077414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1078cf7bbcdf4d267eff580cb7ce6cf4fe16a940a005Mark Brown * Disable the regulator output voltage or current. Calls to 1079cf7bbcdf4d267eff580cb7ce6cf4fe16a940a005Mark Brown * regulator_enable() must be balanced with calls to 1080cf7bbcdf4d267eff580cb7ce6cf4fe16a940a005Mark Brown * regulator_disable(). 108169279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * 1082414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * NOTE: this will only disable the regulator output if no other consumer 1083cf7bbcdf4d267eff580cb7ce6cf4fe16a940a005Mark Brown * devices have it enabled, the regulator device supports disabling and 1084cf7bbcdf4d267eff580cb7ce6cf4fe16a940a005Mark Brown * machine constraints permit this operation. 1085414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1086414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_disable(struct regulator *regulator) 1087414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1088412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell struct regulator_dev *rdev = regulator->rdev; 1089412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell int ret = 0; 1090414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1091412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell mutex_lock(&rdev->mutex); 1092412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell if (regulator->enabled == 1) { 1093412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell ret = _regulator_disable(rdev); 1094412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell if (ret == 0) 1095412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell regulator->uA_load = 0; 1096412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell } else if (WARN(regulator->enabled <= 0, 1097412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell "unbalanced disables for supply %s\n", 1098412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell regulator->supply_name)) 1099412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell ret = -EIO; 1100412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell if (ret == 0) 1101412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell regulator->enabled--; 1102412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell mutex_unlock(&rdev->mutex); 1103414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1104414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1105414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_disable); 1106414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1107414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/* locks held by regulator_force_disable() */ 1108414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic int _regulator_force_disable(struct regulator_dev *rdev) 1109414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1110414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret = 0; 1111414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1112414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* force disable */ 1113414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev->desc->ops->disable) { 1114414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* ah well, who wants to live forever... */ 1115414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = rdev->desc->ops->disable(rdev); 1116414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (ret < 0) { 1117414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: failed to force disable %s\n", 1118414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood __func__, rdev->desc->name); 1119414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1120414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1121414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* notify other consumers that power has been forced off */ 1122414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE, 1123414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood NULL); 1124414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1125414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1126414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* decrease our supplies ref count and disable if required */ 1127414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev->supply) 1128414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood _regulator_disable(rdev->supply); 1129414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1130414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood rdev->use_count = 0; 1131414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1132414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1133414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1134414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1135414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_force_disable - force disable regulator output 1136414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator source 1137414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1138414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Forcibly disable the regulator output voltage or current. 1139414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * NOTE: this *will* disable the regulator output even if other consumer 1140414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * devices have it enabled. This should be used for situations when device 1141414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * damage will likely occur if the regulator is not disabled (e.g. over temp). 1142414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1143414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_force_disable(struct regulator *regulator) 1144414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1145414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret; 1146414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1147414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(®ulator->rdev->mutex); 1148414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator->enabled = 0; 1149414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator->uA_load = 0; 1150414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = _regulator_force_disable(regulator->rdev); 1151414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(®ulator->rdev->mutex); 1152414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1153414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1154414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_force_disable); 1155414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1156414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic int _regulator_is_enabled(struct regulator_dev *rdev) 1157414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1158414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret; 1159414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1160414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(&rdev->mutex); 1161414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1162414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* sanity check */ 1163414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!rdev->desc->ops->is_enabled) { 1164414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = -EINVAL; 1165414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1166414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1167414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1168414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = rdev->desc->ops->is_enabled(rdev); 1169414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodout: 1170414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(&rdev->mutex); 1171414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1172414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1173414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1174414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1175414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_is_enabled - is the regulator output enabled 1176414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator source 1177414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1178412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell * Returns positive if the regulator driver backing the source/client 1179412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell * has requested that the device be enabled, zero if it hasn't, else a 1180412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell * negative errno code. 1181412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell * 1182412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell * Note that the device backing this regulator handle can have multiple 1183412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell * users, so it might be enabled even if regulator_enable() was never 1184412aec610559bdb602a0a21ce149ba8ffbb6f983David Brownell * called for this particular source. 1185414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1186414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_is_enabled(struct regulator *regulator) 1187414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1188414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return _regulator_is_enabled(regulator->rdev); 1189414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1190414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_is_enabled); 1191414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1192414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1193414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_set_voltage - set regulator output voltage 1194414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator source 1195414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @min_uV: Minimum required voltage in uV 1196414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @max_uV: Maximum acceptable voltage in uV 1197414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1198414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Sets a voltage regulator to the desired output voltage. This can be set 1199414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * during any regulator state. IOW, regulator can be disabled or enabled. 1200414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1201414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * If the regulator is enabled then the voltage will change to the new value 1202414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * immediately otherwise if the regulator is disabled the regulator will 1203414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * output at the new voltage when enabled. 1204414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1205414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * NOTE: If the regulator is shared between several devices then the lowest 1206414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * request voltage that meets the system constraints will be used. 120769279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * Regulator system constraints must be set for this regulator before 1208414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * calling this function otherwise this call will fail. 1209414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1210414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV) 1211414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1212414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_dev *rdev = regulator->rdev; 1213414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret; 1214414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1215414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(&rdev->mutex); 1216414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1217414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* sanity check */ 1218414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!rdev->desc->ops->set_voltage) { 1219414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = -EINVAL; 1220414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1221414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1222414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1223414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* constraints check */ 1224414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = regulator_check_voltage(rdev, &min_uV, &max_uV); 1225414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (ret < 0) 1226414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1227414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator->min_uV = min_uV; 1228414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator->max_uV = max_uV; 1229414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV); 1230414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1231414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodout: 1232414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(&rdev->mutex); 1233414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1234414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1235414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_set_voltage); 1236414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1237414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic int _regulator_get_voltage(struct regulator_dev *rdev) 1238414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1239414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* sanity check */ 1240414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev->desc->ops->get_voltage) 1241414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return rdev->desc->ops->get_voltage(rdev); 1242414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood else 1243414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return -EINVAL; 1244414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1245414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1246414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1247414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_get_voltage - get regulator output voltage 1248414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator source 1249414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1250414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * This returns the current regulator voltage in uV. 1251414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1252414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * NOTE: If the regulator is disabled it will return the voltage value. This 1253414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * function should not be used to determine regulator state. 1254414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1255414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_get_voltage(struct regulator *regulator) 1256414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1257414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret; 1258414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1259414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(®ulator->rdev->mutex); 1260414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1261414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = _regulator_get_voltage(regulator->rdev); 1262414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1263414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(®ulator->rdev->mutex); 1264414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1265414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1266414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1267414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_get_voltage); 1268414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1269414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1270414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_set_current_limit - set regulator output current limit 1271414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator source 1272414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @min_uA: Minimuum supported current in uA 1273414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @max_uA: Maximum supported current in uA 1274414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1275414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Sets current sink to the desired output current. This can be set during 1276414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * any regulator state. IOW, regulator can be disabled or enabled. 1277414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1278414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * If the regulator is enabled then the current will change to the new value 1279414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * immediately otherwise if the regulator is disabled the regulator will 1280414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * output at the new current when enabled. 1281414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1282414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * NOTE: Regulator system constraints must be set for this regulator before 1283414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * calling this function otherwise this call will fail. 1284414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1285414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_set_current_limit(struct regulator *regulator, 1286414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int min_uA, int max_uA) 1287414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1288414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_dev *rdev = regulator->rdev; 1289414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret; 1290414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1291414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(&rdev->mutex); 1292414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1293414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* sanity check */ 1294414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!rdev->desc->ops->set_current_limit) { 1295414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = -EINVAL; 1296414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1297414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1298414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1299414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* constraints check */ 1300414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = regulator_check_current_limit(rdev, &min_uA, &max_uA); 1301414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (ret < 0) 1302414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1303414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1304414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = rdev->desc->ops->set_current_limit(rdev, min_uA, max_uA); 1305414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodout: 1306414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(&rdev->mutex); 1307414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1308414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1309414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_set_current_limit); 1310414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1311414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic int _regulator_get_current_limit(struct regulator_dev *rdev) 1312414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1313414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret; 1314414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1315414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(&rdev->mutex); 1316414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1317414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* sanity check */ 1318414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!rdev->desc->ops->get_current_limit) { 1319414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = -EINVAL; 1320414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1321414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1322414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1323414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = rdev->desc->ops->get_current_limit(rdev); 1324414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodout: 1325414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(&rdev->mutex); 1326414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1327414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1328414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1329414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1330414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_get_current_limit - get regulator output current 1331414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator source 1332414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1333414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * This returns the current supplied by the specified current sink in uA. 1334414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1335414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * NOTE: If the regulator is disabled it will return the current value. This 1336414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * function should not be used to determine regulator state. 1337414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1338414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_get_current_limit(struct regulator *regulator) 1339414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1340414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return _regulator_get_current_limit(regulator->rdev); 1341414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1342414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_get_current_limit); 1343414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1344414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1345414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_set_mode - set regulator operating mode 1346414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator source 1347414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @mode: operating mode - one of the REGULATOR_MODE constants 1348414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1349414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Set regulator operating mode to increase regulator efficiency or improve 1350414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulation performance. 1351414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1352414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * NOTE: Regulator system constraints must be set for this regulator before 1353414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * calling this function otherwise this call will fail. 1354414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1355414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_set_mode(struct regulator *regulator, unsigned int mode) 1356414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1357414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_dev *rdev = regulator->rdev; 1358414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret; 1359414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1360414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(&rdev->mutex); 1361414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1362414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* sanity check */ 1363414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!rdev->desc->ops->set_mode) { 1364414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = -EINVAL; 1365414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1366414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1367414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1368414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* constraints check */ 1369414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = regulator_check_mode(rdev, mode); 1370414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (ret < 0) 1371414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1372414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1373414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = rdev->desc->ops->set_mode(rdev, mode); 1374414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodout: 1375414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(&rdev->mutex); 1376414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1377414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1378414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_set_mode); 1379414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1380414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic unsigned int _regulator_get_mode(struct regulator_dev *rdev) 1381414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1382414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret; 1383414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1384414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(&rdev->mutex); 1385414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1386414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* sanity check */ 1387414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!rdev->desc->ops->get_mode) { 1388414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = -EINVAL; 1389414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1390414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1391414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1392414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = rdev->desc->ops->get_mode(rdev); 1393414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodout: 1394414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(&rdev->mutex); 1395414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1396414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1397414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1398414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1399414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_get_mode - get regulator operating mode 1400414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator source 1401414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1402414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Get the current regulator operating mode. 1403414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1404414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodunsigned int regulator_get_mode(struct regulator *regulator) 1405414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1406414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return _regulator_get_mode(regulator->rdev); 1407414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1408414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_get_mode); 1409414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1410414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1411414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_set_optimum_mode - set regulator optimum operating mode 1412414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator source 1413414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @uA_load: load current 1414414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1415414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Notifies the regulator core of a new device load. This is then used by 1416414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * DRMS (if enabled by constraints) to set the most efficient regulator 1417414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * operating mode for the new regulator loading. 1418414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1419414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Consumer devices notify their supply regulator of the maximum power 1420414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * they will require (can be taken from device datasheet in the power 1421414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * consumption tables) when they change operational status and hence power 1422414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * state. Examples of operational state changes that can affect power 1423414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * consumption are :- 1424414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1425414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * o Device is opened / closed. 1426414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * o Device I/O is about to begin or has just finished. 1427414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * o Device is idling in between work. 1428414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1429414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * This information is also exported via sysfs to userspace. 1430414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1431414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * DRMS will sum the total requested load on the regulator and change 1432414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * to the most efficient operating mode if platform constraints allow. 1433414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1434414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Returns the new regulator mode or error. 1435414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1436414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_set_optimum_mode(struct regulator *regulator, int uA_load) 1437414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1438414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_dev *rdev = regulator->rdev; 1439414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator *consumer; 1440414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret, output_uV, input_uV, total_uA_load = 0; 1441414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood unsigned int mode; 1442414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1443414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(&rdev->mutex); 1444414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1445414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator->uA_load = uA_load; 1446414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = regulator_check_drms(rdev); 1447414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (ret < 0) 1448414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1449414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = -EINVAL; 1450414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1451414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* sanity check */ 1452414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!rdev->desc->ops->get_optimum_mode) 1453414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1454414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1455414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* get output voltage */ 1456414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood output_uV = rdev->desc->ops->get_voltage(rdev); 1457414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (output_uV <= 0) { 1458414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: invalid output voltage found for %s\n", 1459414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood __func__, rdev->desc->name); 1460414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1461414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1462414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1463414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* get input voltage */ 1464414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev->supply && rdev->supply->desc->ops->get_voltage) 1465414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood input_uV = rdev->supply->desc->ops->get_voltage(rdev->supply); 1466414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood else 1467414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood input_uV = rdev->constraints->input_uV; 1468414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (input_uV <= 0) { 1469414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: invalid input voltage found for %s\n", 1470414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood __func__, rdev->desc->name); 1471414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1472414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1473414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1474414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* calc total requested load for this regulator */ 1475414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood list_for_each_entry(consumer, &rdev->consumer_list, list) 1476414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood total_uA_load += consumer->uA_load; 1477414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1478414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mode = rdev->desc->ops->get_optimum_mode(rdev, 1479414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood input_uV, output_uV, 1480414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood total_uA_load); 1481e573520b171095c106ffbbbf4f9cbed6d9bff576David Brownell ret = regulator_check_mode(rdev, mode); 1482e573520b171095c106ffbbbf4f9cbed6d9bff576David Brownell if (ret < 0) { 1483414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: failed to get optimum mode for %s @" 1484414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood " %d uA %d -> %d uV\n", __func__, rdev->desc->name, 1485414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood total_uA_load, input_uV, output_uV); 1486414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1487414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1488414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1489414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = rdev->desc->ops->set_mode(rdev, mode); 1490e573520b171095c106ffbbbf4f9cbed6d9bff576David Brownell if (ret < 0) { 1491414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: failed to set optimum mode %x for %s\n", 1492414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood __func__, mode, rdev->desc->name); 1493414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1494414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1495414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = mode; 1496414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodout: 1497414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(&rdev->mutex); 1498414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1499414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1500414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_set_optimum_mode); 1501414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1502414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1503414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_register_notifier - register regulator event notifier 1504414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator source 150569279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @nb: notifier block 1506414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1507414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Register notifier block to receive regulator events. 1508414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1509414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_register_notifier(struct regulator *regulator, 1510414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct notifier_block *nb) 1511414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1512414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return blocking_notifier_chain_register(®ulator->rdev->notifier, 1513414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood nb); 1514414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1515414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_register_notifier); 1516414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1517414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1518414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_unregister_notifier - unregister regulator event notifier 1519414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator source 152069279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @nb: notifier block 1521414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1522414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Unregister regulator event notifier block. 1523414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1524414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_unregister_notifier(struct regulator *regulator, 1525414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct notifier_block *nb) 1526414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1527414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return blocking_notifier_chain_unregister(®ulator->rdev->notifier, 1528414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood nb); 1529414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1530414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_unregister_notifier); 1531414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1532414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/* notify regulator consumers and downstream regulator consumers */ 1533414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic void _notifier_call_chain(struct regulator_dev *rdev, 1534414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood unsigned long event, void *data) 1535414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1536414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_dev *_rdev; 1537414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1538414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* call rdev chain first */ 1539414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(&rdev->mutex); 1540414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood blocking_notifier_call_chain(&rdev->notifier, event, NULL); 1541414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(&rdev->mutex); 1542414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1543414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* now notify regulator we supply */ 1544414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood list_for_each_entry(_rdev, &rdev->supply_list, slist) 1545414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood _notifier_call_chain(_rdev, event, data); 1546414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1547414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1548414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1549414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_bulk_get - get multiple regulator consumers 1550414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1551414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @dev: Device to supply 1552414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @num_consumers: Number of consumers to register 1553414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @consumers: Configuration of consumers; clients are stored here. 1554414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1555414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @return 0 on success, an errno on failure. 1556414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1557414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * This helper function allows drivers to get several regulator 1558414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * consumers in one operation. If any of the regulators cannot be 1559414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * acquired then any regulators that were allocated will be freed 1560414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * before returning to the caller. 1561414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1562414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_bulk_get(struct device *dev, int num_consumers, 1563414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_bulk_data *consumers) 1564414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1565414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int i; 1566414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret; 1567414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1568414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood for (i = 0; i < num_consumers; i++) 1569414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood consumers[i].consumer = NULL; 1570414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1571414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood for (i = 0; i < num_consumers; i++) { 1572414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood consumers[i].consumer = regulator_get(dev, 1573414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood consumers[i].supply); 1574414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (IS_ERR(consumers[i].consumer)) { 1575414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood dev_err(dev, "Failed to get supply '%s'\n", 1576414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood consumers[i].supply); 1577414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = PTR_ERR(consumers[i].consumer); 1578414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood consumers[i].consumer = NULL; 1579414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto err; 1580414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1581414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1582414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1583414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return 0; 1584414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1585414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwooderr: 1586414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood for (i = 0; i < num_consumers && consumers[i].consumer; i++) 1587414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator_put(consumers[i].consumer); 1588414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1589414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1590414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1591414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_bulk_get); 1592414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1593414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1594414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_bulk_enable - enable multiple regulator consumers 1595414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1596414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @num_consumers: Number of consumers 1597414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @consumers: Consumer data; clients are stored here. 1598414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @return 0 on success, an errno on failure 1599414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1600414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * This convenience API allows consumers to enable multiple regulator 1601414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * clients in a single API call. If any consumers cannot be enabled 1602414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * then any others that were enabled will be disabled again prior to 1603414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * return. 1604414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1605414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_bulk_enable(int num_consumers, 1606414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_bulk_data *consumers) 1607414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1608414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int i; 1609414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret; 1610414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1611414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood for (i = 0; i < num_consumers; i++) { 1612414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = regulator_enable(consumers[i].consumer); 1613414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (ret != 0) 1614414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto err; 1615414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1616414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1617414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return 0; 1618414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1619414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwooderr: 1620414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "Failed to enable %s\n", consumers[i].supply); 1621414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood for (i = 0; i < num_consumers; i++) 1622414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator_disable(consumers[i].consumer); 1623414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1624414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1625414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1626414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_bulk_enable); 1627414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1628414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1629414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_bulk_disable - disable multiple regulator consumers 1630414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1631414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @num_consumers: Number of consumers 1632414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @consumers: Consumer data; clients are stored here. 1633414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @return 0 on success, an errno on failure 1634414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1635414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * This convenience API allows consumers to disable multiple regulator 1636414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * clients in a single API call. If any consumers cannot be enabled 1637414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * then any others that were disabled will be disabled again prior to 1638414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * return. 1639414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1640414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_bulk_disable(int num_consumers, 1641414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_bulk_data *consumers) 1642414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1643414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int i; 1644414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret; 1645414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1646414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood for (i = 0; i < num_consumers; i++) { 1647414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = regulator_disable(consumers[i].consumer); 1648414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (ret != 0) 1649414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto err; 1650414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1651414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1652414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return 0; 1653414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1654414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwooderr: 1655414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "Failed to disable %s\n", consumers[i].supply); 1656414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood for (i = 0; i < num_consumers; i++) 1657414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator_enable(consumers[i].consumer); 1658414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1659414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1660414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1661414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_bulk_disable); 1662414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1663414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1664414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_bulk_free - free multiple regulator consumers 1665414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1666414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @num_consumers: Number of consumers 1667414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @consumers: Consumer data; clients are stored here. 1668414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1669414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * This convenience API allows consumers to free multiple regulator 1670414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * clients in a single API call. 1671414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1672414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodvoid regulator_bulk_free(int num_consumers, 1673414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_bulk_data *consumers) 1674414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1675414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int i; 1676414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1677414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood for (i = 0; i < num_consumers; i++) { 1678414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator_put(consumers[i].consumer); 1679414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood consumers[i].consumer = NULL; 1680414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1681414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1682414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_bulk_free); 1683414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1684414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1685414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_notifier_call_chain - call regulator event notifier 168669279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @rdev: regulator source 1687414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @event: notifier block 168869279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @data: callback-specific data. 1689414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1690414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Called by regulator drivers to notify clients a regulator event has 1691414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * occurred. We also notify regulator clients downstream. 1692414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1693414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_notifier_call_chain(struct regulator_dev *rdev, 1694414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood unsigned long event, void *data) 1695414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1696414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood _notifier_call_chain(rdev, event, data); 1697414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return NOTIFY_DONE; 1698414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1699414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1700414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_notifier_call_chain); 1701414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 17027ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell/* 17037ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell * To avoid cluttering sysfs (and memory) with useless state, only 17047ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell * create attributes that can be meaningfully displayed. 17057ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell */ 17067ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownellstatic int add_regulator_attributes(struct regulator_dev *rdev) 17077ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell{ 17087ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell struct device *dev = &rdev->dev; 17097ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell struct regulator_ops *ops = rdev->desc->ops; 17107ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell int status = 0; 17117ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell 17127ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell /* some attributes need specific methods to be displayed */ 17137ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (ops->get_voltage) { 17147ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, &dev_attr_microvolts); 17157ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17167ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17177ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell } 17187ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (ops->get_current_limit) { 17197ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, &dev_attr_microamps); 17207ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17217ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17227ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell } 17237ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (ops->get_mode) { 17247ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, &dev_attr_opmode); 17257ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17267ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17277ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell } 17287ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (ops->is_enabled) { 17297ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, &dev_attr_state); 17307ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17317ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17327ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell } 17337ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell 17347ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell /* some attributes are type-specific */ 17357ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (rdev->desc->type == REGULATOR_CURRENT) { 17367ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, &dev_attr_requested_microamps); 17377ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17387ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17397ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell } 17407ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell 17417ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell /* all the other attributes exist to support constraints; 17427ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell * don't show them if there are no constraints, or if the 17437ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell * relevant supporting methods are missing. 17447ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell */ 17457ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (!rdev->constraints) 17467ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17477ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell 17487ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell /* constraints need specific supporting methods */ 17497ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (ops->set_voltage) { 17507ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, &dev_attr_min_microvolts); 17517ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17527ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17537ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, &dev_attr_max_microvolts); 17547ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17557ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17567ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell } 17577ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (ops->set_current_limit) { 17587ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, &dev_attr_min_microamps); 17597ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17607ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17617ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, &dev_attr_max_microamps); 17627ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17637ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17647ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell } 17657ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell 17667ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell /* suspend mode constraints need multiple supporting methods */ 17677ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (!(ops->set_suspend_enable && ops->set_suspend_disable)) 17687ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17697ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell 17707ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, &dev_attr_suspend_standby_state); 17717ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17727ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17737ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, &dev_attr_suspend_mem_state); 17747ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17757ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17767ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, &dev_attr_suspend_disk_state); 17777ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17787ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17797ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell 17807ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (ops->set_suspend_voltage) { 17817ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, 17827ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell &dev_attr_suspend_standby_microvolts); 17837ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17847ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17857ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, 17867ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell &dev_attr_suspend_mem_microvolts); 17877ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17887ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17897ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, 17907ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell &dev_attr_suspend_disk_microvolts); 17917ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17927ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 17937ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell } 17947ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell 17957ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (ops->set_suspend_mode) { 17967ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, 17977ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell &dev_attr_suspend_standby_mode); 17987ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 17997ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 18007ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, 18017ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell &dev_attr_suspend_mem_mode); 18027ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 18037ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 18047ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell status = device_create_file(dev, 18057ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell &dev_attr_suspend_disk_mode); 18067ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (status < 0) 18077ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 18087ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell } 18097ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell 18107ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell return status; 18117ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell} 18127ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell 1813414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1814414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_register - register regulator 181569279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @regulator_desc: regulator to register 181669279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @dev: struct device for the regulator 181769279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @driver_data: private regulator data 1818414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1819414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Called by regulator drivers to register a regulator. 1820414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Returns 0 on success. 1821414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1822414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstruct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, 1823a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct device *dev, void *driver_data) 1824414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1825414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood static atomic_t regulator_no = ATOMIC_INIT(0); 1826414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_dev *rdev; 1827a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood struct regulator_init_data *init_data = dev->platform_data; 1828a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood int ret, i; 1829414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1830414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (regulator_desc == NULL) 1831414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ERR_PTR(-EINVAL); 1832414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1833414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (regulator_desc->name == NULL || regulator_desc->ops == NULL) 1834414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ERR_PTR(-EINVAL); 1835414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1836414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (!regulator_desc->type == REGULATOR_VOLTAGE && 1837414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood !regulator_desc->type == REGULATOR_CURRENT) 1838414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ERR_PTR(-EINVAL); 1839414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 184046fabe1edd44a8893d88d7982f88d01ccf77f0bbMark Brown if (!init_data) 184146fabe1edd44a8893d88d7982f88d01ccf77f0bbMark Brown return ERR_PTR(-EINVAL); 184246fabe1edd44a8893d88d7982f88d01ccf77f0bbMark Brown 1843414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL); 1844414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev == NULL) 1845414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ERR_PTR(-ENOMEM); 1846414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1847414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(®ulator_list_mutex); 1848414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1849414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_init(&rdev->mutex); 1850a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood rdev->reg_data = driver_data; 1851414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood rdev->owner = regulator_desc->owner; 1852414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood rdev->desc = regulator_desc; 1853414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood INIT_LIST_HEAD(&rdev->consumer_list); 1854414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood INIT_LIST_HEAD(&rdev->supply_list); 1855414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood INIT_LIST_HEAD(&rdev->list); 1856414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood INIT_LIST_HEAD(&rdev->slist); 1857414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier); 1858414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1859a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood /* preform any regulator specific init */ 1860a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood if (init_data->regulator_init) { 1861a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood ret = init_data->regulator_init(rdev->reg_data); 18624fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell if (ret < 0) 18634fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell goto clean; 1864a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood } 1865a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 1866a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood /* register with sysfs */ 1867414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood rdev->dev.class = ®ulator_class; 1868a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood rdev->dev.parent = dev; 1869812460a927c1d0dc1fbdbec9aa07de1b04043d83Kay Sievers dev_set_name(&rdev->dev, "regulator.%d", 1870812460a927c1d0dc1fbdbec9aa07de1b04043d83Kay Sievers atomic_inc_return(®ulator_no) - 1); 1871a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood ret = device_register(&rdev->dev); 18724fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell if (ret != 0) 18734fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell goto clean; 1874a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 1875a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood dev_set_drvdata(&rdev->dev, rdev); 1876a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 187774f544c1fc0339acf6f66ff438b8543b1f9faf10Mike Rapoport /* set regulator constraints */ 187874f544c1fc0339acf6f66ff438b8543b1f9faf10Mike Rapoport ret = set_machine_constraints(rdev, &init_data->constraints); 187974f544c1fc0339acf6f66ff438b8543b1f9faf10Mike Rapoport if (ret < 0) 188074f544c1fc0339acf6f66ff438b8543b1f9faf10Mike Rapoport goto scrub; 188174f544c1fc0339acf6f66ff438b8543b1f9faf10Mike Rapoport 18827ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell /* add attributes supported by this regulator */ 18837ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell ret = add_regulator_attributes(rdev); 18847ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell if (ret < 0) 18857ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell goto scrub; 18867ad68e2f970fd84d15ad67ce3216aed05f944a9cDavid Brownell 1887a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood /* set supply regulator if it exists */ 1888a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood if (init_data->supply_regulator_dev) { 1889a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood ret = set_supply(rdev, 1890a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood dev_get_drvdata(init_data->supply_regulator_dev)); 18914fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell if (ret < 0) 18924fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell goto scrub; 1893a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood } 1894a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 1895a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood /* add consumers devices */ 1896a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood for (i = 0; i < init_data->num_consumer_supplies; i++) { 1897a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood ret = set_consumer_device_supply(rdev, 1898a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood init_data->consumer_supplies[i].dev, 1899a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood init_data->consumer_supplies[i].supply); 1900a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood if (ret < 0) { 1901a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood for (--i; i >= 0; i--) 1902a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood unset_consumer_device_supply(rdev, 1903a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood init_data->consumer_supplies[i].dev); 19044fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell goto scrub; 1905a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood } 1906414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1907a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 1908a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood list_add(&rdev->list, ®ulator_list); 1909a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwoodout: 1910414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(®ulator_list_mutex); 1911414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return rdev; 19124fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell 19134fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownellscrub: 19144fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell device_unregister(&rdev->dev); 19154fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownellclean: 19164fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell kfree(rdev); 19174fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell rdev = ERR_PTR(ret); 19184fca9545d17b99cdb2774716b034c62a70151bcdDavid Brownell goto out; 1919414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1920414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_register); 1921414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1922414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1923414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_unregister - unregister regulator 192469279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @rdev: regulator to unregister 1925414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1926414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Called by regulator drivers to unregister a regulator. 1927414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1928414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodvoid regulator_unregister(struct regulator_dev *rdev) 1929414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1930414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev == NULL) 1931414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return; 1932414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1933414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(®ulator_list_mutex); 1934414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood list_del(&rdev->list); 1935414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (rdev->supply) 1936414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood sysfs_remove_link(&rdev->dev.kobj, "supply"); 1937414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood device_unregister(&rdev->dev); 1938414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(®ulator_list_mutex); 1939414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1940414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_unregister); 1941414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1942414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1943cf7bbcdf4d267eff580cb7ce6cf4fe16a940a005Mark Brown * regulator_suspend_prepare - prepare regulators for system wide suspend 1944414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @state: system suspend state 1945414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1946414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Configure each regulator with it's suspend operating parameters for state. 1947414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * This will usually be called by machine suspend code prior to supending. 1948414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1949414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint regulator_suspend_prepare(suspend_state_t state) 1950414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1951414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood struct regulator_dev *rdev; 1952414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood int ret = 0; 1953414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1954414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood /* ON is handled by regulator active state */ 1955414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (state == PM_SUSPEND_ON) 1956414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return -EINVAL; 1957414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1958414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(®ulator_list_mutex); 1959414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood list_for_each_entry(rdev, ®ulator_list, list) { 1960414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1961414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_lock(&rdev->mutex); 1962414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood ret = suspend_prepare(rdev, state); 1963414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(&rdev->mutex); 1964414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1965414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood if (ret < 0) { 1966414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_ERR "%s: failed to prepare %s\n", 1967414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood __func__, rdev->desc->name); 1968414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood goto out; 1969414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1970414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood } 1971414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodout: 1972414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood mutex_unlock(®ulator_list_mutex); 1973414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return ret; 1974414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1975414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_suspend_prepare); 1976414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1977414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1978414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * rdev_get_drvdata - get rdev regulator driver data 197969279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @rdev: regulator 1980414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1981414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Get rdev regulator driver private data. This call can be used in the 1982414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator driver context. 1983414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1984414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodvoid *rdev_get_drvdata(struct regulator_dev *rdev) 1985414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1986414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return rdev->reg_data; 1987414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 1988414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(rdev_get_drvdata); 1989414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 1990414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 1991414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_get_drvdata - get regulator driver data 1992414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator 1993414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * 1994414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * Get regulator driver private data. This call can be used in the consumer 1995414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * driver context when non API regulator specific functions need to be called. 1996414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 1997414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodvoid *regulator_get_drvdata(struct regulator *regulator) 1998414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 1999414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return regulator->rdev->reg_data; 2000414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 2001414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_get_drvdata); 2002414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 2003414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 2004414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_set_drvdata - set regulator driver data 2005414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @regulator: regulator 2006414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * @data: data 2007414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 2008414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodvoid regulator_set_drvdata(struct regulator *regulator, void *data) 2009414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 2010414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood regulator->rdev->reg_data = data; 2011414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 2012414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_set_drvdata); 2013414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 2014414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/** 2015414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood * regulator_get_id - get regulator ID 201669279fb9a95051971ac03e558c4d46e7ba84ab3aMark Brown * @rdev: regulator 2017414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood */ 2018414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodint rdev_get_id(struct regulator_dev *rdev) 2019414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 2020414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return rdev->desc->id; 2021414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 2022414c70cb91c445ec813b61e16fe4882807e40240Liam GirdwoodEXPORT_SYMBOL_GPL(rdev_get_id); 2023414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 2024a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwoodstruct device *rdev_get_dev(struct regulator_dev *rdev) 2025a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood{ 2026a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood return &rdev->dev; 2027a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood} 2028a5766f11cfd3a0c03450d99c8fe548c2940be884Liam GirdwoodEXPORT_SYMBOL_GPL(rdev_get_dev); 2029a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 2030a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwoodvoid *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data) 2031a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood{ 2032a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood return reg_init_data->driver_data; 2033a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood} 2034a5766f11cfd3a0c03450d99c8fe548c2940be884Liam GirdwoodEXPORT_SYMBOL_GPL(regulator_get_init_drvdata); 2035a5766f11cfd3a0c03450d99c8fe548c2940be884Liam Girdwood 2036414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodstatic int __init regulator_init(void) 2037414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood{ 2038414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood printk(KERN_INFO "regulator: core version %s\n", REGULATOR_VERSION); 2039414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood return class_register(®ulator_class); 2040414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood} 2041414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood 2042414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwood/* init early to allow our consumers to complete system booting */ 2043414c70cb91c445ec813b61e16fe4882807e40240Liam Girdwoodcore_initcall(regulator_init); 2044