drivers: fsi: interrupt polling, i2c client
cover drivers: fsi: interrupt polling, i2c client
From: "Edward A. James" <[email protected]>
First, this series add interrupt polling support to the FSI bus driver. This implements a loop that constantly polls the FSI slave interrupt status register and triggers any registered client interrupt handlers upon detecting an interrupt.
Secondly, this series adds the I2C client driver for FSI bus. This driver interacts with the IBM BOE engine on an FSI slave device.
Christopher Bostic (3):
drivers/fsi: Add slave interrupt polling drivers/fsi: Add Client IRQ Enable / Disable drivers/fsi: Add sysfs file to adjust i-poll period
Edward A. James (5):
drivers: fsi: Add i2c client driver
drivers: fsi: i2c: Add engine access wrappers
drivers: fsi: i2c: probe fsi device for i2c client
drivers: fsi: i2c: add driver file operations and bus locking
drivers: fsi: i2c: boe engine
drivers/fsi/Kconfig | 6 + drivers/fsi/Makefile | 1 + drivers/fsi/fsi-core.c | 170 +++ drivers/fsi/fsi-master-gpio.c | 1 + drivers/fsi/fsi-master.h | 2 + drivers/fsi/i2c/Makefile | 1 + drivers/fsi/i2c/iic-boe.c | 1597 +++++++++++++++++++++++++++++ drivers/fsi/i2c/iic-boe.h | 180 ++++ drivers/fsi/i2c/iic-fsi.c | 715 +++++++++++++ drivers/fsi/i2c/iic-int.h | 395 +++++++ drivers/fsi/i2c/iic-lock.c | 439 ++++++++ drivers/fsi/i2c/iic-mstr.c | 2281 +++++++++++++++++++++++++++++++++++++++++ include/linux/fsi.h | 5 + include/uapi/linux/Kbuild | 1 + include/uapi/linux/i2cfsi.h | 136 +++ 15 files changed, 5930 insertions(+) create mode 100644 drivers/fsi/i2c/Makefile create mode 100644 drivers/fsi/i2c/iic-boe.c create mode 100644 drivers/fsi/i2c/iic-boe.h create mode 100644 drivers/fsi/i2c/iic-fsi.c create mode 100644 drivers/fsi/i2c/iic-int.h create mode 100644 drivers/fsi/i2c/iic-lock.c create mode 100644 drivers/fsi/i2c/iic-mstr.c create mode 100644 include/uapi/linux/i2cfsi.h
Signature · 1 line
1.8.3.1
PATCH 4/8 drivers: fsi: Add i2c client driver
From: "Edward A. James" <[email protected]>
stub for I2C driver over FSI
--- drivers/fsi/Kconfig | 6 ++ drivers/fsi/Makefile | 1 + drivers/fsi/i2c/Makefile | 1 + drivers/fsi/i2c/iic-fsi.c | 166 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/fsi/i2c/iic-fsi.h | 29 ++++++++ drivers/fsi/i2c/iic-int.h | 80 ++++++++++++++++++++++ 6 files changed, 283 insertions(+) create mode 100644 drivers/fsi/i2c/Makefile create mode 100644 drivers/fsi/i2c/iic-fsi.c create mode 100644 drivers/fsi/i2c/iic-fsi.h create mode 100644 drivers/fsi/i2c/iic-int.h
drivers/fsi/Kconfig +6 -0
@@ -24,6 +24,12 @@ config FSI_SCOM ---help--- This option enables an FSI based SCOM device driver. +config FSI_I2C + tristate "I2C FSI client device driver" + depends on FSI + ---help--- + This option enables an FSI based I2C device driver. + endif endmenu
drivers/fsi/Makefile +1 -0
@@ -2,3 +2,4 @@ obj-$(CONFIG_FSI) += fsi-core.o obj-$(CONFIG_FSI_MASTER_GPIO) += fsi-master-gpio.o obj-$(CONFIG_FSI_SCOM) += fsi-scom.o +obj-$(CONFIG_FSI_I2C) += i2c/
drivers/fsi/i2c/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_FSI_I2C) += iic-fsi.o
drivers/fsi/i2c/iic-fsi.c new file +166 -0
166 lines not on this page · raw message
drivers/fsi/i2c/iic-fsi.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* Copyright (c) International Business Machines Corp., 2006 +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef IIC_FSI_H +#define IIC_FSI_H + +/* +* we don't know ahead of time how many minors will be needed as this is based +* on platform type and the possibility of sparsely populated FRU's on special +* systems so picking a safely large number +*/ +#define IIC_FSI_MAX_DEVS 1024 + +#endif
drivers/fsi/i2c/iic-int.h new file +80 -0
80 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [PATCH linux v1 4/8] drivers: fsi: Add i2c client driver
Hi Edward,
Quoted 3 lines · On Thu, 2 Feb 2017 05:25:57 PM [email protected] wrote:
From: "Edward A. James" <[email protected]>
stub for I2C driver over FSI
Unless I've missed something it doesn't look like this uses any of the existing I2C infrastructure in the kernel. This should live in drivers/i2c/busses and register the I2C bus adapter using i2c_add_adapter(). This way all the existing kernel infrastructe for probing and assiging I2C device drivers can be utilised.
For an example see how OPAL currently exposes I2C busses on the host in drivers/i2c/busses/i2c-opal.c.
Regards,
Alistair
Quoted 341 lines
Signed-off-by Edward A. James <[email protected]>--- drivers/fsi/Kconfig | 6 ++ drivers/fsi/Makefile | 1 + drivers/fsi/i2c/Makefile | 1 + drivers/fsi/i2c/iic-fsi.c | 166 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/fsi/i2c/iic-fsi.h | 29 ++++++++ drivers/fsi/i2c/iic-int.h | 80 ++++++++++++++++++++++ 6 files changed, 283 insertions(+) create mode 100644 drivers/fsi/i2c/Makefile create mode 100644 drivers/fsi/i2c/iic-fsi.c create mode 100644 drivers/fsi/i2c/iic-fsi.h create mode 100644 drivers/fsi/i2c/iic-int.hdrivers/fsi/Kconfig +6
-0@@ -24,6 +24,12 @@ config FSI_SCOM ---help--- This option enables an FSI based SCOM device driver. +config FSI_I2C + tristate "I2C FSI client device driver" + depends on FSI + ---help--- + This option enables an FSI based I2C device driver. + endif endmenudrivers/fsi/Makefile +1
-0@@ -2,3 +2,4 @@ obj-$(CONFIG_FSI) += fsi-core.o obj-$(CONFIG_FSI_MASTER_GPIO) += fsi-master-gpio.o obj-$(CONFIG_FSI_SCOM) += fsi-scom.o +obj-$(CONFIG_FSI_I2C) += i2c/drivers/fsi/i2c/Makefile new file +1
-0@@ -0,0 +1 @@ +obj-$(CONFIG_FSI_I2C) += iic-fsi.odrivers/fsi/i2c/iic-fsi.c new file +166
-0@@ -0,0 +1,166 @@ +/* +* Copyright (c) International Business Machines Corp., 2006, 2010, 2012 +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* +* This file contains the architecture independent IIC FSI code. +*/ +#include <linux/init.h> +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/fsi.h> +#include <asm/io.h> +#include <linux/mm.h> +#include <linux/interrupt.h> +#include "iic-int.h" +#include "iic-fsi.h" + +#include <linux/delay.h> +#include <linux/moduleparam.h> + +struct class * iic_fsi_class =0 ; +dev_t iic_devnum_start =0 ; + +static const char iic_fsi_version[] ="3.0" ; + +int iic_fsi_probe (struct device *dev); +int iic_fsi_remove (struct device *dev); + +struct iic_reg_access fsi_reg_access = +{ + .bus_readb = readb_wrap, + .bus_readh = readh_wrap, + .bus_readw = readw_wrap, + .bus_writeb = writeb_wrap, + .bus_writeh = writeh_wrap, + .bus_writew = writew_wrap, +}; + +static const struct fsi_device_id i2c_ids[] = { + { + .engine_type =FSI_ENGID_I2C , + .version =FSI_VERSION_ANY , + }, + { + .engine_type =FSI_ENGID_I2C_BB , + .version =FSI_VERSION_ANY , + }, + {0 } +}; + +static const struct fsi_driver i2c_drv = { + .id_table = i2c_ids, + .drv = { + .name ="iic_fsi_dd" , + .bus = &fsi_bus_type, + .probe = iic_fsi_probe, + .remove = iic_fsi_remove, + } +}; + +/* +* Called when an FSI IIC engine is plugged in. +* Causes creation of the /dev entry. +* Not allowed to access engine registers in this function. +* +*/ +int iic_fsi_probe (struct device *dev) +{ +return 0 ; +} + +/* This function is called when a link is removed or the driver is unloaded. +* It's job is to remove the device from the device hierarchy including +* removal from sysfs (this is where device files get removed). +*/ +int iic_fsi_remove (struct device * dev) +{ +return 0 ; +} + +/* +* Initialize this module. Creates a class for fsi connected iic devices and +* allocates device numbers for them. +*/ +static int __init iic_fsi_init (void ) +{ +int rc =0 ; + +IENTER (); + + rc =alloc_chrdev_region (&iic_devnum_start, +0 ,/*starting minor number*/ +IIC_FSI_MAX_DEVS , +"iic-fsi" ); +if (rc) + { +IFLDe (1 ,"master alloc_chrdev_region failed: rc = %d\n" , rc); +return rc; + } + + iic_fsi_class =class_create (THIS_MODULE ,"iic-fsi" ); +if (IS_ERR (iic_fsi_class)) + { +IFLDe (1 ,"class_create failed: rc=%ld" , +PTR_ERR (iic_fsi_class)); + goto exit_class_create; + } +/* Register this driver with the FSI infrastructure */ + rc =fsi_driver_register (&i2c_drv); +if (rc) + { +IFLDe (1 ,"fsidrv_register failed: %d" , rc); + goto exit_drv_register; + } + +printk ("IIC FSI support loaded, ver. %s\n" , iic_fsi_version); + +IEXIT (rc); +return rc; + +exit_drv_register: +class_destroy (iic_fsi_class); +exit_class_create: +unregister_chrdev_region (iic_devnum_start,IIC_FSI_MAX_DEVS ); +IEXIT (rc); +return rc; +} + +static void __exit iic_fsi_exit(void) +{ +IENTER (); +IDBGd (0 ,"fisdrv_unregister()\n" ); +fsi_driver_unregister (&i2c_drv); +IDBGd (0 ,"unregister_chrdev_region()\n" ); +unregister_chrdev_region (iic_devnum_start,IIC_FSI_MAX_DEVS ); +if (iic_fsi_class) + { +IDBGd (0 ,"class_destroy\n" ); +class_destroy (iic_fsi_class); + } +printk ("IIC FSI support unloaded.\n" ); +IEXIT (0 ); +} + +module_init (iic_fsi_init); +module_exit (iic_fsi_exit); + +MODULE_AUTHOR ("Eddie James <[email protected]>" ); +MODULE_DESCRIPTION ("IIC FSI Driver" ); +MODULE_LICENSE ("GPL" ); +drivers/fsi/i2c/iic-fsi.h new file +29
-0@@ -0,0 +1,29 @@ +/* +* Copyright (c) International Business Machines Corp., 2006 +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef IIC_FSI_H +#define IIC_FSI_H + +/* +* we don't know ahead of time how many minors will be needed as this is based +* on platform type and the possibility of sparsely populated FRU's on special +* systems so picking a safely large number +*/ +#define IIC_FSI_MAX_DEVS 1024 + +#endif drivers/fsi/i2c/iic-int.h new file +80
-0@@ -0,0 +1,80 @@ +/* +* Copyright (c) International Business Machines Corp., 2006, 2012 +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef IIC_INT_H +#define IIC_INT_H +#include <linux/list.h> +#include <linux/spinlock.h> +#include <linux/fs.h> +#include <linux/kobject.h> +#include <linux/cdev.h> +#include <linux/device.h> +#include <linux/kdev_t.h> +#include <linux/wait.h> +#include <linux/i2cfsi.h> +#include <linux/semaphore.h> +#include <linux/fsi.h> +#include <asm/atomic.h> + +#define FSI_ENGID_I2C 0x7 +#define FSI_ENGID_I2C_BB 0x17 + +#ifdef FSI_I2C_DEBUG +#define IDBGs(num, msg, args...) printk(msg, ## args) +#define IDBGd(num, msg, args...) printk(msg, ## args) +#define IDBGf(num, msg, args...) printk(msg, ## args) +#define IDBGl(num, msg, args...) printk(msg, ## args) +#else +#define IDBGs(num, msg, args...) +#define IDBGd(num, msg, args...) +#define IDBGf(num, msg, args...) +#define IDBGl(num, msg, args...) +#endif + +#define IENTER () +#define IEXIT (RC ) + +/* IFLDx traces will not get compiled out */ +#define IFLDe(num, msg, args...)\ + printk("ERR: "msg, ## args) +#define IFLDi(num, msg, args...)\ + printk(msg, ## args) + +#ifdef FSI_I2C_DEBUG +#define IFLDs(num, msg, args...) printk(msg, ## args) +#define IFLDd(num, msg, args...) printk(msg, ## args) +#define IFLDf(num, msg, args...) printk(msg, ## args) +#define IFLDl(num, msg, args...) printk(msg, ## args) +#else +#define IFLDs(num, msg, args...) +#define IFLDd(num, msg, args...) +#define IFLDf(num, msg, args...) +#define IFLDl(num, msg, args...) +#endif + +struct iic_reg_access +{ +int (*bus_readb)(iic_eng_t *,unsigned int ,unsigned char *,iic_ffdc_t **); +int (*bus_readh)(iic_eng_t *,unsigned int ,unsigned short *,iic_ffdc_t **); +int (*bus_readw)(iic_eng_t *,unsigned int ,unsigned long *,iic_ffdc_t **); +int (*bus_writeb)(iic_eng_t *,unsigned int ,unsigned char ,iic_ffdc_t **); +int (*bus_writeh)(iic_eng_t *,unsigned int ,unsigned short ,iic_ffdc_t **); +int (*bus_writew)(iic_eng_t *,unsigned int ,unsigned long ,iic_ffdc_t **); +}; + +#endif
Re: [PATCH linux v1 4/8] drivers: fsi: Add i2c client driver
Quoted 7 lines · Alistair Popple
Hi Edward,
Quoted 3 lines · On Thu, 2 Feb 2017 05:25:57 PM [email protected] wrote:
From: "Edward A. James" <[email protected]>
stub for I2C driver over FSI
Quoted 8 lines
Unless I've missed something it doesn't look like this uses any of the existing I2C infrastructure in the kernel. This should live in
drivers/i2c/bussesand register the I2C bus adapter usingi2c_add_adapter(). This way all the existing kernel infrastructe for probing and assiging I2C device drivers can be utilised.For an example see how OPAL currently exposes I2C busses on the host in
drivers/i2c/busses/i2c-opal.c.
Alistair is right on the money. This should have never seen the light of day.
Alistair, and others: we did agree that due to this functionality being required in short order, and a proper driver not being started yet, we will merge these patches temporarily.
Eddie and Chris will be working with me to write a proper i2c driver on Monday.
Cheers,
Joel
Quoted 347 lines
Regards,
Alistair
Quoted 341 lines
Signed-off-by Edward A. James <[email protected]>--- drivers/fsi/Kconfig | 6 ++ drivers/fsi/Makefile | 1 + drivers/fsi/i2c/Makefile | 1 + drivers/fsi/i2c/iic-fsi.c | 166 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/fsi/i2c/iic-fsi.h | 29 ++++++++ drivers/fsi/i2c/iic-int.h | 80 ++++++++++++++++++++++ 6 files changed, 283 insertions(+) create mode 100644 drivers/fsi/i2c/Makefile create mode 100644 drivers/fsi/i2c/iic-fsi.c create mode 100644 drivers/fsi/i2c/iic-fsi.h create mode 100644 drivers/fsi/i2c/iic-int.hdrivers/fsi/Kconfig +6
-0@@ -24,6 +24,12 @@ config FSI_SCOM ---help--- This option enables an FSI based SCOM device driver. +config FSI_I2C + tristate "I2C FSI client device driver" + depends on FSI + ---help--- + This option enables an FSI based I2C device driver. + endif endmenudrivers/fsi/Makefile +1
-0@@ -2,3 +2,4 @@ obj-$(CONFIG_FSI) += fsi-core.o obj-$(CONFIG_FSI_MASTER_GPIO) += fsi-master-gpio.o obj-$(CONFIG_FSI_SCOM) += fsi-scom.o +obj-$(CONFIG_FSI_I2C) += i2c/drivers/fsi/i2c/Makefile new file +1
-0@@ -0,0 +1 @@ +obj-$(CONFIG_FSI_I2C) += iic-fsi.odrivers/fsi/i2c/iic-fsi.c new file +166
-0@@ -0,0 +1,166 @@ +/* +* Copyright (c) International Business Machines Corp., 2006, 2010, 2012 +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* +* This file contains the architecture independent IIC FSI code. +*/ +#include <linux/init.h> +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/fsi.h> +#include <asm/io.h> +#include <linux/mm.h> +#include <linux/interrupt.h> +#include "iic-int.h" +#include "iic-fsi.h" + +#include <linux/delay.h> +#include <linux/moduleparam.h> + +struct class * iic_fsi_class =0 ; +dev_t iic_devnum_start =0 ; + +static const char iic_fsi_version[] ="3.0" ; + +int iic_fsi_probe (struct device *dev); +int iic_fsi_remove (struct device *dev); + +struct iic_reg_access fsi_reg_access = +{ + .bus_readb = readb_wrap, + .bus_readh = readh_wrap, + .bus_readw = readw_wrap, + .bus_writeb = writeb_wrap, + .bus_writeh = writeh_wrap, + .bus_writew = writew_wrap, +}; + +static const struct fsi_device_id i2c_ids[] = { + { + .engine_type =FSI_ENGID_I2C , + .version =FSI_VERSION_ANY , + }, + { + .engine_type =FSI_ENGID_I2C_BB , + .version =FSI_VERSION_ANY , + }, + {0 } +}; + +static const struct fsi_driver i2c_drv = { + .id_table = i2c_ids, + .drv = { + .name ="iic_fsi_dd" , + .bus = &fsi_bus_type, + .probe = iic_fsi_probe, + .remove = iic_fsi_remove, + } +}; + +/* +* Called when an FSI IIC engine is plugged in. +* Causes creation of the /dev entry. +* Not allowed to access engine registers in this function. +* +*/ +int iic_fsi_probe (struct device *dev) +{ +return 0 ; +} + +/* This function is called when a link is removed or the driver is unloaded. +* It's job is to remove the device from the device hierarchy including +* removal from sysfs (this is where device files get removed). +*/ +int iic_fsi_remove (struct device * dev) +{ +return 0 ; +} + +/* +* Initialize this module. Creates a class for fsi connected iic devices and +* allocates device numbers for them. +*/ +static int __init iic_fsi_init (void ) +{ +int rc =0 ; + +IENTER (); + + rc =alloc_chrdev_region (&iic_devnum_start, +0 ,/*starting minor number*/ +IIC_FSI_MAX_DEVS , +"iic-fsi" ); +if (rc) + { +IFLDe (1 ,"master alloc_chrdev_region failed: rc = %d\n" , rc); +return rc; + } + + iic_fsi_class =class_create (THIS_MODULE ,"iic-fsi" ); +if (IS_ERR (iic_fsi_class)) + { +IFLDe (1 ,"class_create failed: rc=%ld" , +PTR_ERR (iic_fsi_class)); + goto exit_class_create; + } +/* Register this driver with the FSI infrastructure */ + rc =fsi_driver_register (&i2c_drv); +if (rc) + { +IFLDe (1 ,"fsidrv_register failed: %d" , rc); + goto exit_drv_register; + } + +printk ("IIC FSI support loaded, ver. %s\n" , iic_fsi_version); + +IEXIT (rc); +return rc; + +exit_drv_register: +class_destroy (iic_fsi_class); +exit_class_create: +unregister_chrdev_region (iic_devnum_start,IIC_FSI_MAX_DEVS ); +IEXIT (rc); +return rc; +} + +static void __exit iic_fsi_exit(void) +{ +IENTER (); +IDBGd (0 ,"fisdrv_unregister()\n" ); +fsi_driver_unregister (&i2c_drv); +IDBGd (0 ,"unregister_chrdev_region()\n" ); +unregister_chrdev_region (iic_devnum_start,IIC_FSI_MAX_DEVS ); +if (iic_fsi_class) + { +IDBGd (0 ,"class_destroy\n" ); +class_destroy (iic_fsi_class); + } +printk ("IIC FSI support unloaded.\n" ); +IEXIT (0 ); +} + +module_init (iic_fsi_init); +module_exit (iic_fsi_exit); + +MODULE_AUTHOR ("Eddie James <[email protected]>" ); +MODULE_DESCRIPTION ("IIC FSI Driver" ); +MODULE_LICENSE ("GPL" ); +drivers/fsi/i2c/iic-fsi.h new file +29
-0@@ -0,0 +1,29 @@ +/* +* Copyright (c) International Business Machines Corp., 2006 +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef IIC_FSI_H +#define IIC_FSI_H + +/* +* we don't know ahead of time how many minors will be needed as this is based +* on platform type and the possibility of sparsely populated FRU's on special +* systems so picking a safely large number +*/ +#define IIC_FSI_MAX_DEVS 1024 + +#endif drivers/fsi/i2c/iic-int.h new file +80
-0@@ -0,0 +1,80 @@ +/* +* Copyright (c) International Business Machines Corp., 2006, 2012 +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef IIC_INT_H +#define IIC_INT_H +#include <linux/list.h> +#include <linux/spinlock.h> +#include <linux/fs.h> +#include <linux/kobject.h> +#include <linux/cdev.h> +#include <linux/device.h> +#include <linux/kdev_t.h> +#include <linux/wait.h> +#include <linux/i2cfsi.h> +#include <linux/semaphore.h> +#include <linux/fsi.h> +#include <asm/atomic.h> + +#define FSI_ENGID_I2C 0x7 +#define FSI_ENGID_I2C_BB 0x17 + +#ifdef FSI_I2C_DEBUG +#define IDBGs(num, msg, args...) printk(msg, ## args) +#define IDBGd(num, msg, args...) printk(msg, ## args) +#define IDBGf(num, msg, args...) printk(msg, ## args) +#define IDBGl(num, msg, args...) printk(msg, ## args) +#else +#define IDBGs(num, msg, args...) +#define IDBGd(num, msg, args...) +#define IDBGf(num, msg, args...) +#define IDBGl(num, msg, args...) +#endif + +#define IENTER () +#define IEXIT (RC ) + +/* IFLDx traces will not get compiled out */ +#define IFLDe(num, msg, args...)\ + printk("ERR: "msg, ## args) +#define IFLDi(num, msg, args...)\ + printk(msg, ## args) + +#ifdef FSI_I2C_DEBUG +#define IFLDs(num, msg, args...) printk(msg, ## args) +#define IFLDd(num, msg, args...) printk(msg, ## args) +#define IFLDf(num, msg, args...) printk(msg, ## args) +#define IFLDl(num, msg, args...) printk(msg, ## args) +#else +#define IFLDs(num, msg, args...) +#define IFLDd(num, msg, args...) +#define IFLDf(num, msg, args...) +#define IFLDl(num, msg, args...) +#endif + +struct iic_reg_access +{ +int (*bus_readb)(iic_eng_t *,unsigned int ,unsigned char *,iic_ffdc_t **); +int (*bus_readh)(iic_eng_t *,unsigned int ,unsigned short *,iic_ffdc_t **); +int (*bus_readw)(iic_eng_t *,unsigned int ,unsigned long *,iic_ffdc_t **); +int (*bus_writeb)(iic_eng_t *,unsigned int ,unsigned char ,iic_ffdc_t **); +int (*bus_writeh)(iic_eng_t *,unsigned int ,unsigned short ,iic_ffdc_t **); +int (*bus_writew)(iic_eng_t *,unsigned int ,unsigned long ,iic_ffdc_t **); +}; + +#endif
PATCH 5/8 drivers: fsi: i2c: Add engine access wrappers
In reply to [email protected]From: "Edward A. James" <[email protected]>
--- drivers/fsi/i2c/iic-fsi.c | 84 +++++++++++++ drivers/fsi/i2c/iic-fsi.h | 87 +++++++++++++ drivers/fsi/i2c/iic-int.h | 315 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 486 insertions(+)
drivers/fsi/i2c/iic-fsi.c +84 -0
@@ -41,6 +41,90 @@ static const char iic_fsi_version[] = "3.0";int iic_fsi_probe (struct device *dev);int iic_fsi_remove (struct device *dev); +int readb_wrap (iic_eng_t * eng,unsigned int addr,unsigned char *val, +iic_ffdc_t ** ffdc) +{ +int rc; +struct fsi_device *fsi_dev =to_fsi_dev (eng->dev); + rc =fsi_device_read (fsi_dev, addr, val,1 ); +if (rc) + { +IFLDe (3 ,"eng[%08x]: fsi_readb_ffdc(%p)=%d\n" , eng->id, + addr, rc); + } +return rc; +}; + +int readh_wrap (iic_eng_t * eng,unsigned int addr,unsigned short *val, +iic_ffdc_t ** ffdc) +{ +int rc; +struct fsi_device *fsi_dev =to_fsi_dev (eng->dev); + rc =fsi_device_read (fsi_dev, addr, val,2 ); +if (rc) + { +IFLDe (3 ,"eng[%08x]: fsi_readh_ffdc(%p)=%d\n" , eng->id, + addr, rc); + } +return rc; +}; + +int readw_wrap (iic_eng_t * eng,unsigned int addr,unsigned long *val, +iic_ffdc_t ** ffdc) +{ +int rc; +struct fsi_device *fsi_dev =to_fsi_dev (eng->dev); + rc =fsi_device_read (fsi_dev, addr, val,4 ); +if (rc) + { +IFLDe (3 ,"eng[%08x]: fsi_readw_ffdc(%p)=%d\n" , eng->id, + addr, rc); + } +return rc; +}; + +int writeb_wrap (iic_eng_t * eng,unsigned int addr,unsigned char val, +iic_ffdc_t ** ffdc) +{ +int rc; +struct fsi_device *fsi_dev =to_fsi_dev (eng->dev); + rc =fsi_device_write (fsi_dev, addr, &val,1 ); +if (rc) + { +IFLDe (3 ,"eng[%08x]: fsi_writeb_ffdc(%p)=%d\n" , eng->id, + addr, rc); + } +return rc; +}; + +int writeh_wrap (iic_eng_t * eng,unsigned int addr,unsigned short val, +iic_ffdc_t ** ffdc) +{ +int rc; +struct fsi_device *fsi_dev =to_fsi_dev (eng->dev); + rc =fsi_device_write (fsi_dev, addr, &val,2 ); +if (rc) + { +IFLDe (3 ,"eng[%08x]: fsi_writeh_ffdc(%p)=%d\n" , eng->id, + addr, rc); + } +return rc; +}; + +int writew_wrap (iic_eng_t * eng,unsigned int addr,unsigned long val, +iic_ffdc_t ** ffdc) +{ +int rc; +struct fsi_device *fsi_dev =to_fsi_dev (eng->dev); + rc =fsi_device_write (fsi_dev, addr, &val,4 ); +if (rc) + { +IFLDe (3 ,"eng[%08x]: fsi_writew_ffdc(%p)=%d\n" , eng->id, + addr, rc); + } +return rc; +}; +struct iic_reg_access fsi_reg_access = { .bus_readb = readb_wrap,
drivers/fsi/i2c/iic-fsi.h +87 -0
97 lines not on this page · raw message
drivers/fsi/i2c/iic-int.h +315 -0
325 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 6/8 drivers: fsi: i2c: probe fsi device for i2c client
In reply to [email protected]From: "Edward A. James" <[email protected]>
--- drivers/fsi/i2c/Makefile | 2 +- drivers/fsi/i2c/iic-fsi.c | 464 ++++++++++++++++++++++++++++++++++++++++++++- drivers/fsi/i2c/iic-mstr.c | 429 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 893 insertions(+), 2 deletions(-) create mode 100644 drivers/fsi/i2c/iic-mstr.c
drivers/fsi/i2c/Makefile +1 -1
@@ -1 +1 @@ -obj-$(CONFIG_FSI_I2C) += iic-fsi.o +obj-$(CONFIG_FSI_I2C) += iic-fsi.o iic-mstr.o
drivers/fsi/i2c/iic-fsi.c +463 -1
491 lines not on this page · raw message
drivers/fsi/i2c/iic-mstr.c new file +429 -0
429 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 7/8 drivers: fsi: i2c: add driver file operations and bus locking
In reply to [email protected]From: "Edward A. James" <[email protected]>
--- drivers/fsi/i2c/Makefile | 2 +- drivers/fsi/i2c/iic-lock.c | 439 +++++++++++ drivers/fsi/i2c/iic-mstr.c | 1834 +++++++++++++++++++++++++++++++++++++++++++ include/uapi/linux/Kbuild | 1 + include/uapi/linux/i2cfsi.h | 136 ++++ 5 files changed, 2411 insertions(+), 1 deletion(-) create mode 100644 drivers/fsi/i2c/iic-lock.c create mode 100644 include/uapi/linux/i2cfsi.h
drivers/fsi/i2c/Makefile +1 -1
@@ -1 +1 @@ -obj-$(CONFIG_FSI_I2C) += iic-fsi.o iic-mstr.o +obj-$(CONFIG_FSI_I2C) += iic-fsi.o iic-mstr.o iic-lock.o
drivers/fsi/i2c/iic-lock.c new file +439 -0
439 lines not on this page · raw message
drivers/fsi/i2c/iic-mstr.c +1834 -0
1,856 lines not on this page · raw message
include/uapi/linux/Kbuild +1 -0
@@ -155,6 +155,7 @@ header-y += hyperv.h header-y += hysdn_if.h header-y += i2c-dev.h header-y += i2c.h +header-y += i2cfsi.h header-y += i2o-dev.h header-y += i8k.h header-y += icmp.h
include/uapi/linux/i2cfsi.h new file +136 -0
136 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 8/8 drivers: fsi: i2c: boe engine
In reply to [email protected]From: "Edward A. James" <[email protected]>
--- drivers/fsi/i2c/Makefile | 2 +- drivers/fsi/i2c/iic-boe.c | 1597 +++++++++++++++++++++++++++++++++++++++++++++ drivers/fsi/i2c/iic-boe.h | 180 +++++ 3 files changed, 1778 insertions(+), 1 deletion(-) create mode 100644 drivers/fsi/i2c/iic-boe.c create mode 100644 drivers/fsi/i2c/iic-boe.h
drivers/fsi/i2c/Makefile +1 -1
@@ -1 +1 @@ -obj-$(CONFIG_FSI_I2C) += iic-fsi.o iic-mstr.o iic-lock.o +obj-$(CONFIG_FSI_I2C) += iic-fsi.o iic-mstr.o iic-lock.o iic-boe.o
drivers/fsi/i2c/iic-boe.c new file +1597 -0
1,597 lines not on this page · raw message
drivers/fsi/i2c/iic-boe.h new file +180 -0
180 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 1/3 drivers/fsi: Add slave interrupt polling
In reply to [email protected]From: Christopher Bostic <[email protected]>
Scan slaves present for asserting interrupt signals in the si1s register and call a registered client's interrupt handler as appropriate.
--- drivers/fsi/fsi-core.c | 99 +++++++++++++++++++++++++++++++++++++++++++ drivers/fsi/fsi-master-gpio.c | 1 + drivers/fsi/fsi-master.h | 2 + include/linux/fsi.h | 5 +++ 4 files changed, 107 insertions(+)
drivers/fsi/fsi-core.c +99 -0
@@ -15,11 +15,15 @@#include <linux/device.h> #include <linux/fsi.h> +#include <linux/kthread.h> #include <linux/module.h> #include <linux/slab.h> +#include <linux/jiffies.h> #include "fsi-master.h" +#define DEBUG +#define FSI_N_SLAVES 4#define FSI_SLAVE_CONF_NEXT_MASK 0x80000000
@@ -36,7 +40,11 @@#define FSI_PEEK_BASE 0x410#define FSI_SLAVE_BASE 0x800 +#define FSI_IPOLL_PERIOD msecs_to_jiffies(fsi_ipoll_period_ms) +static const int engine_page_size =0x400 ; +static struct task_struct *master_ipoll; +static unsigned int fsi_ipoll_period_ms =100 ;static atomic_t master_idx =ATOMIC_INIT (-1 );
@@ -60,6 +68,8 @@ static int fsi_slave_write(struct fsi_slave *slave, uint32_t addr,* FSI slave engine control register offsets */ #define FSI_SMODE 0x0/* R/W: Mode register */ +#define FSI_SI1M 0x18/* R/W: IRQ mask */ +#define FSI_SI1S 0x1C/* R: IRQ status */ /* * SMODE fields
@@ -197,6 +207,7 @@ static int fsi_slave_scan(struct fsi_slave *slave)uint32_t engine_addr;uint32_t conf;int rc, i; +uint8_t si1s_bit =1 ;INIT_LIST_HEAD (&slave->my_engines);
@@ -253,6 +264,7 @@ static int fsi_slave_scan(struct fsi_slave *slave) dev->unit = i; dev->addr = engine_addr; dev->size = slots * engine_page_size; + dev->si1s_bit = si1s_bit++; dev_info(&slave->dev, "engine[%i]: type %x, version %x, addr %x size %x\n",
@@ -507,6 +519,56 @@ static void fsi_master_unscan(struct fsi_master *master) master->slave_list = false; } +static void fsi_master_irq (struct fsi_master *master,int link,uint32_t si1s) +{ +struct fsi_slave *slave; +struct fsi_device *fsi_dev; + +if (list_empty (&master->my_slaves)) +return ; + + slave = list_first_entry(&master->my_slaves, struct fsi_slave, + list_link); + +list_for_each_entry (fsi_dev, &slave->my_engines, link) { +if (si1s & (0x80000000 >> fsi_dev->si1s_bit) && + fsi_dev->irq_handler) + fsi_dev->irq_handler (0 , &fsi_dev->dev); + } +} + +static int fsi_master_ipoll (void *data) +{ +int rc; +uint32_t si1s; +unsigned long elapsed =0 ; +unsigned long previous_jiffies = jiffies; +struct fsi_master *master = data; + +while (!kthread_should_stop ()) { +if (!master->ipoll) + goto done; + +/* Ignore errors for now */ + rc = master->read (master,0 ,0 ,FSI_SLAVE_BASE +FSI_SI1S , + &si1s,sizeof (uint32_t )); +if (rc) + goto done; + +if (si1s & master->ipoll) +fsi_master_irq (master,0 , si1s); +done: + elapsed = jiffies - previous_jiffies; +if (elapsed <FSI_IPOLL_PERIOD ) { +set_current_state (TASK_UNINTERRUPTIBLE ); +schedule_timeout (FSI_IPOLL_PERIOD - elapsed); + } + previous_jiffies = jiffies; + } + +return 0 ; +} +int fsi_master_register (struct fsi_master *master) {if (!master || !master->dev)
@@ -524,9 +586,36 @@ void fsi_master_unregister(struct fsi_master *master) {fsi_master_unscan (master);put_device (master->dev); +if (master_ipoll) { +kthread_stop (master_ipoll); + master_ipoll =NULL ; + } }EXPORT_SYMBOL_GPL (fsi_master_unregister); +/* +* TODO: move this to master->start_ipoll( ) -each master may have its +* own way of doing this +*/ +int fsi_master_start_ipoll (struct fsi_master *master) +{ +if (master_ipoll) { +dev_err (master->dev,"Already polling for irqs\n" ); +return -EALREADY ; + } + master_ipoll =kthread_create (fsi_master_ipoll, master, +"fsi_master_ipoll" ); +if (IS_ERR (master_ipoll)) { +dev_err (master->dev,"Couldn't create ipoll thread rc:%d\n" , + (int )PTR_ERR (master_ipoll)); +return PTR_ERR (master_ipoll); + } +wake_up_process (master_ipoll); + +return 0 ; +} +EXPORT_SYMBOL_GPL (fsi_master_start_ipoll); +/* FSI core & Linux bus type definitions */ static int fsi_bus_match (struct device *dev,struct device_driver *drv)
@@ -566,6 +655,16 @@ void fsi_driver_unregister(struct fsi_driver *fsi_drv) }EXPORT_SYMBOL_GPL (fsi_driver_unregister); +int fsi_enable_irq (struct fsi_device *dev) +{ +return 0 ; +} +EXPORT_SYMBOL_GPL (fsi_enable_irq); + +void fsi_disable_irq (struct fsi_device *dev) +{ +} +struct bus_type fsi_bus_type = { .name ="fsi" , .match = fsi_bus_match,
drivers/fsi/fsi-master-gpio.c +1 -0
@@ -457,6 +457,7 @@ static ssize_t store_scan(struct device *dev,/* clear out any old scan data if present */ fsi_master_unregister (&master->master);fsi_master_register (&master->master); +fsi_master_start_ipoll (&master->master);return count; }
drivers/fsi/fsi-master.h +2 -0
@@ -25,6 +25,7 @@ struct fsi_master {struct device *dev;int idx;int n_links; +uint32_t ipoll;int (*read)(struct fsi_master *,int link,uint8_t slave,uint32_t addr,void *val,size_t size);
@@ -37,6 +38,7 @@ struct fsi_master {extern int fsi_master_register (struct fsi_master *master);extern void fsi_master_unregister (struct fsi_master *master); +extern int fsi_master_start_ipoll (struct fsi_master *master);/** * crc4 helper: Given a starting crc4 state @c, calculate the crc4 vaue of @x,
include/linux/fsi.h +5 -0
@@ -23,9 +23,11 @@ struct fsi_device {u8 engine_type;u8 version;u8 unit; +u8 si1s_bit;struct fsi_slave *slave;uint32_t addr;uint32_t size; +int (*irq_handler)(int ,void *); }; extern int fsi_device_read(struct fsi_device *dev, uint32_t addr,
@@ -69,4 +71,7 @@ extern void fsi_driver_unregister(struct fsi_driver *);extern struct bus_type fsi_bus_type; +extern int fsi_enable_irq (struct fsi_device *dev); +extern void fsi_disable_irq (struct fsi_device *dev); +#endif /* LINUX_FSI_H */
Signature · 1 line
1.8.2.2
Re: [PATCH v2 1/3] drivers/fsi: Add slave interrupt polling
Hi Edward,
Ideally this should also make use of as much existing kernel infrastructure as possible to avoid remiplementing interfaces that already exist. In the case of IRQs the kernel already has functions implementing interfaces like request_irq() to assign interrupt handlers, etc.
To hook into these calls you need to implement an irqchip. For example arch/powerpc/platforms/powernv/opal-irqchip.c has a resonable example, although there are plenty others in the kernel including for I2C busses. Searching for "struct irq_chip" should turn up more examples.
Regards,
Alistair
Quoted 240 lines · On Thu, 2 Feb 2017 05:26:02 PM [email protected] wrote:
From: Christopher Bostic <[email protected]>
Scan slaves present for asserting interrupt signals in the si1s register and call a registered client's interrupt handler as appropriate.
Signed-off-by Eddie James <[email protected]>Signed-off-by Christopher Bostic <[email protected]>--- drivers/fsi/fsi-core.c | 99 +++++++++++++++++++++++++++++++++++++++++++ drivers/fsi/fsi-master-gpio.c | 1 + drivers/fsi/fsi-master.h | 2 + include/linux/fsi.h | 5 +++ 4 files changed, 107 insertions(+)drivers/fsi/fsi-core.c +99
-0@@ -15,11 +15,15 @@#include <linux/device.h> #include <linux/fsi.h> +#include <linux/kthread.h> #include <linux/module.h> #include <linux/slab.h> +#include <linux/jiffies.h> #include "fsi-master.h" +#define DEBUG +#define FSI_N_SLAVES 4#define FSI_SLAVE_CONF_NEXT_MASK 0x80000000@@ -36,7 +40,11 @@#define FSI_PEEK_BASE 0x410#define FSI_SLAVE_BASE 0x800 +#define FSI_IPOLL_PERIOD msecs_to_jiffies(fsi_ipoll_period_ms) +static const int engine_page_size =0x400 ; +static struct task_struct *master_ipoll; +static unsigned int fsi_ipoll_period_ms =100 ;static atomic_t master_idx =ATOMIC_INIT (-1 );@@ -60,6 +68,8 @@ static int fsi_slave_write(struct fsi_slave *slave, uint32_t addr,* FSI slave engine control register offsets */ #define FSI_SMODE 0x0/* R/W: Mode register */ +#define FSI_SI1M 0x18/* R/W: IRQ mask */ +#define FSI_SI1S 0x1C/* R: IRQ status */ /* * SMODE fields @@ -197,6 +207,7 @@ static int fsi_slave_scan(struct fsi_slave *slave)uint32_t engine_addr;uint32_t conf;int rc, i; +uint8_t si1s_bit =1 ;INIT_LIST_HEAD (&slave->my_engines);@@ -253,6 +264,7 @@ static int fsi_slave_scan(struct fsi_slave *slave) dev->unit = i; dev->addr = engine_addr; dev->size = slots * engine_page_size; + dev->si1s_bit = si1s_bit++; dev_info(&slave->dev, "engine[%i]: type %x, version %x, addr %x size %x\n",@@ -507,6 +519,56 @@ static void fsi_master_unscan(struct fsi_master *master) master->slave_list = false; } +static void fsi_master_irq (struct fsi_master *master,int link,uint32_t si1s) +{ +struct fsi_slave *slave; +struct fsi_device *fsi_dev; + +if (list_empty (&master->my_slaves)) +return ; + + slave = list_first_entry(&master->my_slaves, struct fsi_slave, + list_link); + +list_for_each_entry (fsi_dev, &slave->my_engines, link) { +if (si1s & (0x80000000 >> fsi_dev->si1s_bit) && + fsi_dev->irq_handler) + fsi_dev->irq_handler (0 , &fsi_dev->dev); + } +} + +static int fsi_master_ipoll (void *data) +{ +int rc; +uint32_t si1s; +unsigned long elapsed =0 ; +unsigned long previous_jiffies = jiffies; +struct fsi_master *master = data; + +while (!kthread_should_stop ()) { +if (!master->ipoll) + goto done; + +/* Ignore errors for now */ + rc = master->read (master,0 ,0 ,FSI_SLAVE_BASE +FSI_SI1S , + &si1s,sizeof (uint32_t )); +if (rc) + goto done; + +if (si1s & master->ipoll) +fsi_master_irq (master,0 , si1s); +done: + elapsed = jiffies - previous_jiffies; +if (elapsed <FSI_IPOLL_PERIOD ) { +set_current_state (TASK_UNINTERRUPTIBLE ); +schedule_timeout (FSI_IPOLL_PERIOD - elapsed); + } + previous_jiffies = jiffies; + } + +return 0 ; +} +int fsi_master_register (struct fsi_master *master) {if (!master || !master->dev)@@ -524,9 +586,36 @@ void fsi_master_unregister(struct fsi_master *master) {fsi_master_unscan (master);put_device (master->dev); +if (master_ipoll) { +kthread_stop (master_ipoll); + master_ipoll =NULL ; + } }EXPORT_SYMBOL_GPL (fsi_master_unregister); +/* +* TODO: move this to master->start_ipoll( ) -each master may have its +* own way of doing this +*/ +int fsi_master_start_ipoll (struct fsi_master *master) +{ +if (master_ipoll) { +dev_err (master->dev,"Already polling for irqs\n" ); +return -EALREADY ; + } + master_ipoll =kthread_create (fsi_master_ipoll, master, +"fsi_master_ipoll" ); +if (IS_ERR (master_ipoll)) { +dev_err (master->dev,"Couldn't create ipoll thread rc:%d\n" , + (int )PTR_ERR (master_ipoll)); +return PTR_ERR (master_ipoll); + } +wake_up_process (master_ipoll); + +return 0 ; +} +EXPORT_SYMBOL_GPL (fsi_master_start_ipoll); +/* FSI core & Linux bus type definitions */ static int fsi_bus_match (struct device *dev,struct device_driver *drv)@@ -566,6 +655,16 @@ void fsi_driver_unregister(struct fsi_driver *fsi_drv) }EXPORT_SYMBOL_GPL (fsi_driver_unregister); +int fsi_enable_irq (struct fsi_device *dev) +{ +return 0 ; +} +EXPORT_SYMBOL_GPL (fsi_enable_irq); + +void fsi_disable_irq (struct fsi_device *dev) +{ +} +struct bus_type fsi_bus_type = { .name ="fsi" , .match = fsi_bus_match,drivers/fsi/fsi-master-gpio.c +1
-0@@ -457,6 +457,7 @@ static ssize_t store_scan(struct device *dev,/* clear out any old scan data if present */ fsi_master_unregister (&master->master);fsi_master_register (&master->master); +fsi_master_start_ipoll (&master->master);return count; }drivers/fsi/fsi-master.h +2
-0@@ -25,6 +25,7 @@ struct fsi_master {struct device *dev;int idx;int n_links; +uint32_t ipoll;int (*read)(struct fsi_master *,int link,uint8_t slave,uint32_t addr,void *val,size_t size);@@ -37,6 +38,7 @@ struct fsi_master {extern int fsi_master_register (struct fsi_master *master);extern void fsi_master_unregister (struct fsi_master *master); +extern int fsi_master_start_ipoll (struct fsi_master *master);/** * crc4 helper: Given a starting crc4 state @c, calculate the crc4 vaue of @x, include/linux/fsi.h +5
-0@@ -23,9 +23,11 @@ struct fsi_device {u8 engine_type;u8 version;u8 unit; +u8 si1s_bit;struct fsi_slave *slave;uint32_t addr;uint32_t size; +int (*irq_handler)(int ,void *); }; extern int fsi_device_read(struct fsi_device *dev, uint32_t addr,@@ -69,4 +71,7 @@ extern void fsi_driver_unregister(struct fsi_driver *);extern struct bus_type fsi_bus_type; +extern int fsi_enable_irq (struct fsi_device *dev); +extern void fsi_disable_irq (struct fsi_device *dev); +#endif /* LINUX_FSI_H */
Re: [PATCH v2 1/3] drivers/fsi: Add slave interrupt polling
Quoted 7 lines · Alistair Popple
Hi Edward,
Ideally this should also make use of as much existing kernel infrastructure as possible to avoid remiplementing interfaces that already exist. In the case of IRQs the kernel already has functions implementing interfaces like
request_irq()to assign interrupt handlers, etc.
Hi,
The problem here is that there is no hardware irq. FSI is using GPIO lines to access slave registers. The only indication that we have an interrupt is a bit set in the "slave interrupt status register". So we have to poll that register and handle the results. I'm not aware of any way to turn that into a kernel irq and use the existing kernel framework. But if it can be done, agreed, we should implement that!
Thanks,
Eddie
Quoted 261 lines
To hook into these calls you need to implement an irqchip. For example
arch/powerpc/platforms/powernv/opal-irqchip.chas a resonable example, although there are plenty others in the kernel including for I2C busses. Searching for "structirq_chip" should turn up more examples.Regards,
Alistair
Quoted 250 lines · On Thu, 2 Feb 2017 05:26:02 PM [email protected] wrote:
From: Christopher Bostic <[email protected]>
Scan slaves present for asserting interrupt signals in the si1s register and call a registered client's interrupt handler as appropriate.
Signed-off-by Eddie James <[email protected]>Signed-off-by Christopher Bostic <[email protected]>--- drivers/fsi/fsi-core.c | 99 +++++++++++++++++++++++++++++++++++++++++++ drivers/fsi/fsi-master-gpio.c | 1 + drivers/fsi/fsi-master.h | 2 + include/linux/fsi.h | 5 +++ 4 files changed, 107 insertions(+)drivers/fsi/fsi-core.c +10
-0@@ -15,11 +15,15 @@#include <linux/device.h> #include <linux/fsi.h> +#include <linux/kthread.h> #include <linux/module.h> #include <linux/slab.h> +#include <linux/jiffies.h> #include "fsi-master.h" +#define DEBUG +#define FSI_N_SLAVES 4#define FSI_SLAVE_CONF_NEXT_MASK 0x80000000@@ -36,7 +40,11 @@#define FSI_PEEK_BASE 0x410#define FSI_SLAVE_BASE 0x800 +#define FSI_IPOLL_PERIOD msecs_to_jiffies(fsi_ipoll_period_ms) +static const int engine_page_size =0x400 ; +static struct task_struct *master_ipoll; +static unsigned int fsi_ipoll_period_ms =100 ;static atomic_t master_idx =ATOMIC_INIT (-1 );@@ -60,6 +68,8 @@ static int fsi_slave_write(struct fsi_slave *slave,uint32_t addr, * FSI slave engine control register offsets */ #define FSI_SMODE 0x0/* R/W: Mode register */ +#define FSI_SI1M 0x18/* R/W: IRQ mask */ +#define FSI_SI1S 0x1C/* R: IRQ status */ /* * SMODE fields
drivers/fsi/fsi-core.c +52
-0@@ -197,6 +207,7 @@ static int fsi_slave_scan(struct fsi_slave *slave)uint32_t engine_addr;uint32_t conf;int rc, i; +uint8_t si1s_bit =1 ;INIT_LIST_HEAD (&slave->my_engines);@@ -253,6 +264,7 @@ static int fsi_slave_scan(struct fsi_slave *slave) dev->unit = i; dev->addr = engine_addr; dev->size = slots * engine_page_size; + dev->si1s_bit = si1s_bit++; dev_info(&slave->dev, "engine[%i]: type %x, version %x, addr %x size %x\n",@@ -507,6 +519,56 @@ static void fsi_master_unscan(struct fsi_master *master) master->slave_list = false; } +static void fsi_master_irq (struct fsi_master *master,int link,uint32_t si1s) +{ +struct fsi_slave *slave; +struct fsi_device *fsi_dev; + +if (list_empty (&master->my_slaves)) +return ; + + slave = list_first_entry(&master->my_slaves, struct fsi_slave, + list_link); + +list_for_each_entry (fsi_dev, &slave->my_engines, link) { +if (si1s & (0x80000000 >> fsi_dev->si1s_bit) && + fsi_dev->irq_handler) + fsi_dev->irq_handler (0 , &fsi_dev->dev); + } +} + +static int fsi_master_ipoll (void *data) +{ +int rc; +uint32_t si1s; +unsigned long elapsed =0 ; +unsigned long previous_jiffies = jiffies; +struct fsi_master *master = data; + +while (!kthread_should_stop ()) { +if (!master->ipoll) + goto done; + +/* Ignore errors for now */ + rc = master->read (master,0 ,0 ,FSI_SLAVE_BASE +FSI_SI1S , + &si1s,sizeof (uint32_t )); +if (rc) + goto done; + +if (si1s & master->ipoll) +fsi_master_irq (master,0 , si1s); +done: + elapsed = jiffies - previous_jiffies; +if (elapsed <FSI_IPOLL_PERIOD ) { +set_current_state (TASK_UNINTERRUPTIBLE ); +schedule_timeout (FSI_IPOLL_PERIOD - elapsed); + } + previous_jiffies = jiffies; + } + +return 0 ; +} +int fsi_master_register (struct fsi_master *master){
drivers/fsi/fsi-core.c +6
-0if (!master || !master->dev)@@ -524,9 +586,36 @@ void fsi_master_unregister(struct fsi_master *master) {fsi_master_unscan (master);put_device (master->dev); +if (master_ipoll) { +kthread_stop (master_ipoll); + master_ipoll =NULL ; + } }EXPORT_SYMBOL_GPL (fsi_master_unregister); +/* +* TODO: move this to master->start_ipoll( ) -each master may have its
+ * own way of doing this
+ */drivers/fsi/fsi-core.c +19
-0+int fsi_master_start_ipoll (struct fsi_master *master) +{ +if (master_ipoll) { +dev_err (master->dev,"Already polling for irqs\n" ); +return -EALREADY ; + } + master_ipoll =kthread_create (fsi_master_ipoll, master, +"fsi_master_ipoll" ); +if (IS_ERR (master_ipoll)) { +dev_err (master->dev,"Couldn't create ipoll thread rc:%d\n" , + (int )PTR_ERR (master_ipoll)); +return PTR_ERR (master_ipoll); + } +wake_up_process (master_ipoll); + +return 0 ; +} +EXPORT_SYMBOL_GPL (fsi_master_start_ipoll); +/* FSI core & Linux bus type definitions */ static int fsi_bus_match(struct device *dev, struct device_driver*drv)
drivers/fsi/fsi-core.c +10
-0@@ -566,6 +655,16 @@ void fsi_driver_unregister(struct fsi_driver *fsi_drv) }EXPORT_SYMBOL_GPL (fsi_driver_unregister); +int fsi_enable_irq (struct fsi_device *dev) +{ +return 0 ; +} +EXPORT_SYMBOL_GPL (fsi_enable_irq); + +void fsi_disable_irq (struct fsi_device *dev) +{ +} +struct bus_type fsi_bus_type = { .name ="fsi" ,drivers/fsi/fsi-core.c +0
-0.match = fsi_bus_match,drivers/fsi/fsi-master-gpio.c +1
-0@@ -457,6 +457,7 @@ static ssize_t store_scan(struct device *dev,/* clear out any old scan data if present */ fsi_master_unregister (&master->master);fsi_master_register (&master->master); +fsi_master_start_ipoll (&master->master);return count; }drivers/fsi/fsi-master.h +2
-0@@ -25,6 +25,7 @@ struct fsi_master {struct device *dev;int idx;int n_links; +uint32_t ipoll;int (*read)(struct fsi_master *,int link,uint8_t slave,uint32_t addr,void *val,size_t size);@@ -37,6 +38,7 @@ struct fsi_master {extern int fsi_master_register (struct fsi_master *master);extern void fsi_master_unregister (struct fsi_master *master); +extern int fsi_master_start_ipoll (struct fsi_master *master);/** * crc4 helper: Given a starting crc4 state @c, calculate the crc4 vaue of @x,
include/linux/fsi.h +5
-0@@ -23,9 +23,11 @@ struct fsi_device {u8 engine_type;u8 version;u8 unit; +u8 si1s_bit;struct fsi_slave *slave;uint32_t addr;uint32_t size; +int (*irq_handler)(int ,void *); }; extern int fsi_device_read(struct fsi_device *dev, uint32_t addr,@@ -69,4 +71,7 @@ extern void fsi_driver_unregister(struct fsi_driver *);extern struct bus_type fsi_bus_type; +extern int fsi_enable_irq (struct fsi_device *dev); +extern void fsi_disable_irq (struct fsi_device *dev); +#endif /*
LINUX_FSI_H*/
Re: [PATCH v2 1/3] drivers/fsi: Add slave interrupt polling
Quoted 8 lines · eajames
The problem here is that there is no hardware irq. FSI is using GPIO lines to access slave registers. The only indication that we have an interrupt is a bit set in the "slave interrupt status register". So we
have to poll that register and handle the results. I'm not aware of any
way to turn that into a kernel irq and use the existing kernel framework. But if it can be done, agreed, we should implement that!
The existing kernel i2c framework doesn't require IRQs.
You can poll, which sucks, but you can. With delays of course.
Also, if you know your i2c bit freq, you can always use a timer.
Cheers,
Ben.
PATCH v2 2/3 drivers/fsi: Add Client IRQ Enable / Disable
In reply to [email protected]From: Christopher Bostic <[email protected]>
Allow FSI client drivers to enable and disable their engine IRQ's via the exported interfaces fsi_enable_irq and fsi_disable_irq
--- drivers/fsi/fsi-core.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)
drivers/fsi/fsi-core.c +45 -0
@@ -657,12 +657,57 @@ EXPORT_SYMBOL_GPL(fsi_driver_unregister);int fsi_enable_irq (struct fsi_device *dev) { +int rc; +u32 si1m; +u32 bit =0x80000000 >> dev->si1s_bit; +struct fsi_master *master = dev->slave->master; + +if (!dev->irq_handler) +return -EINVAL ; + + rc = master->read (master,0 ,0 ,FSI_SLAVE_BASE +FSI_SI1M , &si1m, +sizeof (u32)); +if (rc) { +dev_err (master->dev,"couldn't read si1m:%d\n" , rc); +return rc; + } + + si1m |= bit; + rc = master->write (master,0 ,0 ,FSI_SLAVE_BASE +FSI_SI1M , &si1m, +sizeof (u32)); +if (rc) { +dev_err (master->dev,"couldn't write si1m:%d\n" , rc); +return rc; + } + + master->ipoll |= bit;return 0 ; }EXPORT_SYMBOL_GPL (fsi_enable_irq);void fsi_disable_irq (struct fsi_device *dev) { +int rc; +u32 si1m; +u32 bits = ~(0x80000000 >> dev->si1s_bit); +struct fsi_master *master = dev->slave->master; + + master->ipoll &= bits; + + rc = master->read (master,0 ,0 ,FSI_SLAVE_BASE +FSI_SI1M , &si1m, +sizeof (u32)); +if (rc) { +dev_err (master->dev,"couldn't read si1m:%d\n" , rc); +return ; + } + + si1m &= bits; + rc = master->write (master,0 ,0 ,FSI_SLAVE_BASE +FSI_SI1M , &si1m, +sizeof (u32)); +if (rc) { +dev_err (master->dev,"couldn't write si1m:%d\n" , rc); +return ; + } }struct bus_type fsi_bus_type = {
Signature · 1 line
1.8.2.2
PATCH v2 3/3 drivers/fsi: Add sysfs file to adjust i-poll period
In reply to [email protected]From: Christopher Bostic <[email protected]>
Create a sysfs file that can read and modify the period for interrupt polling of connected CFAMs.
--- drivers/fsi/fsi-core.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
drivers/fsi/fsi-core.c +26 -0
@@ -569,6 +569,30 @@ done:return 0 ; } +static ssize_t fsi_ipoll_period_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +return snprintf (buf,PAGE_SIZE -1 ,"%u\n" , fsi_ipoll_period_ms); +} + +static ssize_t fsi_ipoll_period_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +int rc; +unsigned long val =0 ; + + rc =kstrtoul (buf,0 , &val); + +if (val >1 && val <10000 ) + fsi_ipoll_period_ms = val; + +return count; +} + +DEVICE_ATTR (fsi_ipoll_period,S_IRUGO |S_IWUSR , fsi_ipoll_period_show, + fsi_ipoll_period_store); +int fsi_master_register (struct fsi_master *master) {if (!master || !master->dev)
@@ -578,12 +602,14 @@ int fsi_master_register(struct fsi_master *master) master->slave_list = false;get_device (master->dev);fsi_master_scan (master); +device_create_file (master->dev, &dev_attr_fsi_ipoll_period);return 0 ; }EXPORT_SYMBOL_GPL (fsi_master_register);void fsi_master_unregister (struct fsi_master *master) { +device_remove_file (master->dev, &dev_attr_fsi_ipoll_period);fsi_master_unscan (master);put_device (master->dev);if (master_ipoll) {
Signature · 1 line
1.8.2.2
Quoted 15 lines · On Fri, Feb 3, 2017 at 9:55 AM, <[email protected]> wrote:
From: "Edward A. James" <[email protected]>
First, this series add interrupt polling support to the FSI bus driver. This implements a loop that constantly polls the FSI slave interrupt status register and triggers any registered client interrupt handlers upon detecting an interrupt.
Secondly, this series adds the I2C client driver for FSI bus. This driver interacts with the IBM BOE engine on an FSI slave device.
Christopher Bostic (3):
drivers/fsi: Add slave interrupt pollingdrivers/fsi: Add Client IRQ Enable / Disabledrivers/fsi: Add sysfs file to adjust i-poll period
Quoted 6 lines
Edward A. James (5):
drivers: fsi: Add i2c client driver
drivers: fsi: i2c: Add engine access wrappers
drivers: fsi: i2c: probe fsi device for i2c client
drivers: fsi: i2c: add driver file operations and bus locking
drivers: fsi: i2c: boe engine
This series was a bit of a mess. The second 5 patches all had trailing whitespace. They didn't build cleanly. These patches had different subject prefxies too. You can generate the subject line like this:
git format-patch --subject-prefix "PATCH linux dev-4.7" and it will spit out patch files with the same subject prefix on all patches.
If you're doing v2, you can do:
git format-patch -v 2 --subject-prefix "PATCH linux dev-4.7" and it will add the v2 or v3 or v100 to your subject line.
The full incarnation might look like this:
git format-patch -v 2 --subject-prefix "PATCH linux dev-4.7" [email protected] [email protected] origin/dev-4.7 -o fsi-patches-v2
And then once you've edited the cover letter, I do this:
git send-email fsi-patches-v2/*
I fixed the mess this time, but please make sure you're sending patches that cleanly apply and don't introduce warnings next time.
Cheers,
Joel
Quoted 29 lines
drivers/fsi/Kconfig | 6 + drivers/fsi/Makefile | 1 + drivers/fsi/fsi-core.c | 170 +++ drivers/fsi/fsi-master-gpio.c | 1 + drivers/fsi/fsi-master.h | 2 + drivers/fsi/i2c/Makefile | 1 + drivers/fsi/i2c/iic-boe.c | 1597 +++++++++++++++++++++++++++++ drivers/fsi/i2c/iic-boe.h | 180 ++++ drivers/fsi/i2c/iic-fsi.c | 715 +++++++++++++ drivers/fsi/i2c/iic-int.h | 395 +++++++ drivers/fsi/i2c/iic-lock.c | 439 ++++++++ drivers/fsi/i2c/iic-mstr.c | 2281 +++++++++++++++++++++++++++++++++++++++++ include/linux/fsi.h | 5 + include/uapi/linux/Kbuild | 1 + include/uapi/linux/i2cfsi.h | 136 +++ 15 files changed, 5930 insertions(+) create mode 100644 drivers/fsi/i2c/Makefile create mode 100644 drivers/fsi/i2c/iic-boe.c create mode 100644 drivers/fsi/i2c/iic-boe.h create mode 100644 drivers/fsi/i2c/iic-fsi.c create mode 100644 drivers/fsi/i2c/iic-int.h create mode 100644 drivers/fsi/i2c/iic-lock.c create mode 100644 drivers/fsi/i2c/iic-mstr.c create mode 100644 include/uapi/linux/i2cfsi.h--
1.8.3.1
Quoted 43 lines · Joel Stanley
Quoted 15 lines · On Fri, Feb 3, 2017 at 9:55 AM, <[email protected]> wrote:
From: "Edward A. James" <[email protected]>
First, this series add interrupt polling support to the FSI bus driver. This implements a loop that constantly polls the FSI slave interrupt status register and triggers any registered client interrupt handlers upon detecting an interrupt.
Secondly, this series adds the I2C client driver for FSI bus. This driver interacts with the IBM BOE engine on an FSI slave device.
Christopher Bostic (3):
drivers/fsi: Add slave interrupt pollingdrivers/fsi: Add Client IRQ Enable / Disabledrivers/fsi: Add sysfs file to adjust i-poll periodQuoted 6 lines
Edward A. James (5):
drivers: fsi: Add i2c client driver
drivers: fsi: i2c: Add engine access wrappers
drivers: fsi: i2c: probe fsi device for i2c client
drivers: fsi: i2c: add driver file operations and bus locking
drivers: fsi: i2c: boe engineThis series was a bit of a mess. The second 5 patches all had trailing whitespace. They didn't build cleanly. These patches had different subject prefxies too. You can generate the subject line like this:
git format-patch --subject-prefix "PATCH linux dev-4.7" and it will spit out patch files with the same subject prefix on all patches.
If you're doing v2, you can do:
git format-patch -v 2 --subject-prefix "PATCH linux dev-4.7" and it will add the v2 or v3 or v100 to your subject line.
The full incarnation might look like this:
git format-patch -v 2 --subject-prefix "PATCH linux dev-4.7" [email protected] [email protected] origin/dev-4.7 -o fsi-patches-v2
And then once you've edited the cover letter, I do this:
Quoted 8 lines
git send-email fsi-patches-v2/*
I fixed the mess this time, but please make sure you're sending patches that cleanly apply and don't introduce warnings next time.
Cheers,
Joel
Thanks Joel, my apologies for the dirty patch set. I spent no effort cleaning anything up from the FSP code since this is a temporary measure. As for the subject prefixes, Chris generated the first three and I generated the last 5, so I didn't realize they had different subjects before I sent them out. Won't happen again. Looking forward to working on the new i2c driver.
Thanks,
Eddie
Quoted 31 lines
Quoted 31 lines
drivers/fsi/Kconfig | 6 + drivers/fsi/Makefile | 1 + drivers/fsi/fsi-core.c | 170 +++ drivers/fsi/fsi-master-gpio.c | 1 + drivers/fsi/fsi-master.h | 2 + drivers/fsi/i2c/Makefile | 1 + drivers/fsi/i2c/iic-boe.c | 1597 +++++++++++++++++++++++++++++ drivers/fsi/i2c/iic-boe.h | 180 ++++ drivers/fsi/i2c/iic-fsi.c | 715 +++++++++++++ drivers/fsi/i2c/iic-int.h | 395 +++++++ drivers/fsi/i2c/iic-lock.c | 439 ++++++++ drivers/fsi/i2c/iic-mstr.c | 2281 +++++++++++++++++++++++++++++++++++++++++ include/linux/fsi.h | 5 + include/uapi/linux/Kbuild | 1 + include/uapi/linux/i2cfsi.h | 136 +++ 15 files changed, 5930 insertions(+) create mode 100644 drivers/fsi/i2c/Makefile create mode 100644 drivers/fsi/i2c/iic-boe.c create mode 100644 drivers/fsi/i2c/iic-boe.h create mode 100644 drivers/fsi/i2c/iic-fsi.c create mode 100644 drivers/fsi/i2c/iic-int.h create mode 100644 drivers/fsi/i2c/iic-lock.c create mode 100644 drivers/fsi/i2c/iic-mstr.c create mode 100644 include/uapi/linux/i2cfsi.h--
1.8.3.1