From: kernel@martin.sperl.org
To: Rob Herring <robh+dt@kernel.org>, Pawel Moll <pawel.moll@arm.com>,
Mark Rutland <mark.rutland@arm.com>,
Stephen Warren <swarren@wwwdotorg.org>,
Lee Jones <lee@kernel.org>, Eric Anholt <eric@anholt.net>,
Russell King <linux@arm.linux.org.uk>,
devicetree@vger.kernel.org, linux-rpi-kernel@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Cc: Martin Sperl <kernel@martin.sperl.org>
Subject: [PATCH 2/4] memory: bcm2835: add bcm2835-memory controller
Date: Thu, 12 May 2016 12:38:50 +0000 [thread overview]
Message-ID: <1463056732-5607-3-git-send-email-kernel@martin.sperl.org> (raw)
In-Reply-To: <1463056732-5607-1-git-send-email-kernel@martin.sperl.org>
From: Martin Sperl <kernel@martin.sperl.org>
Add a memory-controller driver for the bcm2835 SOC.
This is mostly needed to claim the SDRAM clock
so that this (and the corresponding parent pll)
never gets disabled.
It also exposes the sdram registers via debugfs.
Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
---
drivers/memory/Kconfig | 7 ++
drivers/memory/Makefile | 1 +
drivers/memory/bcm2835-sdram.c | 152 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 160 insertions(+)
create mode 100644 drivers/memory/bcm2835-sdram.c
diff --git a/drivers/memory/Kconfig b/drivers/memory/Kconfig
index 51d5cd2..a55cad3 100644
--- a/drivers/memory/Kconfig
+++ b/drivers/memory/Kconfig
@@ -25,6 +25,13 @@ config ATMEL_SDRAMC
Starting with the at91sam9g45, this controller supports SDR, DDR and
LP-DDR memories.
+config BCM2835_SDRAM
+ bool "Broadcom BCM2835 SDRAM Controller"
+ default y
+ depends on ARCH_BCM2835 || COMPILE_TEST
+ help
+ This driver is for Broadcom BCM2835 SDRAM Controller.
+
config TI_AEMIF
tristate "Texas Instruments AEMIF driver"
depends on (ARCH_DAVINCI || ARCH_KEYSTONE) && OF
diff --git a/drivers/memory/Makefile b/drivers/memory/Makefile
index 890bdf4..1287b90 100644
--- a/drivers/memory/Makefile
+++ b/drivers/memory/Makefile
@@ -7,6 +7,7 @@ obj-$(CONFIG_OF) += of_memory.o
endif
obj-$(CONFIG_ARM_PL172_MPMC) += pl172.o
obj-$(CONFIG_ATMEL_SDRAMC) += atmel-sdramc.o
+obj-$(CONFIG_BCM2835_SDRAM) += bcm2835-sdram.o
obj-$(CONFIG_TI_AEMIF) += ti-aemif.o
obj-$(CONFIG_TI_EMIF) += emif.o
obj-$(CONFIG_OMAP_GPMC) += omap-gpmc.o
diff --git a/drivers/memory/bcm2835-sdram.c b/drivers/memory/bcm2835-sdram.c
new file mode 100644
index 0000000..7c9c0ca
--- /dev/null
+++ b/drivers/memory/bcm2835-sdram.c
@@ -0,0 +1,152 @@
+/*
+ * Driver for Broadcom BCM2835 soc sdram controller
+ *
+ * Copyright (C) 2016 Martin Sperl
+ *
+ * inspired by: atmel-sdramc
+ *
+ * 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.
+ */
+
+#include <linux/clk.h>
+#include <linux/debugfs.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+
+struct bcm2835_sdram_data {
+ void __iomem *regs[2];
+ struct dentry *debugfsdir;
+ struct clk *clk;
+};
+
+#define R(n, o) { .name = n, .offset = o }
+static const struct debugfs_reg32 bcm2835_sdram_regs[] = {
+ R("c", 0x00),
+ R("s", 0x04),
+ R("src0", 0x08),
+ R("src1", 0x0c),
+ R("mask0", 0x10),
+ R("mask1", 0x14),
+ R("mask2", 0x18),
+ R("mask3", 0x1c),
+ R("mask4", 0x20),
+ R("mask5", 0x24),
+ R("mask6", 0x28),
+ R("mask7", 0x2c),
+ R("vaddr", 0x30),
+ R("wakeup", 0x34),
+ R("profile", 0x38),
+ /* 0x3c is not defined */
+ R("force0", 0x40),
+ R("force1", 0x44),
+ /* 0x48 to 0x54 are write only */
+};
+
+static void bcm2835_sdram_debugfs(struct platform_device *pdev)
+{
+ struct bcm2835_sdram_data *data = platform_get_drvdata(pdev);
+ struct debugfs_regset32 *regset;
+ char *name;
+ int i;
+
+ data->debugfsdir = debugfs_create_dir("bcm2835_sdram", NULL);
+ if (!data->debugfsdir)
+ return;
+
+ /* create the regsets */
+ for (i = 0; i < 2; i++) {
+ name = devm_kasprintf(&pdev->dev, GFP_KERNEL,
+ "regset%d", i);
+ if (!name)
+ return;
+
+ regset = devm_kzalloc(&pdev->dev, sizeof(*regset),
+ GFP_KERNEL);
+ if (!regset)
+ return;
+
+ regset->regs = bcm2835_sdram_regs;
+ regset->nregs = ARRAY_SIZE(bcm2835_sdram_regs);
+ regset->base = data->regs[i];
+
+ debugfs_create_regset32(name, S_IRUGO,
+ data->debugfsdir, regset);
+ }
+}
+
+static int bcm2835_sdram_probe(struct platform_device *pdev)
+{
+ struct bcm2835_sdram_data *data;
+ struct resource *res;
+ int err, i;
+
+ data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+ if (!data)
+ return -ENOMEM;
+ platform_set_drvdata(pdev, data);
+
+ /* get registers */
+ for (i = 0; i < 2; i++) {
+ res = platform_get_resource(pdev, IORESOURCE_MEM, i);
+ data->regs[i] = devm_ioremap_resource(&pdev->dev, res);
+ if (IS_ERR(data->regs[i])) {
+ err = PTR_ERR(data->regs[i]);
+ dev_err(&pdev->dev,
+ "Could not get register set %d: %d\n",
+ i, err);
+ return err;
+ }
+ }
+ /* get clock */
+ data->clk = devm_clk_get(&pdev->dev, NULL);
+ if (IS_ERR(data->clk))
+ return PTR_ERR(data->clk);
+ clk_prepare_enable(data->clk);
+
+ bcm2835_sdram_debugfs(pdev);
+
+ return 0;
+}
+
+static int bcm2835_sdram_remove(struct platform_device *pdev)
+{
+ struct bcm2835_sdram_data *data = platform_get_drvdata(pdev);
+
+ debugfs_remove_recursive(data->debugfsdir);
+
+ return 0;
+}
+
+static const struct of_device_id bcm2835_sdram_of_match_table[] = {
+ { .compatible = "brcm,bcm2835-sdram", },
+ {},
+};
+MODULE_DEVICE_TABLE(of, bcm2835_sdram_of_match_table);
+
+static struct platform_driver bcm2835_sdram_driver = {
+ .probe = bcm2835_sdram_probe,
+ .remove = bcm2835_sdram_remove,
+ .driver = {
+ .name = "bcm2835_sdram",
+ .of_match_table = bcm2835_sdram_of_match_table,
+ },
+};
+module_platform_driver(bcm2835_sdram_driver);
+
+MODULE_AUTHOR("Martin Sperl");
+MODULE_DESCRIPTION("sdram driver for bcm2835 chip");
+MODULE_LICENSE("GPL");
--
2.1.4
next prev parent reply other threads:[~2016-05-12 12:38 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-12 12:38 [PATCH 0/4] add minimal bcm2835-sdram driver kernel
2016-05-12 12:38 ` [PATCH 1/4] dt: bindings: add bcm2835-memory-controller documentation kernel
[not found] ` <1463056732-5607-2-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2016-05-16 16:04 ` Rob Herring
2016-05-12 12:38 ` kernel [this message]
2016-05-12 12:38 ` [PATCH 3/4] ARM: dts: bcm2835: add the bcm2835-sdram-controller to the dt kernel
2016-05-12 14:56 ` Stefan Wahren
[not found] ` <73859954.21004.36a104a6-5284-487f-b397-da7ff0407f1f.open-xchange-7tX72C7vayboQLBSYMtkGA@public.gmane.org>
2016-05-12 16:00 ` Martin Sperl
2016-05-12 12:38 ` [PATCH 4/4] ARM: bcm2835_defconfig: add bcm2835-sdram controller kernel
[not found] ` <1463056732-5607-1-git-send-email-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2016-05-12 14:50 ` [PATCH 0/4] add minimal bcm2835-sdram driver Stefan Wahren
2016-05-12 15:28 ` Martin Sperl
2016-05-12 15:55 ` Stefan Wahren
[not found] ` <527736177.22944.36a104a6-5284-487f-b397-da7ff0407f1f.open-xchange-7tX72C7vayboQLBSYMtkGA@public.gmane.org>
2016-05-12 16:03 ` Martin Sperl
2016-05-12 18:15 ` Eric Anholt
[not found] ` <87twi39m80.fsf-omZaPlIz5HhaEpDpdNBo/KxOck334EZe@public.gmane.org>
2016-05-12 19:46 ` Martin Sperl
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=1463056732-5607-3-git-send-email-kernel@martin.sperl.org \
--to=kernel@martin.sperl.org \
--cc=devicetree@vger.kernel.org \
--cc=eric@anholt.net \
--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@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).