All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nishanth Menon <nm@ti.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/2] gpio: tca642x: Add the tca642x gpio expander driver
Date: Mon, 8 Jul 2013 16:27:57 -0500	[thread overview]
Message-ID: <51DB2EDD.5040107@ti.com> (raw)
In-Reply-To: <1373316840-28436-1-git-send-email-dmurphy@ti.com>

On 07/08/2013 03:53 PM, Dan Murphy wrote:
> Add the tca642x gpio expander driver
http://www.ti.com/sitesearch/docs/universalsearch.tsp?searchTerm=tca642&linkId=1
I think there are just TCA6424 ?
giving a link to the product helps I suppose.
>
> Signed-off-by: Dan Murphy <dmurphy@ti.com>
> ---
>   drivers/gpio/Makefile  |    1 +
>   drivers/gpio/tca642x.c |  312 ++++++++++++++++++++++++++++++++++++++++++++++++
>   include/tca642x.h      |   64 ++++++++++
>   3 files changed, 377 insertions(+)
>   create mode 100644 drivers/gpio/tca642x.c
>   create mode 100644 include/tca642x.h
>
> diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
> index f77c1ec..7e74dfe 100644
> --- a/drivers/gpio/Makefile
> +++ b/drivers/gpio/Makefile
> @@ -49,6 +49,7 @@ COBJS-$(CONFIG_BCM2835_GPIO)	+= bcm2835_gpio.o
>   COBJS-$(CONFIG_S3C2440_GPIO)	+= s3c2440_gpio.o
>   COBJS-$(CONFIG_XILINX_GPIO)	+= xilinx_gpio.o
>   COBJS-$(CONFIG_ADI_GPIO2)	+= adi_gpio2.o
> +COBJS-$(CONFIG_TCA642X)		+= tca642x.o
>
>   COBJS	:= $(COBJS-y)
>   SRCS 	:= $(COBJS:.o=.c)
> diff --git a/drivers/gpio/tca642x.c b/drivers/gpio/tca642x.c
> new file mode 100644
> index 0000000..740714d
> --- /dev/null
> +++ b/drivers/gpio/tca642x.c
> @@ -0,0 +1,312 @@
> +/*
> + * Copyright 2013 Texas Instruments, Inc.
> + *
> + * Derived work from the pca953x.c driver
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * Version 2 as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
> + * MA 02111-1307 USA
> + */
> +
> +#include <common.h>
> +#include <i2c.h>
> +#include <tca642x.h>
> +
> +/* tca642x register address definitions */
> +struct tca642x_bank_info tca642x_banks[] = {
> +	{0x00, 0x04, 0x08, 0x0c},
> +	{0x01, 0x05, 0x09, 0x0d},
> +	{0x02, 0x06, 0x0a, 0x0e},
could we use explicit map of the struct params? helps any future expansion.

> +};
> +
> +/*
> + * Modify masked bits in register
> + */
> +static int tca642x_reg_write(uint8_t chip, uint addr, uint mask, uint data)
> +{
> +	uint16_t valw;
why not use u8 instead? same for mask and data?
> +	int org_bus_num;
> +	int ret;
> +
> +	org_bus_num = i2c_get_bus_num();
> +	i2c_set_bus_num(CONFIG_SYS_I2C_TCA642X_BUS_NUM);
> +
> +	if (i2c_read(chip, addr, 1, (u8 *)&valw, 1)) {
> +		printf("Could not read before writing\n");
> +		ret = -1;
> +		goto error;
> +	}
> +	valw &= ~mask;
data &= mask ?
> +	valw |= data;
> +
> +	ret = i2c_write(chip, addr, 1, (u8 *)&valw, 1);
> +
> +error:
> +	i2c_set_bus_num(org_bus_num);
> +	return ret;
> +
extra eol?
> +}
> +
> +static int tca642x_reg_read(uint8_t chip, uint addr, uint *data)
same here? addr is u8, data is u8 *?
> +{
> +	uint16_t valw;
val as u8?
> +	int org_bus_num;
> +	int ret = 0;
> +
> +	org_bus_num = i2c_get_bus_num();
> +	i2c_set_bus_num(CONFIG_SYS_I2C_TCA642X_BUS_NUM);
> +	if (i2c_read(chip, addr, 1, (u8 *)&valw, 1)) {
> +		ret = -1;
> +		goto error;
> +	}
> +
> +	*data = (int)valw;
> +
> +error:
> +	i2c_set_bus_num(org_bus_num);
> +	return ret;
> +}
[...]
-- 
Regards,
Nishanth Menon

  parent reply	other threads:[~2013-07-08 21:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-08 20:53 [U-Boot] [PATCH 1/2] gpio: tca642x: Add the tca642x gpio expander driver Dan Murphy
2013-07-08 20:54 ` [U-Boot] [PATCH 2/2] omap5: Configure the tca6424 gpio expander Dan Murphy
2013-07-08 21:19   ` Nishanth Menon
2013-07-09 16:20     ` Dan Murphy
2013-07-08 21:27 ` Nishanth Menon [this message]
2013-07-09 16:17   ` [U-Boot] [PATCH 1/2] gpio: tca642x: Add the tca642x gpio expander driver Dan Murphy
2013-07-09 16:21     ` Nishanth Menon

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=51DB2EDD.5040107@ti.com \
    --to=nm@ti.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 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.