OMAP3+: VC: make I2C config programmable with PMIC-specific settings
[pandora-kernel.git] / arch / arm / mach-omap2 / voltage.h
1 /*
2  * OMAP Voltage Management Routines
3  *
4  * Author: Thara Gopinath       <thara@ti.com>
5  *
6  * Copyright (C) 2009 Texas Instruments, Inc.
7  * Thara Gopinath <thara@ti.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13
14 #ifndef __ARCH_ARM_MACH_OMAP2_VOLTAGE_H
15 #define __ARCH_ARM_MACH_OMAP2_VOLTAGE_H
16
17 #include <linux/err.h>
18
19 #include "vc.h"
20 #include "vp.h"
21
22 struct powerdomain;
23
24 /* XXX document */
25 #define VOLTSCALE_VPFORCEUPDATE         1
26 #define VOLTSCALE_VCBYPASS              2
27
28 /*
29  * OMAP3 GENERIC setup times. Revisit to see if these needs to be
30  * passed from board or PMIC file
31  */
32 #define OMAP3_CLKSETUP          0xff
33 #define OMAP3_VOLTOFFSET        0xff
34 #define OMAP3_VOLTSETUP2        0xff
35
36 struct omap_vdd_info;
37
38 /**
39  * struct omap_vfsm_instance - per-voltage manager FSM register/bitfield
40  * data
41  * @voltsetup_mask: SETUP_TIME* bitmask in the PRM_VOLTSETUP* register
42  * @voltsetup_reg: register offset of PRM_VOLTSETUP from PRM base
43  *
44  * XXX What about VOLTOFFSET/VOLTCTRL?
45  */
46 struct omap_vfsm_instance {
47         u32 voltsetup_mask;
48         u8 voltsetup_reg;
49 };
50
51 /**
52  * struct voltagedomain - omap voltage domain global structure.
53  * @name: Name of the voltage domain which can be used as a unique identifier.
54  * @scalable: Whether or not this voltage domain is scalable
55  * @node: list_head linking all voltage domains
56  * @pwrdm_list: list_head linking all powerdomains in this voltagedomain
57  * @vc: pointer to VC channel associated with this voltagedomain
58  * @read: read a VC/VP register
59  * @write: write a VC/VP register
60  * @read: read-modify-write a VC/VP register
61  * @vdd: to be removed
62  */
63 struct voltagedomain {
64         char *name;
65         bool scalable;
66         struct list_head node;
67         struct list_head pwrdm_list;
68         struct omap_vc_channel *vc;
69         const struct omap_vfsm_instance *vfsm;
70         struct omap_voltdm_pmic *pmic;
71
72         /* VC/VP register access functions: SoC specific */
73         u32 (*read) (u8 offset);
74         void (*write) (u32 val, u8 offset);
75         u32 (*rmw)(u32 mask, u32 bits, u8 offset);
76
77         struct omap_vdd_info *vdd;
78 };
79
80 /**
81  * struct omap_volt_data - Omap voltage specific data.
82  * @voltage_nominal:    The possible voltage value in uV
83  * @sr_efuse_offs:      The offset of the efuse register(from system
84  *                      control module base address) from where to read
85  *                      the n-target value for the smartreflex module.
86  * @sr_errminlimit:     Error min limit value for smartreflex. This value
87  *                      differs at differnet opp and thus is linked
88  *                      with voltage.
89  * @vp_errorgain:       Error gain value for the voltage processor. This
90  *                      field also differs according to the voltage/opp.
91  */
92 struct omap_volt_data {
93         u32     volt_nominal;
94         u32     sr_efuse_offs;
95         u8      sr_errminlimit;
96         u8      vp_errgain;
97 };
98
99 /**
100  * struct omap_voltdm_pmic - PMIC specific data required by voltage driver.
101  * @slew_rate:  PMIC slew rate (in uv/us)
102  * @step_size:  PMIC voltage step size (in uv)
103  * @i2c_slave_addr: I2C slave address of PMIC
104  * @volt_reg_addr: voltage configuration register address
105  * @cmd_reg_addr: command (on, on-LP, ret, off) configuration register address
106  * @i2c_high_speed: whether VC uses I2C high-speed mode to PMIC
107  * @i2c_mcode: master code value for I2C high-speed preamble transmission
108  * @vsel_to_uv: PMIC API to convert vsel value to actual voltage in uV.
109  * @uv_to_vsel: PMIC API to convert voltage in uV to vsel value.
110  */
111 struct omap_voltdm_pmic {
112         int slew_rate;
113         int step_size;
114         u32 on_volt;
115         u32 onlp_volt;
116         u32 ret_volt;
117         u32 off_volt;
118         u16 volt_setup_time;
119         u16 i2c_slave_addr;
120         u16 volt_reg_addr;
121         u16 cmd_reg_addr;
122         u8 vp_erroroffset;
123         u8 vp_vstepmin;
124         u8 vp_vstepmax;
125         u8 vp_vddmin;
126         u8 vp_vddmax;
127         u8 vp_timeout_us;
128         bool i2c_high_speed;
129         u8 i2c_mcode;
130         unsigned long (*vsel_to_uv) (const u8 vsel);
131         u8 (*uv_to_vsel) (unsigned long uV);
132 };
133
134 /**
135  * omap_vdd_info - Per Voltage Domain info
136  *
137  * @volt_data           : voltage table having the distinct voltages supported
138  *                        by the domain and other associated per voltage data.
139  * @vp_data             : the register values, shifts, masks for various
140  *                        vp registers
141  * @vp_rt_data          : VP data derived at runtime, not predefined
142  * @debug_dir           : debug directory for this voltage domain.
143  * @curr_volt           : current voltage for this vdd.
144  * @vp_enabled          : flag to keep track of whether vp is enabled or not
145  * @volt_scale          : API to scale the voltage of the vdd.
146  */
147 struct omap_vdd_info {
148         struct omap_volt_data *volt_data;
149         struct omap_vp_instance_data *vp_data;
150         struct omap_vp_runtime_data vp_rt_data;
151         struct dentry *debug_dir;
152         u32 curr_volt;
153         bool vp_enabled;
154
155         int (*volt_scale) (struct voltagedomain *voltdm,
156                 unsigned long target_volt);
157 };
158
159 int omap_voltage_scale_vdd(struct voltagedomain *voltdm,
160                 unsigned long target_volt);
161 void omap_voltage_reset(struct voltagedomain *voltdm);
162 void omap_voltage_get_volttable(struct voltagedomain *voltdm,
163                 struct omap_volt_data **volt_data);
164 struct omap_volt_data *omap_voltage_get_voltdata(struct voltagedomain *voltdm,
165                 unsigned long volt);
166 unsigned long omap_voltage_get_nom_volt(struct voltagedomain *voltdm);
167 struct dentry *omap_voltage_get_dbgdir(struct voltagedomain *voltdm);
168 #ifdef CONFIG_PM
169 int omap_voltage_register_pmic(struct voltagedomain *voltdm,
170                                struct omap_voltdm_pmic *pmic);
171 void omap_change_voltscale_method(struct voltagedomain *voltdm,
172                 int voltscale_method);
173 int omap_voltage_late_init(void);
174 #else
175 static inline int omap_voltage_register_pmic(struct voltagedomain *voltdm,
176                                              struct omap_voltdm_pmic *pmic)
177 {
178         return -EINVAL;
179 }
180 static inline  void omap_change_voltscale_method(struct voltagedomain *voltdm,
181                 int voltscale_method) {}
182 static inline int omap_voltage_late_init(void)
183 {
184         return -EINVAL;
185 }
186 #endif
187
188 extern void omap2xxx_voltagedomains_init(void);
189 extern void omap3xxx_voltagedomains_init(void);
190 extern void omap44xx_voltagedomains_init(void);
191
192 struct voltagedomain *voltdm_lookup(const char *name);
193 void voltdm_init(struct voltagedomain **voltdm_list);
194 int voltdm_add_pwrdm(struct voltagedomain *voltdm, struct powerdomain *pwrdm);
195 int voltdm_for_each(int (*fn)(struct voltagedomain *voltdm, void *user),
196                     void *user);
197 int voltdm_for_each_pwrdm(struct voltagedomain *voltdm,
198                           int (*fn)(struct voltagedomain *voltdm,
199                                     struct powerdomain *pwrdm));
200 #endif