blob: 31937a0b924d5375866154d42d4cf09d6f657d56 [file] [log] [blame]
Mayank Rana7e574162013-01-08 15:10:51 +05301/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
Stepan Moskovchenko39236d72011-11-30 17:42:23 -08002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13
14#include <linux/interrupt.h>
Jay Chokshi06fa7542011-12-07 13:09:17 -080015#include <linux/mfd/pm8xxx/pm8038.h>
Stepan Moskovchenko39236d72011-11-30 17:42:23 -080016#include <linux/mfd/pm8xxx/pm8xxx-adc.h>
Stepan Moskovchenko39236d72011-11-30 17:42:23 -080017#include <linux/msm_ssbi.h>
18#include <asm/mach-types.h>
19#include <mach/msm_bus_board.h>
20#include <mach/restart.h>
David Collinsfd344aa2012-08-06 15:02:03 -070021#include <mach/socinfo.h>
Stepan Moskovchenko39236d72011-11-30 17:42:23 -080022#include "devices.h"
Stepan Moskovchenko5a83dba2011-12-05 17:30:17 -080023#include "board-8930.h"
Stepan Moskovchenko39236d72011-11-30 17:42:23 -080024
25struct pm8xxx_gpio_init {
26 unsigned gpio;
27 struct pm_gpio config;
28};
29
30struct pm8xxx_mpp_init {
31 unsigned mpp;
32 struct pm8xxx_mpp_config_data config;
33};
34
David Collinsfd344aa2012-08-06 15:02:03 -070035#define PM8038_GPIO_INIT(_gpio, _dir, _buf, _val, _pull, _vin, _out_strength, \
Stepan Moskovchenko39236d72011-11-30 17:42:23 -080036 _func, _inv, _disable) \
37{ \
Jay Chokshi06fa7542011-12-07 13:09:17 -080038 .gpio = PM8038_GPIO_PM_TO_SYS(_gpio), \
Stepan Moskovchenko39236d72011-11-30 17:42:23 -080039 .config = { \
40 .direction = _dir, \
41 .output_buffer = _buf, \
42 .output_value = _val, \
43 .pull = _pull, \
44 .vin_sel = _vin, \
45 .out_strength = _out_strength, \
46 .function = _func, \
47 .inv_int_pol = _inv, \
48 .disable_pin = _disable, \
49 } \
50}
51
David Collinsfd344aa2012-08-06 15:02:03 -070052#define PM8038_MPP_INIT(_mpp, _type, _level, _control) \
Stepan Moskovchenko39236d72011-11-30 17:42:23 -080053{ \
Jay Chokshi06fa7542011-12-07 13:09:17 -080054 .mpp = PM8038_MPP_PM_TO_SYS(_mpp), \
Stepan Moskovchenko39236d72011-11-30 17:42:23 -080055 .config = { \
56 .type = PM8XXX_MPP_TYPE_##_type, \
57 .level = _level, \
58 .control = PM8XXX_MPP_##_control, \
59 } \
60}
61
David Collinsfd344aa2012-08-06 15:02:03 -070062#define PM8038_GPIO_DISABLE(_gpio) \
63 PM8038_GPIO_INIT(_gpio, PM_GPIO_DIR_IN, 0, 0, 0, PM8038_GPIO_VIN_L11, \
Stepan Moskovchenko39236d72011-11-30 17:42:23 -080064 0, 0, 0, 1)
65
David Collinsfd344aa2012-08-06 15:02:03 -070066#define PM8038_GPIO_OUTPUT(_gpio, _val) \
67 PM8038_GPIO_INIT(_gpio, PM_GPIO_DIR_OUT, PM_GPIO_OUT_BUF_CMOS, _val, \
Jay Chokshi06fa7542011-12-07 13:09:17 -080068 PM_GPIO_PULL_NO, PM8038_GPIO_VIN_L11, \
Stepan Moskovchenko39236d72011-11-30 17:42:23 -080069 PM_GPIO_STRENGTH_HIGH, \
70 PM_GPIO_FUNC_NORMAL, 0, 0)
71
David Collinsfd344aa2012-08-06 15:02:03 -070072#define PM8038_GPIO_INPUT(_gpio, _pull) \
73 PM8038_GPIO_INIT(_gpio, PM_GPIO_DIR_IN, PM_GPIO_OUT_BUF_CMOS, 0, \
Jay Chokshi06fa7542011-12-07 13:09:17 -080074 _pull, PM8038_GPIO_VIN_L11, \
Stepan Moskovchenko39236d72011-11-30 17:42:23 -080075 PM_GPIO_STRENGTH_NO, \
76 PM_GPIO_FUNC_NORMAL, 0, 0)
77
David Collinsfd344aa2012-08-06 15:02:03 -070078#define PM8038_GPIO_OUTPUT_FUNC(_gpio, _val, _func) \
79 PM8038_GPIO_INIT(_gpio, PM_GPIO_DIR_OUT, PM_GPIO_OUT_BUF_CMOS, _val, \
Jay Chokshi06fa7542011-12-07 13:09:17 -080080 PM_GPIO_PULL_NO, PM8038_GPIO_VIN_L11, \
Stepan Moskovchenko39236d72011-11-30 17:42:23 -080081 PM_GPIO_STRENGTH_HIGH, \
82 _func, 0, 0)
83
David Collinsfd344aa2012-08-06 15:02:03 -070084#define PM8038_GPIO_OUTPUT_VIN(_gpio, _val, _vin) \
85 PM8038_GPIO_INIT(_gpio, PM_GPIO_DIR_OUT, PM_GPIO_OUT_BUF_CMOS, _val, \
Stepan Moskovchenko39236d72011-11-30 17:42:23 -080086 PM_GPIO_PULL_NO, _vin, \
87 PM_GPIO_STRENGTH_HIGH, \
88 PM_GPIO_FUNC_NORMAL, 0, 0)
89
David Collinsfd344aa2012-08-06 15:02:03 -070090#define PM8917_GPIO_INIT(_gpio, _dir, _buf, _val, _pull, _vin, _out_strength, \
91 _func, _inv, _disable) \
92{ \
93 .gpio = PM8917_GPIO_PM_TO_SYS(_gpio), \
94 .config = { \
95 .direction = _dir, \
96 .output_buffer = _buf, \
97 .output_value = _val, \
98 .pull = _pull, \
99 .vin_sel = _vin, \
100 .out_strength = _out_strength, \
101 .function = _func, \
102 .inv_int_pol = _inv, \
103 .disable_pin = _disable, \
104 } \
105}
106
107#define PM8917_MPP_INIT(_mpp, _type, _level, _control) \
108{ \
109 .mpp = PM8917_MPP_PM_TO_SYS(_mpp), \
110 .config = { \
111 .type = PM8XXX_MPP_TYPE_##_type, \
112 .level = _level, \
113 .control = PM8XXX_MPP_##_control, \
114 } \
115}
116
117#define PM8917_GPIO_DISABLE(_gpio) \
118 PM8917_GPIO_INIT(_gpio, PM_GPIO_DIR_IN, 0, 0, 0, PM_GPIO_VIN_S4, \
119 0, 0, 0, 1)
120
121#define PM8917_GPIO_OUTPUT(_gpio, _val) \
122 PM8917_GPIO_INIT(_gpio, PM_GPIO_DIR_OUT, PM_GPIO_OUT_BUF_CMOS, _val, \
123 PM_GPIO_PULL_NO, PM_GPIO_VIN_S4, \
124 PM_GPIO_STRENGTH_HIGH, \
125 PM_GPIO_FUNC_NORMAL, 0, 0)
126
127#define PM8917_GPIO_INPUT(_gpio, _pull) \
128 PM8917_GPIO_INIT(_gpio, PM_GPIO_DIR_IN, PM_GPIO_OUT_BUF_CMOS, 0, \
129 _pull, PM_GPIO_VIN_S4, \
130 PM_GPIO_STRENGTH_NO, \
131 PM_GPIO_FUNC_NORMAL, 0, 0)
132
133#define PM8917_GPIO_OUTPUT_FUNC(_gpio, _val, _func) \
134 PM8917_GPIO_INIT(_gpio, PM_GPIO_DIR_OUT, PM_GPIO_OUT_BUF_CMOS, _val, \
135 PM_GPIO_PULL_NO, PM_GPIO_VIN_S4, \
136 PM_GPIO_STRENGTH_HIGH, \
137 _func, 0, 0)
138
139#define PM8917_GPIO_OUTPUT_VIN(_gpio, _val, _vin) \
140 PM8917_GPIO_INIT(_gpio, PM_GPIO_DIR_OUT, PM_GPIO_OUT_BUF_CMOS, _val, \
141 PM_GPIO_PULL_NO, _vin, \
142 PM_GPIO_STRENGTH_HIGH, \
143 PM_GPIO_FUNC_NORMAL, 0, 0)
144
145/* GPIO and MPP configurations for MSM8930 + PM8038 targets */
146
147/* Initial PM8038 GPIO configurations */
Anirudh Ghayaleb3af972011-12-13 17:29:06 +0530148static struct pm8xxx_gpio_init pm8038_gpios[] __initdata = {
149 /* keys GPIOs */
David Collinsfd344aa2012-08-06 15:02:03 -0700150 PM8038_GPIO_INPUT(3, PM_GPIO_PULL_UP_30),
151 PM8038_GPIO_INPUT(8, PM_GPIO_PULL_UP_30),
152 PM8038_GPIO_INPUT(10, PM_GPIO_PULL_UP_30),
153 PM8038_GPIO_INPUT(11, PM_GPIO_PULL_UP_30),
Amy Malochee8de95d2012-02-23 10:40:25 -0800154 /* haptics gpio */
David Collinsfd344aa2012-08-06 15:02:03 -0700155 PM8038_GPIO_OUTPUT_FUNC(7, 0, PM_GPIO_FUNC_1),
Manoj Raoc6d904c2012-06-22 00:32:14 -0700156 /* MHL PWR EN */
David Collinsfd344aa2012-08-06 15:02:03 -0700157 PM8038_GPIO_OUTPUT_VIN(5, 1, PM8038_GPIO_VIN_VPH),
Anirudh Ghayaleb3af972011-12-13 17:29:06 +0530158};
Stepan Moskovchenko39236d72011-11-30 17:42:23 -0800159
David Collinsfd344aa2012-08-06 15:02:03 -0700160/* Initial PM8038 MPP configurations */
161static struct pm8xxx_mpp_init pm8038_mpps[] __initdata = {
162};
163
164/* GPIO and MPP configurations for MSM8930 + PM8917 targets */
165
166/* Initial PM8917 GPIO configurations */
167static struct pm8xxx_gpio_init pm8917_gpios[] __initdata = {
David Collins9898ac32012-08-10 17:24:38 -0700168 /* Backlight enable control */
169 PM8917_GPIO_OUTPUT(24, 1),
David Collinsfd344aa2012-08-06 15:02:03 -0700170 /* keys GPIOs */
171 PM8917_GPIO_INPUT(27, PM_GPIO_PULL_UP_30),
172 PM8917_GPIO_INPUT(28, PM_GPIO_PULL_UP_30),
173 PM8917_GPIO_INPUT(36, PM_GPIO_PULL_UP_30),
174 PM8917_GPIO_INPUT(37, PM_GPIO_PULL_UP_30),
175 /* haptics gpio */
176 PM8917_GPIO_OUTPUT_FUNC(38, 0, PM_GPIO_FUNC_2),
177 /* MHL PWR EN */
178 PM8917_GPIO_OUTPUT_VIN(25, 1, PM_GPIO_VIN_VPH),
179};
180
181/* Initial PM8917 MPP configurations */
182static struct pm8xxx_mpp_init pm8917_mpps[] __initdata = {
Siddartha Mohanadoss0cf08262012-09-12 22:41:05 -0700183 PM8917_MPP_INIT(PM8XXX_AMUX_MPP_3, A_INPUT,
184 PM8XXX_MPP_AIN_AMUX_CH8, DIN_TO_INT),
Mayank Rana7e574162013-01-08 15:10:51 +0530185 /* Configure MPP01 for USB ID detection */
186 PM8917_MPP_INIT(1, D_INPUT, PM8921_MPP_DIG_LEVEL_S4, DIN_TO_INT),
David Collinsfd344aa2012-08-06 15:02:03 -0700187};
Stepan Moskovchenko39236d72011-11-30 17:42:23 -0800188
Jay Chokshi06fa7542011-12-07 13:09:17 -0800189void __init msm8930_pm8038_gpio_mpp_init(void)
Stepan Moskovchenko39236d72011-11-30 17:42:23 -0800190{
191 int i, rc;
192
Jay Chokshi06fa7542011-12-07 13:09:17 -0800193 for (i = 0; i < ARRAY_SIZE(pm8038_gpios); i++) {
194 rc = pm8xxx_gpio_config(pm8038_gpios[i].gpio,
195 &pm8038_gpios[i].config);
Stepan Moskovchenko39236d72011-11-30 17:42:23 -0800196 if (rc) {
197 pr_err("%s: pm8xxx_gpio_config: rc=%d\n", __func__, rc);
198 break;
199 }
200 }
201
Jay Chokshi06fa7542011-12-07 13:09:17 -0800202 /* Initial MPP configuration. */
203 for (i = 0; i < ARRAY_SIZE(pm8038_mpps); i++) {
204 rc = pm8xxx_mpp_config(pm8038_mpps[i].mpp,
205 &pm8038_mpps[i].config);
Stepan Moskovchenko39236d72011-11-30 17:42:23 -0800206 if (rc) {
207 pr_err("%s: pm8xxx_mpp_config: rc=%d\n", __func__, rc);
208 break;
209 }
210 }
211}
212
David Collinsfd344aa2012-08-06 15:02:03 -0700213void __init msm8930_pm8917_gpio_mpp_init(void)
214{
215 int i, rc;
216
217 for (i = 0; i < ARRAY_SIZE(pm8917_gpios); i++) {
218 rc = pm8xxx_gpio_config(pm8917_gpios[i].gpio,
219 &pm8917_gpios[i].config);
220 if (rc) {
221 pr_err("%s: pm8xxx_gpio_config: rc=%d\n", __func__, rc);
222 break;
223 }
224 }
225
226 /* Initial MPP configuration. */
227 for (i = 0; i < ARRAY_SIZE(pm8917_mpps); i++) {
228 rc = pm8xxx_mpp_config(pm8917_mpps[i].mpp,
229 &pm8917_mpps[i].config);
230 if (rc) {
231 pr_err("%s: pm8xxx_mpp_config: rc=%d\n", __func__, rc);
232 break;
233 }
234 }
235}
236
237static struct pm8xxx_adc_amux pm8038_adc_channels_data[] = {
Siddartha Mohanadoss3da01a12011-12-21 19:31:24 -0800238 {"vcoin", CHANNEL_VCOIN, CHAN_PATH_SCALING2, AMUX_RSV1,
239 ADC_DECIMATION_TYPE2, ADC_SCALE_DEFAULT},
240 {"vbat", CHANNEL_VBAT, CHAN_PATH_SCALING2, AMUX_RSV1,
241 ADC_DECIMATION_TYPE2, ADC_SCALE_DEFAULT},
242 {"dcin", CHANNEL_DCIN, CHAN_PATH_SCALING4, AMUX_RSV1,
243 ADC_DECIMATION_TYPE2, ADC_SCALE_DEFAULT},
244 {"ichg", CHANNEL_ICHG, CHAN_PATH_SCALING1, AMUX_RSV1,
245 ADC_DECIMATION_TYPE2, ADC_SCALE_DEFAULT},
246 {"vph_pwr", CHANNEL_VPH_PWR, CHAN_PATH_SCALING2, AMUX_RSV1,
247 ADC_DECIMATION_TYPE2, ADC_SCALE_DEFAULT},
248 {"ibat", CHANNEL_IBAT, CHAN_PATH_SCALING1, AMUX_RSV1,
249 ADC_DECIMATION_TYPE2, ADC_SCALE_DEFAULT},
250 {"batt_therm", CHANNEL_BATT_THERM, CHAN_PATH_SCALING1, AMUX_RSV2,
251 ADC_DECIMATION_TYPE2, ADC_SCALE_BATT_THERM},
252 {"batt_id", CHANNEL_BATT_ID, CHAN_PATH_SCALING1, AMUX_RSV2,
253 ADC_DECIMATION_TYPE2, ADC_SCALE_DEFAULT},
254 {"usbin", CHANNEL_USBIN, CHAN_PATH_SCALING3, AMUX_RSV1,
255 ADC_DECIMATION_TYPE2, ADC_SCALE_DEFAULT},
256 {"pmic_therm", CHANNEL_DIE_TEMP, CHAN_PATH_SCALING1, AMUX_RSV1,
257 ADC_DECIMATION_TYPE2, ADC_SCALE_PMIC_THERM},
258 {"625mv", CHANNEL_625MV, CHAN_PATH_SCALING1, AMUX_RSV1,
259 ADC_DECIMATION_TYPE2, ADC_SCALE_DEFAULT},
260 {"125v", CHANNEL_125V, CHAN_PATH_SCALING1, AMUX_RSV1,
261 ADC_DECIMATION_TYPE2, ADC_SCALE_DEFAULT},
262 {"chg_temp", CHANNEL_CHG_TEMP, CHAN_PATH_SCALING1, AMUX_RSV1,
263 ADC_DECIMATION_TYPE2, ADC_SCALE_DEFAULT},
264 {"pa_therm1", ADC_MPP_1_AMUX4, CHAN_PATH_SCALING1, AMUX_RSV1,
265 ADC_DECIMATION_TYPE2, ADC_SCALE_PA_THERM},
266 {"xo_therm", CHANNEL_MUXOFF, CHAN_PATH_SCALING1, AMUX_RSV0,
267 ADC_DECIMATION_TYPE2, ADC_SCALE_XOTHERM},
268 {"pa_therm0", ADC_MPP_1_AMUX3, CHAN_PATH_SCALING1, AMUX_RSV1,
269 ADC_DECIMATION_TYPE2, ADC_SCALE_PA_THERM},
270};
271
David Collinsfd344aa2012-08-06 15:02:03 -0700272static struct pm8xxx_adc_properties pm8038_adc_data = {
Siddartha Mohanadoss3da01a12011-12-21 19:31:24 -0800273 .adc_vdd_reference = 1800, /* milli-voltage for this adc */
274 .bitresolution = 15,
275 .bipolar = 0,
276};
277
David Collinsfd344aa2012-08-06 15:02:03 -0700278static struct pm8xxx_adc_platform_data pm8038_adc_pdata = {
279 .adc_channel = pm8038_adc_channels_data,
280 .adc_num_board_channel = ARRAY_SIZE(pm8038_adc_channels_data),
281 .adc_prop = &pm8038_adc_data,
Siddartha Mohanadoss3da01a12011-12-21 19:31:24 -0800282 .adc_mpp_base = PM8038_MPP_PM_TO_SYS(1),
283};
284
Stepan Moskovchenko39236d72011-11-30 17:42:23 -0800285static struct pm8xxx_irq_platform_data pm8xxx_irq_pdata __devinitdata = {
Jay Chokshi06fa7542011-12-07 13:09:17 -0800286 .irq_base = PM8038_IRQ_BASE,
Stepan Moskovchenko39236d72011-11-30 17:42:23 -0800287 .devirq = MSM_GPIO_TO_INT(104),
288 .irq_trigger_flag = IRQF_TRIGGER_LOW,
289};
290
291static struct pm8xxx_gpio_platform_data pm8xxx_gpio_pdata __devinitdata = {
Jay Chokshi06fa7542011-12-07 13:09:17 -0800292 .gpio_base = PM8038_GPIO_PM_TO_SYS(1),
Stepan Moskovchenko39236d72011-11-30 17:42:23 -0800293};
294
295static struct pm8xxx_mpp_platform_data pm8xxx_mpp_pdata __devinitdata = {
Jay Chokshi06fa7542011-12-07 13:09:17 -0800296 .mpp_base = PM8038_MPP_PM_TO_SYS(1),
Stepan Moskovchenko39236d72011-11-30 17:42:23 -0800297};
298
299static struct pm8xxx_rtc_platform_data pm8xxx_rtc_pdata __devinitdata = {
Jay Chokshi06fa7542011-12-07 13:09:17 -0800300 .rtc_write_enable = false,
Stepan Moskovchenko39236d72011-11-30 17:42:23 -0800301 .rtc_alarm_powerup = false,
302};
303
304static struct pm8xxx_pwrkey_platform_data pm8xxx_pwrkey_pdata = {
305 .pull_up = 1,
Amy Maloche6218d682012-01-10 17:25:03 -0800306 .kpd_trigger_delay_us = 15625,
Stepan Moskovchenko39236d72011-11-30 17:42:23 -0800307 .wakeup = 1,
308};
309
David Keitelc72d8192012-01-09 11:33:55 -0800310static int pm8921_therm_mitigation[] = {
311 1100,
312 700,
313 600,
314 325,
315};
316
317#define MAX_VOLTAGE_MV 4200
Abhijeet Dharmapurikard6d66c72012-08-06 14:02:51 -0700318#define CHG_TERM_MA 100
David Keitelc72d8192012-01-09 11:33:55 -0800319static struct pm8921_charger_platform_data pm8921_chg_pdata __devinitdata = {
David Keitelc72d8192012-01-09 11:33:55 -0800320 .update_time = 60000,
321 .max_voltage = MAX_VOLTAGE_MV,
322 .min_voltage = 3200,
David Keitel0789fc62012-06-07 17:43:27 -0700323 .uvd_thresh_voltage = 4050,
David Keitel8b079fb2012-06-28 19:14:30 -0700324 .alarm_low_mv = 3400,
325 .alarm_high_mv = 4000,
Xiaozhe Shi14e8fa12012-10-11 15:49:58 -0700326 .resume_voltage_delta = 60,
327 .resume_charge_percent = 99,
Abhijeet Dharmapurikard6d66c72012-08-06 14:02:51 -0700328 .term_current = CHG_TERM_MA,
David Keitelc72d8192012-01-09 11:33:55 -0800329 .cool_temp = 10,
Abhijeet Dharmapurikar807d60f2012-11-05 13:37:13 -0800330 .warm_temp = 45,
David Keitelc72d8192012-01-09 11:33:55 -0800331 .temp_check_period = 1,
332 .max_bat_chg_current = 1100,
333 .cool_bat_chg_current = 350,
334 .warm_bat_chg_current = 350,
335 .cool_bat_voltage = 4100,
336 .warm_bat_voltage = 4100,
337 .thermal_mitigation = pm8921_therm_mitigation,
338 .thermal_levels = ARRAY_SIZE(pm8921_therm_mitigation),
Jay Chokshi74730c72012-03-15 14:11:28 -0700339 .led_src_config = LED_SRC_VPH_PWR,
David Collinsfd344aa2012-08-06 15:02:03 -0700340 .rconn_mohm = 18,
David Keitelc72d8192012-01-09 11:33:55 -0800341};
342
Amy Maloche8a219312012-01-19 17:39:56 -0800343#define PM8038_WLED_MAX_CURRENT 25
Amy Malochea0352b52012-02-27 18:35:23 -0800344#define PM8XXX_LED_PWM_PERIOD 1000
345#define PM8XXX_LED_PWM_DUTY_MS 20
346#define PM8038_RGB_LED_MAX_CURRENT 12
Amy Maloche8a219312012-01-19 17:39:56 -0800347
348static struct led_info pm8038_led_info[] = {
349 [0] = {
350 .name = "wled",
Chandan Uddaraju194a4b52012-03-21 10:11:18 -0700351 .default_trigger = "bkl_trigger",
Amy Maloche8a219312012-01-19 17:39:56 -0800352 },
Amy Malochea0352b52012-02-27 18:35:23 -0800353 [1] = {
354 .name = "led:rgb_red",
355 .default_trigger = "battery-charging",
356 },
357 [2] = {
358 .name = "led:rgb_green",
359 },
360 [3] = {
361 .name = "led:rgb_blue",
362 },
Amy Maloche8a219312012-01-19 17:39:56 -0800363};
364
365static struct led_platform_data pm8038_led_core_pdata = {
366 .num_leds = ARRAY_SIZE(pm8038_led_info),
367 .leds = pm8038_led_info,
368};
369
370static struct wled_config_data wled_cfg = {
371 .dig_mod_gen_en = true,
372 .cs_out_en = true,
373 .ctrl_delay_us = 0,
374 .op_fdbck = true,
375 .ovp_val = WLED_OVP_32V,
376 .boost_curr_lim = WLED_CURR_LIMIT_525mA,
Amy Malochee7d7ef32013-01-30 16:16:35 -0800377 .strings = WLED_SECOND_STRING,
Amy Maloche8a219312012-01-19 17:39:56 -0800378};
379
Amy Malochea0352b52012-02-27 18:35:23 -0800380static int pm8038_led0_pwm_duty_pcts[56] = {
381 1, 4, 8, 12, 16, 20, 24, 28, 32, 36,
382 40, 44, 46, 52, 56, 60, 64, 68, 72, 76,
383 80, 84, 88, 92, 96, 100, 100, 100, 98, 95,
384 92, 88, 84, 82, 78, 74, 70, 66, 62, 58,
385 58, 54, 50, 48, 42, 38, 34, 30, 26, 22,
386 14, 10, 6, 4, 1
387};
388
Jay Chokshibe517232012-06-15 18:20:56 -0700389/*
390 * Note: There is a bug in LPG module that results in incorrect
391 * behavior of pattern when LUT index 0 is used. So effectively
392 * there are 63 usable LUT entries.
393 */
Amy Malochea0352b52012-02-27 18:35:23 -0800394static struct pm8xxx_pwm_duty_cycles pm8038_led0_pwm_duty_cycles = {
395 .duty_pcts = (int *)&pm8038_led0_pwm_duty_pcts,
396 .num_duty_pcts = ARRAY_SIZE(pm8038_led0_pwm_duty_pcts),
397 .duty_ms = PM8XXX_LED_PWM_DUTY_MS,
Jay Chokshibe517232012-06-15 18:20:56 -0700398 .start_idx = 1,
Amy Malochea0352b52012-02-27 18:35:23 -0800399};
400
Amy Maloche8a219312012-01-19 17:39:56 -0800401static struct pm8xxx_led_config pm8038_led_configs[] = {
402 [0] = {
403 .id = PM8XXX_ID_WLED,
404 .mode = PM8XXX_LED_MODE_MANUAL,
405 .max_current = PM8038_WLED_MAX_CURRENT,
Chandan Uddaraju194a4b52012-03-21 10:11:18 -0700406 .default_state = 0,
Amy Maloche8a219312012-01-19 17:39:56 -0800407 .wled_cfg = &wled_cfg,
408 },
Amy Malochea0352b52012-02-27 18:35:23 -0800409 [1] = {
410 .id = PM8XXX_ID_RGB_LED_RED,
411 .mode = PM8XXX_LED_MODE_PWM1,
412 .max_current = PM8038_RGB_LED_MAX_CURRENT,
413 .pwm_channel = 5,
414 .pwm_period_us = PM8XXX_LED_PWM_PERIOD,
415 .pwm_duty_cycles = &pm8038_led0_pwm_duty_cycles,
416 },
417 [2] = {
418 .id = PM8XXX_ID_RGB_LED_GREEN,
419 .mode = PM8XXX_LED_MODE_PWM1,
420 .max_current = PM8038_RGB_LED_MAX_CURRENT,
421 .pwm_channel = 4,
422 .pwm_period_us = PM8XXX_LED_PWM_PERIOD,
423 .pwm_duty_cycles = &pm8038_led0_pwm_duty_cycles,
424 },
425 [3] = {
426 .id = PM8XXX_ID_RGB_LED_BLUE,
427 .mode = PM8XXX_LED_MODE_PWM1,
428 .max_current = PM8038_RGB_LED_MAX_CURRENT,
429 .pwm_channel = 3,
430 .pwm_period_us = PM8XXX_LED_PWM_PERIOD,
431 .pwm_duty_cycles = &pm8038_led0_pwm_duty_cycles,
432 },
Amy Maloche8a219312012-01-19 17:39:56 -0800433};
434
435static struct pm8xxx_led_platform_data pm8xxx_leds_pdata = {
436 .led_core = &pm8038_led_core_pdata,
437 .configs = pm8038_led_configs,
438 .num_configs = ARRAY_SIZE(pm8038_led_configs),
439};
440
David Keitelc72d8192012-01-09 11:33:55 -0800441static struct pm8xxx_ccadc_platform_data pm8xxx_ccadc_pdata = {
Xiaozhe Shid69c91e2012-11-06 10:00:38 -0800442 .r_sense_uohm = 10000,
David Keitel3c378822012-06-07 13:43:22 -0700443 .calib_delay_ms = 600000,
David Keitelc72d8192012-01-09 11:33:55 -0800444};
445
Stepan Moskovchenko39236d72011-11-30 17:42:23 -0800446static struct pm8xxx_misc_platform_data pm8xxx_misc_pdata = {
447 .priority = 0,
448};
449
Asish Bhattacharya59442e22012-09-07 17:22:57 +0530450/*
451 * 0x254=0xC8 (Threshold=110, preamp bias=01)
452 * 0x255=0xC1 (Hold=110, max attn=0000, mute=1)
453 * 0x256=0xB0 (decay=101, attack=10, delay=0)
454 */
455
Asish Bhattacharya218f80b2012-03-19 02:47:34 -0700456static struct pm8xxx_spk_platform_data pm8xxx_spk_pdata = {
457 .spk_add_enable = false,
Asish Bhattacharya53c87b02012-12-12 00:19:30 +0530458 .cd_ng_threshold = 0x0,
Asish Bhattacharya59442e22012-09-07 17:22:57 +0530459 .cd_nf_preamp_bias = 0x1,
460 .cd_ng_hold = 0x6,
461 .cd_ng_max_atten = 0x0,
462 .noise_mute = 1,
463 .cd_ng_decay_rate = 0x5,
464 .cd_ng_attack_rate = 0x2,
465 .cd_delay = 0x0,
Asish Bhattacharya218f80b2012-03-19 02:47:34 -0700466};
467
David Keitelc72d8192012-01-09 11:33:55 -0800468static struct pm8921_bms_platform_data pm8921_bms_pdata __devinitdata = {
Abhijeet Dharmapurikard6d66c72012-08-06 14:02:51 -0700469 .battery_type = BATT_UNKNOWN,
Xiaozhe Shid69c91e2012-11-06 10:00:38 -0800470 .r_sense_uohm = 10000,
Abhijeet Dharmapurikard6d66c72012-08-06 14:02:51 -0700471 .v_cutoff = 3400,
472 .max_voltage_uv = MAX_VOLTAGE_MV * 1000,
473 .shutdown_soc_valid_limit = 20,
474 .adjust_soc_low_threshold = 25,
475 .chg_term_ua = CHG_TERM_MA * 1000,
David Collinsfd344aa2012-08-06 15:02:03 -0700476 .rconn_mohm = 18,
Abhijeet Dharmapurikar683472d2012-10-30 16:21:58 -0700477 .normal_voltage_calc_ms = 20000,
478 .low_voltage_calc_ms = 1000,
Anirudh Ghayal6fe4ffa2013-02-01 11:44:33 +0530479 .alarm_low_mv = 3400,
480 .alarm_high_mv = 4000,
Abhijeet Dharmapurikar48707612013-03-26 13:14:03 -0700481 .high_ocv_correction_limit_uv = 50,
482 .low_ocv_correction_limit_uv = 100,
483 .hold_soc_est = 3,
Anirudh Ghayal0f9116d2013-05-07 16:40:12 +0530484 .enable_fcc_learning = 1,
485 .min_fcc_learning_soc = 20,
486 .min_fcc_ocv_pc = 30,
Anirudh Ghayala221d912013-06-13 19:03:58 +0530487 .min_fcc_learning_samples = 5,
David Keitelc72d8192012-01-09 11:33:55 -0800488};
489
Jay Chokshi06fa7542011-12-07 13:09:17 -0800490static struct pm8038_platform_data pm8038_platform_data __devinitdata = {
Stepan Moskovchenko39236d72011-11-30 17:42:23 -0800491 .irq_pdata = &pm8xxx_irq_pdata,
492 .gpio_pdata = &pm8xxx_gpio_pdata,
493 .mpp_pdata = &pm8xxx_mpp_pdata,
494 .rtc_pdata = &pm8xxx_rtc_pdata,
495 .pwrkey_pdata = &pm8xxx_pwrkey_pdata,
Stepan Moskovchenko39236d72011-11-30 17:42:23 -0800496 .misc_pdata = &pm8xxx_misc_pdata,
David Collins1d4061b2011-12-06 15:36:40 -0800497 .regulator_pdatas = msm8930_pm8038_regulator_pdata,
David Keitelc72d8192012-01-09 11:33:55 -0800498 .charger_pdata = &pm8921_chg_pdata,
499 .bms_pdata = &pm8921_bms_pdata,
David Collinsfd344aa2012-08-06 15:02:03 -0700500 .adc_pdata = &pm8038_adc_pdata,
Amy Maloche8a219312012-01-19 17:39:56 -0800501 .leds_pdata = &pm8xxx_leds_pdata,
David Keitelc72d8192012-01-09 11:33:55 -0800502 .ccadc_pdata = &pm8xxx_ccadc_pdata,
Asish Bhattacharya218f80b2012-03-19 02:47:34 -0700503 .spk_pdata = &pm8xxx_spk_pdata,
Stepan Moskovchenko39236d72011-11-30 17:42:23 -0800504};
505
Jay Chokshi06fa7542011-12-07 13:09:17 -0800506static struct msm_ssbi_platform_data msm8930_ssbi_pm8038_pdata __devinitdata = {
Stepan Moskovchenko39236d72011-11-30 17:42:23 -0800507 .controller_type = MSM_SBI_CTRL_PMIC_ARBITER,
508 .slave = {
Jay Chokshi06fa7542011-12-07 13:09:17 -0800509 .name = "pm8038-core",
510 .platform_data = &pm8038_platform_data,
Stepan Moskovchenko39236d72011-11-30 17:42:23 -0800511 },
512};
513
David Collinsfd344aa2012-08-06 15:02:03 -0700514/* PM8917 platform data */
515
516static struct pm8xxx_adc_amux pm8917_adc_channels_data[] = {
517 {"vcoin", CHANNEL_VCOIN, CHAN_PATH_SCALING2, AMUX_RSV1,
518 ADC_DECIMATION_TYPE2, ADC_SCALE_DEFAULT},
519 {"vbat", CHANNEL_VBAT, CHAN_PATH_SCALING2, AMUX_RSV1,
520 ADC_DECIMATION_TYPE2, ADC_SCALE_DEFAULT},
521 {"dcin", CHANNEL_DCIN, CHAN_PATH_SCALING4, AMUX_RSV1,
522 ADC_DECIMATION_TYPE2, ADC_SCALE_DEFAULT},
523 {"ichg", CHANNEL_ICHG, CHAN_PATH_SCALING1, AMUX_RSV1,
524 ADC_DECIMATION_TYPE2, ADC_SCALE_DEFAULT},
525 {"vph_pwr", CHANNEL_VPH_PWR, CHAN_PATH_SCALING2, AMUX_RSV1,
526 ADC_DECIMATION_TYPE2, ADC_SCALE_DEFAULT},
527 {"ibat", CHANNEL_IBAT, CHAN_PATH_SCALING1, AMUX_RSV1,
528 ADC_DECIMATION_TYPE2, ADC_SCALE_DEFAULT},
529 {"batt_therm", CHANNEL_BATT_THERM, CHAN_PATH_SCALING1, AMUX_RSV2,
530 ADC_DECIMATION_TYPE2, ADC_SCALE_BATT_THERM},
531 {"batt_id", CHANNEL_BATT_ID, CHAN_PATH_SCALING1, AMUX_RSV2,
532 ADC_DECIMATION_TYPE2, ADC_SCALE_DEFAULT},
533 {"usbin", CHANNEL_USBIN, CHAN_PATH_SCALING3, AMUX_RSV1,
534 ADC_DECIMATION_TYPE2, ADC_SCALE_DEFAULT},
535 {"pmic_therm", CHANNEL_DIE_TEMP, CHAN_PATH_SCALING1, AMUX_RSV1,
536 ADC_DECIMATION_TYPE2, ADC_SCALE_PMIC_THERM},
537 {"625mv", CHANNEL_625MV, CHAN_PATH_SCALING1, AMUX_RSV1,
538 ADC_DECIMATION_TYPE2, ADC_SCALE_DEFAULT},
539 {"125v", CHANNEL_125V, CHAN_PATH_SCALING1, AMUX_RSV1,
540 ADC_DECIMATION_TYPE2, ADC_SCALE_DEFAULT},
541 {"chg_temp", CHANNEL_CHG_TEMP, CHAN_PATH_SCALING1, AMUX_RSV1,
542 ADC_DECIMATION_TYPE2, ADC_SCALE_DEFAULT},
543 {"xo_therm", CHANNEL_MUXOFF, CHAN_PATH_SCALING1, AMUX_RSV0,
544 ADC_DECIMATION_TYPE2, ADC_SCALE_XOTHERM},
545 {"pa_therm0", ADC_MPP_1_AMUX3, CHAN_PATH_SCALING1, AMUX_RSV1,
546 ADC_DECIMATION_TYPE2, ADC_SCALE_PA_THERM},
Siddartha Mohanadoss0cf08262012-09-12 22:41:05 -0700547 {"pa_therm1", ADC_MPP_1_AMUX8, CHAN_PATH_SCALING1, AMUX_RSV1,
548 ADC_DECIMATION_TYPE2, ADC_SCALE_PA_THERM},
David Collinsfd344aa2012-08-06 15:02:03 -0700549};
550
551static struct pm8xxx_adc_properties pm8917_adc_data = {
552 .adc_vdd_reference = 1800, /* milli-voltage for this adc */
553 .bitresolution = 15,
554 .bipolar = 0,
555};
556
557static struct pm8xxx_adc_platform_data pm8917_adc_pdata = {
558 .adc_channel = pm8917_adc_channels_data,
559 .adc_num_board_channel = ARRAY_SIZE(pm8917_adc_channels_data),
560 .adc_prop = &pm8917_adc_data,
561 .adc_mpp_base = PM8917_MPP_PM_TO_SYS(1),
562};
563
564static struct pm8921_platform_data pm8917_platform_data __devinitdata = {
565 .irq_pdata = &pm8xxx_irq_pdata,
566 .gpio_pdata = &pm8xxx_gpio_pdata,
567 .mpp_pdata = &pm8xxx_mpp_pdata,
568 .rtc_pdata = &pm8xxx_rtc_pdata,
569 .pwrkey_pdata = &pm8xxx_pwrkey_pdata,
570 .misc_pdata = &pm8xxx_misc_pdata,
David Collins4614cb92012-08-20 12:17:09 -0700571 .regulator_pdatas = msm8930_pm8917_regulator_pdata,
David Collinsfd344aa2012-08-06 15:02:03 -0700572 .charger_pdata = &pm8921_chg_pdata,
573 .bms_pdata = &pm8921_bms_pdata,
574 .adc_pdata = &pm8917_adc_pdata,
575 .ccadc_pdata = &pm8xxx_ccadc_pdata,
576};
577
578static struct msm_ssbi_platform_data msm8930_ssbi_pm8917_pdata __devinitdata = {
579 .controller_type = MSM_SBI_CTRL_PMIC_ARBITER,
580 .slave = {
581 .name = "pm8921-core",
582 .platform_data = &pm8917_platform_data,
583 },
584};
585
Stepan Moskovchenko39236d72011-11-30 17:42:23 -0800586void __init msm8930_init_pmic(void)
587{
David Collinsfd344aa2012-08-06 15:02:03 -0700588 if (socinfo_get_pmic_model() != PMIC_MODEL_PM8917) {
589 /* PM8038 configuration */
590 pmic_reset_irq = PM8038_IRQ_BASE + PM8038_RESOUT_IRQ;
591 msm8960_device_ssbi_pmic.dev.platform_data =
592 &msm8930_ssbi_pm8038_pdata;
593 pm8038_platform_data.num_regulators
594 = msm8930_pm8038_regulator_pdata_len;
David Keitelb7bf2c92012-08-24 17:54:00 -0700595 if (machine_is_msm8930_mtp())
David Collinsfd344aa2012-08-06 15:02:03 -0700596 pm8921_bms_pdata.battery_type = BATT_PALLADIUM;
David Keitelb7bf2c92012-08-24 17:54:00 -0700597 else if (machine_is_msm8930_cdp())
598 pm8921_chg_pdata.has_dc_supply = true;
David Collinsfd344aa2012-08-06 15:02:03 -0700599 } else {
600 /* PM8917 configuration */
601 pmic_reset_irq = PM8917_IRQ_BASE + PM8921_RESOUT_IRQ;
602 msm8960_device_ssbi_pmic.dev.platform_data =
603 &msm8930_ssbi_pm8917_pdata;
David Collins4614cb92012-08-20 12:17:09 -0700604 pm8917_platform_data.num_regulators
605 = msm8930_pm8917_regulator_pdata_len;
David Keitelb7bf2c92012-08-24 17:54:00 -0700606 if (machine_is_msm8930_mtp())
David Collinsfd344aa2012-08-06 15:02:03 -0700607 pm8921_bms_pdata.battery_type = BATT_PALLADIUM;
David Keitelb7bf2c92012-08-24 17:54:00 -0700608 else if (machine_is_msm8930_cdp())
609 pm8921_chg_pdata.has_dc_supply = true;
David Collinsfd344aa2012-08-06 15:02:03 -0700610 }
Abhijeet Dharmapurikarbbaef592012-10-10 10:07:51 -0700611
612 if (!machine_is_msm8930_mtp())
613 pm8921_chg_pdata.battery_less_hardware = 1;
Stepan Moskovchenko39236d72011-11-30 17:42:23 -0800614}