blob: f39a19f94201e685143ad2be122538a3aea80bbf [file] [log] [blame]
Abhijeet Dharmapurikarcbdb53e2011-04-05 14:40:52 -07001/*
Willie Ruan51060352012-01-19 16:58:49 -08002 * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
Abhijeet Dharmapurikarcbdb53e2011-04-05 14:40:52 -07003 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14#define pr_fmt(fmt) "%s: " fmt, __func__
15
16#include <linux/kernel.h>
Steve Mucklef132c6c2012-06-06 18:30:57 -070017#include <linux/module.h>
Abhijeet Dharmapurikarcbdb53e2011-04-05 14:40:52 -070018#include <linux/platform_device.h>
19#include <linux/slab.h>
David Collins75016742011-12-02 15:04:25 -080020#include <linux/string.h>
Abhijeet Dharmapurikarc013f0a2011-04-05 14:40:53 -070021#include <linux/err.h>
Abhijeet Dharmapurikarcbdb53e2011-04-05 14:40:52 -070022#include <linux/msm_ssbi.h>
23#include <linux/mfd/core.h>
24#include <linux/mfd/pm8xxx/pm8921.h>
25#include <linux/mfd/pm8xxx/core.h>
David Collins75016742011-12-02 15:04:25 -080026#include <linux/mfd/pm8xxx/regulator.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070027#include <linux/leds-pm8xxx.h>
Abhijeet Dharmapurikarcbdb53e2011-04-05 14:40:52 -070028
29#define REG_HWREV 0x002 /* PMIC4 revision */
30#define REG_HWREV_2 0x0E8 /* PMIC4 revision 2 */
31
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070032#define REG_MPP_BASE 0x050
Anirudh Ghayalca42c7de2011-11-21 10:42:07 +053033#define REG_IRQ_BASE 0x1BB
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070034
35#define REG_TEMP_ALARM_CTRL 0x1B
36#define REG_TEMP_ALARM_PWM 0x9B
37
38#define REG_BATT_ALARM_THRESH 0x023
39#define REG_BATT_ALARM_CTRL1 0x024
David Collinsa2f1e622011-08-17 09:03:27 -070040#define REG_BATT_ALARM_CTRL2 0x021
41#define REG_BATT_ALARM_PWM_CTRL 0x020
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070042
43#define PM8921_VERSION_MASK 0xFFF0
44#define PM8921_VERSION_VALUE 0x06F0
David Collins999480d2011-11-16 08:52:30 -080045#define PM8922_VERSION_VALUE 0x0AF0
David Collins2da4f9b2012-02-14 11:34:11 -080046#define PM8917_VERSION_VALUE 0x0CF0
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070047#define PM8921_REVISION_MASK 0x000F
48
Abhijeet Dharmapurikar5caa02c2011-08-15 20:11:28 -070049#define REG_PM8921_PON_CNTRL_3 0x01D
50#define PM8921_RESTART_REASON_MASK 0x07
51
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070052#define SINGLE_IRQ_RESOURCE(_name, _irq) \
53{ \
54 .name = _name, \
55 .start = _irq, \
56 .end = _irq, \
57 .flags = IORESOURCE_IRQ, \
58}
59
Abhijeet Dharmapurikarcbdb53e2011-04-05 14:40:52 -070060struct pm8921 {
David Collins75016742011-12-02 15:04:25 -080061 struct device *dev;
62 struct pm_irq_chip *irq_chip;
63 struct mfd_cell *mfd_regulators;
64 struct pm8xxx_regulator_core_platform_data *regulator_cdata;
65 u32 rev_registers;
Abhijeet Dharmapurikarcbdb53e2011-04-05 14:40:52 -070066};
67
68static int pm8921_readb(const struct device *dev, u16 addr, u8 *val)
69{
70 const struct pm8xxx_drvdata *pm8921_drvdata = dev_get_drvdata(dev);
71 const struct pm8921 *pmic = pm8921_drvdata->pm_chip_data;
72
73 return msm_ssbi_read(pmic->dev->parent, addr, val, 1);
74}
75
76static int pm8921_writeb(const struct device *dev, u16 addr, u8 val)
77{
78 const struct pm8xxx_drvdata *pm8921_drvdata = dev_get_drvdata(dev);
79 const struct pm8921 *pmic = pm8921_drvdata->pm_chip_data;
80
81 return msm_ssbi_write(pmic->dev->parent, addr, &val, 1);
82}
83
84static int pm8921_read_buf(const struct device *dev, u16 addr, u8 *buf,
85 int cnt)
86{
87 const struct pm8xxx_drvdata *pm8921_drvdata = dev_get_drvdata(dev);
88 const struct pm8921 *pmic = pm8921_drvdata->pm_chip_data;
89
90 return msm_ssbi_read(pmic->dev->parent, addr, buf, cnt);
91}
92
93static int pm8921_write_buf(const struct device *dev, u16 addr, u8 *buf,
94 int cnt)
95{
96 const struct pm8xxx_drvdata *pm8921_drvdata = dev_get_drvdata(dev);
97 const struct pm8921 *pmic = pm8921_drvdata->pm_chip_data;
98
99 return msm_ssbi_write(pmic->dev->parent, addr, buf, cnt);
100}
101
Abhijeet Dharmapurikarc013f0a2011-04-05 14:40:53 -0700102static int pm8921_read_irq_stat(const struct device *dev, int irq)
103{
104 const struct pm8xxx_drvdata *pm8921_drvdata = dev_get_drvdata(dev);
105 const struct pm8921 *pmic = pm8921_drvdata->pm_chip_data;
106
107 return pm8xxx_get_irq_stat(pmic->irq_chip, irq);
108}
109
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700110static enum pm8xxx_version pm8921_get_version(const struct device *dev)
111{
112 const struct pm8xxx_drvdata *pm8921_drvdata = dev_get_drvdata(dev);
113 const struct pm8921 *pmic = pm8921_drvdata->pm_chip_data;
114 enum pm8xxx_version version = -ENODEV;
115
116 if ((pmic->rev_registers & PM8921_VERSION_MASK) == PM8921_VERSION_VALUE)
117 version = PM8XXX_VERSION_8921;
David Collins999480d2011-11-16 08:52:30 -0800118 else if ((pmic->rev_registers & PM8921_VERSION_MASK)
119 == PM8922_VERSION_VALUE)
120 version = PM8XXX_VERSION_8922;
Willie Ruan51060352012-01-19 16:58:49 -0800121 else if ((pmic->rev_registers & PM8921_VERSION_MASK)
122 == PM8917_VERSION_VALUE)
123 version = PM8XXX_VERSION_8917;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700124
125 return version;
126}
127
128static int pm8921_get_revision(const struct device *dev)
129{
130 const struct pm8xxx_drvdata *pm8921_drvdata = dev_get_drvdata(dev);
131 const struct pm8921 *pmic = pm8921_drvdata->pm_chip_data;
132
133 return pmic->rev_registers & PM8921_REVISION_MASK;
134}
135
Abhijeet Dharmapurikarcbdb53e2011-04-05 14:40:52 -0700136static struct pm8xxx_drvdata pm8921_drvdata = {
137 .pmic_readb = pm8921_readb,
138 .pmic_writeb = pm8921_writeb,
139 .pmic_read_buf = pm8921_read_buf,
140 .pmic_write_buf = pm8921_write_buf,
Abhijeet Dharmapurikarc013f0a2011-04-05 14:40:53 -0700141 .pmic_read_irq_stat = pm8921_read_irq_stat,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700142 .pmic_get_version = pm8921_get_version,
143 .pmic_get_revision = pm8921_get_revision,
Abhijeet Dharmapurikarcbdb53e2011-04-05 14:40:52 -0700144};
145
Willie Ruan51060352012-01-19 16:58:49 -0800146static struct resource gpio_cell_resources[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700147 [0] = {
148 .start = PM8921_IRQ_BLOCK_BIT(PM8921_GPIO_BLOCK_START, 0),
149 .end = PM8921_IRQ_BLOCK_BIT(PM8921_GPIO_BLOCK_START, 0)
150 + PM8921_NR_GPIOS - 1,
151 .flags = IORESOURCE_IRQ,
152 },
153};
154
155static struct mfd_cell gpio_cell __devinitdata = {
156 .name = PM8XXX_GPIO_DEV_NAME,
157 .id = -1,
158 .resources = gpio_cell_resources,
159 .num_resources = ARRAY_SIZE(gpio_cell_resources),
160};
161
162static const struct resource adc_cell_resources[] __devinitconst = {
163 SINGLE_IRQ_RESOURCE(NULL, PM8921_ADC_EOC_USR_IRQ),
164 SINGLE_IRQ_RESOURCE(NULL, PM8921_ADC_BATT_TEMP_WARM_IRQ),
165 SINGLE_IRQ_RESOURCE(NULL, PM8921_ADC_BATT_TEMP_COLD_IRQ),
166};
167
168static struct mfd_cell adc_cell __devinitdata = {
Siddartha Mohanadossaf91d902011-10-20 10:23:34 -0700169 .name = PM8XXX_ADC_DEV_NAME,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700170 .id = -1,
171 .resources = adc_cell_resources,
172 .num_resources = ARRAY_SIZE(adc_cell_resources),
173};
174
Willie Ruan51060352012-01-19 16:58:49 -0800175static struct resource mpp_cell_resources[] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700176 {
177 .start = PM8921_IRQ_BLOCK_BIT(PM8921_MPP_BLOCK_START, 0),
178 .end = PM8921_IRQ_BLOCK_BIT(PM8921_MPP_BLOCK_START, 0)
179 + PM8921_NR_MPPS - 1,
180 .flags = IORESOURCE_IRQ,
181 },
182};
183
184static struct mfd_cell mpp_cell __devinitdata = {
185 .name = PM8XXX_MPP_DEV_NAME,
Jay Chokshi24fc9b62011-07-18 10:51:05 -0700186 .id = 0,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700187 .resources = mpp_cell_resources,
188 .num_resources = ARRAY_SIZE(mpp_cell_resources),
189};
190
191static const struct resource rtc_cell_resources[] __devinitconst = {
192 [0] = SINGLE_IRQ_RESOURCE(NULL, PM8921_RTC_ALARM_IRQ),
193 [1] = {
194 .name = "pmic_rtc_base",
195 .start = PM8921_RTC_BASE,
196 .end = PM8921_RTC_BASE,
197 .flags = IORESOURCE_IO,
198 },
199};
200
201static struct mfd_cell rtc_cell __devinitdata = {
202 .name = PM8XXX_RTC_DEV_NAME,
203 .id = -1,
204 .resources = rtc_cell_resources,
205 .num_resources = ARRAY_SIZE(rtc_cell_resources),
206};
207
208static const struct resource resources_pwrkey[] __devinitconst = {
209 SINGLE_IRQ_RESOURCE(NULL, PM8921_PWRKEY_REL_IRQ),
210 SINGLE_IRQ_RESOURCE(NULL, PM8921_PWRKEY_PRESS_IRQ),
211};
212
213static struct mfd_cell pwrkey_cell __devinitdata = {
214 .name = PM8XXX_PWRKEY_DEV_NAME,
215 .id = -1,
216 .num_resources = ARRAY_SIZE(resources_pwrkey),
217 .resources = resources_pwrkey,
218};
219
220static const struct resource resources_keypad[] = {
221 SINGLE_IRQ_RESOURCE(NULL, PM8921_KEYPAD_IRQ),
222 SINGLE_IRQ_RESOURCE(NULL, PM8921_KEYSTUCK_IRQ),
223};
224
225static struct mfd_cell keypad_cell __devinitdata = {
226 .name = PM8XXX_KEYPAD_DEV_NAME,
227 .id = -1,
228 .num_resources = ARRAY_SIZE(resources_keypad),
229 .resources = resources_keypad,
230};
231
232static struct mfd_cell debugfs_cell __devinitdata = {
233 .name = "pm8xxx-debug",
Jay Chokshi24fc9b62011-07-18 10:51:05 -0700234 .id = 0,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700235 .platform_data = "pm8921-dbg",
236 .pdata_size = sizeof("pm8921-dbg"),
237};
238
239static struct mfd_cell pwm_cell __devinitdata = {
240 .name = PM8XXX_PWM_DEV_NAME,
241 .id = -1,
242};
243
244static const struct resource charger_cell_resources[] __devinitconst = {
245 SINGLE_IRQ_RESOURCE("USBIN_VALID_IRQ", PM8921_USBIN_VALID_IRQ),
246 SINGLE_IRQ_RESOURCE("USBIN_OV_IRQ", PM8921_USBIN_OV_IRQ),
247 SINGLE_IRQ_RESOURCE("BATT_INSERTED_IRQ", PM8921_BATT_INSERTED_IRQ),
248 SINGLE_IRQ_RESOURCE("VBATDET_LOW_IRQ", PM8921_VBATDET_LOW_IRQ),
249 SINGLE_IRQ_RESOURCE("USBIN_UV_IRQ", PM8921_USBIN_UV_IRQ),
250 SINGLE_IRQ_RESOURCE("VBAT_OV_IRQ", PM8921_VBAT_OV_IRQ),
251 SINGLE_IRQ_RESOURCE("CHGWDOG_IRQ", PM8921_CHGWDOG_IRQ),
252 SINGLE_IRQ_RESOURCE("VCP_IRQ", PM8921_VCP_IRQ),
253 SINGLE_IRQ_RESOURCE("ATCDONE_IRQ", PM8921_ATCDONE_IRQ),
254 SINGLE_IRQ_RESOURCE("ATCFAIL_IRQ", PM8921_ATCFAIL_IRQ),
255 SINGLE_IRQ_RESOURCE("CHGDONE_IRQ", PM8921_CHGDONE_IRQ),
256 SINGLE_IRQ_RESOURCE("CHGFAIL_IRQ", PM8921_CHGFAIL_IRQ),
257 SINGLE_IRQ_RESOURCE("CHGSTATE_IRQ", PM8921_CHGSTATE_IRQ),
258 SINGLE_IRQ_RESOURCE("LOOP_CHANGE_IRQ", PM8921_LOOP_CHANGE_IRQ),
259 SINGLE_IRQ_RESOURCE("FASTCHG_IRQ", PM8921_FASTCHG_IRQ),
260 SINGLE_IRQ_RESOURCE("TRKLCHG_IRQ", PM8921_TRKLCHG_IRQ),
261 SINGLE_IRQ_RESOURCE("BATT_REMOVED_IRQ", PM8921_BATT_REMOVED_IRQ),
262 SINGLE_IRQ_RESOURCE("BATTTEMP_HOT_IRQ", PM8921_BATTTEMP_HOT_IRQ),
263 SINGLE_IRQ_RESOURCE("CHGHOT_IRQ", PM8921_CHGHOT_IRQ),
264 SINGLE_IRQ_RESOURCE("BATTTEMP_COLD_IRQ", PM8921_BATTTEMP_COLD_IRQ),
265 SINGLE_IRQ_RESOURCE("CHG_GONE_IRQ", PM8921_CHG_GONE_IRQ),
266 SINGLE_IRQ_RESOURCE("BAT_TEMP_OK_IRQ", PM8921_BAT_TEMP_OK_IRQ),
267 SINGLE_IRQ_RESOURCE("COARSE_DET_LOW_IRQ", PM8921_COARSE_DET_LOW_IRQ),
268 SINGLE_IRQ_RESOURCE("VDD_LOOP_IRQ", PM8921_VDD_LOOP_IRQ),
269 SINGLE_IRQ_RESOURCE("VREG_OV_IRQ", PM8921_VREG_OV_IRQ),
270 SINGLE_IRQ_RESOURCE("VBATDET_IRQ", PM8921_VBATDET_IRQ),
271 SINGLE_IRQ_RESOURCE("BATFET_IRQ", PM8921_BATFET_IRQ),
272 SINGLE_IRQ_RESOURCE("PSI_IRQ", PM8921_PSI_IRQ),
273 SINGLE_IRQ_RESOURCE("DCIN_VALID_IRQ", PM8921_DCIN_VALID_IRQ),
274 SINGLE_IRQ_RESOURCE("DCIN_OV_IRQ", PM8921_DCIN_OV_IRQ),
275 SINGLE_IRQ_RESOURCE("DCIN_UV_IRQ", PM8921_DCIN_UV_IRQ),
276};
277
278static const struct resource bms_cell_resources[] __devinitconst = {
279 SINGLE_IRQ_RESOURCE("PM8921_BMS_SBI_WRITE_OK", PM8921_BMS_SBI_WRITE_OK),
280 SINGLE_IRQ_RESOURCE("PM8921_BMS_CC_THR", PM8921_BMS_CC_THR),
281 SINGLE_IRQ_RESOURCE("PM8921_BMS_VSENSE_THR", PM8921_BMS_VSENSE_THR),
282 SINGLE_IRQ_RESOURCE("PM8921_BMS_VSENSE_FOR_R", PM8921_BMS_VSENSE_FOR_R),
283 SINGLE_IRQ_RESOURCE("PM8921_BMS_OCV_FOR_R", PM8921_BMS_OCV_FOR_R),
284 SINGLE_IRQ_RESOURCE("PM8921_BMS_GOOD_OCV", PM8921_BMS_GOOD_OCV),
285 SINGLE_IRQ_RESOURCE("PM8921_BMS_VSENSE_AVG", PM8921_BMS_VSENSE_AVG),
286};
287
288static struct mfd_cell charger_cell __devinitdata = {
289 .name = PM8921_CHARGER_DEV_NAME,
290 .id = -1,
291 .resources = charger_cell_resources,
292 .num_resources = ARRAY_SIZE(charger_cell_resources),
293};
294
295static struct mfd_cell bms_cell __devinitdata = {
296 .name = PM8921_BMS_DEV_NAME,
297 .id = -1,
298 .resources = bms_cell_resources,
299 .num_resources = ARRAY_SIZE(bms_cell_resources),
300};
301
302static struct mfd_cell misc_cell __devinitdata = {
303 .name = PM8XXX_MISC_DEV_NAME,
304 .id = -1,
305};
306
307static struct mfd_cell leds_cell __devinitdata = {
308 .name = PM8XXX_LEDS_DEV_NAME,
309 .id = -1,
310};
311
312static const struct resource thermal_alarm_cell_resources[] __devinitconst = {
313 SINGLE_IRQ_RESOURCE("pm8921_tempstat_irq", PM8921_TEMPSTAT_IRQ),
314 SINGLE_IRQ_RESOURCE("pm8921_overtemp_irq", PM8921_OVERTEMP_IRQ),
315};
316
317static struct pm8xxx_tm_core_data thermal_alarm_cdata = {
318 .adc_channel = CHANNEL_DIE_TEMP,
Siddartha Mohanadossaf91d902011-10-20 10:23:34 -0700319 .adc_type = PM8XXX_TM_ADC_PM8XXX_ADC,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700320 .reg_addr_temp_alarm_ctrl = REG_TEMP_ALARM_CTRL,
321 .reg_addr_temp_alarm_pwm = REG_TEMP_ALARM_PWM,
322 .tm_name = "pm8921_tz",
323 .irq_name_temp_stat = "pm8921_tempstat_irq",
324 .irq_name_over_temp = "pm8921_overtemp_irq",
325};
326
327static struct mfd_cell thermal_alarm_cell __devinitdata = {
328 .name = PM8XXX_TM_DEV_NAME,
329 .id = -1,
330 .resources = thermal_alarm_cell_resources,
331 .num_resources = ARRAY_SIZE(thermal_alarm_cell_resources),
332 .platform_data = &thermal_alarm_cdata,
333 .pdata_size = sizeof(struct pm8xxx_tm_core_data),
334};
335
336static const struct resource batt_alarm_cell_resources[] __devinitconst = {
337 SINGLE_IRQ_RESOURCE("pm8921_batt_alarm_irq", PM8921_BATT_ALARM_IRQ),
338};
339
340static struct pm8xxx_batt_alarm_core_data batt_alarm_cdata = {
341 .irq_name = "pm8921_batt_alarm_irq",
342 .reg_addr_threshold = REG_BATT_ALARM_THRESH,
343 .reg_addr_ctrl1 = REG_BATT_ALARM_CTRL1,
344 .reg_addr_ctrl2 = REG_BATT_ALARM_CTRL2,
345 .reg_addr_pwm_ctrl = REG_BATT_ALARM_PWM_CTRL,
346};
347
348static struct mfd_cell batt_alarm_cell __devinitdata = {
349 .name = PM8XXX_BATT_ALARM_DEV_NAME,
350 .id = -1,
351 .resources = batt_alarm_cell_resources,
352 .num_resources = ARRAY_SIZE(batt_alarm_cell_resources),
353 .platform_data = &batt_alarm_cdata,
354 .pdata_size = sizeof(struct pm8xxx_batt_alarm_core_data),
355};
356
Abhijeet Dharmapurikar82d93982011-11-09 15:52:25 -0800357static const struct resource ccadc_cell_resources[] __devinitconst = {
358 SINGLE_IRQ_RESOURCE("PM8921_BMS_CCADC_EOC", PM8921_BMS_CCADC_EOC),
359};
360
361static struct mfd_cell ccadc_cell __devinitdata = {
362 .name = PM8XXX_CCADC_DEV_NAME,
363 .id = -1,
364 .resources = ccadc_cell_resources,
365 .num_resources = ARRAY_SIZE(ccadc_cell_resources),
366};
367
Anirudh Ghayal6804c742011-07-27 11:47:53 +0530368static struct mfd_cell vibrator_cell __devinitdata = {
369 .name = PM8XXX_VIBRATOR_DEV_NAME,
370 .id = -1,
371};
372
David Collins75016742011-12-02 15:04:25 -0800373static struct pm8xxx_vreg regulator_data[] = {
374 /* name pc_name ctrl test hpm_min */
375 NLDO("8921_l1", "8921_l1_pc", 0x0AE, 0x0AF, LDO_150),
376 NLDO("8921_l2", "8921_l2_pc", 0x0B0, 0x0B1, LDO_150),
377 PLDO("8921_l3", "8921_l3_pc", 0x0B2, 0x0B3, LDO_150),
378 PLDO("8921_l4", "8921_l4_pc", 0x0B4, 0x0B5, LDO_50),
379 PLDO("8921_l5", "8921_l5_pc", 0x0B6, 0x0B7, LDO_300),
380 PLDO("8921_l6", "8921_l6_pc", 0x0B8, 0x0B9, LDO_600),
381 PLDO("8921_l7", "8921_l7_pc", 0x0BA, 0x0BB, LDO_150),
382 PLDO("8921_l8", "8921_l8_pc", 0x0BC, 0x0BD, LDO_300),
383 PLDO("8921_l9", "8921_l9_pc", 0x0BE, 0x0BF, LDO_300),
384 PLDO("8921_l10", "8921_l10_pc", 0x0C0, 0x0C1, LDO_600),
385 PLDO("8921_l11", "8921_l11_pc", 0x0C2, 0x0C3, LDO_150),
386 NLDO("8921_l12", "8921_l12_pc", 0x0C4, 0x0C5, LDO_150),
387 PLDO("8921_l14", "8921_l14_pc", 0x0C8, 0x0C9, LDO_50),
388 PLDO("8921_l15", "8921_l15_pc", 0x0CA, 0x0CB, LDO_150),
389 PLDO("8921_l16", "8921_l16_pc", 0x0CC, 0x0CD, LDO_300),
390 PLDO("8921_l17", "8921_l17_pc", 0x0CE, 0x0CF, LDO_150),
391 NLDO("8921_l18", "8921_l18_pc", 0x0D0, 0x0D1, LDO_150),
392 PLDO("8921_l21", "8921_l21_pc", 0x0D6, 0x0D7, LDO_150),
393 PLDO("8921_l22", "8921_l22_pc", 0x0D8, 0x0D9, LDO_150),
394 PLDO("8921_l23", "8921_l23_pc", 0x0DA, 0x0DB, LDO_150),
395 NLDO1200("8921_l24", 0x0DC, 0x0DD, LDO_1200),
396 NLDO1200("8921_l25", 0x0DE, 0x0DF, LDO_1200),
397 NLDO1200("8921_l26", 0x0E0, 0x0E1, LDO_1200),
398 NLDO1200("8921_l27", 0x0E2, 0x0E3, LDO_1200),
399 NLDO1200("8921_l28", 0x0E4, 0x0E5, LDO_1200),
400 PLDO("8921_l29", "8921_l29_pc", 0x0E6, 0x0E7, LDO_150),
401
402 /* name pc_name ctrl test2 clk sleep hpm_min */
403 SMPS("8921_s1", "8921_s1_pc", 0x1D0, 0x1D5, 0x009, 0x1D2, SMPS_1500),
404 SMPS("8921_s2", "8921_s2_pc", 0x1D8, 0x1DD, 0x00A, 0x1DA, SMPS_1500),
405 SMPS("8921_s3", "8921_s3_pc", 0x1E0, 0x1E5, 0x00B, 0x1E2, SMPS_1500),
406 SMPS("8921_s4", "8921_s4_pc", 0x1E8, 0x1ED, 0x011, 0x1EA, SMPS_1500),
407
408 /* name ctrl fts_cnfg1 pfm pwr_cnfg hpm_min */
409 FTSMPS("8921_s5", 0x025, 0x02E, 0x026, 0x032, SMPS_2000),
410 FTSMPS("8921_s6", 0x036, 0x03F, 0x037, 0x043, SMPS_2000),
411
412 /* name pc_name ctrl test2 clk sleep hpm_min */
413 SMPS("8921_s7", "8921_s7_pc", 0x1F0, 0x1F5, 0x012, 0x1F2, SMPS_1500),
414 SMPS("8921_s8", "8921_s8_pc", 0x1F8, 0x1FD, 0x013, 0x1FA, SMPS_1500),
415
David Collins1b570d22012-01-30 15:40:55 -0800416 /* name pc_name ctrl test */
417 VS("8921_lvs1", "8921_lvs1_pc", 0x060, 0x061),
418 VS300("8921_lvs2", 0x062, 0x063),
419 VS("8921_lvs3", "8921_lvs3_pc", 0x064, 0x065),
420 VS("8921_lvs4", "8921_lvs4_pc", 0x066, 0x067),
421 VS("8921_lvs5", "8921_lvs5_pc", 0x068, 0x069),
422 VS("8921_lvs6", "8921_lvs6_pc", 0x06A, 0x06B),
423 VS("8921_lvs7", "8921_lvs7_pc", 0x06C, 0x06D),
424 VS300("8921_usb_otg", 0x06E, 0x06F),
425 VS300("8921_hdmi_mvs", 0x070, 0x071),
David Collins75016742011-12-02 15:04:25 -0800426
427 /* name ctrl */
428 NCP("8921_ncp", 0x090),
429};
430
David Collins00f29e52012-02-13 11:38:45 -0800431/*
432 * PM8917 adds 6 LDOs and a boost regulator beyond those available on PM8921.
433 * It also replaces SMPS 3 with FTSMPS 3. PM8917 does not have an NCP.
434 */
435static struct pm8xxx_vreg pm8917_regulator_data[] = {
436 /* name pc_name ctrl test hpm_min */
437 PLDO("8917_l30", "8917_l30_pc", 0x0A3, 0x0A4, LDO_150),
438 PLDO("8917_l31", "8917_l31_pc", 0x0A5, 0x0A6, LDO_150),
439 PLDO("8917_l32", "8917_l32_pc", 0x0A7, 0x0A8, LDO_150),
440 PLDO("8917_l33", "8917_l33_pc", 0x0C6, 0x0C7, LDO_150),
441 PLDO("8917_l34", "8917_l34_pc", 0x0D2, 0x0D3, LDO_150),
442 PLDO("8917_l35", "8917_l35_pc", 0x0D4, 0x0D5, LDO_300),
David Collins83e8f9f2012-03-08 11:57:47 -0800443 PLDO("8917_l36", "8917_l36_pc", 0x0A9, 0x0AA, LDO_50),
David Collins00f29e52012-02-13 11:38:45 -0800444
445 /* name ctrl */
446 BOOST("8917_boost", 0x04B),
447};
448
David Collins75016742011-12-02 15:04:25 -0800449#define MAX_NAME_COMPARISON_LEN 32
450
David Collins00f29e52012-02-13 11:38:45 -0800451static int __devinit match_regulator(enum pm8xxx_version version,
Mark Brown5d028cd2011-10-14 13:36:04 +0100452 struct pm8xxx_regulator_core_platform_data *core_data, const char *name)
David Collins75016742011-12-02 15:04:25 -0800453{
454 int found = 0;
455 int i;
456
457 for (i = 0; i < ARRAY_SIZE(regulator_data); i++) {
458 if (regulator_data[i].rdesc.name
459 && strncmp(regulator_data[i].rdesc.name, name,
460 MAX_NAME_COMPARISON_LEN) == 0) {
461 core_data->is_pin_controlled = false;
462 core_data->vreg = &regulator_data[i];
463 found = 1;
464 break;
465 } else if (regulator_data[i].rdesc_pc.name
466 && strncmp(regulator_data[i].rdesc_pc.name, name,
467 MAX_NAME_COMPARISON_LEN) == 0) {
468 core_data->is_pin_controlled = true;
469 core_data->vreg = &regulator_data[i];
470 found = 1;
471 break;
472 }
473 }
David Collins00f29e52012-02-13 11:38:45 -0800474 if (version == PM8XXX_VERSION_8917) {
475 for (i = 0; i < ARRAY_SIZE(pm8917_regulator_data); i++) {
476 if (pm8917_regulator_data[i].rdesc.name
477 && strncmp(pm8917_regulator_data[i].rdesc.name,
478 name, MAX_NAME_COMPARISON_LEN) == 0) {
479 core_data->is_pin_controlled = false;
480 core_data->vreg = &pm8917_regulator_data[i];
481 found = 1;
482 break;
483 } else if (pm8917_regulator_data[i].rdesc_pc.name
484 && strncmp(pm8917_regulator_data[i].rdesc_pc.name,
485 name, MAX_NAME_COMPARISON_LEN) == 0) {
486 core_data->is_pin_controlled = true;
487 core_data->vreg = &pm8917_regulator_data[i];
488 found = 1;
489 break;
490 }
491 }
492 }
David Collins75016742011-12-02 15:04:25 -0800493
494 if (!found)
495 pr_err("could not find a match for regulator: %s\n", name);
496
497 return found;
498}
499
500static int __devinit
501pm8921_add_regulators(const struct pm8921_platform_data *pdata,
502 struct pm8921 *pmic, int irq_base)
503{
504 int ret = 0;
505 struct mfd_cell *mfd_regulators;
506 struct pm8xxx_regulator_core_platform_data *cdata;
David Collins00f29e52012-02-13 11:38:45 -0800507 enum pm8xxx_version version;
David Collins75016742011-12-02 15:04:25 -0800508 int i;
509
David Collins00f29e52012-02-13 11:38:45 -0800510 version = pm8xxx_get_version(pmic->dev);
511
David Collins75016742011-12-02 15:04:25 -0800512 /* Add one device for each regulator used by the board. */
513 mfd_regulators = kzalloc(sizeof(struct mfd_cell)
514 * (pdata->num_regulators), GFP_KERNEL);
515 if (!mfd_regulators) {
516 pr_err("Cannot allocate %d bytes for pm8921 regulator "
517 "mfd cells\n", sizeof(struct mfd_cell)
518 * (pdata->num_regulators));
519 return -ENOMEM;
520 }
521 cdata = kzalloc(sizeof(struct pm8xxx_regulator_core_platform_data)
522 * pdata->num_regulators, GFP_KERNEL);
523 if (!cdata) {
524 pr_err("Cannot allocate %d bytes for pm8921 regulator "
525 "core data\n", pdata->num_regulators
526 * sizeof(struct pm8xxx_regulator_core_platform_data));
527 kfree(mfd_regulators);
528 return -ENOMEM;
529 }
530 for (i = 0; i < ARRAY_SIZE(regulator_data); i++)
531 mutex_init(&regulator_data[i].pc_lock);
David Collins00f29e52012-02-13 11:38:45 -0800532 for (i = 0; i < ARRAY_SIZE(pm8917_regulator_data); i++)
533 mutex_init(&pm8917_regulator_data[i].pc_lock);
David Collins75016742011-12-02 15:04:25 -0800534
535 for (i = 0; i < pdata->num_regulators; i++) {
536 if (!pdata->regulator_pdatas[i].init_data.constraints.name) {
537 pr_err("name missing for regulator %d\n", i);
538 ret = -EINVAL;
539 goto bail;
540 }
David Collins00f29e52012-02-13 11:38:45 -0800541 if (!match_regulator(version, &cdata[i],
David Collins75016742011-12-02 15:04:25 -0800542 pdata->regulator_pdatas[i].init_data.constraints.name)) {
543 ret = -ENODEV;
544 goto bail;
545 }
546 cdata[i].pdata = &(pdata->regulator_pdatas[i]);
547 mfd_regulators[i].name = PM8XXX_REGULATOR_DEV_NAME;
548 mfd_regulators[i].id = cdata[i].pdata->id;
549 mfd_regulators[i].platform_data = &cdata[i];
550 mfd_regulators[i].pdata_size =
551 sizeof(struct pm8xxx_regulator_core_platform_data);
552 }
553 ret = mfd_add_devices(pmic->dev, 0, mfd_regulators,
554 pdata->num_regulators, NULL, irq_base);
555 if (ret)
556 goto bail;
557
558 pmic->mfd_regulators = mfd_regulators;
559 pmic->regulator_cdata = cdata;
560 return ret;
561
562bail:
563 for (i = 0; i < ARRAY_SIZE(regulator_data); i++)
564 mutex_destroy(&regulator_data[i].pc_lock);
David Collins00f29e52012-02-13 11:38:45 -0800565 for (i = 0; i < ARRAY_SIZE(pm8917_regulator_data); i++)
566 mutex_destroy(&pm8917_regulator_data[i].pc_lock);
David Collins75016742011-12-02 15:04:25 -0800567 kfree(mfd_regulators);
568 kfree(cdata);
569 return ret;
570}
571
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700572static int __devinit
573pm8921_add_subdevices(const struct pm8921_platform_data *pdata,
574 struct pm8921 *pmic)
Abhijeet Dharmapurikarc013f0a2011-04-05 14:40:53 -0700575{
576 int ret = 0, irq_base = 0;
577 struct pm_irq_chip *irq_chip;
David Collins999480d2011-11-16 08:52:30 -0800578 enum pm8xxx_version version;
Abhijeet Dharmapurikarc013f0a2011-04-05 14:40:53 -0700579
David Collins999480d2011-11-16 08:52:30 -0800580 version = pm8xxx_get_version(pmic->dev);
Abhijeet Dharmapurikarc013f0a2011-04-05 14:40:53 -0700581
582 if (pdata->irq_pdata) {
583 pdata->irq_pdata->irq_cdata.nirqs = PM8921_NR_IRQS;
Anirudh Ghayalca42c7de2011-11-21 10:42:07 +0530584 pdata->irq_pdata->irq_cdata.base_addr = REG_IRQ_BASE;
Abhijeet Dharmapurikarc013f0a2011-04-05 14:40:53 -0700585 irq_base = pdata->irq_pdata->irq_base;
586 irq_chip = pm8xxx_irq_init(pmic->dev, pdata->irq_pdata);
587
588 if (IS_ERR(irq_chip)) {
589 pr_err("Failed to init interrupts ret=%ld\n",
590 PTR_ERR(irq_chip));
591 return PTR_ERR(irq_chip);
592 }
593 pmic->irq_chip = irq_chip;
594 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700595
596 if (pdata->gpio_pdata) {
Willie Ruan51060352012-01-19 16:58:49 -0800597 if (version == PM8XXX_VERSION_8917) {
598 gpio_cell_resources[0].end = gpio_cell_resources[0].end
599 + PM8917_NR_GPIOS
600 - PM8921_NR_GPIOS;
601 pdata->gpio_pdata->gpio_cdata.ngpios = PM8917_NR_GPIOS;
602 } else {
603 pdata->gpio_pdata->gpio_cdata.ngpios = PM8921_NR_GPIOS;
604 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700605 gpio_cell.platform_data = pdata->gpio_pdata;
606 gpio_cell.pdata_size = sizeof(struct pm8xxx_gpio_platform_data);
607 ret = mfd_add_devices(pmic->dev, 0, &gpio_cell, 1,
608 NULL, irq_base);
609 if (ret) {
610 pr_err("Failed to add gpio subdevice ret=%d\n", ret);
611 goto bail;
612 }
613 }
614
615 if (pdata->mpp_pdata) {
Willie Ruan51060352012-01-19 16:58:49 -0800616 if (version == PM8XXX_VERSION_8917) {
617 mpp_cell_resources[0].end = mpp_cell_resources[0].end
618 + PM8917_NR_MPPS
619 - PM8921_NR_MPPS;
620 pdata->mpp_pdata->core_data.nmpps = PM8917_NR_MPPS;
621 } else {
622 pdata->mpp_pdata->core_data.nmpps = PM8921_NR_MPPS;
623 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700624 pdata->mpp_pdata->core_data.base_addr = REG_MPP_BASE;
625 mpp_cell.platform_data = pdata->mpp_pdata;
626 mpp_cell.pdata_size = sizeof(struct pm8xxx_mpp_platform_data);
627 ret = mfd_add_devices(pmic->dev, 0, &mpp_cell, 1, NULL,
628 irq_base);
629 if (ret) {
630 pr_err("Failed to add mpp subdevice ret=%d\n", ret);
631 goto bail;
632 }
633 }
634
635 if (pdata->rtc_pdata) {
636 rtc_cell.platform_data = pdata->rtc_pdata;
637 rtc_cell.pdata_size = sizeof(struct pm8xxx_rtc_platform_data);
638 ret = mfd_add_devices(pmic->dev, 0, &rtc_cell, 1, NULL,
639 irq_base);
640 if (ret) {
641 pr_err("Failed to add rtc subdevice ret=%d\n", ret);
642 goto bail;
643 }
644 }
645
646 if (pdata->pwrkey_pdata) {
647 pwrkey_cell.platform_data = pdata->pwrkey_pdata;
648 pwrkey_cell.pdata_size =
649 sizeof(struct pm8xxx_pwrkey_platform_data);
650 ret = mfd_add_devices(pmic->dev, 0, &pwrkey_cell, 1, NULL,
651 irq_base);
652 if (ret) {
653 pr_err("Failed to add pwrkey subdevice ret=%d\n", ret);
654 goto bail;
655 }
656 }
657
658 if (pdata->keypad_pdata) {
659 keypad_cell.platform_data = pdata->keypad_pdata;
660 keypad_cell.pdata_size =
661 sizeof(struct pm8xxx_keypad_platform_data);
662 ret = mfd_add_devices(pmic->dev, 0, &keypad_cell, 1, NULL,
663 irq_base);
664 if (ret) {
665 pr_err("Failed to add keypad subdevice ret=%d\n", ret);
666 goto bail;
667 }
668 }
669
670 if (pdata->charger_pdata) {
671 pdata->charger_pdata->charger_cdata.vbat_channel = CHANNEL_VBAT;
Abhijeet Dharmapurikarb24e2c32011-08-17 17:13:09 -0700672 pdata->charger_pdata->charger_cdata.batt_temp_channel
673 = CHANNEL_BATT_THERM;
Abhijeet Dharmapurikarbe6bd8c2011-08-19 12:15:06 -0700674 pdata->charger_pdata->charger_cdata.batt_id_channel
675 = CHANNEL_BATT_ID;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700676 charger_cell.platform_data = pdata->charger_pdata;
677 charger_cell.pdata_size =
678 sizeof(struct pm8921_charger_platform_data);
679 ret = mfd_add_devices(pmic->dev, 0, &charger_cell, 1, NULL,
680 irq_base);
681 if (ret) {
682 pr_err("Failed to add charger subdevice ret=%d\n", ret);
683 goto bail;
684 }
685 }
686
687 if (pdata->adc_pdata) {
688 adc_cell.platform_data = pdata->adc_pdata;
689 adc_cell.pdata_size =
Siddartha Mohanadossaf91d902011-10-20 10:23:34 -0700690 sizeof(struct pm8xxx_adc_platform_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700691 ret = mfd_add_devices(pmic->dev, 0, &adc_cell, 1, NULL,
692 irq_base);
693 if (ret) {
694 pr_err("Failed to add regulator subdevices ret=%d\n",
695 ret);
696 }
697 }
698
699 if (pdata->bms_pdata) {
Abhijeet Dharmapurikarc448d982011-06-28 20:48:36 -0700700 pdata->bms_pdata->bms_cdata.batt_temp_channel
701 = CHANNEL_BATT_THERM;
Abhijeet Dharmapurikar76d4db92011-07-19 11:54:52 -0700702 pdata->bms_pdata->bms_cdata.vbat_channel = CHANNEL_VBAT;
703 pdata->bms_pdata->bms_cdata.ref625mv_channel = CHANNEL_625MV;
704 pdata->bms_pdata->bms_cdata.ref1p25v_channel = CHANNEL_125V;
Abhijeet Dharmapurikare922bbb2011-09-01 13:05:06 -0700705 pdata->bms_pdata->bms_cdata.batt_id_channel = CHANNEL_BATT_ID;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700706 bms_cell.platform_data = pdata->bms_pdata;
Abhijeet Dharmapurikar76d4db92011-07-19 11:54:52 -0700707 bms_cell.pdata_size = sizeof(struct pm8921_bms_platform_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700708 ret = mfd_add_devices(pmic->dev, 0, &bms_cell, 1, NULL,
709 irq_base);
710 if (ret) {
711 pr_err("Failed to add bms subdevice ret=%d\n", ret);
712 goto bail;
713 }
714 }
715
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700716 if (pdata->num_regulators > 0 && pdata->regulator_pdatas) {
David Collins75016742011-12-02 15:04:25 -0800717 ret = pm8921_add_regulators(pdata, pmic, irq_base);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700718 if (ret) {
719 pr_err("Failed to add regulator subdevices ret=%d\n",
720 ret);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700721 goto bail;
722 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700723 }
724
725 ret = mfd_add_devices(pmic->dev, 0, &debugfs_cell, 1, NULL, irq_base);
726 if (ret) {
727 pr_err("Failed to add debugfs subdevice ret=%d\n", ret);
728 goto bail;
729 }
730
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700731 if (pdata->misc_pdata) {
732 misc_cell.platform_data = pdata->misc_pdata;
733 misc_cell.pdata_size = sizeof(struct pm8xxx_misc_platform_data);
734 ret = mfd_add_devices(pmic->dev, 0, &misc_cell, 1, NULL,
735 irq_base);
736 if (ret) {
737 pr_err("Failed to add misc subdevice ret=%d\n", ret);
738 goto bail;
739 }
740 }
741
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700742 ret = mfd_add_devices(pmic->dev, 0, &thermal_alarm_cell, 1, NULL,
743 irq_base);
744 if (ret) {
745 pr_err("Failed to add thermal alarm subdevice ret=%d\n",
746 ret);
747 goto bail;
748 }
749
750 ret = mfd_add_devices(pmic->dev, 0, &batt_alarm_cell, 1, NULL,
751 irq_base);
752 if (ret) {
753 pr_err("Failed to add battery alarm subdevice ret=%d\n",
754 ret);
755 goto bail;
756 }
757
Willie Ruan51060352012-01-19 16:58:49 -0800758 if (version != PM8XXX_VERSION_8917) {
Jay Chokshib0a0fa52012-02-23 16:18:44 -0800759 if (pdata->pwm_pdata) {
760 pwm_cell.platform_data = pdata->pwm_pdata;
761 pwm_cell.pdata_size =
762 sizeof(struct pm8xxx_pwm_platform_data);
763 }
Willie Ruan51060352012-01-19 16:58:49 -0800764 ret = mfd_add_devices(pmic->dev, 0, &pwm_cell, 1, NULL, 0);
Anirudh Ghayal6804c742011-07-27 11:47:53 +0530765 if (ret) {
Willie Ruan51060352012-01-19 16:58:49 -0800766 pr_err("Failed to add pwm subdevice ret=%d\n", ret);
Anirudh Ghayal6804c742011-07-27 11:47:53 +0530767 goto bail;
768 }
Willie Ruan51060352012-01-19 16:58:49 -0800769
770 if (pdata->leds_pdata) {
771 leds_cell.platform_data = pdata->leds_pdata;
772 leds_cell.pdata_size =
773 sizeof(struct pm8xxx_led_platform_data);
774 ret = mfd_add_devices(pmic->dev, 0, &leds_cell,
775 1, NULL, 0);
776 if (ret) {
777 pr_err("Failed to add leds subdevice ret=%d\n",
778 ret);
779 goto bail;
780 }
781 }
782
783 if (pdata->vibrator_pdata) {
784 vibrator_cell.platform_data = pdata->vibrator_pdata;
785 vibrator_cell.pdata_size =
786 sizeof(struct pm8xxx_vibrator_platform_data);
787 ret = mfd_add_devices(pmic->dev, 0, &vibrator_cell,
788 1, NULL, 0);
789 if (ret) {
790 pr_err("Failed to add vibrator ret=%d\n", ret);
791 goto bail;
792 }
793 }
Anirudh Ghayal6804c742011-07-27 11:47:53 +0530794 }
795
Abhijeet Dharmapurikar82d93982011-11-09 15:52:25 -0800796 if (pdata->ccadc_pdata) {
797 ccadc_cell.platform_data = pdata->ccadc_pdata;
798 ccadc_cell.pdata_size =
799 sizeof(struct pm8xxx_ccadc_platform_data);
800
801 ret = mfd_add_devices(pmic->dev, 0, &ccadc_cell, 1, NULL,
802 irq_base);
803 if (ret) {
804 pr_err("Failed to add ccadc subdevice ret=%d\n", ret);
805 goto bail;
806 }
807 }
808
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700809 return 0;
810bail:
811 if (pmic->irq_chip) {
812 pm8xxx_irq_exit(pmic->irq_chip);
813 pmic->irq_chip = NULL;
814 }
Abhijeet Dharmapurikarc013f0a2011-04-05 14:40:53 -0700815 return ret;
816}
817
Abhijeet Dharmapurikar5caa02c2011-08-15 20:11:28 -0700818static const char * const pm8921_restart_reason[] = {
819 [0] = "Unknown",
820 [1] = "Triggered from CBL (external charger)",
821 [2] = "Triggered from KPD (power key press)",
822 [3] = "Triggered from CHG (usb charger insertion)",
823 [4] = "Triggered from SMPL (sudden momentary power loss)",
824 [5] = "Triggered from RTC (real time clock)",
825 [6] = "Triggered by Hard Reset",
826 [7] = "Triggered by General Purpose Trigger",
827};
828
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700829static const char * const pm8921_rev_names[] = {
830 [PM8XXX_REVISION_8921_TEST] = "test",
831 [PM8XXX_REVISION_8921_1p0] = "1.0",
832 [PM8XXX_REVISION_8921_1p1] = "1.1",
833 [PM8XXX_REVISION_8921_2p0] = "2.0",
David Keitel70251b02011-11-18 12:22:58 -0800834 [PM8XXX_REVISION_8921_3p0] = "3.0",
Jay Chokshi1ba115d2012-04-19 15:42:41 -0700835 [PM8XXX_REVISION_8921_3p1] = "3.1",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700836};
837
David Collins999480d2011-11-16 08:52:30 -0800838static const char * const pm8922_rev_names[] = {
839 [PM8XXX_REVISION_8922_TEST] = "test",
840 [PM8XXX_REVISION_8922_1p0] = "1.0",
841 [PM8XXX_REVISION_8922_1p1] = "1.1",
842 [PM8XXX_REVISION_8922_2p0] = "2.0",
843};
844
Willie Ruan51060352012-01-19 16:58:49 -0800845static const char * const pm8917_rev_names[] = {
846 [PM8XXX_REVISION_8917_TEST] = "test",
847 [PM8XXX_REVISION_8917_1p0] = "1.0",
848};
849
Abhijeet Dharmapurikarcbdb53e2011-04-05 14:40:52 -0700850static int __devinit pm8921_probe(struct platform_device *pdev)
851{
852 const struct pm8921_platform_data *pdata = pdev->dev.platform_data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700853 const char *revision_name = "unknown";
Abhijeet Dharmapurikarcbdb53e2011-04-05 14:40:52 -0700854 struct pm8921 *pmic;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700855 enum pm8xxx_version version;
856 int revision;
Abhijeet Dharmapurikarcbdb53e2011-04-05 14:40:52 -0700857 int rc;
858 u8 val;
859
860 if (!pdata) {
861 pr_err("missing platform data\n");
862 return -EINVAL;
863 }
864
865 pmic = kzalloc(sizeof(struct pm8921), GFP_KERNEL);
866 if (!pmic) {
867 pr_err("Cannot alloc pm8921 struct\n");
868 return -ENOMEM;
869 }
870
871 /* Read PMIC chip revision */
872 rc = msm_ssbi_read(pdev->dev.parent, REG_HWREV, &val, sizeof(val));
873 if (rc) {
874 pr_err("Failed to read hw rev reg %d:rc=%d\n", REG_HWREV, rc);
875 goto err_read_rev;
876 }
877 pr_info("PMIC revision 1: %02X\n", val);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700878 pmic->rev_registers = val;
Abhijeet Dharmapurikarcbdb53e2011-04-05 14:40:52 -0700879
880 /* Read PMIC chip revision 2 */
881 rc = msm_ssbi_read(pdev->dev.parent, REG_HWREV_2, &val, sizeof(val));
882 if (rc) {
883 pr_err("Failed to read hw rev 2 reg %d:rc=%d\n",
884 REG_HWREV_2, rc);
885 goto err_read_rev;
886 }
887 pr_info("PMIC revision 2: %02X\n", val);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700888 pmic->rev_registers |= val << BITS_PER_BYTE;
Abhijeet Dharmapurikarcbdb53e2011-04-05 14:40:52 -0700889
890 pmic->dev = &pdev->dev;
891 pm8921_drvdata.pm_chip_data = pmic;
892 platform_set_drvdata(pdev, &pm8921_drvdata);
893
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700894 /* Print out human readable version and revision names. */
895 version = pm8xxx_get_version(pmic->dev);
David Collins999480d2011-11-16 08:52:30 -0800896 revision = pm8xxx_get_revision(pmic->dev);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700897 if (version == PM8XXX_VERSION_8921) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700898 if (revision >= 0 && revision < ARRAY_SIZE(pm8921_rev_names))
899 revision_name = pm8921_rev_names[revision];
900 pr_info("PMIC version: PM8921 rev %s\n", revision_name);
David Collins999480d2011-11-16 08:52:30 -0800901 } else if (version == PM8XXX_VERSION_8922) {
902 if (revision >= 0 && revision < ARRAY_SIZE(pm8922_rev_names))
903 revision_name = pm8922_rev_names[revision];
904 pr_info("PMIC version: PM8922 rev %s\n", revision_name);
Willie Ruan51060352012-01-19 16:58:49 -0800905 } else if (version == PM8XXX_VERSION_8917) {
906 if (revision >= 0 && revision < ARRAY_SIZE(pm8917_rev_names))
907 revision_name = pm8917_rev_names[revision];
908 pr_info("PMIC version: PM8917 rev %s\n", revision_name);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700909 } else {
David Collins999480d2011-11-16 08:52:30 -0800910 WARN_ON(version != PM8XXX_VERSION_8921
Willie Ruan51060352012-01-19 16:58:49 -0800911 && version != PM8XXX_VERSION_8922
912 && version != PM8XXX_VERSION_8917);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700913 }
914
Abhijeet Dharmapurikar5caa02c2011-08-15 20:11:28 -0700915 /* Log human readable restart reason */
916 rc = msm_ssbi_read(pdev->dev.parent, REG_PM8921_PON_CNTRL_3, &val, 1);
917 if (rc) {
918 pr_err("Cannot read restart reason rc=%d\n", rc);
919 goto err_read_rev;
920 }
921 val &= PM8921_RESTART_REASON_MASK;
922 pr_info("PMIC Restart Reason: %s\n", pm8921_restart_reason[val]);
923
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700924 rc = pm8921_add_subdevices(pdata, pmic);
Abhijeet Dharmapurikarc013f0a2011-04-05 14:40:53 -0700925 if (rc) {
926 pr_err("Cannot add subdevices rc=%d\n", rc);
927 goto err;
928 }
929
930 /* gpio might not work if no irq device is found */
931 WARN_ON(pmic->irq_chip == NULL);
932
Abhijeet Dharmapurikarcbdb53e2011-04-05 14:40:52 -0700933 return 0;
934
Abhijeet Dharmapurikarc013f0a2011-04-05 14:40:53 -0700935err:
936 mfd_remove_devices(pmic->dev);
937 platform_set_drvdata(pdev, NULL);
David Collins75016742011-12-02 15:04:25 -0800938 kfree(pmic->mfd_regulators);
939 kfree(pmic->regulator_cdata);
Abhijeet Dharmapurikarcbdb53e2011-04-05 14:40:52 -0700940err_read_rev:
941 kfree(pmic);
942 return rc;
943}
944
945static int __devexit pm8921_remove(struct platform_device *pdev)
946{
947 struct pm8xxx_drvdata *drvdata;
948 struct pm8921 *pmic = NULL;
David Collins75016742011-12-02 15:04:25 -0800949 int i;
Abhijeet Dharmapurikarcbdb53e2011-04-05 14:40:52 -0700950
951 drvdata = platform_get_drvdata(pdev);
952 if (drvdata)
953 pmic = drvdata->pm_chip_data;
David Collins54e44042011-09-27 15:43:03 -0700954 if (pmic) {
955 if (pmic->dev)
956 mfd_remove_devices(pmic->dev);
957 if (pmic->irq_chip)
958 pm8xxx_irq_exit(pmic->irq_chip);
David Collins75016742011-12-02 15:04:25 -0800959 if (pmic->mfd_regulators) {
960 for (i = 0; i < ARRAY_SIZE(regulator_data); i++)
961 mutex_destroy(&regulator_data[i].pc_lock);
David Collins00f29e52012-02-13 11:38:45 -0800962 for (i = 0; i < ARRAY_SIZE(pm8917_regulator_data); i++)
963 mutex_destroy(
964 &pm8917_regulator_data[i].pc_lock);
David Collins75016742011-12-02 15:04:25 -0800965 }
David Collins54e44042011-09-27 15:43:03 -0700966 kfree(pmic->mfd_regulators);
David Collins75016742011-12-02 15:04:25 -0800967 kfree(pmic->regulator_cdata);
David Collins54e44042011-09-27 15:43:03 -0700968 kfree(pmic);
Abhijeet Dharmapurikarc013f0a2011-04-05 14:40:53 -0700969 }
Abhijeet Dharmapurikarcbdb53e2011-04-05 14:40:52 -0700970 platform_set_drvdata(pdev, NULL);
Abhijeet Dharmapurikarcbdb53e2011-04-05 14:40:52 -0700971
972 return 0;
973}
974
975static struct platform_driver pm8921_driver = {
976 .probe = pm8921_probe,
977 .remove = __devexit_p(pm8921_remove),
978 .driver = {
979 .name = "pm8921-core",
980 .owner = THIS_MODULE,
981 },
982};
983
984static int __init pm8921_init(void)
985{
986 return platform_driver_register(&pm8921_driver);
987}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700988postcore_initcall(pm8921_init);
Abhijeet Dharmapurikarcbdb53e2011-04-05 14:40:52 -0700989
990static void __exit pm8921_exit(void)
991{
992 platform_driver_unregister(&pm8921_driver);
993}
994module_exit(pm8921_exit);
995
996MODULE_LICENSE("GPL v2");
997MODULE_DESCRIPTION("PMIC 8921 core driver");
998MODULE_VERSION("1.0");
999MODULE_ALIAS("platform:pm8921-core");