summaryrefslogtreecommitdiff
path: root/drivers/power/supply/da9150-fg.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/power/supply/da9150-fg.c')
-rw-r--r--drivers/power/supply/da9150-fg.c50
1 files changed, 16 insertions, 34 deletions
diff --git a/drivers/power/supply/da9150-fg.c b/drivers/power/supply/da9150-fg.c
index 8b8ce978656a..4f28ef1bba1a 100644
--- a/drivers/power/supply/da9150-fg.c
+++ b/drivers/power/supply/da9150-fg.c
@@ -1,21 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
* DA9150 Fuel-Gauge Driver
*
* Copyright (c) 2015 Dialog Semiconductor
*
* Author: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/of.h>
-#include <linux/of_platform.h>
#include <linux/slab.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
@@ -24,6 +19,7 @@
#include <asm/div64.h>
#include <linux/mfd/da9150/core.h>
#include <linux/mfd/da9150/registers.h>
+#include <linux/devm-helpers.h>
/* Core2Wire */
#define DA9150_QIF_READ (0x0 << 7)
@@ -92,7 +88,7 @@ struct da9150_fg {
static u32 da9150_fg_read_attr(struct da9150_fg *fg, u8 code, u8 size)
{
- u8 buf[size];
+ u8 buf[DA9150_QIF_LONG_SIZE];
u8 read_addr;
u32 res = 0;
int i;
@@ -111,7 +107,7 @@ static void da9150_fg_write_attr(struct da9150_fg *fg, u8 code, u8 size,
u32 val)
{
- u8 buf[size];
+ u8 buf[DA9150_QIF_LONG_SIZE];
u8 write_addr;
int i;
@@ -251,9 +247,9 @@ static int da9150_fg_current_avg(struct da9150_fg *fg,
DA9150_QIF_SD_GAIN_SIZE);
da9150_fg_read_sync_end(fg);
- div = (u64) (sd_gain * shunt_val * 65536ULL);
+ div = 65536ULL * sd_gain * shunt_val;
do_div(div, 1000000);
- res = (u64) (iavg * 1000000ULL);
+ res = 1000000ULL * iavg;
do_div(res, div);
val->intval = (int) res;
@@ -510,43 +506,30 @@ static int da9150_fg_probe(struct platform_device *pdev)
* work for reporting data updates.
*/
if (fg->interval) {
- INIT_DELAYED_WORK(&fg->work, da9150_fg_work);
+ ret = devm_delayed_work_autocancel(dev, &fg->work,
+ da9150_fg_work);
+ if (ret) {
+ dev_err(dev, "Failed to init work\n");
+ return ret;
+ }
+
schedule_delayed_work(&fg->work,
msecs_to_jiffies(fg->interval));
}
/* Register IRQ */
irq = platform_get_irq_byname(pdev, "FG");
- if (irq < 0) {
- dev_err(dev, "Failed to get IRQ FG: %d\n", irq);
- ret = irq;
- goto irq_fail;
- }
+ if (irq < 0)
+ return irq;
ret = devm_request_threaded_irq(dev, irq, NULL, da9150_fg_irq,
IRQF_ONESHOT, "FG", fg);
if (ret) {
dev_err(dev, "Failed to request IRQ %d: %d\n", irq, ret);
- goto irq_fail;
+ return ret;
}
return 0;
-
-irq_fail:
- if (fg->interval)
- cancel_delayed_work(&fg->work);
-
- return ret;
-}
-
-static int da9150_fg_remove(struct platform_device *pdev)
-{
- struct da9150_fg *fg = platform_get_drvdata(pdev);
-
- if (fg->interval)
- cancel_delayed_work(&fg->work);
-
- return 0;
}
static int da9150_fg_resume(struct platform_device *pdev)
@@ -568,7 +551,6 @@ static struct platform_driver da9150_fg_driver = {
.name = "da9150-fuel-gauge",
},
.probe = da9150_fg_probe,
- .remove = da9150_fg_remove,
.resume = da9150_fg_resume,
};