Skip to contentSkip to conversation

I2C controller support for KEBA PLCs

PATCH Superseded Gerhard Engleder 2 participants 5 messages Jul 10, 2024 – Aug 13, 2024

Subsystems (2)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover I2C controller support for KEBA PLCs

KEBA PLCs use a PCIe FPGA to implement several functions in a common way. This is a first step to include basic support for this FPGA.

Under drivers/misc the cp500 PCI driver is added. This drivers creates auxiliary devices for every function inside the FPGA. As a first step it only creates auxiliary devices for the I2C controllers.

The I2C controller driver is added under drivers/i2c/busses like all the other I2C controller drivers.

This patches enable access to the EEPROMs and to the hardware monitoring chip of KEBA PLCs.

v3:
- first patch is already merged to char-misc-next by Greg KH
- add AUXILIARY_BUS Kconfig dependency
- don't declare int i within for loop (Andi Shyti)
- enable I2C controller as late as possible (Andi Shyti)
- use devm_i2c_add_adapter (Andi Shyti)
- add KI2C_CONTROL_DISABLE (Andi Shyti)

v2:
- use aux bus (Greg KH)
- add Documentation/ABI/ entry for version and keep_cfg sysfs files (Greg KH)
- use sysfs_emit (Greg KH)
- add some information about I2C controller in commit message (Andi Shyti)
- remove old copyright line (Andi Shyti)
- sort header alphabetically (Andi Shyti)
- rework register defines as suggested (Andi Shyti)
- fix block comment style multiple times (Andi Shyti)
- add comment that IN_USE bit is a semaphore (Andi Shyti)
- add comment that IN_USE bit polling sleeps (Andi Shyti)
- addr as first argument of ki2c_wait_for_bit() (Andi Shyti)
- avoid compact style for register flag check (Andi Shyti)
- move bus reset dev_err's to reset implementation (Andi Shyti)
- use dev_err_probe() (Andi Shyti)
- fix 'ki2c_devtype defined but not used' (kernel test robot)
- fix 'WARNING comparing pointer to 0', twice (kernel test robot)
- fix 'Using plain integer as NULL pointer' (kernel test robot)
- fix 'symbol cp035_devices was not declared. Should it be static?', 3 times (kernel test robot)

Gerhard Engleder (2):
misc: keba: Add basic KEBA CP500 system FPGA support
i2c: keba: Add KEBA I2C controller support

 .../ABI/stable/sysfs-driver-misc-cp500        |  25 +
 drivers/i2c/busses/Kconfig                    |  11 +
 drivers/i2c/busses/Makefile                   |   1 +
 drivers/i2c/busses/i2c-keba.c                 | 593 ++++++++++++++++++
 drivers/misc/Kconfig                          |   1 +
 drivers/misc/Makefile                         |   1 +
 drivers/misc/keba/Kconfig                     |  12 +
 drivers/misc/keba/Makefile                    |   3 +
 drivers/misc/keba/cp500.c                     | 458 ++++++++++++++
 include/linux/misc/keba.h                     |  25 +
 10 files changed, 1130 insertions(+)
 create mode 100644 Documentation/ABI/stable/sysfs-driver-misc-cp500
 create mode 100644 drivers/i2c/busses/i2c-keba.c
 create mode 100644 drivers/misc/keba/Kconfig
 create mode 100644 drivers/misc/keba/Makefile
 create mode 100644 drivers/misc/keba/cp500.c
 create mode 100644 include/linux/misc/keba.h
Signature · 1 line
2.39.2
#1 lore raw

PATCH v3 1/2 misc: keba: Add basic KEBA CP500 system FPGA support

From: Gerhard Engleder <[email protected]>

The KEBA CP500 system FPGA is a PCIe device, which consists of multiple IP cores. Every IP core has its own auxiliary driver. The cp500 driver registers an auxiliary device for each device and the corresponding drivers are loaded by the Linux driver infrastructure.

Currently 3 variants of this device exists. Every variant has its own PCI device ID, which is used to determine the list of available IP cores. In this first version only the auxiliary device for the I2C controller is registered.

Besides the auxiliary device registration some other basic functions of the FPGA are implemented; e.g, FPGA version sysfs file, keep FPGA configuration on reset sysfs file, error message for errors on the internal AXI bus of the FPGA.

---
 .../ABI/stable/sysfs-driver-misc-cp500        |  25 +
 drivers/misc/Kconfig                          |   1 +
 drivers/misc/Makefile                         |   1 +
 drivers/misc/keba/Kconfig                     |  12 +
 drivers/misc/keba/Makefile                    |   3 +
 drivers/misc/keba/cp500.c                     | 458 ++++++++++++++++++
 include/linux/misc/keba.h                     |  25 +
 7 files changed, 525 insertions(+)
 create mode 100644 Documentation/ABI/stable/sysfs-driver-misc-cp500
 create mode 100644 drivers/misc/keba/Kconfig
 create mode 100644 drivers/misc/keba/Makefile
 create mode 100644 drivers/misc/keba/cp500.c
 create mode 100644 include/linux/misc/keba.h
Documentation/ABI/stable/sysfs-driver-misc-cp500 new file +25 -0
new file mode 100644
index 000000000000..525bd18a2db4
@@ -0,0 +1,25 @@
+What:		/sys/devices/pciXXXX:XX/0000:XX:XX.X/0000:XX:XX.X/version
+Date:		June 2024
+KernelVersion:	6.11
+Contact:	Gerhard Engleder <[email protected]>
+Description:	Version of the FPGA configuration bitstream as printable string.
+		This file is read only.
+Users:		KEBA
+
+What:		/sys/devices/pciXXXX:XX/0000:XX:XX.X/0000:XX:XX.X/keep_cfg
+Date:		June 2024
+KernelVersion:	6.11
+Contact:	Gerhard Engleder <[email protected]>
+Description:	Flag which signals if FPGA shall keep or reload configuration
+		bitstream on reset. Normal FPGA behavior and default is to keep
+		configuration bitstream and to only reset the configured logic.
+
+		Reloading configuration on reset enables an update of the
+		configuration bitstream with a simple reboot. Otherwise it is
+		necessary to power cycle the device to reload the new
+		configuration bitstream.
+
+		This file is read/write. The values are as follows:
+		1 = keep configuration bitstream on reset, default
+		0 = reload configuration bitstream on reset
+Users:		KEBA
drivers/misc/Kconfig +1 -0
index faf983680040..ca0c6a728a00 100644
@@ -602,4 +602,5 @@ source "drivers/misc/cardreader/Kconfig"
 source "drivers/misc/uacce/Kconfig"
 source "drivers/misc/pvpanic/Kconfig"
 source "drivers/misc/mchp_pci1xxxx/Kconfig"
+source "drivers/misc/keba/Kconfig"
 endmenu
drivers/misc/Makefile +1 -0
index 153a3f4837e8..af125aa25a50 100644
@@ -69,3 +69,4 @@ obj-$(CONFIG_TMR_INJECT)	+= xilinx_tmr_inject.o
 obj-$(CONFIG_TPS6594_ESM)	+= tps6594-esm.o
 obj-$(CONFIG_TPS6594_PFSM)	+= tps6594-pfsm.o
 obj-$(CONFIG_NSM)		+= nsm.o
+obj-y				+= keba/
drivers/misc/keba/Kconfig new file +12 -0
new file mode 100644
index 000000000000..0ebca1d07ef4
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0
+config KEBA_CP500
+	tristate "KEBA CP500 system FPGA support"
+	depends on PCI
+	help
+	  This driver supports the KEBA CP500 system FPGA, which is used in
+	  KEBA CP500 devices. It registers all sub devices present on the CP500
+	  system FPGA as separate devices. A driver is needed for each sub
+	  device.
+
+	  This driver can also be built as a module. If so, the module will be
+	  called cp500.
drivers/misc/keba/Makefile new file +3 -0
new file mode 100644
index 000000000000..0a8b846cda7d
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-$(CONFIG_KEBA_CP500)	+= cp500.o
drivers/misc/keba/cp500.c new file +458 -0

458 lines not on this page · raw message

include/linux/misc/keba.h new file +25 -0
new file mode 100644
index 000000000000..323b31a847c5
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2024, KEBA Industrial Automation Gmbh */
+
+#ifndef _LINUX_MISC_KEBA_H
+#define _LINUX_MISC_KEBA_H
+
+#include <linux/auxiliary_bus.h>
+
+struct i2c_board_info;
+
+/**
+ * struct keba_i2c_auxdev - KEBA I2C auxiliary device
+ * @auxdev: auxiliary device object
+ * @io: address range of I2C controller IO memory
+ * @info_size: number of I2C devices to be probed
+ * @info: I2C devices to be probed
+ */
+struct keba_i2c_auxdev {
+	struct auxiliary_device auxdev;
+	struct resource io;
+	int info_size;
+	struct i2c_board_info *info;
+};
+
+#endif /* _LINUX_MISC_KEBA_H */
Signature · 1 line
2.39.2
maintainer
#2 lore raw

Re: [PATCH v3 1/2] misc: keba: Add basic KEBA CP500 system FPGA support

drivers/misc/keba/cp500.c line 399

Quoted 1 line · Gerhard Engleder
drivers/misc/keba/cp500.c new file +1 -0
+	ret = sysfs_create_group(&pci_dev->dev.kobj, &attrs_group);

You just raced with userspace and lost :(

Please use the default groups for your driver instead, that way the driver core will handle all of the creation/cleanup properly for you without having to worry you about it.

thanks,

greg k-h

#3 lore raw

Re: [PATCH v3 1/2] misc: keba: Add basic KEBA CP500 system FPGA support

Quoted 8 lines · Greg KH

drivers/misc/keba/cp500.c line 399

Quoted 1 line · Gerhard Engleder
drivers/misc/keba/cp500.c new file +1 -0
+	ret = sysfs_create_group(&pci_dev->dev.kobj, &attrs_group);

You just raced with userspace and lost :(

Please use the default groups for your driver instead, that way the driver core will handle all of the creation/cleanup properly for you without having to worry you about it.

I was not aware of that. I will take a look on it and post a patch.

Thank you!

Gerhard

#4 lore raw

PATCH v3 2/2 i2c: keba: Add KEBA I2C controller support

In reply to Gerhard Engleder

From: Gerhard Engleder <[email protected]>

The KEBA I2C controller is found in the system FPGA of KEBA PLC devices. It is used to connect EEPROMs and hardware monitoring chips. The

It is a simple I2C controller with a fixed bus speed of 100 kbit/s. The whole message transmission is executed by the driver. The driver triggers all steps over control, status and data register. There are no FIFOs or interrupts.

---
 drivers/i2c/busses/Kconfig    |  11 +
 drivers/i2c/busses/Makefile   |   1 +
 drivers/i2c/busses/i2c-keba.c | 593 ++++++++++++++++++++++++++++++++++
 3 files changed, 605 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-keba.c
drivers/i2c/busses/Kconfig +11 -0
index 3e32fb882101..41162130c6f2 100644
@@ -771,6 +771,17 @@ config I2C_JZ4780
 
 	 If you don't know what to do here, say N.
 
+config I2C_KEBA
+	tristate "KEBA I2C controller support"
+	depends on HAS_IOMEM
+	select AUXILIARY_BUS
+	help
+	  This driver supports the I2C controller found in KEBA system FPGA
+	  devices.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called i2c-keba.
+
 config I2C_KEMPLD
 	tristate "Kontron COM I2C Controller"
 	depends on MFD_KEMPLD
drivers/i2c/busses/Makefile +1 -0
index 78d0561339e5..ecc07c50f2a0 100644
@@ -76,6 +76,7 @@ obj-$(CONFIG_I2C_IMX)		+= i2c-imx.o
 obj-$(CONFIG_I2C_IMX_LPI2C)	+= i2c-imx-lpi2c.o
 obj-$(CONFIG_I2C_IOP3XX)	+= i2c-iop3xx.o
 obj-$(CONFIG_I2C_JZ4780)	+= i2c-jz4780.o
+obj-$(CONFIG_I2C_KEBA)		+= i2c-keba.o
 obj-$(CONFIG_I2C_KEMPLD)	+= i2c-kempld.o
 obj-$(CONFIG_I2C_LPC2K)		+= i2c-lpc2k.o
 obj-$(CONFIG_I2C_LS2X)		+= i2c-ls2x.o
drivers/i2c/busses/i2c-keba.c new file +593 -0

593 lines not on this page · raw message

Signature · 1 line
2.39.2