blob: c3369fa605f9d80a3bb29cee7b334b42c09335b2 [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 */
Chris Lapaa5deb9a2017-01-11 12:44:45 +110014 BQ27520G2, /* bq27520G2 */
Chris Lapa825e9152017-01-11 12:44:46 +110015 BQ27520G3, /* bq27520G3 */
Chris Lapa8835cae2017-01-11 12:44:47 +110016 BQ27520G4, /* bq27520G4 */
Andrew F. Davis703df6c2015-11-23 10:53:51 -060017 BQ27530, /* bq27530, bq27531 */
18 BQ27541, /* bq27541, bq27542, bq27546, bq27742 */
19 BQ27545, /* bq27545 */
20 BQ27421, /* bq27421, bq27425, bq27441, bq27621 */
21};
22
Lars-Peter Clausen7fb7ba52010-05-24 19:55:27 +020023/**
Andrew F. Davis081bab22015-09-22 14:35:06 -050024 * struct bq27xxx_plaform_data - Platform data for bq27xxx devices
Andrew F. Davis424cfde2015-09-22 14:35:07 -050025 * @name: Name of the battery.
26 * @chip: Chip class number of this device.
Lars-Peter Clausen7fb7ba52010-05-24 19:55:27 +020027 * @read: HDQ read callback.
28 * This function should provide access to the HDQ bus the battery is
29 * connected to.
30 * The first parameter is a pointer to the battery device, the second the
31 * register to be read. The return value should either be the content of
32 * the passed register or an error value.
33 */
Andrew F. Davis081bab22015-09-22 14:35:06 -050034struct bq27xxx_platform_data {
Lars-Peter Clausen7fb7ba52010-05-24 19:55:27 +020035 const char *name;
Andrew F. Davis424cfde2015-09-22 14:35:07 -050036 enum bq27xxx_chip chip;
Lars-Peter Clausen7fb7ba52010-05-24 19:55:27 +020037 int (*read)(struct device *dev, unsigned int);
38};
39
Andrew F. Davis703df6c2015-11-23 10:53:51 -060040struct bq27xxx_device_info;
41struct bq27xxx_access_methods {
42 int (*read)(struct bq27xxx_device_info *di, u8 reg, bool single);
Matt Ranostay14073f62017-06-07 11:37:54 -070043 int (*write)(struct bq27xxx_device_info *di, u8 reg, int value, bool single);
44 int (*read_bulk)(struct bq27xxx_device_info *di, u8 reg, u8 *data, int len);
45 int (*write_bulk)(struct bq27xxx_device_info *di, u8 reg, u8 *data, int len);
Andrew F. Davis703df6c2015-11-23 10:53:51 -060046};
47
48struct bq27xxx_reg_cache {
49 int temperature;
50 int time_to_empty;
51 int time_to_empty_avg;
52 int time_to_full;
53 int charge_full;
54 int cycle_count;
55 int capacity;
56 int energy;
57 int flags;
58 int power_avg;
59 int health;
60};
61
62struct bq27xxx_device_info {
63 struct device *dev;
Ivaylo Dimitrov9aafabc2016-02-02 14:47:37 +020064 int id;
Andrew F. Davis703df6c2015-11-23 10:53:51 -060065 enum bq27xxx_chip chip;
66 const char *name;
67 struct bq27xxx_access_methods bus;
68 struct bq27xxx_reg_cache cache;
69 int charge_design_full;
70 unsigned long last_update;
71 struct delayed_work work;
72 struct power_supply *bat;
Matt Ranostay1d727062016-09-19 20:43:02 -070073 struct list_head list;
Andrew F. Davis703df6c2015-11-23 10:53:51 -060074 struct mutex lock;
75 u8 *regs;
76};
77
78void bq27xxx_battery_update(struct bq27xxx_device_info *di);
79int bq27xxx_battery_setup(struct bq27xxx_device_info *di);
80void bq27xxx_battery_teardown(struct bq27xxx_device_info *di);
81
Lars-Peter Clausen7fb7ba52010-05-24 19:55:27 +020082#endif