blob: 16a1b092cf36902b768010fc899b4defcded7eb3 [file] [log] [blame]
Thara Gopinath2f34ce82010-05-29 22:02:21 +05301/*
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
Santosh Shilimkarfaacebc2011-01-05 16:27:04 +053017#include <linux/err.h>
18
Paul Walmsleyc0718df2011-03-10 22:17:45 -070019#include "vc.h"
20#include "vp.h"
21
Kevin Hilmane69c22b2011-03-16 16:13:15 -070022struct powerdomain;
23
Paul Walmsleyc0718df2011-03-10 22:17:45 -070024/* XXX document */
Thara Gopinath2f34ce82010-05-29 22:02:21 +053025#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
Paul Walmsleyc0718df2011-03-10 22:17:45 -070036/**
Kevin Hilman5892bb12011-03-29 14:36:04 -070037 * struct omap_vfsm_instance - per-voltage manager FSM register/bitfield
Paul Walmsleyc0718df2011-03-10 22:17:45 -070038 * data
39 * @voltsetup_mask: SETUP_TIME* bitmask in the PRM_VOLTSETUP* register
40 * @voltsetup_reg: register offset of PRM_VOLTSETUP from PRM base
Paul Walmsleyc0718df2011-03-10 22:17:45 -070041 *
42 * XXX What about VOLTOFFSET/VOLTCTRL?
Paul Walmsleyc0718df2011-03-10 22:17:45 -070043 */
Kevin Hilman5892bb12011-03-29 14:36:04 -070044struct omap_vfsm_instance {
Paul Walmsleyc0718df2011-03-10 22:17:45 -070045 u32 voltsetup_mask;
46 u8 voltsetup_reg;
Paul Walmsleyc0718df2011-03-10 22:17:45 -070047};
Thara Gopinathbd381072010-12-10 23:15:23 +053048
Thara Gopinath2f34ce82010-05-29 22:02:21 +053049/**
50 * struct voltagedomain - omap voltage domain global structure.
Kevin Hilman81a60482011-03-16 14:25:45 -070051 * @name: Name of the voltage domain which can be used as a unique identifier.
Kevin Hilman37efca72011-03-23 17:00:21 -070052 * @scalable: Whether or not this voltage domain is scalable
Kevin Hilman81a60482011-03-16 14:25:45 -070053 * @node: list_head linking all voltage domains
Kevin Hilmane69c22b2011-03-16 16:13:15 -070054 * @pwrdm_list: list_head linking all powerdomains in this voltagedomain
Kevin Hilmand84adcf2011-03-22 16:14:57 -070055 * @vc: pointer to VC channel associated with this voltagedomain
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070056 * @vp: pointer to VP associated with this voltagedomain
Kevin Hilman4bcc4752011-03-28 10:40:15 -070057 * @read: read a VC/VP register
58 * @write: write a VC/VP register
59 * @read: read-modify-write a VC/VP register
Kevin Hilman0e2f3d92011-04-04 17:22:28 -070060 * @sys_clk: system clock name/frequency, used for various timing calculations
Kevin Hilman0f015652011-07-14 11:12:32 -070061 * @scale: function used to scale the voltage of the voltagedomain
Kevin Hilman7590f602011-04-05 16:55:22 -070062 * @nominal_volt: current nominal voltage for this voltage domain
Kevin Hilmane3277882011-07-14 11:29:06 -070063 * @volt_data: voltage table having the distinct voltages supported
64 * by the domain and other associated per voltage data.
Thara Gopinath2f34ce82010-05-29 22:02:21 +053065 */
66struct voltagedomain {
67 char *name;
Kevin Hilman37efca72011-03-23 17:00:21 -070068 bool scalable;
Kevin Hilman81a60482011-03-16 14:25:45 -070069 struct list_head node;
Kevin Hilmane69c22b2011-03-16 16:13:15 -070070 struct list_head pwrdm_list;
Kevin Hilmand84adcf2011-03-22 16:14:57 -070071 struct omap_vc_channel *vc;
Kevin Hilman5892bb12011-03-29 14:36:04 -070072 const struct omap_vfsm_instance *vfsm;
Kevin Hilmanb7ea8032011-04-04 15:25:07 -070073 struct omap_vp_instance *vp;
Kevin Hilmance8ebe02011-03-30 11:01:10 -070074 struct omap_voltdm_pmic *pmic;
Kevin Hilmand84adcf2011-03-22 16:14:57 -070075
Kevin Hilman4bcc4752011-03-28 10:40:15 -070076 /* VC/VP register access functions: SoC specific */
77 u32 (*read) (u8 offset);
78 void (*write) (u32 val, u8 offset);
79 u32 (*rmw)(u32 mask, u32 bits, u8 offset);
80
Kevin Hilman0e2f3d92011-04-04 17:22:28 -070081 union {
82 const char *name;
83 u32 rate;
84 } sys_clk;
85
Kevin Hilman0f015652011-07-14 11:12:32 -070086 int (*scale) (struct voltagedomain *voltdm,
87 unsigned long target_volt);
88
Kevin Hilmane3277882011-07-14 11:29:06 -070089 u32 nominal_volt;
90 struct omap_volt_data *volt_data;
Thara Gopinath2f34ce82010-05-29 22:02:21 +053091};
92
Thara Gopinath2f34ce82010-05-29 22:02:21 +053093/**
94 * struct omap_volt_data - Omap voltage specific data.
95 * @voltage_nominal: The possible voltage value in uV
96 * @sr_efuse_offs: The offset of the efuse register(from system
97 * control module base address) from where to read
98 * the n-target value for the smartreflex module.
99 * @sr_errminlimit: Error min limit value for smartreflex. This value
100 * differs at differnet opp and thus is linked
101 * with voltage.
102 * @vp_errorgain: Error gain value for the voltage processor. This
103 * field also differs according to the voltage/opp.
104 */
105struct omap_volt_data {
106 u32 volt_nominal;
107 u32 sr_efuse_offs;
108 u8 sr_errminlimit;
109 u8 vp_errgain;
110};
111
112/**
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700113 * struct omap_voltdm_pmic - PMIC specific data required by voltage driver.
Thara Gopinath2f34ce82010-05-29 22:02:21 +0530114 * @slew_rate: PMIC slew rate (in uv/us)
115 * @step_size: PMIC voltage step size (in uv)
Kevin Hilmanba112a42011-03-29 14:02:36 -0700116 * @i2c_slave_addr: I2C slave address of PMIC
Kevin Hilmane74e4402011-03-22 14:12:37 -0700117 * @volt_reg_addr: voltage configuration register address
118 * @cmd_reg_addr: command (on, on-LP, ret, off) configuration register address
Kevin Hilmanf5395482011-03-30 16:36:30 -0700119 * @i2c_high_speed: whether VC uses I2C high-speed mode to PMIC
120 * @i2c_mcode: master code value for I2C high-speed preamble transmission
Kevin Hilmane4e021c2011-06-09 11:01:55 -0700121 * @vsel_to_uv: PMIC API to convert vsel value to actual voltage in uV.
122 * @uv_to_vsel: PMIC API to convert voltage in uV to vsel value.
Thara Gopinath2f34ce82010-05-29 22:02:21 +0530123 */
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700124struct omap_voltdm_pmic {
Thara Gopinath2f34ce82010-05-29 22:02:21 +0530125 int slew_rate;
126 int step_size;
127 u32 on_volt;
128 u32 onlp_volt;
129 u32 ret_volt;
130 u32 off_volt;
131 u16 volt_setup_time;
Kevin Hilmanba112a42011-03-29 14:02:36 -0700132 u16 i2c_slave_addr;
Kevin Hilmane4e021c2011-06-09 11:01:55 -0700133 u16 volt_reg_addr;
134 u16 cmd_reg_addr;
Thara Gopinath2f34ce82010-05-29 22:02:21 +0530135 u8 vp_erroroffset;
136 u8 vp_vstepmin;
137 u8 vp_vstepmax;
138 u8 vp_vddmin;
139 u8 vp_vddmax;
140 u8 vp_timeout_us;
Kevin Hilmanf5395482011-03-30 16:36:30 -0700141 bool i2c_high_speed;
142 u8 i2c_mcode;
Thara Gopinath2f34ce82010-05-29 22:02:21 +0530143 unsigned long (*vsel_to_uv) (const u8 vsel);
144 u8 (*uv_to_vsel) (unsigned long uV);
145};
146
Thara Gopinath2f34ce82010-05-29 22:02:21 +0530147void omap_voltage_get_volttable(struct voltagedomain *voltdm,
148 struct omap_volt_data **volt_data);
149struct omap_volt_data *omap_voltage_get_voltdata(struct voltagedomain *voltdm,
150 unsigned long volt);
Thara Gopinath2f34ce82010-05-29 22:02:21 +0530151int omap_voltage_register_pmic(struct voltagedomain *voltdm,
Kevin Hilmance8ebe02011-03-30 11:01:10 -0700152 struct omap_voltdm_pmic *pmic);
Thara Gopinath2f34ce82010-05-29 22:02:21 +0530153void omap_change_voltscale_method(struct voltagedomain *voltdm,
154 int voltscale_method);
155int omap_voltage_late_init(void);
Thara Gopinath2f34ce82010-05-29 22:02:21 +0530156
Kevin Hilmanaae030f2011-03-23 16:09:41 -0700157extern void omap2xxx_voltagedomains_init(void);
Kevin Hilman81a60482011-03-16 14:25:45 -0700158extern void omap3xxx_voltagedomains_init(void);
159extern void omap44xx_voltagedomains_init(void);
160
161struct voltagedomain *voltdm_lookup(const char *name);
162void voltdm_init(struct voltagedomain **voltdm_list);
Kevin Hilman048a7032011-03-16 15:52:47 -0700163int voltdm_add_pwrdm(struct voltagedomain *voltdm, struct powerdomain *pwrdm);
Kevin Hilmane69c22b2011-03-16 16:13:15 -0700164int voltdm_for_each(int (*fn)(struct voltagedomain *voltdm, void *user),
165 void *user);
166int voltdm_for_each_pwrdm(struct voltagedomain *voltdm,
167 int (*fn)(struct voltagedomain *voltdm,
168 struct powerdomain *pwrdm));
Kevin Hilman5e5651b2011-04-05 16:27:21 -0700169int voltdm_scale(struct voltagedomain *voltdm, unsigned long target_volt);
170void voltdm_reset(struct voltagedomain *voltdm);
Kevin Hilmand5c12822011-07-15 16:05:12 -0700171unsigned long voltdm_get_voltage(struct voltagedomain *voltdm);
Thara Gopinath2f34ce82010-05-29 22:02:21 +0530172#endif