All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Cousson, Benoit" <b-cousson@ti.com>
To: Tarun Kanti DebBarma <tarun.kanti@ti.com>
Cc: "linux-omap@vger.kernel.org" <linux-omap@vger.kernel.org>
Subject: Re: [PATCHv4 7/14] OMAP: dmtimer: use list instead of static array
Date: Tue, 23 Nov 2010 16:22:21 +0100	[thread overview]
Message-ID: <4CEBDC2D.90607@ti.com> (raw)
In-Reply-To: <1290220778-22244-8-git-send-email-tarun.kanti@ti.com>

On 11/20/2010 3:39 AM, Tarun Kanti DebBarma wrote:
> Convert dmtimers static array in functions into list structure.
> Please note that the static arrays will be completely removed
> in subsequent patches when dmtimer is converted to platform driver.

Why do you still need to keep your own list of timers?
The driver already contains a list of devices.
You even have some iterator available in the kernel: 
driver_for_each_device or driver_find_device.

You could probably get rid of all that stuff for my point of view.

Benoit

>
> Signed-off-by: Tarun Kanti DebBarma<tarun.kanti@ti.com>
> ---
>   arch/arm/plat-omap/dmtimer.c |   67 +++++++++++++++++++++++-------------------
>   1 files changed, 37 insertions(+), 30 deletions(-)
>
> diff --git a/arch/arm/plat-omap/dmtimer.c b/arch/arm/plat-omap/dmtimer.c
> index 10daa9d..124fd21 100644
> --- a/arch/arm/plat-omap/dmtimer.c
> +++ b/arch/arm/plat-omap/dmtimer.c
> @@ -168,6 +168,7 @@ struct omap_dm_timer {
>   	unsigned enabled:1;
>   	unsigned posted:1;
>   	struct platform_device *pdev;
> +	struct list_head node;
>   };
>
>   static int dm_timer_count;
> @@ -290,7 +291,8 @@ static struct omap_dm_timer *dm_timers;
>   static const char **dm_source_names;
>   static struct clk **dm_source_clocks;
>
> -static spinlock_t dm_timer_lock;
> +static LIST_HEAD(omap_timer_list);
> +static DEFINE_SPINLOCK(dm_timer_lock);
>
>   /*
>    * Reads timer registers in posted and non-posted mode. The posted mode bit
> @@ -340,7 +342,7 @@ static void omap_dm_timer_reset(struct omap_dm_timer *timer)
>   {
>   	u32 l;
>
> -	if (!cpu_class_is_omap2() || timer !=&dm_timers[0]) {
> +	if (!cpu_class_is_omap2() || timer->id != 1) {
>   		omap_dm_timer_write_reg(timer, OMAP_TIMER_IF_CTRL_REG, 0x06);
>   		omap_dm_timer_wait_for_reset(timer);
>   	}
> @@ -371,23 +373,24 @@ static void omap_dm_timer_prepare(struct omap_dm_timer *timer)
>
>   struct omap_dm_timer *omap_dm_timer_request(void)
>   {
> -	struct omap_dm_timer *timer = NULL;
> +	struct omap_dm_timer *timer = NULL, *t;
>   	unsigned long flags;
> -	int i;
>
>   	spin_lock_irqsave(&dm_timer_lock, flags);
> -	for (i = 0; i<  dm_timer_count; i++) {
> -		if (dm_timers[i].reserved)
> +	list_for_each_entry(t,&omap_timer_list, node) {
> +		if (t->reserved)
>   			continue;
>
> -		timer =&dm_timers[i];
> +		timer = t;
>   		timer->reserved = 1;
>   		break;
>   	}
>   	spin_unlock_irqrestore(&dm_timer_lock, flags);
>
> -	if (timer != NULL)
> +	if (timer)
>   		omap_dm_timer_prepare(timer);
> +	else
> +		pr_debug("%s: free timer not available.\n", __func__);
>
>   	return timer;
>   }
> @@ -395,23 +398,23 @@ EXPORT_SYMBOL_GPL(omap_dm_timer_request);
>
>   struct omap_dm_timer *omap_dm_timer_request_specific(int id)
>   {
> -	struct omap_dm_timer *timer;
> +	struct omap_dm_timer *timer = NULL, *t;
>   	unsigned long flags;
>
>   	spin_lock_irqsave(&dm_timer_lock, flags);
> -	if (id<= 0 || id>  dm_timer_count || dm_timers[id-1].reserved) {
> -		spin_unlock_irqrestore(&dm_timer_lock, flags);
> -		printk("BUG: warning at %s:%d/%s(): unable to get timer %d\n",
> -		       __FILE__, __LINE__, __func__, id);
> -		dump_stack();
> -		return NULL;
> +	list_for_each_entry(t,&omap_timer_list, node) {
> +		if (t->id == id&&  !t->reserved) {
> +			timer = t;
> +			timer->reserved = 1;
> +			break;
> +		}
>   	}
> -
> -	timer =&dm_timers[id-1];
> -	timer->reserved = 1;
>   	spin_unlock_irqrestore(&dm_timer_lock, flags);
>
> -	omap_dm_timer_prepare(timer);
> +	if (timer)
> +		omap_dm_timer_prepare(timer);
> +	else
> +		pr_debug("%s: timer%d not available.\n", __func__, id);
>
>   	return timer;
>   }
> @@ -474,24 +477,29 @@ EXPORT_SYMBOL_GPL(omap_dm_timer_get_irq);
>    */
>   __u32 omap_dm_timer_modify_idlect_mask(__u32 inputmask)
>   {
> -	int i;
> +	int i = 0;
> +	struct omap_dm_timer *timer = NULL;
> +	unsigned long flags;
>
>   	/* If ARMXOR cannot be idled this function call is unnecessary */
>   	if (!(inputmask&  (1<<  1)))
>   		return inputmask;
>
>   	/* If any active timer is using ARMXOR return modified mask */
> -	for (i = 0; i<  dm_timer_count; i++) {
> +	spin_lock_irqsave(&dm_timer_lock, flags);
> +	list_for_each_entry(timer,&omap_timer_list, node) {
>   		u32 l;
>
> -		l = omap_dm_timer_read_reg(&dm_timers[i], OMAP_TIMER_CTRL_REG);
> +		l = omap_dm_timer_read_reg(timer, OMAP_TIMER_CTRL_REG);
>   		if (l&  OMAP_TIMER_CTRL_ST) {
>   			if (((omap_readl(MOD_CONF_CTRL_1)>>  (i * 2))&  0x03) == 0)
>   				inputmask&= ~(1<<  1);
>   			else
>   				inputmask&= ~(1<<  2);
>   		}
> +		i++;
>   	}
> +	spin_unlock_irqrestore(&dm_timer_lock, flags);
>
>   	return inputmask;
>   }
> @@ -722,13 +730,9 @@ EXPORT_SYMBOL_GPL(omap_dm_timer_write_counter);
>
>   int omap_dm_timers_active(void)
>   {
> -	int i;
> -
> -	for (i = 0; i<  dm_timer_count; i++) {
> -		struct omap_dm_timer *timer;
> -
> -		timer =&dm_timers[i];
> +	struct omap_dm_timer *timer;
>
> +	list_for_each_entry(timer,&omap_timer_list, node) {
>   		if (!timer->enabled)
>   			continue;
>
> @@ -743,14 +747,13 @@ EXPORT_SYMBOL_GPL(omap_dm_timers_active);
>
>   int __init omap_dm_timer_init(void)
>   {
> +	unsigned long flags;
>   	struct omap_dm_timer *timer;
>   	int i, map_size = SZ_8K;	/* Module 4KB + L4 4KB except on omap1 */
>
>   	if (!(cpu_is_omap16xx() || cpu_class_is_omap2()))
>   		return -ENODEV;
>
> -	spin_lock_init(&dm_timer_lock);
> -
>   	if (cpu_class_is_omap1()) {
>   		dm_timers = omap1_dm_timers;
>   		dm_timer_count = omap1_dm_timer_count;
> @@ -795,6 +798,10 @@ int __init omap_dm_timer_init(void)
>   			timer->fclk = clk_get(NULL, clk_name);
>   		}
>   #endif
> +		timer->id = i + 1; /* id starts from 1*/
> +		spin_lock_irqsave(&dm_timer_lock, flags);
> +		list_add_tail(&timer->node,&omap_timer_list);
> +		spin_unlock_irqrestore(&dm_timer_lock, flags);
>   	}
>
>   	return 0;


  parent reply	other threads:[~2010-11-23 15:22 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-20  2:39 [PATCHv4 0/14] dmtimer adaptation to platform_driver Tarun Kanti DebBarma
2010-11-20  2:39 ` [PATCHv4 1/14] OMAP2+: dmtimer: add device names to flck nodes Tarun Kanti DebBarma
2010-11-20  2:39   ` [PATCHv4 2/14] OMAP: dmtimer: infrastructure to support hwmod Tarun Kanti DebBarma
2010-11-20  2:39     ` [PATCHv4 3/14] OMAP2420: dmtimer: add hwmod database Tarun Kanti DebBarma
2010-11-20  2:39       ` [PATCHv4 4/14] OMAP2430: " Tarun Kanti DebBarma
2010-11-20  2:39         ` [PATCHv4 5/14] OMAP3: " Tarun Kanti DebBarma
2010-11-20  2:39           ` [PATCHv4 6/14] OMAP4: " Tarun Kanti DebBarma
2010-11-20  2:39             ` [PATCHv4 7/14] OMAP: dmtimer: use list instead of static array Tarun Kanti DebBarma
2010-11-20  2:39               ` [PATCHv4 8/14] OMAP: dmtimer: platform driver Tarun Kanti DebBarma
2010-11-20  2:39                 ` [PATCHv4 9/14] OMAP1: dmtimer: conversion to platform devices Tarun Kanti DebBarma
2010-11-20  2:39                   ` [PATCHv4 10/14] OMAP: dmtimer: access routines to interrupt registers Tarun Kanti DebBarma
2010-11-20  2:39                     ` [PATCHv4 11/14] OMAP2+: dmtimer: convert to platform devices Tarun Kanti DebBarma
2010-11-20  2:39                       ` [PATCHv4 12/14] OMAP: dmtimer: switch-over to platform device driver Tarun Kanti DebBarma
2010-11-20  2:39                         ` [PATCHv4 13/14] OMAP: dmtimer: remove reset function Tarun Kanti DebBarma
2010-11-20  2:39                           ` [PATCHv4 14/14] OMAP: dmtimer: pm_runtime support Tarun Kanti DebBarma
2010-11-22  7:04                             ` Varadarajan, Charulatha
2010-11-22  7:07                               ` DebBarma, Tarun Kanti
2010-11-22  6:44                         ` [PATCHv4 12/14] OMAP: dmtimer: switch-over to platform device driver Varadarajan, Charulatha
2010-11-22  9:14                           ` DebBarma, Tarun Kanti
2010-11-22 12:00                             ` Varadarajan, Charulatha
2010-11-22 12:08                               ` DebBarma, Tarun Kanti
2010-11-22 12:35                                 ` Varadarajan, Charulatha
2010-11-22 12:55                                   ` DebBarma, Tarun Kanti
2010-11-22  6:33                       ` [PATCHv4 11/14] OMAP2+: dmtimer: convert to platform devices Varadarajan, Charulatha
2010-11-22  7:24                         ` DebBarma, Tarun Kanti
2010-11-22  8:24                       ` Varadarajan, Charulatha
2010-11-22  9:00                         ` DebBarma, Tarun Kanti
2010-11-22  9:03                           ` Varadarajan, Charulatha
2010-11-23 17:51                       ` Cousson, Benoit
2010-11-24  7:30                         ` DebBarma, Tarun Kanti
2010-11-22  7:13                 ` [PATCHv4 8/14] OMAP: dmtimer: platform driver Varadarajan, Charulatha
2010-11-22  7:26                   ` DebBarma, Tarun Kanti
2010-11-23 15:22               ` Cousson, Benoit [this message]
2010-11-24  7:01                 ` [PATCHv4 7/14] OMAP: dmtimer: use list instead of static array DebBarma, Tarun Kanti
2010-11-22  6:02             ` [PATCHv4 6/14] OMAP4: dmtimer: add hwmod database Varadarajan, Charulatha
2010-11-22  6:11               ` DebBarma, Tarun Kanti
2010-11-23 14:48     ` [PATCHv4 2/14] OMAP: dmtimer: infrastructure to support hwmod Cousson, Benoit
2010-11-24  6:53       ` DebBarma, Tarun Kanti
2010-11-22 17:32   ` [PATCHv4 1/14] OMAP2+: dmtimer: add device names to flck nodes Cousson, Benoit
2010-11-23  8:36     ` DebBarma, Tarun Kanti
2010-11-23  8:40       ` Cousson, Benoit
2010-11-23  8:43         ` DebBarma, Tarun Kanti

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=4CEBDC2D.90607@ti.com \
    --to=b-cousson@ti.com \
    --cc=linux-omap@vger.kernel.org \
    --cc=tarun.kanti@ti.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 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.