From: Lee Jones <lee.jones@linaro.org>
To: Holger Dengler <dengler@linutronix.de>
Cc: linux-kernel@vger.kernel.org, Peter Mahler <mahler@xkrug.com>,
Juergen Bubeck <bubeck@xkrug.com>,
Benedikt Spranger <b.spranger@linutronix.de>,
Samuel Ortiz <sameo@linux.intel.com>
Subject: Re: [PATCH 03/11] mfd: flexcard: add device attributes
Date: Mon, 30 Mar 2015 09:15:56 +0100 [thread overview]
Message-ID: <20150330081556.GN457@x1> (raw)
In-Reply-To: <1427277120-16924-4-git-send-email-dengler@linutronix.de>
On Wed, 25 Mar 2015, Holger Dengler wrote:
> From: Benedikt Spranger <b.spranger@linutronix.de>
>
> Add device attributes for common flexcard information access. The
> attribiutes are read-only execpt "uid" (user ID register).
> The "uid" attribute can also be used to change the user-defined ID of a
> Flexcard.
>
> Signed-off-by: Holger Dengler <dengler@linutronix.de>
> Signed-off-by: Benedikt Spranger <b.spranger@linutronix.de>
> cc: Samuel Ortiz <sameo@linux.intel.com>
> cc: Lee Jones <lee.jones@linaro.org>
> ---
> drivers/mfd/flexcard/Makefile | 2 +-
> drivers/mfd/flexcard/attr.c | 215 ++++++++++++++++++++++++++++++++++++++++
> drivers/mfd/flexcard/core.c | 11 ++
I suggest this too should be part of the 'misc' driver and I wouldn't
split out attr fn()s into a separate file.
</review>
> drivers/mfd/flexcard/flexcard.h | 7 ++
> 4 files changed, 234 insertions(+), 1 deletion(-)
> create mode 100644 drivers/mfd/flexcard/attr.c
> create mode 100644 drivers/mfd/flexcard/flexcard.h
>
> diff --git a/drivers/mfd/flexcard/Makefile b/drivers/mfd/flexcard/Makefile
> index 6606ebb..101000f 100644
> --- a/drivers/mfd/flexcard/Makefile
> +++ b/drivers/mfd/flexcard/Makefile
> @@ -1,2 +1,2 @@
> obj-$(CONFIG_MFD_FLEXCARD) += flexcard.o
> -flexcard-objs := core.o
> +flexcard-objs := core.o attr.o
> diff --git a/drivers/mfd/flexcard/attr.c b/drivers/mfd/flexcard/attr.c
> new file mode 100644
> index 0000000..c91c884
> --- /dev/null
> +++ b/drivers/mfd/flexcard/attr.c
> @@ -0,0 +1,215 @@
> +/*
> + * Eberspaecher Flexcard PMC II Carrier Board PCI Driver - device attributes
> + *
> + * Copyright (c) 2014,2015 Linutronix GmbH
> + * Author: Holger Dengler
> + * Benedikt Spranger
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU General Public License version 2 as published
> + * by the Free Software Foundation.
> + */
> +#include <linux/device.h>
> +#include <linux/flexcard.h>
> +#include <linux/kref.h>
> +#include <linux/miscdevice.h>
> +#include <linux/pci.h>
> +#include <linux/mfd/flexcard.h>
> +
> +static ssize_t fw_version_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct pci_dev *pdev = to_pci_dev(dev->parent);
> + struct flexcard_device *priv = pci_get_drvdata(pdev);
> +
> + return sprintf(buf, "%02x.%02x.%02x\n", priv->conf->fc_fw_ver.maj,
> + priv->conf->fc_fw_ver.min, priv->conf->fc_fw_ver.dev);
> +}
> +static DEVICE_ATTR_RO(fw_version);
> +
> +static ssize_t hw_version_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct pci_dev *pdev = to_pci_dev(dev->parent);
> + struct flexcard_device *priv = pci_get_drvdata(pdev);
> +
> + return sprintf(buf, "%02x.%02x.%02x\n", priv->conf->fc_hw_ver.maj,
> + priv->conf->fc_hw_ver.min, priv->conf->fc_hw_ver.dev);
> +}
> +static DEVICE_ATTR_RO(hw_version);
> +
> +static ssize_t serialno_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct pci_dev *pdev = to_pci_dev(dev->parent);
> + struct flexcard_device *priv = pci_get_drvdata(pdev);
> +
> + return sprintf(buf, "%lld\n", priv->conf->fc_sn);
> +}
> +static DEVICE_ATTR_RO(serialno);
> +
> +static ssize_t tiny_stat_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct pci_dev *pdev = to_pci_dev(dev->parent);
> + struct flexcard_device *priv = pci_get_drvdata(pdev);
> +
> + return sprintf(buf, "0x%x\n", priv->conf->tiny_stat);
> +}
> +static DEVICE_ATTR_RO(tiny_stat);
> +
> +static ssize_t can_dat_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct pci_dev *pdev = to_pci_dev(dev->parent);
> + struct flexcard_device *priv = pci_get_drvdata(pdev);
> +
> + return sprintf(buf, "%d\n", priv->conf->can_dat_cnt);
> +}
> +static DEVICE_ATTR_RO(can_dat);
> +
> +static ssize_t can_err_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct pci_dev *pdev = to_pci_dev(dev->parent);
> + struct flexcard_device *priv = pci_get_drvdata(pdev);
> +
> + return sprintf(buf, "%d\n", priv->conf->can_err_cnt);
> +}
> +static DEVICE_ATTR_RO(can_err);
> +
> +static ssize_t fc_data_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct pci_dev *pdev = to_pci_dev(dev->parent);
> + struct flexcard_device *priv = pci_get_drvdata(pdev);
> +
> + return sprintf(buf, "%d\n", priv->conf->fc_data_cnt);
> +}
> +static DEVICE_ATTR_RO(fc_data);
> +
> +static ssize_t fr_rx_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct pci_dev *pdev = to_pci_dev(dev->parent);
> + struct flexcard_device *priv = pci_get_drvdata(pdev);
> +
> + return sprintf(buf, "%d\n", priv->conf->fr_rx_cnt);
> +}
> +static DEVICE_ATTR_RO(fr_rx);
> +
> +static ssize_t fr_tx_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct pci_dev *pdev = to_pci_dev(dev->parent);
> + struct flexcard_device *priv = pci_get_drvdata(pdev);
> +
> + return sprintf(buf, "%d\n", priv->conf->fr_tx_cnt);
> +}
> +static DEVICE_ATTR_RO(fr_tx);
> +
> +static ssize_t nmv_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct pci_dev *pdev = to_pci_dev(dev->parent);
> + struct flexcard_device *priv = pci_get_drvdata(pdev);
> +
> + return sprintf(buf, "%d\n", priv->conf->nmv_cnt);
> +}
> +static DEVICE_ATTR_RO(nmv);
> +
> +static ssize_t info_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct pci_dev *pdev = to_pci_dev(dev->parent);
> + struct flexcard_device *priv = pci_get_drvdata(pdev);
> +
> + return sprintf(buf, "%d\n", priv->conf->info_cnt);
> +}
> +static DEVICE_ATTR_RO(info);
> +
> +static ssize_t stat_trg_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct pci_dev *pdev = to_pci_dev(dev->parent);
> + struct flexcard_device *priv = pci_get_drvdata(pdev);
> +
> + return sprintf(buf, "%d\n", priv->conf->stat_trg_cnt);
> +}
> +static DEVICE_ATTR_RO(stat_trg);
> +
> +static ssize_t nf_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct pci_dev *pdev = to_pci_dev(dev->parent);
> + struct flexcard_device *priv = pci_get_drvdata(pdev);
> +
> + return sprintf(buf, "%d\n", priv->conf->nf_cnt);
> +}
> +static DEVICE_ATTR_RO(nf);
> +
> +static ssize_t uid_store(struct device *dev, struct device_attribute *attr,
> + const char *buf, size_t count)
> +{
> + struct pci_dev *pdev = to_pci_dev(dev->parent);
> + struct flexcard_device *priv = pci_get_drvdata(pdev);
> + unsigned long uid;
> + int ret;
> +
> + ret = kstrtou32(buf, 0, &uid);
> + if (ret)
> + return ret;
> +
> + priv->conf->fc_uid = uid;
> + return count;
> +}
> +
> +static ssize_t uid_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct pci_dev *pdev = to_pci_dev(dev->parent);
> + struct flexcard_device *priv = pci_get_drvdata(pdev);
> +
> + return sprintf(buf, "%u\n", priv->conf->fc_uid);
> +}
> +static DEVICE_ATTR(uid, S_IRUGO|S_IWUSR, uid_show, uid_store);
> +
> +static struct attribute *flexcard_misc_dev_attrs[] = {
> + &dev_attr_fw_version.attr,
> + &dev_attr_hw_version.attr,
> + &dev_attr_serialno.attr,
> + &dev_attr_tiny_stat.attr,
> + &dev_attr_can_dat.attr,
> + &dev_attr_can_err.attr,
> + &dev_attr_fc_data.attr,
> + &dev_attr_fr_rx.attr,
> + &dev_attr_fr_tx.attr,
> + &dev_attr_nmv.attr,
> + &dev_attr_info.attr,
> + &dev_attr_stat_trg.attr,
> + &dev_attr_nf.attr,
> + &dev_attr_uid.attr,
> + NULL,
> +};
> +
> +static const struct attribute_group flexcard_misc_dev_group = {
> + .attrs = flexcard_misc_dev_attrs,
> +};
> +
> +int flexcard_misc_add_attrs(struct device *dev)
> +{
> + int ret;
> +
> + ret = sysfs_create_group(&dev->kobj,
> + &flexcard_misc_dev_group);
> +
> + if (ret)
> + dev_err(dev, "failed to create sysfs attributes: %d\n", ret);
> +
> + return ret;
> +}
> +
> +void flexcard_misc_del_attrs(struct device *dev)
> +{
> + sysfs_remove_group(&dev->kobj, &flexcard_misc_dev_group);
> +}
> diff --git a/drivers/mfd/flexcard/core.c b/drivers/mfd/flexcard/core.c
> index 1e7fb0f..6477019 100644
> --- a/drivers/mfd/flexcard/core.c
> +++ b/drivers/mfd/flexcard/core.c
> @@ -22,6 +22,8 @@
> #include <linux/mfd/core.h>
> #include <linux/mfd/flexcard.h>
>
> +#include "flexcard.h"
> +
> static DEFINE_IDA(flexcard_ida);
>
> static const char drv_name[] = "flexcard";
> @@ -237,6 +239,12 @@ static int flexcard_probe(struct pci_dev *pdev,
> goto out_remove;
> }
>
> + ret = flexcard_misc_add_attrs(priv->dev.this_device);
> + if (ret) {
> + dev_err(&pdev->dev, "unable to register miscdevice: %d\n", ret);
> + goto out_deregister;
> + }
> +
> dev_info(&pdev->dev, "HW %02x.%02x.%02x FW %02x.%02x.%02x\n",
> priv->conf->fc_hw_ver.maj, priv->conf->fc_hw_ver.min,
> priv->conf->fc_hw_ver.dev, priv->conf->fc_fw_ver.maj,
> @@ -244,6 +252,8 @@ static int flexcard_probe(struct pci_dev *pdev,
>
> return 0;
>
> +out_deregister:
> + misc_deregister(&priv->dev);
> out_remove:
> mfd_remove_devices(&pdev->dev);
> out_unmap:
> @@ -264,6 +274,7 @@ static void flexcard_remove(struct pci_dev *pdev)
> {
> struct flexcard_device *priv = pci_get_drvdata(pdev);
>
> + flexcard_misc_del_attrs(priv->dev.this_device);
> misc_deregister(&priv->dev);
> mfd_remove_devices(&pdev->dev);
> iounmap(priv->conf);
> diff --git a/drivers/mfd/flexcard/flexcard.h b/drivers/mfd/flexcard/flexcard.h
> new file mode 100644
> index 0000000..1fe451e
> --- /dev/null
> +++ b/drivers/mfd/flexcard/flexcard.h
> @@ -0,0 +1,7 @@
> +#ifndef __FLEXCARD_H
> +#define __FLEXCARD_H
> +
> +int flexcard_misc_add_attrs(struct device *dev);
> +void flexcard_misc_del_attrs(struct device *dev);
> +
> +#endif /* __FLEXCARD_H */
--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
next prev parent reply other threads:[~2015-03-30 8:16 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-25 9:51 [PATCH 00/11] Eberspaecher Flexcard PMC II base support Holger Dengler
2015-03-25 9:51 ` [PATCH 01/11] mfd: Eberspaecher Flexcard PMC II Carrier Board support Holger Dengler
2015-03-30 7:57 ` Lee Jones
2015-03-25 9:51 ` [PATCH 02/11] mfd: flexcard: add flexcard core device Holger Dengler
2015-03-30 8:06 ` Lee Jones
2015-03-25 9:51 ` [PATCH 03/11] mfd: flexcard: add device attributes Holger Dengler
2015-03-30 8:15 ` Lee Jones [this message]
2015-03-25 9:51 ` [PATCH 04/11] mfd: flexcard: add clocksrc device Holger Dengler
2015-03-30 8:30 ` Lee Jones
2015-03-25 9:51 ` [PATCH 05/11] mfd: flexcard: add interrupt support Holger Dengler
2015-03-30 8:46 ` Lee Jones
2015-03-25 9:51 ` [PATCH 06/11] mfd: flexcard: add DMA interrupt domain Holger Dengler
2015-03-30 8:50 ` Lee Jones
2015-03-25 9:51 ` [PATCH 07/11] mfd: flexcard: add UIO IRQ devices Holger Dengler
2015-03-30 8:57 ` Lee Jones
2015-03-25 9:51 ` [PATCH 08/11] mfd: flexcard: add DMA device Holger Dengler
2015-03-30 8:59 ` Lee Jones
2015-03-25 9:51 ` [PATCH 09/11] mfd: flexcard: add DMA ringbuffer demux driver Holger Dengler
2015-03-30 9:02 ` Lee Jones
2015-03-25 9:51 ` [PATCH 10/11] clocksource: flexcard: Add basic timestamp counter support Holger Dengler
2015-03-26 9:41 ` Daniel Lezcano
2015-03-26 11:01 ` Holger Dengler
2015-03-26 16:34 ` John Stultz
2015-03-27 12:27 ` Holger Dengler
2015-03-25 9:52 ` [PATCH 11/11] clocksource: flexcard: Support timestamp trigger selection Holger Dengler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150330081556.GN457@x1 \
--to=lee.jones@linaro.org \
--cc=b.spranger@linutronix.de \
--cc=bubeck@xkrug.com \
--cc=dengler@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=mahler@xkrug.com \
--cc=sameo@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.