1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Siemens SIMATIC IPC driver for CMOS battery monitoring 4 * 5 * Copyright (c) Siemens AG, 2023 6 * 7 * Authors: 8 * Henning Schild <henning.schild@siemens.com> 9 */ 10 11#include <linux/gpio/machine.h> 12#include <linux/gpio/consumer.h> 13#include <linux/kernel.h> 14#include <linux/module.h> 15#include <linux/platform_device.h> 16#include <linux/platform_data/x86/simatic-ipc-base.h> 17 18#include "simatic-ipc-batt.h" 19 20static struct gpiod_lookup_table *batt_lookup_table; 21 22static struct gpiod_lookup_table simatic_ipc_batt_gpio_table_227g = { 23 .table = { 24 GPIO_LOOKUP_IDX("gpio-f7188x-7", 6, NULL, 0, GPIO_ACTIVE_HIGH), 25 GPIO_LOOKUP_IDX("gpio-f7188x-7", 5, NULL, 1, GPIO_ACTIVE_HIGH), 26 GPIO_LOOKUP_IDX("INTC1020:01", 66, NULL, 2, GPIO_ACTIVE_HIGH), 27 {} /* Terminating entry */ 28 }, 29}; 30 31static struct gpiod_lookup_table simatic_ipc_batt_gpio_table_bx_39a = { 32 .table = { 33 GPIO_LOOKUP_IDX("gpio-f7188x-6", 4, NULL, 0, GPIO_ACTIVE_HIGH), 34 GPIO_LOOKUP_IDX("gpio-f7188x-6", 3, NULL, 1, GPIO_ACTIVE_HIGH), 35 {} /* Terminating entry */ 36 }, 37}; 38 39static struct gpiod_lookup_table simatic_ipc_batt_gpio_table_bx_59a = { 40 .table = { 41 GPIO_LOOKUP_IDX("gpio-f7188x-7", 6, NULL, 0, GPIO_ACTIVE_HIGH), 42 GPIO_LOOKUP_IDX("gpio-f7188x-7", 5, NULL, 1, GPIO_ACTIVE_HIGH), 43 GPIO_LOOKUP_IDX("INTC1056:00", 438, NULL, 2, GPIO_ACTIVE_HIGH), 44 {} /* Terminating entry */ 45 } 46}; 47 48static void simatic_ipc_batt_f7188x_remove(struct platform_device *pdev) 49{ 50 simatic_ipc_batt_remove(pdev, batt_lookup_table); 51} 52 53static int simatic_ipc_batt_f7188x_probe(struct platform_device *pdev) 54{ 55 const struct simatic_ipc_platform *plat = pdev->dev.platform_data; 56 57 switch (plat->devmode) { 58 case SIMATIC_IPC_DEVICE_227G: 59 batt_lookup_table = &simatic_ipc_batt_gpio_table_227g; 60 break; 61 case SIMATIC_IPC_DEVICE_BX_39A: 62 batt_lookup_table = &simatic_ipc_batt_gpio_table_bx_39a; 63 break; 64 case SIMATIC_IPC_DEVICE_BX_59A: 65 batt_lookup_table = &simatic_ipc_batt_gpio_table_bx_59a; 66 break; 67 default: 68 return -ENODEV; 69 } 70 71 return simatic_ipc_batt_probe(pdev, batt_lookup_table); 72} 73 74static struct platform_driver simatic_ipc_batt_driver = { 75 .probe = simatic_ipc_batt_f7188x_probe, 76 .remove_new = simatic_ipc_batt_f7188x_remove, 77 .driver = { 78 .name = KBUILD_MODNAME, 79 }, 80}; 81 82module_platform_driver(simatic_ipc_batt_driver); 83 84MODULE_LICENSE("GPL"); 85MODULE_ALIAS("platform:" KBUILD_MODNAME); 86MODULE_SOFTDEP("pre: simatic-ipc-batt gpio_f7188x platform:elkhartlake-pinctrl platform:alderlake-pinctrl"); 87MODULE_AUTHOR("Henning Schild <henning.schild@siemens.com>"); 88