From nobody Wed Nov 27 09:59:15 2024 Received: from mx01lb.world4you.com (mx01lb.world4you.com [81.19.149.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE9811BDAA7 for ; Fri, 11 Oct 2024 19:13:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=81.19.149.111 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728673993; cv=none; b=a0pdaSeD8+zJDJQjqpbs0060KZ/sHzjZBtxkZ0qgls2lq9PGvFKDF3tLeLSiOW7nib0fzlaRhS4jJyug8aYBu48fPs5h3ajkibBrgYYEiGqQKP9VGclo2bsUAnn7nybfgBSwDQjvY/U5Nq8Er1okD1QHobRNYAYBMqQwPz+d+Rw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728673993; c=relaxed/simple; bh=9d627FDTOIkVX66beegSDFYO5t9zTrTs4nuv5e8i32s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=c2FJLMQKDFP/UeNLeIrV/es+PRCITCyWGAEJLEaadvL1Hs2XjnLYsJ8u/iOUL5OWtEfyoSCZAErupaysZM3c7kfbpV/mb/kPRRH90FJe6ygZk4bUG6LAbS8ZutXkdGNjtVn4aRzcuofG7OOIHCNPFdshkqfsrJ4AarM8ebuZ+uE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=engleder-embedded.com; spf=pass smtp.mailfrom=engleder-embedded.com; dkim=pass (1024-bit key) header.d=engleder-embedded.com header.i=@engleder-embedded.com header.b=tEsrqeI2; arc=none smtp.client-ip=81.19.149.111 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=engleder-embedded.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=engleder-embedded.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=engleder-embedded.com header.i=@engleder-embedded.com header.b="tEsrqeI2" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=engleder-embedded.com; s=dkim11; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=lfm5KoQta1gf45olzsRtGjm8PknulBKLLAsOuXP43tM=; b=tEsrqeI2ZPyTD7ByaRePeSCfJ/ C3bHuEF8HszBPBp/JkTWkKidSnOfPa2pHoT05GOPPOUSutOs3OkLUCrmaIk6YqDMxkC21Tvqv1TZb lh0DcGJWAsf2zCYfgfnEUCyLiUfQA4XdzJGs0shfn426Gze5wzrSgUloVBhcm09+ZqcY=; Received: from 88-117-56-173.adsl.highway.telekom.at ([88.117.56.173] helo=hornet.engleder.at) by mx01lb.world4you.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.97.1) (envelope-from ) id 1szL4X-0000000039T-2Ya1; Fri, 11 Oct 2024 21:13:09 +0200 From: Gerhard Engleder To: linux-kernel@vger.kernel.org Cc: arnd@arndb.de, gregkh@linuxfoundation.org, Gerhard Engleder , Gerhard Engleder Subject: [PATCH v2 7/8] misc: keba: Add battery device Date: Fri, 11 Oct 2024 21:12:56 +0200 Message-Id: <20241011191257.19702-8-gerhard@engleder-embedded.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241011191257.19702-1-gerhard@engleder-embedded.com> References: <20241011191257.19702-1-gerhard@engleder-embedded.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-AV-Do-Run: Yes X-ACL-Warn: X-W4Y-Internal Content-Type: text/plain; charset="utf-8" From: Gerhard Engleder Add support for the battery auxiliary device. This enables monitoring of the battery. Signed-off-by: Gerhard Engleder --- 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; }; =20 /* list of devices within FPGA of CP035 family (CP035, CP056, CP057) */ @@ -90,6 +91,7 @@ static struct cp500_devs cp035_devices =3D { .spi =3D { 0x1000, SZ_4K }, .i2c =3D { 0x4000, SZ_4K }, .fan =3D { 0x9000, SZ_4K }, + .batt =3D { 0xA000, SZ_4K }, }; =20 /* list of devices within FPGA of CP505 family (CP503, CP505, CP507) */ @@ -98,6 +100,7 @@ static struct cp500_devs cp505_devices =3D { .spi =3D { 0x4000, SZ_4K }, .i2c =3D { 0x5000, SZ_4K }, .fan =3D { 0x9000, SZ_4K }, + .batt =3D { 0xA000, SZ_4K }, }; =20 /* list of devices within FPGA of CP520 family (CP520, CP530) */ @@ -106,6 +109,7 @@ static struct cp500_devs cp520_devices =3D { .spi =3D { 0x4000, SZ_4K }, .i2c =3D { 0x5000, SZ_4K }, .fan =3D { 0x8000, SZ_4K }, + .batt =3D { 0x9000, SZ_4K }, }; =20 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; =20 /* ECM EtherCAT BAR */ resource_size_t ecm_hwbase; @@ -457,6 +462,54 @@ static int cp500_register_fan(struct cp500 *cp500) return 0; } =20 +static void cp500_batt_release(struct device *dev) +{ + struct keba_batt_auxdev *fan =3D + container_of(dev, struct keba_batt_auxdev, auxdev.dev); + + kfree(fan); +} + +static int cp500_register_batt(struct cp500 *cp500) +{ + int ret; + + cp500->batt =3D kzalloc(sizeof(*cp500->batt), GFP_KERNEL); + if (!cp500->batt) + return -ENOMEM; + + cp500->batt->auxdev.name =3D "batt"; + cp500->batt->auxdev.id =3D 0; + cp500->batt->auxdev.dev.release =3D cp500_batt_release; + cp500->batt->auxdev.dev.parent =3D &cp500->pci_dev->dev; + cp500->batt->io =3D (struct resource) { + /* battery register area */ + .start =3D (resource_size_t) cp500->sys_hwbase + + cp500->devs->batt.offset, + .end =3D (resource_size_t) cp500->sys_hwbase + + cp500->devs->batt.offset + + cp500->devs->batt.size - 1, + .flags =3D IORESOURCE_MEM, + }; + + ret =3D auxiliary_device_init(&cp500->batt->auxdev); + if (ret) { + kfree(cp500->batt); + cp500->batt =3D NULL; + + return ret; + } + ret =3D __auxiliary_device_add(&cp500->batt->auxdev, "keba"); + if (ret) { + auxiliary_device_uninit(&cp500->batt->auxdev); + cp500->batt =3D 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"); } =20 static void cp500_unregister_dev(struct auxiliary_device *auxdev) @@ -635,6 +690,10 @@ static void cp500_unregister_auxiliary_devs(struct cp5= 00 *cp500) cp500_unregister_dev(&cp500->fan->auxdev); cp500->fan =3D NULL; } + if (cp500->batt) { + cp500_unregister_dev(&cp500->batt->auxdev); + cp500->batt =3D NULL; + } } =20 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; }; =20 +/** + * 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 */ --=20 2.39.2