Skip to content

Commit 2b545cd

Browse files
jk-ozlabsgregkh
authored andcommitted
drivers/fsi: Implement slave initialisation
Implement fsi_slave_init: if we can read a chip ID, create fsi_slave devices and register with the driver core. Includes changes from Christopher Bostic <cbostic@linux.vnet.ibm.com>. Signed-off-by: Jeremy Kerr <jk@ozlabs.org> Signed-off-by: Christopher Bostic <cbostic@linux.vnet.ibm.com> Signed-off-by: Joel Stanley <joel@jms.id.au> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2609528 commit 2b545cd

2 files changed

Lines changed: 66 additions & 2 deletions

File tree

‎drivers/fsi/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ menu "FSI support"
66

77
config FSI
88
tristate "FSI support"
9+
select CRC4
910
---help---
1011
FSI - the FRU Support Interface - is a simple bus for low-level
1112
access to POWER-based hardware.

‎drivers/fsi/fsi-core.c‎

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@
1313
* GNU General Public License for more details.
1414
*/
1515

16+
#include <linux/crc4.h>
1617
#include <linux/device.h>
1718
#include <linux/fsi.h>
1819
#include <linux/idr.h>
1920
#include <linux/module.h>
21+
#include <linux/slab.h>
2022

2123
#include "fsi-master.h"
2224

25+
#define FSI_SLAVE_SIZE_23b 0x800000
26+
2327
static DEFINE_IDA(master_ida);
2428

2529
struct fsi_slave {
@@ -90,11 +94,70 @@ static int fsi_slave_write(struct fsi_slave *slave, uint32_t addr,
9094
addr, val, size);
9195
}
9296

97+
static void fsi_slave_release(struct device *dev)
98+
{
99+
struct fsi_slave *slave = to_fsi_slave(dev);
100+
101+
kfree(slave);
102+
}
103+
93104
static int fsi_slave_init(struct fsi_master *master, int link, uint8_t id)
94105
{
95-
/* todo: initialise slave device, perform engine scan */
106+
struct fsi_slave *slave;
107+
uint32_t chip_id;
108+
uint8_t crc;
109+
int rc;
110+
111+
/* Currently, we only support single slaves on a link, and use the
112+
* full 23-bit address range
113+
*/
114+
if (id != 0)
115+
return -EINVAL;
116+
117+
rc = fsi_master_read(master, link, id, 0, &chip_id, sizeof(chip_id));
118+
if (rc) {
119+
dev_dbg(&master->dev, "can't read slave %02x:%02x %d\n",
120+
link, id, rc);
121+
return -ENODEV;
122+
}
123+
chip_id = be32_to_cpu(chip_id);
124+
125+
crc = crc4(0, chip_id, 32);
126+
if (crc) {
127+
dev_warn(&master->dev, "slave %02x:%02x invalid chip id CRC!\n",
128+
link, id);
129+
return -EIO;
130+
}
131+
132+
dev_info(&master->dev, "fsi: found chip %08x at %02x:%02x:%02x\n",
133+
chip_id, master->idx, link, id);
134+
135+
/* We can communicate with a slave; create the slave device and
136+
* register.
137+
*/
138+
slave = kzalloc(sizeof(*slave), GFP_KERNEL);
139+
if (!slave)
140+
return -ENOMEM;
141+
142+
slave->master = master;
143+
slave->dev.parent = &master->dev;
144+
slave->dev.release = fsi_slave_release;
145+
slave->link = link;
146+
slave->id = id;
147+
slave->size = FSI_SLAVE_SIZE_23b;
148+
149+
dev_set_name(&slave->dev, "slave@%02x:%02x", link, id);
150+
rc = device_register(&slave->dev);
151+
if (rc < 0) {
152+
dev_warn(&master->dev, "failed to create slave device: %d\n",
153+
rc);
154+
put_device(&slave->dev);
155+
return rc;
156+
}
157+
158+
/* todo: perform engine scan */
96159

97-
return -ENODEV;
160+
return rc;
98161
}
99162

100163
/* FSI master support */

0 commit comments

Comments
 (0)