linux-sh.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v3 10/19] clocksource: sh_tmu: Add DT support
Date: Mon, 16 Jun 2014 14:32:24 +0000	[thread overview]
Message-ID: <3012797.FyNqyP1CPJ@avalon> (raw)
In-Reply-To: <20140616083423.GE11582@verge.net.au>

Hi Simon,

On Monday 16 June 2014 17:34:23 Simon Horman wrote:
> On Sat, Jun 14, 2014 at 06:23:32PM +0200, Laurent Pinchart wrote:
> > Document DT bindings and parse them in the TMU driver.
> > 
> > Signed-off-by: Laurent Pinchart
> > <laurent.pinchart+renesas@ideasonboard.com>
> 
> [snip]
> 
> > diff --git a/drivers/clocksource/sh_tmu.c b/drivers/clocksource/sh_tmu.c
> > index ef8fb0b..2ece4ab 100644
> > --- a/drivers/clocksource/sh_tmu.c
> > +++ b/drivers/clocksource/sh_tmu.c

[snip]

> > @@ -509,23 +510,46 @@ static int sh_tmu_map_memory(struct sh_tmu_device
> > *tmu)
> >  	return 0;
> >  }
> > 
> > +static int sh_tmu_parse_dt(struct sh_tmu_device *tmu)
> > +{
> > +	struct device_node *np = tmu->pdev->dev.of_node;
> > +
> > +	tmu->num_channels = 3;
> > +	of_property_read_u32(np, "#renesas,channels", &tmu->num_channels);
> > +
> > +	if (tmu->num_channels != 2 && tmu->num_channels != 3) {
> > +		dev_err(&tmu->pdev->dev, "invalid number of channels %u\n",
> > +			tmu->num_channels);
> > +		return -EINVAL;
> > +	}
> > +
> > +	return 0;
> > +}
> > +
> >  static int sh_tmu_setup(struct sh_tmu_device *tmu, struct platform_device
> >  *pdev) {
> > -	struct sh_timer_config *cfg = pdev->dev.platform_data;
> >  	const struct platform_device_id *id = pdev->id_entry;
> >  	unsigned int i;
> >  	int ret;
> > 
> > -	if (!cfg) {
> > -		dev_err(&tmu->pdev->dev, "missing platform data\n");
> > -		return -ENXIO;
> > -	}
> > -
> >  	tmu->pdev = pdev;
> >  	tmu->model = id->driver_data;
> >  	
> >  	raw_spin_lock_init(&tmu->lock);
> > 
> > +	if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {
> > +		ret = sh_tmu_parse_dt(tmu);
> > +		if (ret < 0)
> > +			return ret;
> > +	} else if (pdev->dev.platform_data) {
> > +		struct sh_timer_config *cfg = pdev->dev.platform_data;
> > +
> > +		tmu->num_channels = hweight8(cfg->channels_mask);
> > +	} else {
> > +		dev_err(&tmu->pdev->dev, "missing platform data\n");
> > +		return -ENXIO;
> > +	}
> > +
> > 
> >  	/* Get hold of clock. */
> >  	tmu->clk = clk_get(&tmu->pdev->dev, "fck");
> >  	if (IS_ERR(tmu->clk)) {
> 
> [snip]
> 
> I had a bit of trouble running this code and after some investigation
> it seems to me that in the case of using DT id will be NULL and
> thus things do not go well when id->driver_data is accessed.

Indeed. I wonder how I've missed that :-/ Anyway, I'll fix it and resubmit.

> The following incremental patch resolved the problem for me.
> 
> diff --git a/drivers/clocksource/sh_tmu.c b/drivers/clocksource/sh_tmu.c
> index 2ece4ab..3f90927 100644
> --- a/drivers/clocksource/sh_tmu.c
> +++ b/drivers/clocksource/sh_tmu.c
> @@ -523,6 +523,8 @@ static int sh_tmu_parse_dt(struct sh_tmu_device *tmu)
>  		return -EINVAL;
>  	}
> 
> +	tmu->model = SH_TMU;
> +
>  	return 0;
>  }
> 
> @@ -533,7 +535,6 @@ static int sh_tmu_setup(struct sh_tmu_device *tmu,
> struct platform_device *pdev) int ret;
> 
>  	tmu->pdev = pdev;
> -	tmu->model = id->driver_data;
> 
>  	raw_spin_lock_init(&tmu->lock);
> 
> @@ -545,6 +546,7 @@ static int sh_tmu_setup(struct sh_tmu_device *tmu,
> struct platform_device *pdev) struct sh_timer_config *cfg > pdev->dev.platform_data;
> 
>  		tmu->num_channels = hweight8(cfg->channels_mask);
> +		tmu->model = id->driver_data;
>  	} else {
>  		dev_err(&tmu->pdev->dev, "missing platform data\n");
>  		return -ENXIO;

-- 
Regards,

Laurent Pinchart


  reply	other threads:[~2014-06-16 14:32 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-14 16:23 [PATCH v3 00/19] Renesas CMT, MTU2 and TMU timers DT support Laurent Pinchart
2014-06-14 16:23 ` [PATCH v3 01/19] clocksource: sh_tmu: Fix channel IRQ retrieval in legacy case Laurent Pinchart
2014-06-14 16:23 ` [PATCH v3 02/19] clocksource: sh_cmt: Drop support for legacy platform data Laurent Pinchart
2014-06-14 16:23 ` [PATCH v3 03/19] clocksource: sh_cmt: Replace global spinlock with a per-device spinlock Laurent Pinchart
2014-06-14 16:23 ` [PATCH v3 04/19] clocksource: sh_tmu: Drop support for legacy platform data Laurent Pinchart
2014-06-14 16:23 ` [PATCH v3 05/19] clocksource: sh_tmu: Replace global spinlock with a per-device spinlock Laurent Pinchart
2014-06-14 16:23 ` [PATCH v3 06/19] clocksource: sh_mtu2: Drop support for legacy platform data Laurent Pinchart
2014-06-14 16:23 ` [PATCH v3 07/19] clocksource: sh_mtu2: Replace global spinlock with a per-device spinlock Laurent Pinchart
2014-06-14 16:23 ` [PATCH v3 08/19] clocksource: shmobile: Remove unused sh_timer_config members Laurent Pinchart
2014-06-14 16:23 ` [PATCH v3 09/19] clocksource: sh_cmt: Add DT support Laurent Pinchart
2014-06-14 16:23 ` [PATCH v3 10/19] clocksource: sh_tmu: " Laurent Pinchart
2014-06-16  8:34   ` Simon Horman
2014-06-16 14:32     ` Laurent Pinchart [this message]
2014-06-16  8:48   ` Simon Horman
2014-06-16 14:24     ` Laurent Pinchart
2014-06-14 16:23 ` [PATCH v3 11/19] clocksource: sh_mtu2: " Laurent Pinchart
2014-06-14 17:00   ` Sergei Shtylyov
2014-06-16 14:40     ` Laurent Pinchart
2014-06-16 14:50       ` Laurent Pinchart
2014-06-14 16:23 ` [PATCH v3 12/19] ARM: shmobile: r8a7790: Add CMT devices to DT Laurent Pinchart
2014-06-14 16:54   ` Sergei Shtylyov
2014-06-16 14:38     ` Laurent Pinchart
2014-06-14 16:23 ` [PATCH v3 13/19] ARM: shmobile: r8a7791: " Laurent Pinchart
2014-06-14 16:55   ` Sergei Shtylyov
2014-06-14 16:23 ` [PATCH v3 14/19] ARM: shmobile: r8a7779: Add TMU " Laurent Pinchart
2014-06-16  8:47   ` Simon Horman
2014-06-16 14:22     ` Laurent Pinchart
2014-06-16 16:19       ` Geert Uytterhoeven
2014-06-16 20:31         ` Laurent Pinchart
2014-06-16 23:34       ` Simon Horman
2014-06-14 16:23 ` [PATCH v3 15/19] ARM: shmobile: r7s72100: Add MTU2 device " Laurent Pinchart
2014-06-14 16:23 ` [PATCH v3 16/19] ARM: shmobile: lager-reference: Enable CMT0 in device tree Laurent Pinchart
2014-06-14 16:23 ` [PATCH v3 17/19] ARM: shmobile: koelsch-reference: " Laurent Pinchart
2014-06-14 16:23 ` [PATCH v3 18/19] ARM: shmobile: marzen-reference: Enable TMU0 " Laurent Pinchart
2014-06-14 16:23 ` [PATCH v3 19/19] ARM: shmobile: genmai-reference: Enable MTU2 " Laurent Pinchart
2014-06-16  9:00 ` [PATCH v3 00/19] Renesas CMT, MTU2 and TMU timers DT support Simon Horman

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=3012797.FyNqyP1CPJ@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 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).