blob: 4b2df29fb858b7c70c4bd6d484ccae168cfc2469 [file] [log] [blame]
Rabin Vincent62579262010-05-19 11:39:02 +02001/*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * License Terms: GNU General Public License v2
5 * Author: Srinidhi Kasagar <srinidhi.kasagar@stericsson.com>
6 */
7#ifndef MFD_AB8500_H
8#define MFD_AB8500_H
9
10#include <linux/device.h>
Linus Walleij0f6208372012-02-20 21:42:10 +010011/*
12 * AB IC versions
13 *
14 * AB8500_VERSION_AB8500 should be 0xFF but will never be read as need a
15 * non-supported multi-byte I2C access via PRCMU. Set to 0x00 to ease the
16 * print of version string.
17 */
18enum ab8500_version {
19 AB8500_VERSION_AB8500 = 0x0,
20 AB8500_VERSION_AB8505 = 0x1,
21 AB8500_VERSION_AB9540 = 0x2,
22 AB8500_VERSION_AB8540 = 0x3,
23 AB8500_VERSION_UNDEFINED,
24};
25
26/* AB8500 CIDs*/
27#define AB8500_CUTEARLY 0x00
28#define AB8500_CUT1P0 0x10
29#define AB8500_CUT1P1 0x11
30#define AB8500_CUT2P0 0x20
31#define AB8500_CUT3P0 0x30
32#define AB8500_CUT3P3 0x33
Rabin Vincent62579262010-05-19 11:39:02 +020033
34/*
Mattias Wallin47c16972010-09-10 17:47:56 +020035 * AB8500 bank addresses
36 */
37#define AB8500_SYS_CTRL1_BLOCK 0x1
38#define AB8500_SYS_CTRL2_BLOCK 0x2
39#define AB8500_REGU_CTRL1 0x3
40#define AB8500_REGU_CTRL2 0x4
41#define AB8500_USB 0x5
42#define AB8500_TVOUT 0x6
43#define AB8500_DBI 0x7
44#define AB8500_ECI_AV_ACC 0x8
45#define AB8500_RESERVED 0x9
46#define AB8500_GPADC 0xA
47#define AB8500_CHARGER 0xB
48#define AB8500_GAS_GAUGE 0xC
49#define AB8500_AUDIO 0xD
50#define AB8500_INTERRUPT 0xE
51#define AB8500_RTC 0xF
52#define AB8500_MISC 0x10
Linus Walleij0a1b0892011-06-09 23:57:57 +020053#define AB8500_DEVELOPMENT 0x11
Mattias Wallin47c16972010-09-10 17:47:56 +020054#define AB8500_DEBUG 0x12
55#define AB8500_PROD_TEST 0x13
56#define AB8500_OTP_EMUL 0x15
57
58/*
Rabin Vincent62579262010-05-19 11:39:02 +020059 * Interrupts
Linus Walleijd6255522012-02-20 21:42:24 +010060 * Values used to index into array ab8500_irq_regoffset[] defined in
61 * drivers/mdf/ab8500-core.c
Rabin Vincent62579262010-05-19 11:39:02 +020062 */
Linus Walleijd6255522012-02-20 21:42:24 +010063/* Definitions for AB8500 and AB9540 */
64/* ab8500_irq_regoffset[0] -> IT[Source|Latch|Mask]1 */
Rabin Vincent62579262010-05-19 11:39:02 +020065#define AB8500_INT_MAIN_EXT_CH_NOT_OK 0
66#define AB8500_INT_UN_PLUG_TV_DET 1
67#define AB8500_INT_PLUG_TV_DET 2
68#define AB8500_INT_TEMP_WARM 3
69#define AB8500_INT_PON_KEY2DB_F 4
70#define AB8500_INT_PON_KEY2DB_R 5
71#define AB8500_INT_PON_KEY1DB_F 6
72#define AB8500_INT_PON_KEY1DB_R 7
Linus Walleijd6255522012-02-20 21:42:24 +010073/* ab8500_irq_regoffset[1] -> IT[Source|Latch|Mask]2 */
Rabin Vincent62579262010-05-19 11:39:02 +020074#define AB8500_INT_BATT_OVV 8
75#define AB8500_INT_MAIN_CH_UNPLUG_DET 10
76#define AB8500_INT_MAIN_CH_PLUG_DET 11
77#define AB8500_INT_USB_ID_DET_F 12
78#define AB8500_INT_USB_ID_DET_R 13
79#define AB8500_INT_VBUS_DET_F 14
80#define AB8500_INT_VBUS_DET_R 15
Linus Walleijd6255522012-02-20 21:42:24 +010081/* ab8500_irq_regoffset[2] -> IT[Source|Latch|Mask]3 */
Rabin Vincent62579262010-05-19 11:39:02 +020082#define AB8500_INT_VBUS_CH_DROP_END 16
83#define AB8500_INT_RTC_60S 17
84#define AB8500_INT_RTC_ALARM 18
85#define AB8500_INT_BAT_CTRL_INDB 20
86#define AB8500_INT_CH_WD_EXP 21
87#define AB8500_INT_VBUS_OVV 22
88#define AB8500_INT_MAIN_CH_DROP_END 23
Linus Walleijd6255522012-02-20 21:42:24 +010089/* ab8500_irq_regoffset[3] -> IT[Source|Latch|Mask]4 */
Rabin Vincent62579262010-05-19 11:39:02 +020090#define AB8500_INT_CCN_CONV_ACC 24
91#define AB8500_INT_INT_AUD 25
92#define AB8500_INT_CCEOC 26
93#define AB8500_INT_CC_INT_CALIB 27
94#define AB8500_INT_LOW_BAT_F 28
95#define AB8500_INT_LOW_BAT_R 29
96#define AB8500_INT_BUP_CHG_NOT_OK 30
97#define AB8500_INT_BUP_CHG_OK 31
Linus Walleijd6255522012-02-20 21:42:24 +010098/* ab8500_irq_regoffset[4] -> IT[Source|Latch|Mask]5 */
Rabin Vincent62579262010-05-19 11:39:02 +020099#define AB8500_INT_GP_HW_ADC_CONV_END 32
100#define AB8500_INT_ACC_DETECT_1DB_F 33
101#define AB8500_INT_ACC_DETECT_1DB_R 34
102#define AB8500_INT_ACC_DETECT_22DB_F 35
103#define AB8500_INT_ACC_DETECT_22DB_R 36
104#define AB8500_INT_ACC_DETECT_21DB_F 37
105#define AB8500_INT_ACC_DETECT_21DB_R 38
106#define AB8500_INT_GP_SW_ADC_CONV_END 39
Linus Walleijd6255522012-02-20 21:42:24 +0100107/* ab8500_irq_regoffset[5] -> IT[Source|Latch|Mask]7 */
Bibek Basu0cb3fcd2011-02-09 11:02:35 +0530108#define AB8500_INT_GPIO6R 40
109#define AB8500_INT_GPIO7R 41
110#define AB8500_INT_GPIO8R 42
111#define AB8500_INT_GPIO9R 43
112#define AB8500_INT_GPIO10R 44
113#define AB8500_INT_GPIO11R 45
114#define AB8500_INT_GPIO12R 46
115#define AB8500_INT_GPIO13R 47
Linus Walleijd6255522012-02-20 21:42:24 +0100116/* ab8500_irq_regoffset[6] -> IT[Source|Latch|Mask]8 */
Bibek Basu0cb3fcd2011-02-09 11:02:35 +0530117#define AB8500_INT_GPIO24R 48
118#define AB8500_INT_GPIO25R 49
119#define AB8500_INT_GPIO36R 50
120#define AB8500_INT_GPIO37R 51
121#define AB8500_INT_GPIO38R 52
122#define AB8500_INT_GPIO39R 53
123#define AB8500_INT_GPIO40R 54
124#define AB8500_INT_GPIO41R 55
Linus Walleijd6255522012-02-20 21:42:24 +0100125/* ab8500_irq_regoffset[7] -> IT[Source|Latch|Mask]9 */
Bibek Basu0cb3fcd2011-02-09 11:02:35 +0530126#define AB8500_INT_GPIO6F 56
127#define AB8500_INT_GPIO7F 57
128#define AB8500_INT_GPIO8F 58
129#define AB8500_INT_GPIO9F 59
130#define AB8500_INT_GPIO10F 60
131#define AB8500_INT_GPIO11F 61
132#define AB8500_INT_GPIO12F 62
133#define AB8500_INT_GPIO13F 63
Linus Walleijd6255522012-02-20 21:42:24 +0100134/* ab8500_irq_regoffset[8] -> IT[Source|Latch|Mask]10 */
Bibek Basu0cb3fcd2011-02-09 11:02:35 +0530135#define AB8500_INT_GPIO24F 64
136#define AB8500_INT_GPIO25F 65
137#define AB8500_INT_GPIO36F 66
138#define AB8500_INT_GPIO37F 67
139#define AB8500_INT_GPIO38F 68
140#define AB8500_INT_GPIO39F 69
141#define AB8500_INT_GPIO40F 70
142#define AB8500_INT_GPIO41F 71
Linus Walleijd6255522012-02-20 21:42:24 +0100143/* ab8500_irq_regoffset[9] -> IT[Source|Latch|Mask]12 */
Mattias Wallin92d50a42010-12-07 11:20:47 +0100144#define AB8500_INT_ADP_SOURCE_ERROR 72
145#define AB8500_INT_ADP_SINK_ERROR 73
146#define AB8500_INT_ADP_PROBE_PLUG 74
147#define AB8500_INT_ADP_PROBE_UNPLUG 75
148#define AB8500_INT_ADP_SENSE_OFF 76
149#define AB8500_INT_USB_PHY_POWER_ERR 78
150#define AB8500_INT_USB_LINK_STATUS 79
Linus Walleijd6255522012-02-20 21:42:24 +0100151/* ab8500_irq_regoffset[10] -> IT[Source|Latch|Mask]19 */
Mattias Wallin92d50a42010-12-07 11:20:47 +0100152#define AB8500_INT_BTEMP_LOW 80
153#define AB8500_INT_BTEMP_LOW_MEDIUM 81
154#define AB8500_INT_BTEMP_MEDIUM_HIGH 82
155#define AB8500_INT_BTEMP_HIGH 83
Linus Walleijd6255522012-02-20 21:42:24 +0100156/* ab8500_irq_regoffset[11] -> IT[Source|Latch|Mask]20 */
Mattias Wallin92d50a42010-12-07 11:20:47 +0100157#define AB8500_INT_USB_CHARGER_NOT_OK 89
158#define AB8500_INT_ID_WAKEUP_R 90
159#define AB8500_INT_ID_DET_R1R 92
160#define AB8500_INT_ID_DET_R2R 93
161#define AB8500_INT_ID_DET_R3R 94
162#define AB8500_INT_ID_DET_R4R 95
Linus Walleijd6255522012-02-20 21:42:24 +0100163/* ab8500_irq_regoffset[12] -> IT[Source|Latch|Mask]21 */
Mattias Wallin92d50a42010-12-07 11:20:47 +0100164#define AB8500_INT_ID_WAKEUP_F 96
165#define AB8500_INT_ID_DET_R1F 98
166#define AB8500_INT_ID_DET_R2F 99
167#define AB8500_INT_ID_DET_R3F 100
168#define AB8500_INT_ID_DET_R4F 101
169#define AB8500_INT_USB_CHG_DET_DONE 102
Linus Walleijd6255522012-02-20 21:42:24 +0100170/* ab8500_irq_regoffset[13] -> IT[Source|Latch|Mask]22 */
Mattias Wallin92d50a42010-12-07 11:20:47 +0100171#define AB8500_INT_USB_CH_TH_PROT_F 104
172#define AB8500_INT_USB_CH_TH_PROT_R 105
173#define AB8500_INT_MAIN_CH_TH_PROT_F 106
174#define AB8500_INT_MAIN_CH_TH_PROT_R 107
175#define AB8500_INT_USB_CHARGER_NOT_OKF 111
Rabin Vincent62579262010-05-19 11:39:02 +0200176
Linus Walleijd6255522012-02-20 21:42:24 +0100177/* Definitions for AB9540 */
178/* ab8500_irq_regoffset[14] -> IT[Source|Latch|Mask]13 */
179#define AB9540_INT_GPIO50R 113
180#define AB9540_INT_GPIO51R 114
181#define AB9540_INT_GPIO52R 115
182#define AB9540_INT_GPIO53R 116
183#define AB9540_INT_GPIO54R 117
184#define AB9540_INT_IEXT_CH_RF_BFN_R 118
185#define AB9540_INT_IEXT_CH_RF_BFN_F 119
186/* ab8500_irq_regoffset[15] -> IT[Source|Latch|Mask]14 */
187#define AB9540_INT_GPIO50F 121
188#define AB9540_INT_GPIO51F 122
189#define AB9540_INT_GPIO52F 123
190#define AB9540_INT_GPIO53F 124
191#define AB9540_INT_GPIO54F 125
192
193/*
194 * AB8500_AB9540_NR_IRQS is used when configuring the IRQ numbers for the
195 * entire platform. This is a "compile time" constant so this must be set to
196 * the largest possible value that may be encountered with different AB SOCs.
197 * Of the currently supported AB devices, AB8500 and AB9540, it is the AB9540
198 * which is larger.
199 */
Mattias Wallin92d50a42010-12-07 11:20:47 +0100200#define AB8500_NR_IRQS 112
Linus Walleijd6255522012-02-20 21:42:24 +0100201#define AB9540_NR_IRQS 128
202/* This is set to the roof of any AB8500 chip variant IRQ counts */
203#define AB8500_MAX_NR_IRQS AB9540_NR_IRQS
204
Mattias Wallin92d50a42010-12-07 11:20:47 +0100205#define AB8500_NUM_IRQ_REGS 14
Linus Walleijd6255522012-02-20 21:42:24 +0100206#define AB9540_NUM_IRQ_REGS 17
Rabin Vincent62579262010-05-19 11:39:02 +0200207
208/**
209 * struct ab8500 - ab8500 internal structure
210 * @dev: parent device
211 * @lock: read/write operations lock
212 * @irq_lock: genirq bus lock
Rabin Vincent62579262010-05-19 11:39:02 +0200213 * @irq: irq line
Linus Walleij0f6208372012-02-20 21:42:10 +0100214 * @version: chip version id (e.g. ab8500 or ab9540)
Mattias Wallinadceed62011-03-02 11:51:11 +0100215 * @chip_id: chip revision id
Rabin Vincent62579262010-05-19 11:39:02 +0200216 * @write: register write
217 * @read: register read
218 * @rx_buf: rx buf for SPI
219 * @tx_buf: tx buf for SPI
220 * @mask: cache of IRQ regs for bus lock
221 * @oldmask: cache of previous IRQ regs for bus lock
Linus Walleij2ced4452012-02-20 21:42:17 +0100222 * @mask_size: Actual number of valid entries in mask[], oldmask[] and
223 * irq_reg_offset
224 * @irq_reg_offset: Array of offsets into IRQ registers
Rabin Vincent62579262010-05-19 11:39:02 +0200225 */
226struct ab8500 {
227 struct device *dev;
228 struct mutex lock;
229 struct mutex irq_lock;
Mattias Wallinadceed62011-03-02 11:51:11 +0100230
Rabin Vincent62579262010-05-19 11:39:02 +0200231 int irq_base;
232 int irq;
Linus Walleij0f6208372012-02-20 21:42:10 +0100233 enum ab8500_version version;
Mattias Wallin47c16972010-09-10 17:47:56 +0200234 u8 chip_id;
Rabin Vincent62579262010-05-19 11:39:02 +0200235
236 int (*write) (struct ab8500 *a8500, u16 addr, u8 data);
237 int (*read) (struct ab8500 *a8500, u16 addr);
238
239 unsigned long tx_buf[4];
240 unsigned long rx_buf[4];
241
Linus Walleij2ced4452012-02-20 21:42:17 +0100242 u8 *mask;
243 u8 *oldmask;
244 int mask_size;
245 const int *irq_reg_offset;
Rabin Vincent62579262010-05-19 11:39:02 +0200246};
247
Bengt Jonsson79568b92011-03-11 11:54:46 +0100248struct regulator_reg_init;
Sundar R Iyer549931f2010-07-13 11:51:28 +0530249struct regulator_init_data;
Bibek Basu0cb3fcd2011-02-09 11:02:35 +0530250struct ab8500_gpio_platform_data;
Sundar R Iyer549931f2010-07-13 11:51:28 +0530251
Rabin Vincent62579262010-05-19 11:39:02 +0200252/**
253 * struct ab8500_platform_data - AB8500 platform data
254 * @irq_base: start of AB8500 IRQs, AB8500_NR_IRQS will be used
255 * @init: board-specific initialization after detection of ab8500
Bengt Jonsson79568b92011-03-11 11:54:46 +0100256 * @num_regulator_reg_init: number of regulator init registers
257 * @regulator_reg_init: regulator init registers
258 * @num_regulator: number of regulators
Sundar R Iyer549931f2010-07-13 11:51:28 +0530259 * @regulator: machine-specific constraints for regulators
Rabin Vincent62579262010-05-19 11:39:02 +0200260 */
261struct ab8500_platform_data {
262 int irq_base;
263 void (*init) (struct ab8500 *);
Bengt Jonsson79568b92011-03-11 11:54:46 +0100264 int num_regulator_reg_init;
265 struct ab8500_regulator_reg_init *regulator_reg_init;
Bengt Jonssoncb189b02010-12-10 11:08:40 +0100266 int num_regulator;
267 struct regulator_init_data *regulator;
Bibek Basu0cb3fcd2011-02-09 11:02:35 +0530268 struct ab8500_gpio_platform_data *gpio;
Rabin Vincent62579262010-05-19 11:39:02 +0200269};
270
Linus Walleij0f6208372012-02-20 21:42:10 +0100271extern int __devinit ab8500_init(struct ab8500 *ab8500,
272 enum ab8500_version version);
Rabin Vincent62579262010-05-19 11:39:02 +0200273extern int __devexit ab8500_exit(struct ab8500 *ab8500);
274
Linus Walleij0f6208372012-02-20 21:42:10 +0100275static inline int is_ab8500(struct ab8500 *ab)
276{
277 return ab->version == AB8500_VERSION_AB8500;
278}
279
280static inline int is_ab8505(struct ab8500 *ab)
281{
282 return ab->version == AB8500_VERSION_AB8505;
283}
284
285static inline int is_ab9540(struct ab8500 *ab)
286{
287 return ab->version == AB8500_VERSION_AB9540;
288}
289
290static inline int is_ab8540(struct ab8500 *ab)
291{
292 return ab->version == AB8500_VERSION_AB8540;
293}
294
295/* include also ab8505, ab9540... */
296static inline int is_ab8500_1p1_or_earlier(struct ab8500 *ab)
297{
298 return (is_ab8500(ab) && (ab->chip_id <= AB8500_CUT1P1));
299}
300
301/* include also ab8505, ab9540... */
302static inline int is_ab8500_2p0_or_earlier(struct ab8500 *ab)
303{
304 return (is_ab8500(ab) && (ab->chip_id <= AB8500_CUT2P0));
305}
306
Rabin Vincent62579262010-05-19 11:39:02 +0200307#endif /* MFD_AB8500_H */