3 * Samsung battery data parsing from device tree
5 * Copyright (C) 2014 Samsung Electronics
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
14 #include <linux/of_device.h>
15 #include <linux/of_gpio.h>
16 #include <linux/of_irq.h>
17 #include <soc/sprd/adc.h>
18 #include <linux/battery/sec_battery.h>
20 #include <soc/sprd/sci_glb_regs.h>
21 #include <soc/sprd/sci.h>
22 #include <soc/sprd/adi.h>
23 #include <soc/sprd/arch_misc.h>
24 #include <soc/sprd/hardware.h>
25 #include <linux/delay.h>
27 #ifdef CONFIG_MFD_RT8973
28 #include <linux/mfd/rt8973.h>
30 #ifdef CONFIG_SM5502_MUIC
31 #include <linux/mfd/sm5502-muic.h>
33 #ifdef CONFIG_MFD_SM5504
34 #include <linux/mfd/sm5504.h>
36 #ifdef CONFIG_FUELGAUGE_SPRD4SAMSUNG27X3
37 #include <linux/battery/fuelgauge/sprd27x3_fuelgauge4samsung.h>
40 #define BATT_DET_CURRENT 313
42 static int current_cable_type = POWER_SUPPLY_TYPE_BATTERY;
43 static u8 attached_cable;
44 static bool is_jig_on;
45 /* static unsigned int lpcharge; */
46 /* EXPORT_SYMBOL(lpcharge); */
47 unsigned int lpcharge;
48 EXPORT_SYMBOL(lpcharge);
49 static unsigned chg_irq;
50 static int gpio_vbat_detect;
52 #if defined(CONFIG_INPUT_TOUCHSCREEN)
53 void (*tsp_charger_status_cb)(int);
54 EXPORT_SYMBOL(tsp_charger_status_cb);
57 static bool sec_fg_gpio_init(void)
62 static bool sec_fg_fuelalert_process(bool is_fuel_alerted) { return true; }
64 static bool sec_bat_adc_none_init(struct platform_device *pdev) { return true; }
65 static bool sec_bat_adc_none_exit(void) { return true; }
66 static int sec_bat_adc_none_read(unsigned int channel) { return 0; }
68 static bool sec_bat_adc_ap_init(struct platform_device *pdev) { return true; }
69 static bool sec_bat_adc_ap_exit(void) { return true; }
71 static bool sec_bat_adc_ic_init(struct platform_device *pdev) { return true; }
72 static bool sec_bat_adc_ic_exit(void) { return true; }
73 static int sec_bat_adc_ic_read(unsigned int channel) { return 0; }
75 static sec_bat_adc_api_t adc_api[SEC_BATTERY_ADC_TYPE_NUM] = {
77 .init = sec_bat_adc_none_init,
78 .exit = sec_bat_adc_none_exit,
79 .read = sec_bat_adc_none_read
82 .init = sec_bat_adc_ap_init,
83 .exit = sec_bat_adc_ap_exit,
86 .init = sec_bat_adc_ic_init,
87 .exit = sec_bat_adc_ic_exit,
88 .read = sec_bat_adc_ic_read
92 static bool sec_chg_gpio_init(void)
97 bool sec_bat_check_cable_result_callback(int cable_type)
100 current_cable_type = cable_type;
102 switch (cable_type) {
103 case POWER_SUPPLY_TYPE_USB:
104 pr_info("%s set vbus applied\n",
107 case POWER_SUPPLY_TYPE_BATTERY:
108 pr_info("%s set vbus cut\n",
111 case POWER_SUPPLY_TYPE_MAINS:
114 pr_err("%s cable type (%d)\n",
115 __func__, cable_type);
123 static bool sec_bat_ovp_uvlo_result_callback(int health)
128 /* Get LP charging mode state */
129 static int sec_bat_is_lpm_check(char *str)
131 if (strncmp(str, "charger", 7) == 0)
134 pr_info("%s: Low power charging mode: %d\n", __func__, lpcharge);
138 __setup("androidboot.mode=", sec_bat_is_lpm_check);
140 bool sec_bat_is_lpm(void)
142 return lpcharge == 1 ? true : false;
145 * val.intval : temperature
147 static bool sec_bat_get_temperature_callback(
148 enum power_supply_property psp,
149 union power_supply_propval *val)
154 void check_jig_status(int status)
157 pr_info("%s: JIG On so reset fuel gauge capacity\n", __func__);
163 bool sec_bat_check_jig_status(void)
168 //int sec_bat_check_cable_callback(void)
169 int sec_bat_check_cable_callback(struct sec_battery_info *battery)
172 union power_supply_propval value;
173 struct power_supply *psy = power_supply_get_by_name("battery");
175 ta_nconnected = gpio_get_value(chg_irq);
177 pr_info("%s : ta_nconnected : %d\n", __func__, ta_nconnected);
180 current_cable_type = POWER_SUPPLY_TYPE_BATTERY;
182 current_cable_type = POWER_SUPPLY_TYPE_MAINS;
184 #ifdef CONFIG_MFD_RT8973
185 if (attached_cable == MUIC_RT8973_CABLE_TYPE_0x1A) {
187 current_cable_type = POWER_SUPPLY_TYPE_BATTERY;
189 current_cable_type = POWER_SUPPLY_TYPE_MISC;
191 return current_cable_type;
194 #ifdef CONFIG_MFD_SM5504
195 if (attached_cable == MUIC_SM5504_CABLE_TYPE_0x1A) {
197 current_cable_type = POWER_SUPPLY_TYPE_BATTERY;
199 current_cable_type = POWER_SUPPLY_TYPE_MISC;
201 return current_cable_type;
203 if (!psy || !psy->set_property)
204 pr_err("%s: fail to get battery psy\n", __func__);
206 value.intval = current_cable_type;
207 psy->set_property(psy, POWER_SUPPLY_PROP_ONLINE, &value);
210 return current_cable_type;
213 void sec_bat_initial_check(void)
215 union power_supply_propval value;
217 if (POWER_SUPPLY_TYPE_BATTERY < current_cable_type) {
218 value.intval = current_cable_type;
219 psy_do_property("battery", set,
220 POWER_SUPPLY_PROP_ONLINE, value);
222 psy_do_property("sec-charger", get,
223 POWER_SUPPLY_PROP_ONLINE, value);
224 if (value.intval == POWER_SUPPLY_TYPE_WPC) {
225 value.intval = POWER_SUPPLY_TYPE_WPC;
226 psy_do_property("battery", set,
227 POWER_SUPPLY_PROP_ONLINE, value);
231 value.intval = POWER_SUPPLY_TYPE_BATTERY;
232 psy_do_property("sec-charger", set,
233 POWER_SUPPLY_PROP_ONLINE, value);
239 static bool sec_bat_gpio_init(void)
244 //static bool sec_bat_check_callback(void) { return true; }
245 extern bool sec_bat_check_callback(struct sec_battery_info *battery){return true; }
246 static bool sec_bat_check_result_callback(void) { return true; }
248 /* callback for OVP/UVLO check
252 static int sec_bat_ovp_uvlo_callback(void)
255 health = POWER_SUPPLY_HEALTH_GOOD;
260 #if defined(CONFIG_SENSORS_GRIP_SX9500) && defined(CONFIG_MACH_DEGAS)
261 extern void charger_status_cb(int status);
264 #ifdef CONFIG_MFD_RT8973
265 void sec_charger_cb(u8 cable_type)
267 union power_supply_propval value;
268 struct power_supply *psy = power_supply_get_by_name("battery");
270 pr_info("%s: cable type (0x%02x)\n", __func__, cable_type);
272 attached_cable = cable_type;
274 switch (cable_type) {
275 case MUIC_RT8973_CABLE_TYPE_NONE:
276 case MUIC_RT8973_CABLE_TYPE_JIG_UART_OFF:
277 current_cable_type = POWER_SUPPLY_TYPE_BATTERY;
279 case MUIC_RT8973_CABLE_TYPE_USB:
280 case MUIC_RT8973_CABLE_TYPE_L_USB:
281 case MUIC_RT8973_CABLE_TYPE_CDP:
282 case MUIC_RT8973_CABLE_TYPE_JIG_USB_ON:
283 case MUIC_RT8973_CABLE_TYPE_JIG_USB_OFF:
284 current_cable_type = POWER_SUPPLY_TYPE_USB;
286 case MUIC_RT8973_CABLE_TYPE_REGULAR_TA:
287 case MUIC_RT8973_CABLE_TYPE_ATT_TA:
288 case MUIC_RT8973_CABLE_TYPE_JIG_UART_OFF_WITH_VBUS:
289 case MUIC_RT8973_CABLE_TYPE_JIG_UART_ON_WITH_VBUS:
290 case MUIC_RT8973_CABLE_TYPE_TYPE1_CHARGER:
291 current_cable_type = POWER_SUPPLY_TYPE_MAINS;
293 case MUIC_RT8973_CABLE_TYPE_OTG:
295 case MUIC_RT8973_CABLE_TYPE_0x15:
296 case MUIC_RT8973_CABLE_TYPE_0x1A:
297 //case MUIC_RT8973_CABLE_TYPE_0x1A_VBUS:
298 current_cable_type = POWER_SUPPLY_TYPE_MISC;
301 pr_err("%s: invalid type for charger:%d\n",
302 __func__, cable_type);
303 current_cable_type = POWER_SUPPLY_TYPE_UNKNOWN;
307 if (!psy || !psy->set_property)
308 pr_err("%s: fail to get battery psy\n", __func__);
310 value.intval = current_cable_type;
311 psy->set_property(psy, POWER_SUPPLY_PROP_ONLINE, &value);
313 #if defined(CONFIG_INPUT_TOUCHSCREEN)
314 /* for changing of tsp operation mode */
315 if (tsp_charger_status_cb)
316 tsp_charger_status_cb(current_cable_type);
325 #ifdef CONFIG_SM5502_MUIC
326 void sec_charger_cb(u8 cable_type)
329 union power_supply_propval value;
330 struct power_supply *psy = power_supply_get_by_name("battery");
332 pr_info("%s: cable type (0x%02x)\n", __func__, cable_type);
334 attached_cable = cable_type;
337 switch (cable_type) {
338 case CABLE_TYPE_NONE_MUIC:
339 case CABLE_TYPE2_DESKDOCK_MUIC:
340 current_cable_type = POWER_SUPPLY_TYPE_BATTERY;
342 case CABLE_TYPE1_USB_MUIC:
343 current_cable_type = POWER_SUPPLY_TYPE_USB;
345 case CABLE_TYPE1_TA_MUIC:
346 case CABLE_TYPE3_U200CHG_MUIC:
347 case CABLE_TYPE3_NONSTD_SDP_MUIC:
348 pr_info("%s: VBUS Online\n", __func__);
349 current_cable_type = POWER_SUPPLY_TYPE_MAINS;
351 case CABLE_TYPE2_JIG_UART_OFF_VB_MUIC:
352 case CABLE_TYPE2_JIG_UART_ON_VB_MUIC:
354 current_cable_type = POWER_SUPPLY_TYPE_MAINS;
356 case CABLE_TYPE1_OTG_MUIC:
358 case CABLE_TYPE2_JIG_UART_OFF_MUIC:
360 current_cable_type = POWER_SUPPLY_TYPE_BATTERY;
362 case CABLE_TYPE2_JIG_USB_ON_MUIC:
363 case CABLE_TYPE2_JIG_USB_OFF_MUIC:
365 current_cable_type = POWER_SUPPLY_TYPE_USB;
367 case CABLE_TYPE1_CARKIT_T1OR2_MUIC:
368 current_cable_type = POWER_SUPPLY_TYPE_USB;
370 case CABLE_TYPE3_DESKDOCK_VB_MUIC:
371 current_cable_type = POWER_SUPPLY_TYPE_MISC;
374 pr_err("%s: invalid type for charger:%d\n",
375 __func__, cable_type);
376 current_cable_type = POWER_SUPPLY_TYPE_UNKNOWN;
380 if (!psy || !psy->set_property)
381 pr_err("%s: fail to get battery psy\n", __func__);
383 value.intval = current_cable_type;
384 psy->set_property(psy, POWER_SUPPLY_PROP_ONLINE, &value);
386 #if defined(CONFIG_INPUT_TOUCHSCREEN)
387 /* for changing of tsp operation mode */
388 if (tsp_charger_status_cb)
389 tsp_charger_status_cb(current_cable_type);
392 #if defined(CONFIG_SENSORS_GRIP_SX9500) && defined(CONFIG_MACH_DEGAS)
393 /* for grip sensor threshold change at TA/USB status - sx9500.c */
394 charger_status_cb(current_cable_type);
400 #endif /* CONFIG_SM5502_MUIC */
403 #ifdef CONFIG_MFD_SM5504
404 void sec_charger_cb(u8 cable_type)
406 union power_supply_propval value;
407 struct power_supply *psy = power_supply_get_by_name("battery");
409 pr_info("%s: cable type (0x%02x)\n", __func__, cable_type);
411 attached_cable = cable_type;
413 switch (cable_type) {
414 case MUIC_SM5504_CABLE_TYPE_NONE:
415 case MUIC_SM5504_CABLE_TYPE_JIG_UART_ON:
416 case MUIC_SM5504_CABLE_TYPE_JIG_UART_OFF:
417 case MUIC_SM5504_CABLE_TYPE_JIG_UART_ON_WITH_VBUS:
418 current_cable_type = POWER_SUPPLY_TYPE_BATTERY;
420 case MUIC_SM5504_CABLE_TYPE_USB:
421 case MUIC_SM5504_CABLE_TYPE_CDP:
422 case MUIC_SM5504_CABLE_TYPE_L_USB:
423 case MUIC_SM5504_CABLE_TYPE_JIG_USB_ON:
424 case MUIC_SM5504_CABLE_TYPE_JIG_USB_OFF:
425 current_cable_type = POWER_SUPPLY_TYPE_USB;
427 case MUIC_SM5504_CABLE_TYPE_REGULAR_TA:
428 case MUIC_SM5504_CABLE_TYPE_ATT_TA:
429 case MUIC_SM5504_CABLE_TYPE_JIG_UART_OFF_WITH_VBUS:
430 case MUIC_SM5504_CABLE_TYPE_TYPE1_CHARGER:
431 current_cable_type = POWER_SUPPLY_TYPE_MAINS;
433 case MUIC_SM5504_CABLE_TYPE_UART:
434 current_cable_type = POWER_SUPPLY_TYPE_UNKNOWN;
436 case MUIC_SM5504_CABLE_TYPE_OTG:
437 case MUIC_SM5504_CABLE_TYPE_OTG_WITH_VBUS:
438 current_cable_type = POWER_SUPPLY_TYPE_OTG;
440 case MUIC_SM5504_CABLE_TYPE_0x15:
441 case MUIC_SM5504_CABLE_TYPE_0x1A:
442 // case MUIC_SM5504_CABLE_TYPE_0x1A_VBUS:
443 current_cable_type = POWER_SUPPLY_TYPE_MISC;
446 pr_err("%s: invalid type for charger:%d\n",
447 __func__, cable_type);
448 current_cable_type = POWER_SUPPLY_TYPE_UNKNOWN;
452 if (!psy || !psy->set_property)
453 pr_err("%s: fail to get battery psy\n", __func__);
455 value.intval = current_cable_type;
456 psy->set_property(psy, POWER_SUPPLY_PROP_ONLINE, &value);
458 #if defined(CONFIG_INPUT_TOUCHSCREEN)
459 /* for changing of tsp operation mode */
460 if (tsp_charger_status_cb)
461 tsp_charger_status_cb(current_cable_type);
469 #endif /* CONFIG_MFD_SM5504 */
471 int sec_vf_adc_current_check(void)
475 sci_adi_set(ANA_REG_GLB_AUXAD_CTL,
476 (BIT_AUXAD_CURRENTSEN_EN | BITS_AUXAD_CURRENT_IBS(0x6)));
477 sci_adi_set(ANA_REG_GLB_BATDET_CUR_CTRL,
478 (BIT_BATDET_CUR_EN | BITS_BATDET_CUR_I(0x4)));
481 if (gpio_get_value(gpio_vbat_detect))
483 printk("%s : vbat good!\n", __func__);
488 printk("%s : vbat is not connected!\n", __func__);
492 sci_adi_clr(ANA_REG_GLB_AUXAD_CTL, BIT_AUXAD_CURRENTSEN_EN);
493 sci_adi_clr(ANA_REG_GLB_BATDET_CUR_CTRL, BIT_BATDET_CUR_EN);
498 /* vf adc check, only for MUIC & young2dtv */
499 int sec_vf_adc_check(void)
503 adc = sci_adc_get_value(0, false);
504 pr_info("%s, vf adc : %d", __func__, adc);
512 int sec_bat_dt_init(struct device_node *np,
514 sec_battery_platform_data_t *pdata)
517 unsigned int bat_irq_attr;
520 ret = of_property_read_string(np,
521 "battery,vendor", (char const **)&pdata->vendor);
523 pr_info("%s: Vendor is Empty\n", __func__);
525 ret = of_property_read_string(np,
526 "battery,charger_name", (char const **)&pdata->charger_name);
528 pr_info("%s: charger_name is Empty\n", __func__);
530 ret = of_property_read_string(np,
531 "battery,fuelgauge_name", (char const **)&pdata->fuelgauge_name);
533 pr_info("%s: fuelguage_name is Empty\n", __func__);
535 ret = of_property_read_u32(np, "battery,technology",
538 pr_info("%s : technology is Empty\n", __func__);
540 p = of_get_property(np, "battery,polling_time", &len);
544 len = len / sizeof(u32);
545 pdata->polling_time = kzalloc(sizeof(*pdata->polling_time) * len, GFP_KERNEL);
546 ret = of_property_read_u32_array(np, "battery,polling_time",
547 pdata->polling_time, len);
549 p = of_get_property(np, "battery,temp_table_adc", &len);
553 len = len / sizeof(u32);
555 pdata->temp_adc_table_size = len;
556 pdata->temp_amb_adc_table_size = len;
558 pdata->temp_adc_table =
559 kzalloc(sizeof(sec_bat_adc_table_data_t) *
560 pdata->temp_adc_table_size, GFP_KERNEL);
561 pdata->temp_amb_adc_table =
562 kzalloc(sizeof(sec_bat_adc_table_data_t) *
563 pdata->temp_adc_table_size, GFP_KERNEL);
565 for(i = 0; i < pdata->temp_adc_table_size; i++) {
566 ret = of_property_read_u32_index(np,
567 "battery,temp_table_adc", i,
568 &pdata->temp_adc_table[i].adc);
570 pr_info("%s : Temp_adc_table(adc) is Empty\n",
573 ret = of_property_read_u32_index(np,
574 "battery,temp_table_data", i,
575 &pdata->temp_adc_table[i].temperature);
577 pr_info("%s : Temp_adc_table(data) is Empty\n",
580 ret = of_property_read_u32_index(np,
581 "battery,temp_table_adc", i,
582 &pdata->temp_amb_adc_table[i].adc);
584 pr_info("%s : Temp_amb_adc_table(adc) is Empty\n",
587 ret = of_property_read_u32_index(np,
588 "battery,temp_table_data", i,
589 &pdata->temp_amb_adc_table[i].temperature);
591 pr_info("%s : Temp_amb_adc_table(data) is Empty\n",
595 p = of_get_property(np, "battery,input_current_limit", &len);
599 len = len / sizeof(u32);
601 pdata->charging_current =
602 kzalloc(sizeof(sec_charging_current_t) * len,
605 for(i = 0; i < len; i++) {
606 ret = of_property_read_u32_index(np,
607 "battery,input_current_limit", i,
608 &pdata->charging_current[i].input_current_limit);
610 pr_info("%s : Input_current_limit is Empty\n",
613 ret = of_property_read_u32_index(np,
614 "battery,fast_charging_current", i,
615 &pdata->charging_current[i].fast_charging_current);
617 pr_info("%s : Fast charging current is Empty\n",
620 ret = of_property_read_u32_index(np,
621 "battery,full_check_current_1st", i,
622 &pdata->charging_current[i].full_check_current_1st);
624 pr_info("%s : Full check current 1st is Empty\n",
627 ret = of_property_read_u32_index(np,
628 "battery,full_check_current_2nd", i,
629 &pdata->charging_current[i].full_check_current_2nd);
631 pr_info("%s : Full check current 2nd is Empty\n",
635 ret = of_property_read_u32(np, "battery,adc_check_count",
636 &pdata->adc_check_count);
638 pr_info("%s : Adc check count is Empty\n", __func__);
640 ret = of_property_read_u32(np, "battery,cable_check_type",
641 &pdata->cable_check_type);
643 pr_info("%s : Cable check type is Empty\n", __func__);
645 ret = of_property_read_u32(np, "battery,cable_source_type",
646 &pdata->cable_source_type);
648 pr_info("%s : Cable source type is Empty\n", __func__);
650 ret = of_property_read_u32(np, "battery,event_waiting_time",
651 &pdata->event_waiting_time);
653 pr_info("%s : Event waiting time is Empty\n", __func__);
655 ret = of_property_read_u32(np, "battery,polling_type",
656 &pdata->polling_type);
658 pr_info("%s : Polling type is Empty\n", __func__);
660 ret = of_property_read_u32(np, "battery,monitor_initial_count",
661 &pdata->monitor_initial_count);
663 pr_info("%s : Monitor initial count is Empty\n", __func__);
665 ret = of_property_read_u32(np, "battery,battery_check_type",
666 &pdata->battery_check_type);
668 pr_info("%s : Battery check type is Empty\n", __func__);
670 ret = of_property_read_u32(np, "battery,check_count",
671 &pdata->check_count);
674 pr_info("%s : Check count is Empty\n", __func__);
676 ret = of_property_read_u32(np, "battery,check_adc_max",
677 &pdata->check_adc_max);
679 pr_info("%s : Check adc max is Empty\n", __func__);
681 ret = of_property_read_u32(np, "battery,check_adc_min",
682 &pdata->check_adc_min);
684 pr_info("%s : Check adc min is Empty\n", __func__);
686 ret = of_property_read_u32(np, "battery,ovp_uvlo_check_type",
687 &pdata->ovp_uvlo_check_type);
689 pr_info("%s : Ovp Uvlo check type is Empty\n", __func__);
691 ret = of_property_read_u32(np, "battery,thermal_source",
692 &pdata->thermal_source);
694 pr_info("%s : Thermal source is Empty\n", __func__);
696 ret = of_property_read_u32(np, "battery,temp_check_type",
697 &pdata->temp_check_type);
699 pr_info("%s : Temp check type is Empty\n", __func__);
701 ret = of_property_read_u32(np, "battery,temp_check_count",
702 &pdata->temp_check_count);
704 pr_info("%s : Temp check count is Empty\n", __func__);
706 ret = of_property_read_u32(np, "battery,temp_high_recovery_event",
707 &pdata->temp_high_recovery_event);
709 pr_info("%s : Temp high recovery event is Empty\n", __func__);
711 #if defined(CONFIG_MACH_DEGAS_USA)
712 pdata->temp_high_threshold_event = 550;
713 pdata->temp_high_recovery_event = 480;
714 pdata->temp_low_threshold_event = 20;
715 pdata->temp_low_recovery_event = 50;
716 pdata->temp_high_threshold_normal = 550;
717 pdata->temp_high_recovery_normal = 480;
718 pdata->temp_low_threshold_normal = 20;
719 pdata->temp_low_recovery_normal = 50;
720 pdata->temp_high_threshold_lpm = 550;
721 pdata->temp_high_recovery_lpm = 480;
722 pdata->temp_low_threshold_lpm = 20;
723 pdata->temp_low_recovery_lpm = 50;
724 #elif defined(CONFIG_MACH_DEGAS_BMW)
725 pdata->temp_high_threshold_event = 450;
726 pdata->temp_high_recovery_event = 400;
727 pdata->temp_low_threshold_event = 0;
728 pdata->temp_low_recovery_event = 50;
729 pdata->temp_high_threshold_normal = 450;
730 pdata->temp_high_recovery_normal = 400;
731 pdata->temp_low_threshold_normal = 0;
732 pdata->temp_low_recovery_normal = 50;
733 pdata->temp_high_threshold_lpm = 450;
734 pdata->temp_high_recovery_lpm = 400;
735 pdata->temp_low_threshold_lpm = 0;
736 pdata->temp_low_recovery_lpm = 50;
738 ret = of_property_read_u32(np, "battery,temp_highlimit_threshold_event",
739 &pdata->temp_highlimit_threshold_event);
741 pr_info("%s : Temp highlimit threshold event is Empty\n", __func__);
743 ret = of_property_read_u32(np, "battery,battery,temp_highlimit_recovery_event",
744 &pdata->temp_highlimit_recovery_event);
746 pr_info("%s : Temp highlimit threshold event recovery is Empty\n", __func__);
748 ret = of_property_read_u32(np, "battery,temp_highlimit_threshold_normal",
749 &pdata->temp_highlimit_threshold_normal);
751 pr_info("%s : Temp highlimit threshold normal is Empty\n", __func__);
753 ret = of_property_read_u32(np, "battery,temp_highlimit_recovery_normal",
754 &pdata->temp_highlimit_recovery_normal);
756 pr_info("%s : Temp highlimit threshold normal recovery is Empty\n", __func__);
758 ret = of_property_read_u32(np, "battery,temp_highlimit_threshold_lpm",
759 &pdata->temp_highlimit_threshold_lpm);
761 pr_info("%s : Temp highlimit threshold lpm is Empty\n", __func__);
763 ret = of_property_read_u32(np, "battery,temp_highlimit_recovery_lpm",
764 &pdata->temp_highlimit_recovery_lpm);
766 pr_info("%s : Temp highlimit threshold lpm recovery is Empty\n", __func__);
768 ret = of_property_read_u32(np, "battery,temp_high_threshold_event",
769 &pdata->temp_high_threshold_event);
771 pr_info("%s : Temp high threshold event is Empty\n", __func__);
773 ret = of_property_read_u32(np, "battery,temp_low_threshold_event",
774 &pdata->temp_low_threshold_event);
776 pr_info("%s : Temp low threshold event is Empty\n", __func__);
778 ret = of_property_read_u32(np, "battery,temp_low_recovery_event",
779 &pdata->temp_low_recovery_event);
781 pr_info("%s : Temp low recovery event is Empty\n", __func__);
783 ret = of_property_read_u32(np, "battery,temp_high_threshold_normal",
784 &pdata->temp_high_threshold_normal);
786 pr_info("%s : Temp high threshold normal is Empty\n", __func__);
788 ret = of_property_read_u32(np, "battery,temp_high_recovery_normal",
789 &pdata->temp_high_recovery_normal);
791 pr_info("%s : Temp high recovery normal is Empty\n", __func__);
793 ret = of_property_read_u32(np, "battery,temp_low_threshold_normal",
794 &pdata->temp_low_threshold_normal);
796 pr_info("%s : Temp low threshold normal is Empty\n", __func__);
798 ret = of_property_read_u32(np, "battery,temp_low_recovery_normal",
799 &pdata->temp_low_recovery_normal);
802 pr_info("%s : Temp low recovery normal is Empty\n", __func__);
804 ret = of_property_read_u32(np, "battery,temp_high_threshold_lpm",
805 &pdata->temp_high_threshold_lpm);
807 pr_info("%s : Temp high threshold lpm is Empty\n", __func__);
809 ret = of_property_read_u32(np, "battery,temp_high_recovery_lpm",
810 &pdata->temp_high_recovery_lpm);
812 pr_info("%s : Temp high recovery lpm is Empty\n", __func__);
814 ret = of_property_read_u32(np, "battery,temp_low_threshold_lpm",
815 &pdata->temp_low_threshold_lpm);
817 pr_info("%s : Temp low threshold lpm is Empty\n", __func__);
819 ret = of_property_read_u32(np, "battery,temp_low_recovery_lpm",
820 &pdata->temp_low_recovery_lpm);
822 pr_info("%s : Temp low recovery lpm is Empty\n", __func__);
825 ret = of_property_read_u32(np, "battery,full_check_type",
826 &pdata->full_check_type);
828 pr_info("%s : Full check type is Empty\n", __func__);
830 ret = of_property_read_u32(np, "battery,full_check_type_2nd",
831 &pdata->full_check_type_2nd);
833 pr_info("%s : Full check type 2nd is Empty\n", __func__);
835 ret = of_property_read_u32(np, "battery,full_check_count",
836 &pdata->full_check_count);
838 pr_info("%s : Full check count is Empty\n", __func__);
840 ret = of_property_read_u32(np, "battery,chg_gpio_full_check",
841 &pdata->chg_gpio_full_check);
843 pr_info("%s : Chg gpio full check is Empty\n", __func__);
845 ret = of_property_read_u32(np, "battery,chg_polarity_full_check",
846 &pdata->chg_polarity_full_check);
848 pr_info("%s : Chg polarity full check is Empty\n", __func__);
850 ret = of_property_read_u32(np, "battery,full_condition_type",
851 &pdata->full_condition_type);
853 pr_info("%s : Full condition type is Empty\n", __func__);
855 ret = of_property_read_u32(np, "battery,full_condition_soc",
856 &pdata->full_condition_soc);
858 pr_info("%s : Full condition soc is Empty\n", __func__);
860 ret = of_property_read_u32(np, "battery,full_condition_vcell",
861 &pdata->full_condition_vcell);
863 pr_info("%s : Full condition vcell is Empty\n", __func__);
865 ret = of_property_read_u32(np, "battery,recharge_check_count",
866 &pdata->recharge_check_count);
868 pr_info("%s : Recharge check count is Empty\n", __func__);
870 ret = of_property_read_u32(np, "battery,recharge_condition_type",
871 &pdata->recharge_condition_type);
873 pr_info("%s : Recharge condition type is Empty\n", __func__);
875 ret = of_property_read_u32(np, "battery,recharge_condition_soc",
876 &pdata->recharge_condition_soc);
878 pr_info("%s : Recharge condition soc is Empty\n", __func__);
880 ret = of_property_read_u32(np, "battery,recharge_condition_vcell",
881 &pdata->recharge_condition_vcell);
883 pr_info("%s : Recharge condition vcell is Empty\n", __func__);
885 ret = of_property_read_u32(np, "battery,recharge_condition_avgvcell",
886 &pdata->recharge_condition_avgvcell);
888 pr_info("%s : Recharge condition avgvcell is Empty\n", __func__);
890 ret = of_property_read_u32(np, "battery,charging_total_time",
891 (unsigned int *)&pdata->charging_total_time);
893 pr_info("%s : Charging total time is Empty\n", __func__);
895 ret = of_property_read_u32(np, "battery,recharging_total_time",
896 (unsigned int *)&pdata->recharging_total_time);
898 pr_info("%s : Recharging total time is Empty\n", __func__);
900 ret = of_property_read_u32(np, "battery,charging_reset_time",
901 (unsigned int *)&pdata->charging_reset_time);
903 pr_info("%s : Charging reset time is Empty\n", __func__);
905 ret = of_property_read_u32(np, "battery,charging_reset_time",
906 (unsigned int *)&pdata->charging_reset_time);
908 pr_info("%s : Charging reset time is Empty\n", __func__);
910 ret = of_property_read_u32(np, "battery,bat-irq-attr", &bat_irq_attr);
912 pr_info("%s : Battery irq is Empty\n", __func__);
914 pdata->bat_gpio_init = sec_bat_gpio_init;
915 pdata->check_battery_callback = sec_bat_check_callback;
916 pdata->check_battery_result_callback = sec_bat_check_result_callback;
917 pdata->check_cable_callback = sec_bat_check_cable_callback;
918 pdata->check_cable_result_callback =
919 sec_bat_check_cable_result_callback;
920 pdata->get_temperature_callback = sec_bat_get_temperature_callback;
921 pdata->initial_check = sec_bat_initial_check;
922 pdata->is_lpm = sec_bat_is_lpm;
923 pdata->ovp_uvlo_callback = sec_bat_ovp_uvlo_callback;
924 pdata->ovp_uvlo_result_callback = sec_bat_ovp_uvlo_result_callback;
925 pdata->check_jig_status = sec_bat_check_jig_status;
927 for (i = 0; i < SEC_BATTERY_ADC_TYPE_NUM; i++)
928 pdata->adc_api[i] = adc_api[i];
933 int sec_chg_dt_init(struct device_node *np,
935 sec_battery_platform_data_t *pdata)
937 int ret = 0, len = 0;
938 unsigned int chg_irq_attr = 0;
940 int chg_irq_gpio = 0;
945 chg_gpio_en = of_get_named_gpio(np, "chgen-gpio", 0);
946 if (chg_gpio_en < 0) {
947 pr_err("%s: of_get_named_gpio failed: %d\n", __func__,
952 ret = of_property_read_u32(np, "chg-irq-attr",
955 pr_info("%s chg_irq_attr request failed: %d\n", __func__, chg_irq_attr);
958 ret = gpio_request(chg_gpio_en, "chgen-gpio");
960 pr_err("%s gpio_request failed: %d\n", __func__, chg_gpio_en);
964 chg_irq_gpio = of_get_named_gpio(np, "chgirq-gpio", 0);
965 if (chg_irq_gpio < 0)
966 pr_err("%s: chgirq gpio get failed: %d\n", __func__, chg_irq_gpio);
968 ret = gpio_request(chg_irq_gpio, "chgirq-gpio");
970 pr_err("%s gpio_request failed: %d\n", __func__, chg_irq_gpio);
972 ret = of_property_read_u32(np, "chg-float-voltage",
973 &pdata->chg_float_voltage);
977 np = of_find_node_by_name(NULL, "sec-battery");
979 pr_err("%s np NULL\n", __func__);
984 p = of_get_property(np, "battery,input_current_limit", &len);
987 pr_err("%s charger,input_current_limit is Empty\n", __func__);
992 len = len / sizeof(u32);
994 pdata->charging_current = kzalloc(sizeof(sec_charging_current_t) * len,
997 for(i = 0; i < len; i++) {
998 ret = of_property_read_u32_index(np,
999 "battery,input_current_limit", i,
1000 &pdata->charging_current[i].input_current_limit);
1002 pr_info("%s : Input_current_limit is Empty\n",
1005 ret = of_property_read_u32_index(np,
1006 "battery,fast_charging_current", i,
1007 &pdata->charging_current[i].fast_charging_current);
1009 pr_info("%s : Fast charging current is Empty\n",
1012 ret = of_property_read_u32_index(np,
1013 "battery,full_check_current_1st", i,
1014 &pdata->charging_current[i].full_check_current_1st);
1016 pr_info("%s : Full check current 1st is Empty\n",
1019 ret = of_property_read_u32_index(np,
1020 "battery,full_check_current_2nd", i,
1021 &pdata->charging_current[i].full_check_current_2nd);
1023 pr_info("%s : Full check current 2nd is Empty\n",
1029 ret = of_property_read_u32(np, "battery,ovp_uvlo_check_type",
1030 &pdata->ovp_uvlo_check_type);
1032 pr_info("%s : Ovp Uvlo check type is Empty\n", __func__);
1034 ret = of_property_read_u32(np, "battery,full_check_type",
1035 &pdata->full_check_type);
1037 pr_info("%s : Full check type is Empty\n", __func__);
1039 ret = of_property_read_u32(np, "battery,full_check_type_2nd",
1040 &pdata->full_check_type_2nd);
1042 pr_info("%s : Full check type 2nd is Empty\n", __func__);
1044 #if defined(CONFIG_MACH_PIKEAYOUNG2DTV)
1045 gpio_vbat_detect = BATT_DET_CURRENT;
1047 if (!gpio_is_valid(gpio_vbat_detect)) {
1048 printk("%s: battery detect gpio %d failed\n", __func__, gpio_vbat_detect);
1051 gpio_request(gpio_vbat_detect, "battery-detect");
1052 gpio_direction_input(gpio_vbat_detect);
1053 printk("%s: battery detect gpio %d\n", __func__, gpio_vbat_detect);
1056 if (chg_irq_gpio > 0) {
1057 pdata->chg_irq_attr = chg_irq_attr;
1058 pdata->chg_irq = gpio_to_irq(chg_irq_gpio);
1060 pdata->chg_gpio_en = chg_gpio_en;
1061 pdata->chg_gpio_init = sec_chg_gpio_init;
1062 pdata->check_cable_result_callback =
1063 sec_bat_check_cable_result_callback;
1068 #ifdef CONFIG_FUELGAUGE_SPRD4SAMSUNG27X3
1069 struct battery_data_t bat_data;
1072 int sec_fg_dt_init(struct device_node *np,
1074 sec_battery_platform_data_t *pdata)
1077 unsigned int fg_irq_attr;
1079 ret = of_property_read_u32(np, "capacity-max", &pdata->capacity_max);
1082 ret = of_property_read_u32(np, "capacity-max-margin",
1083 &pdata->capacity_max_margin);
1086 ret = of_property_read_u32(np, "capacity-min", &pdata->capacity_min);
1089 ret = of_property_read_u32(np, "fg-irq-attr", &fg_irq_attr);
1092 ret = of_property_read_u32(np, "fuel-alert-soc",
1093 &pdata->fuel_alert_soc);
1096 if (of_find_property(np, "repeated-fuelalert", NULL))
1097 pdata->repeated_fuelalert = true;
1099 ret = of_property_read_u32(np, "temp_adc_channel",
1100 &pdata->temp_adc_channel);
1104 #ifdef CONFIG_FUELGAUGE_SPRD4SAMSUNG27X3
1106 struct sprd_battery_platform_data *battery_data;
1108 uint32_t cell_value;
1109 struct device_node *temp_np = NULL;
1111 battery_data = devm_kzalloc(dev, sizeof(*battery_data), GFP_KERNEL);
1112 temp_np = of_get_child_by_name(np, "sprd_fgu");
1114 return ERR_PTR(-EINVAL);
1116 battery_data->gpio_vchg_detect = (uint32_t) of_get_named_gpio(np, "gpios", 0);
1117 battery_data->irq_fgu = irq_of_parse_and_map(temp_np, 0);
1118 of_property_read_u32(np, "chg_bat_safety_vol", &battery_data->chg_bat_safety_vol);
1119 of_property_read_u32(np, "soft_vbat_uvlo", &battery_data->soft_vbat_uvlo);
1120 of_property_read_u32(np, "vmod", &battery_data->fgu_mode);
1121 of_property_read_u32(np, "alm_soc", &battery_data->alm_soc);
1122 of_property_read_u32(np, "alm_vbat", &battery_data->alm_vol);
1123 of_property_read_u32(np, "rint", &battery_data->rint);
1124 of_property_read_u32(np, "cnom", &battery_data->cnom);
1125 of_property_read_u32(np, "rsense_real", &battery_data->rsense_real);
1126 of_property_read_u32(np, "rsense_spec", &battery_data->rsense_spec);
1127 of_property_read_u32(np, "relax_current", &battery_data->relax_current);
1128 of_property_read_u32(np, "cal_ajust", &battery_data->fgu_cal_ajust);
1129 of_get_property(np, "cnom_temp_tab", &len);
1131 battery_data->cnom_temp_tab_size = len >> 1;
1132 battery_data->cnom_temp_tab = kzalloc(sizeof(struct sprdbat_table_data) *
1133 battery_data->cnom_temp_tab_size, GFP_KERNEL);
1134 for (i = 0; i < len; i++) {
1135 of_property_read_u32_index(np, "cnom_temp_tab", i, &cell_value);
1137 battery_data->cnom_temp_tab[i >> 1].y = cell_value;
1139 battery_data->cnom_temp_tab[i >> 1].x = cell_value - 1000;
1143 of_get_property(np, "rint_temp_tab", &len);
1145 battery_data->rint_temp_tab_size = len >> 1;
1146 battery_data->rint_temp_tab = kzalloc(sizeof(struct sprdbat_table_data) *
1147 battery_data->rint_temp_tab_size, GFP_KERNEL);
1148 for (i = 0; i < len; i++) {
1149 of_property_read_u32_index(np, "rint_temp_tab", i, &cell_value);
1151 battery_data->rint_temp_tab[i >> 1].y = cell_value;
1153 battery_data->rint_temp_tab[i >> 1].x = cell_value - 1000;
1156 of_get_property(np, "ocv_table", &len);
1158 battery_data->ocv_tab_size = len >> 1;
1159 battery_data->ocv_tab = kzalloc(sizeof(struct sprdbat_table_data) *
1160 battery_data->ocv_tab_size, GFP_KERNEL);
1161 for (i = 0; i < len; i++) {
1162 of_property_read_u32_index(np, "ocv_table", i, &cell_value);
1164 battery_data->ocv_tab[i >> 1].y = cell_value;
1166 battery_data->ocv_tab[i >> 1].x = cell_value;
1169 bat_data.pdata = battery_data;
1170 pdata->battery_data = &bat_data;
1174 pdata->fg_irq_attr = fg_irq_attr;
1175 pdata->fuelalert_process = sec_fg_fuelalert_process;
1176 pdata->fg_gpio_init = sec_fg_gpio_init;
1177 pdata->capacity_calculation_type =
1178 SEC_FUELGAUGE_CAPACITY_TYPE_RAW;
1179 pdata->check_jig_status = sec_bat_check_jig_status;