source: G950FXXS5DSI1
[GitHub/exynos8895/android_kernel_samsung_universal8895.git] / drivers / battery_v2 / include / sec_charging_common.h
1 /*
2 * sec_charging_common.h
3 * Samsung Mobile Charging Common Header
4 *
5 * Copyright (C) 2012 Samsung Electronics, Inc.
6 *
7 *
8 * This software is licensed under the terms of the GNU General Public
9 * License version 2, as published by the Free Software Foundation, and
10 * may be copied, distributed, and modified under those terms.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 */
18
19 #ifndef __SEC_CHARGING_COMMON_H
20 #define __SEC_CHARGING_COMMON_H __FILE__
21
22 #include <linux/module.h>
23 #include <linux/init.h>
24 #include <linux/platform_device.h>
25 #include <linux/err.h>
26 #include <linux/delay.h>
27 #include <linux/gpio.h>
28 #include <linux/irq.h>
29 #include <linux/interrupt.h>
30 #include <linux/i2c.h>
31 #include <linux/power_supply.h>
32 #include <linux/slab.h>
33 #include <linux/device.h>
34 #include <linux/wakelock.h>
35
36 #if defined(CONFIG_BATTERY_SBM_DATA)
37 #include "sec_battery_sbm.h"
38 #endif
39
40 /* definitions */
41 #define SEC_BATTERY_CABLE_HV_WIRELESS_ETX 100
42
43 #define MFC_LDO_ON 1
44 #define MFC_LDO_OFF 0
45
46 enum power_supply_ext_property {
47 POWER_SUPPLY_EXT_PROP_CHECK_SLAVE_I2C = POWER_SUPPLY_PROP_MAX,
48 POWER_SUPPLY_EXT_PROP_MULTI_CHARGER_MODE,
49 POWER_SUPPLY_EXT_PROP_WIRELESS_OP_FREQ,
50 POWER_SUPPLY_EXT_PROP_WIRELESS_TX_CMD,
51 POWER_SUPPLY_EXT_PROP_WIRELESS_TX_VAL,
52 POWER_SUPPLY_EXT_PROP_WIRELESS_TX_ID,
53 POWER_SUPPLY_EXT_PROP_WIRELESS_TX_CHG_ERR,
54 POWER_SUPPLY_EXT_PROP_AICL_CURRENT,
55 POWER_SUPPLY_EXT_PROP_CHECK_MULTI_CHARGE,
56 POWER_SUPPLY_EXT_PROP_CHIP_ID,
57 POWER_SUPPLY_EXT_PROP_SYSOVLO,
58 POWER_SUPPLY_EXT_PROP_VBAT_OVP,
59 #if defined(CONFIG_BATTERY_SBM_DATA)
60 POWER_SUPPLY_EXT_PROP_SBM_DATA,
61 #endif
62 POWER_SUPPLY_EXT_PROP_USB_CONFIGURE,
63 POWER_SUPPLY_EXT_PROP_WATER_DETECT,
64 POWER_SUPPLY_EXT_PROP_SURGE,
65 POWER_SUPPLY_EXT_PROP_SUB_PBA_TEMP_REC,
66 POWER_SUPPLY_EXT_PROP_HV_DISABLE,
67 POWER_SUPPLY_EXT_PROP_WC_CONTROL,
68 POWER_SUPPLY_EXT_PROP_CALL_EVENT,
69 };
70
71 enum sec_battery_usb_conf {
72 USB_CURRENT_UNCONFIGURED = 100,
73 USB_CURRENT_HIGH_SPEED = 500,
74 USB_CURRENT_SUPER_SPEED = 900,
75 };
76
77 enum sec_battery_rp_curr {
78 RP_CURRENT_RP1 = 500,
79 RP_CURRENT_RP2 = 1500,
80 RP_CURRENT_RP3 = 3000,
81 };
82
83 enum power_supply_ext_health {
84 POWER_SUPPLY_HEALTH_VSYS_OVP = POWER_SUPPLY_HEALTH_MAX,
85 POWER_SUPPLY_HEALTH_VBAT_OVP,
86 };
87
88 enum sec_battery_cable {
89 SEC_BATTERY_CABLE_UNKNOWN = 0,
90 SEC_BATTERY_CABLE_NONE, /* 1 */
91 SEC_BATTERY_CABLE_PREPARE_TA, /* 2 */
92 SEC_BATTERY_CABLE_TA, /* 3 */
93 SEC_BATTERY_CABLE_USB, /* 4 */
94 SEC_BATTERY_CABLE_USB_CDP, /* 5 */
95 SEC_BATTERY_CABLE_9V_TA, /* 6 */
96 SEC_BATTERY_CABLE_9V_ERR, /* 7 */
97 SEC_BATTERY_CABLE_9V_UNKNOWN, /* 8 */
98 SEC_BATTERY_CABLE_12V_TA, /* 9 */
99 SEC_BATTERY_CABLE_WIRELESS, /* 10 */
100 SEC_BATTERY_CABLE_HV_WIRELESS, /* 11 */
101 SEC_BATTERY_CABLE_PMA_WIRELESS, /* 12 */
102 SEC_BATTERY_CABLE_WIRELESS_PACK, /* 13 */
103 SEC_BATTERY_CABLE_WIRELESS_HV_PACK, /* 14 */
104 SEC_BATTERY_CABLE_WIRELESS_STAND, /* 15 */
105 SEC_BATTERY_CABLE_WIRELESS_HV_STAND, /* 16 */
106 SEC_BATTERY_CABLE_QC20, /* 17 */
107 SEC_BATTERY_CABLE_QC30, /* 18 */
108 SEC_BATTERY_CABLE_PDIC, /* 19 */
109 SEC_BATTERY_CABLE_UARTOFF, /* 20 */
110 SEC_BATTERY_CABLE_OTG, /* 21 */
111 SEC_BATTERY_CABLE_LAN_HUB, /* 22 */
112 SEC_BATTERY_CABLE_POWER_SHARING, /* 23 */
113 SEC_BATTERY_CABLE_HMT_CONNECTED, /* 24 */
114 SEC_BATTERY_CABLE_HMT_CHARGE, /* 25 */
115 SEC_BATTERY_CABLE_HV_TA_CHG_LIMIT, /* 26 */
116 SEC_BATTERY_CABLE_WIRELESS_VEHICLE, /* 27 */
117 SEC_BATTERY_CABLE_WIRELESS_HV_VEHICLE, /* 28 */
118 SEC_BATTERY_CABLE_PREPARE_WIRELESS_HV, /* 29 */
119 SEC_BATTERY_CABLE_TIMEOUT, /* 30 */
120 SEC_BATTERY_CABLE_SMART_OTG, /* 31 */
121 SEC_BATTERY_CABLE_SMART_NOTG, /* 32 */
122 SEC_BATTERY_CABLE_WIRELESS_TX, /* 33 */
123 SEC_BATTERY_CABLE_MAX, /* 34 */
124 };
125
126 enum sec_battery_voltage_mode {
127 /* average voltage */
128 SEC_BATTERY_VOLTAGE_AVERAGE = 0,
129 /* open circuit voltage */
130 SEC_BATTERY_VOLTAGE_OCV,
131 };
132
133 enum sec_battery_current_mode {
134 /* uA */
135 SEC_BATTERY_CURRENT_UA = 0,
136 /* mA */
137 SEC_BATTERY_CURRENT_MA,
138 };
139
140 enum sec_battery_capacity_mode {
141 /* designed capacity */
142 SEC_BATTERY_CAPACITY_DESIGNED = 0,
143 /* absolute capacity by fuel gauge */
144 SEC_BATTERY_CAPACITY_ABSOLUTE,
145 /* temperary capacity in the time */
146 SEC_BATTERY_CAPACITY_TEMPERARY,
147 /* current capacity now */
148 SEC_BATTERY_CAPACITY_CURRENT,
149 /* cell aging information */
150 SEC_BATTERY_CAPACITY_AGEDCELL,
151 /* charge count */
152 SEC_BATTERY_CAPACITY_CYCLE,
153 /* full capacity rep */
154 SEC_BATTERY_CAPACITY_FULL,
155 /* QH capacity */
156 SEC_BATTERY_CAPACITY_QH,
157 /* vfsoc */
158 SEC_BATTERY_CAPACITY_VFSOC,
159 };
160
161 /* ext_event */
162 #define BATT_EXT_EVENT_NONE 0x00000000
163 #define BATT_EXT_EVENT_CALL 0x00000004
164
165 enum sec_wireless_info_mode {
166 SEC_WIRELESS_OTP_FIRM_RESULT = 0,
167 SEC_WIRELESS_IC_REVISION,
168 SEC_WIRELESS_IC_GRADE,
169 SEC_WIRELESS_OTP_FIRM_VER_BIN,
170 SEC_WIRELESS_OTP_FIRM_VER,
171 SEC_WIRELESS_TX_FIRM_RESULT,
172 SEC_WIRELESS_TX_FIRM_VER,
173 SEC_TX_FIRMWARE,
174 SEC_WIRELESS_OTP_FIRM_VERIFY,
175 SEC_WIRELESS_MST_SWITCH_VERIFY,
176 };
177
178 enum sec_wireless_firm_update_mode {
179 SEC_WIRELESS_RX_SDCARD_MODE = 0,
180 SEC_WIRELESS_RX_BUILT_IN_MODE,
181 SEC_WIRELESS_TX_ON_MODE,
182 SEC_WIRELESS_TX_OFF_MODE,
183 SEC_WIRELESS_RX_INIT,
184 };
185
186 enum sec_tx_firmware_mode {
187 SEC_TX_OFF = 0,
188 SEC_TX_STANDBY,
189 SEC_TX_POWER_TRANSFER,
190 SEC_TX_ERROR,
191 };
192
193 enum sec_wireless_control_mode {
194 WIRELESS_VOUT_OFF = 0,
195 WIRELESS_VOUT_NORMAL_VOLTAGE, /* 5V , reserved by factory */
196 WIRELESS_VOUT_RESERVED, /* 6V */
197 WIRELESS_VOUT_HIGH_VOLTAGE, /* 9V , reserved by factory */
198 WIRELESS_VOUT_CC_CV_VOUT,
199 WIRELESS_VOUT_CV_CALL,
200 WIRELESS_VOUT_CC_CALL,
201 WIRELESS_VOUT_5V,
202 WIRELESS_VOUT_9V,
203 WIRELESS_VOUT_10V,
204 WIRELESS_VOUT_5V_STEP,
205 WIRELESS_VOUT_9V_STEP,
206 WIRELESS_VOUT_10V_STEP,
207 WIRELESS_PAD_FAN_OFF,
208 WIRELESS_PAD_FAN_ON,
209 WIRELESS_PAD_LED_OFF,
210 WIRELESS_PAD_LED_ON,
211 WIRELESS_VRECT_ADJ_ON,
212 WIRELESS_VRECT_ADJ_OFF,
213 WIRELESS_VRECT_ADJ_ROOM_0,
214 WIRELESS_VRECT_ADJ_ROOM_1,
215 WIRELESS_VRECT_ADJ_ROOM_2,
216 WIRELESS_VRECT_ADJ_ROOM_3,
217 WIRELESS_VRECT_ADJ_ROOM_4,
218 WIRELESS_VRECT_ADJ_ROOM_5,
219 WIRELESS_CLAMP_ENABLE,
220 };
221
222 enum sec_wireless_pad_mode {
223 SEC_WIRELESS_PAD_NONE = 0,
224 SEC_WIRELESS_PAD_WPC,
225 SEC_WIRELESS_PAD_WPC_HV,
226 SEC_WIRELESS_PAD_WPC_PACK,
227 SEC_WIRELESS_PAD_WPC_PACK_HV,
228 SEC_WIRELESS_PAD_WPC_STAND,
229 SEC_WIRELESS_PAD_WPC_STAND_HV,
230 SEC_WIRELESS_PAD_PMA,
231 SEC_WIRELESS_PAD_VEHICLE,
232 SEC_WIRELESS_PAD_VEHICLE_HV,
233 SEC_WIRELESS_PAD_PREPARE_HV,
234 SEC_WIRELESS_PAD_A4WP,
235 SEC_WIRELESS_PAD_TX,
236 };
237
238 enum sec_wireless_pad_id {
239 WC_PAD_ID_UNKNOWN = 0x00,
240 /* 0x01~1F : Single Port */
241 WC_PAD_ID_SNGL_NOBLE = 0x10,
242 WC_PAD_ID_SNGL_VEHICLE,
243 WC_PAD_ID_SNGL_MINI,
244 WC_PAD_ID_SNGL_ZERO,
245 WC_PAD_ID_SNGL_DREAM,
246 /* 0x20~2F : Multi Port */
247 /* 0x30~3F : Stand Type */
248 WC_PAD_ID_STAND_HERO = 0x30,
249 WC_PAD_ID_STAND_DREAM,
250 /* 0x40~4F : External Battery Pack */
251 WC_PAD_ID_EXT_BATT_PACK = 0x40,
252 WC_PAD_ID_EXT_BATT_PACK_TA,
253 /* 0x50~6F : Reserved */
254 WC_PAD_ID_MAX = 0x6F,
255 };
256
257 enum sec_battery_temp_control_source {
258 TEMP_CONTROL_SOURCE_NONE = 0,
259 TEMP_CONTROL_SOURCE_BAT_THM,
260 TEMP_CONTROL_SOURCE_CHG_THM,
261 TEMP_CONTROL_SOURCE_WPC_THM,
262 TEMP_CONTROL_SOURCE_USB_THM,
263 };
264
265 /* ADC type */
266 enum sec_battery_adc_type {
267 /* NOT using this ADC channel */
268 SEC_BATTERY_ADC_TYPE_NONE = 0,
269 /* ADC in AP */
270 SEC_BATTERY_ADC_TYPE_AP,
271 /* ADC by additional IC */
272 SEC_BATTERY_ADC_TYPE_IC,
273 SEC_BATTERY_ADC_TYPE_NUM
274 };
275
276 enum sec_battery_adc_channel {
277 SEC_BAT_ADC_CHANNEL_CABLE_CHECK = 0,
278 SEC_BAT_ADC_CHANNEL_BAT_CHECK,
279 SEC_BAT_ADC_CHANNEL_TEMP,
280 SEC_BAT_ADC_CHANNEL_TEMP_AMBIENT,
281 SEC_BAT_ADC_CHANNEL_FULL_CHECK,
282 SEC_BAT_ADC_CHANNEL_VOLTAGE_NOW,
283 SEC_BAT_ADC_CHANNEL_CHG_TEMP,
284 SEC_BAT_ADC_CHANNEL_INBAT_VOLTAGE,
285 SEC_BAT_ADC_CHANNEL_DISCHARGING_CHECK,
286 SEC_BAT_ADC_CHANNEL_DISCHARGING_NTC,
287 SEC_BAT_ADC_CHANNEL_WPC_TEMP,
288 SEC_BAT_ADC_CHANNEL_SLAVE_CHG_TEMP,
289 SEC_BAT_ADC_CHANNEL_USB_TEMP,
290 SEC_BAT_ADC_CHANNEL_NUM,
291 };
292
293 enum sec_battery_charge_mode {
294 SEC_BAT_CHG_MODE_CHARGING = 0,
295 SEC_BAT_CHG_MODE_CHARGING_OFF,
296 SEC_BAT_CHG_MODE_BUCK_OFF,
297 };
298
299 /* charging mode */
300 enum sec_battery_charging_mode {
301 /* no charging */
302 SEC_BATTERY_CHARGING_NONE = 0,
303 /* 1st charging */
304 SEC_BATTERY_CHARGING_1ST,
305 /* 2nd charging */
306 SEC_BATTERY_CHARGING_2ND,
307 /* recharging */
308 SEC_BATTERY_CHARGING_RECHARGING,
309 };
310
311 struct sec_bat_adc_api {
312 bool (*init)(struct platform_device *);
313 bool (*exit)(void);
314 int (*read)(unsigned int);
315 };
316 #define sec_bat_adc_api_t struct sec_bat_adc_api
317
318 /* monitor activation */
319 enum sec_battery_polling_time_type {
320 /* same order with power supply status */
321 SEC_BATTERY_POLLING_TIME_BASIC = 0,
322 SEC_BATTERY_POLLING_TIME_CHARGING,
323 SEC_BATTERY_POLLING_TIME_DISCHARGING,
324 SEC_BATTERY_POLLING_TIME_NOT_CHARGING,
325 SEC_BATTERY_POLLING_TIME_SLEEP,
326 };
327
328 enum sec_battery_monitor_polling {
329 /* polling work queue */
330 SEC_BATTERY_MONITOR_WORKQUEUE,
331 /* alarm polling */
332 SEC_BATTERY_MONITOR_ALARM,
333 /* timer polling (NOT USE) */
334 SEC_BATTERY_MONITOR_TIMER,
335 };
336 #define sec_battery_monitor_polling_t \
337 enum sec_battery_monitor_polling
338
339 /* full charged check : POWER_SUPPLY_PROP_STATUS */
340 enum sec_battery_full_charged {
341 SEC_BATTERY_FULLCHARGED_NONE = 0,
342 /* current check by ADC */
343 SEC_BATTERY_FULLCHARGED_ADC,
344 /* fuel gauge current check */
345 SEC_BATTERY_FULLCHARGED_FG_CURRENT,
346 /* time check */
347 SEC_BATTERY_FULLCHARGED_TIME,
348 /* SOC check */
349 SEC_BATTERY_FULLCHARGED_SOC,
350 /* charger GPIO, NO additional full condition */
351 SEC_BATTERY_FULLCHARGED_CHGGPIO,
352 /* charger interrupt, NO additional full condition */
353 SEC_BATTERY_FULLCHARGED_CHGINT,
354 /* charger power supply property, NO additional full condition */
355 SEC_BATTERY_FULLCHARGED_CHGPSY,
356 };
357
358 #define sec_battery_full_charged_t \
359 enum sec_battery_full_charged
360
361 /* full check condition type (can be used overlapped) */
362 #define sec_battery_full_condition_t unsigned int
363 /* SEC_BATTERY_FULL_CONDITION_NOTIMEFULL
364 * full-charged by absolute-timer only in high voltage
365 */
366 #define SEC_BATTERY_FULL_CONDITION_NOTIMEFULL 1
367 /* SEC_BATTERY_FULL_CONDITION_NOSLEEPINFULL
368 * do not set polling time as sleep polling time in full-charged
369 */
370 #define SEC_BATTERY_FULL_CONDITION_NOSLEEPINFULL 2
371 /* SEC_BATTERY_FULL_CONDITION_SOC
372 * use capacity for full-charged check
373 */
374 #define SEC_BATTERY_FULL_CONDITION_SOC 4
375 /* SEC_BATTERY_FULL_CONDITION_VCELL
376 * use VCELL for full-charged check
377 */
378 #define SEC_BATTERY_FULL_CONDITION_VCELL 8
379 /* SEC_BATTERY_FULL_CONDITION_AVGVCELL
380 * use average VCELL for full-charged check
381 */
382 #define SEC_BATTERY_FULL_CONDITION_AVGVCELL 16
383 /* SEC_BATTERY_FULL_CONDITION_OCV
384 * use OCV for full-charged check
385 */
386 #define SEC_BATTERY_FULL_CONDITION_OCV 32
387
388 /* recharge check condition type (can be used overlapped) */
389 #define sec_battery_recharge_condition_t unsigned int
390 /* SEC_BATTERY_RECHARGE_CONDITION_SOC
391 * use capacity for recharging check
392 */
393 #define SEC_BATTERY_RECHARGE_CONDITION_SOC 1
394 /* SEC_BATTERY_RECHARGE_CONDITION_AVGVCELL
395 * use average VCELL for recharging check
396 */
397 #define SEC_BATTERY_RECHARGE_CONDITION_AVGVCELL 2
398 /* SEC_BATTERY_RECHARGE_CONDITION_VCELL
399 * use VCELL for recharging check
400 */
401 #define SEC_BATTERY_RECHARGE_CONDITION_VCELL 4
402
403 /* battery check : POWER_SUPPLY_PROP_PRESENT */
404 enum sec_battery_check {
405 /* No Check for internal battery */
406 SEC_BATTERY_CHECK_NONE,
407 /* by ADC */
408 SEC_BATTERY_CHECK_ADC,
409 /* by callback function (battery certification by 1 wired)*/
410 SEC_BATTERY_CHECK_CALLBACK,
411 /* by PMIC */
412 SEC_BATTERY_CHECK_PMIC,
413 /* by fuel gauge */
414 SEC_BATTERY_CHECK_FUELGAUGE,
415 /* by charger */
416 SEC_BATTERY_CHECK_CHARGER,
417 /* by interrupt (use check_battery_callback() to check battery) */
418 SEC_BATTERY_CHECK_INT,
419 };
420 #define sec_battery_check_t \
421 enum sec_battery_check
422
423 /* OVP, UVLO check : POWER_SUPPLY_PROP_HEALTH */
424 enum sec_battery_ovp_uvlo {
425 /* by callback function */
426 SEC_BATTERY_OVP_UVLO_CALLBACK,
427 /* by PMIC polling */
428 SEC_BATTERY_OVP_UVLO_PMICPOLLING,
429 /* by PMIC interrupt */
430 SEC_BATTERY_OVP_UVLO_PMICINT,
431 /* by charger polling */
432 SEC_BATTERY_OVP_UVLO_CHGPOLLING,
433 /* by charger interrupt */
434 SEC_BATTERY_OVP_UVLO_CHGINT,
435 };
436 #define sec_battery_ovp_uvlo_t \
437 enum sec_battery_ovp_uvlo
438
439 /* thermal source */
440 enum sec_battery_thermal_source {
441 /* by fuel gauge */
442 SEC_BATTERY_THERMAL_SOURCE_FG,
443 /* by external source */
444 SEC_BATTERY_THERMAL_SOURCE_CALLBACK,
445 /* by ADC */
446 SEC_BATTERY_THERMAL_SOURCE_ADC,
447 };
448 #define sec_battery_thermal_source_t \
449 enum sec_battery_thermal_source
450
451 /* temperature check type */
452 enum sec_battery_temp_check {
453 SEC_BATTERY_TEMP_CHECK_NONE = 0, /* no temperature check */
454 SEC_BATTERY_TEMP_CHECK_ADC, /* by ADC value */
455 SEC_BATTERY_TEMP_CHECK_TEMP, /* by temperature */
456 };
457 #define sec_battery_temp_check_t \
458 enum sec_battery_temp_check
459
460 /* cable check (can be used overlapped) */
461 #define sec_battery_cable_check_t unsigned int
462 /* SEC_BATTERY_CABLE_CHECK_NOUSBCHARGE
463 * for USB cable in tablet model,
464 * status is stuck into discharging,
465 * but internal charging logic is working
466 */
467 #define SEC_BATTERY_CABLE_CHECK_NOUSBCHARGE 1
468 /* SEC_BATTERY_CABLE_CHECK_NOINCOMPATIBLECHARGE
469 * for incompatible charger
470 * (Not compliant to USB specification,
471 * cable type is SEC_BATTERY_CABLE_UNKNOWN),
472 * do NOT charge and show message to user
473 * (only for VZW)
474 */
475 #define SEC_BATTERY_CABLE_CHECK_NOINCOMPATIBLECHARGE 2
476 /* SEC_BATTERY_CABLE_CHECK_PSY
477 * check cable by power supply set_property
478 */
479 #define SEC_BATTERY_CABLE_CHECK_PSY 4
480 /* SEC_BATTERY_CABLE_CHECK_INT
481 * check cable by interrupt
482 */
483 #define SEC_BATTERY_CABLE_CHECK_INT 8
484 /* SEC_BATTERY_CABLE_CHECK_CHGINT
485 * check cable by charger interrupt
486 */
487 #define SEC_BATTERY_CABLE_CHECK_CHGINT 16
488 /* SEC_BATTERY_CABLE_CHECK_POLLING
489 * check cable by GPIO polling
490 */
491 #define SEC_BATTERY_CABLE_CHECK_POLLING 32
492
493 /* check cable source (can be used overlapped) */
494 #define sec_battery_cable_source_t unsigned int
495 /* SEC_BATTERY_CABLE_SOURCE_EXTERNAL
496 * already given by external argument
497 */
498 #define SEC_BATTERY_CABLE_SOURCE_EXTERNAL 1
499 /* SEC_BATTERY_CABLE_SOURCE_CALLBACK
500 * by callback (MUIC, USB switch)
501 */
502 #define SEC_BATTERY_CABLE_SOURCE_CALLBACK 2
503 /* SEC_BATTERY_CABLE_SOURCE_ADC
504 * by ADC
505 */
506 #define SEC_BATTERY_CABLE_SOURCE_ADC 4
507
508 /* capacity calculation type (can be used overlapped) */
509 #define sec_fuelgauge_capacity_type_t int
510 /* SEC_FUELGAUGE_CAPACITY_TYPE_RESET
511 * use capacity information to reset fuel gauge
512 * (only for driver algorithm, can NOT be set by user)
513 */
514 #define SEC_FUELGAUGE_CAPACITY_TYPE_RESET (-1)
515 /* SEC_FUELGAUGE_CAPACITY_TYPE_RAW
516 * use capacity information from fuel gauge directly
517 */
518 #define SEC_FUELGAUGE_CAPACITY_TYPE_RAW 1
519 /* SEC_FUELGAUGE_CAPACITY_TYPE_SCALE
520 * rescale capacity by scaling, need min and max value for scaling
521 */
522 #define SEC_FUELGAUGE_CAPACITY_TYPE_SCALE 2
523 /* SEC_FUELGAUGE_CAPACITY_TYPE_DYNAMIC_SCALE
524 * change only maximum capacity dynamically
525 * to keep time for every SOC unit
526 */
527 #define SEC_FUELGAUGE_CAPACITY_TYPE_DYNAMIC_SCALE 4
528 /* SEC_FUELGAUGE_CAPACITY_TYPE_ATOMIC
529 * change capacity value by only -1 or +1
530 * no sudden change of capacity
531 */
532 #define SEC_FUELGAUGE_CAPACITY_TYPE_ATOMIC 8
533 /* SEC_FUELGAUGE_CAPACITY_TYPE_SKIP_ABNORMAL
534 * skip current capacity value
535 * if it is abnormal value
536 */
537 #define SEC_FUELGAUGE_CAPACITY_TYPE_SKIP_ABNORMAL 16
538
539 /* charger function settings (can be used overlapped) */
540 #define sec_charger_functions_t unsigned int
541 /* SEC_CHARGER_NO_GRADUAL_CHARGING_CURRENT
542 * disable gradual charging current setting
543 * SUMMIT:AICL, MAXIM:regulation loop
544 */
545 #define SEC_CHARGER_NO_GRADUAL_CHARGING_CURRENT 1
546
547 /* SEC_CHARGER_MINIMUM_SIOP_CHARGING_CURRENT
548 * charging current should be over than USB charging current
549 */
550 #define SEC_CHARGER_MINIMUM_SIOP_CHARGING_CURRENT 2
551
552 /**
553 * struct sec_bat_adc_table_data - adc to temperature table for sec battery
554 * driver
555 * @adc: adc value
556 * @temperature: temperature(C) * 10
557 */
558 struct sec_bat_adc_table_data {
559 int adc;
560 int data;
561 };
562 #define sec_bat_adc_table_data_t \
563 struct sec_bat_adc_table_data
564
565 struct sec_bat_adc_region {
566 int min;
567 int max;
568 };
569 #define sec_bat_adc_region_t \
570 struct sec_bat_adc_region
571
572 struct sec_charging_current {
573 unsigned int input_current_limit;
574 unsigned int fast_charging_current;
575 };
576
577 #define sec_charging_current_t \
578 struct sec_charging_current
579
580 #if defined(CONFIG_BATTERY_AGE_FORECAST)
581 struct sec_age_data {
582 int cycle;
583 unsigned int float_voltage;
584 unsigned int recharge_condition_vcell;
585 unsigned int full_condition_vcell;
586 unsigned int full_condition_soc;
587 };
588
589 #define sec_age_data_t \
590 struct sec_age_data
591 #endif
592
593 struct sec_battery_platform_data {
594 /* NO NEED TO BE CHANGED */
595 /* callback functions */
596 void (*initial_check)(void);
597 void (*monitor_additional_check)(void);
598 bool (*bat_gpio_init)(void);
599 bool (*fg_gpio_init)(void);
600 bool (*is_lpm)(void);
601 bool (*check_jig_status)(void);
602 bool (*is_interrupt_cable_check_possible)(int);
603 int (*check_cable_callback)(void);
604 int (*get_cable_from_extended_cable_type)(int);
605 bool (*cable_switch_check)(void);
606 bool (*cable_switch_normal)(void);
607 bool (*check_cable_result_callback)(int);
608 bool (*check_battery_callback)(void);
609 bool (*check_battery_result_callback)(void);
610 int (*ovp_uvlo_callback)(void);
611 bool (*ovp_uvlo_result_callback)(int);
612 bool (*fuelalert_process)(bool);
613 bool (*get_temperature_callback)(
614 enum power_supply_property,
615 union power_supply_propval*);
616
617 /* ADC API for each ADC type */
618 sec_bat_adc_api_t adc_api[SEC_BATTERY_ADC_TYPE_NUM];
619 /* ADC region by power supply type
620 * ADC region should be exclusive
621 */
622 sec_bat_adc_region_t *cable_adc_value;
623 /* charging current for type (0: not use) */
624 sec_charging_current_t *charging_current;
625 unsigned int *polling_time;
626 char *chip_vendor;
627 unsigned int temp_adc_type;
628 /* NO NEED TO BE CHANGED */
629 unsigned int pre_afc_input_current;
630 unsigned int pre_wc_afc_input_current;
631 unsigned int store_mode_afc_input_current;
632 unsigned int store_mode_hv_wireless_input_current;
633
634 char *pmic_name;
635
636 /* battery */
637 char *vendor;
638 int technology;
639 int battery_type;
640 void *battery_data;
641
642 int bat_gpio_ta_nconnected;
643 /* 1 : active high, 0 : active low */
644 int bat_polarity_ta_nconnected;
645 int bat_irq;
646 int bat_irq_gpio; /* BATT_INT(BAT_ID detecting) */
647 unsigned long bat_irq_attr;
648 int jig_irq;
649 unsigned long jig_irq_attr;
650 sec_battery_cable_check_t cable_check_type;
651 sec_battery_cable_source_t cable_source_type;
652
653 bool use_LED; /* use charging LED */
654
655 /* flag for skipping the swelling mode */
656 bool swelling_mode_skip_in_high_temp;
657 /* sustaining event after deactivated (second) */
658 unsigned int event_waiting_time;
659
660 /* battery swelling */
661 int swelling_high_temp_block;
662 int swelling_high_temp_recov;
663 int swelling_wc_high_temp_recov;
664 int swelling_low_temp_block_1st;
665 int swelling_low_temp_recov_1st;
666 int swelling_low_temp_block_2nd;
667 int swelling_low_temp_recov_2nd;
668 unsigned int swelling_low_temp_current;
669 unsigned int swelling_low_temp_topoff;
670 unsigned int swelling_high_temp_current;
671 unsigned int swelling_high_temp_topoff;
672 unsigned int swelling_wc_high_temp_current;
673 unsigned int swelling_wc_low_temp_current;
674
675 unsigned int swelling_normal_float_voltage;
676 unsigned int swelling_drop_float_voltage;
677 unsigned int swelling_high_rechg_voltage;
678 unsigned int swelling_low_rechg_voltage;
679 unsigned int swelling_drop_voltage_condition;
680 unsigned int wa_fl_check_count;
681
682 unsigned int wa_volt_recov;
683 unsigned int wa_volt_thr;
684 unsigned int wa_float_voltage;
685
686 #if defined(CONFIG_CALC_TIME_TO_FULL)
687 unsigned int ttf_hv_12v_charge_current;
688 unsigned int ttf_hv_charge_current;
689 unsigned int ttf_hv_wireless_charge_current;
690 unsigned int ttf_wireless_charge_current;
691 #endif
692
693 #if defined(CONFIG_STEP_CHARGING)
694 /* step charging */
695 unsigned int *step_charging_condition;
696 unsigned int *step_charging_current;
697 #endif
698
699 /* Monitor setting */
700 sec_battery_monitor_polling_t polling_type;
701 /* for initial check */
702 unsigned int monitor_initial_count;
703
704 /* Battery check */
705 sec_battery_check_t battery_check_type;
706 /* how many times do we need to check battery */
707 unsigned int check_count;
708 /* ADC */
709 /* battery check ADC maximum value */
710 unsigned int check_adc_max;
711 /* battery check ADC minimum value */
712 unsigned int check_adc_min;
713
714 /* OVP/UVLO check */
715 sec_battery_ovp_uvlo_t ovp_uvlo_check_type;
716
717 sec_battery_thermal_source_t thermal_source;
718
719 /*
720 * inbat_adc_table
721 * in-battery voltage check for table models:
722 * To read real battery voltage with Jig cable attached,
723 * dedicated hw pin & conversion table of adc-voltage are required
724 */
725 sec_bat_adc_table_data_t *temp_adc_table;
726 sec_bat_adc_table_data_t *temp_amb_adc_table;
727 sec_bat_adc_table_data_t *usb_temp_adc_table;
728 sec_bat_adc_table_data_t *chg_temp_adc_table;
729 sec_bat_adc_table_data_t *wpc_temp_adc_table;
730 sec_bat_adc_table_data_t *slave_chg_temp_adc_table;
731 sec_bat_adc_table_data_t *inbat_adc_table;
732
733 unsigned int temp_adc_table_size;
734 unsigned int temp_amb_adc_table_size;
735 unsigned int usb_temp_adc_table_size;
736 unsigned int chg_temp_adc_table_size;
737 unsigned int wpc_temp_adc_table_size;
738 unsigned int slave_chg_temp_adc_table_size;
739 unsigned int inbat_adc_table_size;
740
741 sec_battery_temp_check_t temp_check_type;
742 unsigned int temp_check_count;
743 unsigned int usb_temp_check;
744 unsigned int usb_thermal_source; /* To confirm the usb temperature */
745 unsigned int chg_temp_check; /* Control the charging current depending on the chg_thm */
746 unsigned int chg_thermal_source; /* To confirm the charger temperature */
747 unsigned int wpc_temp_check;
748 unsigned int wpc_thermal_source; /* To confirm the wpc temperature */
749 unsigned int coil_temp_check;
750 unsigned int coil_thermal_source; /* To confirm the coil temperature */
751 unsigned int slave_chg_temp_check;
752 unsigned int slave_thermal_source; /* To confirm the slave charger temperature */
753 unsigned int inbat_voltage;
754
755 /*
756 * limit can be ADC value or Temperature
757 * depending on temp_check_type
758 * temperature should be temp x 10 (0.1 degree)
759 */
760 int temp_highlimit_threshold_normal;
761 int temp_highlimit_recovery_normal;
762 int temp_high_threshold_normal;
763 int temp_high_recovery_normal;
764 int temp_low_threshold_normal;
765 int temp_low_recovery_normal;
766 int temp_highlimit_threshold_lpm;
767 int temp_highlimit_recovery_lpm;
768 int temp_high_threshold_lpm;
769 int temp_high_recovery_lpm;
770 int temp_low_threshold_lpm;
771 int temp_low_recovery_lpm;
772 int wpc_high_threshold_normal;
773 int wpc_high_recovery_normal;
774 int wpc_low_threshold_normal;
775 int wpc_low_recovery_normal;
776 int chg_12v_high_temp;
777 int chg_high_temp;
778 int chg_high_temp_recovery;
779 unsigned int chg_charging_limit_current;
780 unsigned int chg_input_limit_current;
781 unsigned int wpc_temp_control_source;
782 unsigned int wpc_temp_lcd_on_control_source;
783 int wpc_high_temp;
784 int wpc_high_temp_recovery;
785 unsigned int wpc_charging_limit_current;
786 int wpc_lcd_on_high_temp;
787 int wpc_lcd_on_high_temp_rec;
788 unsigned int wpc_lcd_on_charging_limit_current;
789 unsigned int sleep_mode_limit_current;
790 unsigned int wc_full_input_limit_current;
791 unsigned int wc_cv_current;
792 unsigned int wc_cv_tx_current;
793 unsigned int wc_cv_pack_current;
794 unsigned int max_charging_current;
795 int mix_high_temp;
796 int mix_high_chg_temp;
797 int mix_high_temp_recovery;
798
799 /* If these is NOT full check type or NONE full check type,
800 * it is skipped
801 */
802 /* 1st full check */
803 sec_battery_full_charged_t full_check_type;
804 /* 2nd full check */
805 sec_battery_full_charged_t full_check_type_2nd;
806 unsigned int full_check_count;
807 int chg_gpio_full_check;
808 /* 1 : active high, 0 : active low */
809 int chg_polarity_full_check;
810 sec_battery_full_condition_t full_condition_type;
811 unsigned int full_condition_soc;
812 unsigned int full_condition_vcell;
813 unsigned int full_condition_avgvcell;
814 unsigned int full_condition_ocv;
815
816 unsigned int recharge_check_count;
817 sec_battery_recharge_condition_t recharge_condition_type;
818 unsigned int recharge_condition_soc;
819 unsigned int recharge_condition_avgvcell;
820 unsigned int recharge_condition_vcell;
821
822 /* for absolute timer (second) */
823 unsigned long charging_total_time;
824 /* for recharging timer (second) */
825 unsigned long recharging_total_time;
826 /* reset charging for abnormal malfunction (0: not use) */
827 unsigned long charging_reset_time;
828 unsigned int hv_charging_total_time;
829 unsigned int normal_charging_total_time;
830 unsigned int usb_charging_total_time;
831
832 /* fuel gauge */
833 char *fuelgauge_name;
834 int fg_irq;
835 unsigned long fg_irq_attr;
836 /* fuel alert SOC (-1: not use) */
837 int fuel_alert_soc;
838 /* fuel alert can be repeated */
839 bool repeated_fuelalert;
840 sec_fuelgauge_capacity_type_t capacity_calculation_type;
841 /* soc should be soc x 10 (0.1% degree)
842 * only for scaling
843 */
844 int capacity_max;
845 int capacity_max_hv;
846
847 int capacity_max_margin;
848 int capacity_min;
849
850 /* charger */
851 char *charger_name;
852 char *fgsrc_switch_name;
853 bool support_fgsrc_change;
854
855 /* wireless charger */
856 char *wireless_charger_name;
857 int wireless_cc_cv;
858 int set_cv_vout_in_low_capacity;
859 int wpc_det;
860 int wpc_en;
861
862 int chg_gpio_en;
863 int chg_irq;
864 unsigned long chg_irq_attr;
865 /* float voltage (mV) */
866 unsigned int chg_float_voltage;
867 unsigned int chg_float_voltage_conv;
868
869 #if defined(CONFIG_BATTERY_AGE_FORECAST)
870 int num_age_step;
871 int age_step;
872 int age_data_length;
873 sec_age_data_t* age_data;
874 #endif
875 int siop_input_limit_current;
876 int siop_charging_limit_current;
877 int siop_hv_input_limit_current;
878 int siop_hv_charging_limit_current;
879 int siop_hv_12v_input_limit_current;
880 int siop_hv_12v_charging_limit_current;
881
882 int siop_wireless_input_limit_current;
883 int siop_wireless_charging_limit_current;
884 int siop_hv_wireless_input_limit_current;
885 int siop_hv_wireless_charging_limit_current;
886 int wc_hero_stand_cc_cv;
887 int wc_hero_stand_cv_current;
888 int wc_hero_stand_hv_cv_current;
889
890 int default_input_current;
891 int default_charging_current;
892 int max_input_voltage;
893 int max_input_current;
894 int pre_afc_work_delay;
895 int pre_wc_afc_work_delay;
896
897 sec_charger_functions_t chg_functions_setting;
898
899 bool fake_capacity;
900
901 #if defined(CONFIG_BATTERY_CISD)
902 unsigned int battery_full_capacity;
903 unsigned int cisd_cap_high_thr;
904 unsigned int cisd_cap_low_thr;
905 unsigned int cisd_cap_limit;
906 unsigned int max_voltage_thr;
907 unsigned int cisd_alg_index;
908 #endif
909
910 /* ADC setting */
911 unsigned int adc_check_count;
912
913 unsigned int full_check_current_1st;
914 unsigned int full_check_current_2nd;
915
916 unsigned int pd_charging_charge_power;
917 unsigned int nv_charge_power;
918
919 unsigned int expired_time;
920 unsigned int recharging_expired_time;
921 int standard_curr;
922
923 /* ADC type for each channel */
924 unsigned int adc_type[];
925 };
926
927 struct sec_charger_platform_data {
928 bool (*chg_gpio_init)(void);
929
930 /* charging current for type (0: not use) */
931 sec_charging_current_t *charging_current;
932
933 /* wirelss charger */
934 char *wireless_charger_name;
935 int wireless_cc_cv;
936
937 int vbus_ctrl_gpio;
938 int chg_gpio_en;
939 /* float voltage (mV) */
940 int chg_float_voltage;
941 int irq_gpio;
942 int chg_irq;
943 unsigned long chg_irq_attr;
944
945 /* otg_en setting */
946 int otg_en;
947
948 /* OVP/UVLO check */
949 sec_battery_ovp_uvlo_t ovp_uvlo_check_type;
950 /* 1st full check */
951 sec_battery_full_charged_t full_check_type;
952 /* 2nd full check */
953 sec_battery_full_charged_t full_check_type_2nd;
954
955 sec_charger_functions_t chg_functions_setting;
956
957 #if defined(CONFIG_BATTERY_SBM_DATA)
958 int sbm_data_type;
959 char sbm_str[512];
960 #endif
961 };
962
963 struct sec_fuelgauge_platform_data {
964 bool (*fg_gpio_init)(void);
965 bool (*check_jig_status)(void);
966 int (*check_cable_callback)(void);
967 bool (*fuelalert_process)(bool);
968
969 /* charging current for type (0: not use) */
970 unsigned int full_check_current_1st;
971 unsigned int full_check_current_2nd;
972
973 int jig_irq;
974 int jig_gpio;
975 bool jig_low_active;
976 unsigned long jig_irq_attr;
977
978 sec_battery_thermal_source_t thermal_source;
979
980 int fg_irq;
981 unsigned long fg_irq_attr;
982 /* fuel alert SOC (-1: not use) */
983 int fuel_alert_soc;
984 int fuel_alert_vol;
985 /* fuel alert can be repeated */
986 bool repeated_fuelalert;
987 sec_fuelgauge_capacity_type_t capacity_calculation_type;
988 /* soc should be soc x 10 (0.1% degree)
989 * only for scaling
990 */
991 int capacity_max;
992 int capacity_max_hv;
993 int capacity_max_margin;
994 int capacity_min;
995
996 #if defined(CONFIG_BATTERY_AGE_FORECAST)
997 unsigned int full_condition_soc;
998 #endif
999
1000 #if defined(CONFIG_BATTERY_SBM_DATA)
1001 int sbm_data_type;
1002 char sbm_str[512];
1003 #endif
1004 };
1005
1006 #define sec_battery_platform_data_t \
1007 struct sec_battery_platform_data
1008
1009 #define sec_charger_platform_data_t \
1010 struct sec_charger_platform_data
1011
1012 #define sec_fuelgauge_platform_data_t \
1013 struct sec_fuelgauge_platform_data
1014
1015 static inline struct power_supply *get_power_supply_by_name(char *name)
1016 {
1017 if (!name)
1018 return (struct power_supply *)NULL;
1019 else
1020 return power_supply_get_by_name(name);
1021 }
1022
1023 #define psy_do_property(name, function, property, value) \
1024 ({ \
1025 struct power_supply *psy; \
1026 int ret = 0; \
1027 psy = get_power_supply_by_name((name)); \
1028 if (!psy) { \
1029 pr_err("%s: Fail to "#function" psy (%s)\n", \
1030 __func__, (name)); \
1031 value.intval = 0; \
1032 ret = -ENOENT; \
1033 } else { \
1034 if (psy->desc->function##_property != NULL) { \
1035 ret = psy->desc->function##_property(psy, \
1036 (enum power_supply_property) (property), &(value)); \
1037 if (ret < 0) { \
1038 pr_err("%s: Fail to %s "#function" (%d=>%d)\n", \
1039 __func__, name, (property), ret); \
1040 value.intval = 0; \
1041 } \
1042 } else { \
1043 ret = -ENOSYS; \
1044 } \
1045 power_supply_put(psy); \
1046 } \
1047 ret; \
1048 })
1049
1050 #define get_battery_data(driver) \
1051 (((struct battery_data_t *)(driver)->pdata->battery_data) \
1052 [(driver)->pdata->battery_type])
1053
1054 #define is_hv_wireless_type(cable_type) ( \
1055 cable_type == SEC_BATTERY_CABLE_HV_WIRELESS || \
1056 cable_type == SEC_BATTERY_CABLE_WIRELESS_HV_PACK || \
1057 cable_type == SEC_BATTERY_CABLE_HV_WIRELESS_ETX || \
1058 cable_type == SEC_BATTERY_CABLE_WIRELESS_HV_STAND || \
1059 cable_type == SEC_BATTERY_CABLE_WIRELESS_HV_VEHICLE)
1060
1061 #define is_nv_wireless_type(cable_type) ( \
1062 cable_type == SEC_BATTERY_CABLE_WIRELESS || \
1063 cable_type == SEC_BATTERY_CABLE_PMA_WIRELESS || \
1064 cable_type == SEC_BATTERY_CABLE_WIRELESS_PACK || \
1065 cable_type == SEC_BATTERY_CABLE_WIRELESS_STAND || \
1066 cable_type == SEC_BATTERY_CABLE_WIRELESS_VEHICLE || \
1067 cable_type == SEC_BATTERY_CABLE_PREPARE_WIRELESS_HV || \
1068 cable_type == SEC_BATTERY_CABLE_WIRELESS_TX)
1069
1070 #define is_wireless_type(cable_type) \
1071 (is_hv_wireless_type(cable_type) || is_nv_wireless_type(cable_type))
1072
1073 #define is_not_wireless_type(cable_type) ( \
1074 cable_type != SEC_BATTERY_CABLE_WIRELESS && \
1075 cable_type != SEC_BATTERY_CABLE_PMA_WIRELESS && \
1076 cable_type != SEC_BATTERY_CABLE_WIRELESS_PACK && \
1077 cable_type != SEC_BATTERY_CABLE_WIRELESS_HV_PACK && \
1078 cable_type != SEC_BATTERY_CABLE_WIRELESS_STAND && \
1079 cable_type != SEC_BATTERY_CABLE_HV_WIRELESS && \
1080 cable_type != SEC_BATTERY_CABLE_HV_WIRELESS_ETX && \
1081 cable_type != SEC_BATTERY_CABLE_PREPARE_WIRELESS_HV && \
1082 cable_type != SEC_BATTERY_CABLE_WIRELESS_HV_STAND && \
1083 cable_type != SEC_BATTERY_CABLE_WIRELESS_VEHICLE && \
1084 cable_type != SEC_BATTERY_CABLE_WIRELESS_HV_VEHICLE && \
1085 cable_type != SEC_BATTERY_CABLE_WIRELESS_TX)
1086
1087 #define is_wired_type(cable_type) \
1088 (is_not_wireless_type(cable_type) && (cable_type != SEC_BATTERY_CABLE_NONE))
1089
1090 #define is_hv_qc_wire_type(cable_type) ( \
1091 cable_type == SEC_BATTERY_CABLE_QC20 || \
1092 cable_type == SEC_BATTERY_CABLE_QC30)
1093
1094 #define is_hv_afc_wire_type(cable_type) ( \
1095 cable_type == SEC_BATTERY_CABLE_9V_ERR || \
1096 cable_type == SEC_BATTERY_CABLE_9V_TA || \
1097 cable_type == SEC_BATTERY_CABLE_9V_UNKNOWN || \
1098 cable_type == SEC_BATTERY_CABLE_12V_TA)
1099
1100 #define is_hv_wire_9v_type(cable_type) ( \
1101 cable_type == SEC_BATTERY_CABLE_9V_ERR || \
1102 cable_type == SEC_BATTERY_CABLE_9V_TA || \
1103 cable_type == SEC_BATTERY_CABLE_9V_UNKNOWN || \
1104 cable_type == SEC_BATTERY_CABLE_QC20)
1105
1106 #define is_hv_wire_12v_type(cable_type) ( \
1107 cable_type == SEC_BATTERY_CABLE_12V_TA || \
1108 cable_type == SEC_BATTERY_CABLE_QC30)
1109
1110 #define is_hv_wire_type(cable_type) ( \
1111 is_hv_afc_wire_type(cable_type) || is_hv_qc_wire_type(cable_type))
1112
1113 #endif /* __SEC_CHARGING_COMMON_H */