linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: ryan@bluewatersys.com (Ryan Mallon)
To: linux-arm-kernel@lists.infradead.org
Subject: GPIO support for HTC Dream
Date: Wed, 09 Dec 2009 11:10:54 +1300	[thread overview]
Message-ID: <4B1ECEEE.3000209@bluewatersys.com> (raw)
In-Reply-To: <20091208214658.GC4164@elf.ucw.cz>

Pavel Machek wrote:
> Add GPIO support for HTC Dream.
> 
> Signed-off-by: Pavel Machek <pavel@ucw.cz>
> 
> +int register_gpio_chip(struct gpio_chip *new_gpio_chip)
> +{
> +	int err = 0;
> +	struct gpio_chip *gpio_chip;
> +	int i;
> +	unsigned long irq_flags;
> +	/* Start/end indexes into chip array */
> +	unsigned int start, end;
> +	int size = (new_gpio_chip->end + 1 - new_gpio_chip->start) *
> +		   sizeof(new_gpio_chip->state[0]);
> +
> +	new_gpio_chip->state = kzalloc(size, GFP_KERNEL);
> +	if (new_gpio_chip->state == NULL) {
> +		printk(KERN_ERR "register_gpio_chip: failed to allocate state\n");
> +		return -ENOMEM;
> +	}
> +
> +	spin_lock_irqsave(&gpio_chips_lock, irq_flags);
> +	start = GPIO_NUM_TO_CHIP_INDEX(new_gpio_chip->start);
> +	end = GPIO_NUM_TO_CHIP_INDEX(new_gpio_chip->end);
> +
> +	if (end >= gpio_chip_array_size) {
> +		/* New gpio chip array */
> +		struct gpio_chip **new_array;
> +		/* Size of gpio chip array */
> +		unsigned long array_size = end + 1;
> +
> +		new_array = kmalloc(array_size * sizeof(new_array[0]), GFP_ATOMIC);
> +		if (!new_array) {
> +			printk(KERN_ERR "register_gpio_chip: failed to allocate array\n");
> +			err = -ENOMEM;
> +			goto failed;
> +		}
> +		for (i = 0; i < gpio_chip_array_size; i++)
> +			new_array[i] = gpio_chip_array[i];
> +		for (i = gpio_chip_array_size; i < array_size; i++)
> +			new_array[i] = NULL;
> +		gpio_chip_array = new_array;
> +		gpio_chip_array_size = array_size;
> +	}
> +
> +	list_for_each_entry(gpio_chip, &gpio_chip_list, list) {
> +		if (gpio_chip->start > new_gpio_chip->end) {
> +			list_add_tail(&new_gpio_chip->list, &gpio_chip->list);
> +			goto added;
> +		}
> +		if (gpio_chip->end >= new_gpio_chip->start) {
> +			printk(KERN_ERR "register_gpio_source %u-%u overlaps with %u-%u\n",
> +			       new_gpio_chip->start, new_gpio_chip->end,
> +			       gpio_chip->start, gpio_chip->end);
> +			err = -EBUSY;
> +			goto failed;
> +		}
> +	}
> +
> +	list_add_tail(&new_gpio_chip->list, &gpio_chip_list);
> +added:
> +	for (i = start; i <= end; i++) {
> +		if ((!gpio_chip_array[i]) || gpio_chip_array[i]->start > new_gpio_chip->start)
> +			gpio_chip_array[i] = new_gpio_chip;
> +	}
> +failed:
> +	spin_unlock_irqrestore(&gpio_chips_lock, irq_flags);
> +	if (err)
> +		kfree(new_gpio_chip->state);
> +	return err;
> +}

This is still really screwy. Why are you creating your own version of
struct gpio_chip in addition to the one in include/asm-generic/gpio.h
(which you also appear to include in some places). It makes the code
extremely confusing. Other architectures use wrapper structures. Can you
have something like this instead:

	struct dream_gpio_chip {
		struct gpio_chip chip;

		/* Dream specific bits */
	};

The name of this function also needs to be changed to something less
generic since it is being exported globally.

I also think this function is doing way to much work for what it is.
Does it really need to be this complicated?

~Ryan

-- 
Bluewater Systems Ltd - ARM Technology Solution Centre

Ryan Mallon         		5 Amuri Park, 404 Barbadoes St
ryan at bluewatersys.com         	PO Box 13 889, Christchurch 8013
http://www.bluewatersys.com	New Zealand
Phone: +64 3 3779127		Freecall: Australia 1800 148 751
Fax:   +64 3 3779135			  USA 1800 261 2934

  parent reply	other threads:[~2009-12-08 22:10 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-08 10:28 GPIO support for HTC Dream Pavel Machek
2009-12-08 20:22 ` Ryan Mallon
2009-12-08 21:37   ` Pavel Machek
2009-12-08 21:53     ` Ryan Mallon
2009-12-10 16:26       ` Pavel Machek
2009-12-08 21:56     ` Arve Hjønnevåg
2009-12-09 11:32       ` Pavel Machek
2009-12-08 21:46   ` Pavel Machek
2009-12-08 22:03     ` Joe Perches
2009-12-09 11:46       ` Pavel Machek
2009-12-08 22:10     ` Ryan Mallon [this message]
2009-12-09 23:40       ` Ryan Mallon
2009-12-10 17:24         ` Pavel Machek
2009-12-10 17:41           ` Mark Brown
2009-12-10 19:49           ` Ryan Mallon
2009-12-10 23:14             ` H Hartley Sweeten
2009-12-11 19:58               ` Pavel Machek
2009-12-11 22:10               ` Pavel Machek
2009-12-11 22:40                 ` Arve Hjønnevåg
2009-12-11 23:12                   ` H Hartley Sweeten
2009-12-16 22:53                     ` Pavel Machek
2009-12-16 23:03                       ` Daniel Walker
2009-12-11 23:04                 ` H Hartley Sweeten
2009-12-14  6:45                   ` Pavel Machek
2009-12-14 17:54                     ` Daniel Walker
2009-12-14 18:12                       ` H Hartley Sweeten
2009-12-15  6:40                         ` Arve Hjønnevåg
2009-12-15 19:12                           ` Pavel Machek
2009-12-15 20:07                             ` Daniel Walker
2009-12-15 21:21                               ` Pavel Machek
2009-12-15 20:48                         ` Jamie Lokier
2009-12-15 21:07                           ` Brian Swetland
2009-12-14 19:00                     ` H Hartley Sweeten
2009-12-15 19:47                       ` Pavel Machek
2009-12-15 20:15                         ` H Hartley Sweeten
2009-12-15 20:47                           ` Pavel Machek
2009-12-15 21:16                           ` [patch] " Pavel Machek
2009-12-25 17:10                             ` Pavel Machek
2009-12-25 23:49                               ` Daniel Walker
2009-12-26  8:51                                 ` Pavel Machek
2009-12-15 20:24                         ` Ryan Mallon
2009-12-15 20:44                           ` Pavel Machek
2009-12-15  6:48                     ` Arve Hjønnevåg
2009-12-11 23:28                 ` Russell King - ARM Linux
2009-12-11 23:50                   ` H Hartley Sweeten
2009-12-14  6:24                   ` Pavel Machek
2009-12-10 16:57       ` Pavel Machek
2009-12-08 22:45 ` Russell King - ARM Linux
2009-12-09  0:39   ` Arve Hjønnevåg
2009-12-09 11:37     ` Pavel Machek
2009-12-09 11:42       ` Arve Hjønnevåg
2009-12-10 16:27         ` Pavel Machek
2009-12-09 16:18       ` Daniel Walker
2009-12-13 21:29         ` Pavel Machek
2009-12-13 21:38           ` Brian Swetland
2009-12-15 19:09             ` Pavel Machek
2009-12-14 17:40           ` Daniel Walker
2009-12-15 19:10             ` Pavel Machek
2009-12-09 11:41   ` Pavel Machek

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=4B1ECEEE.3000209@bluewatersys.com \
    --to=ryan@bluewatersys.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).