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