Skip to content

Commit

Permalink
fsi: Add support for device-tree provided chip IDs
Browse files Browse the repository at this point in the history
They get retrieved from the device-tree and exposed
as an attribute in sysfs

Signed-off-by: Benjamin Herrenschmidt <[email protected]>
  • Loading branch information
ozbenh committed Jul 23, 2018
1 parent e13c542 commit 0a21377
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions drivers/fsi/fsi-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ struct fsi_slave {
struct fsi_master *master;
int id;
int link;
int chip_id;
uint32_t size; /* size of slave address space */
u8 t_send_delay;
u8 t_echo_delay;
Expand Down Expand Up @@ -717,6 +718,17 @@ static ssize_t slave_send_echo_store(struct device *dev,
static DEVICE_ATTR(send_echo_delays, 0600,
slave_send_echo_show, slave_send_echo_store);

static ssize_t chip_id_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct fsi_slave *slave = to_fsi_slave(dev);

return sprintf(buf, "%d\n", slave->chip_id);
}

static DEVICE_ATTR_RO(chip_id);

static int fsi_slave_init(struct fsi_master *master, int link, uint8_t id)
{
uint32_t chip_id;
Expand Down Expand Up @@ -780,6 +792,14 @@ static int fsi_slave_init(struct fsi_master *master, int link, uint8_t id)
slave->t_send_delay = 16;
slave->t_echo_delay = 16;

/* Get chip ID if any */
slave->chip_id = -1;
if (slave->dev.of_node) {
uint32_t prop;
if (!of_property_read_u32(slave->dev.of_node, "chip-id", &prop))
slave->chip_id = prop;

}
rc = fsi_slave_set_smode(slave);
if (rc) {
dev_warn(&master->dev,
Expand Down Expand Up @@ -814,6 +834,10 @@ static int fsi_slave_init(struct fsi_master *master, int link, uint8_t id)
if (rc)
dev_warn(&slave->dev, "failed to create delay attr: %d\n", rc);

rc = device_create_file(&slave->dev, &dev_attr_chip_id);
if (rc)
dev_warn(&slave->dev, "failed to create chip id: %d\n", rc);

rc = fsi_slave_scan(slave);
if (rc)
dev_dbg(&master->dev, "failed during slave scan with: %d\n",
Expand Down

0 comments on commit 0a21377

Please sign in to comment.