Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1 | /* |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 2 | * bq2415x charger driver |
| 3 | * |
Pali Rohár | 3226030 | 2013-11-19 11:18:04 +0100 | [diff] [blame] | 4 | * Copyright (C) 2011-2013 Pali Rohár <pali.rohar@gmail.com> |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 16 | * Datasheets: |
| 17 | * http://www.ti.com/product/bq24150 |
| 18 | * http://www.ti.com/product/bq24150a |
| 19 | * http://www.ti.com/product/bq24152 |
| 20 | * http://www.ti.com/product/bq24153 |
| 21 | * http://www.ti.com/product/bq24153a |
| 22 | * http://www.ti.com/product/bq24155 |
Anda-Maria Nicolae | 0e1392d | 2015-03-05 13:23:57 +0200 | [diff] [blame] | 23 | * http://www.ti.com/product/bq24157s |
| 24 | * http://www.ti.com/product/bq24158 |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 25 | */ |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 26 | |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 27 | #include <linux/kernel.h> |
| 28 | #include <linux/module.h> |
| 29 | #include <linux/param.h> |
| 30 | #include <linux/err.h> |
| 31 | #include <linux/workqueue.h> |
| 32 | #include <linux/sysfs.h> |
| 33 | #include <linux/platform_device.h> |
| 34 | #include <linux/power_supply.h> |
| 35 | #include <linux/idr.h> |
| 36 | #include <linux/i2c.h> |
| 37 | #include <linux/slab.h> |
Anda-Maria Nicolae | b01e7c3 | 2015-05-12 12:11:33 +0300 | [diff] [blame] | 38 | #include <linux/acpi.h> |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 39 | |
| 40 | #include <linux/power/bq2415x_charger.h> |
| 41 | |
| 42 | /* timeout for resetting chip timer */ |
| 43 | #define BQ2415X_TIMER_TIMEOUT 10 |
| 44 | |
| 45 | #define BQ2415X_REG_STATUS 0x00 |
| 46 | #define BQ2415X_REG_CONTROL 0x01 |
| 47 | #define BQ2415X_REG_VOLTAGE 0x02 |
| 48 | #define BQ2415X_REG_VENDER 0x03 |
| 49 | #define BQ2415X_REG_CURRENT 0x04 |
| 50 | |
| 51 | /* reset state for all registers */ |
| 52 | #define BQ2415X_RESET_STATUS BIT(6) |
| 53 | #define BQ2415X_RESET_CONTROL (BIT(4)|BIT(5)) |
| 54 | #define BQ2415X_RESET_VOLTAGE (BIT(1)|BIT(3)) |
| 55 | #define BQ2415X_RESET_CURRENT (BIT(0)|BIT(3)|BIT(7)) |
| 56 | |
| 57 | /* status register */ |
| 58 | #define BQ2415X_BIT_TMR_RST 7 |
| 59 | #define BQ2415X_BIT_OTG 7 |
| 60 | #define BQ2415X_BIT_EN_STAT 6 |
| 61 | #define BQ2415X_MASK_STAT (BIT(4)|BIT(5)) |
| 62 | #define BQ2415X_SHIFT_STAT 4 |
| 63 | #define BQ2415X_BIT_BOOST 3 |
| 64 | #define BQ2415X_MASK_FAULT (BIT(0)|BIT(1)|BIT(2)) |
| 65 | #define BQ2415X_SHIFT_FAULT 0 |
| 66 | |
| 67 | /* control register */ |
| 68 | #define BQ2415X_MASK_LIMIT (BIT(6)|BIT(7)) |
| 69 | #define BQ2415X_SHIFT_LIMIT 6 |
| 70 | #define BQ2415X_MASK_VLOWV (BIT(4)|BIT(5)) |
| 71 | #define BQ2415X_SHIFT_VLOWV 4 |
| 72 | #define BQ2415X_BIT_TE 3 |
| 73 | #define BQ2415X_BIT_CE 2 |
| 74 | #define BQ2415X_BIT_HZ_MODE 1 |
| 75 | #define BQ2415X_BIT_OPA_MODE 0 |
| 76 | |
| 77 | /* voltage register */ |
| 78 | #define BQ2415X_MASK_VO (BIT(2)|BIT(3)|BIT(4)|BIT(5)|BIT(6)|BIT(7)) |
| 79 | #define BQ2415X_SHIFT_VO 2 |
| 80 | #define BQ2415X_BIT_OTG_PL 1 |
| 81 | #define BQ2415X_BIT_OTG_EN 0 |
| 82 | |
| 83 | /* vender register */ |
| 84 | #define BQ2415X_MASK_VENDER (BIT(5)|BIT(6)|BIT(7)) |
| 85 | #define BQ2415X_SHIFT_VENDER 5 |
| 86 | #define BQ2415X_MASK_PN (BIT(3)|BIT(4)) |
| 87 | #define BQ2415X_SHIFT_PN 3 |
| 88 | #define BQ2415X_MASK_REVISION (BIT(0)|BIT(1)|BIT(2)) |
| 89 | #define BQ2415X_SHIFT_REVISION 0 |
| 90 | |
| 91 | /* current register */ |
| 92 | #define BQ2415X_MASK_RESET BIT(7) |
| 93 | #define BQ2415X_MASK_VI_CHRG (BIT(4)|BIT(5)|BIT(6)) |
| 94 | #define BQ2415X_SHIFT_VI_CHRG 4 |
| 95 | /* N/A BIT(3) */ |
| 96 | #define BQ2415X_MASK_VI_TERM (BIT(0)|BIT(1)|BIT(2)) |
| 97 | #define BQ2415X_SHIFT_VI_TERM 0 |
| 98 | |
| 99 | |
| 100 | enum bq2415x_command { |
| 101 | BQ2415X_TIMER_RESET, |
| 102 | BQ2415X_OTG_STATUS, |
| 103 | BQ2415X_STAT_PIN_STATUS, |
| 104 | BQ2415X_STAT_PIN_ENABLE, |
| 105 | BQ2415X_STAT_PIN_DISABLE, |
| 106 | BQ2415X_CHARGE_STATUS, |
| 107 | BQ2415X_BOOST_STATUS, |
| 108 | BQ2415X_FAULT_STATUS, |
| 109 | |
| 110 | BQ2415X_CHARGE_TERMINATION_STATUS, |
| 111 | BQ2415X_CHARGE_TERMINATION_ENABLE, |
| 112 | BQ2415X_CHARGE_TERMINATION_DISABLE, |
| 113 | BQ2415X_CHARGER_STATUS, |
| 114 | BQ2415X_CHARGER_ENABLE, |
| 115 | BQ2415X_CHARGER_DISABLE, |
| 116 | BQ2415X_HIGH_IMPEDANCE_STATUS, |
| 117 | BQ2415X_HIGH_IMPEDANCE_ENABLE, |
| 118 | BQ2415X_HIGH_IMPEDANCE_DISABLE, |
| 119 | BQ2415X_BOOST_MODE_STATUS, |
| 120 | BQ2415X_BOOST_MODE_ENABLE, |
| 121 | BQ2415X_BOOST_MODE_DISABLE, |
| 122 | |
| 123 | BQ2415X_OTG_LEVEL, |
| 124 | BQ2415X_OTG_ACTIVATE_HIGH, |
| 125 | BQ2415X_OTG_ACTIVATE_LOW, |
| 126 | BQ2415X_OTG_PIN_STATUS, |
| 127 | BQ2415X_OTG_PIN_ENABLE, |
| 128 | BQ2415X_OTG_PIN_DISABLE, |
| 129 | |
| 130 | BQ2415X_VENDER_CODE, |
| 131 | BQ2415X_PART_NUMBER, |
| 132 | BQ2415X_REVISION, |
| 133 | }; |
| 134 | |
| 135 | enum bq2415x_chip { |
| 136 | BQUNKNOWN, |
| 137 | BQ24150, |
| 138 | BQ24150A, |
| 139 | BQ24151, |
| 140 | BQ24151A, |
| 141 | BQ24152, |
| 142 | BQ24153, |
| 143 | BQ24153A, |
| 144 | BQ24155, |
| 145 | BQ24156, |
| 146 | BQ24156A, |
Anda-Maria Nicolae | 0e1392d | 2015-03-05 13:23:57 +0200 | [diff] [blame] | 147 | BQ24157S, |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 148 | BQ24158, |
| 149 | }; |
| 150 | |
| 151 | static char *bq2415x_chip_name[] = { |
| 152 | "unknown", |
| 153 | "bq24150", |
| 154 | "bq24150a", |
| 155 | "bq24151", |
| 156 | "bq24151a", |
| 157 | "bq24152", |
| 158 | "bq24153", |
| 159 | "bq24153a", |
| 160 | "bq24155", |
| 161 | "bq24156", |
| 162 | "bq24156a", |
Anda-Maria Nicolae | 0e1392d | 2015-03-05 13:23:57 +0200 | [diff] [blame] | 163 | "bq24157s", |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 164 | "bq24158", |
| 165 | }; |
| 166 | |
| 167 | struct bq2415x_device { |
| 168 | struct device *dev; |
| 169 | struct bq2415x_platform_data init_data; |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 170 | struct power_supply *charger; |
| 171 | struct power_supply_desc charger_desc; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 172 | struct delayed_work work; |
Pali Rohár | b68c316 | 2015-08-11 13:22:19 +0200 | [diff] [blame] | 173 | struct device_node *notify_node; |
Pali Rohár | 3226030 | 2013-11-19 11:18:04 +0100 | [diff] [blame] | 174 | struct notifier_block nb; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 175 | enum bq2415x_mode reported_mode;/* mode reported by hook function */ |
Pavel Machek | 881f985 | 2015-02-11 11:47:16 +0100 | [diff] [blame] | 176 | enum bq2415x_mode mode; /* currently configured mode */ |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 177 | enum bq2415x_chip chip; |
| 178 | const char *timer_error; |
| 179 | char *model; |
| 180 | char *name; |
| 181 | int autotimer; /* 1 - if driver automatically reset timer, 0 - not */ |
| 182 | int automode; /* 1 - enabled, 0 - disabled; -1 - not supported */ |
| 183 | int id; |
| 184 | }; |
| 185 | |
| 186 | /* each registered chip must have unique id */ |
| 187 | static DEFINE_IDR(bq2415x_id); |
| 188 | |
| 189 | static DEFINE_MUTEX(bq2415x_id_mutex); |
| 190 | static DEFINE_MUTEX(bq2415x_timer_mutex); |
| 191 | static DEFINE_MUTEX(bq2415x_i2c_mutex); |
| 192 | |
| 193 | /**** i2c read functions ****/ |
| 194 | |
| 195 | /* read value from register */ |
| 196 | static int bq2415x_i2c_read(struct bq2415x_device *bq, u8 reg) |
| 197 | { |
| 198 | struct i2c_client *client = to_i2c_client(bq->dev); |
| 199 | struct i2c_msg msg[2]; |
| 200 | u8 val; |
| 201 | int ret; |
| 202 | |
| 203 | if (!client->adapter) |
| 204 | return -ENODEV; |
| 205 | |
| 206 | msg[0].addr = client->addr; |
| 207 | msg[0].flags = 0; |
| 208 | msg[0].buf = ® |
| 209 | msg[0].len = sizeof(reg); |
| 210 | msg[1].addr = client->addr; |
| 211 | msg[1].flags = I2C_M_RD; |
| 212 | msg[1].buf = &val; |
| 213 | msg[1].len = sizeof(val); |
| 214 | |
| 215 | mutex_lock(&bq2415x_i2c_mutex); |
| 216 | ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)); |
| 217 | mutex_unlock(&bq2415x_i2c_mutex); |
| 218 | |
| 219 | if (ret < 0) |
| 220 | return ret; |
| 221 | |
| 222 | return val; |
| 223 | } |
| 224 | |
| 225 | /* read value from register, apply mask and right shift it */ |
| 226 | static int bq2415x_i2c_read_mask(struct bq2415x_device *bq, u8 reg, |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 227 | u8 mask, u8 shift) |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 228 | { |
| 229 | int ret; |
| 230 | |
| 231 | if (shift > 8) |
| 232 | return -EINVAL; |
| 233 | |
| 234 | ret = bq2415x_i2c_read(bq, reg); |
| 235 | if (ret < 0) |
| 236 | return ret; |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 237 | return (ret & mask) >> shift; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | /* read value from register and return one specified bit */ |
| 241 | static int bq2415x_i2c_read_bit(struct bq2415x_device *bq, u8 reg, u8 bit) |
| 242 | { |
| 243 | if (bit > 8) |
| 244 | return -EINVAL; |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 245 | return bq2415x_i2c_read_mask(bq, reg, BIT(bit), bit); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | /**** i2c write functions ****/ |
| 249 | |
| 250 | /* write value to register */ |
| 251 | static int bq2415x_i2c_write(struct bq2415x_device *bq, u8 reg, u8 val) |
| 252 | { |
| 253 | struct i2c_client *client = to_i2c_client(bq->dev); |
| 254 | struct i2c_msg msg[1]; |
| 255 | u8 data[2]; |
| 256 | int ret; |
| 257 | |
| 258 | data[0] = reg; |
| 259 | data[1] = val; |
| 260 | |
| 261 | msg[0].addr = client->addr; |
| 262 | msg[0].flags = 0; |
| 263 | msg[0].buf = data; |
| 264 | msg[0].len = ARRAY_SIZE(data); |
| 265 | |
| 266 | mutex_lock(&bq2415x_i2c_mutex); |
| 267 | ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)); |
| 268 | mutex_unlock(&bq2415x_i2c_mutex); |
| 269 | |
| 270 | /* i2c_transfer returns number of messages transferred */ |
| 271 | if (ret < 0) |
| 272 | return ret; |
| 273 | else if (ret != 1) |
| 274 | return -EIO; |
| 275 | |
| 276 | return 0; |
| 277 | } |
| 278 | |
| 279 | /* read value from register, change it with mask left shifted and write back */ |
| 280 | static int bq2415x_i2c_write_mask(struct bq2415x_device *bq, u8 reg, u8 val, |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 281 | u8 mask, u8 shift) |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 282 | { |
| 283 | int ret; |
| 284 | |
| 285 | if (shift > 8) |
| 286 | return -EINVAL; |
| 287 | |
| 288 | ret = bq2415x_i2c_read(bq, reg); |
| 289 | if (ret < 0) |
| 290 | return ret; |
| 291 | |
| 292 | ret &= ~mask; |
| 293 | ret |= val << shift; |
| 294 | |
| 295 | return bq2415x_i2c_write(bq, reg, ret); |
| 296 | } |
| 297 | |
| 298 | /* change only one bit in register */ |
| 299 | static int bq2415x_i2c_write_bit(struct bq2415x_device *bq, u8 reg, |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 300 | bool val, u8 bit) |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 301 | { |
| 302 | if (bit > 8) |
| 303 | return -EINVAL; |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 304 | return bq2415x_i2c_write_mask(bq, reg, val, BIT(bit), bit); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | /**** global functions ****/ |
| 308 | |
| 309 | /* exec command function */ |
| 310 | static int bq2415x_exec_command(struct bq2415x_device *bq, |
| 311 | enum bq2415x_command command) |
| 312 | { |
| 313 | int ret; |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 314 | |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 315 | switch (command) { |
| 316 | case BQ2415X_TIMER_RESET: |
| 317 | return bq2415x_i2c_write_bit(bq, BQ2415X_REG_STATUS, |
| 318 | 1, BQ2415X_BIT_TMR_RST); |
| 319 | case BQ2415X_OTG_STATUS: |
| 320 | return bq2415x_i2c_read_bit(bq, BQ2415X_REG_STATUS, |
| 321 | BQ2415X_BIT_OTG); |
| 322 | case BQ2415X_STAT_PIN_STATUS: |
| 323 | return bq2415x_i2c_read_bit(bq, BQ2415X_REG_STATUS, |
| 324 | BQ2415X_BIT_EN_STAT); |
| 325 | case BQ2415X_STAT_PIN_ENABLE: |
| 326 | return bq2415x_i2c_write_bit(bq, BQ2415X_REG_STATUS, 1, |
| 327 | BQ2415X_BIT_EN_STAT); |
| 328 | case BQ2415X_STAT_PIN_DISABLE: |
| 329 | return bq2415x_i2c_write_bit(bq, BQ2415X_REG_STATUS, 0, |
| 330 | BQ2415X_BIT_EN_STAT); |
| 331 | case BQ2415X_CHARGE_STATUS: |
| 332 | return bq2415x_i2c_read_mask(bq, BQ2415X_REG_STATUS, |
| 333 | BQ2415X_MASK_STAT, BQ2415X_SHIFT_STAT); |
| 334 | case BQ2415X_BOOST_STATUS: |
| 335 | return bq2415x_i2c_read_bit(bq, BQ2415X_REG_STATUS, |
| 336 | BQ2415X_BIT_BOOST); |
| 337 | case BQ2415X_FAULT_STATUS: |
| 338 | return bq2415x_i2c_read_mask(bq, BQ2415X_REG_STATUS, |
| 339 | BQ2415X_MASK_FAULT, BQ2415X_SHIFT_FAULT); |
| 340 | |
| 341 | case BQ2415X_CHARGE_TERMINATION_STATUS: |
| 342 | return bq2415x_i2c_read_bit(bq, BQ2415X_REG_CONTROL, |
| 343 | BQ2415X_BIT_TE); |
| 344 | case BQ2415X_CHARGE_TERMINATION_ENABLE: |
| 345 | return bq2415x_i2c_write_bit(bq, BQ2415X_REG_CONTROL, |
| 346 | 1, BQ2415X_BIT_TE); |
| 347 | case BQ2415X_CHARGE_TERMINATION_DISABLE: |
| 348 | return bq2415x_i2c_write_bit(bq, BQ2415X_REG_CONTROL, |
| 349 | 0, BQ2415X_BIT_TE); |
| 350 | case BQ2415X_CHARGER_STATUS: |
| 351 | ret = bq2415x_i2c_read_bit(bq, BQ2415X_REG_CONTROL, |
| 352 | BQ2415X_BIT_CE); |
| 353 | if (ret < 0) |
| 354 | return ret; |
Anda-Maria Nicolae | 42d0631 | 2015-03-05 13:23:56 +0200 | [diff] [blame] | 355 | return ret > 0 ? 0 : 1; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 356 | case BQ2415X_CHARGER_ENABLE: |
| 357 | return bq2415x_i2c_write_bit(bq, BQ2415X_REG_CONTROL, |
| 358 | 0, BQ2415X_BIT_CE); |
| 359 | case BQ2415X_CHARGER_DISABLE: |
| 360 | return bq2415x_i2c_write_bit(bq, BQ2415X_REG_CONTROL, |
| 361 | 1, BQ2415X_BIT_CE); |
| 362 | case BQ2415X_HIGH_IMPEDANCE_STATUS: |
| 363 | return bq2415x_i2c_read_bit(bq, BQ2415X_REG_CONTROL, |
| 364 | BQ2415X_BIT_HZ_MODE); |
| 365 | case BQ2415X_HIGH_IMPEDANCE_ENABLE: |
| 366 | return bq2415x_i2c_write_bit(bq, BQ2415X_REG_CONTROL, |
| 367 | 1, BQ2415X_BIT_HZ_MODE); |
| 368 | case BQ2415X_HIGH_IMPEDANCE_DISABLE: |
| 369 | return bq2415x_i2c_write_bit(bq, BQ2415X_REG_CONTROL, |
| 370 | 0, BQ2415X_BIT_HZ_MODE); |
| 371 | case BQ2415X_BOOST_MODE_STATUS: |
| 372 | return bq2415x_i2c_read_bit(bq, BQ2415X_REG_CONTROL, |
| 373 | BQ2415X_BIT_OPA_MODE); |
| 374 | case BQ2415X_BOOST_MODE_ENABLE: |
| 375 | return bq2415x_i2c_write_bit(bq, BQ2415X_REG_CONTROL, |
| 376 | 1, BQ2415X_BIT_OPA_MODE); |
| 377 | case BQ2415X_BOOST_MODE_DISABLE: |
| 378 | return bq2415x_i2c_write_bit(bq, BQ2415X_REG_CONTROL, |
| 379 | 0, BQ2415X_BIT_OPA_MODE); |
| 380 | |
| 381 | case BQ2415X_OTG_LEVEL: |
| 382 | return bq2415x_i2c_read_bit(bq, BQ2415X_REG_VOLTAGE, |
| 383 | BQ2415X_BIT_OTG_PL); |
| 384 | case BQ2415X_OTG_ACTIVATE_HIGH: |
| 385 | return bq2415x_i2c_write_bit(bq, BQ2415X_REG_VOLTAGE, |
| 386 | 1, BQ2415X_BIT_OTG_PL); |
| 387 | case BQ2415X_OTG_ACTIVATE_LOW: |
| 388 | return bq2415x_i2c_write_bit(bq, BQ2415X_REG_VOLTAGE, |
| 389 | 0, BQ2415X_BIT_OTG_PL); |
| 390 | case BQ2415X_OTG_PIN_STATUS: |
| 391 | return bq2415x_i2c_read_bit(bq, BQ2415X_REG_VOLTAGE, |
| 392 | BQ2415X_BIT_OTG_EN); |
| 393 | case BQ2415X_OTG_PIN_ENABLE: |
| 394 | return bq2415x_i2c_write_bit(bq, BQ2415X_REG_VOLTAGE, |
| 395 | 1, BQ2415X_BIT_OTG_EN); |
| 396 | case BQ2415X_OTG_PIN_DISABLE: |
| 397 | return bq2415x_i2c_write_bit(bq, BQ2415X_REG_VOLTAGE, |
| 398 | 0, BQ2415X_BIT_OTG_EN); |
| 399 | |
| 400 | case BQ2415X_VENDER_CODE: |
| 401 | return bq2415x_i2c_read_mask(bq, BQ2415X_REG_VENDER, |
| 402 | BQ2415X_MASK_VENDER, BQ2415X_SHIFT_VENDER); |
| 403 | case BQ2415X_PART_NUMBER: |
| 404 | return bq2415x_i2c_read_mask(bq, BQ2415X_REG_VENDER, |
| 405 | BQ2415X_MASK_PN, BQ2415X_SHIFT_PN); |
| 406 | case BQ2415X_REVISION: |
| 407 | return bq2415x_i2c_read_mask(bq, BQ2415X_REG_VENDER, |
| 408 | BQ2415X_MASK_REVISION, BQ2415X_SHIFT_REVISION); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 409 | } |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 410 | return -EINVAL; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | /* detect chip type */ |
| 414 | static enum bq2415x_chip bq2415x_detect_chip(struct bq2415x_device *bq) |
| 415 | { |
| 416 | struct i2c_client *client = to_i2c_client(bq->dev); |
| 417 | int ret = bq2415x_exec_command(bq, BQ2415X_PART_NUMBER); |
| 418 | |
| 419 | if (ret < 0) |
| 420 | return ret; |
| 421 | |
| 422 | switch (client->addr) { |
| 423 | case 0x6b: |
| 424 | switch (ret) { |
| 425 | case 0: |
| 426 | if (bq->chip == BQ24151A) |
| 427 | return bq->chip; |
Anda-Maria Nicolae | 42d0631 | 2015-03-05 13:23:56 +0200 | [diff] [blame] | 428 | return BQ24151; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 429 | case 1: |
| 430 | if (bq->chip == BQ24150A || |
| 431 | bq->chip == BQ24152 || |
| 432 | bq->chip == BQ24155) |
| 433 | return bq->chip; |
Anda-Maria Nicolae | 42d0631 | 2015-03-05 13:23:56 +0200 | [diff] [blame] | 434 | return BQ24150; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 435 | case 2: |
| 436 | if (bq->chip == BQ24153A) |
| 437 | return bq->chip; |
Anda-Maria Nicolae | 42d0631 | 2015-03-05 13:23:56 +0200 | [diff] [blame] | 438 | return BQ24153; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 439 | default: |
| 440 | return BQUNKNOWN; |
| 441 | } |
| 442 | break; |
| 443 | |
| 444 | case 0x6a: |
| 445 | switch (ret) { |
| 446 | case 0: |
| 447 | if (bq->chip == BQ24156A) |
| 448 | return bq->chip; |
Anda-Maria Nicolae | 42d0631 | 2015-03-05 13:23:56 +0200 | [diff] [blame] | 449 | return BQ24156; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 450 | case 2: |
Anda-Maria Nicolae | 0e1392d | 2015-03-05 13:23:57 +0200 | [diff] [blame] | 451 | if (bq->chip == BQ24157S) |
| 452 | return bq->chip; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 453 | return BQ24158; |
| 454 | default: |
| 455 | return BQUNKNOWN; |
| 456 | } |
| 457 | break; |
| 458 | } |
| 459 | |
| 460 | return BQUNKNOWN; |
| 461 | } |
| 462 | |
| 463 | /* detect chip revision */ |
| 464 | static int bq2415x_detect_revision(struct bq2415x_device *bq) |
| 465 | { |
| 466 | int ret = bq2415x_exec_command(bq, BQ2415X_REVISION); |
| 467 | int chip = bq2415x_detect_chip(bq); |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 468 | |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 469 | if (ret < 0 || chip < 0) |
| 470 | return -1; |
| 471 | |
| 472 | switch (chip) { |
| 473 | case BQ24150: |
| 474 | case BQ24150A: |
| 475 | case BQ24151: |
| 476 | case BQ24151A: |
| 477 | case BQ24152: |
| 478 | if (ret >= 0 && ret <= 3) |
| 479 | return ret; |
Anda-Maria Nicolae | 42d0631 | 2015-03-05 13:23:56 +0200 | [diff] [blame] | 480 | return -1; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 481 | case BQ24153: |
| 482 | case BQ24153A: |
| 483 | case BQ24156: |
| 484 | case BQ24156A: |
Anda-Maria Nicolae | 0e1392d | 2015-03-05 13:23:57 +0200 | [diff] [blame] | 485 | case BQ24157S: |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 486 | case BQ24158: |
| 487 | if (ret == 3) |
| 488 | return 0; |
| 489 | else if (ret == 1) |
| 490 | return 1; |
Anda-Maria Nicolae | 42d0631 | 2015-03-05 13:23:56 +0200 | [diff] [blame] | 491 | return -1; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 492 | case BQ24155: |
| 493 | if (ret == 3) |
| 494 | return 3; |
Anda-Maria Nicolae | 42d0631 | 2015-03-05 13:23:56 +0200 | [diff] [blame] | 495 | return -1; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 496 | case BQUNKNOWN: |
| 497 | return -1; |
| 498 | } |
| 499 | |
| 500 | return -1; |
| 501 | } |
| 502 | |
| 503 | /* return chip vender code */ |
| 504 | static int bq2415x_get_vender_code(struct bq2415x_device *bq) |
| 505 | { |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 506 | int ret; |
| 507 | |
| 508 | ret = bq2415x_exec_command(bq, BQ2415X_VENDER_CODE); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 509 | if (ret < 0) |
| 510 | return 0; |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 511 | |
| 512 | /* convert to binary */ |
| 513 | return (ret & 0x1) + |
| 514 | ((ret >> 1) & 0x1) * 10 + |
| 515 | ((ret >> 2) & 0x1) * 100; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | /* reset all chip registers to default state */ |
| 519 | static void bq2415x_reset_chip(struct bq2415x_device *bq) |
| 520 | { |
| 521 | bq2415x_i2c_write(bq, BQ2415X_REG_CURRENT, BQ2415X_RESET_CURRENT); |
| 522 | bq2415x_i2c_write(bq, BQ2415X_REG_VOLTAGE, BQ2415X_RESET_VOLTAGE); |
| 523 | bq2415x_i2c_write(bq, BQ2415X_REG_CONTROL, BQ2415X_RESET_CONTROL); |
| 524 | bq2415x_i2c_write(bq, BQ2415X_REG_STATUS, BQ2415X_RESET_STATUS); |
| 525 | bq->timer_error = NULL; |
| 526 | } |
| 527 | |
| 528 | /**** properties functions ****/ |
| 529 | |
| 530 | /* set current limit in mA */ |
| 531 | static int bq2415x_set_current_limit(struct bq2415x_device *bq, int mA) |
| 532 | { |
| 533 | int val; |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 534 | |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 535 | if (mA <= 100) |
| 536 | val = 0; |
| 537 | else if (mA <= 500) |
| 538 | val = 1; |
| 539 | else if (mA <= 800) |
| 540 | val = 2; |
| 541 | else |
| 542 | val = 3; |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 543 | |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 544 | return bq2415x_i2c_write_mask(bq, BQ2415X_REG_CONTROL, val, |
| 545 | BQ2415X_MASK_LIMIT, BQ2415X_SHIFT_LIMIT); |
| 546 | } |
| 547 | |
| 548 | /* get current limit in mA */ |
| 549 | static int bq2415x_get_current_limit(struct bq2415x_device *bq) |
| 550 | { |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 551 | int ret; |
| 552 | |
| 553 | ret = bq2415x_i2c_read_mask(bq, BQ2415X_REG_CONTROL, |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 554 | BQ2415X_MASK_LIMIT, BQ2415X_SHIFT_LIMIT); |
| 555 | if (ret < 0) |
| 556 | return ret; |
| 557 | else if (ret == 0) |
| 558 | return 100; |
| 559 | else if (ret == 1) |
| 560 | return 500; |
| 561 | else if (ret == 2) |
| 562 | return 800; |
| 563 | else if (ret == 3) |
| 564 | return 1800; |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 565 | return -EINVAL; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | /* set weak battery voltage in mV */ |
| 569 | static int bq2415x_set_weak_battery_voltage(struct bq2415x_device *bq, int mV) |
| 570 | { |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 571 | int val; |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 572 | |
| 573 | /* round to 100mV */ |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 574 | if (mV <= 3400 + 50) |
| 575 | val = 0; |
| 576 | else if (mV <= 3500 + 50) |
| 577 | val = 1; |
| 578 | else if (mV <= 3600 + 50) |
| 579 | val = 2; |
| 580 | else |
| 581 | val = 3; |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 582 | |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 583 | return bq2415x_i2c_write_mask(bq, BQ2415X_REG_CONTROL, val, |
| 584 | BQ2415X_MASK_VLOWV, BQ2415X_SHIFT_VLOWV); |
| 585 | } |
| 586 | |
| 587 | /* get weak battery voltage in mV */ |
| 588 | static int bq2415x_get_weak_battery_voltage(struct bq2415x_device *bq) |
| 589 | { |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 590 | int ret; |
| 591 | |
| 592 | ret = bq2415x_i2c_read_mask(bq, BQ2415X_REG_CONTROL, |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 593 | BQ2415X_MASK_VLOWV, BQ2415X_SHIFT_VLOWV); |
| 594 | if (ret < 0) |
| 595 | return ret; |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 596 | return 100 * (34 + ret); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | /* set battery regulation voltage in mV */ |
| 600 | static int bq2415x_set_battery_regulation_voltage(struct bq2415x_device *bq, |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 601 | int mV) |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 602 | { |
| 603 | int val = (mV/10 - 350) / 2; |
| 604 | |
Alexandre Belloni | 3ed5cd7 | 2013-10-16 16:08:31 +0200 | [diff] [blame] | 605 | /* |
| 606 | * According to datasheet, maximum battery regulation voltage is |
| 607 | * 4440mV which is b101111 = 47. |
| 608 | */ |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 609 | if (val < 0) |
| 610 | val = 0; |
Alexandre Belloni | 3ed5cd7 | 2013-10-16 16:08:31 +0200 | [diff] [blame] | 611 | else if (val > 47) |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 612 | return -EINVAL; |
| 613 | |
| 614 | return bq2415x_i2c_write_mask(bq, BQ2415X_REG_VOLTAGE, val, |
| 615 | BQ2415X_MASK_VO, BQ2415X_SHIFT_VO); |
| 616 | } |
| 617 | |
| 618 | /* get battery regulation voltage in mV */ |
| 619 | static int bq2415x_get_battery_regulation_voltage(struct bq2415x_device *bq) |
| 620 | { |
| 621 | int ret = bq2415x_i2c_read_mask(bq, BQ2415X_REG_VOLTAGE, |
| 622 | BQ2415X_MASK_VO, BQ2415X_SHIFT_VO); |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 623 | |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 624 | if (ret < 0) |
| 625 | return ret; |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 626 | return 10 * (350 + 2*ret); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | /* set charge current in mA (platform data must provide resistor sense) */ |
| 630 | static int bq2415x_set_charge_current(struct bq2415x_device *bq, int mA) |
| 631 | { |
| 632 | int val; |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 633 | |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 634 | if (bq->init_data.resistor_sense <= 0) |
Anda-Maria Nicolae | f6d8b77 | 2015-05-12 12:11:32 +0300 | [diff] [blame] | 635 | return -EINVAL; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 636 | |
| 637 | val = (mA * bq->init_data.resistor_sense - 37400) / 6800; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 638 | if (val < 0) |
| 639 | val = 0; |
| 640 | else if (val > 7) |
| 641 | val = 7; |
| 642 | |
| 643 | return bq2415x_i2c_write_mask(bq, BQ2415X_REG_CURRENT, val, |
| 644 | BQ2415X_MASK_VI_CHRG | BQ2415X_MASK_RESET, |
| 645 | BQ2415X_SHIFT_VI_CHRG); |
| 646 | } |
| 647 | |
| 648 | /* get charge current in mA (platform data must provide resistor sense) */ |
| 649 | static int bq2415x_get_charge_current(struct bq2415x_device *bq) |
| 650 | { |
| 651 | int ret; |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 652 | |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 653 | if (bq->init_data.resistor_sense <= 0) |
Anda-Maria Nicolae | f6d8b77 | 2015-05-12 12:11:32 +0300 | [diff] [blame] | 654 | return -EINVAL; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 655 | |
| 656 | ret = bq2415x_i2c_read_mask(bq, BQ2415X_REG_CURRENT, |
| 657 | BQ2415X_MASK_VI_CHRG, BQ2415X_SHIFT_VI_CHRG); |
| 658 | if (ret < 0) |
| 659 | return ret; |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 660 | return (37400 + 6800*ret) / bq->init_data.resistor_sense; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | /* set termination current in mA (platform data must provide resistor sense) */ |
| 664 | static int bq2415x_set_termination_current(struct bq2415x_device *bq, int mA) |
| 665 | { |
| 666 | int val; |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 667 | |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 668 | if (bq->init_data.resistor_sense <= 0) |
Anda-Maria Nicolae | f6d8b77 | 2015-05-12 12:11:32 +0300 | [diff] [blame] | 669 | return -EINVAL; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 670 | |
| 671 | val = (mA * bq->init_data.resistor_sense - 3400) / 3400; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 672 | if (val < 0) |
| 673 | val = 0; |
| 674 | else if (val > 7) |
| 675 | val = 7; |
| 676 | |
| 677 | return bq2415x_i2c_write_mask(bq, BQ2415X_REG_CURRENT, val, |
| 678 | BQ2415X_MASK_VI_TERM | BQ2415X_MASK_RESET, |
| 679 | BQ2415X_SHIFT_VI_TERM); |
| 680 | } |
| 681 | |
| 682 | /* get termination current in mA (platform data must provide resistor sense) */ |
| 683 | static int bq2415x_get_termination_current(struct bq2415x_device *bq) |
| 684 | { |
| 685 | int ret; |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 686 | |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 687 | if (bq->init_data.resistor_sense <= 0) |
Anda-Maria Nicolae | f6d8b77 | 2015-05-12 12:11:32 +0300 | [diff] [blame] | 688 | return -EINVAL; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 689 | |
| 690 | ret = bq2415x_i2c_read_mask(bq, BQ2415X_REG_CURRENT, |
| 691 | BQ2415X_MASK_VI_TERM, BQ2415X_SHIFT_VI_TERM); |
| 692 | if (ret < 0) |
| 693 | return ret; |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 694 | return (3400 + 3400*ret) / bq->init_data.resistor_sense; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | /* set default value of property */ |
| 698 | #define bq2415x_set_default_value(bq, prop) \ |
| 699 | do { \ |
| 700 | int ret = 0; \ |
| 701 | if (bq->init_data.prop != -1) \ |
| 702 | ret = bq2415x_set_##prop(bq, bq->init_data.prop); \ |
| 703 | if (ret < 0) \ |
| 704 | return ret; \ |
| 705 | } while (0) |
| 706 | |
| 707 | /* set default values of all properties */ |
| 708 | static int bq2415x_set_defaults(struct bq2415x_device *bq) |
| 709 | { |
| 710 | bq2415x_exec_command(bq, BQ2415X_BOOST_MODE_DISABLE); |
| 711 | bq2415x_exec_command(bq, BQ2415X_CHARGER_DISABLE); |
| 712 | bq2415x_exec_command(bq, BQ2415X_CHARGE_TERMINATION_DISABLE); |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 713 | |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 714 | bq2415x_set_default_value(bq, current_limit); |
| 715 | bq2415x_set_default_value(bq, weak_battery_voltage); |
| 716 | bq2415x_set_default_value(bq, battery_regulation_voltage); |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 717 | |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 718 | if (bq->init_data.resistor_sense > 0) { |
| 719 | bq2415x_set_default_value(bq, charge_current); |
| 720 | bq2415x_set_default_value(bq, termination_current); |
| 721 | bq2415x_exec_command(bq, BQ2415X_CHARGE_TERMINATION_ENABLE); |
| 722 | } |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 723 | |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 724 | bq2415x_exec_command(bq, BQ2415X_CHARGER_ENABLE); |
| 725 | return 0; |
| 726 | } |
| 727 | |
| 728 | /**** charger mode functions ****/ |
| 729 | |
| 730 | /* set charger mode */ |
| 731 | static int bq2415x_set_mode(struct bq2415x_device *bq, enum bq2415x_mode mode) |
| 732 | { |
| 733 | int ret = 0; |
| 734 | int charger = 0; |
| 735 | int boost = 0; |
| 736 | |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 737 | if (mode == BQ2415X_MODE_BOOST) |
| 738 | boost = 1; |
Pali Rohár | ac6324e | 2013-02-10 18:32:18 +0100 | [diff] [blame] | 739 | else if (mode != BQ2415X_MODE_OFF) |
| 740 | charger = 1; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 741 | |
| 742 | if (!charger) |
| 743 | ret = bq2415x_exec_command(bq, BQ2415X_CHARGER_DISABLE); |
| 744 | |
| 745 | if (!boost) |
| 746 | ret = bq2415x_exec_command(bq, BQ2415X_BOOST_MODE_DISABLE); |
| 747 | |
| 748 | if (ret < 0) |
| 749 | return ret; |
| 750 | |
| 751 | switch (mode) { |
Pali Rohár | ac6324e | 2013-02-10 18:32:18 +0100 | [diff] [blame] | 752 | case BQ2415X_MODE_OFF: |
| 753 | dev_dbg(bq->dev, "changing mode to: Offline\n"); |
| 754 | ret = bq2415x_set_current_limit(bq, 100); |
| 755 | break; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 756 | case BQ2415X_MODE_NONE: |
| 757 | dev_dbg(bq->dev, "changing mode to: N/A\n"); |
| 758 | ret = bq2415x_set_current_limit(bq, 100); |
| 759 | break; |
| 760 | case BQ2415X_MODE_HOST_CHARGER: |
| 761 | dev_dbg(bq->dev, "changing mode to: Host/HUB charger\n"); |
| 762 | ret = bq2415x_set_current_limit(bq, 500); |
| 763 | break; |
| 764 | case BQ2415X_MODE_DEDICATED_CHARGER: |
| 765 | dev_dbg(bq->dev, "changing mode to: Dedicated charger\n"); |
| 766 | ret = bq2415x_set_current_limit(bq, 1800); |
| 767 | break; |
| 768 | case BQ2415X_MODE_BOOST: /* Boost mode */ |
| 769 | dev_dbg(bq->dev, "changing mode to: Boost\n"); |
| 770 | ret = bq2415x_set_current_limit(bq, 100); |
| 771 | break; |
| 772 | } |
| 773 | |
| 774 | if (ret < 0) |
| 775 | return ret; |
| 776 | |
| 777 | if (charger) |
| 778 | ret = bq2415x_exec_command(bq, BQ2415X_CHARGER_ENABLE); |
| 779 | else if (boost) |
| 780 | ret = bq2415x_exec_command(bq, BQ2415X_BOOST_MODE_ENABLE); |
| 781 | |
| 782 | if (ret < 0) |
| 783 | return ret; |
| 784 | |
| 785 | bq2415x_set_default_value(bq, weak_battery_voltage); |
| 786 | bq2415x_set_default_value(bq, battery_regulation_voltage); |
| 787 | |
| 788 | bq->mode = mode; |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 789 | sysfs_notify(&bq->charger->dev.kobj, NULL, "mode"); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 790 | |
| 791 | return 0; |
| 792 | |
| 793 | } |
| 794 | |
Pali Rohár | b68c316 | 2015-08-11 13:22:19 +0200 | [diff] [blame] | 795 | static bool bq2415x_update_reported_mode(struct bq2415x_device *bq, int mA) |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 796 | { |
Pali Rohár | 3226030 | 2013-11-19 11:18:04 +0100 | [diff] [blame] | 797 | enum bq2415x_mode mode; |
Pali Rohár | 3226030 | 2013-11-19 11:18:04 +0100 | [diff] [blame] | 798 | |
| 799 | if (mA == 0) |
| 800 | mode = BQ2415X_MODE_OFF; |
| 801 | else if (mA < 500) |
| 802 | mode = BQ2415X_MODE_NONE; |
| 803 | else if (mA < 1800) |
| 804 | mode = BQ2415X_MODE_HOST_CHARGER; |
| 805 | else |
| 806 | mode = BQ2415X_MODE_DEDICATED_CHARGER; |
| 807 | |
| 808 | if (bq->reported_mode == mode) |
Pali Rohár | b68c316 | 2015-08-11 13:22:19 +0200 | [diff] [blame] | 809 | return false; |
Pali Rohár | 3226030 | 2013-11-19 11:18:04 +0100 | [diff] [blame] | 810 | |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 811 | bq->reported_mode = mode; |
Pali Rohár | b68c316 | 2015-08-11 13:22:19 +0200 | [diff] [blame] | 812 | return true; |
| 813 | } |
| 814 | |
| 815 | static int bq2415x_notifier_call(struct notifier_block *nb, |
| 816 | unsigned long val, void *v) |
| 817 | { |
| 818 | struct bq2415x_device *bq = |
| 819 | container_of(nb, struct bq2415x_device, nb); |
| 820 | struct power_supply *psy = v; |
| 821 | union power_supply_propval prop; |
| 822 | int ret; |
| 823 | |
| 824 | if (val != PSY_EVENT_PROP_CHANGED) |
| 825 | return NOTIFY_OK; |
| 826 | |
| 827 | /* Ignore event if it was not send by notify_node/notify_device */ |
| 828 | if (bq->notify_node) { |
| 829 | if (!psy->dev.parent || |
| 830 | psy->dev.parent->of_node != bq->notify_node) |
| 831 | return NOTIFY_OK; |
| 832 | } else if (bq->init_data.notify_device) { |
| 833 | if (strcmp(psy->desc->name, bq->init_data.notify_device) != 0) |
| 834 | return NOTIFY_OK; |
| 835 | } |
| 836 | |
| 837 | dev_dbg(bq->dev, "notifier call was called\n"); |
| 838 | |
| 839 | ret = power_supply_get_property(psy, POWER_SUPPLY_PROP_CURRENT_MAX, |
| 840 | &prop); |
| 841 | if (ret != 0) |
| 842 | return NOTIFY_OK; |
| 843 | |
| 844 | if (!bq2415x_update_reported_mode(bq, prop.intval)) |
| 845 | return NOTIFY_OK; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 846 | |
| 847 | /* if automode is not enabled do not tell about reported_mode */ |
| 848 | if (bq->automode < 1) |
Pali Rohár | 3226030 | 2013-11-19 11:18:04 +0100 | [diff] [blame] | 849 | return NOTIFY_OK; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 850 | |
Sebastian Reichel | 3c01850 | 2014-04-07 13:14:04 +0200 | [diff] [blame] | 851 | schedule_delayed_work(&bq->work, 0); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 852 | |
Pali Rohár | 3226030 | 2013-11-19 11:18:04 +0100 | [diff] [blame] | 853 | return NOTIFY_OK; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | /**** timer functions ****/ |
| 857 | |
| 858 | /* enable/disable auto resetting chip timer */ |
| 859 | static void bq2415x_set_autotimer(struct bq2415x_device *bq, int state) |
| 860 | { |
| 861 | mutex_lock(&bq2415x_timer_mutex); |
| 862 | |
| 863 | if (bq->autotimer == state) { |
| 864 | mutex_unlock(&bq2415x_timer_mutex); |
| 865 | return; |
| 866 | } |
| 867 | |
| 868 | bq->autotimer = state; |
| 869 | |
| 870 | if (state) { |
| 871 | schedule_delayed_work(&bq->work, BQ2415X_TIMER_TIMEOUT * HZ); |
| 872 | bq2415x_exec_command(bq, BQ2415X_TIMER_RESET); |
| 873 | bq->timer_error = NULL; |
| 874 | } else { |
| 875 | cancel_delayed_work_sync(&bq->work); |
| 876 | } |
| 877 | |
| 878 | mutex_unlock(&bq2415x_timer_mutex); |
| 879 | } |
| 880 | |
| 881 | /* called by bq2415x_timer_work on timer error */ |
| 882 | static void bq2415x_timer_error(struct bq2415x_device *bq, const char *msg) |
| 883 | { |
| 884 | bq->timer_error = msg; |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 885 | sysfs_notify(&bq->charger->dev.kobj, NULL, "timer"); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 886 | dev_err(bq->dev, "%s\n", msg); |
| 887 | if (bq->automode > 0) |
| 888 | bq->automode = 0; |
Pali Rohár | ac6324e | 2013-02-10 18:32:18 +0100 | [diff] [blame] | 889 | bq2415x_set_mode(bq, BQ2415X_MODE_OFF); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 890 | bq2415x_set_autotimer(bq, 0); |
| 891 | } |
| 892 | |
| 893 | /* delayed work function for auto resetting chip timer */ |
| 894 | static void bq2415x_timer_work(struct work_struct *work) |
| 895 | { |
| 896 | struct bq2415x_device *bq = container_of(work, struct bq2415x_device, |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 897 | work.work); |
| 898 | int ret; |
| 899 | int error; |
| 900 | int boost; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 901 | |
Sebastian Reichel | 3c01850 | 2014-04-07 13:14:04 +0200 | [diff] [blame] | 902 | if (bq->automode > 0 && (bq->reported_mode != bq->mode)) { |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 903 | sysfs_notify(&bq->charger->dev.kobj, NULL, "reported_mode"); |
Sebastian Reichel | 3c01850 | 2014-04-07 13:14:04 +0200 | [diff] [blame] | 904 | bq2415x_set_mode(bq, bq->reported_mode); |
| 905 | } |
| 906 | |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 907 | if (!bq->autotimer) |
| 908 | return; |
| 909 | |
| 910 | ret = bq2415x_exec_command(bq, BQ2415X_TIMER_RESET); |
| 911 | if (ret < 0) { |
| 912 | bq2415x_timer_error(bq, "Resetting timer failed"); |
| 913 | return; |
| 914 | } |
| 915 | |
| 916 | boost = bq2415x_exec_command(bq, BQ2415X_BOOST_MODE_STATUS); |
| 917 | if (boost < 0) { |
| 918 | bq2415x_timer_error(bq, "Unknown error"); |
| 919 | return; |
| 920 | } |
| 921 | |
| 922 | error = bq2415x_exec_command(bq, BQ2415X_FAULT_STATUS); |
| 923 | if (error < 0) { |
| 924 | bq2415x_timer_error(bq, "Unknown error"); |
| 925 | return; |
| 926 | } |
| 927 | |
| 928 | if (boost) { |
| 929 | switch (error) { |
| 930 | /* Non fatal errors, chip is OK */ |
| 931 | case 0: /* No error */ |
| 932 | break; |
| 933 | case 6: /* Timer expired */ |
| 934 | dev_err(bq->dev, "Timer expired\n"); |
| 935 | break; |
| 936 | case 3: /* Battery voltage too low */ |
| 937 | dev_err(bq->dev, "Battery voltage to low\n"); |
| 938 | break; |
| 939 | |
| 940 | /* Fatal errors, disable and reset chip */ |
| 941 | case 1: /* Overvoltage protection (chip fried) */ |
| 942 | bq2415x_timer_error(bq, |
| 943 | "Overvoltage protection (chip fried)"); |
| 944 | return; |
| 945 | case 2: /* Overload */ |
| 946 | bq2415x_timer_error(bq, "Overload"); |
| 947 | return; |
| 948 | case 4: /* Battery overvoltage protection */ |
| 949 | bq2415x_timer_error(bq, |
| 950 | "Battery overvoltage protection"); |
| 951 | return; |
| 952 | case 5: /* Thermal shutdown (too hot) */ |
| 953 | bq2415x_timer_error(bq, |
| 954 | "Thermal shutdown (too hot)"); |
| 955 | return; |
| 956 | case 7: /* N/A */ |
| 957 | bq2415x_timer_error(bq, "Unknown error"); |
| 958 | return; |
| 959 | } |
| 960 | } else { |
| 961 | switch (error) { |
| 962 | /* Non fatal errors, chip is OK */ |
| 963 | case 0: /* No error */ |
| 964 | break; |
| 965 | case 2: /* Sleep mode */ |
| 966 | dev_err(bq->dev, "Sleep mode\n"); |
| 967 | break; |
| 968 | case 3: /* Poor input source */ |
| 969 | dev_err(bq->dev, "Poor input source\n"); |
| 970 | break; |
| 971 | case 6: /* Timer expired */ |
| 972 | dev_err(bq->dev, "Timer expired\n"); |
| 973 | break; |
| 974 | case 7: /* No battery */ |
| 975 | dev_err(bq->dev, "No battery\n"); |
| 976 | break; |
| 977 | |
| 978 | /* Fatal errors, disable and reset chip */ |
| 979 | case 1: /* Overvoltage protection (chip fried) */ |
| 980 | bq2415x_timer_error(bq, |
| 981 | "Overvoltage protection (chip fried)"); |
| 982 | return; |
| 983 | case 4: /* Battery overvoltage protection */ |
| 984 | bq2415x_timer_error(bq, |
| 985 | "Battery overvoltage protection"); |
| 986 | return; |
| 987 | case 5: /* Thermal shutdown (too hot) */ |
| 988 | bq2415x_timer_error(bq, |
| 989 | "Thermal shutdown (too hot)"); |
| 990 | return; |
| 991 | } |
| 992 | } |
| 993 | |
| 994 | schedule_delayed_work(&bq->work, BQ2415X_TIMER_TIMEOUT * HZ); |
| 995 | } |
| 996 | |
| 997 | /**** power supply interface code ****/ |
| 998 | |
| 999 | static enum power_supply_property bq2415x_power_supply_props[] = { |
| 1000 | /* TODO: maybe add more power supply properties */ |
| 1001 | POWER_SUPPLY_PROP_STATUS, |
| 1002 | POWER_SUPPLY_PROP_MODEL_NAME, |
| 1003 | }; |
| 1004 | |
| 1005 | static int bq2415x_power_supply_get_property(struct power_supply *psy, |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1006 | enum power_supply_property psp, |
| 1007 | union power_supply_propval *val) |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1008 | { |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1009 | struct bq2415x_device *bq = power_supply_get_drvdata(psy); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1010 | int ret; |
| 1011 | |
| 1012 | switch (psp) { |
| 1013 | case POWER_SUPPLY_PROP_STATUS: |
| 1014 | ret = bq2415x_exec_command(bq, BQ2415X_CHARGE_STATUS); |
| 1015 | if (ret < 0) |
| 1016 | return ret; |
| 1017 | else if (ret == 0) /* Ready */ |
| 1018 | val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; |
| 1019 | else if (ret == 1) /* Charge in progress */ |
| 1020 | val->intval = POWER_SUPPLY_STATUS_CHARGING; |
| 1021 | else if (ret == 2) /* Charge done */ |
| 1022 | val->intval = POWER_SUPPLY_STATUS_FULL; |
| 1023 | else |
| 1024 | val->intval = POWER_SUPPLY_STATUS_UNKNOWN; |
| 1025 | break; |
| 1026 | case POWER_SUPPLY_PROP_MODEL_NAME: |
| 1027 | val->strval = bq->model; |
| 1028 | break; |
| 1029 | default: |
| 1030 | return -EINVAL; |
| 1031 | } |
| 1032 | return 0; |
| 1033 | } |
| 1034 | |
| 1035 | static int bq2415x_power_supply_init(struct bq2415x_device *bq) |
| 1036 | { |
| 1037 | int ret; |
| 1038 | int chip; |
| 1039 | char revstr[8]; |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1040 | struct power_supply_config psy_cfg = { .drv_data = bq, }; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1041 | |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1042 | bq->charger_desc.name = bq->name; |
| 1043 | bq->charger_desc.type = POWER_SUPPLY_TYPE_USB; |
| 1044 | bq->charger_desc.properties = bq2415x_power_supply_props; |
| 1045 | bq->charger_desc.num_properties = |
| 1046 | ARRAY_SIZE(bq2415x_power_supply_props); |
| 1047 | bq->charger_desc.get_property = bq2415x_power_supply_get_property; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1048 | |
| 1049 | ret = bq2415x_detect_chip(bq); |
| 1050 | if (ret < 0) |
| 1051 | chip = BQUNKNOWN; |
| 1052 | else |
| 1053 | chip = ret; |
| 1054 | |
| 1055 | ret = bq2415x_detect_revision(bq); |
| 1056 | if (ret < 0) |
| 1057 | strcpy(revstr, "unknown"); |
| 1058 | else |
| 1059 | sprintf(revstr, "1.%d", ret); |
| 1060 | |
| 1061 | bq->model = kasprintf(GFP_KERNEL, |
| 1062 | "chip %s, revision %s, vender code %.3d", |
| 1063 | bq2415x_chip_name[chip], revstr, |
| 1064 | bq2415x_get_vender_code(bq)); |
| 1065 | if (!bq->model) { |
| 1066 | dev_err(bq->dev, "failed to allocate model name\n"); |
| 1067 | return -ENOMEM; |
| 1068 | } |
| 1069 | |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1070 | bq->charger = power_supply_register(bq->dev, &bq->charger_desc, |
| 1071 | &psy_cfg); |
| 1072 | if (IS_ERR(bq->charger)) { |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1073 | kfree(bq->model); |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1074 | return PTR_ERR(bq->charger); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | return 0; |
| 1078 | } |
| 1079 | |
| 1080 | static void bq2415x_power_supply_exit(struct bq2415x_device *bq) |
| 1081 | { |
| 1082 | bq->autotimer = 0; |
| 1083 | if (bq->automode > 0) |
| 1084 | bq->automode = 0; |
| 1085 | cancel_delayed_work_sync(&bq->work); |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1086 | power_supply_unregister(bq->charger); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1087 | kfree(bq->model); |
| 1088 | } |
| 1089 | |
| 1090 | /**** additional sysfs entries for power supply interface ****/ |
| 1091 | |
| 1092 | /* show *_status entries */ |
| 1093 | static ssize_t bq2415x_sysfs_show_status(struct device *dev, |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1094 | struct device_attribute *attr, |
| 1095 | char *buf) |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1096 | { |
| 1097 | struct power_supply *psy = dev_get_drvdata(dev); |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1098 | struct bq2415x_device *bq = power_supply_get_drvdata(psy); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1099 | enum bq2415x_command command; |
| 1100 | int ret; |
| 1101 | |
| 1102 | if (strcmp(attr->attr.name, "otg_status") == 0) |
| 1103 | command = BQ2415X_OTG_STATUS; |
| 1104 | else if (strcmp(attr->attr.name, "charge_status") == 0) |
| 1105 | command = BQ2415X_CHARGE_STATUS; |
| 1106 | else if (strcmp(attr->attr.name, "boost_status") == 0) |
| 1107 | command = BQ2415X_BOOST_STATUS; |
| 1108 | else if (strcmp(attr->attr.name, "fault_status") == 0) |
| 1109 | command = BQ2415X_FAULT_STATUS; |
| 1110 | else |
| 1111 | return -EINVAL; |
| 1112 | |
| 1113 | ret = bq2415x_exec_command(bq, command); |
| 1114 | if (ret < 0) |
| 1115 | return ret; |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1116 | return sprintf(buf, "%d\n", ret); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1117 | } |
| 1118 | |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1119 | /* |
| 1120 | * set timer entry: |
| 1121 | * auto - enable auto mode |
| 1122 | * off - disable auto mode |
| 1123 | * (other values) - reset chip timer |
| 1124 | */ |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1125 | static ssize_t bq2415x_sysfs_set_timer(struct device *dev, |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1126 | struct device_attribute *attr, |
| 1127 | const char *buf, |
| 1128 | size_t count) |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1129 | { |
| 1130 | struct power_supply *psy = dev_get_drvdata(dev); |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1131 | struct bq2415x_device *bq = power_supply_get_drvdata(psy); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1132 | int ret = 0; |
| 1133 | |
| 1134 | if (strncmp(buf, "auto", 4) == 0) |
| 1135 | bq2415x_set_autotimer(bq, 1); |
| 1136 | else if (strncmp(buf, "off", 3) == 0) |
| 1137 | bq2415x_set_autotimer(bq, 0); |
| 1138 | else |
| 1139 | ret = bq2415x_exec_command(bq, BQ2415X_TIMER_RESET); |
| 1140 | |
| 1141 | if (ret < 0) |
| 1142 | return ret; |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1143 | return count; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1144 | } |
| 1145 | |
| 1146 | /* show timer entry (auto or off) */ |
| 1147 | static ssize_t bq2415x_sysfs_show_timer(struct device *dev, |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1148 | struct device_attribute *attr, |
| 1149 | char *buf) |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1150 | { |
| 1151 | struct power_supply *psy = dev_get_drvdata(dev); |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1152 | struct bq2415x_device *bq = power_supply_get_drvdata(psy); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1153 | |
| 1154 | if (bq->timer_error) |
| 1155 | return sprintf(buf, "%s\n", bq->timer_error); |
| 1156 | |
| 1157 | if (bq->autotimer) |
| 1158 | return sprintf(buf, "auto\n"); |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1159 | return sprintf(buf, "off\n"); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1160 | } |
| 1161 | |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1162 | /* |
| 1163 | * set mode entry: |
| 1164 | * auto - if automode is supported, enable it and set mode to reported |
| 1165 | * none - disable charger and boost mode |
| 1166 | * host - charging mode for host/hub chargers (current limit 500mA) |
| 1167 | * dedicated - charging mode for dedicated chargers (unlimited current limit) |
| 1168 | * boost - disable charger and enable boost mode |
| 1169 | */ |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1170 | static ssize_t bq2415x_sysfs_set_mode(struct device *dev, |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1171 | struct device_attribute *attr, |
| 1172 | const char *buf, |
| 1173 | size_t count) |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1174 | { |
| 1175 | struct power_supply *psy = dev_get_drvdata(dev); |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1176 | struct bq2415x_device *bq = power_supply_get_drvdata(psy); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1177 | enum bq2415x_mode mode; |
| 1178 | int ret = 0; |
| 1179 | |
| 1180 | if (strncmp(buf, "auto", 4) == 0) { |
| 1181 | if (bq->automode < 0) |
Anda-Maria Nicolae | f6d8b77 | 2015-05-12 12:11:32 +0300 | [diff] [blame] | 1182 | return -EINVAL; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1183 | bq->automode = 1; |
| 1184 | mode = bq->reported_mode; |
Pali Rohár | ac6324e | 2013-02-10 18:32:18 +0100 | [diff] [blame] | 1185 | } else if (strncmp(buf, "off", 3) == 0) { |
| 1186 | if (bq->automode > 0) |
| 1187 | bq->automode = 0; |
| 1188 | mode = BQ2415X_MODE_OFF; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1189 | } else if (strncmp(buf, "none", 4) == 0) { |
| 1190 | if (bq->automode > 0) |
| 1191 | bq->automode = 0; |
| 1192 | mode = BQ2415X_MODE_NONE; |
| 1193 | } else if (strncmp(buf, "host", 4) == 0) { |
| 1194 | if (bq->automode > 0) |
| 1195 | bq->automode = 0; |
| 1196 | mode = BQ2415X_MODE_HOST_CHARGER; |
| 1197 | } else if (strncmp(buf, "dedicated", 9) == 0) { |
| 1198 | if (bq->automode > 0) |
| 1199 | bq->automode = 0; |
| 1200 | mode = BQ2415X_MODE_DEDICATED_CHARGER; |
| 1201 | } else if (strncmp(buf, "boost", 5) == 0) { |
| 1202 | if (bq->automode > 0) |
| 1203 | bq->automode = 0; |
| 1204 | mode = BQ2415X_MODE_BOOST; |
| 1205 | } else if (strncmp(buf, "reset", 5) == 0) { |
| 1206 | bq2415x_reset_chip(bq); |
| 1207 | bq2415x_set_defaults(bq); |
| 1208 | if (bq->automode <= 0) |
| 1209 | return count; |
| 1210 | bq->automode = 1; |
| 1211 | mode = bq->reported_mode; |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1212 | } else { |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1213 | return -EINVAL; |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1214 | } |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1215 | |
| 1216 | ret = bq2415x_set_mode(bq, mode); |
| 1217 | if (ret < 0) |
| 1218 | return ret; |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1219 | return count; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | /* show mode entry (auto, none, host, dedicated or boost) */ |
| 1223 | static ssize_t bq2415x_sysfs_show_mode(struct device *dev, |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1224 | struct device_attribute *attr, |
| 1225 | char *buf) |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1226 | { |
| 1227 | struct power_supply *psy = dev_get_drvdata(dev); |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1228 | struct bq2415x_device *bq = power_supply_get_drvdata(psy); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1229 | ssize_t ret = 0; |
| 1230 | |
| 1231 | if (bq->automode > 0) |
| 1232 | ret += sprintf(buf+ret, "auto ("); |
| 1233 | |
| 1234 | switch (bq->mode) { |
Pali Rohár | ac6324e | 2013-02-10 18:32:18 +0100 | [diff] [blame] | 1235 | case BQ2415X_MODE_OFF: |
| 1236 | ret += sprintf(buf+ret, "off"); |
| 1237 | break; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1238 | case BQ2415X_MODE_NONE: |
| 1239 | ret += sprintf(buf+ret, "none"); |
| 1240 | break; |
| 1241 | case BQ2415X_MODE_HOST_CHARGER: |
| 1242 | ret += sprintf(buf+ret, "host"); |
| 1243 | break; |
| 1244 | case BQ2415X_MODE_DEDICATED_CHARGER: |
| 1245 | ret += sprintf(buf+ret, "dedicated"); |
| 1246 | break; |
| 1247 | case BQ2415X_MODE_BOOST: |
| 1248 | ret += sprintf(buf+ret, "boost"); |
| 1249 | break; |
| 1250 | } |
| 1251 | |
| 1252 | if (bq->automode > 0) |
| 1253 | ret += sprintf(buf+ret, ")"); |
| 1254 | |
| 1255 | ret += sprintf(buf+ret, "\n"); |
| 1256 | return ret; |
| 1257 | } |
| 1258 | |
| 1259 | /* show reported_mode entry (none, host, dedicated or boost) */ |
| 1260 | static ssize_t bq2415x_sysfs_show_reported_mode(struct device *dev, |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1261 | struct device_attribute *attr, |
| 1262 | char *buf) |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1263 | { |
| 1264 | struct power_supply *psy = dev_get_drvdata(dev); |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1265 | struct bq2415x_device *bq = power_supply_get_drvdata(psy); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1266 | |
| 1267 | if (bq->automode < 0) |
| 1268 | return -EINVAL; |
| 1269 | |
| 1270 | switch (bq->reported_mode) { |
Pali Rohár | ac6324e | 2013-02-10 18:32:18 +0100 | [diff] [blame] | 1271 | case BQ2415X_MODE_OFF: |
| 1272 | return sprintf(buf, "off\n"); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1273 | case BQ2415X_MODE_NONE: |
| 1274 | return sprintf(buf, "none\n"); |
| 1275 | case BQ2415X_MODE_HOST_CHARGER: |
| 1276 | return sprintf(buf, "host\n"); |
| 1277 | case BQ2415X_MODE_DEDICATED_CHARGER: |
| 1278 | return sprintf(buf, "dedicated\n"); |
| 1279 | case BQ2415X_MODE_BOOST: |
| 1280 | return sprintf(buf, "boost\n"); |
| 1281 | } |
| 1282 | |
| 1283 | return -EINVAL; |
| 1284 | } |
| 1285 | |
| 1286 | /* directly set raw value to chip register, format: 'register value' */ |
| 1287 | static ssize_t bq2415x_sysfs_set_registers(struct device *dev, |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1288 | struct device_attribute *attr, |
| 1289 | const char *buf, |
| 1290 | size_t count) |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1291 | { |
| 1292 | struct power_supply *psy = dev_get_drvdata(dev); |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1293 | struct bq2415x_device *bq = power_supply_get_drvdata(psy); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1294 | ssize_t ret = 0; |
| 1295 | unsigned int reg; |
| 1296 | unsigned int val; |
| 1297 | |
| 1298 | if (sscanf(buf, "%x %x", ®, &val) != 2) |
| 1299 | return -EINVAL; |
| 1300 | |
| 1301 | if (reg > 4 || val > 255) |
| 1302 | return -EINVAL; |
| 1303 | |
| 1304 | ret = bq2415x_i2c_write(bq, reg, val); |
| 1305 | if (ret < 0) |
| 1306 | return ret; |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1307 | return count; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | /* print value of chip register, format: 'register=value' */ |
| 1311 | static ssize_t bq2415x_sysfs_print_reg(struct bq2415x_device *bq, |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1312 | u8 reg, |
| 1313 | char *buf) |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1314 | { |
| 1315 | int ret = bq2415x_i2c_read(bq, reg); |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1316 | |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1317 | if (ret < 0) |
| 1318 | return sprintf(buf, "%#.2x=error %d\n", reg, ret); |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1319 | return sprintf(buf, "%#.2x=%#.2x\n", reg, ret); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | /* show all raw values of chip register, format per line: 'register=value' */ |
| 1323 | static ssize_t bq2415x_sysfs_show_registers(struct device *dev, |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1324 | struct device_attribute *attr, |
| 1325 | char *buf) |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1326 | { |
| 1327 | struct power_supply *psy = dev_get_drvdata(dev); |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1328 | struct bq2415x_device *bq = power_supply_get_drvdata(psy); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1329 | ssize_t ret = 0; |
| 1330 | |
| 1331 | ret += bq2415x_sysfs_print_reg(bq, BQ2415X_REG_STATUS, buf+ret); |
| 1332 | ret += bq2415x_sysfs_print_reg(bq, BQ2415X_REG_CONTROL, buf+ret); |
| 1333 | ret += bq2415x_sysfs_print_reg(bq, BQ2415X_REG_VOLTAGE, buf+ret); |
| 1334 | ret += bq2415x_sysfs_print_reg(bq, BQ2415X_REG_VENDER, buf+ret); |
| 1335 | ret += bq2415x_sysfs_print_reg(bq, BQ2415X_REG_CURRENT, buf+ret); |
| 1336 | return ret; |
| 1337 | } |
| 1338 | |
| 1339 | /* set current and voltage limit entries (in mA or mV) */ |
| 1340 | static ssize_t bq2415x_sysfs_set_limit(struct device *dev, |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1341 | struct device_attribute *attr, |
| 1342 | const char *buf, |
| 1343 | size_t count) |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1344 | { |
| 1345 | struct power_supply *psy = dev_get_drvdata(dev); |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1346 | struct bq2415x_device *bq = power_supply_get_drvdata(psy); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1347 | long val; |
| 1348 | int ret; |
| 1349 | |
| 1350 | if (kstrtol(buf, 10, &val) < 0) |
| 1351 | return -EINVAL; |
| 1352 | |
| 1353 | if (strcmp(attr->attr.name, "current_limit") == 0) |
| 1354 | ret = bq2415x_set_current_limit(bq, val); |
| 1355 | else if (strcmp(attr->attr.name, "weak_battery_voltage") == 0) |
| 1356 | ret = bq2415x_set_weak_battery_voltage(bq, val); |
| 1357 | else if (strcmp(attr->attr.name, "battery_regulation_voltage") == 0) |
| 1358 | ret = bq2415x_set_battery_regulation_voltage(bq, val); |
| 1359 | else if (strcmp(attr->attr.name, "charge_current") == 0) |
| 1360 | ret = bq2415x_set_charge_current(bq, val); |
| 1361 | else if (strcmp(attr->attr.name, "termination_current") == 0) |
| 1362 | ret = bq2415x_set_termination_current(bq, val); |
| 1363 | else |
| 1364 | return -EINVAL; |
| 1365 | |
| 1366 | if (ret < 0) |
| 1367 | return ret; |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1368 | return count; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | /* show current and voltage limit entries (in mA or mV) */ |
| 1372 | static ssize_t bq2415x_sysfs_show_limit(struct device *dev, |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1373 | struct device_attribute *attr, |
| 1374 | char *buf) |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1375 | { |
| 1376 | struct power_supply *psy = dev_get_drvdata(dev); |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1377 | struct bq2415x_device *bq = power_supply_get_drvdata(psy); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1378 | int ret; |
| 1379 | |
| 1380 | if (strcmp(attr->attr.name, "current_limit") == 0) |
| 1381 | ret = bq2415x_get_current_limit(bq); |
| 1382 | else if (strcmp(attr->attr.name, "weak_battery_voltage") == 0) |
| 1383 | ret = bq2415x_get_weak_battery_voltage(bq); |
| 1384 | else if (strcmp(attr->attr.name, "battery_regulation_voltage") == 0) |
| 1385 | ret = bq2415x_get_battery_regulation_voltage(bq); |
| 1386 | else if (strcmp(attr->attr.name, "charge_current") == 0) |
| 1387 | ret = bq2415x_get_charge_current(bq); |
| 1388 | else if (strcmp(attr->attr.name, "termination_current") == 0) |
| 1389 | ret = bq2415x_get_termination_current(bq); |
| 1390 | else |
| 1391 | return -EINVAL; |
| 1392 | |
| 1393 | if (ret < 0) |
| 1394 | return ret; |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1395 | return sprintf(buf, "%d\n", ret); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1396 | } |
| 1397 | |
| 1398 | /* set *_enable entries */ |
| 1399 | static ssize_t bq2415x_sysfs_set_enable(struct device *dev, |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1400 | struct device_attribute *attr, |
| 1401 | const char *buf, |
| 1402 | size_t count) |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1403 | { |
| 1404 | struct power_supply *psy = dev_get_drvdata(dev); |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1405 | struct bq2415x_device *bq = power_supply_get_drvdata(psy); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1406 | enum bq2415x_command command; |
| 1407 | long val; |
| 1408 | int ret; |
| 1409 | |
| 1410 | if (kstrtol(buf, 10, &val) < 0) |
| 1411 | return -EINVAL; |
| 1412 | |
| 1413 | if (strcmp(attr->attr.name, "charge_termination_enable") == 0) |
| 1414 | command = val ? BQ2415X_CHARGE_TERMINATION_ENABLE : |
| 1415 | BQ2415X_CHARGE_TERMINATION_DISABLE; |
| 1416 | else if (strcmp(attr->attr.name, "high_impedance_enable") == 0) |
| 1417 | command = val ? BQ2415X_HIGH_IMPEDANCE_ENABLE : |
| 1418 | BQ2415X_HIGH_IMPEDANCE_DISABLE; |
| 1419 | else if (strcmp(attr->attr.name, "otg_pin_enable") == 0) |
| 1420 | command = val ? BQ2415X_OTG_PIN_ENABLE : |
| 1421 | BQ2415X_OTG_PIN_DISABLE; |
| 1422 | else if (strcmp(attr->attr.name, "stat_pin_enable") == 0) |
| 1423 | command = val ? BQ2415X_STAT_PIN_ENABLE : |
| 1424 | BQ2415X_STAT_PIN_DISABLE; |
| 1425 | else |
| 1426 | return -EINVAL; |
| 1427 | |
| 1428 | ret = bq2415x_exec_command(bq, command); |
| 1429 | if (ret < 0) |
| 1430 | return ret; |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1431 | return count; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | /* show *_enable entries */ |
| 1435 | static ssize_t bq2415x_sysfs_show_enable(struct device *dev, |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1436 | struct device_attribute *attr, |
| 1437 | char *buf) |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1438 | { |
| 1439 | struct power_supply *psy = dev_get_drvdata(dev); |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1440 | struct bq2415x_device *bq = power_supply_get_drvdata(psy); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1441 | enum bq2415x_command command; |
| 1442 | int ret; |
| 1443 | |
| 1444 | if (strcmp(attr->attr.name, "charge_termination_enable") == 0) |
| 1445 | command = BQ2415X_CHARGE_TERMINATION_STATUS; |
| 1446 | else if (strcmp(attr->attr.name, "high_impedance_enable") == 0) |
| 1447 | command = BQ2415X_HIGH_IMPEDANCE_STATUS; |
| 1448 | else if (strcmp(attr->attr.name, "otg_pin_enable") == 0) |
| 1449 | command = BQ2415X_OTG_PIN_STATUS; |
| 1450 | else if (strcmp(attr->attr.name, "stat_pin_enable") == 0) |
| 1451 | command = BQ2415X_STAT_PIN_STATUS; |
| 1452 | else |
| 1453 | return -EINVAL; |
| 1454 | |
| 1455 | ret = bq2415x_exec_command(bq, command); |
| 1456 | if (ret < 0) |
| 1457 | return ret; |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1458 | return sprintf(buf, "%d\n", ret); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | static DEVICE_ATTR(current_limit, S_IWUSR | S_IRUGO, |
| 1462 | bq2415x_sysfs_show_limit, bq2415x_sysfs_set_limit); |
| 1463 | static DEVICE_ATTR(weak_battery_voltage, S_IWUSR | S_IRUGO, |
| 1464 | bq2415x_sysfs_show_limit, bq2415x_sysfs_set_limit); |
| 1465 | static DEVICE_ATTR(battery_regulation_voltage, S_IWUSR | S_IRUGO, |
| 1466 | bq2415x_sysfs_show_limit, bq2415x_sysfs_set_limit); |
| 1467 | static DEVICE_ATTR(charge_current, S_IWUSR | S_IRUGO, |
| 1468 | bq2415x_sysfs_show_limit, bq2415x_sysfs_set_limit); |
| 1469 | static DEVICE_ATTR(termination_current, S_IWUSR | S_IRUGO, |
| 1470 | bq2415x_sysfs_show_limit, bq2415x_sysfs_set_limit); |
| 1471 | |
| 1472 | static DEVICE_ATTR(charge_termination_enable, S_IWUSR | S_IRUGO, |
| 1473 | bq2415x_sysfs_show_enable, bq2415x_sysfs_set_enable); |
| 1474 | static DEVICE_ATTR(high_impedance_enable, S_IWUSR | S_IRUGO, |
| 1475 | bq2415x_sysfs_show_enable, bq2415x_sysfs_set_enable); |
| 1476 | static DEVICE_ATTR(otg_pin_enable, S_IWUSR | S_IRUGO, |
| 1477 | bq2415x_sysfs_show_enable, bq2415x_sysfs_set_enable); |
| 1478 | static DEVICE_ATTR(stat_pin_enable, S_IWUSR | S_IRUGO, |
| 1479 | bq2415x_sysfs_show_enable, bq2415x_sysfs_set_enable); |
| 1480 | |
| 1481 | static DEVICE_ATTR(reported_mode, S_IRUGO, |
| 1482 | bq2415x_sysfs_show_reported_mode, NULL); |
| 1483 | static DEVICE_ATTR(mode, S_IWUSR | S_IRUGO, |
| 1484 | bq2415x_sysfs_show_mode, bq2415x_sysfs_set_mode); |
| 1485 | static DEVICE_ATTR(timer, S_IWUSR | S_IRUGO, |
| 1486 | bq2415x_sysfs_show_timer, bq2415x_sysfs_set_timer); |
| 1487 | |
| 1488 | static DEVICE_ATTR(registers, S_IWUSR | S_IRUGO, |
| 1489 | bq2415x_sysfs_show_registers, bq2415x_sysfs_set_registers); |
| 1490 | |
| 1491 | static DEVICE_ATTR(otg_status, S_IRUGO, bq2415x_sysfs_show_status, NULL); |
| 1492 | static DEVICE_ATTR(charge_status, S_IRUGO, bq2415x_sysfs_show_status, NULL); |
| 1493 | static DEVICE_ATTR(boost_status, S_IRUGO, bq2415x_sysfs_show_status, NULL); |
| 1494 | static DEVICE_ATTR(fault_status, S_IRUGO, bq2415x_sysfs_show_status, NULL); |
| 1495 | |
| 1496 | static struct attribute *bq2415x_sysfs_attributes[] = { |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1497 | /* |
| 1498 | * TODO: some (appropriate) of these attrs should be switched to |
| 1499 | * use power supply class props. |
| 1500 | */ |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1501 | &dev_attr_current_limit.attr, |
| 1502 | &dev_attr_weak_battery_voltage.attr, |
| 1503 | &dev_attr_battery_regulation_voltage.attr, |
| 1504 | &dev_attr_charge_current.attr, |
| 1505 | &dev_attr_termination_current.attr, |
| 1506 | |
| 1507 | &dev_attr_charge_termination_enable.attr, |
| 1508 | &dev_attr_high_impedance_enable.attr, |
| 1509 | &dev_attr_otg_pin_enable.attr, |
| 1510 | &dev_attr_stat_pin_enable.attr, |
| 1511 | |
| 1512 | &dev_attr_reported_mode.attr, |
| 1513 | &dev_attr_mode.attr, |
| 1514 | &dev_attr_timer.attr, |
| 1515 | |
| 1516 | &dev_attr_registers.attr, |
| 1517 | |
| 1518 | &dev_attr_otg_status.attr, |
| 1519 | &dev_attr_charge_status.attr, |
| 1520 | &dev_attr_boost_status.attr, |
| 1521 | &dev_attr_fault_status.attr, |
| 1522 | NULL, |
| 1523 | }; |
| 1524 | |
| 1525 | static const struct attribute_group bq2415x_sysfs_attr_group = { |
| 1526 | .attrs = bq2415x_sysfs_attributes, |
| 1527 | }; |
| 1528 | |
| 1529 | static int bq2415x_sysfs_init(struct bq2415x_device *bq) |
| 1530 | { |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1531 | return sysfs_create_group(&bq->charger->dev.kobj, |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1532 | &bq2415x_sysfs_attr_group); |
| 1533 | } |
| 1534 | |
| 1535 | static void bq2415x_sysfs_exit(struct bq2415x_device *bq) |
| 1536 | { |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1537 | sysfs_remove_group(&bq->charger->dev.kobj, &bq2415x_sysfs_attr_group); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | /* main bq2415x probe function */ |
| 1541 | static int bq2415x_probe(struct i2c_client *client, |
Anton Vorontsov | 6c47a3e | 2012-11-18 15:35:32 -0800 | [diff] [blame] | 1542 | const struct i2c_device_id *id) |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1543 | { |
| 1544 | int ret; |
| 1545 | int num; |
Anda-Maria Nicolae | b01e7c3 | 2015-05-12 12:11:33 +0300 | [diff] [blame] | 1546 | char *name = NULL; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1547 | struct bq2415x_device *bq; |
Sebastian Reichel | faffd23 | 2013-11-24 17:49:30 +0100 | [diff] [blame] | 1548 | struct device_node *np = client->dev.of_node; |
| 1549 | struct bq2415x_platform_data *pdata = client->dev.platform_data; |
Anda-Maria Nicolae | b01e7c3 | 2015-05-12 12:11:33 +0300 | [diff] [blame] | 1550 | const struct acpi_device_id *acpi_id = NULL; |
Pali Rohár | b68c316 | 2015-08-11 13:22:19 +0200 | [diff] [blame] | 1551 | struct power_supply *notify_psy = NULL; |
| 1552 | union power_supply_propval prop; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1553 | |
Anda-Maria Nicolae | b01e7c3 | 2015-05-12 12:11:33 +0300 | [diff] [blame] | 1554 | if (!np && !pdata && !ACPI_HANDLE(&client->dev)) { |
| 1555 | dev_err(&client->dev, "Neither devicetree, nor platform data, nor ACPI support\n"); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1556 | return -ENODEV; |
| 1557 | } |
| 1558 | |
| 1559 | /* Get new ID for the new device */ |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1560 | mutex_lock(&bq2415x_id_mutex); |
Tejun Heo | 05e2cef | 2013-02-27 17:04:37 -0800 | [diff] [blame] | 1561 | num = idr_alloc(&bq2415x_id, client, 0, 0, GFP_KERNEL); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1562 | mutex_unlock(&bq2415x_id_mutex); |
Tejun Heo | 05e2cef | 2013-02-27 17:04:37 -0800 | [diff] [blame] | 1563 | if (num < 0) |
| 1564 | return num; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1565 | |
Anda-Maria Nicolae | b01e7c3 | 2015-05-12 12:11:33 +0300 | [diff] [blame] | 1566 | if (id) { |
| 1567 | name = kasprintf(GFP_KERNEL, "%s-%d", id->name, num); |
| 1568 | } else if (ACPI_HANDLE(&client->dev)) { |
| 1569 | acpi_id = |
| 1570 | acpi_match_device(client->dev.driver->acpi_match_table, |
| 1571 | &client->dev); |
| 1572 | name = kasprintf(GFP_KERNEL, "%s-%d", acpi_id->id, num); |
| 1573 | } |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1574 | if (!name) { |
| 1575 | dev_err(&client->dev, "failed to allocate device name\n"); |
| 1576 | ret = -ENOMEM; |
| 1577 | goto error_1; |
| 1578 | } |
| 1579 | |
Sachin Kamat | a9672e1 | 2012-11-27 11:28:46 +0530 | [diff] [blame] | 1580 | bq = devm_kzalloc(&client->dev, sizeof(*bq), GFP_KERNEL); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1581 | if (!bq) { |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1582 | ret = -ENOMEM; |
| 1583 | goto error_2; |
| 1584 | } |
| 1585 | |
| 1586 | i2c_set_clientdata(client, bq); |
| 1587 | |
| 1588 | bq->id = num; |
| 1589 | bq->dev = &client->dev; |
Anda-Maria Nicolae | b01e7c3 | 2015-05-12 12:11:33 +0300 | [diff] [blame] | 1590 | if (id) |
| 1591 | bq->chip = id->driver_data; |
| 1592 | else if (ACPI_HANDLE(bq->dev)) |
| 1593 | bq->chip = acpi_id->driver_data; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1594 | bq->name = name; |
Pali Rohár | ac6324e | 2013-02-10 18:32:18 +0100 | [diff] [blame] | 1595 | bq->mode = BQ2415X_MODE_OFF; |
| 1596 | bq->reported_mode = BQ2415X_MODE_OFF; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1597 | bq->autotimer = 0; |
| 1598 | bq->automode = 0; |
| 1599 | |
Anda-Maria Nicolae | b01e7c3 | 2015-05-12 12:11:33 +0300 | [diff] [blame] | 1600 | if (np || ACPI_HANDLE(bq->dev)) { |
| 1601 | ret = device_property_read_u32(bq->dev, |
| 1602 | "ti,current-limit", |
| 1603 | &bq->init_data.current_limit); |
Sebastian Reichel | faffd23 | 2013-11-24 17:49:30 +0100 | [diff] [blame] | 1604 | if (ret) |
Pali Rohár | b68c316 | 2015-08-11 13:22:19 +0200 | [diff] [blame] | 1605 | goto error_2; |
Anda-Maria Nicolae | b01e7c3 | 2015-05-12 12:11:33 +0300 | [diff] [blame] | 1606 | ret = device_property_read_u32(bq->dev, |
| 1607 | "ti,weak-battery-voltage", |
| 1608 | &bq->init_data.weak_battery_voltage); |
Sebastian Reichel | faffd23 | 2013-11-24 17:49:30 +0100 | [diff] [blame] | 1609 | if (ret) |
Pali Rohár | b68c316 | 2015-08-11 13:22:19 +0200 | [diff] [blame] | 1610 | goto error_2; |
Anda-Maria Nicolae | b01e7c3 | 2015-05-12 12:11:33 +0300 | [diff] [blame] | 1611 | ret = device_property_read_u32(bq->dev, |
| 1612 | "ti,battery-regulation-voltage", |
Sebastian Reichel | faffd23 | 2013-11-24 17:49:30 +0100 | [diff] [blame] | 1613 | &bq->init_data.battery_regulation_voltage); |
| 1614 | if (ret) |
Pali Rohár | b68c316 | 2015-08-11 13:22:19 +0200 | [diff] [blame] | 1615 | goto error_2; |
Anda-Maria Nicolae | b01e7c3 | 2015-05-12 12:11:33 +0300 | [diff] [blame] | 1616 | ret = device_property_read_u32(bq->dev, |
| 1617 | "ti,charge-current", |
| 1618 | &bq->init_data.charge_current); |
Sebastian Reichel | faffd23 | 2013-11-24 17:49:30 +0100 | [diff] [blame] | 1619 | if (ret) |
Pali Rohár | b68c316 | 2015-08-11 13:22:19 +0200 | [diff] [blame] | 1620 | goto error_2; |
Anda-Maria Nicolae | b01e7c3 | 2015-05-12 12:11:33 +0300 | [diff] [blame] | 1621 | ret = device_property_read_u32(bq->dev, |
| 1622 | "ti,termination-current", |
| 1623 | &bq->init_data.termination_current); |
Sebastian Reichel | faffd23 | 2013-11-24 17:49:30 +0100 | [diff] [blame] | 1624 | if (ret) |
Pali Rohár | b68c316 | 2015-08-11 13:22:19 +0200 | [diff] [blame] | 1625 | goto error_2; |
Anda-Maria Nicolae | b01e7c3 | 2015-05-12 12:11:33 +0300 | [diff] [blame] | 1626 | ret = device_property_read_u32(bq->dev, |
| 1627 | "ti,resistor-sense", |
| 1628 | &bq->init_data.resistor_sense); |
Sebastian Reichel | faffd23 | 2013-11-24 17:49:30 +0100 | [diff] [blame] | 1629 | if (ret) |
Pali Rohár | b68c316 | 2015-08-11 13:22:19 +0200 | [diff] [blame] | 1630 | goto error_2; |
| 1631 | if (np) |
| 1632 | bq->notify_node = of_parse_phandle(np, |
| 1633 | "ti,usb-charger-detection", 0); |
Sebastian Reichel | faffd23 | 2013-11-24 17:49:30 +0100 | [diff] [blame] | 1634 | } else { |
| 1635 | memcpy(&bq->init_data, pdata, sizeof(bq->init_data)); |
| 1636 | } |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1637 | |
| 1638 | bq2415x_reset_chip(bq); |
| 1639 | |
| 1640 | ret = bq2415x_power_supply_init(bq); |
| 1641 | if (ret) { |
| 1642 | dev_err(bq->dev, "failed to register power supply: %d\n", ret); |
Pali Rohár | b68c316 | 2015-08-11 13:22:19 +0200 | [diff] [blame] | 1643 | goto error_2; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1644 | } |
| 1645 | |
| 1646 | ret = bq2415x_sysfs_init(bq); |
| 1647 | if (ret) { |
| 1648 | dev_err(bq->dev, "failed to create sysfs entries: %d\n", ret); |
Pali Rohár | b68c316 | 2015-08-11 13:22:19 +0200 | [diff] [blame] | 1649 | goto error_3; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1650 | } |
| 1651 | |
| 1652 | ret = bq2415x_set_defaults(bq); |
| 1653 | if (ret) { |
| 1654 | dev_err(bq->dev, "failed to set default values: %d\n", ret); |
Pali Rohár | b68c316 | 2015-08-11 13:22:19 +0200 | [diff] [blame] | 1655 | goto error_4; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1656 | } |
| 1657 | |
Pali Rohár | b68c316 | 2015-08-11 13:22:19 +0200 | [diff] [blame] | 1658 | if (bq->notify_node || bq->init_data.notify_device) { |
Pali Rohár | 3226030 | 2013-11-19 11:18:04 +0100 | [diff] [blame] | 1659 | bq->nb.notifier_call = bq2415x_notifier_call; |
| 1660 | ret = power_supply_reg_notifier(&bq->nb); |
| 1661 | if (ret) { |
| 1662 | dev_err(bq->dev, "failed to reg notifier: %d\n", ret); |
Pali Rohár | b68c316 | 2015-08-11 13:22:19 +0200 | [diff] [blame] | 1663 | goto error_4; |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1664 | } |
Sebastian Reichel | faffd23 | 2013-11-24 17:49:30 +0100 | [diff] [blame] | 1665 | |
Pali Rohár | 3226030 | 2013-11-19 11:18:04 +0100 | [diff] [blame] | 1666 | bq->automode = 1; |
Pali Rohár | b68c316 | 2015-08-11 13:22:19 +0200 | [diff] [blame] | 1667 | dev_info(bq->dev, "automode supported, waiting for events\n"); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1668 | } else { |
| 1669 | bq->automode = -1; |
| 1670 | dev_info(bq->dev, "automode not supported\n"); |
| 1671 | } |
| 1672 | |
Pali Rohár | b68c316 | 2015-08-11 13:22:19 +0200 | [diff] [blame] | 1673 | /* Query for initial reported_mode and set it */ |
| 1674 | if (bq->nb.notifier_call) { |
| 1675 | if (np) { |
| 1676 | notify_psy = power_supply_get_by_phandle(np, |
| 1677 | "ti,usb-charger-detection"); |
| 1678 | if (IS_ERR(notify_psy)) |
| 1679 | notify_psy = NULL; |
| 1680 | } else if (bq->init_data.notify_device) { |
| 1681 | notify_psy = power_supply_get_by_name( |
| 1682 | bq->init_data.notify_device); |
| 1683 | } |
| 1684 | } |
| 1685 | if (notify_psy) { |
| 1686 | ret = power_supply_get_property(notify_psy, |
| 1687 | POWER_SUPPLY_PROP_CURRENT_MAX, &prop); |
| 1688 | power_supply_put(notify_psy); |
| 1689 | |
| 1690 | if (ret == 0) { |
| 1691 | bq2415x_update_reported_mode(bq, prop.intval); |
| 1692 | bq2415x_set_mode(bq, bq->reported_mode); |
| 1693 | } |
| 1694 | } |
| 1695 | |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1696 | INIT_DELAYED_WORK(&bq->work, bq2415x_timer_work); |
| 1697 | bq2415x_set_autotimer(bq, 1); |
| 1698 | |
| 1699 | dev_info(bq->dev, "driver registered\n"); |
| 1700 | return 0; |
| 1701 | |
Krzysztof Kozlowski | 1a8dbe6 | 2015-03-12 08:44:18 +0100 | [diff] [blame] | 1702 | error_4: |
Pali Rohár | b68c316 | 2015-08-11 13:22:19 +0200 | [diff] [blame] | 1703 | bq2415x_sysfs_exit(bq); |
Krzysztof Kozlowski | 1a8dbe6 | 2015-03-12 08:44:18 +0100 | [diff] [blame] | 1704 | error_3: |
Pali Rohár | b68c316 | 2015-08-11 13:22:19 +0200 | [diff] [blame] | 1705 | bq2415x_power_supply_exit(bq); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1706 | error_2: |
Markus Elfring | b7e16ec | 2015-11-06 16:48:46 +0100 | [diff] [blame] | 1707 | if (bq) |
Pali Rohár | b68c316 | 2015-08-11 13:22:19 +0200 | [diff] [blame] | 1708 | of_node_put(bq->notify_node); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1709 | kfree(name); |
| 1710 | error_1: |
| 1711 | mutex_lock(&bq2415x_id_mutex); |
| 1712 | idr_remove(&bq2415x_id, num); |
| 1713 | mutex_unlock(&bq2415x_id_mutex); |
| 1714 | |
| 1715 | return ret; |
| 1716 | } |
| 1717 | |
| 1718 | /* main bq2415x remove function */ |
| 1719 | |
| 1720 | static int bq2415x_remove(struct i2c_client *client) |
| 1721 | { |
| 1722 | struct bq2415x_device *bq = i2c_get_clientdata(client); |
| 1723 | |
Pali Rohár | b68c316 | 2015-08-11 13:22:19 +0200 | [diff] [blame] | 1724 | if (bq->nb.notifier_call) |
Pali Rohár | 3226030 | 2013-11-19 11:18:04 +0100 | [diff] [blame] | 1725 | power_supply_unreg_notifier(&bq->nb); |
Pali Rohár | b68c316 | 2015-08-11 13:22:19 +0200 | [diff] [blame] | 1726 | |
Markus Elfring | b7e16ec | 2015-11-06 16:48:46 +0100 | [diff] [blame] | 1727 | of_node_put(bq->notify_node); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1728 | bq2415x_sysfs_exit(bq); |
| 1729 | bq2415x_power_supply_exit(bq); |
| 1730 | |
| 1731 | bq2415x_reset_chip(bq); |
| 1732 | |
| 1733 | mutex_lock(&bq2415x_id_mutex); |
| 1734 | idr_remove(&bq2415x_id, bq->id); |
| 1735 | mutex_unlock(&bq2415x_id_mutex); |
| 1736 | |
| 1737 | dev_info(bq->dev, "driver unregistered\n"); |
| 1738 | |
| 1739 | kfree(bq->name); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1740 | |
| 1741 | return 0; |
| 1742 | } |
| 1743 | |
| 1744 | static const struct i2c_device_id bq2415x_i2c_id_table[] = { |
| 1745 | { "bq2415x", BQUNKNOWN }, |
| 1746 | { "bq24150", BQ24150 }, |
| 1747 | { "bq24150a", BQ24150A }, |
| 1748 | { "bq24151", BQ24151 }, |
| 1749 | { "bq24151a", BQ24151A }, |
| 1750 | { "bq24152", BQ24152 }, |
| 1751 | { "bq24153", BQ24153 }, |
| 1752 | { "bq24153a", BQ24153A }, |
| 1753 | { "bq24155", BQ24155 }, |
| 1754 | { "bq24156", BQ24156 }, |
| 1755 | { "bq24156a", BQ24156A }, |
Anda-Maria Nicolae | 0e1392d | 2015-03-05 13:23:57 +0200 | [diff] [blame] | 1756 | { "bq24157s", BQ24157S }, |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1757 | { "bq24158", BQ24158 }, |
| 1758 | {}, |
| 1759 | }; |
| 1760 | MODULE_DEVICE_TABLE(i2c, bq2415x_i2c_id_table); |
| 1761 | |
Pali Rohár | ec3d7d0 | 2016-02-21 12:28:20 +0100 | [diff] [blame^] | 1762 | #ifdef CONFIG_ACPI |
Anda-Maria Nicolae | b01e7c3 | 2015-05-12 12:11:33 +0300 | [diff] [blame] | 1763 | static const struct acpi_device_id bq2415x_i2c_acpi_match[] = { |
| 1764 | { "BQ2415X", BQUNKNOWN }, |
| 1765 | { "BQ241500", BQ24150 }, |
| 1766 | { "BQA24150", BQ24150A }, |
| 1767 | { "BQ241510", BQ24151 }, |
| 1768 | { "BQA24151", BQ24151A }, |
| 1769 | { "BQ241520", BQ24152 }, |
| 1770 | { "BQ241530", BQ24153 }, |
| 1771 | { "BQA24153", BQ24153A }, |
| 1772 | { "BQ241550", BQ24155 }, |
| 1773 | { "BQ241560", BQ24156 }, |
| 1774 | { "BQA24156", BQ24156A }, |
| 1775 | { "BQS24157", BQ24157S }, |
| 1776 | { "BQ241580", BQ24158 }, |
| 1777 | {}, |
| 1778 | }; |
| 1779 | MODULE_DEVICE_TABLE(acpi, bq2415x_i2c_acpi_match); |
Pali Rohár | ec3d7d0 | 2016-02-21 12:28:20 +0100 | [diff] [blame^] | 1780 | #endif |
Anda-Maria Nicolae | b01e7c3 | 2015-05-12 12:11:33 +0300 | [diff] [blame] | 1781 | |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1782 | static struct i2c_driver bq2415x_driver = { |
| 1783 | .driver = { |
| 1784 | .name = "bq2415x-charger", |
Anda-Maria Nicolae | b01e7c3 | 2015-05-12 12:11:33 +0300 | [diff] [blame] | 1785 | .acpi_match_table = ACPI_PTR(bq2415x_i2c_acpi_match), |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1786 | }, |
| 1787 | .probe = bq2415x_probe, |
| 1788 | .remove = bq2415x_remove, |
| 1789 | .id_table = bq2415x_i2c_id_table, |
| 1790 | }; |
Sachin Kamat | 463df51 | 2012-11-27 11:28:45 +0530 | [diff] [blame] | 1791 | module_i2c_driver(bq2415x_driver); |
Pali Rohár | 0bc98cc | 2012-11-02 20:18:11 +0100 | [diff] [blame] | 1792 | |
| 1793 | MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>"); |
| 1794 | MODULE_DESCRIPTION("bq2415x charger driver"); |
| 1795 | MODULE_LICENSE("GPL"); |