FSI device driver introduction
Subsystems (3)
cover FSI device driver introduction
From: Chris Bostic <[email protected]>
Introduction of the IBM 'Flexible Support Interface' (FSI) bus device driver. FSI is a high fan out serial bus consisting of a clock and a serial data line capable of running at speeds up to 166 MHz.
This set provides the basic framework to add FSI extensions to the Linux bus and device models. Master specific implementations are defined to utilize the core FSI function.
In Linux, we have a core FSI "bus type", along with drivers for FSI masters and engines.
The FSI master drivers expose a read/write interface to the bus address space. The master drivers are under drivers/fsi/fsi-master-*.c.
The core handles probing and discovery of slaves and slave engines, using those read/write interfaces. It is responsible for creating the endpoint Linux devices corresponding to the discovered engines on each slave.
Slave engines are identified by an 'engine' type, and an optional version. Engine, a.k.a. client, drivers are matched and bound to these engines during discovery.
This patch set does not include extended FSI function such as:
* Hub master support
* Cascaded master support
* Application layer hot plug notification
* Application layer FSI bus status interfaceCommon FSI terminology:
* Master
Controller of the FSI bus. Only the master is allowed to control the clock line and is the initiator of all transactions on a bus.
* Slave
The receiver or target of a master initiated transaction. The slave cannot initiate communications on a bus and must respond to any master requests for data.
* CFAM
Stands for Common Field replaceable unit Access Macro. A CFAM is an ASIC residing in any device requiring FSI communications. CFAMs consist of an array of hardware 'engines' used for various purposes. I2C masters, UARTs, General Purpose IO hardware are common types of these engines.
* Configuration Space / Table
A table contained at the beginning of each CFAM address space. This table lists information such as the CFAM's ID, which engine types and versions it has available, as well as its addressing range.
* FSI Engine driver
A device driver that registers with the FSI core so that it can access devices it owns on an FSI bus.
Chris Bostic (7):
drivers/fsi: Set up links for slave communication drivers/fsi: Set slave SMODE to init communication drivers/fsi: Add master unscan drivers/fsi: Add GPIO based FSI master drivers/fsi: Add client driver register utilities drivers/fsi: Add SCOM FSI client device driver drivers/fsi: Add Mailbox FSI client device driver
Jeremy Kerr (12):
fsi: Add empty fsi bus definitions
fsi: Add device & driver definitions
fsi: add driver to device matches
fsi: Add fsi master definition
fsi: Add fake master driver
fsi: enable debug
fsi: Add slave definition
fsi: Add empty master scan
fsi: Add crc4 helpers
fsi: Implement slave initialisation
fsi: scan slaves & register devices
fsi: Add device read/write/peek functions
.../devicetree/bindings/fsi/fsi-master-gpio.txt | 21 + arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dts | 9 + arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts | 9 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/fsi/Kconfig | 41 ++ drivers/fsi/Makefile | 6 + drivers/fsi/fsi-core.c | 533 +++++++++++++++++++ drivers/fsi/fsi-master-fake.c | 95 ++++ drivers/fsi/fsi-master-gpio.c | 578 +++++++++++++++++++++ drivers/fsi/fsi-master.h | 62 +++ drivers/fsi/fsi-mbx.c | 196 +++++++ drivers/fsi/fsi-scom.c | 225 ++++++++ include/linux/fsi.h | 73 +++ 14 files changed, 1851 insertions(+) create mode 100644 Documentation/devicetree/bindings/fsi/fsi-master-gpio.txt create mode 100644 drivers/fsi/Kconfig create mode 100644 drivers/fsi/Makefile create mode 100644 drivers/fsi/fsi-core.c create mode 100644 drivers/fsi/fsi-master-fake.c create mode 100644 drivers/fsi/fsi-master-gpio.c create mode 100644 drivers/fsi/fsi-master.h create mode 100644 drivers/fsi/fsi-mbx.c create mode 100644 drivers/fsi/fsi-scom.c create mode 100644 include/linux/fsi.h
Signature · 1 line
1.8.2.2
PATCH 2/19 fsi: Add device & driver definitions
From: Jeremy Kerr <[email protected]>
Add structs for fsi devices & drivers, and struct device conversion functions.
--- include/linux/fsi.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
include/linux/fsi.h +11 -0
@@ -18,6 +18,17 @@#include <linux/device.h> +struct fsi_device { +struct device dev; +}; + +struct fsi_driver { +struct device_driver drv; +}; + +#define to_fsi_dev (devp) container_of(devp, struct fsi_device, dev) +#define to_fsi_drv (drvp) container_of(drvp, struct fsi_driver, drv) +extern struct bus_type fsi_bus_type;#endif /* LINUX_FSI_H */
Signature · 1 line
1.8.2.2
PATCH 3/19 fsi: add driver to device matches
In reply to [email protected]From: Jeremy Kerr <[email protected]>
Driver bind to devices based on the engine types & (optional) versions.
--- drivers/fsi/fsi-core.c | 21 +++++++++++++++++++++ include/linux/fsi.h | 21 +++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-)
drivers/fsi/fsi-core.c +21 -0
@@ -19,8 +19,29 @@/* FSI core & Linux bus type definitions */ +static int fsi_bus_match (struct device *dev,struct device_driver *drv) +{ +struct fsi_device *fsi_dev =to_fsi_dev (dev); +struct fsi_driver *fsi_drv =to_fsi_drv (drv); +const struct fsi_device_id *id; + +if (!fsi_drv->id_table) +return 0 ; + +for (id = fsi_drv->id_table; id->engine_type; id++) { +if (id->engine_type != fsi_dev->engine_type) +continue ; +if (id->version ==FSI_VERSION_ANY || + id->version == fsi_dev->version) +return 1 ; + } + +return 0 ; +} +struct bus_type fsi_bus_type = { .name ="fsi" , + .match = fsi_bus_match, };EXPORT_SYMBOL_GPL (fsi_bus_type);
include/linux/fsi.h +19 -2
@@ -19,11 +19,28 @@#include <linux/device.h> struct fsi_device { -struct device dev; +struct device dev; +u8 engine_type; +u8 version; }; +struct fsi_device_id { +u8 engine_type; +u8 version; +}; + +#define FSI_VERSION_ANY 0 + +#define FSI_DEVICE (t) \ + .engine_type = (t), .version = FSI_VERSION_ANY, + +#define FSI_DEVICE_VERSIONED (t, v) \ + .engine_type = (t), .version = (v), + +struct fsi_driver { -struct device_driver drv; +struct device_driver drv; +const struct fsi_device_id *id_table; };#define to_fsi_dev (devp) container_of(devp, struct fsi_device, dev)
Signature · 1 line
1.8.2.2
PATCH 5/19 fsi: Add fake master driver
In reply to [email protected]From: Jeremy Kerr <[email protected]>
For debugging, add a fake master driver, that only supports reads, returning a fixed set of data.
Includes changes from Chris Bostic <[email protected]>.
--- drivers/fsi/Kconfig | 10 +++++ drivers/fsi/Makefile | 1 + drivers/fsi/fsi-master-fake.c | 95 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 drivers/fsi/fsi-master-fake.c
drivers/fsi/Kconfig +10 -0
@@ -9,4 +9,14 @@ config FSI ---help--- FSI - the FRU Support Interface - is a simple bus for low-level access to POWER-based hardware. + +if FSI + +config FSI_MASTER_FAKE + tristate "Fake FSI master" + depends on FSI + ---help--- + This option enables a fake FSI master driver for debugging. +endif + endmenu
drivers/fsi/Makefile +1 -0
@@ -1,2 +1,3 @@ obj-$(CONFIG_FSI) += fsi-core.o +obj-$(CONFIG_FSI_MASTER_FAKE) += fsi-master-fake.o
drivers/fsi/fsi-master-fake.c new file +95 -0
95 lines not on this page · raw message
Signature · 1 line
1.8.2.2
PATCH 6/19 fsi: enable debug
In reply to [email protected]From: Jeremy Kerr <[email protected]>
Enable debug for the fsi core during development. Remove before submission.
--- drivers/fsi/fsi-core.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/fsi/fsi-core.c +2 -0
@@ -13,6 +13,8 @@* GNU General Public License for more details. */ +#define DEBUG +#include <linux/device.h> #include <linux/fsi.h> #include <linux/module.h>
Signature · 1 line
1.8.2.2
PATCH 7/19 fsi: Add slave definition
In reply to [email protected]From: Jeremy Kerr <[email protected]>
Add the initial fsi slave device, which is private to the core code. This will be a child of the master, and parent to endpoint devices.
--- drivers/fsi/fsi-core.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/fsi/fsi-core.c +9 -0
@@ -23,6 +23,15 @@static atomic_t master_idx =ATOMIC_INIT (-1 ); +struct fsi_slave { +struct device dev; +struct fsi_master *master; +int link; +uint8_t id; +}; + +#define to_fsi_slave (d) container_of(d, struct fsi_slave, dev) +/* FSI master support */ int fsi_master_register (struct fsi_master *master)
Signature · 1 line
1.8.2.2
PATCH 8/19 fsi: Add empty master scan
In reply to [email protected]From: Jeremy Kerr <[email protected]>
When a new fsi master is added, we will need to scan its links, and slaves attached to those links. This change introduces a little shell to iterate the links, which we will populate with the actual slave scan in a later change.
--- drivers/fsi/fsi-core.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/fsi/fsi-core.c +24 -0
@@ -21,6 +21,8 @@#include "fsi-master.h" +#define FSI_N_SLAVES 4 +static atomic_t master_idx =ATOMIC_INIT (-1 );struct fsi_slave {
@@ -32,12 +34,34 @@ struct fsi_slave {#define to_fsi_slave (d) container_of(d, struct fsi_slave, dev) +/* FSI slave support */ +static int fsi_slave_init (struct fsi_master *master, +int link,uint8_t slave_id) +{ +/* todo: initialise slave device, perform engine scan */ + +return -ENODEV ; +} +/* FSI master support */ +static int fsi_master_scan (struct fsi_master *master) +{ +int link, slave_id; + +for (link =0 ; link < master->n_links; link++) +for (slave_id =0 ; slave_id <FSI_N_SLAVES ; slave_id++) +fsi_slave_init (master, link, slave_id); + +return 0 ; + +} +int fsi_master_register (struct fsi_master *master) { master->idx =atomic_inc_return (&master_idx);get_device (master->dev); +fsi_master_scan (master);return 0 ; }EXPORT_SYMBOL_GPL (fsi_master_register);
Signature · 1 line
1.8.2.2
PATCH 9/19 fsi: Add crc4 helpers
In reply to [email protected]From: Jeremy Kerr <[email protected]>
Add some helpers for the crc checks for the slave configuration table. This works 4-bits-at-a-time, using a simple table approach.
We will need this in the FSI core code, as well as any master implementations that need to calculate CRCs in software.
--- drivers/fsi/fsi-core.c | 21 +++++++++++++++++++++ drivers/fsi/fsi-master.h | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+)
drivers/fsi/fsi-core.c +21 -0
@@ -34,6 +34,27 @@ struct fsi_slave {#define to_fsi_slave (d) container_of(d, struct fsi_slave, dev) +/* crc helpers */ +static const uint8_t crc4_tab[] = { +0x0 ,0x7 ,0xe ,0x9 ,0xb ,0xc ,0x5 ,0x2 , +0x1 ,0x6 ,0xf ,0x8 ,0xa ,0xd ,0x4 ,0x3 , +}; + +uint8_t fsi_crc4 (uint8_t c,uint64_t x,int bits) +{ +int i; + +/* Align to 4-bits */ + bits = (bits +3 ) & ~0x3 ; + +/* Calculate crc4 over four-bit nibbles, starting at the MSbit */ +for (i = bits; i >=0 ; i -=4 ) + c = crc4_tab[c ^ ((x >> i) &0xf )]; + +return c; +} +EXPORT_SYMBOL_GPL (fsi_crc4); +/* FSI slave support */ static int fsi_slave_init (struct fsi_master *master,int link,uint8_t slave_id)
drivers/fsi/fsi-master.h +21 -0
@@ -34,4 +34,25 @@ struct fsi_master {extern int fsi_master_register (struct fsi_master *master);extern void fsi_master_unregister (struct fsi_master *master); +/** +* crc4 helper: Given a starting crc4 state @c, calculate the crc4 vaue of @x, +* which is @bits in length. This may be required by master implementations +* that do not provide their own hardware checksums. +* +* The crc4 is performed on 4-bit chunks (which is all we need for FSI +* calculations). Typically, we'll want a starting state of 0: +* +* c = fsi_crc4(0, msg, len); +* +* To crc4 a message that includes a single start bit, initialise crc4 state +* with: +* +* c = fsi_crc4(0, 1, 1); +* +* Then update with message data: +* +* c = fsi_crc4(c, msg, len); +*/ +uint8_t fsi_crc4 (uint8_t c,uint64_t x,int bits); +#endif /* DRIVERS_FSI_MASTER_H */
Signature · 1 line
1.8.2.2
PATCH 10/19 fsi: Implement slave initialisation
In reply to [email protected]From: Jeremy Kerr <[email protected]>
Create fsi_slave devices during the master scan.
--- drivers/fsi/fsi-core.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-)
drivers/fsi/fsi-core.c +53 -2
@@ -18,10 +18,14 @@#include <linux/device.h> #include <linux/fsi.h> #include <linux/module.h> +#include <linux/slab.h> #include "fsi-master.h" #define FSI_N_SLAVES 4 +#define FSI_SLAVE_CONF_CRC_SHIFT 4 +#define FSI_SLAVE_CONF_CRC_MASK 0x0000000f +#define FSI_SLAVE_CONF_DATA_BITS 28static atomic_t master_idx =ATOMIC_INIT (-1 );
@@ -56,12 +60,59 @@ uint8_t fsi_crc4(uint8_t c, uint64_t x, int bits)EXPORT_SYMBOL_GPL (fsi_crc4);/* FSI slave support */ + +static void fsi_slave_release (struct device *dev) +{ +struct fsi_slave *slave =to_fsi_slave (dev); + +kfree (slave); +} +static int fsi_slave_init (struct fsi_master *master,int link,uint8_t slave_id) { -/* todo: initialise slave device, perform engine scan */ +struct fsi_slave *slave; +uint32_t chip_id; +int rc; +uint8_t crc; + + rc = master->read (master, link, slave_id,0 , &chip_id,sizeof (chip_id)); +if (rc) { +dev_warn (master->dev,"can't read slave %02x:%02x: %d\n" , + link, slave_id, rc); +return -ENODEV ; + } + crc =fsi_crc4 (0 , chip_id >>FSI_SLAVE_CONF_CRC_SHIFT , +FSI_SLAVE_CONF_DATA_BITS ); +if (crc != (chip_id &FSI_SLAVE_CONF_CRC_MASK )) { +dev_warn (master->dev,"slave %02x:%02x invalid chip id CRC!\n" , + link, slave_id); +return -EIO ; + } + +pr_debug ("fsi: found chip %08x at %02x:%02x:%02x\n" , + master->idx, chip_id, link, slave_id); + +/* we can communicate with a slave; create devices and scan */ + slave =kzalloc (sizeof (*slave),GFP_KERNEL ); +if (!slave) +return -ENOMEM ; + + slave->master = master; + slave->id = slave_id; + slave->dev.parent = master->dev; + slave->dev.release = fsi_slave_release; + +dev_set_name (&slave->dev,"slave@%02x:%02x" , link, slave_id); + rc =device_register (&slave->dev); +if (rc <0 ) { +dev_warn (master->dev,"failed to create slave device: %d\n" , + rc); +put_device (&slave->dev); +return rc; + } -return -ENODEV ; +return rc; }/* FSI master support */
Signature · 1 line
1.8.2.2
PATCH 11/19 fsi: scan slaves & register devices
In reply to [email protected]From: Jeremy Kerr <[email protected]>
Now that we have fsi_slave devices, scan each for endpoints, and register them on the fsi bus.
Includes contributions from Chris Bostic <[email protected]>
--- drivers/fsi/fsi-core.c | 136 +++++++++++++++++++++++++++++++++++++++++++++++-- include/linux/fsi.h | 4 ++ 2 files changed, 136 insertions(+), 4 deletions(-)
drivers/fsi/fsi-core.c +132 -4
@@ -23,9 +23,19 @@#include "fsi-master.h" #define FSI_N_SLAVES 4 -#define FSI_SLAVE_CONF_CRC_SHIFT 4 -#define FSI_SLAVE_CONF_CRC_MASK 0x0000000f -#define FSI_SLAVE_CONF_DATA_BITS 28 + +#define FSI_SLAVE_CONF_NEXT_MASK 0x80000000 +#define FSI_SLAVE_CONF_SLOTS_MASK 0x00ff0000 +#define FSI_SLAVE_CONF_SLOTS_SHIFT 16 +#define FSI_SLAVE_CONF_VERSION_MASK 0x0000f000 +#define FSI_SLAVE_CONF_VERSION_SHIFT 12 +#define FSI_SLAVE_CONF_TYPE_MASK 0x00000ff0 +#define FSI_SLAVE_CONF_TYPE_SHIFT 4 +#define FSI_SLAVE_CONF_CRC_SHIFT 4 +#define FSI_SLAVE_CONF_CRC_MASK 0x0000000f +#define FSI_SLAVE_CONF_DATA_BITS 28 + +static const int engine_page_size =0x400 ;static atomic_t master_idx =ATOMIC_INIT (-1 );
@@ -38,6 +48,30 @@ struct fsi_slave {#define to_fsi_slave (d) container_of(d, struct fsi_slave, dev) +/* FSI endpoint-device support */ + +static void fsi_device_release (struct device *_device) +{ +struct fsi_device *device =to_fsi_dev (_device); + +kfree (device); +} + +static struct fsi_device *fsi_create_device (struct fsi_slave *slave) +{ +struct fsi_device *dev; + + dev =kzalloc (sizeof (*dev),GFP_KERNEL ); +if (!dev) +return NULL ; + + dev->dev.parent = &slave->dev; + dev->dev.bus = &fsi_bus_type; + dev->dev.release = fsi_device_release; + +return dev; +} +/* crc helpers */ static const uint8_t crc4_tab[] = {0x0 ,0x7 ,0xe ,0x9 ,0xb ,0xc ,0x5 ,0x2 ,
@@ -61,6 +95,99 @@ EXPORT_SYMBOL_GPL(fsi_crc4);/* FSI slave support */ +static int fsi_slave_read (struct fsi_slave *slave,uint32_t addr, +void *val,size_t size) +{ +return slave->master->read (slave->master, slave->link, + slave->id, addr, val, size); +} + +static int fsi_slave_scan (struct fsi_slave *slave) +{ +uint32_t engine_addr; +uint32_t conf; +int rc, i; + +/* +* scan engines +* +* We keep the peek mode and slave engines for the core; so start +* at the third slot in the configuration table. We also need to +* skip the chip ID entry at the start of the address space. +*/ + engine_addr = engine_page_size *3 ; +for (i =2 ; i < engine_page_size /sizeof (uint32_t ); i++) { +uint8_t slots, version, type, crc; +struct fsi_device *dev; + + rc =fsi_slave_read (slave, (i +1 ) *sizeof (conf), + &conf,sizeof (conf)); +if (rc) { +dev_warn (&slave->dev, +"error reading slave registers\n" ); +return -1 ; + } + + crc =fsi_crc4 (0 , conf >>FSI_SLAVE_CONF_CRC_SHIFT , +FSI_SLAVE_CONF_DATA_BITS ); +if (crc != (conf &FSI_SLAVE_CONF_CRC_MASK )) { +dev_warn (&slave->dev, +"crc error in slave register at 0x%04x\n" , + i); +return -1 ; + } + + slots = (conf &FSI_SLAVE_CONF_SLOTS_MASK ) + >>FSI_SLAVE_CONF_SLOTS_SHIFT ; + version = (conf &FSI_SLAVE_CONF_VERSION_MASK ) + >>FSI_SLAVE_CONF_VERSION_SHIFT ; + type = (conf &FSI_SLAVE_CONF_TYPE_MASK ) + >>FSI_SLAVE_CONF_TYPE_SHIFT ; + +/* +* Unused address areas are marked by a zero type value; this +* skips the defined address areas +*/ +if (type !=0 ) { + +/* create device */ + dev =fsi_create_device (slave); +if (!dev) +return -ENOMEM ; + + dev->slave = slave; + dev->engine_type = type; + dev->version = version; + dev->unit = i; + dev->addr = engine_addr; + dev->size = slots * engine_page_size; + +dev_info (&slave->dev, +"engine[%i]: type %x, version %x, addr %x size %x\n" , + dev->unit, dev->engine_type, version, + dev->addr, dev->size); + +device_initialize (&dev->dev); +dev_set_name (&dev->dev,"%02x:%02x:%02x:%02x" , + slave->master->idx, slave->link, + slave->id, i -2 ); + + rc =device_add (&dev->dev); +if (rc) { +dev_warn (&slave->dev,"add failed: %d\n" , rc); +put_device (&dev->dev); + } + } + + engine_addr += slots * engine_page_size; + +if (!(conf &FSI_SLAVE_CONF_NEXT_MASK )) +break ; + } + +return 0 ; +} +static void fsi_slave_release (struct device *dev) {struct fsi_slave *slave =to_fsi_slave (dev);
@@ -112,7 +239,8 @@ static int fsi_slave_init(struct fsi_master *master,return rc; } -return rc; +fsi_slave_scan (slave); +return 0 ; }/* FSI master support */
include/linux/fsi.h +4 -0
@@ -22,6 +22,10 @@ struct fsi_device {struct device dev;u8 engine_type;u8 version; +u8 unit; +struct fsi_slave *slave; +uint32_t addr; +uint32_t size; };struct fsi_device_id {
Signature · 1 line
1.8.2.2
PATCH 12/19 fsi: Add device read/write/peek functions
In reply to [email protected]From: Jeremy Kerr <[email protected]>
This change introduces the fsi device API: simple read, write and peek accessors for the devices' address spaces.
Includes contributions from Chris Bostic <[email protected]>
--- drivers/fsi/fsi-core.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/fsi.h | 7 ++++++- 2 files changed, 53 insertions(+), 1 deletion(-)
drivers/fsi/fsi-core.c +47 -0
@@ -35,6 +35,8 @@#define FSI_SLAVE_CONF_CRC_MASK 0x0000000f#define FSI_SLAVE_CONF_DATA_BITS 28 +#define FSI_PEEK_BASE 0x410 +static const int engine_page_size =0x400 ;static atomic_t master_idx =ATOMIC_INIT (-1 );
@@ -48,8 +50,46 @@ struct fsi_slave {#define to_fsi_slave (d) container_of(d, struct fsi_slave, dev) +static int fsi_slave_read (struct fsi_slave *slave,uint32_t addr, +void *val,size_t size); +static int fsi_slave_write (struct fsi_slave *slave,uint32_t addr, +const void *val,size_t size); +/* FSI endpoint-device support */ +int fsi_device_read (struct fsi_device *dev,uint32_t addr,void *val, +size_t size) +{ +if (addr > dev->size) +return -EINVAL ; + +if (addr + size > dev->size) +return -EINVAL ; + +return fsi_slave_read (dev->slave, dev->addr + addr, val, size); +} +EXPORT_SYMBOL_GPL (fsi_device_read); + +int fsi_device_write (struct fsi_device *dev,uint32_t addr,const void *val, +size_t size) +{ +if (addr > dev->size) +return -EINVAL ; + +if (addr + size > dev->size) +return -EINVAL ; + +return fsi_slave_write (dev->slave, dev->addr + addr, val, size); +} +EXPORT_SYMBOL_GPL (fsi_device_write); + +int fsi_device_peek (struct fsi_device *dev,void *val) +{ +uint32_t addr =FSI_PEEK_BASE + ((dev->unit -2 ) *sizeof (uint32_t )); + +return fsi_slave_read (dev->slave, addr, val,sizeof (uint32_t )); +} +static void fsi_device_release (struct device *_device) {struct fsi_device *device =to_fsi_dev (_device);
@@ -102,6 +142,13 @@ static int fsi_slave_read(struct fsi_slave *slave, uint32_t addr, slave->id, addr, val, size); } +static int fsi_slave_write (struct fsi_slave *slave,uint32_t addr, +const void *val,size_t size) +{ +return slave->master->write (slave->master, slave->link, + slave->id, addr, val, size); +} +static int fsi_slave_scan (struct fsi_slave *slave) {uint32_t engine_addr;
include/linux/fsi.h +6 -1
@@ -28,6 +28,12 @@ struct fsi_device {uint32_t size; }; +extern int fsi_device_read (struct fsi_device *dev,uint32_t addr, +void *val,size_t size); +extern int fsi_device_write (struct fsi_device *dev,uint32_t addr, +const void *val,size_t size); +extern int fsi_device_peek (struct fsi_device *dev,void *val); +struct fsi_device_id {u8 engine_type;u8 version;
@@ -41,7 +47,6 @@ struct fsi_device_id {#define FSI_DEVICE_VERSIONED (t, v) \ .engine_type = (t), .version = (v), -struct fsi_driver {struct device_driver drv;const struct fsi_device_id *id_table;
Signature · 1 line
1.8.2.2
PATCH 13/19 drivers/fsi: Set up links for slave communication
In reply to [email protected]From: Chris Bostic <[email protected]>
Enable each link and send a break command in preparation for scanning each link for slaves.
--- drivers/fsi/fsi-core.c | 39 ++++++++++++++++++++++++++++++++++++--- drivers/fsi/fsi-master.h | 2 ++ 2 files changed, 38 insertions(+), 3 deletions(-)
drivers/fsi/fsi-core.c +36 -3
@@ -292,16 +292,49 @@ static int fsi_slave_init(struct fsi_master *master,/* FSI master support */ +static int fsi_master_link_enable (struct fsi_master *master,int link) +{ +if (master->link_enable) +return master->link_enable (master, link); + +return 0 ; +} + +/* +* Issue a break command on this link +*/ +static int fsi_master_break (struct fsi_master *master,int link) +{ +if (master->send_break) +return master->send_break (master, link); + +return 0 ; +} +static int fsi_master_scan (struct fsi_master *master) { -int link, slave_id; +int link, slave_id, rc; + +for (link =0 ; link < master->n_links; link++) { + rc =fsi_master_link_enable (master, link); +if (rc) { +dev_dbg (master->dev, +"enable link:%d failed with:%d\n" , link, rc); +continue ; + } + rc =fsi_master_break (master, link); +if (rc) { +dev_dbg (master->dev, +"Break to link:%d failed with:%d\n" , link, rc); +continue ; + } -for (link =0 ; link < master->n_links; link++)for (slave_id =0 ; slave_id <FSI_N_SLAVES ; slave_id++)fsi_slave_init (master, link, slave_id); -return 0 ; + } +return 0 ; }int fsi_master_register (struct fsi_master *master)
drivers/fsi/fsi-master.h +2 -0
@@ -29,6 +29,8 @@ struct fsi_master {int (*write)(struct fsi_master *,int link,uint8_t slave,uint32_t addr,const void *val,size_t size); +int (*send_break)(struct fsi_master *,int link); +int (*link_enable)(struct fsi_master *,int link); };extern int fsi_master_register (struct fsi_master *master);
Signature · 1 line
1.8.2.2
PATCH 15/19 drivers/fsi: Add master unscan
In reply to [email protected]From: Chris Bostic <[email protected]>
Allow a master to undo a previous scan. Should a master scan a bus twice it will need to ensure it doesn't double register any previously detected device.
--- drivers/fsi/fsi-core.c | 36 +++++++++++++++++++++++++++++++++++- drivers/fsi/fsi-master.h | 2 ++ include/linux/fsi.h | 1 + 3 files changed, 38 insertions(+), 1 deletion(-)
drivers/fsi/fsi-core.c +35 -1
@@ -43,6 +43,8 @@ static const int engine_page_size = 0x400;static atomic_t master_idx =ATOMIC_INIT (-1 );struct fsi_slave { +struct list_head list_link;/* Master's list of slaves */ +struct list_head my_engines;struct device dev;struct fsi_master *master;int link;
@@ -198,6 +200,8 @@ static int fsi_slave_scan(struct fsi_slave *slave)uint32_t conf;int rc, i; +INIT_LIST_HEAD (&slave->my_engines); +/* * scan engines *
@@ -266,7 +270,9 @@ static int fsi_slave_scan(struct fsi_slave *slave)if (rc) {dev_warn (&slave->dev,"add failed: %d\n" , rc);put_device (&dev->dev); +continue ; } +list_add (&dev->link, &slave->my_engines); } engine_addr += slots * engine_page_size;
@@ -359,7 +365,7 @@ static int fsi_slave_init(struct fsi_master *master,put_device (&slave->dev);return rc; } - +list_add (&slave->list_link, &master->my_slaves);fsi_slave_scan (slave);return 0 ; }
@@ -390,6 +396,11 @@ static int fsi_master_scan(struct fsi_master *master)int link, slave_id, rc;uint32_t smode; +if (!master->slave_list) { +INIT_LIST_HEAD (&master->my_slaves); + master->slave_list = true; + } +for (link =0 ; link < master->n_links; link++) { rc =fsi_master_link_enable (master, link);if (rc) {
@@ -425,9 +436,31 @@ static int fsi_master_scan(struct fsi_master *master)return 0 ; } +static void fsi_master_unscan (struct fsi_master *master) +{ +struct fsi_slave *slave, *slave_tmp; +struct fsi_device *fsi_dev, *fsi_dev_tmp; + +if (!master->slave_list) +return ; + +list_for_each_entry_safe (slave, slave_tmp, &master->my_slaves, + list_link) { +list_del (&slave->list_link); +list_for_each_entry_safe (fsi_dev, fsi_dev_tmp, + &slave->my_engines, link) { +list_del (&fsi_dev->link); +put_device (&fsi_dev->dev); + } +device_unregister (&slave->dev); + } + master->slave_list = false; +} +int fsi_master_register (struct fsi_master *master) { master->idx =atomic_inc_return (&master_idx); + master->slave_list = false;get_device (master->dev);fsi_master_scan (master);return 0 ;
@@ -436,6 +469,7 @@ EXPORT_SYMBOL_GPL(fsi_master_register);void fsi_master_unregister (struct fsi_master *master) { +fsi_master_unscan (master);put_device (master->dev); }EXPORT_SYMBOL_GPL (fsi_master_unregister);
drivers/fsi/fsi-master.h +2 -0
@@ -20,6 +20,8 @@#include <linux/device.h> struct fsi_master { +struct list_head my_slaves; +bool slave_list;struct device *dev;int idx;int n_links;
include/linux/fsi.h +1 -0
@@ -19,6 +19,7 @@#include <linux/device.h> struct fsi_device { +struct list_head link;/* for slave's list */ struct device dev;u8 engine_type;u8 version;
Signature · 1 line
1.8.2.2
PATCH 16/19 drivers/fsi: Add GPIO based FSI master
In reply to [email protected]From: Chris Bostic <[email protected]>
Implement a FSI master using GPIO. Will generate FSI protocol for read and write commands to particular addresses. Sends master command and waits for and decodes a slave response. Includes Jeremy Kerr's original GPIO master base commit.
Includes workaround for voltage translator pin to access I/O via registers. Issue with busy pin prevented normal registration.
--- .../devicetree/bindings/fsi/fsi-master-gpio.txt | 21 + arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dts | 9 + arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts | 9 + drivers/fsi/Kconfig | 6 + drivers/fsi/Makefile | 1 + drivers/fsi/fsi-master-gpio.c | 578 +++++++++++++++++++++ 6 files changed, 624 insertions(+) create mode 100644 Documentation/devicetree/bindings/fsi/fsi-master-gpio.txt create mode 100644 drivers/fsi/fsi-master-gpio.c
Documentation/devicetree/bindings/fsi/fsi-master-gpio.txt new file +21 -0
@@ -0,0 +1,21 @@ +Device-tree bindings for gpio-based FSI master driver +----------------------------------------------------- + +Required properties: + - compatible = "ibm,fsi-master-gpio"; + - clk-gpios; + - data-gpios; + +Optional properties: + - enable-gpios; + - trans-gpios; + - mux-gpios; + +fsi-master { + compatible = "ibm,fsi-master", "ibm,fsi-master-gpio"; + clk-gpios = <&gpio 0 &gpio 6>; + data-gpios = <&gpio 1 &gpio 7>; + enable-gpios = <&gpio 2 &gpio 8>; /* Enable FSI data in/out */ + trans-gpios = <&gpio 3 &gpio 9>; /* Volts translator direction */ + mux-gpios = <&gpio 4> &gpio 10>; /* Multiplexer for FSI pins */ +}
arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dts +9 -0
@@ -36,6 +36,15 @@ }; }; + fsi-master { + compatible = "ibm,fsi-master", "ibm,fsi-master-gpio"; + clock-gpios = <&gpio ASPEED_GPIO(A, 4) GPIO_ACTIVE_HIGH>; + data-gpios = <&gpio ASPEED_GPIO(A, 5) GPIO_ACTIVE_HIGH>; + mux-gpios = <&gpio ASPEED_GPIO(A, 6) GPIO_ACTIVE_HIGH>; + enable-gpios = <&gpio ASPEED_GPIO(D, 0) GPIO_ACTIVE_HIGH>; + trans-gpios = <&gpio ASPEED_GPIO(H, 6) GPIO_ACTIVE_HIGH>; + }; + ahb { bmc_pnor: fmc@1e620000 { reg = < 0x1e620000 0x94
arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts +9 -0
@@ -19,6 +19,15 @@ memory { reg = <0x80000000 0x40000000>; }; + + fsi-master { + compatible = "ibm,fsi-master", "ibm,fsi-master-gpio"; + clock-gpios = <&gpio ASPEED_GPIO(AA, 0) GPIO_ACTIVE_LOW>; + data-gpios = <&gpio ASPEED_GPIO(E, 0) GPIO_ACTIVE_HIGH>; + mux-gpios = <&gpio ASPEED_GPIO(A, 6) GPIO_ACTIVE_LOW>; + enable-gpios = <&gpio ASPEED_GPIO(D, 0) GPIO_ACTIVE_LOW>; + trans-gpios = <&gpio ASPEED_GPIO(R, 2) GPIO_ACTIVE_LOW>; + }; }; &fmc {
drivers/fsi/Kconfig +6 -0
@@ -17,6 +17,12 @@ config FSI_MASTER_FAKE depends on FSI ---help--- This option enables a fake FSI master driver for debugging. + +config FSI_MASTER_GPIO + tristate "GPIO-based FSI master" + depends on FSI + ---help--- + This option enables a FSI master driver using GPIO lines. endif endmenu
drivers/fsi/Makefile +1 -0
@@ -1,3 +1,4 @@ obj-$(CONFIG_FSI) += fsi-core.o obj-$(CONFIG_FSI_MASTER_FAKE) += fsi-master-fake.o +obj-$(CONFIG_FSI_MASTER_GPIO) += fsi-master-gpio.o
drivers/fsi/fsi-master-gpio.c new file +578 -0
578 lines not on this page · raw message
Signature · 1 line
1.8.2.2
PATCH 17/19 drivers/fsi: Add client driver register utilities
In reply to [email protected]From: Chris Bostic <[email protected]>
Add driver_register and driver_unregister wrappers for FSI.
--- drivers/fsi/fsi-core.c | 17 +++++++++++++++++ include/linux/fsi.h | 12 ++++++++++++ 2 files changed, 29 insertions(+)
drivers/fsi/fsi-core.c +17 -0
@@ -496,6 +496,23 @@ static int fsi_bus_match(struct device *dev, struct device_driver *drv)return 0 ; } +int fsi_driver_register (struct fsi_driver *fsi_drv) +{ +if (!fsi_drv) +return -EINVAL ; +if (!fsi_drv->id_table) +return -EINVAL ; + +return driver_register (&fsi_drv->drv); +} +EXPORT_SYMBOL_GPL (fsi_driver_register); + +void fsi_driver_unregister (struct fsi_driver *fsi_drv) +{ +driver_unregister (&fsi_drv->drv); +} +EXPORT_SYMBOL_GPL (fsi_driver_unregister); +struct bus_type fsi_bus_type = { .name ="fsi" , .match = fsi_bus_match,
include/linux/fsi.h +12 -0
@@ -56,6 +56,18 @@ struct fsi_driver {#define to_fsi_dev (devp) container_of(devp, struct fsi_device, dev)#define to_fsi_drv (drvp) container_of(drvp, struct fsi_driver, drv) +extern int fsi_driver_register (struct fsi_driver *); +extern void fsi_driver_unregister (struct fsi_driver *); + +/* module_fsi_driver() - Helper macro for drivers that don't do +* anything special in module init/exit. This eliminates a lot of +* boilerplate. Each module may only use this macro once, and +* calling it replaces module_init() and module_exit() +*/ +#define module_fsi_driver (__fsi_driver) \ + module_driver(__fsi_driver, fsi_driver_register, \ + fsi_driver_unregister) +extern struct bus_type fsi_bus_type;#endif /* LINUX_FSI_H */
Signature · 1 line
1.8.2.2
PATCH 18/19 drivers/fsi: Add SCOM FSI client device driver
In reply to [email protected]From: Chris Bostic <[email protected]>
Create a simple SCOM engine device driver that reads and writes its control registers via an FSI bus.
--- drivers/fsi/Kconfig | 6 ++ drivers/fsi/Makefile | 1 + drivers/fsi/fsi-scom.c | 225 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 232 insertions(+) create mode 100644 drivers/fsi/fsi-scom.c
drivers/fsi/Kconfig +6 -0
@@ -23,6 +23,12 @@ config FSI_MASTER_GPIO depends on FSI ---help--- This option enables a FSI master driver using GPIO lines. + +config FSI_SCOM + tristate "SCOM FSI client device driver" + depends on FSI + ---help--- + This option enables an FSI based SCOM device driver. endif endmenu
drivers/fsi/Makefile +1 -0
@@ -2,3 +2,4 @@ obj-$(CONFIG_FSI) += fsi-core.o obj-$(CONFIG_FSI_MASTER_FAKE) += fsi-master-fake.o obj-$(CONFIG_FSI_MASTER_GPIO) += fsi-master-gpio.o +obj-$(CONFIG_FSI_SCOM) += fsi-scom.o
drivers/fsi/fsi-scom.c new file +225 -0
225 lines not on this page · raw message
Signature · 1 line
1.8.2.2
PATCH 19/19 drivers/fsi: Add Mailbox FSI client device driver
In reply to [email protected]From: Chris Bostic <[email protected]>
Create a simple mailbox engine device driver that can access its registers across an FSI bus.
--- drivers/fsi/Kconfig | 7 ++ drivers/fsi/Makefile | 1 + drivers/fsi/fsi-mbx.c | 196 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 204 insertions(+) create mode 100644 drivers/fsi/fsi-mbx.c
drivers/fsi/Kconfig +7 -0
@@ -29,6 +29,13 @@ config FSI_SCOM depends on FSI ---help--- This option enables an FSI based SCOM device driver. + +config FSI_MBX + tristate "Mailbox FSI client device driver" + depends on FSI + ---help--- + This option enables an FSI based Mailbox device driver. + endif endmenu
drivers/fsi/Makefile +1 -0
@@ -3,3 +3,4 @@ obj-$(CONFIG_FSI) += fsi-core.o obj-$(CONFIG_FSI_MASTER_FAKE) += fsi-master-fake.o obj-$(CONFIG_FSI_MASTER_GPIO) += fsi-master-gpio.o obj-$(CONFIG_FSI_SCOM) += fsi-scom.o +obj-$(CONFIG_FSI_MBX) += fsi-mbx.o
drivers/fsi/fsi-mbx.c new file +196 -0
196 lines not on this page · raw message
Signature · 1 line
1.8.2.2
Re: [PATCH linux 06/19] fsi: enable debug
In reply to [email protected]Hi Chris,
Quoted 2 lines
Enable debug for the fsi core during development. Remove before submission.
We probably want to drop this one now :)
Cheers,
Jeremy
Joel Stanley
maintainerHello Chris,
Quoted 9 lines · On Mon, Nov 21, 2016 at 1:10 PM, <[email protected]> wrote:
Chris Bostic (7):
drivers/fsi: Set up links for slave communicationdrivers/fsi: Set slave SMODE to init communicationdrivers/fsi: Add master unscandrivers/fsi: Add GPIO based FSI masterdrivers/fsi: Add client driver register utilitiesdrivers/fsi: Add SCOM FSI client device driverdrivers/fsi: Add Mailbox FSI client device driver
Quoted 8 lines
Jeremy Kerr (12):
fsi: Add empty fsi bus definitions
fsi: Add device & driver definitions
fsi: add driver to device matches
fsi: Add fsi master definition
fsi: Add fake master driverfsi: enable debug
Drop this debug patch.
Quoted 6 lines
fsi: Add slave definition
fsi: Add empty master scan
fsi: Add crc4 helpers
fsi: Implement slave initialisation
fsi: scan slaves & register devices
fsi: Add device read/write/peek functions
A few housekeeping issues:
You're missing patch 1, 4 and 14 from the series.
Please resend with the full series and add cc [email protected].
You should base your series on an upstream tree. I suggest 4.9-rc1. This will mean dropping the patch to the Witherspoon dts which is not upstream.
Finally, make the subjects consistent: pick either drivers/fsi or fsi for the entire series.
Cheers,
Joel
Quoted 30 lines
.../devicetree/bindings/fsi/fsi-master-gpio.txt | 21 + arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dts | 9 + arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts | 9 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/fsi/Kconfig | 41 ++ drivers/fsi/Makefile | 6 + drivers/fsi/fsi-core.c | 533 +++++++++++++++++++ drivers/fsi/fsi-master-fake.c | 95 ++++ drivers/fsi/fsi-master-gpio.c | 578 +++++++++++++++++++++ drivers/fsi/fsi-master.h | 62 +++ drivers/fsi/fsi-mbx.c | 196 +++++++ drivers/fsi/fsi-scom.c | 225 ++++++++ include/linux/fsi.h | 73 +++ 14 files changed, 1851 insertions(+) create mode 100644 Documentation/devicetree/bindings/fsi/fsi-master-gpio.txt create mode 100644 drivers/fsi/Kconfig create mode 100644 drivers/fsi/Makefile create mode 100644 drivers/fsi/fsi-core.c create mode 100644 drivers/fsi/fsi-master-fake.c create mode 100644 drivers/fsi/fsi-master-gpio.c create mode 100644 drivers/fsi/fsi-master.h create mode 100644 drivers/fsi/fsi-mbx.c create mode 100644 drivers/fsi/fsi-scom.c create mode 100644 include/linux/fsi.h--
1.8.2.2