| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Battery driver for wm8350 PMIC |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 6 | 7 | * Based on OLPC Battery Driver |
|---|
| 7 | 8 | * |
|---|
| 8 | 9 | * Copyright 2006 David Woodhouse <dwmw2@infradead.org> |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 11 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 12 | | - * published by the Free Software Foundation. |
|---|
| 13 | 10 | */ |
|---|
| 14 | 11 | |
|---|
| 15 | 12 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 230 | 227 | case WM8350_IRQ_EXT_USB_FB: |
|---|
| 231 | 228 | case WM8350_IRQ_EXT_WALL_FB: |
|---|
| 232 | 229 | wm8350_charger_config(wm8350, policy); |
|---|
| 233 | | - /* Fall through */ |
|---|
| 230 | + fallthrough; |
|---|
| 234 | 231 | case WM8350_IRQ_EXT_BAT_FB: |
|---|
| 235 | 232 | power_supply_changed(power->battery); |
|---|
| 236 | 233 | power_supply_changed(power->usb); |
|---|
| .. | .. |
|---|
| 411 | 408 | * Initialisation |
|---|
| 412 | 409 | *********************************************************************/ |
|---|
| 413 | 410 | |
|---|
| 414 | | -static void wm8350_init_charger(struct wm8350 *wm8350) |
|---|
| 411 | +static int wm8350_init_charger(struct wm8350 *wm8350) |
|---|
| 415 | 412 | { |
|---|
| 413 | + int ret; |
|---|
| 414 | + |
|---|
| 416 | 415 | /* register our interest in charger events */ |
|---|
| 417 | | - wm8350_register_irq(wm8350, WM8350_IRQ_CHG_BAT_HOT, |
|---|
| 416 | + ret = wm8350_register_irq(wm8350, WM8350_IRQ_CHG_BAT_HOT, |
|---|
| 418 | 417 | wm8350_charger_handler, 0, "Battery hot", wm8350); |
|---|
| 419 | | - wm8350_register_irq(wm8350, WM8350_IRQ_CHG_BAT_COLD, |
|---|
| 418 | + if (ret) |
|---|
| 419 | + goto err; |
|---|
| 420 | + |
|---|
| 421 | + ret = wm8350_register_irq(wm8350, WM8350_IRQ_CHG_BAT_COLD, |
|---|
| 420 | 422 | wm8350_charger_handler, 0, "Battery cold", wm8350); |
|---|
| 421 | | - wm8350_register_irq(wm8350, WM8350_IRQ_CHG_BAT_FAIL, |
|---|
| 423 | + if (ret) |
|---|
| 424 | + goto free_chg_bat_hot; |
|---|
| 425 | + |
|---|
| 426 | + ret = wm8350_register_irq(wm8350, WM8350_IRQ_CHG_BAT_FAIL, |
|---|
| 422 | 427 | wm8350_charger_handler, 0, "Battery fail", wm8350); |
|---|
| 423 | | - wm8350_register_irq(wm8350, WM8350_IRQ_CHG_TO, |
|---|
| 428 | + if (ret) |
|---|
| 429 | + goto free_chg_bat_cold; |
|---|
| 430 | + |
|---|
| 431 | + ret = wm8350_register_irq(wm8350, WM8350_IRQ_CHG_TO, |
|---|
| 424 | 432 | wm8350_charger_handler, 0, |
|---|
| 425 | 433 | "Charger timeout", wm8350); |
|---|
| 426 | | - wm8350_register_irq(wm8350, WM8350_IRQ_CHG_END, |
|---|
| 434 | + if (ret) |
|---|
| 435 | + goto free_chg_bat_fail; |
|---|
| 436 | + |
|---|
| 437 | + ret = wm8350_register_irq(wm8350, WM8350_IRQ_CHG_END, |
|---|
| 427 | 438 | wm8350_charger_handler, 0, |
|---|
| 428 | 439 | "Charge end", wm8350); |
|---|
| 429 | | - wm8350_register_irq(wm8350, WM8350_IRQ_CHG_START, |
|---|
| 440 | + if (ret) |
|---|
| 441 | + goto free_chg_to; |
|---|
| 442 | + |
|---|
| 443 | + ret = wm8350_register_irq(wm8350, WM8350_IRQ_CHG_START, |
|---|
| 430 | 444 | wm8350_charger_handler, 0, |
|---|
| 431 | 445 | "Charge start", wm8350); |
|---|
| 432 | | - wm8350_register_irq(wm8350, WM8350_IRQ_CHG_FAST_RDY, |
|---|
| 446 | + if (ret) |
|---|
| 447 | + goto free_chg_end; |
|---|
| 448 | + |
|---|
| 449 | + ret = wm8350_register_irq(wm8350, WM8350_IRQ_CHG_FAST_RDY, |
|---|
| 433 | 450 | wm8350_charger_handler, 0, |
|---|
| 434 | 451 | "Fast charge ready", wm8350); |
|---|
| 435 | | - wm8350_register_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P9, |
|---|
| 452 | + if (ret) |
|---|
| 453 | + goto free_chg_start; |
|---|
| 454 | + |
|---|
| 455 | + ret = wm8350_register_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P9, |
|---|
| 436 | 456 | wm8350_charger_handler, 0, |
|---|
| 437 | 457 | "Battery <3.9V", wm8350); |
|---|
| 438 | | - wm8350_register_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P1, |
|---|
| 458 | + if (ret) |
|---|
| 459 | + goto free_chg_fast_rdy; |
|---|
| 460 | + |
|---|
| 461 | + ret = wm8350_register_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P1, |
|---|
| 439 | 462 | wm8350_charger_handler, 0, |
|---|
| 440 | 463 | "Battery <3.1V", wm8350); |
|---|
| 441 | | - wm8350_register_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_2P85, |
|---|
| 464 | + if (ret) |
|---|
| 465 | + goto free_chg_vbatt_lt_3p9; |
|---|
| 466 | + |
|---|
| 467 | + ret = wm8350_register_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_2P85, |
|---|
| 442 | 468 | wm8350_charger_handler, 0, |
|---|
| 443 | 469 | "Battery <2.85V", wm8350); |
|---|
| 470 | + if (ret) |
|---|
| 471 | + goto free_chg_vbatt_lt_3p1; |
|---|
| 444 | 472 | |
|---|
| 445 | 473 | /* and supply change events */ |
|---|
| 446 | | - wm8350_register_irq(wm8350, WM8350_IRQ_EXT_USB_FB, |
|---|
| 474 | + ret = wm8350_register_irq(wm8350, WM8350_IRQ_EXT_USB_FB, |
|---|
| 447 | 475 | wm8350_charger_handler, 0, "USB", wm8350); |
|---|
| 448 | | - wm8350_register_irq(wm8350, WM8350_IRQ_EXT_WALL_FB, |
|---|
| 476 | + if (ret) |
|---|
| 477 | + goto free_chg_vbatt_lt_2p85; |
|---|
| 478 | + |
|---|
| 479 | + ret = wm8350_register_irq(wm8350, WM8350_IRQ_EXT_WALL_FB, |
|---|
| 449 | 480 | wm8350_charger_handler, 0, "Wall", wm8350); |
|---|
| 450 | | - wm8350_register_irq(wm8350, WM8350_IRQ_EXT_BAT_FB, |
|---|
| 481 | + if (ret) |
|---|
| 482 | + goto free_ext_usb_fb; |
|---|
| 483 | + |
|---|
| 484 | + ret = wm8350_register_irq(wm8350, WM8350_IRQ_EXT_BAT_FB, |
|---|
| 451 | 485 | wm8350_charger_handler, 0, "Battery", wm8350); |
|---|
| 486 | + if (ret) |
|---|
| 487 | + goto free_ext_wall_fb; |
|---|
| 488 | + |
|---|
| 489 | + return 0; |
|---|
| 490 | + |
|---|
| 491 | +free_ext_wall_fb: |
|---|
| 492 | + wm8350_free_irq(wm8350, WM8350_IRQ_EXT_WALL_FB, wm8350); |
|---|
| 493 | +free_ext_usb_fb: |
|---|
| 494 | + wm8350_free_irq(wm8350, WM8350_IRQ_EXT_USB_FB, wm8350); |
|---|
| 495 | +free_chg_vbatt_lt_2p85: |
|---|
| 496 | + wm8350_free_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_2P85, wm8350); |
|---|
| 497 | +free_chg_vbatt_lt_3p1: |
|---|
| 498 | + wm8350_free_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P1, wm8350); |
|---|
| 499 | +free_chg_vbatt_lt_3p9: |
|---|
| 500 | + wm8350_free_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P9, wm8350); |
|---|
| 501 | +free_chg_fast_rdy: |
|---|
| 502 | + wm8350_free_irq(wm8350, WM8350_IRQ_CHG_FAST_RDY, wm8350); |
|---|
| 503 | +free_chg_start: |
|---|
| 504 | + wm8350_free_irq(wm8350, WM8350_IRQ_CHG_START, wm8350); |
|---|
| 505 | +free_chg_end: |
|---|
| 506 | + wm8350_free_irq(wm8350, WM8350_IRQ_CHG_END, wm8350); |
|---|
| 507 | +free_chg_to: |
|---|
| 508 | + wm8350_free_irq(wm8350, WM8350_IRQ_CHG_TO, wm8350); |
|---|
| 509 | +free_chg_bat_fail: |
|---|
| 510 | + wm8350_free_irq(wm8350, WM8350_IRQ_CHG_BAT_FAIL, wm8350); |
|---|
| 511 | +free_chg_bat_cold: |
|---|
| 512 | + wm8350_free_irq(wm8350, WM8350_IRQ_CHG_BAT_COLD, wm8350); |
|---|
| 513 | +free_chg_bat_hot: |
|---|
| 514 | + wm8350_free_irq(wm8350, WM8350_IRQ_CHG_BAT_HOT, wm8350); |
|---|
| 515 | +err: |
|---|
| 516 | + return ret; |
|---|
| 452 | 517 | } |
|---|
| 453 | 518 | |
|---|
| 454 | 519 | static void free_charger_irq(struct wm8350 *wm8350) |
|---|
| .. | .. |
|---|
| 459 | 524 | wm8350_free_irq(wm8350, WM8350_IRQ_CHG_TO, wm8350); |
|---|
| 460 | 525 | wm8350_free_irq(wm8350, WM8350_IRQ_CHG_END, wm8350); |
|---|
| 461 | 526 | wm8350_free_irq(wm8350, WM8350_IRQ_CHG_START, wm8350); |
|---|
| 527 | + wm8350_free_irq(wm8350, WM8350_IRQ_CHG_FAST_RDY, wm8350); |
|---|
| 462 | 528 | wm8350_free_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P9, wm8350); |
|---|
| 463 | 529 | wm8350_free_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P1, wm8350); |
|---|
| 464 | 530 | wm8350_free_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_2P85, wm8350); |
|---|