blob: eddd969368750698f1fa71228ad200a177c0961f [file] [log] [blame]
Lars-Peter Clausen7fb7ba52010-05-24 19:55:27 +02001#ifndef __LINUX_BQ27X00_BATTERY_H__
2#define __LINUX_BQ27X00_BATTERY_H__
3
Andrew F. Davis703df6c2015-11-23 10:53:51 -06004enum bq27xxx_chip {
5 BQ27000 = 1, /* bq27000, bq27200 */
6 BQ27010, /* bq27010, bq27210 */
Chris Lapa818e3012017-01-11 12:44:38 +11007 BQ2750X, /* bq27500 deprecated alias */
Chris Lapa6da6e4b2017-01-11 12:44:39 +11008 BQ2751X, /* bq27510, bq27520 deprecated alias */
Chris Lapa32833632017-01-11 12:44:40 +11009 BQ27500, /* bq27500/1 */
Chris Lapabd281772017-01-11 12:44:41 +110010 BQ27510G1, /* bq27510G1 */
Chris Lapa698a2bf2017-01-11 12:44:42 +110011 BQ27510G2, /* bq27510G2 */
Chris Lapa71375aa2017-01-11 12:44:43 +110012 BQ27510G3, /* bq27510G3 */
Chris Lapa68f2a812017-01-11 12:44:44 +110013 BQ27520G1, /* bq27520G1 */
Andrew F. Davis703df6c2015-11-23 10:53:51 -060014 BQ27530, /* bq27530, bq27531 */
15 BQ27541, /* bq27541, bq27542, bq27546, bq27742 */
16 BQ27545, /* bq27545 */
17 BQ27421, /* bq27421, bq27425, bq27441, bq27621 */
18};
19
Lars-Peter Clausen7fb7ba52010-05-24 19:55:27 +020020/**
Andrew F. Davis081bab22015-09-22 14:35:06 -050021 * struct bq27xxx_plaform_data - Platform data for bq27xxx devices
Andrew F. Davis424cfde2015-09-22 14:35:07 -050022 * @name: Name of the battery.
23 * @chip: Chip class number of this device.
Lars-Peter Clausen7fb7ba52010-05-24 19:55:27 +020024 * @read: HDQ read callback.
25 * This function should provide access to the HDQ bus the battery is
26 * connected to.
27 * The first parameter is a pointer to the battery device, the second the
28 * register to be read. The return value should either be the content of
29 * the passed register or an error value.
30 */
Andrew F. Davis081bab22015-09-22 14:35:06 -050031struct bq27xxx_platform_data {
Lars-Peter Clausen7fb7ba52010-05-24 19:55:27 +020032 const char *name;
Andrew F. Davis424cfde2015-09-22 14:35:07 -050033 enum bq27xxx_chip chip;
Lars-Peter Clausen7fb7ba52010-05-24 19:55:27 +020034 int (*read)(struct device *dev, unsigned int);
35};
36
Andrew F. Davis703df6c2015-11-23 10:53:51 -060037struct bq27xxx_device_info;
38struct bq27xxx_access_methods {
39 int (*read)(struct bq27xxx_device_info *di, u8 reg, bool single);
40};
41
42struct bq27xxx_reg_cache {
43 int temperature;
44 int time_to_empty;
45 int time_to_empty_avg;
46 int time_to_full;
47 int charge_full;
48 int cycle_count;
49 int capacity;
50 int energy;
51 int flags;
52 int power_avg;
53 int health;
54};
55
56struct bq27xxx_device_info {
57 struct device *dev;
Ivaylo Dimitrov9aafabc2016-02-02 14:47:37 +020058 int id;
Andrew F. Davis703df6c2015-11-23 10:53:51 -060059 enum bq27xxx_chip chip;
60 const char *name;
61 struct bq27xxx_access_methods bus;
62 struct bq27xxx_reg_cache cache;
63 int charge_design_full;
64 unsigned long last_update;
65 struct delayed_work work;
66 struct power_supply *bat;
Matt Ranostay1d727062016-09-19 20:43:02 -070067 struct list_head list;
Andrew F. Davis703df6c2015-11-23 10:53:51 -060068 struct mutex lock;
69 u8 *regs;
70};
71
72void bq27xxx_battery_update(struct bq27xxx_device_info *di);
73int bq27xxx_battery_setup(struct bq27xxx_device_info *di);
74void bq27xxx_battery_teardown(struct bq27xxx_device_info *di);
75
Lars-Peter Clausen7fb7ba52010-05-24 19:55:27 +020076#endif