From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v4 09/19] clocksource: sh_cmt: Add DT support
Date: Fri, 04 Jul 2014 13:15:37 +0000 [thread overview]
Message-ID: <1897420.z4gRLGjo6K@avalon> (raw)
In-Reply-To: <1402931251-22581-10-git-send-email-laurent.pinchart+renesas@ideasonboard.com>
On Monday 16 June 2014 17:07:21 Laurent Pinchart wrote:
> Document DT bindings and parse them in the CMT driver.
>
> Cc: devicetree@vger.kernel.org
> Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
> Tested-by: Simon Horman <horms+renesas@verge.net.au>
> ---
> .../devicetree/bindings/timer/renesas,cmt.txt | 47 +++++++++++++++
> drivers/clocksource/sh_cmt.c | 66 +++++++++++++------
> 2 files changed, 95 insertions(+), 18 deletions(-)
> create mode 100644 Documentation/devicetree/bindings/timer/renesas,cmt.txt
>
> diff --git a/Documentation/devicetree/bindings/timer/renesas,cmt.txt
> b/Documentation/devicetree/bindings/timer/renesas,cmt.txt new file mode
> 100644
> index 0000000..643cfff
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/timer/renesas,cmt.txt
> @@ -0,0 +1,47 @@
> +* Renesas R-Car Compare Match Timer (CMT)
> +
> +The CMT is a multi-channel 16/32/48-bit timer/counter with configurable
> clock
> +inputs and programmable compare match.
> +
> +Channels share hardware resources but their counter and compare match value
> +are independent. A particular CMT instance can implement only a subset of
> the
> +channels supported by the CMT model. Channel indices represent the hardware
> +position of the channel in the CMT and don't match the channel numbers in
> the
> +datasheets.
> +
> +Required Properties:
> +
> + - compatible: must contain one of the following.
> + - "renesas,cmt-32" for the 32-bit CMT
> + (CMT0 on sh7372, sh73a0 and r8a7740)
> + - "renesas,cmt-32-fast" for the 32-bit CMT with fast clock support
> + (CMT[234] on sh7372, sh73a0 and r8a7740)
> + - "renasas,cmt-48" for the 48-bit CMT
Simon has spotted a nasty typo here and below in the OF match table. I'll fix
that and resubmit the pull request.
> + (CMT1 on sh7372, sh73a0 and r8a7740)
> + - "renesas,cmt-48-gen2" for the second generation 48-bit CMT
> + (CMT[01] on r8a73a4, r8a7790 and r8a7791)
> +
> + - reg: base address and length of the registers block for the timer
> module.
> + - interrupts: interrupt-specifier for the timer, one per channel.
> + - clocks: a list of phandle + clock-specifier pairs, one for each entry
> + in clock-names.
> + - clock-names: must contain "fck" for the functional clock.
> +
> + - renesas,channels-mask: bitmask of the available channels.
> +
> +
> +Example: R8A7790 (R-Car H2) CMT0 node
> +
> + CMT0 on R8A7790 implements hardware channels 5 and 6 only and names
> + them channels 0 and 1 in the documentation.
> +
> + cmt0: timer@ffca0000 {
> + compatible = "renesas,cmt-48-gen2";
> + reg = <0 0xffca0000 0 0x1004>;
> + interrupts = <0 142 IRQ_TYPE_LEVEL_HIGH>,
> + <0 142 IRQ_TYPE_LEVEL_HIGH>;
> + clocks = <&mstp1_clks R8A7790_CLK_CMT0>;
> + clock-names = "fck";
> +
> + renesas,channels-mask = <0x60>;
> + };
> diff --git a/drivers/clocksource/sh_cmt.c b/drivers/clocksource/sh_cmt.c
> index 4d00e4b..09a93c4 100644
> --- a/drivers/clocksource/sh_cmt.c
> +++ b/drivers/clocksource/sh_cmt.c
> @@ -24,6 +24,7 @@
> #include <linux/ioport.h>
> #include <linux/irq.h>
> #include <linux/module.h>
> +#include <linux/of.h>
> #include <linux/platform_device.h>
> #include <linux/pm_domain.h>
> #include <linux/pm_runtime.h>
> @@ -122,6 +123,7 @@ struct sh_cmt_device {
>
> struct sh_cmt_channel *channels;
> unsigned int num_channels;
> + unsigned int hw_channels;
>
> bool has_clockevent;
> bool has_clocksource;
> @@ -924,10 +926,35 @@ static int sh_cmt_map_memory(struct sh_cmt_device
> *cmt) return 0;
> }
>
> +static const struct platform_device_id sh_cmt_id_table[] = {
> + { "sh-cmt-16", (kernel_ulong_t)&sh_cmt_info[SH_CMT_16BIT] },
> + { "sh-cmt-32", (kernel_ulong_t)&sh_cmt_info[SH_CMT_32BIT] },
> + { "sh-cmt-32-fast", (kernel_ulong_t)&sh_cmt_info[SH_CMT_32BIT_FAST] },
> + { "sh-cmt-48", (kernel_ulong_t)&sh_cmt_info[SH_CMT_48BIT] },
> + { "sh-cmt-48-gen2", (kernel_ulong_t)&sh_cmt_info[SH_CMT_48BIT_GEN2] },
> + { }
> +};
> +MODULE_DEVICE_TABLE(platform, sh_cmt_id_table);
> +
> +static const struct of_device_id sh_cmt_of_table[] __maybe_unused = {
> + { .compatible = "renesas,cmt-32", .data = &sh_cmt_info[SH_CMT_32BIT] },
> + { .compatible = "renesas,cmt-32-fast", .data > &sh_cmt_info[SH_CMT_32BIT_FAST] }, + { .compatible = "renasas,cmt-48",
> .data = &sh_cmt_info[SH_CMT_48BIT] }, + { .compatible > "renesas,cmt-48-gen2", .data = &sh_cmt_info[SH_CMT_48BIT_GEN2] }, + { }
> +};
> +MODULE_DEVICE_TABLE(of, sh_cmt_of_table);
> +
> +static int sh_cmt_parse_dt(struct sh_cmt_device *cmt)
> +{
> + struct device_node *np = cmt->pdev->dev.of_node;
> +
> + return of_property_read_u32(np, "renesas,channels-mask",
> + &cmt->hw_channels);
> +}
> +
> static int sh_cmt_setup(struct sh_cmt_device *cmt, struct platform_device
> *pdev) {
> - struct sh_timer_config *cfg = pdev->dev.platform_data;
> - const struct platform_device_id *id = pdev->id_entry;
> unsigned int mask;
> unsigned int i;
> int ret;
> @@ -936,13 +963,26 @@ static int sh_cmt_setup(struct sh_cmt_device *cmt,
> struct platform_device *pdev) cmt->pdev = pdev;
> raw_spin_lock_init(&cmt->lock);
>
> - if (!cfg) {
> + if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {
> + const struct of_device_id *id;
> +
> + id = of_match_node(sh_cmt_of_table, pdev->dev.of_node);
> + cmt->info = id->data;
> +
> + ret = sh_cmt_parse_dt(cmt);
> + if (ret < 0)
> + return ret;
> + } else if (pdev->dev.platform_data) {
> + struct sh_timer_config *cfg = pdev->dev.platform_data;
> + const struct platform_device_id *id = pdev->id_entry;
> +
> + cmt->info = (const struct sh_cmt_info *)id->driver_data;
> + cmt->hw_channels = cfg->channels_mask;
> + } else {
> dev_err(&cmt->pdev->dev, "missing platform data\n");
> return -ENXIO;
> }
>
> - cmt->info = (const struct sh_cmt_info *)id->driver_data;
> -
> /* Get hold of clock. */
> cmt->clk = clk_get(&cmt->pdev->dev, "fck");
> if (IS_ERR(cmt->clk)) {
> @@ -960,8 +1000,7 @@ static int sh_cmt_setup(struct sh_cmt_device *cmt,
> struct platform_device *pdev) goto err_clk_unprepare;
>
> /* Allocate and setup the channels. */
> - cmt->num_channels = hweight8(cfg->channels_mask);
> -
> + cmt->num_channels = hweight8(cmt->hw_channels);
> cmt->channels = kzalloc(cmt->num_channels * sizeof(*cmt->channels),
> GFP_KERNEL);
> if (cmt->channels = NULL) {
> @@ -973,7 +1012,7 @@ static int sh_cmt_setup(struct sh_cmt_device *cmt,
> struct platform_device *pdev) * Use the first channel as a clock event
> device and the second channel * as a clock source. If only one channel is
> available use it for both. */
> - for (i = 0, mask = cfg->channels_mask; i < cmt->num_channels; ++i) {
> + for (i = 0, mask = cmt->hw_channels; i < cmt->num_channels; ++i) {
> unsigned int hwidx = ffs(mask) - 1;
> bool clocksource = i = 1 || cmt->num_channels = 1;
> bool clockevent = i = 0;
> @@ -1044,21 +1083,12 @@ static int sh_cmt_remove(struct platform_device
> *pdev) return -EBUSY; /* cannot unregister clockevent and clocksource */ }
>
> -static const struct platform_device_id sh_cmt_id_table[] = {
> - { "sh-cmt-16", (kernel_ulong_t)&sh_cmt_info[SH_CMT_16BIT] },
> - { "sh-cmt-32", (kernel_ulong_t)&sh_cmt_info[SH_CMT_32BIT] },
> - { "sh-cmt-32-fast", (kernel_ulong_t)&sh_cmt_info[SH_CMT_32BIT_FAST] },
> - { "sh-cmt-48", (kernel_ulong_t)&sh_cmt_info[SH_CMT_48BIT] },
> - { "sh-cmt-48-gen2", (kernel_ulong_t)&sh_cmt_info[SH_CMT_48BIT_GEN2] },
> - { }
> -};
> -MODULE_DEVICE_TABLE(platform, sh_cmt_id_table);
> -
> static struct platform_driver sh_cmt_device_driver = {
> .probe = sh_cmt_probe,
> .remove = sh_cmt_remove,
> .driver = {
> .name = "sh_cmt",
> + .of_match_table = of_match_ptr(sh_cmt_of_table),
> },
> .id_table = sh_cmt_id_table,
> };
--
Regards,
Laurent Pinchart
WARNING: multiple messages have this Message-ID (diff)
From: laurent.pinchart@ideasonboard.com (Laurent Pinchart)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v4 09/19] clocksource: sh_cmt: Add DT support
Date: Fri, 04 Jul 2014 15:15:37 +0200 [thread overview]
Message-ID: <1897420.z4gRLGjo6K@avalon> (raw)
In-Reply-To: <1402931251-22581-10-git-send-email-laurent.pinchart+renesas@ideasonboard.com>
On Monday 16 June 2014 17:07:21 Laurent Pinchart wrote:
> Document DT bindings and parse them in the CMT driver.
>
> Cc: devicetree at vger.kernel.org
> Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
> Tested-by: Simon Horman <horms+renesas@verge.net.au>
> ---
> .../devicetree/bindings/timer/renesas,cmt.txt | 47 +++++++++++++++
> drivers/clocksource/sh_cmt.c | 66 +++++++++++++------
> 2 files changed, 95 insertions(+), 18 deletions(-)
> create mode 100644 Documentation/devicetree/bindings/timer/renesas,cmt.txt
>
> diff --git a/Documentation/devicetree/bindings/timer/renesas,cmt.txt
> b/Documentation/devicetree/bindings/timer/renesas,cmt.txt new file mode
> 100644
> index 0000000..643cfff
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/timer/renesas,cmt.txt
> @@ -0,0 +1,47 @@
> +* Renesas R-Car Compare Match Timer (CMT)
> +
> +The CMT is a multi-channel 16/32/48-bit timer/counter with configurable
> clock
> +inputs and programmable compare match.
> +
> +Channels share hardware resources but their counter and compare match value
> +are independent. A particular CMT instance can implement only a subset of
> the
> +channels supported by the CMT model. Channel indices represent the hardware
> +position of the channel in the CMT and don't match the channel numbers in
> the
> +datasheets.
> +
> +Required Properties:
> +
> + - compatible: must contain one of the following.
> + - "renesas,cmt-32" for the 32-bit CMT
> + (CMT0 on sh7372, sh73a0 and r8a7740)
> + - "renesas,cmt-32-fast" for the 32-bit CMT with fast clock support
> + (CMT[234] on sh7372, sh73a0 and r8a7740)
> + - "renasas,cmt-48" for the 48-bit CMT
Simon has spotted a nasty typo here and below in the OF match table. I'll fix
that and resubmit the pull request.
> + (CMT1 on sh7372, sh73a0 and r8a7740)
> + - "renesas,cmt-48-gen2" for the second generation 48-bit CMT
> + (CMT[01] on r8a73a4, r8a7790 and r8a7791)
> +
> + - reg: base address and length of the registers block for the timer
> module.
> + - interrupts: interrupt-specifier for the timer, one per channel.
> + - clocks: a list of phandle + clock-specifier pairs, one for each entry
> + in clock-names.
> + - clock-names: must contain "fck" for the functional clock.
> +
> + - renesas,channels-mask: bitmask of the available channels.
> +
> +
> +Example: R8A7790 (R-Car H2) CMT0 node
> +
> + CMT0 on R8A7790 implements hardware channels 5 and 6 only and names
> + them channels 0 and 1 in the documentation.
> +
> + cmt0: timer at ffca0000 {
> + compatible = "renesas,cmt-48-gen2";
> + reg = <0 0xffca0000 0 0x1004>;
> + interrupts = <0 142 IRQ_TYPE_LEVEL_HIGH>,
> + <0 142 IRQ_TYPE_LEVEL_HIGH>;
> + clocks = <&mstp1_clks R8A7790_CLK_CMT0>;
> + clock-names = "fck";
> +
> + renesas,channels-mask = <0x60>;
> + };
> diff --git a/drivers/clocksource/sh_cmt.c b/drivers/clocksource/sh_cmt.c
> index 4d00e4b..09a93c4 100644
> --- a/drivers/clocksource/sh_cmt.c
> +++ b/drivers/clocksource/sh_cmt.c
> @@ -24,6 +24,7 @@
> #include <linux/ioport.h>
> #include <linux/irq.h>
> #include <linux/module.h>
> +#include <linux/of.h>
> #include <linux/platform_device.h>
> #include <linux/pm_domain.h>
> #include <linux/pm_runtime.h>
> @@ -122,6 +123,7 @@ struct sh_cmt_device {
>
> struct sh_cmt_channel *channels;
> unsigned int num_channels;
> + unsigned int hw_channels;
>
> bool has_clockevent;
> bool has_clocksource;
> @@ -924,10 +926,35 @@ static int sh_cmt_map_memory(struct sh_cmt_device
> *cmt) return 0;
> }
>
> +static const struct platform_device_id sh_cmt_id_table[] = {
> + { "sh-cmt-16", (kernel_ulong_t)&sh_cmt_info[SH_CMT_16BIT] },
> + { "sh-cmt-32", (kernel_ulong_t)&sh_cmt_info[SH_CMT_32BIT] },
> + { "sh-cmt-32-fast", (kernel_ulong_t)&sh_cmt_info[SH_CMT_32BIT_FAST] },
> + { "sh-cmt-48", (kernel_ulong_t)&sh_cmt_info[SH_CMT_48BIT] },
> + { "sh-cmt-48-gen2", (kernel_ulong_t)&sh_cmt_info[SH_CMT_48BIT_GEN2] },
> + { }
> +};
> +MODULE_DEVICE_TABLE(platform, sh_cmt_id_table);
> +
> +static const struct of_device_id sh_cmt_of_table[] __maybe_unused = {
> + { .compatible = "renesas,cmt-32", .data = &sh_cmt_info[SH_CMT_32BIT] },
> + { .compatible = "renesas,cmt-32-fast", .data =
> &sh_cmt_info[SH_CMT_32BIT_FAST] }, + { .compatible = "renasas,cmt-48",
> .data = &sh_cmt_info[SH_CMT_48BIT] }, + { .compatible =
> "renesas,cmt-48-gen2", .data = &sh_cmt_info[SH_CMT_48BIT_GEN2] }, + { }
> +};
> +MODULE_DEVICE_TABLE(of, sh_cmt_of_table);
> +
> +static int sh_cmt_parse_dt(struct sh_cmt_device *cmt)
> +{
> + struct device_node *np = cmt->pdev->dev.of_node;
> +
> + return of_property_read_u32(np, "renesas,channels-mask",
> + &cmt->hw_channels);
> +}
> +
> static int sh_cmt_setup(struct sh_cmt_device *cmt, struct platform_device
> *pdev) {
> - struct sh_timer_config *cfg = pdev->dev.platform_data;
> - const struct platform_device_id *id = pdev->id_entry;
> unsigned int mask;
> unsigned int i;
> int ret;
> @@ -936,13 +963,26 @@ static int sh_cmt_setup(struct sh_cmt_device *cmt,
> struct platform_device *pdev) cmt->pdev = pdev;
> raw_spin_lock_init(&cmt->lock);
>
> - if (!cfg) {
> + if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {
> + const struct of_device_id *id;
> +
> + id = of_match_node(sh_cmt_of_table, pdev->dev.of_node);
> + cmt->info = id->data;
> +
> + ret = sh_cmt_parse_dt(cmt);
> + if (ret < 0)
> + return ret;
> + } else if (pdev->dev.platform_data) {
> + struct sh_timer_config *cfg = pdev->dev.platform_data;
> + const struct platform_device_id *id = pdev->id_entry;
> +
> + cmt->info = (const struct sh_cmt_info *)id->driver_data;
> + cmt->hw_channels = cfg->channels_mask;
> + } else {
> dev_err(&cmt->pdev->dev, "missing platform data\n");
> return -ENXIO;
> }
>
> - cmt->info = (const struct sh_cmt_info *)id->driver_data;
> -
> /* Get hold of clock. */
> cmt->clk = clk_get(&cmt->pdev->dev, "fck");
> if (IS_ERR(cmt->clk)) {
> @@ -960,8 +1000,7 @@ static int sh_cmt_setup(struct sh_cmt_device *cmt,
> struct platform_device *pdev) goto err_clk_unprepare;
>
> /* Allocate and setup the channels. */
> - cmt->num_channels = hweight8(cfg->channels_mask);
> -
> + cmt->num_channels = hweight8(cmt->hw_channels);
> cmt->channels = kzalloc(cmt->num_channels * sizeof(*cmt->channels),
> GFP_KERNEL);
> if (cmt->channels == NULL) {
> @@ -973,7 +1012,7 @@ static int sh_cmt_setup(struct sh_cmt_device *cmt,
> struct platform_device *pdev) * Use the first channel as a clock event
> device and the second channel * as a clock source. If only one channel is
> available use it for both. */
> - for (i = 0, mask = cfg->channels_mask; i < cmt->num_channels; ++i) {
> + for (i = 0, mask = cmt->hw_channels; i < cmt->num_channels; ++i) {
> unsigned int hwidx = ffs(mask) - 1;
> bool clocksource = i == 1 || cmt->num_channels == 1;
> bool clockevent = i == 0;
> @@ -1044,21 +1083,12 @@ static int sh_cmt_remove(struct platform_device
> *pdev) return -EBUSY; /* cannot unregister clockevent and clocksource */ }
>
> -static const struct platform_device_id sh_cmt_id_table[] = {
> - { "sh-cmt-16", (kernel_ulong_t)&sh_cmt_info[SH_CMT_16BIT] },
> - { "sh-cmt-32", (kernel_ulong_t)&sh_cmt_info[SH_CMT_32BIT] },
> - { "sh-cmt-32-fast", (kernel_ulong_t)&sh_cmt_info[SH_CMT_32BIT_FAST] },
> - { "sh-cmt-48", (kernel_ulong_t)&sh_cmt_info[SH_CMT_48BIT] },
> - { "sh-cmt-48-gen2", (kernel_ulong_t)&sh_cmt_info[SH_CMT_48BIT_GEN2] },
> - { }
> -};
> -MODULE_DEVICE_TABLE(platform, sh_cmt_id_table);
> -
> static struct platform_driver sh_cmt_device_driver = {
> .probe = sh_cmt_probe,
> .remove = sh_cmt_remove,
> .driver = {
> .name = "sh_cmt",
> + .of_match_table = of_match_ptr(sh_cmt_of_table),
> },
> .id_table = sh_cmt_id_table,
> };
--
Regards,
Laurent Pinchart
WARNING: multiple messages have this Message-ID (diff)
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Cc: linux-sh@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Thomas Gleixner <tglx@linutronix.de>,
Simon Horman <horms@verge.net.au>,
devicetree@vger.kernel.org
Subject: Re: [PATCH v4 09/19] clocksource: sh_cmt: Add DT support
Date: Fri, 04 Jul 2014 15:15:37 +0200 [thread overview]
Message-ID: <1897420.z4gRLGjo6K@avalon> (raw)
In-Reply-To: <1402931251-22581-10-git-send-email-laurent.pinchart+renesas@ideasonboard.com>
On Monday 16 June 2014 17:07:21 Laurent Pinchart wrote:
> Document DT bindings and parse them in the CMT driver.
>
> Cc: devicetree@vger.kernel.org
> Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
> Tested-by: Simon Horman <horms+renesas@verge.net.au>
> ---
> .../devicetree/bindings/timer/renesas,cmt.txt | 47 +++++++++++++++
> drivers/clocksource/sh_cmt.c | 66 +++++++++++++------
> 2 files changed, 95 insertions(+), 18 deletions(-)
> create mode 100644 Documentation/devicetree/bindings/timer/renesas,cmt.txt
>
> diff --git a/Documentation/devicetree/bindings/timer/renesas,cmt.txt
> b/Documentation/devicetree/bindings/timer/renesas,cmt.txt new file mode
> 100644
> index 0000000..643cfff
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/timer/renesas,cmt.txt
> @@ -0,0 +1,47 @@
> +* Renesas R-Car Compare Match Timer (CMT)
> +
> +The CMT is a multi-channel 16/32/48-bit timer/counter with configurable
> clock
> +inputs and programmable compare match.
> +
> +Channels share hardware resources but their counter and compare match value
> +are independent. A particular CMT instance can implement only a subset of
> the
> +channels supported by the CMT model. Channel indices represent the hardware
> +position of the channel in the CMT and don't match the channel numbers in
> the
> +datasheets.
> +
> +Required Properties:
> +
> + - compatible: must contain one of the following.
> + - "renesas,cmt-32" for the 32-bit CMT
> + (CMT0 on sh7372, sh73a0 and r8a7740)
> + - "renesas,cmt-32-fast" for the 32-bit CMT with fast clock support
> + (CMT[234] on sh7372, sh73a0 and r8a7740)
> + - "renasas,cmt-48" for the 48-bit CMT
Simon has spotted a nasty typo here and below in the OF match table. I'll fix
that and resubmit the pull request.
> + (CMT1 on sh7372, sh73a0 and r8a7740)
> + - "renesas,cmt-48-gen2" for the second generation 48-bit CMT
> + (CMT[01] on r8a73a4, r8a7790 and r8a7791)
> +
> + - reg: base address and length of the registers block for the timer
> module.
> + - interrupts: interrupt-specifier for the timer, one per channel.
> + - clocks: a list of phandle + clock-specifier pairs, one for each entry
> + in clock-names.
> + - clock-names: must contain "fck" for the functional clock.
> +
> + - renesas,channels-mask: bitmask of the available channels.
> +
> +
> +Example: R8A7790 (R-Car H2) CMT0 node
> +
> + CMT0 on R8A7790 implements hardware channels 5 and 6 only and names
> + them channels 0 and 1 in the documentation.
> +
> + cmt0: timer@ffca0000 {
> + compatible = "renesas,cmt-48-gen2";
> + reg = <0 0xffca0000 0 0x1004>;
> + interrupts = <0 142 IRQ_TYPE_LEVEL_HIGH>,
> + <0 142 IRQ_TYPE_LEVEL_HIGH>;
> + clocks = <&mstp1_clks R8A7790_CLK_CMT0>;
> + clock-names = "fck";
> +
> + renesas,channels-mask = <0x60>;
> + };
> diff --git a/drivers/clocksource/sh_cmt.c b/drivers/clocksource/sh_cmt.c
> index 4d00e4b..09a93c4 100644
> --- a/drivers/clocksource/sh_cmt.c
> +++ b/drivers/clocksource/sh_cmt.c
> @@ -24,6 +24,7 @@
> #include <linux/ioport.h>
> #include <linux/irq.h>
> #include <linux/module.h>
> +#include <linux/of.h>
> #include <linux/platform_device.h>
> #include <linux/pm_domain.h>
> #include <linux/pm_runtime.h>
> @@ -122,6 +123,7 @@ struct sh_cmt_device {
>
> struct sh_cmt_channel *channels;
> unsigned int num_channels;
> + unsigned int hw_channels;
>
> bool has_clockevent;
> bool has_clocksource;
> @@ -924,10 +926,35 @@ static int sh_cmt_map_memory(struct sh_cmt_device
> *cmt) return 0;
> }
>
> +static const struct platform_device_id sh_cmt_id_table[] = {
> + { "sh-cmt-16", (kernel_ulong_t)&sh_cmt_info[SH_CMT_16BIT] },
> + { "sh-cmt-32", (kernel_ulong_t)&sh_cmt_info[SH_CMT_32BIT] },
> + { "sh-cmt-32-fast", (kernel_ulong_t)&sh_cmt_info[SH_CMT_32BIT_FAST] },
> + { "sh-cmt-48", (kernel_ulong_t)&sh_cmt_info[SH_CMT_48BIT] },
> + { "sh-cmt-48-gen2", (kernel_ulong_t)&sh_cmt_info[SH_CMT_48BIT_GEN2] },
> + { }
> +};
> +MODULE_DEVICE_TABLE(platform, sh_cmt_id_table);
> +
> +static const struct of_device_id sh_cmt_of_table[] __maybe_unused = {
> + { .compatible = "renesas,cmt-32", .data = &sh_cmt_info[SH_CMT_32BIT] },
> + { .compatible = "renesas,cmt-32-fast", .data =
> &sh_cmt_info[SH_CMT_32BIT_FAST] }, + { .compatible = "renasas,cmt-48",
> .data = &sh_cmt_info[SH_CMT_48BIT] }, + { .compatible =
> "renesas,cmt-48-gen2", .data = &sh_cmt_info[SH_CMT_48BIT_GEN2] }, + { }
> +};
> +MODULE_DEVICE_TABLE(of, sh_cmt_of_table);
> +
> +static int sh_cmt_parse_dt(struct sh_cmt_device *cmt)
> +{
> + struct device_node *np = cmt->pdev->dev.of_node;
> +
> + return of_property_read_u32(np, "renesas,channels-mask",
> + &cmt->hw_channels);
> +}
> +
> static int sh_cmt_setup(struct sh_cmt_device *cmt, struct platform_device
> *pdev) {
> - struct sh_timer_config *cfg = pdev->dev.platform_data;
> - const struct platform_device_id *id = pdev->id_entry;
> unsigned int mask;
> unsigned int i;
> int ret;
> @@ -936,13 +963,26 @@ static int sh_cmt_setup(struct sh_cmt_device *cmt,
> struct platform_device *pdev) cmt->pdev = pdev;
> raw_spin_lock_init(&cmt->lock);
>
> - if (!cfg) {
> + if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {
> + const struct of_device_id *id;
> +
> + id = of_match_node(sh_cmt_of_table, pdev->dev.of_node);
> + cmt->info = id->data;
> +
> + ret = sh_cmt_parse_dt(cmt);
> + if (ret < 0)
> + return ret;
> + } else if (pdev->dev.platform_data) {
> + struct sh_timer_config *cfg = pdev->dev.platform_data;
> + const struct platform_device_id *id = pdev->id_entry;
> +
> + cmt->info = (const struct sh_cmt_info *)id->driver_data;
> + cmt->hw_channels = cfg->channels_mask;
> + } else {
> dev_err(&cmt->pdev->dev, "missing platform data\n");
> return -ENXIO;
> }
>
> - cmt->info = (const struct sh_cmt_info *)id->driver_data;
> -
> /* Get hold of clock. */
> cmt->clk = clk_get(&cmt->pdev->dev, "fck");
> if (IS_ERR(cmt->clk)) {
> @@ -960,8 +1000,7 @@ static int sh_cmt_setup(struct sh_cmt_device *cmt,
> struct platform_device *pdev) goto err_clk_unprepare;
>
> /* Allocate and setup the channels. */
> - cmt->num_channels = hweight8(cfg->channels_mask);
> -
> + cmt->num_channels = hweight8(cmt->hw_channels);
> cmt->channels = kzalloc(cmt->num_channels * sizeof(*cmt->channels),
> GFP_KERNEL);
> if (cmt->channels == NULL) {
> @@ -973,7 +1012,7 @@ static int sh_cmt_setup(struct sh_cmt_device *cmt,
> struct platform_device *pdev) * Use the first channel as a clock event
> device and the second channel * as a clock source. If only one channel is
> available use it for both. */
> - for (i = 0, mask = cfg->channels_mask; i < cmt->num_channels; ++i) {
> + for (i = 0, mask = cmt->hw_channels; i < cmt->num_channels; ++i) {
> unsigned int hwidx = ffs(mask) - 1;
> bool clocksource = i == 1 || cmt->num_channels == 1;
> bool clockevent = i == 0;
> @@ -1044,21 +1083,12 @@ static int sh_cmt_remove(struct platform_device
> *pdev) return -EBUSY; /* cannot unregister clockevent and clocksource */ }
>
> -static const struct platform_device_id sh_cmt_id_table[] = {
> - { "sh-cmt-16", (kernel_ulong_t)&sh_cmt_info[SH_CMT_16BIT] },
> - { "sh-cmt-32", (kernel_ulong_t)&sh_cmt_info[SH_CMT_32BIT] },
> - { "sh-cmt-32-fast", (kernel_ulong_t)&sh_cmt_info[SH_CMT_32BIT_FAST] },
> - { "sh-cmt-48", (kernel_ulong_t)&sh_cmt_info[SH_CMT_48BIT] },
> - { "sh-cmt-48-gen2", (kernel_ulong_t)&sh_cmt_info[SH_CMT_48BIT_GEN2] },
> - { }
> -};
> -MODULE_DEVICE_TABLE(platform, sh_cmt_id_table);
> -
> static struct platform_driver sh_cmt_device_driver = {
> .probe = sh_cmt_probe,
> .remove = sh_cmt_remove,
> .driver = {
> .name = "sh_cmt",
> + .of_match_table = of_match_ptr(sh_cmt_of_table),
> },
> .id_table = sh_cmt_id_table,
> };
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2014-07-04 13:15 UTC|newest]
Thread overview: 76+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-16 15:07 [PATCH v4 00/19] Renesas CMT, MTU2 and TMU timers DT support Laurent Pinchart
2014-06-16 15:07 ` Laurent Pinchart
2014-06-16 15:07 ` Laurent Pinchart
2014-06-16 15:07 ` [PATCH v4 01/19] clocksource: sh_tmu: Fix channel IRQ retrieval in legacy case Laurent Pinchart
2014-06-16 15:07 ` Laurent Pinchart
2014-06-16 15:07 ` [PATCH v4 02/19] clocksource: sh_cmt: Drop support for legacy platform data Laurent Pinchart
2014-06-16 15:07 ` Laurent Pinchart
2014-06-16 15:07 ` [PATCH v4 03/19] clocksource: sh_cmt: Replace global spinlock with a per-device spinlock Laurent Pinchart
2014-06-16 15:07 ` Laurent Pinchart
2014-06-16 15:07 ` [PATCH v4 04/19] clocksource: sh_tmu: Drop support for legacy platform data Laurent Pinchart
2014-06-16 15:07 ` Laurent Pinchart
2014-06-16 15:07 ` [PATCH v4 05/19] clocksource: sh_tmu: Replace global spinlock with a per-device spinlock Laurent Pinchart
2014-06-16 15:07 ` Laurent Pinchart
2014-06-16 15:07 ` [PATCH v4 06/19] clocksource: sh_mtu2: Drop support for legacy platform data Laurent Pinchart
2014-06-16 15:07 ` Laurent Pinchart
2014-06-16 15:07 ` [PATCH v4 07/19] clocksource: sh_mtu2: Replace global spinlock with a per-device spinlock Laurent Pinchart
2014-06-16 15:07 ` Laurent Pinchart
2014-06-16 15:07 ` [PATCH v4 08/19] clocksource: shmobile: Remove unused sh_timer_config members Laurent Pinchart
2014-06-16 15:07 ` Laurent Pinchart
2014-06-16 15:07 ` [PATCH v4 09/19] clocksource: sh_cmt: Add DT support Laurent Pinchart
2014-06-16 15:07 ` Laurent Pinchart
2014-06-16 15:07 ` Laurent Pinchart
2014-07-04 13:15 ` Laurent Pinchart [this message]
2014-07-04 13:15 ` Laurent Pinchart
2014-07-04 13:15 ` Laurent Pinchart
2014-06-16 15:07 ` [PATCH v4 10/19] clocksource: sh_tmu: " Laurent Pinchart
2014-06-16 15:07 ` Laurent Pinchart
2014-06-16 15:07 ` Laurent Pinchart
2014-06-17 1:11 ` Simon Horman
2014-06-17 1:11 ` Simon Horman
2014-06-17 1:11 ` Simon Horman
2014-06-16 15:07 ` [PATCH v4 11/19] clocksource: sh_mtu2: " Laurent Pinchart
2014-06-16 15:07 ` Laurent Pinchart
2014-06-16 15:07 ` Laurent Pinchart
2014-06-16 15:07 ` [PATCH v4 12/19] ARM: shmobile: r8a7790: Add CMT devices to DT Laurent Pinchart
2014-06-16 15:07 ` Laurent Pinchart
2014-06-16 15:07 ` [PATCH v4 13/19] ARM: shmobile: r8a7791: " Laurent Pinchart
2014-06-16 15:07 ` Laurent Pinchart
2014-06-16 15:07 ` [PATCH v4 14/19] ARM: shmobile: r8a7779: Add TMU " Laurent Pinchart
2014-06-16 15:07 ` Laurent Pinchart
2014-06-17 1:12 ` Simon Horman
2014-06-17 1:12 ` Simon Horman
2014-06-16 15:07 ` [PATCH v4 15/19] ARM: shmobile: r7s72100: Add MTU2 device " Laurent Pinchart
2014-06-16 15:07 ` Laurent Pinchart
2014-06-16 15:07 ` [PATCH v4 16/19] ARM: shmobile: lager-reference: Enable CMT0 in device tree Laurent Pinchart
2014-06-16 15:07 ` Laurent Pinchart
2014-06-16 15:07 ` [PATCH v4 17/19] ARM: shmobile: koelsch-reference: " Laurent Pinchart
2014-06-16 15:07 ` Laurent Pinchart
2014-06-16 15:07 ` [PATCH v4 18/19] ARM: shmobile: marzen-reference: Enable TMU0 " Laurent Pinchart
2014-06-16 15:07 ` Laurent Pinchart
2014-06-17 1:14 ` Simon Horman
2014-06-17 1:14 ` Simon Horman
2014-06-16 15:07 ` [PATCH v4 19/19] ARM: shmobile: genmai-reference: Enable MTU2 " Laurent Pinchart
2014-06-16 15:07 ` Laurent Pinchart
2014-07-02 14:23 ` [GIT PULL FOR v3.17] Renesas CMT, MTU2 and TMU timers DT support Laurent Pinchart
2014-07-02 14:23 ` Laurent Pinchart
2014-07-04 13:53 ` [GIT PULL v2 " Laurent Pinchart
2014-07-04 13:53 ` Laurent Pinchart
2014-07-09 9:59 ` Laurent Pinchart
2014-07-09 9:59 ` Laurent Pinchart
2014-07-13 9:55 ` Simon Horman
2014-07-13 9:55 ` Simon Horman
2014-07-13 13:00 ` Laurent Pinchart
2014-07-13 13:00 ` Laurent Pinchart
2014-07-13 14:42 ` Daniel Lezcano
2014-07-13 14:42 ` Daniel Lezcano
2014-07-13 20:39 ` Simon Horman
2014-07-13 20:39 ` Simon Horman
2014-07-14 21:54 ` Daniel Lezcano
2014-07-14 21:54 ` Daniel Lezcano
2014-07-15 9:09 ` Simon Horman
2014-07-15 9:09 ` Simon Horman
2014-07-14 9:06 ` Laurent Pinchart
2014-07-14 9:06 ` Laurent Pinchart
2014-07-14 10:20 ` Daniel Lezcano
2014-07-14 10:20 ` Daniel Lezcano
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=1897420.z4gRLGjo6K@avalon \
--to=laurent.pinchart@ideasonboard.com \
--cc=linux-arm-kernel@lists.infradead.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 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.