xref: /rk3399_rockchip-uboot/drivers/power/fuel_gauge/fuel_gauge_uclass.c (revision 5ce558eee1d84a2b85f2bbc4c4547c8ea1c1dae4)
1 /*
2  * (C) Copyright 2017 Rockchip Electronics Co., Ltd
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  */
6 
7 #include <errno.h>
8 #include <dm.h>
9 #include <power/fuel_gauge.h>
10 
11 DECLARE_GLOBAL_DATA_PTR;
12 
13 int fuel_gauge_get_voltage(struct udevice *dev)
14 {
15 	const struct dm_fuel_gauge_ops *ops = dev_get_driver_ops(dev);
16 
17 	if (!ops || !ops->get_voltage)
18 		return -ENOSYS;
19 
20 	return ops->get_voltage(dev);
21 }
22 
23 int fuel_gauge_get_soc(struct udevice *dev)
24 {
25 	const struct dm_fuel_gauge_ops *ops = dev_get_driver_ops(dev);
26 
27 	if (!ops || !ops->get_soc)
28 		return -ENOSYS;
29 
30 	return ops->get_soc(dev);
31 }
32 
33 bool fuel_gauge_get_chrg_online(struct udevice *dev)
34 {
35 	const struct dm_fuel_gauge_ops *ops = dev_get_driver_ops(dev);
36 
37 	if (!ops || !ops->get_chrg_online)
38 		return -ENOSYS;
39 
40 	return ops->get_chrg_online(dev);
41 }
42 
43 UCLASS_DRIVER(fuel_guage) = {
44 	.id		= UCLASS_FG,
45 	.name		= "fuel_gauge",
46 };
47