aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/chips/tps65010.c184
1 files changed, 38 insertions, 146 deletions
diff --git a/drivers/i2c/chips/tps65010.c b/drivers/i2c/chips/tps65010.c
index 402d911a9e7b..e320994b981c 100644
--- a/drivers/i2c/chips/tps65010.c
+++ b/drivers/i2c/chips/tps65010.c
@@ -24,20 +24,13 @@
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/interrupt.h> 26#include <linux/interrupt.h>
27#include <linux/device.h>
28#include <linux/i2c.h> 27#include <linux/i2c.h>
29#include <linux/delay.h> 28#include <linux/delay.h>
30#include <linux/workqueue.h> 29#include <linux/workqueue.h>
31#include <linux/suspend.h>
32#include <linux/debugfs.h> 30#include <linux/debugfs.h>
33#include <linux/seq_file.h> 31#include <linux/seq_file.h>
34#include <linux/mutex.h> 32#include <linux/mutex.h>
35 33
36#include <asm/irq.h>
37#include <asm/mach-types.h>
38
39#include <asm/arch/gpio.h>
40#include <asm/arch/mux.h>
41#include <asm/arch/tps65010.h> 34#include <asm/arch/tps65010.h>
42 35
43/*-------------------------------------------------------------------------*/ 36/*-------------------------------------------------------------------------*/
@@ -48,10 +41,6 @@
48MODULE_DESCRIPTION("TPS6501x Power Management Driver"); 41MODULE_DESCRIPTION("TPS6501x Power Management Driver");
49MODULE_LICENSE("GPL"); 42MODULE_LICENSE("GPL");
50 43
51static unsigned short normal_i2c[] = { 0x48, /* 0x49, */ I2C_CLIENT_END };
52
53I2C_CLIENT_INSMOD;
54
55static struct i2c_driver tps65010_driver; 44static struct i2c_driver tps65010_driver;
56 45
57/*-------------------------------------------------------------------------*/ 46/*-------------------------------------------------------------------------*/
@@ -79,10 +68,8 @@ enum tps_model {
79}; 68};
80 69
81struct tps65010 { 70struct tps65010 {
82 struct i2c_client c;
83 struct i2c_client *client; 71 struct i2c_client *client;
84 struct mutex lock; 72 struct mutex lock;
85 int irq;
86 struct delayed_work work; 73 struct delayed_work work;
87 struct dentry *file; 74 struct dentry *file;
88 unsigned charging:1; 75 unsigned charging:1;
@@ -445,7 +432,7 @@ static void tps65010_work(struct work_struct *work)
445 } 432 }
446 433
447 if (test_and_clear_bit(FLAG_IRQ_ENABLE, &tps->flags)) 434 if (test_and_clear_bit(FLAG_IRQ_ENABLE, &tps->flags))
448 enable_irq(tps->irq); 435 enable_irq(tps->client->irq);
449 436
450 mutex_unlock(&tps->lock); 437 mutex_unlock(&tps->lock);
451} 438}
@@ -464,116 +451,75 @@ static irqreturn_t tps65010_irq(int irq, void *_tps)
464 451
465static struct tps65010 *the_tps; 452static struct tps65010 *the_tps;
466 453
467static int __exit tps65010_detach_client(struct i2c_client *client) 454static int __exit tps65010_remove(struct i2c_client *client)
468{ 455{
469 struct tps65010 *tps; 456 struct tps65010 *tps = i2c_get_clientdata(client);
470 457
471 tps = container_of(client, struct tps65010, c); 458 if (client->irq > 0)
472 free_irq(tps->irq, tps); 459 free_irq(client->irq, tps);
473#ifdef CONFIG_ARM
474 if (machine_is_omap_h2())
475 omap_free_gpio(58);
476 if (machine_is_omap_osk())
477 omap_free_gpio(OMAP_MPUIO(1));
478#endif
479 cancel_delayed_work(&tps->work); 460 cancel_delayed_work(&tps->work);
480 flush_scheduled_work(); 461 flush_scheduled_work();
481 debugfs_remove(tps->file); 462 debugfs_remove(tps->file);
482 if (i2c_detach_client(client) == 0) 463 kfree(tps);
483 kfree(tps);
484 the_tps = NULL; 464 the_tps = NULL;
485 return 0; 465 return 0;
486} 466}
487 467
488static int tps65010_noscan(struct i2c_adapter *bus) 468static int tps65010_probe(struct i2c_client *client)
489{
490 /* pure paranoia, in case someone adds another i2c bus
491 * after our init section's gone...
492 */
493 return -ENODEV;
494}
495
496/* no error returns, they'd just make bus scanning stop */
497static int __init
498tps65010_probe(struct i2c_adapter *bus, int address, int kind)
499{ 469{
500 struct tps65010 *tps; 470 struct tps65010 *tps;
501 int status; 471 int status;
502 unsigned long irqflags;
503 struct i2c_client *client;
504 472
505 if (the_tps) { 473 if (the_tps) {
506 dev_dbg(&bus->dev, "only one %s for now\n", DRIVER_NAME); 474 dev_dbg(&client->dev, "only one tps6501x chip allowed\n");
507 return 0; 475 return -ENODEV;
508 } 476 }
509 477
478 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
479 return -EINVAL;
480
510 tps = kzalloc(sizeof *tps, GFP_KERNEL); 481 tps = kzalloc(sizeof *tps, GFP_KERNEL);
511 if (!tps) 482 if (!tps)
512 return 0; 483 return -ENOMEM;
513 484
514 mutex_init(&tps->lock); 485 mutex_init(&tps->lock);
515 INIT_DELAYED_WORK(&tps->work, tps65010_work); 486 INIT_DELAYED_WORK(&tps->work, tps65010_work);
516 tps->irq = -1; 487 tps->client = client;
517 tps->c.addr = address;
518 tps->c.adapter = bus;
519 tps->c.driver = &tps65010_driver;
520 strlcpy(tps->c.name, DRIVER_NAME, I2C_NAME_SIZE);
521 tps->client = client = &tps->c;
522
523 status = i2c_attach_client(client);
524 if (status < 0) {
525 dev_dbg(&bus->dev, "can't attach %s to device %d, err %d\n",
526 DRIVER_NAME, address, status);
527 goto fail1;
528 }
529 488
530 /* the IRQ is active low, but many gpio lines can't support that 489 if (strcmp(client->name, "tps65010") == 0)
531 * so this driver can use falling-edge triggers instead.
532 */
533 irqflags = IRQF_SAMPLE_RANDOM;
534#ifdef CONFIG_ARM
535 if (machine_is_omap_h2()) {
536 tps->model = TPS65010;
537 omap_cfg_reg(W4_GPIO58);
538 tps->irq = OMAP_GPIO_IRQ(58);
539 omap_request_gpio(58);
540 omap_set_gpio_direction(58, 1);
541 irqflags |= IRQF_TRIGGER_FALLING;
542 }
543 if (machine_is_omap_osk()) {
544 tps->model = TPS65010; 490 tps->model = TPS65010;
545 // omap_cfg_reg(U19_1610_MPUIO1); 491 else if (strcmp(client->name, "tps65011") == 0)
546 tps->irq = OMAP_GPIO_IRQ(OMAP_MPUIO(1)); 492 tps->model = TPS65011;
547 omap_request_gpio(OMAP_MPUIO(1)); 493 else if (strcmp(client->name, "tps65012") == 0)
548 omap_set_gpio_direction(OMAP_MPUIO(1), 1); 494 tps->model = TPS65012;
549 irqflags |= IRQF_TRIGGER_FALLING; 495 else if (strcmp(client->name, "tps65013") == 0)
550 }
551 if (machine_is_omap_h3()) {
552 tps->model = TPS65013; 496 tps->model = TPS65013;
553 497 else {
554 // FIXME set up this board's IRQ ... 498 dev_warn(&client->dev, "unknown chip '%s'\n", client->name);
499 status = -ENODEV;
500 goto fail1;
555 } 501 }
556#endif
557 502
558 if (tps->irq > 0) { 503 /* the IRQ is active low, but many gpio lines can't support that
559 status = request_irq(tps->irq, tps65010_irq, 504 * so this driver uses falling-edge triggers instead.
560 irqflags, DRIVER_NAME, tps); 505 */
506 if (client->irq > 0) {
507 status = request_irq(client->irq, tps65010_irq,
508 IRQF_SAMPLE_RANDOM | IRQF_TRIGGER_FALLING,
509 DRIVER_NAME, tps);
561 if (status < 0) { 510 if (status < 0) {
562 dev_dbg(&client->dev, "can't get IRQ %d, err %d\n", 511 dev_dbg(&client->dev, "can't get IRQ %d, err %d\n",
563 tps->irq, status); 512 client->irq, status);
564 i2c_detach_client(client);
565 goto fail1; 513 goto fail1;
566 } 514 }
567#ifdef CONFIG_ARM
568 /* annoying race here, ideally we'd have an option 515 /* annoying race here, ideally we'd have an option
569 * to claim the irq now and enable it later. 516 * to claim the irq now and enable it later.
517 * FIXME genirq IRQF_NOAUTOEN now solves that ...
570 */ 518 */
571 disable_irq(tps->irq); 519 disable_irq(client->irq);
572 set_bit(FLAG_IRQ_ENABLE, &tps->flags); 520 set_bit(FLAG_IRQ_ENABLE, &tps->flags);
573#endif
574 } else 521 } else
575 printk(KERN_WARNING "%s: IRQ not configured!\n", 522 dev_warn(&client->dev, "IRQ not configured!\n");
576 DRIVER_NAME);
577 523
578 524
579 switch (tps->model) { 525 switch (tps->model) {
@@ -602,7 +548,6 @@ tps65010_probe(struct i2c_adapter *bus, int address, int kind)
602 i2c_smbus_read_byte_data(client, TPS_DEFGPIO), 548 i2c_smbus_read_byte_data(client, TPS_DEFGPIO),
603 i2c_smbus_read_byte_data(client, TPS_MASK3)); 549 i2c_smbus_read_byte_data(client, TPS_MASK3));
604 550
605 tps65010_driver.attach_adapter = tps65010_noscan;
606 the_tps = tps; 551 the_tps = tps;
607 552
608#if defined(CONFIG_USB_GADGET) && !defined(CONFIG_USB_OTG) 553#if defined(CONFIG_USB_GADGET) && !defined(CONFIG_USB_OTG)
@@ -635,22 +580,15 @@ tps65010_probe(struct i2c_adapter *bus, int address, int kind)
635 return 0; 580 return 0;
636fail1: 581fail1:
637 kfree(tps); 582 kfree(tps);
638 return 0; 583 return status;
639}
640
641static int __init tps65010_scan_bus(struct i2c_adapter *bus)
642{
643 if (!i2c_check_functionality(bus, I2C_FUNC_SMBUS_BYTE_DATA))
644 return -EINVAL;
645 return i2c_probe(bus, &addr_data, tps65010_probe);
646} 584}
647 585
648static struct i2c_driver tps65010_driver = { 586static struct i2c_driver tps65010_driver = {
649 .driver = { 587 .driver = {
650 .name = "tps65010", 588 .name = "tps65010",
651 }, 589 },
652 .attach_adapter = tps65010_scan_bus, 590 .probe = tps65010_probe,
653 .detach_client = __exit_p(tps65010_detach_client), 591 .remove = __exit_p(tps65010_remove),
654}; 592};
655 593
656/*-------------------------------------------------------------------------*/ 594/*-------------------------------------------------------------------------*/
@@ -1014,52 +952,6 @@ static int __init tps_init(void)
1014 msleep(10); 952 msleep(10);
1015 } 953 }
1016 954
1017#ifdef CONFIG_ARM
1018 if (machine_is_omap_osk()) {
1019
1020 // FIXME: More should be placed in the initialization code
1021 // of the submodules (DSP, ethernet, power management,
1022 // board-osk.c). Careful: I2C is initialized "late".
1023
1024 /* Let LED1 (D9) blink */
1025 tps65010_set_led(LED1, BLINK);
1026
1027 /* Disable LED 2 (D2) */
1028 tps65010_set_led(LED2, OFF);
1029
1030 /* Set GPIO 1 HIGH to disable VBUS power supply;
1031 * OHCI driver powers it up/down as needed.
1032 */
1033 tps65010_set_gpio_out_value(GPIO1, HIGH);
1034
1035 /* Set GPIO 2 low to turn on LED D3 */
1036 tps65010_set_gpio_out_value(GPIO2, HIGH);
1037
1038 /* Set GPIO 3 low to take ethernet out of reset */
1039 tps65010_set_gpio_out_value(GPIO3, LOW);
1040
1041 /* gpio4 for VDD_DSP */
1042
1043 /* Enable LOW_PWR */
1044 tps65010_set_low_pwr(ON);
1045
1046 /* Switch VLDO2 to 3.0V for AIC23 */
1047 tps65010_config_vregs1(TPS_LDO2_ENABLE | TPS_VLDO2_3_0V | TPS_LDO1_ENABLE);
1048
1049 } else if (machine_is_omap_h2()) {
1050 /* gpio3 for SD, gpio4 for VDD_DSP */
1051
1052 /* Enable LOW_PWR */
1053 tps65010_set_low_pwr(ON);
1054 } else if (machine_is_omap_h3()) {
1055 /* gpio4 for SD, gpio3 for VDD_DSP */
1056#ifdef CONFIG_PM
1057 /* Enable LOW_PWR */
1058 tps65013_set_low_pwr(ON);
1059#endif
1060 }
1061#endif
1062
1063 return status; 955 return status;
1064} 956}
1065/* NOTE: this MUST be initialized before the other parts of the system 957/* NOTE: this MUST be initialized before the other parts of the system