public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mfd: altr-a10sr: Add Arria10 SR sysfs attributes
@ 2017-02-14 17:53 thor.thayer
  2017-03-07 17:10 ` Thor Thayer
  2017-03-15 10:31 ` Lee Jones
  0 siblings, 2 replies; 4+ messages in thread
From: thor.thayer @ 2017-02-14 17:53 UTC (permalink / raw)
  To: lee.jones; +Cc: thor.thayer, linux-kernel

From: Thor Thayer <thor.thayer@linux.intel.com>

Add the Altera Arria10 DevKit sysfs attributes to the
MFD device. Update copyright and email.

Signed-off-by: Thor Thayer <thor.thayer@linux.intel.com>
---
 drivers/mfd/altera-a10sr.c | 98 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 95 insertions(+), 3 deletions(-)

diff --git a/drivers/mfd/altera-a10sr.c b/drivers/mfd/altera-a10sr.c
index 06e1f7f..8c51818 100644
--- a/drivers/mfd/altera-a10sr.c
+++ b/drivers/mfd/altera-a10sr.c
@@ -1,9 +1,9 @@
 /*
  * Altera Arria10 DevKit System Resource MFD Driver
  *
- * Author: Thor Thayer <tthayer@opensource.altera.com>
+ * Author: Thor Thayer <thor.thayer@linux.intel.com>
  *
- * Copyright Intel Corporation (C) 2014-2016. All Rights Reserved
+ * Copyright Intel Corporation (C) 2014-2017. All Rights Reserved
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -35,6 +35,89 @@
 	},
 };
 
+/* Add sysfs interface for MAX5 System Resource Controller */
+static unsigned int a10sr_reg_addr;
+static ssize_t a10sr_reg_show(struct device *dev,
+			      struct device_attribute *attr, char *buf)
+{
+	return sprintf(buf, "0x%02x\n", a10sr_reg_addr);
+}
+
+static ssize_t a10sr_reg_store(struct device *dev,
+			       struct device_attribute *attr,
+			       const char *buf, size_t count)
+{
+	int ret = kstrtouint(buf, 0, &a10sr_reg_addr);
+
+	if (ret || (a10sr_reg_addr < 0) ||
+	    (a10sr_reg_addr > ALTR_A10SR_PMBUS_REG)) {
+		a10sr_reg_addr = 0;
+		dev_err(dev, "Invalid register address\n");
+		return -EINVAL;
+	}
+	return (ssize_t)count;
+}
+
+static ssize_t a10sr_val_show(struct device *dev,
+			      struct device_attribute *attr, char *buf)
+{
+	int ret;
+	unsigned int val;
+	struct altr_a10sr *a10sr_regs = dev_get_drvdata(dev);
+
+	ret = regmap_read(a10sr_regs->regmap, a10sr_reg_addr, &val);
+	if (ret < 0) {
+		dev_err(dev, "Failed to read 0x%x\n", a10sr_reg_addr);
+		return -EIO;
+	}
+
+	return sprintf(buf, "0x%02x\n", val);
+}
+
+static ssize_t a10sr_val_store(struct device *dev,
+			       struct device_attribute *attr,
+			       const char *buf, size_t count)
+{
+	int ret;
+	unsigned int val;
+	struct altr_a10sr *a10sr_regs = dev_get_drvdata(dev);
+
+	ret = kstrtouint(buf, 0, &val);
+	if (ret)
+		return ret;
+
+	ret = regmap_write(a10sr_regs->regmap, a10sr_reg_addr, val);
+	if (ret) {
+		dev_err(dev, "Failed to write value 0x%02x to address 0x%x",
+			val, a10sr_reg_addr);
+		return -EIO;
+	}
+	return count;
+}
+
+static ssize_t a10sr_version(struct device *dev,
+			     struct device_attribute *devattr, char *buf)
+{
+	a10sr_reg_addr = ALTR_A10SR_VERSION_READ;
+	return a10sr_val_show(dev, devattr, buf);
+}
+
+/* Define FS entries */
+static DEVICE_ATTR(max5_version, 0444, a10sr_version, NULL);
+static DEVICE_ATTR(max5_address, 0644, a10sr_reg_show, a10sr_reg_store);
+static DEVICE_ATTR(max5_value, 0644, a10sr_val_show, a10sr_val_store);
+
+static struct attribute *altr_a10sr_attr[] = {
+	&dev_attr_max5_version.attr,
+	&dev_attr_max5_address.attr,
+	&dev_attr_max5_value.attr,
+	NULL
+};
+
+static const struct attribute_group a10sr_attr_group = {
+	.attrs = altr_a10sr_attr,
+};
+
 static bool altr_a10sr_reg_readable(struct device *dev, unsigned int reg)
 {
 	switch (reg) {
@@ -141,13 +224,22 @@ static int altr_a10sr_spi_probe(struct spi_device *spi)
 		return ret;
 	}
 
+	/* Add the A10SR Registers to the device's sysfs */
+	ret = sysfs_create_group(&a10sr->dev->kobj, &a10sr_attr_group);
+	if (ret) {
+		dev_err(&spi->dev, "unable to create sysfs attributes\n");
+		return ret;
+	}
+
 	ret = devm_mfd_add_devices(a10sr->dev, PLATFORM_DEVID_AUTO,
 				   altr_a10sr_subdev_info,
 				   ARRAY_SIZE(altr_a10sr_subdev_info),
 				   NULL, 0, NULL);
-	if (ret)
+	if (ret) {
 		dev_err(a10sr->dev, "Failed to register sub-devices: %d\n",
 			ret);
+		sysfs_remove_group(&a10sr->dev->kobj, &a10sr_attr_group);
+	}
 
 	return ret;
 }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] mfd: altr-a10sr: Add Arria10 SR sysfs attributes
  2017-02-14 17:53 [PATCH] mfd: altr-a10sr: Add Arria10 SR sysfs attributes thor.thayer
@ 2017-03-07 17:10 ` Thor Thayer
  2017-03-14 10:54   ` Lee Jones
  2017-03-15 10:31 ` Lee Jones
  1 sibling, 1 reply; 4+ messages in thread
From: Thor Thayer @ 2017-03-07 17:10 UTC (permalink / raw)
  To: lee.jones; +Cc: linux-kernel

Hi Lee,

On 02/14/2017 11:53 AM, thor.thayer@linux.intel.com wrote:
> From: Thor Thayer <thor.thayer@linux.intel.com>
>
> Add the Altera Arria10 DevKit sysfs attributes to the
> MFD device. Update copyright and email.
>
> Signed-off-by: Thor Thayer <thor.thayer@linux.intel.com>
> ---
>  drivers/mfd/altera-a10sr.c | 98 ++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 95 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mfd/altera-a10sr.c b/drivers/mfd/altera-a10sr.c
> index 06e1f7f..8c51818 100644
> --- a/drivers/mfd/altera-a10sr.c
> +++ b/drivers/mfd/altera-a10sr.c
> @@ -1,9 +1,9 @@
>  /*
>   * Altera Arria10 DevKit System Resource MFD Driver
>   *
> - * Author: Thor Thayer <tthayer@opensource.altera.com>
> + * Author: Thor Thayer <thor.thayer@linux.intel.com>
>   *
> - * Copyright Intel Corporation (C) 2014-2016. All Rights Reserved
> + * Copyright Intel Corporation (C) 2014-2017. All Rights Reserved
>   *
>   * This program is free software; you can redistribute it and/or modify it
>   * under the terms and conditions of the GNU General Public License,
> @@ -35,6 +35,89 @@
>  	},
>  };
>
> +/* Add sysfs interface for MAX5 System Resource Controller */
> +static unsigned int a10sr_reg_addr;
> +static ssize_t a10sr_reg_show(struct device *dev,
> +			      struct device_attribute *attr, char *buf)
> +{
> +	return sprintf(buf, "0x%02x\n", a10sr_reg_addr);
> +}
> +
> +static ssize_t a10sr_reg_store(struct device *dev,
> +			       struct device_attribute *attr,
> +			       const char *buf, size_t count)
> +{
> +	int ret = kstrtouint(buf, 0, &a10sr_reg_addr);
> +
> +	if (ret || (a10sr_reg_addr < 0) ||
> +	    (a10sr_reg_addr > ALTR_A10SR_PMBUS_REG)) {
> +		a10sr_reg_addr = 0;
> +		dev_err(dev, "Invalid register address\n");
> +		return -EINVAL;
> +	}
> +	return (ssize_t)count;
> +}
> +
> +static ssize_t a10sr_val_show(struct device *dev,
> +			      struct device_attribute *attr, char *buf)
> +{
> +	int ret;
> +	unsigned int val;
> +	struct altr_a10sr *a10sr_regs = dev_get_drvdata(dev);
> +
> +	ret = regmap_read(a10sr_regs->regmap, a10sr_reg_addr, &val);
> +	if (ret < 0) {
> +		dev_err(dev, "Failed to read 0x%x\n", a10sr_reg_addr);
> +		return -EIO;
> +	}
> +
> +	return sprintf(buf, "0x%02x\n", val);
> +}
> +
> +static ssize_t a10sr_val_store(struct device *dev,
> +			       struct device_attribute *attr,
> +			       const char *buf, size_t count)
> +{
> +	int ret;
> +	unsigned int val;
> +	struct altr_a10sr *a10sr_regs = dev_get_drvdata(dev);
> +
> +	ret = kstrtouint(buf, 0, &val);
> +	if (ret)
> +		return ret;
> +
> +	ret = regmap_write(a10sr_regs->regmap, a10sr_reg_addr, val);
> +	if (ret) {
> +		dev_err(dev, "Failed to write value 0x%02x to address 0x%x",
> +			val, a10sr_reg_addr);
> +		return -EIO;
> +	}
> +	return count;
> +}
> +
> +static ssize_t a10sr_version(struct device *dev,
> +			     struct device_attribute *devattr, char *buf)
> +{
> +	a10sr_reg_addr = ALTR_A10SR_VERSION_READ;
> +	return a10sr_val_show(dev, devattr, buf);
> +}
> +
> +/* Define FS entries */
> +static DEVICE_ATTR(max5_version, 0444, a10sr_version, NULL);
> +static DEVICE_ATTR(max5_address, 0644, a10sr_reg_show, a10sr_reg_store);
> +static DEVICE_ATTR(max5_value, 0644, a10sr_val_show, a10sr_val_store);
> +
> +static struct attribute *altr_a10sr_attr[] = {
> +	&dev_attr_max5_version.attr,
> +	&dev_attr_max5_address.attr,
> +	&dev_attr_max5_value.attr,
> +	NULL
> +};
> +
> +static const struct attribute_group a10sr_attr_group = {
> +	.attrs = altr_a10sr_attr,
> +};
> +
>  static bool altr_a10sr_reg_readable(struct device *dev, unsigned int reg)
>  {
>  	switch (reg) {
> @@ -141,13 +224,22 @@ static int altr_a10sr_spi_probe(struct spi_device *spi)
>  		return ret;
>  	}
>
> +	/* Add the A10SR Registers to the device's sysfs */
> +	ret = sysfs_create_group(&a10sr->dev->kobj, &a10sr_attr_group);
> +	if (ret) {
> +		dev_err(&spi->dev, "unable to create sysfs attributes\n");
> +		return ret;
> +	}
> +
>  	ret = devm_mfd_add_devices(a10sr->dev, PLATFORM_DEVID_AUTO,
>  				   altr_a10sr_subdev_info,
>  				   ARRAY_SIZE(altr_a10sr_subdev_info),
>  				   NULL, 0, NULL);
> -	if (ret)
> +	if (ret) {
>  		dev_err(a10sr->dev, "Failed to register sub-devices: %d\n",
>  			ret);
> +		sysfs_remove_group(&a10sr->dev->kobj, &a10sr_attr_group);
> +	}
>
>  	return ret;
>  }
>
Any comments on this patch?

Thanks,

Thor

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mfd: altr-a10sr: Add Arria10 SR sysfs attributes
  2017-03-07 17:10 ` Thor Thayer
@ 2017-03-14 10:54   ` Lee Jones
  0 siblings, 0 replies; 4+ messages in thread
From: Lee Jones @ 2017-03-14 10:54 UTC (permalink / raw)
  To: Thor Thayer; +Cc: linux-kernel

On Tue, 07 Mar 2017, Thor Thayer wrote:
> Hi Lee,
> 
> On 02/14/2017 11:53 AM, thor.thayer@linux.intel.com wrote:
> > From: Thor Thayer <thor.thayer@linux.intel.com>

[...]

> Any comments on this patch?

Just returned from vacation.

I'm on it!

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mfd: altr-a10sr: Add Arria10 SR sysfs attributes
  2017-02-14 17:53 [PATCH] mfd: altr-a10sr: Add Arria10 SR sysfs attributes thor.thayer
  2017-03-07 17:10 ` Thor Thayer
@ 2017-03-15 10:31 ` Lee Jones
  1 sibling, 0 replies; 4+ messages in thread
From: Lee Jones @ 2017-03-15 10:31 UTC (permalink / raw)
  To: thor.thayer; +Cc: linux-kernel

On Tue, 14 Feb 2017, thor.thayer@linux.intel.com wrote:

> From: Thor Thayer <thor.thayer@linux.intel.com>
> 
> Add the Altera Arria10 DevKit sysfs attributes to the
> MFD device. Update copyright and email.
> 
> Signed-off-by: Thor Thayer <thor.thayer@linux.intel.com>
> ---
>  drivers/mfd/altera-a10sr.c | 98 ++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 95 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/mfd/altera-a10sr.c b/drivers/mfd/altera-a10sr.c
> index 06e1f7f..8c51818 100644
> --- a/drivers/mfd/altera-a10sr.c
> +++ b/drivers/mfd/altera-a10sr.c
> @@ -1,9 +1,9 @@
>  /*
>   * Altera Arria10 DevKit System Resource MFD Driver
>   *
> - * Author: Thor Thayer <tthayer@opensource.altera.com>
> + * Author: Thor Thayer <thor.thayer@linux.intel.com>
>   *
> - * Copyright Intel Corporation (C) 2014-2016. All Rights Reserved
> + * Copyright Intel Corporation (C) 2014-2017. All Rights Reserved
>   *
>   * This program is free software; you can redistribute it and/or modify it
>   * under the terms and conditions of the GNU General Public License,
> @@ -35,6 +35,89 @@
>  	},
>  };
>  
> +/* Add sysfs interface for MAX5 System Resource Controller */
> +static unsigned int a10sr_reg_addr;
> +static ssize_t a10sr_reg_show(struct device *dev,
> +			      struct device_attribute *attr, char *buf)
> +{
> +	return sprintf(buf, "0x%02x\n", a10sr_reg_addr);
> +}
> +
> +static ssize_t a10sr_reg_store(struct device *dev,
> +			       struct device_attribute *attr,
> +			       const char *buf, size_t count)
> +{
> +	int ret = kstrtouint(buf, 0, &a10sr_reg_addr);
> +
> +	if (ret || (a10sr_reg_addr < 0) ||
> +	    (a10sr_reg_addr > ALTR_A10SR_PMBUS_REG)) {
> +		a10sr_reg_addr = 0;
> +		dev_err(dev, "Invalid register address\n");
> +		return -EINVAL;
> +	}
> +	return (ssize_t)count;
> +}

I don't think we can allow this.  Allowing users to read and write
directly to registers from userspace is a really bad idea. 

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-03-15 10:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-14 17:53 [PATCH] mfd: altr-a10sr: Add Arria10 SR sysfs attributes thor.thayer
2017-03-07 17:10 ` Thor Thayer
2017-03-14 10:54   ` Lee Jones
2017-03-15 10:31 ` Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox