From: Philipp Zabel <p.zabel@pengutronix.de>
To: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: u.kleine-koenig@pengutronix.de, afaerber@suse.de,
geert@linux-m68k.org, Rob Herring <robh+dt@kernel.org>,
Linus Walleij <linus.walleij@linaro.org>,
Arnd Bergmann <arnd@arndb.de>,
stefan@agner.ch, pmeerw@pmeerw.net, pebolle@tiscali.nl,
Jonathan Corbet <corbet@lwn.net>, Pawel Moll <pawel.moll@arm.com>,
Mark Rutland <mark.rutland@arm.com>,
Ian Campbell <ijc+devicetree@hellion.org.uk>,
Kumar Gala <galak@codeaurora.org>,
Russell King <linux@arm.linux.org.uk>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Thomas Gleixner <tglx@linutronix.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jslaby@suse.cz>,
Andrew Morton <akpm@linux-foundation.org>,
"David S. Miller" <davem@davemloft.net>,
Mauro Carvalho Chehab <mchehab@osg.samsung.com>,
Joe Perches <joe@perches.com>, Antti Palosaari <crope@iki.fi>,
Tejun Heo <tj@kernel.org>, Will Deacon <will.deacon@arm.com>
Subject: Re: [PATCH v3 06/15] drivers: reset: Add STM32 reset driver
Date: Fri, 13 Mar 2015 09:54:55 +0100 [thread overview]
Message-ID: <1426236895.3083.20.camel@pengutronix.de> (raw)
In-Reply-To: <1426197361-19290-7-git-send-email-maxime.coquelin@st.com>
Am Donnerstag, den 12.03.2015, 22:55 +0100 schrieb Maxime Coquelin:
> From: Maxime Coquelin <mcoquelin.stm32@gmail.com>
>
> The STM32 MCUs family IP can be reset by accessing some shared registers.
>
> The specificity is that some reset lines are used by the timers.
> At timer initialization time, the timer has to be reset, that's why
> we cannot use a regular driver.
But this is a regular driver now, should this comment be updated?
> Signed-off-by: Maxime Coquelin <mcoquelin.stm32@gmail.com>
> ---
> drivers/reset/Makefile | 1 +
> drivers/reset/reset-stm32.c | 125 ++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 126 insertions(+)
> create mode 100644 drivers/reset/reset-stm32.c
>
> diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile
> index 157d421..aed12d1 100644
> --- a/drivers/reset/Makefile
> +++ b/drivers/reset/Makefile
> @@ -1,5 +1,6 @@
> obj-$(CONFIG_RESET_CONTROLLER) += core.o
> obj-$(CONFIG_ARCH_SOCFPGA) += reset-socfpga.o
> obj-$(CONFIG_ARCH_BERLIN) += reset-berlin.o
> +obj-$(CONFIG_ARCH_STM32) += reset-stm32.o
> obj-$(CONFIG_ARCH_SUNXI) += reset-sunxi.o
> obj-$(CONFIG_ARCH_STI) += sti/
> diff --git a/drivers/reset/reset-stm32.c b/drivers/reset/reset-stm32.c
> new file mode 100644
> index 0000000..0d389b1
> --- /dev/null
> +++ b/drivers/reset/reset-stm32.c
> @@ -0,0 +1,125 @@
> +/*
> + * Copyright (C) Maxime Coquelin 2015
> + * Author: Maxime Coquelin <mcoquelin.stm32@gmail.com>
> + * License terms: GNU General Public License (GPL), version 2
> + *
> + * Heavily based on sunxi driver from Maxime Ripard.
> + */
> +
> +#include <linux/err.h>
> +#include <linux/io.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/of_address.h>
> +#include <linux/platform_device.h>
> +#include <linux/reset-controller.h>
> +#include <linux/slab.h>
> +#include <linux/spinlock.h>
> +#include <linux/types.h>
> +
> +struct stm32_reset_data {
> + spinlock_t lock;
> + void __iomem *membase;
> + struct reset_controller_dev rcdev;
> +};
> +
> +static int stm32_reset_assert(struct reset_controller_dev *rcdev,
> + unsigned long id)
> +{
> + struct stm32_reset_data *data = container_of(rcdev,
> + struct stm32_reset_data,
> + rcdev);
> + int bank = id / BITS_PER_LONG;
> + int offset = id % BITS_PER_LONG;
> + unsigned long flags;
> + u32 reg;
> +
> + spin_lock_irqsave(&data->lock, flags);
> +
> + reg = readl_relaxed(data->membase + (bank * 4));
> + writel_relaxed(reg | BIT(offset), data->membase + (bank * 4));
> +
> + spin_unlock_irqrestore(&data->lock, flags);
> +
> + return 0;
> +}
> +
> +static int stm32_reset_deassert(struct reset_controller_dev *rcdev,
> + unsigned long id)
> +{
> + struct stm32_reset_data *data = container_of(rcdev,
> + struct stm32_reset_data,
> + rcdev);
> + int bank = id / BITS_PER_LONG;
> + int offset = id % BITS_PER_LONG;
> + unsigned long flags;
> + u32 reg;
> +
> + spin_lock_irqsave(&data->lock, flags);
> +
> + reg = readl_relaxed(data->membase + (bank * 4));
> + writel_relaxed(reg & ~BIT(offset), data->membase + (bank * 4));
> +
> + spin_unlock_irqrestore(&data->lock, flags);
> +
> + return 0;
> +}
> +
> +static struct reset_control_ops stm32_reset_ops = {
> + .assert = stm32_reset_assert,
> + .deassert = stm32_reset_deassert,
> +};
> +
> +static const struct of_device_id stm32_reset_dt_ids[] = {
> + { .compatible = "st,stm32-rcc", },
> + { /* sentinel */ },
> +};
> +MODULE_DEVICE_TABLE(of, sstm32_reset_dt_ids);
> +
> +static int stm32_reset_probe(struct platform_device *pdev)
> +{
> + struct stm32_reset_data *data;
> + struct resource *res;
> +
> + data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
> + if (!data)
> + return -ENOMEM;
> +
> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + data->membase = devm_ioremap_resource(&pdev->dev, res);
> + if (IS_ERR(data->membase))
> + return PTR_ERR(data->membase);
> +
> + spin_lock_init(&data->lock);
> +
> + data->rcdev.owner = THIS_MODULE;
> + data->rcdev.nr_resets = resource_size(res) * 8;
> + data->rcdev.ops = &stm32_reset_ops;
> + data->rcdev.of_node = pdev->dev.of_node;
> +
> + return reset_controller_register(&data->rcdev);
> +}
> +
> +static int stm32_reset_remove(struct platform_device *pdev)
> +{
> + struct stm32_reset_data *data = platform_get_drvdata(pdev);
> +
> + reset_controller_unregister(&data->rcdev);
> +
> + return 0;
> +}
> +
> +static struct platform_driver stm32_reset_driver = {
> + .probe = stm32_reset_probe,
> + .remove = stm32_reset_remove,
> + .driver = {
> + .name = "stm32-rcc-reset",
> + .of_match_table = stm32_reset_dt_ids,
> + },
> +};
> +module_platform_driver(stm32_reset_driver);
> +
> +MODULE_AUTHOR("Maxime Coquelin <maxime.coquelin@gmail.com>");
> +MODULE_DESCRIPTION("STM32 MCUs Reset Controller Driver");
> +MODULE_LICENSE("GPL");
> +
regards
Philipp
next prev parent reply other threads:[~2015-03-13 8:54 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-12 21:55 [PATCH v3 00/15] Add support to STMicroelectronics STM32 family Maxime Coquelin
2015-03-12 21:55 ` [PATCH v3 02/15] ARM: ARMv7-M: Enlarge vector table up to 256 entries Maxime Coquelin
2015-03-12 21:55 ` [PATCH v3 03/15] dt-bindings: Document the ARM System timer bindings Maxime Coquelin
2015-03-12 21:55 ` [PATCH v3 04/15] clocksource: Add ARM System timer driver Maxime Coquelin
2015-03-26 9:50 ` Daniel Lezcano
2015-03-26 20:19 ` Maxime Coquelin
2015-03-27 8:36 ` Daniel Lezcano
2015-03-27 12:33 ` Maxime Coquelin
2015-03-12 21:55 ` [PATCH v3 05/15] dt-bindings: Document the STM32 reset bindings Maxime Coquelin
2015-03-13 0:09 ` Chanwoo Choi
2015-03-17 16:57 ` Maxime Coquelin
2015-03-13 8:50 ` Philipp Zabel
[not found] ` <1426236654.3083.19.camel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2015-03-17 17:13 ` Maxime Coquelin
2015-03-12 21:55 ` [PATCH v3 06/15] drivers: reset: Add STM32 reset driver Maxime Coquelin
2015-03-13 0:11 ` Chanwoo Choi
2015-03-13 8:54 ` Philipp Zabel [this message]
2015-03-17 17:23 ` Maxime Coquelin
2015-03-12 21:55 ` [PATCH v3 07/15] dt-bindings: Document the STM32 timer bindings Maxime Coquelin
2015-03-12 21:55 ` [PATCH v3 08/15] clockevent: Add STM32 Timer driver Maxime Coquelin
2015-03-12 21:55 ` [PATCH v3 09/15] dt-bindings: Document the STM32 USART bindings Maxime Coquelin
[not found] ` <1426197361-19290-1-git-send-email-maxime.coquelin-qxv4g6HH51o@public.gmane.org>
2015-03-12 21:55 ` [PATCH v3 01/15] scripts: link-vmlinux: Don't pass page offset to kallsyms if XIP Kernel Maxime Coquelin
2015-03-12 21:55 ` [PATCH v3 10/15] serial: stm32-usart: Add STM32 USART Driver Maxime Coquelin
2015-03-13 9:41 ` Paul Bolle
2015-03-17 17:39 ` Maxime Coquelin
2015-03-13 14:19 ` Andy Shevchenko
2015-03-17 17:32 ` Maxime Coquelin
[not found] ` <CALszF6BWuUYRh+3rWnSQLApkAHA5dQXw=6x6D_evRtb+5B_ukA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-03-17 17:56 ` Andy Shevchenko
2015-03-19 13:55 ` Maxime Coquelin
[not found] ` <CALszF6A5Zu7i0hxSLTS-nfOAXmd0__jLjB=fHxK93Ex5Vbi9LA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-03-19 14:58 ` Peter Hurley
[not found] ` <550AE41C.8070803-WaGBZJeGNqdsbIuE7sb01tBPR1lH4CV8@public.gmane.org>
2015-03-19 17:35 ` Maxime Coquelin
2015-03-24 17:21 ` Maxime Coquelin
[not found] ` <CALszF6Dg7t9+F9NG+xREPQeaAj7T6D1GuGabkr8EvOAAdtg7yA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-03-24 17:44 ` Peter Hurley
[not found] ` <1426197361-19290-11-git-send-email-maxime.coquelin-qxv4g6HH51o@public.gmane.org>
2015-03-24 18:23 ` Peter Hurley
[not found] ` <5511ABAA.2010303-WaGBZJeGNqdsbIuE7sb01tBPR1lH4CV8@public.gmane.org>
2015-03-26 15:46 ` Russell King - ARM Linux
2015-03-26 22:05 ` Maxime Coquelin
2015-03-26 22:03 ` Maxime Coquelin
2015-03-27 11:32 ` Peter Hurley
2015-03-27 12:30 ` Maxime Coquelin
2015-03-12 21:55 ` [PATCH v3 11/15] ARM: Add STM32 family machine Maxime Coquelin
2015-03-12 21:55 ` [PATCH v3 12/15] ARM: dts: Add ARM System timer as clockevent in armv7m Maxime Coquelin
2015-03-12 21:55 ` [PATCH v3 13/15] ARM: dts: Introduce STM32F429 MCU Maxime Coquelin
2015-03-12 21:56 ` [PATCH v3 14/15] ARM: configs: Add STM32 defconfig Maxime Coquelin
2015-03-12 21:56 ` [PATCH v3 15/15] MAINTAINERS: Add entry for STM32 MCUs Maxime Coquelin
2015-03-12 23:45 ` [PATCH v3 00/15] Add support to STMicroelectronics STM32 family Chanwoo Choi
2015-03-18 23:35 ` Chanwoo Choi
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=1426236895.3083.20.camel@pengutronix.de \
--to=p.zabel@pengutronix.de \
--cc=afaerber@suse.de \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=corbet@lwn.net \
--cc=crope@iki.fi \
--cc=daniel.lezcano@linaro.org \
--cc=davem@davemloft.net \
--cc=galak@codeaurora.org \
--cc=geert@linux-m68k.org \
--cc=gregkh@linuxfoundation.org \
--cc=ijc+devicetree@hellion.org.uk \
--cc=joe@perches.com \
--cc=jslaby@suse.cz \
--cc=linus.walleij@linaro.org \
--cc=linux@arm.linux.org.uk \
--cc=mark.rutland@arm.com \
--cc=mchehab@osg.samsung.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=pawel.moll@arm.com \
--cc=pebolle@tiscali.nl \
--cc=pmeerw@pmeerw.net \
--cc=robh+dt@kernel.org \
--cc=stefan@agner.ch \
--cc=tglx@linutronix.de \
--cc=tj@kernel.org \
--cc=u.kleine-koenig@pengutronix.de \
--cc=will.deacon@arm.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 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).