sec_charging_common.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  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. #ifndef __SEC_CHARGING_COMMON_H
  19. #define __SEC_CHARGING_COMMON_H __FILE__
  20. #include <linux/module.h>
  21. #include <linux/init.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/err.h>
  24. #include <linux/delay.h>
  25. #include <linux/gpio.h>
  26. #include <linux/irq.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/i2c.h>
  29. #include <linux/power_supply.h>
  30. #include <linux/slab.h>
  31. #include <linux/device.h>
  32. /* definitions */
  33. #define SEC_SIZEOF_POWER_SUPPLY_TYPE POWER_SUPPLY_TYPE_MAX
  34. enum sec_battery_voltage_mode {
  35. /* average voltage */
  36. SEC_BATTEY_VOLTAGE_AVERAGE = 0,
  37. /* open circuit voltage */
  38. SEC_BATTEY_VOLTAGE_OCV,
  39. };
  40. enum sec_battery_current_mode {
  41. /* uA */
  42. SEC_BATTEY_CURRENT_UA = 0,
  43. /* mA */
  44. SEC_BATTEY_CURRENT_MA,
  45. };
  46. enum sec_battery_capacity_mode {
  47. /* designed capacity */
  48. SEC_BATTEY_CAPACITY_DESIGNED = 0,
  49. /* absolute capacity by fuel gauge */
  50. SEC_BATTEY_CAPACITY_ABSOLUTE,
  51. /* temperary capacity in the time */
  52. SEC_BATTEY_CAPACITY_TEMPERARY,
  53. /* current capacity now */
  54. SEC_BATTEY_CAPACITY_CURRENT,
  55. };
  56. /* ADC type */
  57. enum sec_battery_adc_type {
  58. /* NOT using this ADC channel */
  59. SEC_BATTERY_ADC_TYPE_NONE = 0,
  60. /* ADC in AP */
  61. SEC_BATTERY_ADC_TYPE_AP,
  62. /* ADC by additional IC */
  63. SEC_BATTERY_ADC_TYPE_IC,
  64. SEC_BATTERY_ADC_TYPE_NUM
  65. };
  66. enum sec_battery_adc_channel {
  67. SEC_BAT_ADC_CHANNEL_CABLE_CHECK = 0,
  68. SEC_BAT_ADC_CHANNEL_BAT_CHECK,
  69. SEC_BAT_ADC_CHANNEL_TEMP,
  70. SEC_BAT_ADC_CHANNEL_TEMP_AMBIENT,
  71. SEC_BAT_ADC_CHANNEL_CHG_TEMP,
  72. SEC_BAT_ADC_CHANNEL_FULL_CHECK,
  73. SEC_BAT_ADC_CHANNEL_VOLTAGE_NOW,
  74. SEC_BAT_ADC_CHANNEL_INBAT_VOLTAGE,
  75. SEC_BAT_ADC_CHANNEL_NUM
  76. };
  77. /* charging mode */
  78. enum sec_battery_charging_mode {
  79. /* no charging */
  80. SEC_BATTERY_CHARGING_NONE = 0,
  81. /* 1st charging */
  82. SEC_BATTERY_CHARGING_1ST,
  83. /* 2nd charging */
  84. SEC_BATTERY_CHARGING_2ND,
  85. /* recharging */
  86. SEC_BATTERY_CHARGING_RECHARGING,
  87. };
  88. struct sec_bat_adc_api {
  89. bool (*init)(struct platform_device *);
  90. bool (*exit)(void);
  91. int (*read)(unsigned int);
  92. };
  93. #define sec_bat_adc_api_t struct sec_bat_adc_api
  94. /* monitor activation */
  95. enum sec_battery_polling_time_type {
  96. /* same order with power supply status */
  97. SEC_BATTERY_POLLING_TIME_BASIC = 0,
  98. SEC_BATTERY_POLLING_TIME_CHARGING,
  99. SEC_BATTERY_POLLING_TIME_DISCHARGING,
  100. SEC_BATTERY_POLLING_TIME_NOT_CHARGING,
  101. SEC_BATTERY_POLLING_TIME_SLEEP,
  102. };
  103. enum sec_battery_monitor_polling {
  104. /* polling work queue */
  105. SEC_BATTERY_MONITOR_WORKQUEUE,
  106. /* alarm polling */
  107. SEC_BATTERY_MONITOR_ALARM,
  108. /* timer polling (NOT USE) */
  109. SEC_BATTERY_MONITOR_TIMER,
  110. };
  111. #define sec_battery_monitor_polling_t \
  112. enum sec_battery_monitor_polling
  113. /* full charged check : POWER_SUPPLY_PROP_STATUS */
  114. enum sec_battery_full_charged {
  115. SEC_BATTERY_FULLCHARGED_NONE = 0,
  116. /* current check by ADC */
  117. SEC_BATTERY_FULLCHARGED_ADC,
  118. /* fuel gauge current check */
  119. SEC_BATTERY_FULLCHARGED_FG_CURRENT,
  120. /* time check */
  121. SEC_BATTERY_FULLCHARGED_TIME,
  122. /* SOC check */
  123. SEC_BATTERY_FULLCHARGED_SOC,
  124. /* charger GPIO, NO additional full condition */
  125. SEC_BATTERY_FULLCHARGED_CHGGPIO,
  126. /* charger interrupt, NO additional full condition */
  127. SEC_BATTERY_FULLCHARGED_CHGINT,
  128. /* charger power supply property, NO additional full condition */
  129. SEC_BATTERY_FULLCHARGED_CHGPSY,
  130. };
  131. #define sec_battery_full_charged_t \
  132. enum sec_battery_full_charged
  133. /* full check condition type (can be used overlapped) */
  134. #define sec_battery_full_condition_t unsigned int
  135. /* SEC_BATTERY_FULL_CONDITION_NOTIMEFULL
  136. * full-charged by absolute-timer only in high voltage
  137. */
  138. #define SEC_BATTERY_FULL_CONDITION_NOTIMEFULL 1
  139. /* SEC_BATTERY_FULL_CONDITION_NOSLEEPINFULL
  140. * do not set polling time as sleep polling time in full-charged
  141. */
  142. #define SEC_BATTERY_FULL_CONDITION_NOSLEEPINFULL 2
  143. /* SEC_BATTERY_FULL_CONDITION_SOC
  144. * use capacity for full-charged check
  145. */
  146. #define SEC_BATTERY_FULL_CONDITION_SOC 4
  147. /* SEC_BATTERY_FULL_CONDITION_VCELL
  148. * use VCELL for full-charged check
  149. */
  150. #define SEC_BATTERY_FULL_CONDITION_VCELL 8
  151. /* SEC_BATTERY_FULL_CONDITION_AVGVCELL
  152. * use average VCELL for full-charged check
  153. */
  154. #define SEC_BATTERY_FULL_CONDITION_AVGVCELL 16
  155. /* SEC_BATTERY_FULL_CONDITION_OCV
  156. * use OCV for full-charged check
  157. */
  158. #define SEC_BATTERY_FULL_CONDITION_OCV 32
  159. /* recharge check condition type (can be used overlapped) */
  160. #define sec_battery_recharge_condition_t unsigned int
  161. /* SEC_BATTERY_RECHARGE_CONDITION_SOC
  162. * use capacity for recharging check
  163. */
  164. #define SEC_BATTERY_RECHARGE_CONDITION_SOC 1
  165. /* SEC_BATTERY_RECHARGE_CONDITION_AVGVCELL
  166. * use average VCELL for recharging check
  167. */
  168. #define SEC_BATTERY_RECHARGE_CONDITION_AVGVCELL 2
  169. /* SEC_BATTERY_RECHARGE_CONDITION_VCELL
  170. * use VCELL for recharging check
  171. */
  172. #define SEC_BATTERY_RECHARGE_CONDITION_VCELL 4
  173. /* battery check : POWER_SUPPLY_PROP_PRESENT */
  174. enum sec_battery_check {
  175. /* No Check for internal battery */
  176. SEC_BATTERY_CHECK_NONE,
  177. /* by ADC */
  178. SEC_BATTERY_CHECK_ADC,
  179. /* by callback function (battery certification by 1 wired)*/
  180. SEC_BATTERY_CHECK_CALLBACK,
  181. /* by PMIC */
  182. SEC_BATTERY_CHECK_PMIC,
  183. /* by fuel gauge */
  184. SEC_BATTERY_CHECK_FUELGAUGE,
  185. /* by charger */
  186. SEC_BATTERY_CHECK_CHARGER,
  187. /* by interrupt (use check_battery_callback() to check battery) */
  188. SEC_BATTERY_CHECK_INT,
  189. };
  190. #define sec_battery_check_t \
  191. enum sec_battery_check
  192. /* OVP, UVLO check : POWER_SUPPLY_PROP_HEALTH */
  193. enum sec_battery_ovp_uvlo {
  194. /* by callback function */
  195. SEC_BATTERY_OVP_UVLO_CALLBACK,
  196. /* by PMIC polling */
  197. SEC_BATTERY_OVP_UVLO_PMICPOLLING,
  198. /* by PMIC interrupt */
  199. SEC_BATTERY_OVP_UVLO_PMICINT,
  200. /* by charger polling */
  201. SEC_BATTERY_OVP_UVLO_CHGPOLLING,
  202. /* by charger interrupt */
  203. SEC_BATTERY_OVP_UVLO_CHGINT,
  204. };
  205. #define sec_battery_ovp_uvlo_t \
  206. enum sec_battery_ovp_uvlo
  207. /* thermal source */
  208. enum sec_battery_thermal_source {
  209. /* by fuel gauge */
  210. SEC_BATTERY_THERMAL_SOURCE_FG,
  211. /* by external source */
  212. SEC_BATTERY_THERMAL_SOURCE_CALLBACK,
  213. /* by ADC */
  214. SEC_BATTERY_THERMAL_SOURCE_ADC,
  215. };
  216. #define sec_battery_thermal_source_t \
  217. enum sec_battery_thermal_source
  218. /* temperature check type */
  219. enum sec_battery_temp_check {
  220. SEC_BATTERY_TEMP_CHECK_NONE = 0, /* no temperature check */
  221. SEC_BATTERY_TEMP_CHECK_ADC, /* by ADC value */
  222. SEC_BATTERY_TEMP_CHECK_TEMP, /* by temperature */
  223. };
  224. #define sec_battery_temp_check_t \
  225. enum sec_battery_temp_check
  226. /* cable check (can be used overlapped) */
  227. #define sec_battery_cable_check_t unsigned int
  228. /* SEC_BATTERY_CABLE_CHECK_NOUSBCHARGE
  229. * for USB cable in tablet model,
  230. * status is stuck into discharging,
  231. * but internal charging logic is working
  232. */
  233. #define SEC_BATTERY_CABLE_CHECK_NOUSBCHARGE 1
  234. /* SEC_BATTERY_CABLE_CHECK_NOINCOMPATIBLECHARGE
  235. * for incompatible charger
  236. * (Not compliant to USB specification,
  237. * cable type is POWER_SUPPLY_TYPE_UNKNOWN),
  238. * do NOT charge and show message to user
  239. * (only for VZW)
  240. */
  241. #define SEC_BATTERY_CABLE_CHECK_NOINCOMPATIBLECHARGE 2
  242. /* SEC_BATTERY_CABLE_CHECK_PSY
  243. * check cable by power supply set_property
  244. */
  245. #define SEC_BATTERY_CABLE_CHECK_PSY 4
  246. /* SEC_BATTERY_CABLE_CHECK_INT
  247. * check cable by interrupt
  248. */
  249. #define SEC_BATTERY_CABLE_CHECK_INT 8
  250. /* SEC_BATTERY_CABLE_CHECK_CHGINT
  251. * check cable by charger interrupt
  252. */
  253. #define SEC_BATTERY_CABLE_CHECK_CHGINT 16
  254. /* SEC_BATTERY_CABLE_CHECK_POLLING
  255. * check cable by GPIO polling
  256. */
  257. #define SEC_BATTERY_CABLE_CHECK_POLLING 32
  258. /* check cable source (can be used overlapped) */
  259. #define sec_battery_cable_source_t unsigned int
  260. /* SEC_BATTERY_CABLE_SOURCE_EXTERNAL
  261. * already given by external argument
  262. */
  263. #define SEC_BATTERY_CABLE_SOURCE_EXTERNAL 1
  264. /* SEC_BATTERY_CABLE_SOURCE_CALLBACK
  265. * by callback (MUIC, USB switch)
  266. */
  267. #define SEC_BATTERY_CABLE_SOURCE_CALLBACK 2
  268. /* SEC_BATTERY_CABLE_SOURCE_ADC
  269. * by ADC
  270. */
  271. #define SEC_BATTERY_CABLE_SOURCE_ADC 4
  272. /* SEC_BATTERY_CABLE_SOURCE_EXTENDED
  273. * use extended cable type
  274. */
  275. #define SEC_BATTERY_CABLE_SOURCE_EXTENDED 8
  276. /* capacity calculation type (can be used overlapped) */
  277. #define sec_fuelgauge_capacity_type_t int
  278. /* SEC_FUELGAUGE_CAPACITY_TYPE_RESET
  279. * use capacity information to reset fuel gauge
  280. * (only for driver algorithm, can NOT be set by user)
  281. */
  282. #define SEC_FUELGAUGE_CAPACITY_TYPE_RESET (-1)
  283. /* SEC_FUELGAUGE_CAPACITY_TYPE_RAW
  284. * use capacity information from fuel gauge directly
  285. */
  286. #define SEC_FUELGAUGE_CAPACITY_TYPE_RAW 1
  287. /* SEC_FUELGAUGE_CAPACITY_TYPE_SCALE
  288. * rescale capacity by scaling, need min and max value for scaling
  289. */
  290. #define SEC_FUELGAUGE_CAPACITY_TYPE_SCALE 2
  291. /* SEC_FUELGAUGE_CAPACITY_TYPE_DYNAMIC_SCALE
  292. * change only maximum capacity dynamically
  293. * to keep time for every SOC unit
  294. */
  295. #define SEC_FUELGAUGE_CAPACITY_TYPE_DYNAMIC_SCALE 4
  296. /* SEC_FUELGAUGE_CAPACITY_TYPE_ATOMIC
  297. * change capacity value by only -1 or +1
  298. * no sudden change of capacity
  299. */
  300. #define SEC_FUELGAUGE_CAPACITY_TYPE_ATOMIC 8
  301. /* SEC_FUELGAUGE_CAPACITY_TYPE_SKIP_ABNORMAL
  302. * skip current capacity value
  303. * if it is abnormal value
  304. */
  305. #define SEC_FUELGAUGE_CAPACITY_TYPE_SKIP_ABNORMAL 16
  306. /* charger function settings (can be used overlapped) */
  307. #define sec_charger_functions_t unsigned int
  308. /* SEC_CHARGER_NO_GRADUAL_CHARGING_CURRENT
  309. * disable gradual charging current setting
  310. * SUMMIT:AICL, MAXIM:regulation loop
  311. */
  312. #define SEC_CHARGER_NO_GRADUAL_CHARGING_CURRENT 1
  313. /* SEC_CHARGER_MINIMUM_SIOP_CHARGING_CURRENT
  314. * charging current should be over than USB charging current
  315. */
  316. #define SEC_CHARGER_MINIMUM_SIOP_CHARGING_CURRENT 2
  317. /**
  318. * struct sec_bat_adc_table_data - adc to temperature table for sec battery
  319. * driver
  320. * @adc: adc value
  321. * @temperature: temperature(C) * 10
  322. */
  323. struct sec_bat_adc_table_data {
  324. int adc;
  325. int data;
  326. };
  327. #define sec_bat_adc_table_data_t \
  328. struct sec_bat_adc_table_data
  329. struct sec_bat_adc_region {
  330. int min;
  331. int max;
  332. };
  333. #define sec_bat_adc_region_t \
  334. struct sec_bat_adc_region
  335. struct sec_charging_current {
  336. int input_current_limit;
  337. int fast_charging_current;
  338. int full_check_current_1st;
  339. int full_check_current_2nd;
  340. };
  341. #define sec_charging_current_t \
  342. struct sec_charging_current
  343. struct sec_battery_platform_data {
  344. /* NO NEED TO BE CHANGED */
  345. /* callback functions */
  346. void (*monitor_additional_check)(void);
  347. bool (*bat_gpio_init)(void);
  348. bool (*fg_gpio_init)(void);
  349. bool (*chg_gpio_init)(void);
  350. bool (*is_lpm)(void);
  351. bool (*check_jig_status)(void);
  352. bool (*is_interrupt_cable_check_possible)(int);
  353. int (*check_cable_callback)(void);
  354. int (*get_cable_from_extended_cable_type)(int);
  355. bool (*cable_switch_check)(void);
  356. bool (*cable_switch_normal)(void);
  357. bool (*check_cable_result_callback)(int);
  358. bool (*check_battery_callback)(void);
  359. bool (*check_battery_result_callback)(void);
  360. int (*ovp_uvlo_callback)(void);
  361. bool (*ovp_uvlo_result_callback)(int);
  362. bool (*fuelalert_process)(bool);
  363. bool (*get_temperature_callback)(
  364. enum power_supply_property,
  365. union power_supply_propval*);
  366. void (*check_batt_id)(void);
  367. /* ADC API for each ADC type */
  368. sec_bat_adc_api_t adc_api[SEC_BATTERY_ADC_TYPE_NUM];
  369. /* ADC region by power supply type
  370. * ADC region should be exclusive
  371. */
  372. sec_bat_adc_region_t *cable_adc_value;
  373. /* charging current for type (0: not use) */
  374. sec_charging_current_t *charging_current;
  375. #ifdef CONFIG_OF
  376. char *chip_vendor;
  377. unsigned int temp_adc_type;
  378. #endif
  379. int *polling_time;
  380. /* NO NEED TO BE CHANGED */
  381. char *pmic_name;
  382. /* battery */
  383. char *vendor;
  384. int technology;
  385. int battery_type;
  386. void *battery_data;
  387. int bat_gpio_ta_nconnected;
  388. /* 1 : active high, 0 : active low */
  389. int bat_polarity_ta_nconnected;
  390. int ta_irq;
  391. int ta_irq_gpio; /* TA_INT(Vbus detecting) */
  392. unsigned long ta_irq_attr;
  393. int bat_irq;
  394. int bat_irq_gpio; /* BATT_INT(BAT_ID detecting) */
  395. unsigned long bat_irq_attr;
  396. int jig_irq;
  397. unsigned long jig_irq_attr;
  398. sec_battery_cable_check_t cable_check_type;
  399. sec_battery_cable_source_t cable_source_type;
  400. bool use_LED; /* use charging LED */
  401. bool event_check;
  402. bool use_wireless_to_pogo;
  403. bool chg_temp_check;
  404. unsigned int chg_high_temp;
  405. unsigned int chg_high_temp_recovery;
  406. unsigned int chg_charging_limit_current;
  407. /* sustaining event after deactivated (second) */
  408. unsigned int event_waiting_time;
  409. #if defined(CONFIG_BATTERY_SWELLING)
  410. /* battery swelling */
  411. int swelling_high_temp_block;
  412. int swelling_high_temp_recov;
  413. int swelling_low_temp_block;
  414. int swelling_low_temp_recov;
  415. unsigned int swelling_high_chg_current;
  416. unsigned int swelling_low_chg_current;
  417. unsigned int swelling_normal_float_voltage;
  418. unsigned int swelling_drop_float_voltage;
  419. unsigned int swelling_high_rechg_voltage;
  420. unsigned int swelling_low_rechg_voltage;
  421. #endif
  422. /* Monitor setting */
  423. sec_battery_monitor_polling_t polling_type;
  424. /* for initial check */
  425. unsigned int monitor_initial_count;
  426. /* Battery check */
  427. sec_battery_check_t battery_check_type;
  428. /* how many times do we need to check battery */
  429. unsigned int check_count;
  430. /* ADC */
  431. /* battery check ADC maximum value */
  432. unsigned int check_adc_max;
  433. /* battery check ADC minimum value */
  434. unsigned int check_adc_min;
  435. /* OVP/UVLO check */
  436. sec_battery_ovp_uvlo_t ovp_uvlo_check_type;
  437. sec_battery_thermal_source_t thermal_source;
  438. #ifdef CONFIG_OF
  439. sec_bat_adc_table_data_t *temp_adc_table;
  440. sec_bat_adc_table_data_t *temp_amb_adc_table;
  441. sec_bat_adc_table_data_t *chg_temp_adc_table;
  442. sec_bat_adc_table_data_t *inbat_adc_table;
  443. #else
  444. const sec_bat_adc_table_data_t *temp_adc_table;
  445. const sec_bat_adc_table_data_t *temp_amb_adc_table;
  446. #endif
  447. unsigned int temp_adc_table_size;
  448. unsigned int temp_amb_adc_table_size;
  449. unsigned int chg_temp_adc_table_size;
  450. unsigned int inbat_adc_table_size;
  451. sec_battery_temp_check_t temp_check_type;
  452. unsigned int temp_check_count;
  453. unsigned int inbat_voltage;
  454. /*
  455. * limit can be ADC value or Temperature
  456. * depending on temp_check_type
  457. * temperature should be temp x 10 (0.1 degree)
  458. */
  459. int temp_highlimit_threshold_event;
  460. int temp_highlimit_recovery_event;
  461. int temp_high_threshold_event;
  462. int temp_high_recovery_event;
  463. int temp_low_threshold_event;
  464. int temp_low_recovery_event;
  465. int temp_highlimit_threshold_normal;
  466. int temp_highlimit_recovery_normal;
  467. int temp_high_threshold_normal;
  468. int temp_high_recovery_normal;
  469. int temp_low_threshold_normal;
  470. int temp_low_recovery_normal;
  471. int temp_highlimit_threshold_lpm;
  472. int temp_highlimit_recovery_lpm;
  473. int temp_high_threshold_lpm;
  474. int temp_high_recovery_lpm;
  475. int temp_low_threshold_lpm;
  476. int temp_low_recovery_lpm;
  477. /* If these is NOT full check type or NONE full check type,
  478. * it is skipped
  479. */
  480. /* 1st full check */
  481. sec_battery_full_charged_t full_check_type;
  482. /* 2nd full check */
  483. sec_battery_full_charged_t full_check_type_2nd;
  484. unsigned int full_check_count;
  485. int chg_gpio_full_check;
  486. /* 1 : active high, 0 : active low */
  487. int chg_polarity_full_check;
  488. sec_battery_full_condition_t full_condition_type;
  489. unsigned int full_condition_soc;
  490. unsigned int full_condition_vcell;
  491. unsigned int full_condition_avgvcell;
  492. unsigned int full_condition_ocv;
  493. unsigned int recharge_check_count;
  494. sec_battery_recharge_condition_t recharge_condition_type;
  495. unsigned int recharge_condition_soc;
  496. unsigned int recharge_condition_avgvcell;
  497. unsigned int recharge_condition_vcell;
  498. /* for absolute timer (second) */
  499. unsigned long charging_total_time;
  500. /* for recharging timer (second) */
  501. unsigned long recharging_total_time;
  502. /* reset charging for abnormal malfunction (0: not use) */
  503. unsigned long charging_reset_time;
  504. /* fuel gauge */
  505. char *fuelgauge_name;
  506. int fg_irq;
  507. unsigned long fg_irq_attr;
  508. /* fuel alert SOC (-1: not use) */
  509. int fuel_alert_soc;
  510. /* fuel alert can be repeated */
  511. bool repeated_fuelalert;
  512. sec_fuelgauge_capacity_type_t capacity_calculation_type;
  513. /* soc should be soc x 10 (0.1% degree)
  514. * only for scaling
  515. */
  516. int capacity_max;
  517. int capacity_max_hv;
  518. int capacity_max_margin;
  519. int capacity_min;
  520. int rcomp0;
  521. int rcomp_charging;
  522. /* charger */
  523. char *charger_name;
  524. int vbus_ctrl_gpio;
  525. int chg_gpio_en;
  526. /* 1 : active high, 0 : active low */
  527. int chg_polarity_en;
  528. int chg_gpio_curr_adj;
  529. /* 1 : active high, 0 : active low */
  530. int chg_polarity_curr_adj;
  531. int chg_gpio_status;
  532. /* 1 : active high, 0 : active low */
  533. int chg_polarity_status;
  534. int chg_irq;
  535. unsigned long chg_irq_attr;
  536. /* float voltage (mV) */
  537. int chg_float_voltage;
  538. int chg_min_system_voltage;
  539. sec_charger_functions_t chg_functions_setting;
  540. int siop_level;
  541. bool siop_activated;
  542. /* ADC setting */
  543. unsigned int adc_check_count;
  544. /* ADC type for each channel */
  545. unsigned int adc_type[];
  546. };
  547. #define sec_battery_platform_data_t \
  548. struct sec_battery_platform_data
  549. static inline struct power_supply *get_power_supply_by_name(char *name)
  550. {
  551. if (!name)
  552. return (struct power_supply *)NULL;
  553. else
  554. return power_supply_get_by_name(name);
  555. }
  556. #define psy_do_property(name, function, property, value) \
  557. { \
  558. struct power_supply *psy; \
  559. int ret; \
  560. psy = get_power_supply_by_name((name)); \
  561. if (!psy) { \
  562. pr_err("%s: Fail to "#function" psy (%s)\n", \
  563. __func__, (name)); \
  564. value.intval = 0; \
  565. } else { \
  566. if (psy->function##_property != NULL) { \
  567. ret = psy->function##_property(psy, (property), &(value)); \
  568. if (ret < 0) { \
  569. pr_err("%s: Fail to %s "#function" (%d=>%d)\n", \
  570. __func__, name, (property), ret); \
  571. value.intval = 0; \
  572. } \
  573. } \
  574. } \
  575. }
  576. #ifndef CONFIG_OF
  577. #define adc_init(pdev, pdata, channel) \
  578. (((pdata)->adc_api)[((((pdata)->adc_type[(channel)]) < \
  579. SEC_BATTERY_ADC_TYPE_NUM) ? ((pdata)->adc_type[(channel)]) : \
  580. SEC_BATTERY_ADC_TYPE_NONE)].init((pdev)))
  581. #define adc_exit(pdata, channel) \
  582. (((pdata)->adc_api)[((pdata)->adc_type[(channel)])].exit())
  583. #define adc_read(pdata, channel) \
  584. (((pdata)->adc_api)[((pdata)->adc_type[(channel)])].read((channel)))
  585. #endif
  586. #define get_battery_data(driver) \
  587. (((struct battery_data_t *)(driver)->pdata->battery_data) \
  588. [(driver)->pdata->battery_type])
  589. #define GET_MAIN_CABLE_TYPE(extended) \
  590. ((extended >> ONLINE_TYPE_MAIN_SHIFT)&0xf)
  591. #define GET_SUB_CABLE_TYPE(extended) \
  592. ((extended >> ONLINE_TYPE_SUB_SHIFT)&0xf)
  593. #define GET_POWER_CABLE_TYPE(extended) \
  594. ((extended >> ONLINE_TYPE_PWR_SHIFT)&0xf)
  595. #endif /* __SEC_CHARGING_COMMON_H */