* [PATCH] i2c: mux: demux-pinctrl: Clean up sysfs attributes
@ 2016-03-31 15:40 Ben Hutchings
2016-04-01 10:59 ` Wolfram Sang
0 siblings, 1 reply; 2+ messages in thread
From: Ben Hutchings @ 2016-03-31 15:40 UTC (permalink / raw)
To: Wolfram Sang; +Cc: linux-i2c, CT kernel, Ben Dooks
sysfs attributes should use the same format for reads and writes,
rather than pretty-printing on read.
* Make the "cur_master" attribute read back as just the name of the
master
* Expose the list of all masters as a read-only "available_masters"
attribute, using space separators as in similar attributes of other
devices
Also, spell out "cur_master" in full as "current_master".
Fixes: 50a5ba876908 ("i2c: mux: demux-pinctrl: add driver")
Cc: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
---
drivers/i2c/muxes/i2c-demux-pinctrl.c | 39 ++++++++++++++++++++++++++---------
1 file changed, 29 insertions(+), 10 deletions(-)
diff --git a/drivers/i2c/muxes/i2c-demux-pinctrl.c b/drivers/i2c/muxes/i2c-demux-pinctrl.c
index 7748a0a5ddb9..8de073aed001 100644
--- a/drivers/i2c/muxes/i2c-demux-pinctrl.c
+++ b/drivers/i2c/muxes/i2c-demux-pinctrl.c
@@ -140,22 +140,34 @@ static int i2c_demux_change_master(struct i2c_demux_pinctrl_priv *priv, u32 new_
return i2c_demux_activate_master(priv, new_chan);
}
-static ssize_t cur_master_show(struct device *dev, struct device_attribute *attr,
- char *buf)
+static ssize_t available_masters_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
{
struct i2c_demux_pinctrl_priv *priv = dev_get_drvdata(dev);
int count = 0, i;
for (i = 0; i < priv->num_chan && count < PAGE_SIZE; i++)
- count += scnprintf(buf + count, PAGE_SIZE - count, "%c %d - %s\n",
- i == priv->cur_chan ? '*' : ' ', i,
- priv->chan[i].parent_np->full_name);
+ count += scnprintf(buf + count, PAGE_SIZE - count, "%d:%s%c",
+ i, priv->chan[i].parent_np->full_name,
+ i == priv->num_chan - 1 ? '\n' : ' ');
return count;
}
+static DEVICE_ATTR_RO(available_masters);
-static ssize_t cur_master_store(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t count)
+static ssize_t current_master_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct i2c_demux_pinctrl_priv *priv = dev_get_drvdata(dev);
+
+ return sprintf(buf, "%d\n", priv->cur_chan);
+}
+
+static ssize_t current_master_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
{
struct i2c_demux_pinctrl_priv *priv = dev_get_drvdata(dev);
unsigned int val;
@@ -172,7 +184,7 @@ static ssize_t cur_master_store(struct device *dev, struct device_attribute *att
return ret < 0 ? ret : count;
}
-static DEVICE_ATTR_RW(cur_master);
+static DEVICE_ATTR_RW(current_master);
static int i2c_demux_pinctrl_probe(struct platform_device *pdev)
{
@@ -218,12 +230,18 @@ static int i2c_demux_pinctrl_probe(struct platform_device *pdev)
/* switch to first parent as active master */
i2c_demux_activate_master(priv, 0);
- err = device_create_file(&pdev->dev, &dev_attr_cur_master);
+ err = device_create_file(&pdev->dev, &dev_attr_available_masters);
if (err)
goto err_rollback;
+ err = device_create_file(&pdev->dev, &dev_attr_current_master);
+ if (err)
+ goto err_rollback_available;
+
return 0;
+err_rollback_available:
+ device_remove_file(&pdev->dev, &dev_attr_available_masters);
err_rollback:
for (j = 0; j < i; j++) {
of_node_put(priv->chan[j].parent_np);
@@ -238,7 +256,8 @@ static int i2c_demux_pinctrl_remove(struct platform_device *pdev)
struct i2c_demux_pinctrl_priv *priv = platform_get_drvdata(pdev);
int i;
- device_remove_file(&pdev->dev, &dev_attr_cur_master);
+ device_remove_file(&pdev->dev, &dev_attr_current_master);
+ device_remove_file(&pdev->dev, &dev_attr_available_masters);
i2c_demux_deactivate_master(priv);
--
Ben Hutchings
Software Developer, Codethink Ltd.
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] i2c: mux: demux-pinctrl: Clean up sysfs attributes
2016-03-31 15:40 [PATCH] i2c: mux: demux-pinctrl: Clean up sysfs attributes Ben Hutchings
@ 2016-04-01 10:59 ` Wolfram Sang
0 siblings, 0 replies; 2+ messages in thread
From: Wolfram Sang @ 2016-04-01 10:59 UTC (permalink / raw)
To: Ben Hutchings; +Cc: linux-i2c, CT kernel, Ben Dooks
[-- Attachment #1: Type: text/plain, Size: 705 bytes --]
On Thu, Mar 31, 2016 at 04:40:05PM +0100, Ben Hutchings wrote:
> sysfs attributes should use the same format for reads and writes,
> rather than pretty-printing on read.
>
> * Make the "cur_master" attribute read back as just the name of the
> master
> * Expose the list of all masters as a read-only "available_masters"
> attribute, using space separators as in similar attributes of other
> devices
>
> Also, spell out "cur_master" in full as "current_master".
>
> Fixes: 50a5ba876908 ("i2c: mux: demux-pinctrl: add driver")
> Cc: Wolfram Sang <wsa+renesas@sang-engineering.com>
> Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
Applied to for-current, thanks!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-04-01 11:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-31 15:40 [PATCH] i2c: mux: demux-pinctrl: Clean up sysfs attributes Ben Hutchings
2016-04-01 10:59 ` Wolfram Sang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).