Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

misc: keba: Add battery device

Add support for the battery auxiliary device. This enables monitoring of
the battery.

Signed-off-by: Gerhard Engleder <eg@keba.com>
Link: https://lore.kernel.org/r/20241011191257.19702-8-gerhard@engleder-embedded.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Gerhard Engleder and committed by
Greg Kroah-Hartman
ca7b844b f965d315

+69
+59
drivers/misc/keba/cp500.c
··· 82 82 struct cp500_dev_info spi; 83 83 struct cp500_dev_info i2c; 84 84 struct cp500_dev_info fan; 85 + struct cp500_dev_info batt; 85 86 }; 86 87 87 88 /* list of devices within FPGA of CP035 family (CP035, CP056, CP057) */ ··· 91 90 .spi = { 0x1000, SZ_4K }, 92 91 .i2c = { 0x4000, SZ_4K }, 93 92 .fan = { 0x9000, SZ_4K }, 93 + .batt = { 0xA000, SZ_4K }, 94 94 }; 95 95 96 96 /* list of devices within FPGA of CP505 family (CP503, CP505, CP507) */ ··· 100 98 .spi = { 0x4000, SZ_4K }, 101 99 .i2c = { 0x5000, SZ_4K }, 102 100 .fan = { 0x9000, SZ_4K }, 101 + .batt = { 0xA000, SZ_4K }, 103 102 }; 104 103 105 104 /* list of devices within FPGA of CP520 family (CP520, CP530) */ ··· 109 106 .spi = { 0x4000, SZ_4K }, 110 107 .i2c = { 0x5000, SZ_4K }, 111 108 .fan = { 0x8000, SZ_4K }, 109 + .batt = { 0x9000, SZ_4K }, 112 110 }; 113 111 114 112 struct cp500_nvmem { ··· 134 130 struct keba_spi_auxdev *spi; 135 131 struct keba_i2c_auxdev *i2c; 136 132 struct keba_fan_auxdev *fan; 133 + struct keba_batt_auxdev *batt; 137 134 138 135 /* ECM EtherCAT BAR */ 139 136 resource_size_t ecm_hwbase; ··· 462 457 return 0; 463 458 } 464 459 460 + static void cp500_batt_release(struct device *dev) 461 + { 462 + struct keba_batt_auxdev *fan = 463 + container_of(dev, struct keba_batt_auxdev, auxdev.dev); 464 + 465 + kfree(fan); 466 + } 467 + 468 + static int cp500_register_batt(struct cp500 *cp500) 469 + { 470 + int ret; 471 + 472 + cp500->batt = kzalloc(sizeof(*cp500->batt), GFP_KERNEL); 473 + if (!cp500->batt) 474 + return -ENOMEM; 475 + 476 + cp500->batt->auxdev.name = "batt"; 477 + cp500->batt->auxdev.id = 0; 478 + cp500->batt->auxdev.dev.release = cp500_batt_release; 479 + cp500->batt->auxdev.dev.parent = &cp500->pci_dev->dev; 480 + cp500->batt->io = (struct resource) { 481 + /* battery register area */ 482 + .start = (resource_size_t) cp500->sys_hwbase + 483 + cp500->devs->batt.offset, 484 + .end = (resource_size_t) cp500->sys_hwbase + 485 + cp500->devs->batt.offset + 486 + cp500->devs->batt.size - 1, 487 + .flags = IORESOURCE_MEM, 488 + }; 489 + 490 + ret = auxiliary_device_init(&cp500->batt->auxdev); 491 + if (ret) { 492 + kfree(cp500->batt); 493 + cp500->batt = NULL; 494 + 495 + return ret; 496 + } 497 + ret = __auxiliary_device_add(&cp500->batt->auxdev, "keba"); 498 + if (ret) { 499 + auxiliary_device_uninit(&cp500->batt->auxdev); 500 + cp500->batt = NULL; 501 + 502 + return ret; 503 + } 504 + 505 + return 0; 506 + } 507 + 465 508 static int cp500_nvmem_read(void *priv, unsigned int offset, void *val, 466 509 size_t bytes) 467 510 { ··· 666 613 if (present & CP500_PRESENT_FAN0) 667 614 if (cp500_register_fan(cp500)) 668 615 dev_warn(dev, "Failed to register fan!\n"); 616 + if (cp500_register_batt(cp500)) 617 + dev_warn(dev, "Failed to register battery!\n"); 669 618 } 670 619 671 620 static void cp500_unregister_dev(struct auxiliary_device *auxdev) ··· 689 634 if (cp500->fan) { 690 635 cp500_unregister_dev(&cp500->fan->auxdev); 691 636 cp500->fan = NULL; 637 + } 638 + if (cp500->batt) { 639 + cp500_unregister_dev(&cp500->batt->auxdev); 640 + cp500->batt = NULL; 692 641 } 693 642 } 694 643
+10
include/linux/misc/keba.h
··· 47 47 struct resource io; 48 48 }; 49 49 50 + /** 51 + * struct keba_batt_auxdev - KEBA battery auxiliary device 52 + * @auxdev: auxiliary device object 53 + * @io: address range of battery controller IO memory 54 + */ 55 + struct keba_batt_auxdev { 56 + struct auxiliary_device auxdev; 57 + struct resource io; 58 + }; 59 + 50 60 #endif /* _LINUX_MISC_KEBA_H */