hwmon: Add KEBA battery monitoring controller support
Subsystems (2)
PATCH v2 1/1 hwmon: Add KEBA battery monitoring controller support
From: Gerhard Engleder <[email protected]>
The KEBA battery monitoring controller is found in the system FPGA of KEBA PLC devices. It puts a load on the coin cell battery to check the state of the battery. If the coin cell battery is nearly empty, then the user space is signaled with a hwmon alarm.
The auxiliary device for this driver is instantiated by the cp500 misc driver.
---
v2:
- add info of relation to cp500 to commit message (Thomas Weißschuh)
- add Documentation/hwmon/kbatt.rst (Thomas Weißschuh, Guenter Roeck)
- remove COMPILE_TEST, HAS_IOMEM and AUXILIARY_BUS Kconfig dependencies (Thomas Weißschuh, Guenter Roeck)
- fix typo and year position in copyright line (Thomas Weißschuh)
- add missing device.h, auxiliary_bus.h and mutex.h includes (Thomas Weißschuh)
- remove auxdev from struct kbatt (Thomas Weißschuh)
- remove hwmon_dev from struct kbatt (Thomas Weißschuh)
- use bool for alarm in struct kbatt (Thomas Weißschuh, Guenter Roeck)
- eliminate valid from struct kbatt (Thomas Weißschuh)
- use flseep() instead of msleep() (Thomas Weißschuh)
- remove useless argument check in kbatt_read() (Thomas Weißschuh)
- remove channel 0 dummy (Thomas Weißschuh, Guenter Roeck)
- use sizeof(*kbatt) for devm_kzalloc() (Thomas Weißschuh)
- use devm_mutex_init() (Thomas Weißschuh)
- remove useless auxiliary_set_drvdata() calls (Thomas Weißschuh)
- use PTR_ERR_OR_ZERO() (Thomas Weißschuh)
- remove unnecessary ( ) (Guenter Roeck)
- switch to in0_min_alarm (Guenter Roeck)
- rework last_updated to next_update in struct kbatt
- increase polling to 10s
--- Documentation/hwmon/index.rst | 1 + Documentation/hwmon/kbatt.rst | 60 ++++++++++++++ drivers/hwmon/Kconfig | 10 +++ drivers/hwmon/Makefile | 1 + drivers/hwmon/kbatt.c | 147 ++++++++++++++++++++++++++++++++++ 5 files changed, 219 insertions(+) create mode 100644 Documentation/hwmon/kbatt.rst create mode 100644 drivers/hwmon/kbatt.c
Documentation/hwmon/index.rst +1 -0
@@ -106,6 +106,7 @@ Hardware Monitoring Kernel Drivers jc42 k10temp k8temp + kbatt lan966x lineage-pem lm25066
Documentation/hwmon/kbatt.rst new file +60 -0
60 lines not on this page · raw message
drivers/hwmon/Kconfig +10 -0
@@ -335,6 +335,16 @@ config SENSORS_K10TEMP This driver can also be built as a module. If so, the module will be called k10temp. +config SENSORS_KBATT + tristate "KEBA battery controller support" + depends on KEBA_CP500 + help + This driver supports the battery monitoring controller found in + KEBA system FPGA devices. + + This driver can also be built as a module. If so, the module + will be called kbatt. + config SENSORS_FAM15H_POWER tristate "AMD Family 15h processor power" depends on X86 && PCI && CPU_SUP_AMD
drivers/hwmon/Makefile +1 -0
@@ -110,6 +110,7 @@ obj-$(CONFIG_SENSORS_IT87) += it87.o obj-$(CONFIG_SENSORS_JC42) += jc42.o obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o obj-$(CONFIG_SENSORS_K10TEMP) += k10temp.o +obj-$(CONFIG_SENSORS_KBATT) += kbatt.o obj-$(CONFIG_SENSORS_LAN966X) += lan966x-hwmon.o obj-$(CONFIG_SENSORS_LENOVO_EC) += lenovo-ec-sensors.o obj-$(CONFIG_SENSORS_LINEAGE) += lineage-pem.o
drivers/hwmon/kbatt.c new file +147 -0
147 lines not on this page · raw message
Signature · 1 line
2.39.5
Guenter Roeck
maintainerQuoted 12 lines · Gerhard Engleder
From: Gerhard Engleder <[email protected]>
The KEBA battery monitoring controller is found in the system FPGA of KEBA PLC devices. It puts a load on the coin cell battery to check the state of the battery. If the coin cell battery is nearly empty, then the user space is signaled with a hwmon alarm.
The auxiliary device for this driver is instantiated by the cp500 misc driver.
Signed-off-by Gerhard Engleder <[email protected]>---
...
drivers/hwmon/kbatt.c line 55
Quoted 13 lines
drivers/hwmon/kbatt.c new file +8
-0+ +/* check battery state */ +if (ioread8 (kbatt->base +KBATT_STATUS_REG ) & +KBATT_STATUS_BAT_OK ) + kbatt->alarm = false; +else + kbatt->alarm = true; +
kbatt->alarm = !(ioread8(kbatt->base + KBATT_STATUS_REG) & KBATT_STATUS_BAT_OK);
Quoted 7 lines
drivers/hwmon/kbatt.c new file +7
-0+/* switch load off */ +iowrite8 (0 , kbatt->base +KBATT_CONTROL_REG ); + + kbatt->next_update = jiffies +KBATT_MAX_UPD_INTERVAL ; + } + +mutex_unlock (&kbatt->lock);
drivers/hwmon/kbatt.c line 72
Quoted 10 lines
drivers/hwmon/kbatt.c new file +10
-0+ +return kbatt->alarm; +} + +static int kbatt_read (struct device *dev,enum hwmon_sensor_types type, +u32 attr,int channel,long *val) +{ +struct kbatt *kbatt =dev_get_drvdata (dev); + + *val =kbatt_alarm (kbatt) ?1 :0 ;
and
*val = kbatt_alarm(kbatt);
would have been equivalent and a bit simpler. Also, kbatt_is_visible() could have just returned 0444 without any checks since there is only one attribute and it is always present. However, I am tired of arguing today, so applied.
Guenter
Quoted 50 lines · Guenter Roeck
Quoted 12 lines · Gerhard Engleder
From: Gerhard Engleder <[email protected]>
The KEBA battery monitoring controller is found in the system FPGA of KEBA PLC devices. It puts a load on the coin cell battery to check the state of the battery. If the coin cell battery is nearly empty, then the user space is signaled with a hwmon alarm.
The auxiliary device for this driver is instantiated by the cp500 misc driver.
Signed-off-by Gerhard Engleder <[email protected]>---
...
drivers/hwmon/kbatt.c line 55
Quoted 13 lines
drivers/hwmon/kbatt.c new file +8
-0+ +/* check battery state */ +if (ioread8 (kbatt->base +KBATT_STATUS_REG ) & +KBATT_STATUS_BAT_OK ) + kbatt->alarm = false; +else + kbatt->alarm = true; +kbatt->alarm = !(ioread8(kbatt->base + KBATT_STATUS_REG) & KBATT_STATUS_BAT_OK);Quoted 7 lines
drivers/hwmon/kbatt.c new file +7
-0+/* switch load off */ +iowrite8 (0 , kbatt->base +KBATT_CONTROL_REG ); + + kbatt->next_update = jiffies +KBATT_MAX_UPD_INTERVAL ; + } + +mutex_unlock (&kbatt->lock);drivers/hwmon/kbatt.c line 72
Quoted 10 lines
drivers/hwmon/kbatt.c new file +10
-0+ +return kbatt->alarm; +} + +static int kbatt_read (struct device *dev,enum hwmon_sensor_types type, +u32 attr,int channel,long *val) +{ +struct kbatt *kbatt =dev_get_drvdata (dev); + + *val =kbatt_alarm (kbatt) ?1 :0 ;and
Quoted 6 lines
*val = kbatt_alarm(kbatt);would have been equivalent and a bit simpler. Also,
kbatt_is_visible()could have just returned 0444 without any checks since there is only one attribute and it is always present. However, I am tired of arguing today, so applied.
Thanks for applying! I will try to make you less tired next time.
Gerhard
Guenter Roeck
maintainerQuoted 7 lines · Gerhard Engleder
Quoted 4 lines
would have been equivalent and a bit simpler. Also,
kbatt_is_visible()could have just returned 0444 without any checks since there is only one attribute and it is always present. However, I am tired of arguing today, so applied.Thanks for applying! I will try to make you less tired next time.
Wasn't you :-)
Guenter