diff options
author | Bhuvanchandra DV <bhuvanchandra.dv@toradex.com> | 2016-03-30 01:20:43 +0530 |
---|---|---|
committer | Stefan Agner <stefan.agner@toradex.com> | 2016-03-29 22:57:03 -0700 |
commit | 88c66ffd8ed6cd50e436ce0d5830cd27f93259a2 (patch) | |
tree | 77738ca8d8167a23f38dd5fbc9c29f2da9529a3e /drivers | |
parent | b84a7643279332aca39d4be85d47c0734802c91e (diff) |
spi core: Add new sysfs 'num_chipselect' fileColibri_VF_LinuxImageV2.6Beta1_20160331
Add new sysfs 'num_chipselect' file to expose the maximum number
of chipselects a SPI master can support.
This allows to create a script in user space which automatically
creates a new spidev instance for every chipselect on a bus.
Signed-off-by: Bhuvanchandra DV <bhuvanchandra.dv@toradex.com>
Signed-off-by: Stefan Agner <stefan.agner@toradex.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/spi/spi.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index dee1cb87d24f..06fb3dd1b297 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -67,6 +67,19 @@ modalias_show(struct device *dev, struct device_attribute *a, char *buf) } static DEVICE_ATTR_RO(modalias); +static ssize_t +num_chipselect_show(struct device *dev, struct device_attribute *a, char *buf) +{ + struct spi_master *master = container_of(dev, + struct spi_master, dev); + + return sprintf(buf, "%d\n", master->num_chipselect); +} +static struct device_attribute dev_attr_num_chipselect = { + .attr = { .name = "num_chipselect", .mode = S_IRUGO }, + .show = num_chipselect_show, +}; + #define SPI_STATISTICS_ATTRS(field, file) \ static ssize_t spi_master_##field##_show(struct device *dev, \ struct device_attribute *attr, \ @@ -154,6 +167,15 @@ static const struct attribute_group spi_dev_group = { .attrs = spi_dev_attrs, }; +static struct attribute *spi_master_attrs[] = { + &dev_attr_num_chipselect.attr, + NULL, +}; + +static const struct attribute_group spi_master_group = { + .attrs = spi_master_attrs, +}; + static struct attribute *spi_device_statistics_attrs[] = { &dev_attr_spi_device_messages.attr, &dev_attr_spi_device_transfers.attr, @@ -233,6 +255,7 @@ static const struct attribute_group spi_master_statistics_group = { }; static const struct attribute_group *spi_master_groups[] = { + &spi_master_group, &spi_master_statistics_group, NULL, }; |