aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
authorDavid Brownell <david-b@pacbell.net>2008-02-29 01:07:28 -0500
committerTony Lindgren <tony@atomide.com>2008-04-14 12:57:06 -0400
commit79966fd9b4781f9bd257312489ff511f2c01f210 (patch)
tree43ed798fcb5dabdb334f5a00f173d0a5fccf4be9 /drivers/i2c
parentac37a0b0ba7e8a6afce8db3f6c3367a3cfedad26 (diff)
ARM: OMAP: I2C: tps65010 driver converts to gpiolib
Make the tps65010 driver use gpiolib to expose its GPIOs. Note: This patch will get merged via omap tree instead of I2C as it will cause some board updates. This has been discussed at on the I2C list: http://lists.lm-sensors.org/pipermail/i2c/2008-March/003031.html Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Cc: i2c@lm-sensors.org Signed-off-by: Tony Lindgren <tony@atomide.com>
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/chips/Kconfig1
-rw-r--r--drivers/i2c/chips/tps65010.c101
2 files changed, 101 insertions, 1 deletions
diff --git a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig
index b21593f93586..2da2edfa68ec 100644
--- a/drivers/i2c/chips/Kconfig
+++ b/drivers/i2c/chips/Kconfig
@@ -93,6 +93,7 @@ config ISP1301_OMAP
93 93
94config TPS65010 94config TPS65010
95 tristate "TPS6501x Power Management chips" 95 tristate "TPS6501x Power Management chips"
96 depends on HAVE_GPIO_LIB
96 default y if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_OSK 97 default y if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_OSK
97 help 98 help
98 If you say yes here you get support for the TPS6501x series of 99 If you say yes here you get support for the TPS6501x series of
diff --git a/drivers/i2c/chips/tps65010.c b/drivers/i2c/chips/tps65010.c
index 4154a9108859..b67f69c2e7f3 100644
--- a/drivers/i2c/chips/tps65010.c
+++ b/drivers/i2c/chips/tps65010.c
@@ -30,9 +30,13 @@
30#include <linux/debugfs.h> 30#include <linux/debugfs.h>
31#include <linux/seq_file.h> 31#include <linux/seq_file.h>
32#include <linux/mutex.h> 32#include <linux/mutex.h>
33#include <linux/platform_device.h>
33 34
34#include <linux/i2c/tps65010.h> 35#include <linux/i2c/tps65010.h>
35 36
37#include <asm/gpio.h>
38
39
36/*-------------------------------------------------------------------------*/ 40/*-------------------------------------------------------------------------*/
37 41
38#define DRIVER_VERSION "2 May 2005" 42#define DRIVER_VERSION "2 May 2005"
@@ -84,7 +88,9 @@ struct tps65010 {
84 u8 chgstatus, regstatus, chgconf; 88 u8 chgstatus, regstatus, chgconf;
85 u8 nmask1, nmask2; 89 u8 nmask1, nmask2;
86 90
87 /* not currently tracking GPIO state */ 91 u8 outmask;
92 struct gpio_chip chip;
93 struct platform_device *leds;
88}; 94};
89 95
90#define POWER_POLL_DELAY msecs_to_jiffies(5000) 96#define POWER_POLL_DELAY msecs_to_jiffies(5000)
@@ -449,12 +455,72 @@ static irqreturn_t tps65010_irq(int irq, void *_tps)
449 455
450/*-------------------------------------------------------------------------*/ 456/*-------------------------------------------------------------------------*/
451 457
458/* offsets 0..3 == GPIO1..GPIO4
459 * offsets 4..5 == LED1/nPG, LED2 (we set one of the non-BLINK modes)
460 */
461static void
462tps65010_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
463{
464 if (offset < 4)
465 tps65010_set_gpio_out_value(offset + 1, value);
466 else
467 tps65010_set_led(offset - 3, value ? ON : OFF);
468}
469
470static int
471tps65010_output(struct gpio_chip *chip, unsigned offset, int value)
472{
473 /* GPIOs may be input-only */
474 if (offset < 4) {
475 struct tps65010 *tps;
476
477 tps = container_of(chip, struct tps65010, chip);
478 if (!(tps->outmask & (1 << offset)))
479 return -EINVAL;
480 tps65010_set_gpio_out_value(offset + 1, value);
481 } else
482 tps65010_set_led(offset - 3, value ? ON : OFF);
483
484 return 0;
485}
486
487static int tps65010_gpio_get(struct gpio_chip *chip, unsigned offset)
488{
489 int value;
490 struct tps65010 *tps;
491
492 tps = container_of(chip, struct tps65010, chip);
493
494 if (offset < 4) {
495 value = i2c_smbus_read_byte_data(tps->client, TPS_DEFGPIO);
496 if (value < 0)
497 return 0;
498 if (value & (1 << (offset + 4))) /* output */
499 return !(value & (1 << offset));
500 else /* input */
501 return (value & (1 << offset));
502 }
503
504 /* REVISIT we *could* report LED1/nPG and LED2 state ... */
505 return 0;
506}
507
508
509/*-------------------------------------------------------------------------*/
510
452static struct tps65010 *the_tps; 511static struct tps65010 *the_tps;
453 512
454static int __exit tps65010_remove(struct i2c_client *client) 513static int __exit tps65010_remove(struct i2c_client *client)
455{ 514{
456 struct tps65010 *tps = i2c_get_clientdata(client); 515 struct tps65010 *tps = i2c_get_clientdata(client);
516 struct tps65010_board *board = client->dev.platform_data;
457 517
518 if (board && board->teardown) {
519 int status = board->teardown(client, board->context);
520 if (status < 0)
521 dev_dbg(&client->dev, "board %s %s err %d\n",
522 "teardown", client->name, status);
523 }
458 if (client->irq > 0) 524 if (client->irq > 0)
459 free_irq(client->irq, tps); 525 free_irq(client->irq, tps);
460 cancel_delayed_work(&tps->work); 526 cancel_delayed_work(&tps->work);
@@ -469,6 +535,7 @@ static int tps65010_probe(struct i2c_client *client)
469{ 535{
470 struct tps65010 *tps; 536 struct tps65010 *tps;
471 int status; 537 int status;
538 struct tps65010_board *board = client->dev.platform_data;
472 539
473 if (the_tps) { 540 if (the_tps) {
474 dev_dbg(&client->dev, "only one tps6501x chip allowed\n"); 541 dev_dbg(&client->dev, "only one tps6501x chip allowed\n");
@@ -577,6 +644,38 @@ static int tps65010_probe(struct i2c_client *client)
577 644
578 tps->file = debugfs_create_file(DRIVER_NAME, S_IRUGO, NULL, 645 tps->file = debugfs_create_file(DRIVER_NAME, S_IRUGO, NULL,
579 tps, DEBUG_FOPS); 646 tps, DEBUG_FOPS);
647
648 /* optionally register GPIOs */
649 if (board && board->base > 0) {
650 tps->outmask = board->outmask;
651
652 tps->chip.label = client->name;
653
654 tps->chip.set = tps65010_gpio_set;
655 tps->chip.direction_output = tps65010_output;
656
657 /* NOTE: only partial support for inputs; nyet IRQs */
658 tps->chip.get = tps65010_gpio_get;
659
660 tps->chip.base = board->base;
661 tps->chip.ngpio = 6;
662 tps->chip.can_sleep = 1;
663
664 status = gpiochip_add(&tps->chip);
665 if (status < 0)
666 dev_err(&client->dev, "can't add gpiochip, err %d\n",
667 status);
668 else if (board->setup) {
669 status = board->setup(client, board->context);
670 if (status < 0) {
671 dev_dbg(&client->dev,
672 "board %s %s err %d\n",
673 "setup", client->name, status);
674 status = 0;
675 }
676 }
677 }
678
580 return 0; 679 return 0;
581fail1: 680fail1:
582 kfree(tps); 681 kfree(tps);