blob: 2dae05705f13e21b9d3410b6c5dfb494a1b9bab8 [file] [log] [blame]
Liam Girdwood571a3542008-04-30 15:42:28 +01001/*
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
Liam Girdwood571a3542008-04-30 15:42:28 +010021struct regulator_dev;
Liam Girdwooda5766f12008-10-10 13:22:20 +010022struct regulator_init_data;
Liam Girdwood571a3542008-04-30 15:42:28 +010023
24/**
25 * struct regulator_ops - regulator operations.
26 *
Mark Brownc8e7e462008-12-31 12:52:42 +000027 * 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.
Randy Dunlap0ba48872009-01-08 11:50:23 -080032 * @is_enabled: Return 1 if the regulator is enabled, 0 otherwise.
Mark Brownc8e7e462008-12-31 12:52:42 +000033 *
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 *
Mark Brownc8e7e462008-12-31 12:52:42 +000038 * @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.
Liam Girdwood571a3542008-04-30 15:42:28 +010054 */
55struct 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
Mark Brown3de89602008-09-09 16:21:17 +010080 * its parent PMIC enters a global STANDBY/HIBERNATE state */
Liam Girdwood571a3542008-04-30 15:42:28 +010081
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 */
96enum regulator_type {
97 REGULATOR_VOLTAGE,
98 REGULATOR_CURRENT,
99};
100
101/**
102 * struct regulator_desc - Regulator descriptor
103 *
Mark Brownc8e7e462008-12-31 12:52:42 +0000104 * 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.
Randy Dunlap0ba48872009-01-08 11:50:23 -0800110 * @irq: Interrupt number for the regulator.
Mark Brownc8e7e462008-12-31 12:52:42 +0000111 * @type: Indicates if the regulator is a voltage or current regulator.
112 * @owner: Module providing the regulator, used for refcounting.
Liam Girdwood571a3542008-04-30 15:42:28 +0100113 */
114struct 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
Liam Girdwood571a3542008-04-30 15:42:28 +0100123struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
Liam Girdwooda5766f12008-10-10 13:22:20 +0100124 struct device *dev, void *driver_data);
Liam Girdwood571a3542008-04-30 15:42:28 +0100125void regulator_unregister(struct regulator_dev *rdev);
126
127int regulator_notifier_call_chain(struct regulator_dev *rdev,
128 unsigned long event, void *data);
129
130void *rdev_get_drvdata(struct regulator_dev *rdev);
Liam Girdwooda5766f12008-10-10 13:22:20 +0100131struct device *rdev_get_dev(struct regulator_dev *rdev);
Liam Girdwood571a3542008-04-30 15:42:28 +0100132int rdev_get_id(struct regulator_dev *rdev);
133
Liam Girdwooda5766f12008-10-10 13:22:20 +0100134void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data);
135
Liam Girdwood571a3542008-04-30 15:42:28 +0100136#endif