public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Peter Tyser <ptyser@xes-inc.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCHv2] pca953x: support 16-pin devices
Date: Wed, 08 Dec 2010 18:08:52 -0600	[thread overview]
Message-ID: <1291853332.20072.874.camel@petert> (raw)
In-Reply-To: <AANLkTik6U8tm44XfKZrpYYT9g2dCw-Tsx8kr7y8mjOF6@mail.gmail.com>

The patch looks good.  I had a few minor nitpicky style comments below:

> As suggested by Peter I've implemented the 16-pin support in the existing
> pca953x driver. So this is pretty much a re-write of the v1 patch. Is the commit
> message sufficient to document CONFIG_SYS_I2C_PCA953X_WIDTH or is
> there something under doc/ that I should be adding to.

You could add a brief description to the top-level README file.  There
is currently a bit of info in the "GPIO Support" section that could be
added to.

>  #include <common.h>
> @@ -38,22 +38,78 @@ enum {
>  	PCA953X_CMD_INVERT,
>  };
> 
> +#ifdef CONFIG_SYS_I2C_PCA953X_WIDTH
> +struct chip_ngpio {
> +	uint8_t chip;
> +	uint8_t ngpio;
> +};

Since this structure is 953x-specific I'd rename chip_ngpio
pca953x_chip_ngpio to clarify its a driver-specific structure and to
prevent the (unlikely) name collision down the road.

The same comment applies to ngpio()->pca953x_ngpio(),
chip_ngpios[]->pca953x_chip_ngpios[].

> +static struct chip_ngpio chip_ngpios[] = CONFIG_SYS_I2C_PCA953X_WIDTH;
> +#define NUM_CHIP_GPIOS (sizeof(chip_ngpios) / sizeof(struct chip_ngpio))
> +
> +/*
> + * Determine the number of GPIO pins supported. If we don't know we assume
> + * 8 pins.
> + */
> +static int ngpio(uint8_t chip)
> +{
> +	int i;
> +
> +	for (i = 0; i < NUM_CHIP_GPIOS; i++) {
> +		if (chip_ngpios[i].chip == chip)
> +			return chip_ngpios[i].ngpio;
> +	}

I'd remove the for loop braces above per the Linux CodingStyle
documentation that U-Boot adheres to.

There should also be an empty line above the "return 8" below.

> +	return 8;
> +}
> +#else
> +#define ngpio(chip)	8
> +#endif
> +
>  /*
>   * Modify masked bits in register
>   */
>  static int pca953x_reg_write(uint8_t chip, uint addr, uint mask, uint data)
>  {
> -	uint8_t val;
> +	uint8_t  valb;
> +	uint16_t valw;

I'd remove one of the spaces between "valb" above.  My understanding is
spaces shouldn't be used for such vertical alignment.

> 
> -	if (i2c_read(chip, addr, 1, &val, 1))
> -		return -1;
> +	if (ngpio(chip) <= 8) {
> +		if (i2c_read(chip, addr, 1, &valb, 1))
> +			return -1;
> +
> +		valb &= ~mask;
> +		valb |= data;
> +
> +		return i2c_write(chip, addr, 1, &valb, 1);
> +	} else {
> +		if (i2c_read(chip, addr << 1, 1, (u8*)&valw, 2))
> +			return -1;
> +
> +		valw &= ~mask;
> +		valw |= data;
> +
> +		return i2c_write(chip, addr << 1, 1, (u8*)&valw, 2);
> +	}
> +}
> 
> -	val &= ~mask;
> -	val |= data;
> +static int pca953x_reg_read(uint8_t chip, uint addr, uint *data)
> +{
> +	uint8_t  valb;
> +	uint16_t valw;
> 
> -	return i2c_write(chip, addr, 1, &val, 1);
> +	if (ngpio(chip) <= 8) {
> +		if (i2c_read(chip, addr, 1, &valb, 1))
> +			return -1;
> +		*data = (int) valb;

The space in "(int) valb" should be removed.  Same below.

> +	} else {
> +		if (i2c_read(chip, addr << 1, 1, (u8*)&valw, 2))
> +			return -1;
> +		*data = (int) valw;
> +	}
> +	return 0;
>  }

<snip>

> +	for (i = msb; i >= 0; i--)
> +		printf("%x",i);
> +	printf("\n");
> +	if (nr_gpio > 8)
> +		printf("--------");
>  	printf("-------------------\n");

What about changing the printing of '-'s to a for loop like
for (i = 19 + nr_gpio; i >0; i++)
	puts("-");

I'll give the next iteration of the patch a shot, it looks like it
should work just fine.

Best,
Peter

  reply	other threads:[~2010-12-09  0:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-07 22:00 [U-Boot] [PATCHv2] pca953x: support 16-pin devices Chris Packham
2010-12-09  0:08 ` Peter Tyser [this message]
2010-12-09  4:40   ` Chris Packham
2010-12-09  9:11     ` [U-Boot] [PATCHv3] " Chris Packham
2010-12-09 17:08       ` Peter Tyser
2010-12-15  2:49         ` Chris Packham
2010-12-18 23:26           ` Wolfgang Denk
2010-12-19 20:12             ` [U-Boot] [PATCHv4] " Chris Packham
2011-01-10  7:02               ` [U-Boot] [U-Boot,PATCHv4] " Heiko Schocher
2011-01-13  4:02                 ` Chris Packham
2011-01-13  6:08                   ` Peter Tyser

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=1291853332.20072.874.camel@petert \
    --to=ptyser@xes-inc.com \
    --cc=u-boot@lists.denx.de \
    /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