Skip to content
Snippets Groups Projects
Commit 1afdf002 authored by Dietmar Muscholik's avatar Dietmar Muscholik
Browse files

drivers:seco-stm32.c: some info about stm32 made available through sysfs

 - firmware version and chip-id of the stm32 can be read from sysfs
 - in difference to other gpio controlers the stm32 can serve as interrupt-
   controler without having gpios configured
parent ff3fa159
No related branches found
No related tags found
1 merge request!496drivers:seco-stm32.c: some info about stm32 made available through sysfs
Pipeline #121493 passed with stage
in 53 seconds
......@@ -45,6 +45,7 @@ struct stm32 {
struct mutex lock;
int irq_base;
int irq_map[STM32_IRQ_MAX];
unsigned char chip_id, fw_ver;
//unsigned int irq_mask;
//struct mutex i2c_lock;
//struct mutex irq_lock;
......@@ -466,6 +467,27 @@ static void stm32_irq_flow_handler(struct irq_desc *desc)
}
#endif
// sysfs
// can be found in /sys/bus/i2c/devices/b-aaaa
// were b is the bus number and aaaa is the address in hex
static ssize_t fw_ver_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct stm32 *stm32=dev_get_drvdata(dev);
return sprintf(buf, "0x%02hhx\n",stm32->fw_ver);
}
static DEVICE_ATTR_RO(fw_ver);
static ssize_t chip_id_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct stm32 *stm32=dev_get_drvdata(dev);
return sprintf(buf, "0x%02hhx\n",stm32->chip_id);
}
static DEVICE_ATTR_RO(chip_id);
// parse the device tree
//static int stm32_parse_dt(struct device *dev, struct stm32 *stm32)
static int stm32_parse_dt(struct i2c_client *client, struct stm32 *stm32)
......@@ -598,6 +620,13 @@ static int stm32_probe(struct i2c_client *client,
struct stm32 *stm32;
dev_info(dev,"%s\n", __FUNCTION__);
// allocate memory for private data
stm32=devm_kzalloc(dev, sizeof(*stm32), GFP_KERNEL);
if(!stm32)
return -ENOMEM;
stm32->pwm_chip.dev=dev;
// read the chip id
err=i2c_xfer(client, STM32_READ, STM32_REG_ID, 0);
if(err < 0)
......@@ -612,6 +641,7 @@ static int stm32_probe(struct i2c_client *client,
dev_err(dev, "%s: invalid chip id (0x%02x)\n", __FUNCTION__, err);
return -ENOENT;
}
stm32->chip_id=(unsigned char)err;
dev_info(dev, "%s: chip id: 0x%02x\n", __FUNCTION__, err);
// read firmware version
......@@ -622,19 +652,15 @@ static int stm32_probe(struct i2c_client *client,
__FUNCTION__, err);
return err;
}
stm32->fw_ver=(unsigned char)err;
dev_info(dev,"%s: firmware 0x%02x\n", __FUNCTION__, err);
// allocate memory for private data and fill it from the device tree
stm32=devm_kzalloc(dev, sizeof(*stm32), GFP_KERNEL);
if(!stm32)
return -ENOMEM;
stm32->pwm_chip.dev=dev;
// fill private data from the device tree
err=stm32_parse_dt(client, stm32);
if(err)
return err;
if(!stm32->pwm_chip.npwm && !stm32->gpio_chip.ngpio)
if(!stm32->pwm_chip.npwm && !stm32->gpio_chip.ngpio && !client->irq)
return -ENOENT;
mutex_init(&stm32->lock);
dev_set_drvdata(dev, stm32);
......@@ -695,6 +721,10 @@ static int stm32_probe(struct i2c_client *client,
return err;
}
// add sysfs entries
device_create_file(dev, &dev_attr_chip_id);
device_create_file(dev, &dev_attr_fw_ver);
dev_info(dev, "%s: OK\n", __FUNCTION__);
return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment