linux-omap.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tony Lindgren <tony@atomide.com>
To: Charulatha V <charu@ti.com>
Cc: linux-omap@vger.kernel.org, rnayak@ti.com, paul@pwsan.com,
	khilman@deeprootsystems.com
Subject: Re: [PATCH 5/9] OMAP:GPIO: Introduce support for OMAP2PLUS chip specific GPIO
Date: Wed, 5 May 2010 15:31:47 -0700	[thread overview]
Message-ID: <20100505223147.GG29604@atomide.com> (raw)
In-Reply-To: <1271951720-21714-6-git-send-email-charu@ti.com>

* Charulatha V <charu@ti.com> [100422 08:50]:
> This patch adds support for handling GPIO as a HWMOD adapted
> platform device for OMAP2PLUS chips.

<snip>

> +int __init gpio_init(void)
> +{
> +	int i = 0;
> +	static int is_early_device = true;
> +
> +	do {
> +		struct omap_device *od;
> +		struct omap_hwmod *oh;
> +		int hw_mod_name_len = 16;
> +		int l;
> +		char oh_name[hw_mod_name_len];
> +		struct omap_gpio_platform_data *pdata;
> +		char *name = "omap-gpio";
> +
> +		l = snprintf(oh_name, hw_mod_name_len, "gpio%d_hwmod", i + 1);
> +		WARN(l >= hw_mod_name_len,
> +			"String buffer overflow in GPIO device setup\n");
> +
> +		oh = omap_hwmod_lookup(oh_name);
> +		if (!oh) {
> +			pr_err("Could not look up %s\n", oh_name);
> +			i++;
> +			continue;
> +		}
> +
> +		pdata = kzalloc(sizeof(struct omap_gpio_platform_data),
> +					GFP_KERNEL);
> +		if (!pdata) {
> +			pr_err("Memory allocation failed gpio%d\n", i + 1);
> +			return -ENOMEM;
> +		}
> +		pdata->base = oh->_rt_va;
> +		pdata->irq = oh->mpu_irqs[0].irq;
> +		if (cpu_is_omap24xx() || cpu_is_omap34xx())
> +			pdata->method = METHOD_GPIO_24XX;
> +		if (cpu_is_omap44xx())
> +			pdata->method = METHOD_GPIO_44XX;
> +		pdata->virtual_irq_start = IH_GPIO_BASE + 32 * i;
> +		pdata->device_enable = omap_device_enable;
> +		pdata->device_idle = omap_device_idle;
> +		pdata->device_shutdown = omap_device_shutdown;
> +
> +		od = omap_device_build(name, i, oh, pdata,
> +					sizeof(*pdata),	omap_gpio_latency,
> +					ARRAY_SIZE(omap_gpio_latency),
> +					is_early_device);
> +		WARN(IS_ERR(od), "Cant build omap_device for %s:%s.\n",
> +					name, oh->name);
> +
> +		i++;
> +	} while (i < gpio_bank_count);
> +	is_early_device = false;
> +
> +	return 0;
> +}
> +arch_initcall(gpio_init);

You can get rid of most of the cpu_is_omapxxxx in gpio_init if you pass
the method as a parameter to gpio_init(int method). We should only need
to use cpu_is_omap exactly once for every init.

> +int __init omap2_gpio_init(void)
> +{
> +	if (cpu_is_omap242x())
> +		gpio_bank_count = 4;
> +	else if (cpu_is_omap243x())
> +		gpio_bank_count = 5;
> +	else if (cpu_is_omap34xx() || cpu_is_omap44xx())
> +		gpio_bank_count = OMAP34XX_NR_GPIOS;
> +
> +	if (gpio_init())
> +		return -EINVAL;
> +
> +	early_platform_driver_register_all("earlygpio");
> +	early_platform_driver_probe("earlygpio", gpio_bank_count, 0);
> +	return 0;
> +}

Then please replace this init with something like:

#ifdef CONFIG_ARCH_OMAP2
int __init omap242x_gpio_init(void)
{
	if (!cpu_is_omap2420())
		return -EINVAL;

	gpio_bank_count = 4;

	return gpio_init(METHOD_GPIO_24XX);
}
subsys_initcall(omap242x_gpio_init);

int __init omap243x_gpio_init(void)
{
	if (!cpu_is_omap2430())
		return -EINVAL;

	gpio_bank_count = 5;

	return gpio_init(METHOD_GPIO_24XX);
}
subsys_initcall(omap243x_gpio_init);
#endif

#ifdef CONFIG_ARCH_OMAP3
int __init omap34xx_gpio_init(void)
{
	if (!cpu_is_omap34xx())
		return -EINVAL;

	gpio_bank_count = OMAP34X_NR_GPIOS;

	return gpio_init(METHOD_GPIO_34XX);
}
subsys_initcall(omap34xx_gpio_init);
#endif
...

This way it will be more future proof when new omaps get added
and the if else stuff disappears. Also then you'll have an omap
specific function to initialize the gpio stuff.

Note that then early_platform_driver_register_all and
early_platform_driver_probe can be moved to gpio_init.

With multi-omap build the subsys_initcall runs for all of the
selected platforms, but returns early except for the machine
we're running on. All the code is optimized out for omap
specific product kernels.

Regards,

Tony

  parent reply	other threads:[~2010-05-05 22:31 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-22 15:55 [PATCH 00/09] OMAP:GPIO:Implement GPIO in HWMOD way Charulatha V
2010-04-22 15:55 ` [PATCH 1/9] OMAP:GPIO: Modify init() in preparation for platform device implementation Charulatha V
2010-04-22 15:55   ` [PATCH 2/9] OMAP:GPIO: Introduce support for OMAP15xx chip specific GPIO Charulatha V
2010-04-22 15:55     ` [PATCH 3/9] OMAP:GPIO: Introduce support for OMAP16xx " Charulatha V
2010-04-22 15:55       ` [PATCH 4/9] OMAP:GPIO: Introduce support for OMAP7xx " Charulatha V
2010-04-22 15:55         ` [PATCH 5/9] OMAP:GPIO: Introduce support for OMAP2PLUS " Charulatha V
2010-04-22 15:55           ` [PATCH 6/9] OMAP:GPIO:hwmod: add GPIO hwmods for OMAP3 Charulatha V
2010-04-22 15:55             ` [PATCH 7/9] OMAP:GPIO:hwmod: add GPIO hwmods for OMAP2420 Charulatha V
2010-04-22 15:55               ` [PATCH 8/9] OMAP:GPIO:hwmod: add GPIO hwmods for OMAP2430 Charulatha V
2010-04-22 15:55                 ` [PATCH 9/9] OMAP:GPIO: Implement GPIO as a platform device Charulatha V
2010-05-01  0:04                   ` Kevin Hilman
2010-05-04 15:59                     ` Varadarajan, Charulatha
2010-05-05 20:59                       ` Kevin Hilman
2010-05-05 22:37                         ` Tony Lindgren
2010-05-07  6:52                         ` Varadarajan, Charulatha
2010-05-12 12:29                         ` Varadarajan, Charulatha
2010-05-12 14:47                           ` Kevin Hilman
2010-05-20 10:13             ` [PATCH 6/9] OMAP:GPIO:hwmod: add GPIO hwmods for OMAP3 Benoit Cousson
2010-05-20 10:16               ` Varadarajan, Charulatha
2010-04-30 23:03           ` [PATCH 5/9] OMAP:GPIO: Introduce support for OMAP2PLUS chip specific GPIO Kevin Hilman
2010-05-04 15:59             ` Varadarajan, Charulatha
2010-05-11 14:43               ` Varadarajan, Charulatha
2010-05-11 15:25                 ` Kevin Hilman
2010-05-05 22:31           ` Tony Lindgren [this message]
2010-05-07  6:52             ` Varadarajan, Charulatha
2010-05-12 12:29             ` Varadarajan, Charulatha
2010-05-12 14:49               ` Kevin Hilman
2010-05-07  6:57 ` [PATCH 00/09] OMAP:GPIO:Implement GPIO in HWMOD way Varadarajan, Charulatha
2010-05-07 15:32   ` Tony Lindgren
2010-05-10 15:14     ` Kevin Hilman
2010-05-10 22:22       ` Tony Lindgren
2010-05-11 15:21         ` Kevin Hilman
2010-05-11 15:54           ` Tony Lindgren

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=20100505223147.GG29604@atomide.com \
    --to=tony@atomide.com \
    --cc=charu@ti.com \
    --cc=khilman@deeprootsystems.com \
    --cc=linux-omap@vger.kernel.org \
    --cc=paul@pwsan.com \
    --cc=rnayak@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 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).