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_capability(struct udevice *dev) 14 { 15 const struct dm_fuel_gauge_ops *ops = dev_get_driver_ops(dev); 16 17 if (!ops || !ops->capability) 18 return (FG_CAP_CHARGER | FG_CAP_FUEL_GAUGE); 19 20 return ops->capability(dev); 21 } 22 23 int fuel_gauge_bat_is_exist(struct udevice *dev) 24 { 25 const struct dm_fuel_gauge_ops *ops = dev_get_driver_ops(dev); 26 27 if (!ops || !ops->bat_is_exist) 28 return -ENOSYS; 29 30 return ops->bat_is_exist(dev); 31 } 32 33 int fuel_gauge_get_current(struct udevice *dev) 34 { 35 const struct dm_fuel_gauge_ops *ops = dev_get_driver_ops(dev); 36 37 if (!ops || !ops->get_current) 38 return -ENOSYS; 39 40 return ops->get_current(dev); 41 } 42 43 int fuel_gauge_get_voltage(struct udevice *dev) 44 { 45 const struct dm_fuel_gauge_ops *ops = dev_get_driver_ops(dev); 46 47 if (!ops || !ops->get_voltage) 48 return -ENOSYS; 49 50 return ops->get_voltage(dev); 51 } 52 53 int fuel_gauge_get_soc(struct udevice *dev) 54 { 55 const struct dm_fuel_gauge_ops *ops = dev_get_driver_ops(dev); 56 57 if (!ops || !ops->get_soc) 58 return -ENOSYS; 59 60 return ops->get_soc(dev); 61 } 62 63 bool fuel_gauge_get_chrg_online(struct udevice *dev) 64 { 65 const struct dm_fuel_gauge_ops *ops = dev_get_driver_ops(dev); 66 67 if (!ops || !ops->get_chrg_online) 68 return -ENOSYS; 69 70 return ops->get_chrg_online(dev); 71 } 72 73 UCLASS_DRIVER(fuel_guage) = { 74 .id = UCLASS_FG, 75 .name = "fuel_gauge", 76 }; 77