From: Gerhard Engleder <gerhard@engleder-embedded.com>
To: linux-kernel@vger.kernel.org
Cc: arnd@arndb.de, gregkh@linuxfoundation.org,
Gerhard Engleder <gerhard@engleder-embedded.com>,
Gerhard Engleder <eg@keba.com>
Subject: [PATCH 5/6] misc: keba: Add battery device
Date: Wed, 9 Oct 2024 22:29:48 +0200 [thread overview]
Message-ID: <20241009202949.20164-6-gerhard@engleder-embedded.com> (raw)
In-Reply-To: <20241009202949.20164-1-gerhard@engleder-embedded.com>
From: Gerhard Engleder <eg@keba.com>
Add support for the battery auxiliary device. This enables monitoring of
the battery.
Signed-off-by: Gerhard Engleder <eg@keba.com>
---
drivers/misc/keba/cp500.c | 59 +++++++++++++++++++++++++++++++++++++++
include/linux/misc/keba.h | 10 +++++++
2 files changed, 69 insertions(+)
diff --git a/drivers/misc/keba/cp500.c b/drivers/misc/keba/cp500.c
index ae3ed1cece32..afd4d7c06cee 100644
--- a/drivers/misc/keba/cp500.c
+++ b/drivers/misc/keba/cp500.c
@@ -82,6 +82,7 @@ struct cp500_devs {
struct cp500_dev_info spi;
struct cp500_dev_info i2c;
struct cp500_dev_info fan;
+ struct cp500_dev_info batt;
};
/* list of devices within FPGA of CP035 family (CP035, CP056, CP057) */
@@ -90,6 +91,7 @@ static struct cp500_devs cp035_devices = {
.spi = { 0x1000, SZ_4K },
.i2c = { 0x4000, SZ_4K },
.fan = { 0x9000, SZ_4K },
+ .batt = { 0xA000, SZ_4K },
};
/* list of devices within FPGA of CP505 family (CP503, CP505, CP507) */
@@ -98,6 +100,7 @@ static struct cp500_devs cp505_devices = {
.spi = { 0x4000, SZ_4K },
.i2c = { 0x5000, SZ_4K },
.fan = { 0x9000, SZ_4K },
+ .batt = { 0xA000, SZ_4K },
};
/* list of devices within FPGA of CP520 family (CP520, CP530) */
@@ -106,6 +109,7 @@ static struct cp500_devs cp520_devices = {
.spi = { 0x4000, SZ_4K },
.i2c = { 0x5000, SZ_4K },
.fan = { 0x8000, SZ_4K },
+ .batt = { 0x9000, SZ_4K },
};
struct cp500_nvmem {
@@ -130,6 +134,7 @@ struct cp500 {
struct keba_spi_auxdev *spi;
struct keba_i2c_auxdev *i2c;
struct keba_fan_auxdev *fan;
+ struct keba_batt_auxdev *batt;
/* ECM EtherCAT BAR */
resource_size_t ecm_hwbase;
@@ -457,6 +462,54 @@ static int cp500_register_fan(struct cp500 *cp500)
return 0;
}
+static void cp500_batt_release(struct device *dev)
+{
+ struct keba_batt_auxdev *fan =
+ container_of(dev, struct keba_batt_auxdev, auxdev.dev);
+
+ kfree(fan);
+}
+
+static int cp500_register_batt(struct cp500 *cp500)
+{
+ int ret;
+
+ cp500->batt = kzalloc(sizeof(*cp500->batt), GFP_KERNEL);
+ if (!cp500->batt)
+ return -ENOMEM;
+
+ cp500->batt->auxdev.name = "batt";
+ cp500->batt->auxdev.id = 0;
+ cp500->batt->auxdev.dev.release = cp500_batt_release;
+ cp500->batt->auxdev.dev.parent = &cp500->pci_dev->dev;
+ cp500->batt->io = (struct resource) {
+ /* battery register area */
+ .start = (resource_size_t) cp500->sys_hwbase +
+ cp500->devs->batt.offset,
+ .end = (resource_size_t) cp500->sys_hwbase +
+ cp500->devs->batt.offset +
+ cp500->devs->batt.size - 1,
+ .flags = IORESOURCE_MEM,
+ };
+
+ ret = auxiliary_device_init(&cp500->batt->auxdev);
+ if (ret) {
+ kfree(cp500->batt);
+ cp500->batt = NULL;
+
+ return ret;
+ }
+ ret = __auxiliary_device_add(&cp500->batt->auxdev, "keba");
+ if (ret) {
+ auxiliary_device_uninit(&cp500->batt->auxdev);
+ cp500->batt = NULL;
+
+ return ret;
+ }
+
+ return 0;
+}
+
static int cp500_nvmem_read(void *priv, unsigned int offset, void *val,
size_t bytes)
{
@@ -613,6 +666,8 @@ static void cp500_register_auxiliary_devs(struct cp500 *cp500)
if (present & CP500_PRESENT_FAN0)
if (cp500_register_fan(cp500))
dev_warn(dev, "Failed to register fan!\n");
+ if (cp500_register_batt(cp500))
+ dev_warn(dev, "Failed to register battery!\n");
}
static void cp500_unregister_dev(struct auxiliary_device *auxdev)
@@ -635,6 +690,10 @@ static void cp500_unregister_auxiliary_devs(struct cp500 *cp500)
cp500_unregister_dev(&cp500->fan->auxdev);
cp500->fan = NULL;
}
+ if (cp500->batt) {
+ cp500_unregister_dev(&cp500->batt->auxdev);
+ cp500->batt = NULL;
+ }
}
static irqreturn_t cp500_axi_handler(int irq, void *dev)
diff --git a/include/linux/misc/keba.h b/include/linux/misc/keba.h
index 451777acc262..ca52716f8437 100644
--- a/include/linux/misc/keba.h
+++ b/include/linux/misc/keba.h
@@ -47,4 +47,14 @@ struct keba_fan_auxdev {
struct resource io;
};
+/**
+ * struct keba_batt_auxdev - KEBA battery auxiliary device
+ * @auxdev: auxiliary device object
+ * @io: address range of battery controller IO memory
+ */
+struct keba_batt_auxdev {
+ struct auxiliary_device auxdev;
+ struct resource io;
+};
+
#endif /* _LINUX_MISC_KEBA_H */
--
2.39.2
next prev parent reply other threads:[~2024-10-09 20:30 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-09 20:29 [PATCH 0/6] misc: keba: Add support for additional devices Gerhard Engleder
2024-10-09 20:29 ` [PATCH 1/6] misc: keba: Add SPI controller device Gerhard Engleder
2024-10-10 7:12 ` Greg KH
2024-10-10 19:53 ` Gerhard Engleder
2024-10-13 1:03 ` kernel test robot
2024-10-09 20:29 ` [PATCH 2/6] misc: keba: Add LAN9252 driver Gerhard Engleder
2024-10-11 8:28 ` kernel test robot
2024-10-09 20:29 ` [PATCH 3/6] misc: keba: Support EEPROM sections as separate devices Gerhard Engleder
2024-10-13 8:52 ` kernel test robot
2024-10-09 20:29 ` [PATCH 4/6] misc: keba: Add fan device Gerhard Engleder
2024-10-09 20:29 ` Gerhard Engleder [this message]
2024-10-09 20:29 ` [PATCH 6/6] misc: keba: Add UART devices Gerhard Engleder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241009202949.20164-6-gerhard@engleder-embedded.com \
--to=gerhard@engleder-embedded.com \
--cc=arnd@arndb.de \
--cc=eg@keba.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox