LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Baruch Siach <baruch@tkos.co.il>
To: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v4 2/2] clocksource: driver for Conexant Digicolor SoC timer
Date: Mon, 26 Jan 2015 12:15:11 +0200	[thread overview]
Message-ID: <20150126101511.GC3148@tarshish> (raw)
In-Reply-To: <54C60C4F.50507@linaro.org>

Hi Daniel,

On Mon, Jan 26, 2015 at 10:43:43AM +0100, Daniel Lezcano wrote:
[...]
> >+static struct dc_dev_t {
> >+	void __iomem *timer_base;
> >+	u32 ticks_per_jiffy;
> >+} dc_dev;
> 
> Hi Baruch,
> 
> your code is valid but I think there is a misunderstanding when we talked
> about the encapsulation.
> 
> I was expecting something like:
> 
> static struct digicolor_timer {
> 	void __iomem *base;
> 	u32 ticks_per_jiffy;
> 	int channel;
> 	struct clock_event_device ce;
> };
> 
> struct digicolor_timer *dg_timer(struct clock_event_device *ce)
> {
> 	return container_of(ce, struct digicolor_timer, ce);
> }
> 
> So the timer could be accessed directly from the clock_event_device
> structure. The exception is the 'sched_read' and the init function where you
> will have to address directly the global variable.
> 
> Perhaps, that would be nice if you take the opportunity to encapsulate the
> enable/disable functions.
> 
> static inline void dg_timer_disable(struct clock_event_device *ce)
> {
> 	struct digital_timer *dt = dg_timer(ce);
> 	writeb(CONTROL_DISABLE, dt->base + CONTROL(dt->channel));	
> }
> 
> static inline void dg_timer_enable(struct clock_event_device *ce, int mode)
> {
> 	struct digital_timer *dt = dg_timer(ce);
> 	writeb(CONTROL_ENABLE | mode, dt->base, CONTROL(dt->channel));
> }
> 
> >+
> >+static void digicolor_clkevt_mode(enum clock_event_mode mode,
> >+				  struct clock_event_device *clk)
> 
> IMO, 'clk' argument name is confusing. I would suggest to use 'ce' or
> whatever.
> 
> >+{
> >+	switch (mode) {
> >+	case CLOCK_EVT_MODE_PERIODIC:
> >+		writeb(CONTROL_DISABLE, dc_dev.timer_base + CONTROL(TIMER_C));
> >+		writel(dc_dev.ticks_per_jiffy,
> >+		       dc_dev.timer_base + COUNT(TIMER_C));
> >+		writeb(CONTROL_ENABLE | CONTROL_MODE_PERIODIC,
> >+		       dc_dev.timer_base + CONTROL(TIMER_C));
> 
> Becomes:
> 
> 		dg_timer_disable(ce);
> 		dg_timer_enable(ce, CONTROL_MODE_PERIODIC);
> 
> ...
> 
> >+		break;
> >+	case CLOCK_EVT_MODE_ONESHOT:
> >+		writeb(CONTROL_DISABLE, dc_dev.timer_base + CONTROL(TIMER_C));
> >+		writeb(CONTROL_ENABLE | CONTROL_MODE_ONESHOT,
> >+		       dc_dev.timer_base + CONTROL(TIMER_C));
> 
> 
> Becomes:
> 		dg_timer_disable(ce);
> 		dg_timer_enable(ce, CONTROL_MODE_ONESHOT);
> 	
> 
> >+		break;
> >+	case CLOCK_EVT_MODE_UNUSED:
> >+	case CLOCK_EVT_MODE_SHUTDOWN:
> >+	default:
> >+		writeb(CONTROL_DISABLE, dc_dev.timer_base + CONTROL(TIMER_C));
> 
> Becomes:
> 		dg_timer_disable(ce);
> 
> >+		break;
> >+	}
> >+}
> >+
> >+static int digicolor_clkevt_next_event(unsigned long evt,
> >+				       struct clock_event_device *unused)
> >+{
> >+	writeb(CONTROL_DISABLE, dc_dev.timer_base + CONTROL(TIMER_C));
> >+	writel(evt, dc_dev.timer_base + COUNT(TIMER_C));
> >+	writeb(CONTROL_ENABLE | CONTROL_MODE_ONESHOT,
> >+	       dc_dev.timer_base + CONTROL(TIMER_C));
> 
> Becomes:
> 	dg_timer_disable(ce);
> 	writel(evt, dg_timer(ce)->base + COUNT(dg_timer(ce)->base));
> 	dg_timer_enable(ce, CONTROL_MODE_ONESHOT);
> >+	return 0;
> >+}
> >+
> >+static struct clock_event_device digicolor_clockevent = {
> >+	.name = "digicolor_tick",
> >+	.rating = 340,
> >+	.features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
> >+	.set_mode = digicolor_clkevt_mode,
> >+	.set_next_event = digicolor_clkevt_next_event,
> >+};
> 
> 
> struct digicolor_timer dg_timer = {
> 	
> 	.ce = {
> 		.name = "digicolor_tick",
> 		.rating = 340,
> 		.features = CLOCK_EVT_FEAT_PERIODIC |
> 				CLOCK_EVT_FEAT_ONESHOT,
> 		.set_mode = digicolor_clkevt_mode,
> 		.set_next_event = digicolor_clkevt_next_event,
> 	},
> 	.channel = TIMER_C,
> };
> 
> What do you think ?

OK. I'll give it a try.

Thanks for your prompt response and thorough review.

baruch

-- 
     http://baruch.siach.name/blog/                  ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch@tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -

  reply	other threads:[~2015-01-26 10:18 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-26  7:56 [PATCH v4 0/2] clocksource: Conexant CX92755 timers support Baruch Siach
2015-01-26  7:56 ` [PATCH v4 1/2] clocksource: devicetree: document Conexant Digicolor timer binding Baruch Siach
2015-01-26  7:56 ` [PATCH v4 2/2] clocksource: driver for Conexant Digicolor SoC timer Baruch Siach
2015-01-26  9:43   ` Daniel Lezcano
2015-01-26 10:15     ` Baruch Siach [this message]
2015-01-26 10:26       ` Daniel Lezcano
2015-01-26 10:38       ` Thomas Gleixner

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=20150126101511.GC3148@tarshish \
    --to=baruch@tkos.co.il \
    --cc=daniel.lezcano@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --subject='Re: [PATCH v4 2/2] clocksource: driver for Conexant Digicolor SoC timer' \
    /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

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).