xref: /openbmc/linux/arch/arm/mach-omap2/voltage.h (revision 25985edc)
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 /**
35  * struct omap_vfsm_instance_data - per-voltage manager FSM register/bitfield
36  * data
37  * @voltsetup_mask: SETUP_TIME* bitmask in the PRM_VOLTSETUP* register
38  * @voltsetup_reg: register offset of PRM_VOLTSETUP from PRM base
39  * @voltsetup_shift: SETUP_TIME* field shift in the PRM_VOLTSETUP* register
40  *
41  * XXX What about VOLTOFFSET/VOLTCTRL?
42  * XXX It is not necessary to have both a _mask and a _shift for the same
43  *     bitfield - remove one!
44  */
45 struct omap_vfsm_instance_data {
46 	u32 voltsetup_mask;
47 	u8 voltsetup_reg;
48 	u8 voltsetup_shift;
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
54  *		identifier.
55  */
56 struct voltagedomain {
57 	char *name;
58 };
59 
60 /**
61  * struct omap_volt_data - Omap voltage specific data.
62  * @voltage_nominal:	The possible voltage value in uV
63  * @sr_efuse_offs:	The offset of the efuse register(from system
64  *			control module base address) from where to read
65  *			the n-target value for the smartreflex module.
66  * @sr_errminlimit:	Error min limit value for smartreflex. This value
67  *			differs at differnet opp and thus is linked
68  *			with voltage.
69  * @vp_errorgain:	Error gain value for the voltage processor. This
70  *			field also differs according to the voltage/opp.
71  */
72 struct omap_volt_data {
73 	u32	volt_nominal;
74 	u32	sr_efuse_offs;
75 	u8	sr_errminlimit;
76 	u8	vp_errgain;
77 };
78 
79 /**
80  * struct omap_volt_pmic_info - PMIC specific data required by voltage driver.
81  * @slew_rate:	PMIC slew rate (in uv/us)
82  * @step_size:	PMIC voltage step size (in uv)
83  * @vsel_to_uv:	PMIC API to convert vsel value to actual voltage in uV.
84  * @uv_to_vsel:	PMIC API to convert voltage in uV to vsel value.
85  */
86 struct omap_volt_pmic_info {
87 	int slew_rate;
88 	int step_size;
89 	u32 on_volt;
90 	u32 onlp_volt;
91 	u32 ret_volt;
92 	u32 off_volt;
93 	u16 volt_setup_time;
94 	u8 vp_erroroffset;
95 	u8 vp_vstepmin;
96 	u8 vp_vstepmax;
97 	u8 vp_vddmin;
98 	u8 vp_vddmax;
99 	u8 vp_timeout_us;
100 	u8 i2c_slave_addr;
101 	u8 pmic_reg;
102 	unsigned long (*vsel_to_uv) (const u8 vsel);
103 	u8 (*uv_to_vsel) (unsigned long uV);
104 };
105 
106 /**
107  * omap_vdd_info - Per Voltage Domain info
108  *
109  * @volt_data		: voltage table having the distinct voltages supported
110  *			  by the domain and other associated per voltage data.
111  * @pmic_info		: pmic specific parameters which should be populted by
112  *			  the pmic drivers.
113  * @vp_data		: the register values, shifts, masks for various
114  *			  vp registers
115  * @vp_rt_data          : VP data derived at runtime, not predefined
116  * @vc_data		: structure containing various various vc registers,
117  *			  shifts, masks etc.
118  * @vfsm                : voltage manager FSM data
119  * @voltdm		: pointer to the voltage domain structure
120  * @debug_dir		: debug directory for this voltage domain.
121  * @curr_volt		: current voltage for this vdd.
122  * @vp_enabled		: flag to keep track of whether vp is enabled or not
123  * @volt_scale		: API to scale the voltage of the vdd.
124  */
125 struct omap_vdd_info {
126 	struct omap_volt_data *volt_data;
127 	struct omap_volt_pmic_info *pmic_info;
128 	struct omap_vp_instance_data *vp_data;
129 	struct omap_vp_runtime_data vp_rt_data;
130 	struct omap_vc_instance_data *vc_data;
131 	const struct omap_vfsm_instance_data *vfsm;
132 	struct voltagedomain voltdm;
133 	struct dentry *debug_dir;
134 	u32 curr_volt;
135 	bool vp_enabled;
136 	u32 (*read_reg) (u16 mod, u8 offset);
137 	void (*write_reg) (u32 val, u16 mod, u8 offset);
138 	int (*volt_scale) (struct omap_vdd_info *vdd,
139 		unsigned long target_volt);
140 };
141 
142 unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm);
143 void omap_vp_enable(struct voltagedomain *voltdm);
144 void omap_vp_disable(struct voltagedomain *voltdm);
145 int omap_voltage_scale_vdd(struct voltagedomain *voltdm,
146 		unsigned long target_volt);
147 void omap_voltage_reset(struct voltagedomain *voltdm);
148 void omap_voltage_get_volttable(struct voltagedomain *voltdm,
149 		struct omap_volt_data **volt_data);
150 struct omap_volt_data *omap_voltage_get_voltdata(struct voltagedomain *voltdm,
151 		unsigned long volt);
152 unsigned long omap_voltage_get_nom_volt(struct voltagedomain *voltdm);
153 struct dentry *omap_voltage_get_dbgdir(struct voltagedomain *voltdm);
154 int __init omap_voltage_early_init(s16 prm_mod, s16 prm_irqst_mod,
155 				   struct omap_vdd_info *omap_vdd_array[],
156 				   u8 omap_vdd_count);
157 #ifdef CONFIG_PM
158 int omap_voltage_register_pmic(struct voltagedomain *voltdm,
159 		struct omap_volt_pmic_info *pmic_info);
160 void omap_change_voltscale_method(struct voltagedomain *voltdm,
161 		int voltscale_method);
162 /* API to get the voltagedomain pointer */
163 struct voltagedomain *omap_voltage_domain_lookup(char *name);
164 
165 int omap_voltage_late_init(void);
166 #else
167 static inline int omap_voltage_register_pmic(struct voltagedomain *voltdm,
168 		struct omap_volt_pmic_info *pmic_info)
169 {
170 	return -EINVAL;
171 }
172 static inline  void omap_change_voltscale_method(struct voltagedomain *voltdm,
173 		int voltscale_method) {}
174 static inline int omap_voltage_late_init(void)
175 {
176 	return -EINVAL;
177 }
178 static inline struct voltagedomain *omap_voltage_domain_lookup(char *name)
179 {
180 	return ERR_PTR(-EINVAL);
181 }
182 #endif
183 
184 #endif
185