[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1481674313-30378-3-git-send-email-dengler@linutronix.de>
Date: Wed, 14 Dec 2016 01:11:43 +0100
From: Holger Dengler <dengler@...utronix.de>
To: Lee Jones <lee.jones@...aro.org>, Arnd Bergmann <arnd@...db.de>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Vinod Koul <vinod.koul@...el.com>
Cc: linux-kernel@...r.kernel.org, dmaengine@...r.kernel.org,
Thomas Gleixner <tglx@...utronix.de>,
Sebastian Siewior <bigeasy@...utronix.de>,
Juergen Bubeck <bubeck@...ug.com>,
Peter Mahler <mahler@...ug.com>,
Holger Dengler <dengler@...utronix.de>,
Benedikt Spranger <b.spranger@...utronix.de>
Subject: [PATCH 02/12] mfd: flexcard: add flexcard misc mfd-cell
The Flexcard PCI BAR0 contain registers for configuration and
informational purpose. Add an appropriate MFD-cell for these registers.
Signed-off-by: Benedikt Spranger <b.spranger@...utronix.de>
Signed-off-by: Holger Dengler <dengler@...utronix.de>
cc: Lee Jones <lee.jones@...aro.org>
---
drivers/mfd/flexcard_core.c | 58 +++++++++++++++++++++++++++++++++++++++++++-
include/linux/mfd/flexcard.h | 1 +
2 files changed, 58 insertions(+), 1 deletion(-)
diff --git a/drivers/mfd/flexcard_core.c b/drivers/mfd/flexcard_core.c
index e580971..2ee9089 100644
--- a/drivers/mfd/flexcard_core.c
+++ b/drivers/mfd/flexcard_core.c
@@ -11,6 +11,7 @@
*/
#include <linux/init.h>
+#include <linux/ioport.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/pci.h>
@@ -25,11 +26,48 @@
#define FLEXCARD_FR_OFFSET 0x4000
#define FLEXCARD_FR_SIZE 0x2000
+#define FLEXCARD_CONF_START 0x000
+#define FLEXCARD_CONF_SIZE 0x13F
+#define FLEXCARD_NF_START 0x170
+#define FLEXCARD_NF_SIZE 0x7
+
+static DEFINE_IDA(flexcard_ida);
+
+static struct resource flexcard_misc_res[] = {
+ DEFINE_RES_MEM_NAMED(FLEXCARD_CONF_START,
+ FLEXCARD_CONF_SIZE,
+ "flexcard-conf"),
+ DEFINE_RES_MEM_NAMED(FLEXCARD_NF_START,
+ FLEXCARD_NF_SIZE,
+ "flexcard-nf"),
+};
+
+static struct mfd_cell flexcard_misc_dev[] = {
+ {
+ .name = "flexcard-misc",
+ .num_resources = ARRAY_SIZE(flexcard_misc_res),
+ .resources = flexcard_misc_res,
+ },
+};
+
enum flexcard_cell_id {
FLEXCARD_CELL_CAN,
FLEXCARD_CELL_FLEXRAY,
};
+static int flexcard_misc_setup(struct flexcard_device *priv)
+{
+ struct pci_dev *pdev = priv->pdev;
+
+ flexcard_misc_dev[0].id = priv->cardnr;
+ flexcard_misc_res[0].parent = &pdev->resource[0];
+ flexcard_misc_res[1].parent = &pdev->resource[0];
+
+ return mfd_add_devices(&pdev->dev, 0, flexcard_misc_dev,
+ ARRAY_SIZE(flexcard_misc_dev),
+ &pdev->resource[0], 0, NULL);
+}
+
static int flexcard_tiny_can(struct flexcard_device *priv,
int idx, int id, u32 offset)
{
@@ -163,10 +201,23 @@ static int flexcard_probe(struct pci_dev *pdev,
fw_ver.reg = readl(&priv->bar0->conf.fc_fw_ver);
hw_ver.reg = readl(&priv->bar0->conf.fc_hw_ver);
+ ret = ida_simple_get(&flexcard_ida, 0, 0, GFP_KERNEL);
+ if (ret < 0) {
+ dev_err(&pdev->dev, "could not get new Flexcard id:%d\n", ret);
+ goto out_unmap;
+ }
+ priv->cardnr = ret;
+
ret = flexcard_tiny_probe(priv);
if (ret) {
dev_err(&pdev->dev, "unable to probe tinys: %d", ret);
- goto out_unmap;
+ goto out_ida;
+ }
+
+ ret = flexcard_misc_setup(priv);
+ if (ret) {
+ dev_err(&pdev->dev, "unable to probe tinys: %d", ret);
+ goto out_mfd_dev_remove;
}
dev_info(&pdev->dev, "HW %02x.%02x.%02x FW %02x.%02x.%02x\n",
@@ -175,6 +226,10 @@ static int flexcard_probe(struct pci_dev *pdev,
return 0;
+out_mfd_dev_remove:
+ mfd_remove_devices(&pdev->dev);
+out_ida:
+ ida_simple_remove(&flexcard_ida, priv->cardnr);
out_unmap:
iounmap(priv->bar0);
out_release:
@@ -190,6 +245,7 @@ static void flexcard_remove(struct pci_dev *pdev)
struct flexcard_device *priv = pci_get_drvdata(pdev);
mfd_remove_devices(&pdev->dev);
+ ida_simple_remove(&flexcard_ida, priv->cardnr);
iounmap(priv->bar0);
pci_release_regions(pdev);
pci_disable_device(pdev);
diff --git a/include/linux/mfd/flexcard.h b/include/linux/mfd/flexcard.h
index 362b909..4116305 100644
--- a/include/linux/mfd/flexcard.h
+++ b/include/linux/mfd/flexcard.h
@@ -94,6 +94,7 @@ struct fc_bar0 {
} __packed;
struct flexcard_device {
+ unsigned int cardnr;
struct pci_dev *pdev;
struct fc_bar0 __iomem *bar0;
struct mfd_cell *cells;
--
2.1.4
Powered by blists - more mailing lists