Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Battery measurement code for Ingenic JZ SOC. |
| 3 | * |
| 4 | * Copyright (C) 2009 Jiejing Zhang <kzjeef@gmail.com> |
| 5 | * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de> |
| 6 | * |
| 7 | * based on tosa_battery.c |
| 8 | * |
| 9 | * Copyright (C) 2008 Marek Vasut <marek.vasut@gmail.com> |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License version 2 as |
| 13 | * published by the Free Software Foundation. |
| 14 | * |
| 15 | */ |
| 16 | |
| 17 | #include <linux/interrupt.h> |
| 18 | #include <linux/kernel.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/platform_device.h> |
| 21 | #include <linux/slab.h> |
Anton Vorontsov | f3dcab7 | 2010-12-22 02:44:49 +0300 | [diff] [blame] | 22 | #include <linux/io.h> |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 23 | |
| 24 | #include <linux/delay.h> |
Thierry Reding | e2cbdf3 | 2013-01-21 11:09:15 +0100 | [diff] [blame] | 25 | #include <linux/err.h> |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 26 | #include <linux/gpio.h> |
| 27 | #include <linux/mfd/core.h> |
| 28 | #include <linux/power_supply.h> |
| 29 | |
| 30 | #include <linux/power/jz4740-battery.h> |
| 31 | #include <linux/jz4740-adc.h> |
| 32 | |
| 33 | struct jz_battery { |
| 34 | struct jz_battery_platform_data *pdata; |
| 35 | struct platform_device *pdev; |
| 36 | |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 37 | void __iomem *base; |
| 38 | |
| 39 | int irq; |
| 40 | int charge_irq; |
| 41 | |
Andres Salomon | e930006 | 2011-03-01 13:35:48 -0800 | [diff] [blame] | 42 | const struct mfd_cell *cell; |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 43 | |
| 44 | int status; |
| 45 | long voltage; |
| 46 | |
| 47 | struct completion read_completion; |
| 48 | |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 49 | struct power_supply *battery; |
| 50 | struct power_supply_desc battery_desc; |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 51 | struct delayed_work work; |
Lars-Peter Clausen | 8ec98fe | 2010-11-11 19:00:52 +0100 | [diff] [blame] | 52 | |
| 53 | struct mutex lock; |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | static inline struct jz_battery *psy_to_jz_battery(struct power_supply *psy) |
| 57 | { |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 58 | return power_supply_get_drvdata(psy); |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | static irqreturn_t jz_battery_irq_handler(int irq, void *devid) |
| 62 | { |
| 63 | struct jz_battery *battery = devid; |
| 64 | |
| 65 | complete(&battery->read_completion); |
| 66 | return IRQ_HANDLED; |
| 67 | } |
| 68 | |
| 69 | static long jz_battery_read_voltage(struct jz_battery *battery) |
| 70 | { |
Axel Lin | ef7906f | 2011-12-08 21:05:26 +0800 | [diff] [blame] | 71 | long t; |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 72 | unsigned long val; |
| 73 | long voltage; |
| 74 | |
Lars-Peter Clausen | 8ec98fe | 2010-11-11 19:00:52 +0100 | [diff] [blame] | 75 | mutex_lock(&battery->lock); |
| 76 | |
Wolfram Sang | 16735d0 | 2013-11-14 14:32:02 -0800 | [diff] [blame] | 77 | reinit_completion(&battery->read_completion); |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 78 | |
| 79 | enable_irq(battery->irq); |
| 80 | battery->cell->enable(battery->pdev); |
| 81 | |
| 82 | t = wait_for_completion_interruptible_timeout(&battery->read_completion, |
| 83 | HZ); |
| 84 | |
| 85 | if (t > 0) { |
| 86 | val = readw(battery->base) & 0xfff; |
| 87 | |
| 88 | if (battery->pdata->info.voltage_max_design <= 2500000) |
| 89 | val = (val * 78125UL) >> 7UL; |
| 90 | else |
| 91 | val = ((val * 924375UL) >> 9UL) + 33000; |
| 92 | voltage = (long)val; |
| 93 | } else { |
| 94 | voltage = t ? t : -ETIMEDOUT; |
| 95 | } |
| 96 | |
| 97 | battery->cell->disable(battery->pdev); |
| 98 | disable_irq(battery->irq); |
| 99 | |
Lars-Peter Clausen | 8ec98fe | 2010-11-11 19:00:52 +0100 | [diff] [blame] | 100 | mutex_unlock(&battery->lock); |
| 101 | |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 102 | return voltage; |
| 103 | } |
| 104 | |
| 105 | static int jz_battery_get_capacity(struct power_supply *psy) |
| 106 | { |
| 107 | struct jz_battery *jz_battery = psy_to_jz_battery(psy); |
| 108 | struct power_supply_info *info = &jz_battery->pdata->info; |
| 109 | long voltage; |
| 110 | int ret; |
| 111 | int voltage_span; |
| 112 | |
| 113 | voltage = jz_battery_read_voltage(jz_battery); |
| 114 | |
| 115 | if (voltage < 0) |
| 116 | return voltage; |
| 117 | |
| 118 | voltage_span = info->voltage_max_design - info->voltage_min_design; |
| 119 | ret = ((voltage - info->voltage_min_design) * 100) / voltage_span; |
| 120 | |
| 121 | if (ret > 100) |
| 122 | ret = 100; |
| 123 | else if (ret < 0) |
| 124 | ret = 0; |
| 125 | |
| 126 | return ret; |
| 127 | } |
| 128 | |
| 129 | static int jz_battery_get_property(struct power_supply *psy, |
| 130 | enum power_supply_property psp, union power_supply_propval *val) |
| 131 | { |
| 132 | struct jz_battery *jz_battery = psy_to_jz_battery(psy); |
| 133 | struct power_supply_info *info = &jz_battery->pdata->info; |
| 134 | long voltage; |
| 135 | |
| 136 | switch (psp) { |
| 137 | case POWER_SUPPLY_PROP_STATUS: |
| 138 | val->intval = jz_battery->status; |
| 139 | break; |
| 140 | case POWER_SUPPLY_PROP_TECHNOLOGY: |
| 141 | val->intval = jz_battery->pdata->info.technology; |
| 142 | break; |
| 143 | case POWER_SUPPLY_PROP_HEALTH: |
| 144 | voltage = jz_battery_read_voltage(jz_battery); |
| 145 | if (voltage < info->voltage_min_design) |
| 146 | val->intval = POWER_SUPPLY_HEALTH_DEAD; |
| 147 | else |
| 148 | val->intval = POWER_SUPPLY_HEALTH_GOOD; |
| 149 | break; |
| 150 | case POWER_SUPPLY_PROP_CAPACITY: |
| 151 | val->intval = jz_battery_get_capacity(psy); |
| 152 | break; |
| 153 | case POWER_SUPPLY_PROP_VOLTAGE_NOW: |
| 154 | val->intval = jz_battery_read_voltage(jz_battery); |
| 155 | if (val->intval < 0) |
| 156 | return val->intval; |
| 157 | break; |
| 158 | case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: |
| 159 | val->intval = info->voltage_max_design; |
| 160 | break; |
| 161 | case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: |
| 162 | val->intval = info->voltage_min_design; |
| 163 | break; |
| 164 | case POWER_SUPPLY_PROP_PRESENT: |
| 165 | val->intval = 1; |
| 166 | break; |
| 167 | default: |
| 168 | return -EINVAL; |
| 169 | } |
| 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | static void jz_battery_external_power_changed(struct power_supply *psy) |
| 174 | { |
| 175 | struct jz_battery *jz_battery = psy_to_jz_battery(psy); |
| 176 | |
Tejun Heo | 41f63c5 | 2012-08-03 10:30:47 -0700 | [diff] [blame] | 177 | mod_delayed_work(system_wq, &jz_battery->work, 0); |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | static irqreturn_t jz_battery_charge_irq(int irq, void *data) |
| 181 | { |
| 182 | struct jz_battery *jz_battery = data; |
| 183 | |
Tejun Heo | 41f63c5 | 2012-08-03 10:30:47 -0700 | [diff] [blame] | 184 | mod_delayed_work(system_wq, &jz_battery->work, 0); |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 185 | |
| 186 | return IRQ_HANDLED; |
| 187 | } |
| 188 | |
| 189 | static void jz_battery_update(struct jz_battery *jz_battery) |
| 190 | { |
| 191 | int status; |
| 192 | long voltage; |
| 193 | bool has_changed = false; |
| 194 | int is_charging; |
| 195 | |
| 196 | if (gpio_is_valid(jz_battery->pdata->gpio_charge)) { |
| 197 | is_charging = gpio_get_value(jz_battery->pdata->gpio_charge); |
| 198 | is_charging ^= jz_battery->pdata->gpio_charge_active_low; |
| 199 | if (is_charging) |
| 200 | status = POWER_SUPPLY_STATUS_CHARGING; |
| 201 | else |
| 202 | status = POWER_SUPPLY_STATUS_NOT_CHARGING; |
| 203 | |
| 204 | if (status != jz_battery->status) { |
| 205 | jz_battery->status = status; |
| 206 | has_changed = true; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | voltage = jz_battery_read_voltage(jz_battery); |
| 211 | if (abs(voltage - jz_battery->voltage) < 50000) { |
| 212 | jz_battery->voltage = voltage; |
| 213 | has_changed = true; |
| 214 | } |
| 215 | |
| 216 | if (has_changed) |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 217 | power_supply_changed(jz_battery->battery); |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | static enum power_supply_property jz_battery_properties[] = { |
| 221 | POWER_SUPPLY_PROP_STATUS, |
| 222 | POWER_SUPPLY_PROP_TECHNOLOGY, |
| 223 | POWER_SUPPLY_PROP_HEALTH, |
| 224 | POWER_SUPPLY_PROP_CAPACITY, |
| 225 | POWER_SUPPLY_PROP_VOLTAGE_NOW, |
| 226 | POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, |
| 227 | POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, |
| 228 | POWER_SUPPLY_PROP_PRESENT, |
| 229 | }; |
| 230 | |
| 231 | static void jz_battery_work(struct work_struct *work) |
| 232 | { |
| 233 | /* Too small interval will increase system workload */ |
| 234 | const int interval = HZ * 30; |
| 235 | struct jz_battery *jz_battery = container_of(work, struct jz_battery, |
| 236 | work.work); |
| 237 | |
| 238 | jz_battery_update(jz_battery); |
| 239 | schedule_delayed_work(&jz_battery->work, interval); |
| 240 | } |
| 241 | |
Bill Pemberton | c8afa64 | 2012-11-19 13:22:23 -0500 | [diff] [blame] | 242 | static int jz_battery_probe(struct platform_device *pdev) |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 243 | { |
| 244 | int ret = 0; |
| 245 | struct jz_battery_platform_data *pdata = pdev->dev.parent->platform_data; |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 246 | struct power_supply_config psy_cfg = {}; |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 247 | struct jz_battery *jz_battery; |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 248 | struct power_supply_desc *battery_desc; |
Marcos Paulo de Souza | 9790f98 | 2012-11-06 21:11:12 -0200 | [diff] [blame] | 249 | struct resource *mem; |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 250 | |
Lars-Peter Clausen | 8477ced | 2010-11-11 19:00:53 +0100 | [diff] [blame] | 251 | if (!pdata) { |
| 252 | dev_err(&pdev->dev, "No platform_data supplied\n"); |
| 253 | return -ENXIO; |
| 254 | } |
| 255 | |
Marcos Paulo de Souza | ec073c9 | 2012-11-06 21:11:11 -0200 | [diff] [blame] | 256 | jz_battery = devm_kzalloc(&pdev->dev, sizeof(*jz_battery), GFP_KERNEL); |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 257 | if (!jz_battery) { |
| 258 | dev_err(&pdev->dev, "Failed to allocate driver structure\n"); |
| 259 | return -ENOMEM; |
| 260 | } |
| 261 | |
Andres Salomon | 6a54ac2 | 2011-02-17 19:07:10 -0800 | [diff] [blame] | 262 | jz_battery->cell = mfd_get_cell(pdev); |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 263 | |
| 264 | jz_battery->irq = platform_get_irq(pdev, 0); |
| 265 | if (jz_battery->irq < 0) { |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 266 | dev_err(&pdev->dev, "Failed to get platform irq: %d\n", ret); |
Marcos Paulo de Souza | ec073c9 | 2012-11-06 21:11:11 -0200 | [diff] [blame] | 267 | return jz_battery->irq; |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 268 | } |
| 269 | |
Marcos Paulo de Souza | 9790f98 | 2012-11-06 21:11:12 -0200 | [diff] [blame] | 270 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 271 | |
Thierry Reding | e2cbdf3 | 2013-01-21 11:09:15 +0100 | [diff] [blame] | 272 | jz_battery->base = devm_ioremap_resource(&pdev->dev, mem); |
| 273 | if (IS_ERR(jz_battery->base)) |
| 274 | return PTR_ERR(jz_battery->base); |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 275 | |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 276 | battery_desc = &jz_battery->battery_desc; |
| 277 | battery_desc->name = pdata->info.name; |
| 278 | battery_desc->type = POWER_SUPPLY_TYPE_BATTERY; |
| 279 | battery_desc->properties = jz_battery_properties; |
| 280 | battery_desc->num_properties = ARRAY_SIZE(jz_battery_properties); |
| 281 | battery_desc->get_property = jz_battery_get_property; |
| 282 | battery_desc->external_power_changed = |
| 283 | jz_battery_external_power_changed; |
| 284 | battery_desc->use_for_apm = 1; |
| 285 | |
| 286 | psy_cfg.drv_data = jz_battery; |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 287 | |
| 288 | jz_battery->pdata = pdata; |
| 289 | jz_battery->pdev = pdev; |
| 290 | |
| 291 | init_completion(&jz_battery->read_completion); |
Lars-Peter Clausen | 8ec98fe | 2010-11-11 19:00:52 +0100 | [diff] [blame] | 292 | mutex_init(&jz_battery->lock); |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 293 | |
| 294 | INIT_DELAYED_WORK(&jz_battery->work, jz_battery_work); |
| 295 | |
| 296 | ret = request_irq(jz_battery->irq, jz_battery_irq_handler, 0, pdev->name, |
| 297 | jz_battery); |
| 298 | if (ret) { |
| 299 | dev_err(&pdev->dev, "Failed to request irq %d\n", ret); |
Jingoo Han | 8ff3fb2 | 2013-05-06 13:22:41 +0900 | [diff] [blame] | 300 | return ret; |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 301 | } |
| 302 | disable_irq(jz_battery->irq); |
| 303 | |
| 304 | if (gpio_is_valid(pdata->gpio_charge)) { |
| 305 | ret = gpio_request(pdata->gpio_charge, dev_name(&pdev->dev)); |
| 306 | if (ret) { |
| 307 | dev_err(&pdev->dev, "charger state gpio request failed.\n"); |
| 308 | goto err_free_irq; |
| 309 | } |
| 310 | ret = gpio_direction_input(pdata->gpio_charge); |
| 311 | if (ret) { |
| 312 | dev_err(&pdev->dev, "charger state gpio set direction failed.\n"); |
| 313 | goto err_free_gpio; |
| 314 | } |
| 315 | |
| 316 | jz_battery->charge_irq = gpio_to_irq(pdata->gpio_charge); |
| 317 | |
| 318 | if (jz_battery->charge_irq >= 0) { |
| 319 | ret = request_irq(jz_battery->charge_irq, |
| 320 | jz_battery_charge_irq, |
| 321 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, |
| 322 | dev_name(&pdev->dev), jz_battery); |
| 323 | if (ret) { |
| 324 | dev_err(&pdev->dev, "Failed to request charge irq: %d\n", ret); |
| 325 | goto err_free_gpio; |
| 326 | } |
| 327 | } |
| 328 | } else { |
| 329 | jz_battery->charge_irq = -1; |
| 330 | } |
| 331 | |
| 332 | if (jz_battery->pdata->info.voltage_max_design <= 2500000) |
| 333 | jz4740_adc_set_config(pdev->dev.parent, JZ_ADC_CONFIG_BAT_MB, |
| 334 | JZ_ADC_CONFIG_BAT_MB); |
| 335 | else |
| 336 | jz4740_adc_set_config(pdev->dev.parent, JZ_ADC_CONFIG_BAT_MB, 0); |
| 337 | |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 338 | jz_battery->battery = power_supply_register(&pdev->dev, battery_desc, |
| 339 | &psy_cfg); |
| 340 | if (IS_ERR(jz_battery->battery)) { |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 341 | dev_err(&pdev->dev, "power supply battery register failed.\n"); |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 342 | ret = PTR_ERR(jz_battery->battery); |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 343 | goto err_free_charge_irq; |
| 344 | } |
| 345 | |
| 346 | platform_set_drvdata(pdev, jz_battery); |
| 347 | schedule_delayed_work(&jz_battery->work, 0); |
| 348 | |
| 349 | return 0; |
| 350 | |
| 351 | err_free_charge_irq: |
| 352 | if (jz_battery->charge_irq >= 0) |
| 353 | free_irq(jz_battery->charge_irq, jz_battery); |
| 354 | err_free_gpio: |
| 355 | if (gpio_is_valid(pdata->gpio_charge)) |
| 356 | gpio_free(jz_battery->pdata->gpio_charge); |
| 357 | err_free_irq: |
| 358 | free_irq(jz_battery->irq, jz_battery); |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 359 | return ret; |
| 360 | } |
| 361 | |
Bill Pemberton | 415ec69 | 2012-11-19 13:26:07 -0500 | [diff] [blame] | 362 | static int jz_battery_remove(struct platform_device *pdev) |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 363 | { |
| 364 | struct jz_battery *jz_battery = platform_get_drvdata(pdev); |
| 365 | |
| 366 | cancel_delayed_work_sync(&jz_battery->work); |
| 367 | |
| 368 | if (gpio_is_valid(jz_battery->pdata->gpio_charge)) { |
| 369 | if (jz_battery->charge_irq >= 0) |
| 370 | free_irq(jz_battery->charge_irq, jz_battery); |
| 371 | gpio_free(jz_battery->pdata->gpio_charge); |
| 372 | } |
| 373 | |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 374 | power_supply_unregister(jz_battery->battery); |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 375 | |
| 376 | free_irq(jz_battery->irq, jz_battery); |
| 377 | |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 378 | return 0; |
| 379 | } |
| 380 | |
| 381 | #ifdef CONFIG_PM |
| 382 | static int jz_battery_suspend(struct device *dev) |
| 383 | { |
| 384 | struct jz_battery *jz_battery = dev_get_drvdata(dev); |
| 385 | |
| 386 | cancel_delayed_work_sync(&jz_battery->work); |
| 387 | jz_battery->status = POWER_SUPPLY_STATUS_UNKNOWN; |
| 388 | |
| 389 | return 0; |
| 390 | } |
| 391 | |
| 392 | static int jz_battery_resume(struct device *dev) |
| 393 | { |
| 394 | struct jz_battery *jz_battery = dev_get_drvdata(dev); |
| 395 | |
| 396 | schedule_delayed_work(&jz_battery->work, 0); |
| 397 | |
| 398 | return 0; |
| 399 | } |
| 400 | |
| 401 | static const struct dev_pm_ops jz_battery_pm_ops = { |
| 402 | .suspend = jz_battery_suspend, |
| 403 | .resume = jz_battery_resume, |
| 404 | }; |
| 405 | |
| 406 | #define JZ_BATTERY_PM_OPS (&jz_battery_pm_ops) |
| 407 | #else |
| 408 | #define JZ_BATTERY_PM_OPS NULL |
| 409 | #endif |
| 410 | |
| 411 | static struct platform_driver jz_battery_driver = { |
| 412 | .probe = jz_battery_probe, |
Bill Pemberton | 28ea73f | 2012-11-19 13:20:40 -0500 | [diff] [blame] | 413 | .remove = jz_battery_remove, |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 414 | .driver = { |
| 415 | .name = "jz4740-battery", |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 416 | .pm = JZ_BATTERY_PM_OPS, |
| 417 | }, |
| 418 | }; |
| 419 | |
Axel Lin | 300bac7 | 2011-11-26 12:01:10 +0800 | [diff] [blame] | 420 | module_platform_driver(jz_battery_driver); |
Lars-Peter Clausen | f6a2138 | 2010-06-19 04:08:29 +0000 | [diff] [blame] | 421 | |
| 422 | MODULE_ALIAS("platform:jz4740-battery"); |
| 423 | MODULE_LICENSE("GPL"); |
| 424 | MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); |
| 425 | MODULE_DESCRIPTION("JZ4740 SoC battery driver"); |