From: kernel@martin.sperl.org
To: Stephen Warren <swarren@wwwdotorg.org>,
Lee Jones <lee@kernel.org>, Russell King <linux@arm.linux.org.uk>,
Mark Brown <broonie@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
devicetree@vger.kernel.org, linux-rpi-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, linux-spi@vger.kernel.org,
Ian Campbell <ijc+devicetree@hellion.org.uk>,
Rob Herring <robh+dt@kernel.org>, Pawel Moll <pawel.moll@arm.com>,
Kumar Gala <galak@codeaurora.org>
Cc: Martin Sperl <kernel@martin.sperl.org>
Subject: [PATCH v4 1/5] soc: bcm2835: auxiliar devices enable infrastructure
Date: Mon, 24 Aug 2015 08:40:04 +0000 [thread overview]
Message-ID: <1440405608-3995-2-git-send-email-kernel@martin.sperl.org> (raw)
In-Reply-To: <1440405608-3995-1-git-send-email-kernel@martin.sperl.org>
From: Martin Sperl <kernel@martin.sperl.org>
The bcm2835 SOC contains 3 auxiliar devices (spi1, spi2 and uart1)
that all are enabled via a shared register.
To serialize access to this shared register this soc-driver
is created that implements:
bcm2835aux_enable(struct device *dev, const char *property);
bcm2835aux_disable(struct device *dev, const char *property);
Which will read the property from the device tree of the device
and enable/disable that specific device as per device tree.
First use of this api will be spi-bcm2835aux.
Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
---
drivers/soc/Kconfig | 1 +
drivers/soc/Makefile | 1 +
drivers/soc/bcm/Kconfig | 11 +++
drivers/soc/bcm/Makefile | 1 +
drivers/soc/bcm/bcm2835-aux.c | 154 +++++++++++++++++++++++++++++++++++
include/linux/soc/bcm/bcm2835-aux.h | 23 ++++++
6 files changed, 191 insertions(+)
create mode 100644 drivers/soc/bcm/Kconfig
create mode 100644 drivers/soc/bcm/Makefile
create mode 100644 drivers/soc/bcm/bcm2835-aux.c
create mode 100644 include/linux/soc/bcm/bcm2835-aux.h
diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
index 96ddecb..5506e39 100644
--- a/drivers/soc/Kconfig
+++ b/drivers/soc/Kconfig
@@ -1,5 +1,6 @@
menu "SOC (System On Chip) specific Drivers"
+source "drivers/soc/bcm/Kconfig"
source "drivers/soc/mediatek/Kconfig"
source "drivers/soc/qcom/Kconfig"
source "drivers/soc/sunxi/Kconfig"
diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile
index 7dc7c0d..c5744e1 100644
--- a/drivers/soc/Makefile
+++ b/drivers/soc/Makefile
@@ -2,6 +2,7 @@
# Makefile for the Linux Kernel SOC specific device drivers.
#
+obj-$(CONFIG_ARCH_BCM) += bcm/
obj-$(CONFIG_ARCH_MEDIATEK) += mediatek/
obj-$(CONFIG_ARCH_QCOM) += qcom/
obj-$(CONFIG_ARCH_SUNXI) += sunxi/
diff --git a/drivers/soc/bcm/Kconfig b/drivers/soc/bcm/Kconfig
new file mode 100644
index 0000000..b0af34b3
--- /dev/null
+++ b/drivers/soc/bcm/Kconfig
@@ -0,0 +1,11 @@
+#
+# Broadcom SoC drivers
+#
+config SOC_BCM2835_AUX
+ tristate "Broadcom BCM2835 aux"
+ depends on OF
+ depends on ARCH_BCM2835 || COMPILE_TEST
+
+ help
+ Support to enable/disable the BCM2835 auxiliar
+ devices spi1, spi2, uart1
diff --git a/drivers/soc/bcm/Makefile b/drivers/soc/bcm/Makefile
new file mode 100644
index 0000000..370a872
--- /dev/null
+++ b/drivers/soc/bcm/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_SOC_BCM2835_AUX) += bcm2835-aux.o
diff --git a/drivers/soc/bcm/bcm2835-aux.c b/drivers/soc/bcm/bcm2835-aux.c
new file mode 100644
index 0000000..887508d
--- /dev/null
+++ b/drivers/soc/bcm/bcm2835-aux.c
@@ -0,0 +1,154 @@
+/*
+ * bcm2835-aux
+ *
+ * Copyright (C) 2015 Martin Sperl
+ *
+ * Author: Martin Sperl <kernel@martin.sperl.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/soc/bcm/bcm2835-aux.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+
+static DEFINE_SPINLOCK(bcm2835aux_lock);
+
+static struct platform_driver bcm2835aux_driver;
+
+static int bcm2835aux_dev_match(struct device *dev, void *data)
+{
+ struct device_node *dn = data;
+
+ return (dev->of_node == dn) ? 1 : 0;
+}
+
+static void *bcm2835aux_find_base(struct device *dev, const char *property)
+{
+ struct device *found = NULL;
+ struct device_node *np;
+
+ /* get the phandle of the device */
+ np = of_parse_phandle(dev->of_node, property, 0);
+ if (!np) {
+ dev_err(dev, "missing property %s\n", property);
+ return ERR_PTR(-ENODEV);
+ }
+
+ /* now find the device it points to */
+ found = driver_find_device(&bcm2835aux_driver.driver, NULL,
+ np, bcm2835aux_dev_match);
+ if (!found) {
+ dev_err(dev, "device for phandle of %s not found\n",
+ property);
+ return ERR_PTR(-ENODEV);
+ }
+
+ /* now we got the device, so return the pointer */
+ return dev_get_drvdata(found);
+}
+
+static u32 bcm2835aux_find_mask(struct device *dev, const char *property)
+{
+ int err;
+ u32 mask;
+
+ err = of_property_read_u32_index(dev->of_node, property, 1, &mask);
+ if (err) {
+ dev_err(dev, "missing argument to %s: %d\n",
+ property, err);
+ return 0;
+ }
+
+ return mask;
+}
+
+static int bcm2835aux_bitset(struct device *dev, const char *property,
+ bool set)
+{
+ u32 v, mask;
+ unsigned long flags;
+ void __iomem *base;
+
+ /* find the device */
+ base = bcm2835aux_find_base(dev, property);
+ if (IS_ERR(base))
+ return PTR_ERR(base);
+
+ /* and extract the mask */
+ mask = bcm2835aux_find_mask(dev, property);
+ if (!mask)
+ return -ENOENT;
+
+ spin_lock_irqsave(&bcm2835aux_lock, flags);
+
+ v = readl(base);
+ if (set)
+ v |= mask;
+ else
+ v &= ~mask;
+
+ writel(v, base);
+
+ spin_unlock_irqrestore(&bcm2835aux_lock, flags);
+
+ return 0;
+}
+
+int bcm2835aux_enable(struct device *dev, const char *property)
+{
+ return bcm2835aux_bitset(dev, property, true);
+}
+EXPORT_SYMBOL_GPL(bcm2835aux_enable);
+
+int bcm2835aux_disable(struct device *dev, const char *property)
+{
+ return bcm2835aux_bitset(dev, property, false);
+}
+EXPORT_SYMBOL_GPL(bcm2835aux_disable);
+
+static int bcm2835aux_probe(struct platform_device *pdev)
+{
+ struct resource *res;
+ void __iomem *base;
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!res)
+ return -ENOENT;
+
+ base = devm_ioremap_resource(&pdev->dev, res);
+ if (IS_ERR(base))
+ return PTR_ERR(base);
+
+ platform_set_drvdata(pdev, base);
+
+ return 0;
+}
+
+static const struct of_device_id bcm2835aux_match[] = {
+ { .compatible = "brcm,bcm2835-aux", },
+ {}
+};
+MODULE_DEVICE_TABLE(of, bcm2835aux_match);
+
+static struct platform_driver bcm2835aux_driver = {
+ .driver = {
+ .name = "bcm2835-aux",
+ .of_match_table = bcm2835aux_match,
+ },
+ .probe = bcm2835aux_probe,
+};
+module_platform_driver(bcm2835aux_driver);
+
+MODULE_DESCRIPTION("enable/disable driver for aux-spi1/spi2/uart1 on Broadcom BCM2835");
+MODULE_AUTHOR("Martin Sperl <kernel@martin.sperl.org>");
+MODULE_LICENSE("GPL v2");
diff --git a/include/linux/soc/bcm/bcm2835-aux.h b/include/linux/soc/bcm/bcm2835-aux.h
new file mode 100644
index 0000000..17a64c6
--- /dev/null
+++ b/include/linux/soc/bcm/bcm2835-aux.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2015 Martin Sperl
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef __BCM2835_AUX_H__
+#define __BCM2835_AUX_H__
+
+struct device;
+
+int bcm2835aux_enable(struct device *dev, const char *property);
+int bcm2835aux_disable(struct device *dev, const char *property);
+
+#endif
--
1.7.10.4
next prev parent reply other threads:[~2015-08-24 8:40 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-24 8:40 [PATCH v4 0/5] bcm2835: auxiliar device support for spi kernel-TqfNSX0MhmxHKSADF0wUEw
2015-08-24 8:40 ` kernel [this message]
[not found] ` <1440405608-3995-2-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2015-08-26 1:52 ` [PATCH v4 1/5] soc: bcm2835: auxiliar devices enable infrastructure Stephen Warren
2015-08-24 8:40 ` [PATCH v4 2/5] ARM: bcm2835: add DT for the bcm2835 auxiliar devices kernel
2015-08-24 8:40 ` [PATCH v4 3/5] dt/bindings: bcm2835: add binding documentation for bcm2835-aux kernel
[not found] ` <1440405608-3995-4-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2015-08-26 1:44 ` Stephen Warren
2015-09-04 8:26 ` Martin Sperl
[not found] ` <9D45476C-88E2-4F76-AB55-9D0C7194E29C-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2015-09-16 4:12 ` Stephen Warren
[not found] ` <55F8EC22.7020909-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2015-09-16 5:25 ` Martin Sperl
2015-08-24 8:40 ` [PATCH v4 4/5] spi: bcm2835: new driver implementing auxiliar spi1/spi2 on the bcm2835 soc kernel
[not found] ` <1440405608-3995-5-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2015-08-26 1:56 ` Stephen Warren
[not found] ` <1440405608-3995-1-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2015-08-24 8:40 ` [PATCH v4 5/5] dt/bindings: bcm2835: Add binding documentation for auxiliar spi devices kernel-TqfNSX0MhmxHKSADF0wUEw
[not found] ` <1440405608-3995-6-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2015-08-26 1:49 ` Stephen Warren
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=1440405608-3995-2-git-send-email-kernel@martin.sperl.org \
--to=kernel@martin.sperl.org \
--cc=broonie@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=galak@codeaurora.org \
--cc=ijc+devicetree@hellion.org.uk \
--cc=lee@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rpi-kernel@lists.infradead.org \
--cc=linux-spi@vger.kernel.org \
--cc=linux@arm.linux.org.uk \
--cc=mark.rutland@arm.com \
--cc=pawel.moll@arm.com \
--cc=robh+dt@kernel.org \
--cc=swarren@wwwdotorg.org \
/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 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).