OMAP3+ VP: replace transaction done check/clear with VP ops
[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_data - 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  * @voltsetup_shift: SETUP_TIME* field shift in the PRM_VOLTSETUP* register
44  *
45  * XXX What about VOLTOFFSET/VOLTCTRL?
46  * XXX It is not necessary to have both a _mask and a _shift for the same
47  *     bitfield - remove one!
48  */
49 struct omap_vfsm_instance_data {
50         u32 voltsetup_mask;
51         u8 voltsetup_reg;
52         u8 voltsetup_shift;
53 };
54
55 /**
56  * struct voltagedomain - omap voltage domain global structure.
57  * @name: Name of the voltage domain which can be used as a unique identifier.
58  * @scalable: Whether or not this voltage domain is scalable
59  * @node: list_head linking all voltage domains
60  * @pwrdm_list: list_head linking all powerdomains in this voltagedomain
61  * @vc: pointer to VC channel associated with this voltagedomain
62  * @vdd: to be removed
63  */
64 struct voltagedomain {
65         char *name;
66         bool scalable;
67         struct list_head node;
68         struct list_head pwrdm_list;
69         struct omap_vc_channel *vc;
70
71         struct omap_vdd_info *vdd;
72 };
73
74 /**
75  * struct omap_volt_data - Omap voltage specific data.
76  * @voltage_nominal:    The possible voltage value in uV
77  * @sr_efuse_offs:      The offset of the efuse register(from system
78  *                      control module base address) from where to read
79  *                      the n-target value for the smartreflex module.
80  * @sr_errminlimit:     Error min limit value for smartreflex. This value
81  *                      differs at differnet opp and thus is linked
82  *                      with voltage.
83  * @vp_errorgain:       Error gain value for the voltage processor. This
84  *                      field also differs according to the voltage/opp.
85  */
86 struct omap_volt_data {
87         u32     volt_nominal;
88         u32     sr_efuse_offs;
89         u8      sr_errminlimit;
90         u8      vp_errgain;
91 };
92
93 /**
94  * struct omap_volt_pmic_info - PMIC specific data required by voltage driver.
95  * @slew_rate:  PMIC slew rate (in uv/us)
96  * @step_size:  PMIC voltage step size (in uv)
97  * @vsel_to_uv: PMIC API to convert vsel value to actual voltage in uV.
98  * @uv_to_vsel: PMIC API to convert voltage in uV to vsel value.
99  * @volt_reg_addr: voltage configuration register address
100  * @cmd_reg_addr: command (on, on-LP, ret, off) configuration register address
101  */
102 struct omap_volt_pmic_info {
103         int slew_rate;
104         int step_size;
105         u32 on_volt;
106         u32 onlp_volt;
107         u32 ret_volt;
108         u32 off_volt;
109         u16 volt_setup_time;
110         u8 vp_erroroffset;
111         u8 vp_vstepmin;
112         u8 vp_vstepmax;
113         u8 vp_vddmin;
114         u8 vp_vddmax;
115         u8 vp_timeout_us;
116         u8 i2c_slave_addr;
117         u8 volt_reg_addr;
118         u8 cmd_reg_addr;
119         unsigned long (*vsel_to_uv) (const u8 vsel);
120         u8 (*uv_to_vsel) (unsigned long uV);
121 };
122
123 /**
124  * omap_vdd_info - Per Voltage Domain info
125  *
126  * @volt_data           : voltage table having the distinct voltages supported
127  *                        by the domain and other associated per voltage data.
128  * @pmic_info           : pmic specific parameters which should be populted by
129  *                        the pmic drivers.
130  * @vp_data             : the register values, shifts, masks for various
131  *                        vp registers
132  * @vp_rt_data          : VP data derived at runtime, not predefined
133  * @vfsm                : voltage manager FSM data
134  * @debug_dir           : debug directory for this voltage domain.
135  * @curr_volt           : current voltage for this vdd.
136  * @vp_enabled          : flag to keep track of whether vp is enabled or not
137  * @volt_scale          : API to scale the voltage of the vdd.
138  */
139 struct omap_vdd_info {
140         struct omap_volt_data *volt_data;
141         struct omap_volt_pmic_info *pmic_info;
142         struct omap_vp_instance_data *vp_data;
143         struct omap_vp_runtime_data vp_rt_data;
144         const struct omap_vfsm_instance_data *vfsm;
145         struct dentry *debug_dir;
146         u32 curr_volt;
147         bool vp_enabled;
148
149         u32 (*read_reg) (u16 mod, u8 offset);
150         void (*write_reg) (u32 val, u16 mod, u8 offset);
151         int (*volt_scale) (struct voltagedomain *voltdm,
152                 unsigned long target_volt);
153 };
154
155 int omap_voltage_scale_vdd(struct voltagedomain *voltdm,
156                 unsigned long target_volt);
157 void omap_voltage_reset(struct voltagedomain *voltdm);
158 void omap_voltage_get_volttable(struct voltagedomain *voltdm,
159                 struct omap_volt_data **volt_data);
160 struct omap_volt_data *omap_voltage_get_voltdata(struct voltagedomain *voltdm,
161                 unsigned long volt);
162 unsigned long omap_voltage_get_nom_volt(struct voltagedomain *voltdm);
163 struct dentry *omap_voltage_get_dbgdir(struct voltagedomain *voltdm);
164 #ifdef CONFIG_PM
165 int omap_voltage_register_pmic(struct voltagedomain *voltdm,
166                 struct omap_volt_pmic_info *pmic_info);
167 void omap_change_voltscale_method(struct voltagedomain *voltdm,
168                 int voltscale_method);
169 int omap_voltage_late_init(void);
170 #else
171 static inline int omap_voltage_register_pmic(struct voltagedomain *voltdm,
172                 struct omap_volt_pmic_info *pmic_info)
173 {
174         return -EINVAL;
175 }
176 static inline  void omap_change_voltscale_method(struct voltagedomain *voltdm,
177                 int voltscale_method) {}
178 static inline int omap_voltage_late_init(void)
179 {
180         return -EINVAL;
181 }
182 #endif
183
184 extern void omap2xxx_voltagedomains_init(void);
185 extern void omap3xxx_voltagedomains_init(void);
186 extern void omap44xx_voltagedomains_init(void);
187
188 struct voltagedomain *voltdm_lookup(const char *name);
189 void voltdm_init(struct voltagedomain **voltdm_list);
190 int voltdm_add_pwrdm(struct voltagedomain *voltdm, struct powerdomain *pwrdm);
191 int voltdm_for_each(int (*fn)(struct voltagedomain *voltdm, void *user),
192                     void *user);
193 int voltdm_for_each_pwrdm(struct voltagedomain *voltdm,
194                           int (*fn)(struct voltagedomain *voltdm,
195                                     struct powerdomain *pwrdm));
196 #endif