1 /* 2 * driver.h -- SoC Regulator driver support. 3 * 4 * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC. 5 * 6 * Author: Liam Girdwood <lg@opensource.wolfsonmicro.com> 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License version 2 as 10 * published by the Free Software Foundation. 11 * 12 * Regulator Driver Interface. 13 */ 14 15 #ifndef __LINUX_REGULATOR_DRIVER_H_ 16 #define __LINUX_REGULATOR_DRIVER_H_ 17 18 #include <linux/device.h> 19 #include <linux/regulator/consumer.h> 20 21 struct regulator_dev; 22 struct regulator_init_data; 23 24 /** 25 * struct regulator_ops - regulator operations. 26 * 27 * This struct describes regulator operations which can be implemented by 28 * regulator chip drivers. 29 * 30 * @enable: Enable the regulator. 31 * @disable: Disable the regulator. 32 * @is_enabled: Return 1 if the regulator is enabled, 0 otherwise. 33 * 34 * @set_voltage: Set the voltage for the regulator within the range specified. 35 * The driver should select the voltage closest to min_uV. 36 * @get_voltage: Return the currently configured voltage for the regulator. 37 * 38 * @set_current_limit: Configure a limit for a current-limited regulator. 39 * @get_current_limit: Get the limit for a current-limited regulator. 40 * 41 * @set_mode: Set the operating mode for the regulator. 42 * @get_mode: Get the current operating mode for the regulator. 43 * @get_optimum_mode: Get the most efficient operating mode for the regulator 44 * when running with the specified parameters. 45 * 46 * @set_suspend_voltage: Set the voltage for the regulator when the system 47 * is suspended. 48 * @set_suspend_enable: Mark the regulator as enabled when the system is 49 * suspended. 50 * @set_suspend_disable: Mark the regulator as disabled when the system is 51 * suspended. 52 * @set_suspend_mode: Set the operating mode for the regulator when the 53 * system is suspended. 54 */ 55 struct regulator_ops { 56 57 /* get/set regulator voltage */ 58 int (*set_voltage) (struct regulator_dev *, int min_uV, int max_uV); 59 int (*get_voltage) (struct regulator_dev *); 60 61 /* get/set regulator current */ 62 int (*set_current_limit) (struct regulator_dev *, 63 int min_uA, int max_uA); 64 int (*get_current_limit) (struct regulator_dev *); 65 66 /* enable/disable regulator */ 67 int (*enable) (struct regulator_dev *); 68 int (*disable) (struct regulator_dev *); 69 int (*is_enabled) (struct regulator_dev *); 70 71 /* get/set regulator operating mode (defined in regulator.h) */ 72 int (*set_mode) (struct regulator_dev *, unsigned int mode); 73 unsigned int (*get_mode) (struct regulator_dev *); 74 75 /* get most efficient regulator operating mode for load */ 76 unsigned int (*get_optimum_mode) (struct regulator_dev *, int input_uV, 77 int output_uV, int load_uA); 78 79 /* the operations below are for configuration of regulator state when 80 * its parent PMIC enters a global STANDBY/HIBERNATE state */ 81 82 /* set regulator suspend voltage */ 83 int (*set_suspend_voltage) (struct regulator_dev *, int uV); 84 85 /* enable/disable regulator in suspend state */ 86 int (*set_suspend_enable) (struct regulator_dev *); 87 int (*set_suspend_disable) (struct regulator_dev *); 88 89 /* set regulator suspend operating mode (defined in regulator.h) */ 90 int (*set_suspend_mode) (struct regulator_dev *, unsigned int mode); 91 }; 92 93 /* 94 * Regulators can either control voltage or current. 95 */ 96 enum regulator_type { 97 REGULATOR_VOLTAGE, 98 REGULATOR_CURRENT, 99 }; 100 101 /** 102 * struct regulator_desc - Regulator descriptor 103 * 104 * Each regulator registered with the core is described with a structure of 105 * this type. 106 * 107 * @name: Identifying name for the regulator. 108 * @id: Numerical identifier for the regulator. 109 * @ops: Regulator operations table. 110 * @irq: Interrupt number for the regulator. 111 * @type: Indicates if the regulator is a voltage or current regulator. 112 * @owner: Module providing the regulator, used for refcounting. 113 */ 114 struct regulator_desc { 115 const char *name; 116 int id; 117 struct regulator_ops *ops; 118 int irq; 119 enum regulator_type type; 120 struct module *owner; 121 }; 122 123 struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, 124 struct device *dev, void *driver_data); 125 void regulator_unregister(struct regulator_dev *rdev); 126 127 int regulator_notifier_call_chain(struct regulator_dev *rdev, 128 unsigned long event, void *data); 129 130 void *rdev_get_drvdata(struct regulator_dev *rdev); 131 struct device *rdev_get_dev(struct regulator_dev *rdev); 132 int rdev_get_id(struct regulator_dev *rdev); 133 134 void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data); 135 136 #endif 137