xref: /openbmc/linux/include/linux/mfd/abx500.h (revision fa661258)
1812f9e9dSLinus Walleij /*
2812f9e9dSLinus Walleij  * Copyright (C) 2007-2009 ST-Ericsson AB
3812f9e9dSLinus Walleij  * License terms: GNU General Public License (GPL) version 2
4812f9e9dSLinus Walleij  * AB3100 core access functions
5812f9e9dSLinus Walleij  * Author: Linus Walleij <linus.walleij@stericsson.com>
6fa661258SMattias Wallin  *
7fa661258SMattias Wallin  * ABX500 core access functions.
8fa661258SMattias Wallin  * The abx500 interface is used for the Analog Baseband chip
9fa661258SMattias Wallin  * ab3100, ab3550, ab5500 and possibly comming. It is not used for
10fa661258SMattias Wallin  * ab4500 and ab8500 since they are another family of chip.
11fa661258SMattias Wallin  *
12fa661258SMattias Wallin  * Author: Mattias Wallin <mattias.wallin@stericsson.com>
13fa661258SMattias Wallin  * Author: Mattias Nilsson <mattias.i.nilsson@stericsson.com>
14fa661258SMattias Wallin  * Author: Bengt Jonsson <bengt.g.jonsson@stericsson.com>
15fa661258SMattias Wallin  * Author: Rickard Andersson <rickard.andersson@stericsson.com>
16812f9e9dSLinus Walleij  */
17812f9e9dSLinus Walleij 
18812f9e9dSLinus Walleij #include <linux/device.h>
19812f9e9dSLinus Walleij #include <linux/regulator/machine.h>
20812f9e9dSLinus Walleij 
21fa661258SMattias Wallin #ifndef MFD_ABX500_H
22fa661258SMattias Wallin #define MFD_ABX500_H
23812f9e9dSLinus Walleij 
24fa661258SMattias Wallin #define AB3100_P1A	0xc0
25fa661258SMattias Wallin #define AB3100_P1B	0xc1
26fa661258SMattias Wallin #define AB3100_P1C	0xc2
27fa661258SMattias Wallin #define AB3100_P1D	0xc3
28fa661258SMattias Wallin #define AB3100_P1E	0xc4
29fa661258SMattias Wallin #define AB3100_P1F	0xc5
30fa661258SMattias Wallin #define AB3100_P1G	0xc6
31fa661258SMattias Wallin #define AB3100_R2A	0xc7
32fa661258SMattias Wallin #define AB3100_R2B	0xc8
33fa661258SMattias Wallin #define AB3550_P1A	0x10
34fa661258SMattias Wallin #define AB5500_1_0	0x20
35fa661258SMattias Wallin #define AB5500_2_0	0x21
36fa661258SMattias Wallin #define AB5500_2_1	0x22
37812f9e9dSLinus Walleij 
38812f9e9dSLinus Walleij /*
39812f9e9dSLinus Walleij  * AB3100, EVENTA1, A2 and A3 event register flags
40812f9e9dSLinus Walleij  * these are catenated into a single 32-bit flag in the code
41812f9e9dSLinus Walleij  * for event notification broadcasts.
42812f9e9dSLinus Walleij  */
43812f9e9dSLinus Walleij #define AB3100_EVENTA1_ONSWA				(0x01<<16)
44812f9e9dSLinus Walleij #define AB3100_EVENTA1_ONSWB				(0x02<<16)
45812f9e9dSLinus Walleij #define AB3100_EVENTA1_ONSWC				(0x04<<16)
46812f9e9dSLinus Walleij #define AB3100_EVENTA1_DCIO				(0x08<<16)
47812f9e9dSLinus Walleij #define AB3100_EVENTA1_OVER_TEMP			(0x10<<16)
48812f9e9dSLinus Walleij #define AB3100_EVENTA1_SIM_OFF				(0x20<<16)
49812f9e9dSLinus Walleij #define AB3100_EVENTA1_VBUS				(0x40<<16)
50812f9e9dSLinus Walleij #define AB3100_EVENTA1_VSET_USB				(0x80<<16)
51812f9e9dSLinus Walleij 
52812f9e9dSLinus Walleij #define AB3100_EVENTA2_READY_TX				(0x01<<8)
53812f9e9dSLinus Walleij #define AB3100_EVENTA2_READY_RX				(0x02<<8)
54812f9e9dSLinus Walleij #define AB3100_EVENTA2_OVERRUN_ERROR			(0x04<<8)
55812f9e9dSLinus Walleij #define AB3100_EVENTA2_FRAMING_ERROR			(0x08<<8)
56812f9e9dSLinus Walleij #define AB3100_EVENTA2_CHARG_OVERCURRENT		(0x10<<8)
57812f9e9dSLinus Walleij #define AB3100_EVENTA2_MIDR				(0x20<<8)
58812f9e9dSLinus Walleij #define AB3100_EVENTA2_BATTERY_REM			(0x40<<8)
59812f9e9dSLinus Walleij #define AB3100_EVENTA2_ALARM				(0x80<<8)
60812f9e9dSLinus Walleij 
61812f9e9dSLinus Walleij #define AB3100_EVENTA3_ADC_TRIG5			(0x01)
62812f9e9dSLinus Walleij #define AB3100_EVENTA3_ADC_TRIG4			(0x02)
63812f9e9dSLinus Walleij #define AB3100_EVENTA3_ADC_TRIG3			(0x04)
64812f9e9dSLinus Walleij #define AB3100_EVENTA3_ADC_TRIG2			(0x08)
65812f9e9dSLinus Walleij #define AB3100_EVENTA3_ADC_TRIGVBAT			(0x10)
66812f9e9dSLinus Walleij #define AB3100_EVENTA3_ADC_TRIGVTX			(0x20)
67812f9e9dSLinus Walleij #define AB3100_EVENTA3_ADC_TRIG1			(0x40)
68812f9e9dSLinus Walleij #define AB3100_EVENTA3_ADC_TRIG0			(0x80)
69812f9e9dSLinus Walleij 
70812f9e9dSLinus Walleij /* AB3100, STR register flags */
71812f9e9dSLinus Walleij #define AB3100_STR_ONSWA				(0x01)
72812f9e9dSLinus Walleij #define AB3100_STR_ONSWB				(0x02)
73812f9e9dSLinus Walleij #define AB3100_STR_ONSWC				(0x04)
74812f9e9dSLinus Walleij #define AB3100_STR_DCIO					(0x08)
75812f9e9dSLinus Walleij #define AB3100_STR_BOOT_MODE				(0x10)
76812f9e9dSLinus Walleij #define AB3100_STR_SIM_OFF				(0x20)
77812f9e9dSLinus Walleij #define AB3100_STR_BATT_REMOVAL				(0x40)
78812f9e9dSLinus Walleij #define AB3100_STR_VBUS					(0x80)
79812f9e9dSLinus Walleij 
80812f9e9dSLinus Walleij /*
81812f9e9dSLinus Walleij  * AB3100 contains 8 regulators, one external regulator controller
82812f9e9dSLinus Walleij  * and a buck converter, further the LDO E and buck converter can
83812f9e9dSLinus Walleij  * have separate settings if they are in sleep mode, this is
84812f9e9dSLinus Walleij  * modeled as a separate regulator.
85812f9e9dSLinus Walleij  */
86812f9e9dSLinus Walleij #define AB3100_NUM_REGULATORS				10
87812f9e9dSLinus Walleij 
88812f9e9dSLinus Walleij /**
89812f9e9dSLinus Walleij  * struct ab3100
90812f9e9dSLinus Walleij  * @access_mutex: lock out concurrent accesses to the AB3100 registers
91812f9e9dSLinus Walleij  * @dev: pointer to the containing device
92812f9e9dSLinus Walleij  * @i2c_client: I2C client for this chip
93812f9e9dSLinus Walleij  * @testreg_client: secondary client for test registers
94812f9e9dSLinus Walleij  * @chip_name: name of this chip variant
95812f9e9dSLinus Walleij  * @chip_id: 8 bit chip ID for this chip variant
96812f9e9dSLinus Walleij  * @event_subscribers: event subscribers are listed here
97812f9e9dSLinus Walleij  * @startup_events: a copy of the first reading of the event registers
98812f9e9dSLinus Walleij  * @startup_events_read: whether the first events have been read
99812f9e9dSLinus Walleij  *
100812f9e9dSLinus Walleij  * This struct is PRIVATE and devices using it should NOT
101812f9e9dSLinus Walleij  * access ANY fields. It is used as a token for calling the
102812f9e9dSLinus Walleij  * AB3100 functions.
103812f9e9dSLinus Walleij  */
104812f9e9dSLinus Walleij struct ab3100 {
105812f9e9dSLinus Walleij 	struct mutex access_mutex;
106812f9e9dSLinus Walleij 	struct device *dev;
107812f9e9dSLinus Walleij 	struct i2c_client *i2c_client;
108812f9e9dSLinus Walleij 	struct i2c_client *testreg_client;
109812f9e9dSLinus Walleij 	char chip_name[32];
110812f9e9dSLinus Walleij 	u8 chip_id;
111812f9e9dSLinus Walleij 	struct blocking_notifier_head event_subscribers;
112fa661258SMattias Wallin 	u8 startup_events[3];
113812f9e9dSLinus Walleij 	bool startup_events_read;
114812f9e9dSLinus Walleij };
115812f9e9dSLinus Walleij 
116812f9e9dSLinus Walleij /**
117812f9e9dSLinus Walleij  * struct ab3100_platform_data
118812f9e9dSLinus Walleij  * Data supplied to initialize board connections to the AB3100
119812f9e9dSLinus Walleij  * @reg_constraints: regulator constraints for target board
120812f9e9dSLinus Walleij  *     the order of these constraints are: LDO A, C, D, E,
121812f9e9dSLinus Walleij  *     F, G, H, K, EXT and BUCK.
122812f9e9dSLinus Walleij  * @reg_initvals: initial values for the regulator registers
123812f9e9dSLinus Walleij  *     plus two sleep settings for LDO E and the BUCK converter.
124812f9e9dSLinus Walleij  *     exactly AB3100_NUM_REGULATORS+2 values must be sent in.
125812f9e9dSLinus Walleij  *     Order: LDO A, C, E, E sleep, F, G, H, K, EXT, BUCK,
126812f9e9dSLinus Walleij  *     BUCK sleep, LDO D. (LDO D need to be initialized last.)
127812f9e9dSLinus Walleij  * @external_voltage: voltage level of the external regulator.
128812f9e9dSLinus Walleij  */
129812f9e9dSLinus Walleij struct ab3100_platform_data {
130812f9e9dSLinus Walleij 	struct regulator_init_data reg_constraints[AB3100_NUM_REGULATORS];
131812f9e9dSLinus Walleij 	u8 reg_initvals[AB3100_NUM_REGULATORS+2];
132812f9e9dSLinus Walleij 	int external_voltage;
133812f9e9dSLinus Walleij };
134812f9e9dSLinus Walleij 
135812f9e9dSLinus Walleij int ab3100_event_register(struct ab3100 *ab3100,
136812f9e9dSLinus Walleij 			  struct notifier_block *nb);
137812f9e9dSLinus Walleij int ab3100_event_unregister(struct ab3100 *ab3100,
138812f9e9dSLinus Walleij 			    struct notifier_block *nb);
139812f9e9dSLinus Walleij 
140fa661258SMattias Wallin /* AB3550, STR register flags */
141fa661258SMattias Wallin #define AB3550_STR_ONSWA				(0x01)
142fa661258SMattias Wallin #define AB3550_STR_ONSWB				(0x02)
143fa661258SMattias Wallin #define AB3550_STR_ONSWC				(0x04)
144fa661258SMattias Wallin #define AB3550_STR_DCIO					(0x08)
145fa661258SMattias Wallin #define AB3550_STR_BOOT_MODE				(0x10)
146fa661258SMattias Wallin #define AB3550_STR_SIM_OFF				(0x20)
147fa661258SMattias Wallin #define AB3550_STR_BATT_REMOVAL				(0x40)
148fa661258SMattias Wallin #define AB3550_STR_VBUS					(0x80)
149fa661258SMattias Wallin 
150fa661258SMattias Wallin /* Interrupt mask registers */
151fa661258SMattias Wallin #define AB3550_IMR1 0x29
152fa661258SMattias Wallin #define AB3550_IMR2 0x2a
153fa661258SMattias Wallin #define AB3550_IMR3 0x2b
154fa661258SMattias Wallin #define AB3550_IMR4 0x2c
155fa661258SMattias Wallin #define AB3550_IMR5 0x2d
156fa661258SMattias Wallin 
157fa661258SMattias Wallin enum ab3550_devid {
158fa661258SMattias Wallin 	AB3550_DEVID_ADC,
159fa661258SMattias Wallin 	AB3550_DEVID_DAC,
160fa661258SMattias Wallin 	AB3550_DEVID_LEDS,
161fa661258SMattias Wallin 	AB3550_DEVID_POWER,
162fa661258SMattias Wallin 	AB3550_DEVID_REGULATORS,
163fa661258SMattias Wallin 	AB3550_DEVID_SIM,
164fa661258SMattias Wallin 	AB3550_DEVID_UART,
165fa661258SMattias Wallin 	AB3550_DEVID_RTC,
166fa661258SMattias Wallin 	AB3550_DEVID_CHARGER,
167fa661258SMattias Wallin 	AB3550_DEVID_FUELGAUGE,
168fa661258SMattias Wallin 	AB3550_DEVID_VIBRATOR,
169fa661258SMattias Wallin 	AB3550_DEVID_CODEC,
170fa661258SMattias Wallin 	AB3550_NUM_DEVICES,
171fa661258SMattias Wallin };
172fa661258SMattias Wallin 
173fa661258SMattias Wallin /**
174fa661258SMattias Wallin  * struct abx500_init_setting
175fa661258SMattias Wallin  * Initial value of the registers for driver to use during setup.
176fa661258SMattias Wallin  */
177fa661258SMattias Wallin struct abx500_init_settings {
178fa661258SMattias Wallin 	u8 bank;
179fa661258SMattias Wallin 	u8 reg;
180fa661258SMattias Wallin 	u8 setting;
181fa661258SMattias Wallin };
182fa661258SMattias Wallin 
183fa661258SMattias Wallin /**
184fa661258SMattias Wallin  * struct ab3550_platform_data
185fa661258SMattias Wallin  * Data supplied to initialize board connections to the AB3550
186fa661258SMattias Wallin  */
187fa661258SMattias Wallin struct ab3550_platform_data {
188fa661258SMattias Wallin 	struct {unsigned int base; unsigned int count; } irq;
189fa661258SMattias Wallin 	void *dev_data[AB3550_NUM_DEVICES];
190fa661258SMattias Wallin 	size_t dev_data_sz[AB3550_NUM_DEVICES];
191fa661258SMattias Wallin 	struct abx500_init_settings *init_settings;
192fa661258SMattias Wallin 	unsigned int init_settings_sz;
193fa661258SMattias Wallin };
194fa661258SMattias Wallin 
195fa661258SMattias Wallin int abx500_set_register_interruptible(struct device *dev, u8 bank, u8 reg,
196fa661258SMattias Wallin 	u8 value);
197fa661258SMattias Wallin int abx500_get_register_interruptible(struct device *dev, u8 bank, u8 reg,
198fa661258SMattias Wallin 	u8 *value);
199fa661258SMattias Wallin int abx500_get_register_page_interruptible(struct device *dev, u8 bank,
200fa661258SMattias Wallin 	u8 first_reg, u8 *regvals, u8 numregs);
201fa661258SMattias Wallin int abx500_set_register_page_interruptible(struct device *dev, u8 bank,
202fa661258SMattias Wallin 	u8 first_reg, u8 *regvals, u8 numregs);
203fa661258SMattias Wallin /**
204fa661258SMattias Wallin  * abx500_mask_and_set_register_inerruptible() - Modifies selected bits of a
205fa661258SMattias Wallin  *	target register
206fa661258SMattias Wallin  *
207fa661258SMattias Wallin  * @dev: The AB sub device.
208fa661258SMattias Wallin  * @bank: The i2c bank number.
209fa661258SMattias Wallin  * @bitmask: The bit mask to use.
210fa661258SMattias Wallin  * @bitvalues: The new bit values.
211fa661258SMattias Wallin  *
212fa661258SMattias Wallin  * Updates the value of an AB register:
213fa661258SMattias Wallin  * value -> ((value & ~bitmask) | (bitvalues & bitmask))
214fa661258SMattias Wallin  */
215fa661258SMattias Wallin int abx500_mask_and_set_register_interruptible(struct device *dev, u8 bank,
216fa661258SMattias Wallin 	u8 reg, u8 bitmask, u8 bitvalues);
217fa661258SMattias Wallin int abx500_get_chip_id(struct device *dev);
218fa661258SMattias Wallin int abx500_event_registers_startup_state_get(struct device *dev, u8 *event);
219fa661258SMattias Wallin int abx500_startup_irq_enabled(struct device *dev, unsigned int irq);
220fa661258SMattias Wallin 
221fa661258SMattias Wallin struct abx500_ops {
222fa661258SMattias Wallin 	int (*get_chip_id) (struct device *);
223fa661258SMattias Wallin 	int (*get_register) (struct device *, u8, u8, u8 *);
224fa661258SMattias Wallin 	int (*set_register) (struct device *, u8, u8, u8);
225fa661258SMattias Wallin 	int (*get_register_page) (struct device *, u8, u8, u8 *, u8);
226fa661258SMattias Wallin 	int (*set_register_page) (struct device *, u8, u8, u8 *, u8);
227fa661258SMattias Wallin 	int (*mask_and_set_register) (struct device *, u8, u8, u8, u8);
228fa661258SMattias Wallin 	int (*event_registers_startup_state_get) (struct device *, u8 *);
229fa661258SMattias Wallin 	int (*startup_irq_enabled) (struct device *, unsigned int);
230fa661258SMattias Wallin };
231fa661258SMattias Wallin 
232fa661258SMattias Wallin int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
233812f9e9dSLinus Walleij #endif
234