2 * twl4030_core.c - driver for TWL4030 PM and audio CODEC device
4 * Copyright (C) 2005-2006 Texas Instruments, Inc.
6 * Modifications to defer interrupt handling to a kernel thread:
7 * Copyright (C) 2006 MontaVista Software, Inc.
9 * Based on tlv320aic23.c:
10 * Copyright (c) by Kai Svahn <kai.svahn@nokia.com>
12 * Code cleanup and modifications to IRQ handler.
13 * by syed khasim <x0khasim@ti.com>
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include <linux/module.h>
32 #include <linux/kernel_stat.h>
33 #include <linux/init.h>
34 #include <linux/time.h>
35 #include <linux/interrupt.h>
36 #include <linux/random.h>
37 #include <linux/syscalls.h>
38 #include <linux/kthread.h>
40 #include <linux/i2c.h>
41 #include <linux/slab.h>
42 #include <linux/clk.h>
43 #include <linux/device.h>
46 #include <asm/mach/irq.h>
48 #include <asm/arch/twl4030.h>
49 #include <asm/arch/gpio.h>
50 #include <asm/arch/mux.h>
52 #define DRIVER_NAME "twl4030"
54 /* Macro Definitions */
55 #define TWL_CLIENT_STRING "TWL4030-ID"
56 #define TWL_CLIENT_USED 1
57 #define TWL_CLIENT_FREE 0
63 /* Primary Interrupt Handler on TWL4030 Registers */
65 /* Register Definitions */
67 #define REG_PIH_ISR_P1 (0x1)
68 #define REG_PIH_ISR_P2 (0x2)
69 #define REG_PIH_SIR (0x3)
71 /* Triton Core internal information (BEGIN) */
73 /* Last - for index max*/
74 #define TWL4030_MODULE_LAST TWL4030_MODULE_SECURED_REG
77 #define TWL4030_NUM_SLAVES 0x04
78 #define TWL4030_SLAVENUM_NUM0 0x00
79 #define TWL4030_SLAVENUM_NUM1 0x01
80 #define TWL4030_SLAVENUM_NUM2 0x02
81 #define TWL4030_SLAVENUM_NUM3 0x03
82 #define TWL4030_SLAVEID_ID0 0x48
83 #define TWL4030_SLAVEID_ID1 0x49
84 #define TWL4030_SLAVEID_ID2 0x4A
85 #define TWL4030_SLAVEID_ID3 0x4B
87 /* Base Address defns */
89 #define TWL4030_BASEADD_USB 0x0000
91 #define TWL4030_BASEADD_AUDIO_VOICE 0x0000
92 #define TWL4030_BASEADD_GPIO 0x0098
94 #define TWL4030_BASEADD_INTBR 0x0085
95 #define TWL4030_BASEADD_PIH 0x0080
96 #define TWL4030_BASEADD_TEST 0x004C
98 #define TWL4030_BASEADD_INTERRUPTS 0x00B9
99 #define TWL4030_BASEADD_LED 0x00EE
100 #define TWL4030_BASEADD_MADC 0x0000
101 #define TWL4030_BASEADD_MAIN_CHARGE 0x0074
102 #define TWL4030_BASEADD_PRECHARGE 0x00AA
103 #define TWL4030_BASEADD_PWM0 0x00F8
104 #define TWL4030_BASEADD_PWM1 0x00FB
105 #define TWL4030_BASEADD_PWMA 0x00EF
106 #define TWL4030_BASEADD_PWMB 0x00F1
107 #define TWL4030_BASEADD_KEYPAD 0x00D2
109 #define TWL4030_BASEADD_BACKUP 0x0014
110 #define TWL4030_BASEADD_INT 0x002E
111 #define TWL4030_BASEADD_PM_MASTER 0x0036
112 #define TWL4030_BASEADD_PM_RECEIVER 0x005B
113 #define TWL4030_BASEADD_RTC 0x001C
114 #define TWL4030_BASEADD_SECURED_REG 0x0000
116 /* Triton Core internal information (END) */
118 /* Few power values */
119 #define R_CFG_BOOT 0x05
120 #define R_PROTECT_KEY 0x0E
123 #define KEY_UNLOCK1 0xce
124 #define KEY_UNLOCK2 0xec
125 #define KEY_LOCK 0x00
127 #define HFCLK_FREQ_19p2_MHZ (1 << 0)
128 #define HFCLK_FREQ_26_MHZ (2 << 0)
129 #define HFCLK_FREQ_38p4_MHZ (3 << 0)
130 #define HIGH_PERF_SQ (1 << 3)
132 /* on I2C-1 for 2430SDP */
133 #define CONFIG_I2C_TWL4030_ID 1
135 /* Helper functions */
137 twl4030_detect_client(struct i2c_adapter *adapter, unsigned char sid);
138 static int twl4030_attach_adapter(struct i2c_adapter *adapter);
139 static int twl4030_detach_client(struct i2c_client *client);
140 static void do_twl4030_irq(unsigned int irq, irq_desc_t *desc);
142 static void twl_init_irq(void);
144 /* Data Structures */
145 /* To have info on T2 IRQ substem activated or not */
146 static unsigned char twl_irq_used = FREE;
147 static struct completion irq_event;
149 /* Structure to define on TWL4030 Slave ID */
150 struct twl4030_client {
151 struct i2c_client client;
152 const char client_name[sizeof(TWL_CLIENT_STRING) + 1];
153 const unsigned char address;
154 const char adapter_index;
157 /* max numb of i2c_msg required is for read =2 */
158 struct i2c_msg xfer_msg[2];
160 /* To lock access to xfer_msg */
161 struct semaphore xfer_lock;
165 struct twl4030mapping {
166 unsigned char sid; /* Slave ID */
167 unsigned char base; /* base address */
170 /* mapping the module id to slave id and base address */
171 static struct twl4030mapping twl4030_map[TWL4030_MODULE_LAST + 1] = {
172 { TWL4030_SLAVENUM_NUM0, TWL4030_BASEADD_USB },
173 { TWL4030_SLAVENUM_NUM1, TWL4030_BASEADD_AUDIO_VOICE },
174 { TWL4030_SLAVENUM_NUM1, TWL4030_BASEADD_GPIO },
175 { TWL4030_SLAVENUM_NUM1, TWL4030_BASEADD_INTBR },
176 { TWL4030_SLAVENUM_NUM1, TWL4030_BASEADD_PIH },
177 { TWL4030_SLAVENUM_NUM1, TWL4030_BASEADD_TEST },
178 { TWL4030_SLAVENUM_NUM2, TWL4030_BASEADD_KEYPAD },
179 { TWL4030_SLAVENUM_NUM2, TWL4030_BASEADD_MADC },
180 { TWL4030_SLAVENUM_NUM2, TWL4030_BASEADD_INTERRUPTS },
181 { TWL4030_SLAVENUM_NUM2, TWL4030_BASEADD_LED },
182 { TWL4030_SLAVENUM_NUM2, TWL4030_BASEADD_MAIN_CHARGE },
183 { TWL4030_SLAVENUM_NUM2, TWL4030_BASEADD_PRECHARGE },
184 { TWL4030_SLAVENUM_NUM2, TWL4030_BASEADD_PWM0 },
185 { TWL4030_SLAVENUM_NUM2, TWL4030_BASEADD_PWM1 },
186 { TWL4030_SLAVENUM_NUM2, TWL4030_BASEADD_PWMA },
187 { TWL4030_SLAVENUM_NUM2, TWL4030_BASEADD_PWMB },
188 { TWL4030_SLAVENUM_NUM3, TWL4030_BASEADD_BACKUP },
189 { TWL4030_SLAVENUM_NUM3, TWL4030_BASEADD_INT },
190 { TWL4030_SLAVENUM_NUM3, TWL4030_BASEADD_PM_MASTER },
191 { TWL4030_SLAVENUM_NUM3, TWL4030_BASEADD_PM_RECEIVER },
192 { TWL4030_SLAVENUM_NUM3, TWL4030_BASEADD_RTC },
193 { TWL4030_SLAVENUM_NUM3, TWL4030_BASEADD_SECURED_REG },
196 static struct twl4030_client twl4030_modules[TWL4030_NUM_SLAVES] = {
198 .address = TWL4030_SLAVEID_ID0,
199 .client_name = TWL_CLIENT_STRING "0",
200 .adapter_index = CONFIG_I2C_TWL4030_ID,
203 .address = TWL4030_SLAVEID_ID1,
204 .client_name = TWL_CLIENT_STRING "1",
205 .adapter_index = CONFIG_I2C_TWL4030_ID,
208 .address = TWL4030_SLAVEID_ID2,
209 .client_name = TWL_CLIENT_STRING "2",
210 .adapter_index = CONFIG_I2C_TWL4030_ID,
213 .address = TWL4030_SLAVEID_ID3,
214 .client_name = TWL_CLIENT_STRING "3",
215 .adapter_index = CONFIG_I2C_TWL4030_ID,
219 /* One Client Driver , 4 Clients */
220 static struct i2c_driver twl4030_driver = {
221 .driver.name = "TWL4030 I2C",
222 .attach_adapter = twl4030_attach_adapter,
223 .detach_client = twl4030_detach_client,
227 * TWL4030 doesn't have PIH mask, hence dummy function for mask
231 static void twl4030_i2c_ackirq(unsigned int irq) {}
232 static void twl4030_i2c_disableint(unsigned int irq) {}
233 static void twl4030_i2c_enableint(unsigned int irq) {}
235 /* information for processing in the Work Item */
236 static struct irq_chip twl4030_irq_chip = {
237 .ack = twl4030_i2c_ackirq,
238 .mask = twl4030_i2c_disableint,
239 .unmask = twl4030_i2c_enableint,
242 /* Global Functions */
244 * @brief twl4030_i2c_write - Writes a n bit register in TWL4030
246 * @param mod_no - module number
247 * @param *value - an array of num_bytes+1 containing data to write
248 * IMPORTANT - Allocate value num_bytes+1 and valid data starts at
250 * @param reg - register address (just offset will do)
251 * @param num_bytes - number of bytes to transfer
253 * @return result of operation - 0 is success
255 int twl4030_i2c_write(u8 mod_no, u8 * value, u8 reg, u8 num_bytes)
259 struct twl4030_client *client;
262 if (unlikely(mod_no > TWL4030_MODULE_LAST)) {
263 pr_err("Invalid module Number\n");
266 sid = twl4030_map[mod_no].sid;
267 client = &(twl4030_modules[sid]);
269 if (unlikely(client->inuse != TWL_CLIENT_USED)) {
270 pr_err("I2C Client[%d] is not initialized[%d]\n",
274 down(&(client->xfer_lock));
276 * [MSG1]: fill the register address data
277 * fill the data Tx buffer
279 msg = &(client->xfer_msg[0]);
280 msg->addr = client->address;
281 msg->len = num_bytes + 1;
284 /* over write the first byte of buffer with the register address */
285 *value = twl4030_map[mod_no].base + reg;
286 ret = i2c_transfer(client->client.adapter, client->xfer_msg, 1);
287 up(&(client->xfer_lock));
289 /* i2cTransfer returns num messages.translate it pls.. */
296 * @brief twl4030_i2c_read - Reads a n bit register in TWL4030
298 * @param mod_no - module number
299 * @param *value - an array of num_bytes containing data to be read
300 * @param reg - register address (just offset will do)
301 * @param num_bytes - number of bytes to transfer
303 * @return result of operation - num_bytes is success else failure.
305 int twl4030_i2c_read(u8 mod_no, u8 * value, u8 reg, u8 num_bytes)
310 struct twl4030_client *client;
313 if (unlikely(mod_no > TWL4030_MODULE_LAST)) {
314 pr_err("Invalid module Number\n");
317 sid = twl4030_map[mod_no].sid;
318 client = &(twl4030_modules[sid]);
320 if (unlikely(client->inuse != TWL_CLIENT_USED)) {
321 pr_err("I2C Client[%d] is not initialized[%d]\n", sid,
325 down(&(client->xfer_lock));
326 /* [MSG1] fill the register address data */
327 msg = &(client->xfer_msg[0]);
328 msg->addr = client->address;
330 msg->flags = 0; /* Read the register value */
331 val = twl4030_map[mod_no].base + reg;
333 /* [MSG2] fill the data rx buffer */
334 msg = &(client->xfer_msg[1]);
335 msg->addr = client->address;
336 msg->flags = I2C_M_RD; /* Read the register value */
337 msg->len = num_bytes; /* only n bytes */
339 ret = i2c_transfer(client->client.adapter, client->xfer_msg, 2);
340 up(&(client->xfer_lock));
342 /* i2cTransfer returns num messages.translate it pls.. */
349 * @brief twl4030_i2c_write_u8 - Writes a 8 bit register in TWL4030
351 * @param mod_no - module number
352 * @param value - the value to be written 8 bit
353 * @param reg - register address (just offset will do)
355 * @return result of operation - 0 is success
357 int twl4030_i2c_write_u8(u8 mod_no, u8 value, u8 reg)
360 /* 2 bytes offset 1 contains the data offset 0 is used by i2c_write */
361 u8 temp_buffer[2] = { 0 };
362 /* offset 1 contains the data */
363 temp_buffer[1] = value;
364 return twl4030_i2c_write(mod_no, temp_buffer, reg, 1);
368 * @brief twl4030_i2c_read_u8 - Reads a 8 bit register from TWL4030
370 * @param mod_no - module number
371 * @param *value - the value read 8 bit
372 * @param reg - register address (just offset will do)
374 * @return result of operation - 0 is success
376 int twl4030_i2c_read_u8(u8 mod_no, u8 * value, u8 reg)
378 return twl4030_i2c_read(mod_no, value, reg, 1);
381 /* Helper Functions */
384 * do_twl4030_module_irq() is the desc->handle method for each of the twl4030
385 * module interrupts. It executes in kernel thread context.
386 * On entry, cpu interrupts are disabled.
388 static void do_twl4030_module_irq(unsigned int irq, irq_desc_t *desc)
390 struct irqaction *action;
391 const unsigned int cpu = smp_processor_id();
394 * Earlier this was desc->triggered = 1;
396 desc->status |= IRQ_LEVEL;
399 * The desc->handle method would normally call the desc->chip->ack
400 * method here, but we won't bother since our ack method is NULL.
404 kstat_cpu(cpu).irqs[irq]++;
406 action = desc->action;
415 /* Call the ISR with cpu interrupts enabled */
416 ret = action->handler(irq, action->dev_id);
417 if (ret == IRQ_HANDLED)
418 status |= action->flags;
420 action = action->next;
423 if (status & IRQF_SAMPLE_RANDOM)
424 add_interrupt_randomness(irq);
428 if (retval != IRQ_HANDLED)
429 printk(KERN_ERR "ISR for TWL4030 module"
430 " irq %d can't handle interrupt\n", irq);
433 * Here is where we should call the unmask method, but
434 * again we won't bother since it is NULL.
437 printk(KERN_CRIT "TWL4030 module irq %d has no ISR"
438 " but can't be masked!\n", irq);
440 printk(KERN_CRIT "TWL4030 module irq %d is disabled but can't"
441 " be masked!\n", irq);
445 * twl4030_irq_thread() runs as a kernel thread. It queries the twl4030
446 * interrupt controller to see which modules are generating interrupt requests
447 * and then calls the desc->handle method for each module requesting service.
449 static int twl4030_irq_thread(void *data)
452 irq_desc_t *desc = irq_desc + irq;
453 static unsigned i2c_errors;
454 const static unsigned max_i2c_errors = 100;
456 daemonize("twl4030-irq");
457 current->flags |= PF_NOFREEZE;
459 while (!kthread_should_stop()) {
464 wait_for_completion_interruptible(&irq_event);
466 ret = twl4030_i2c_read_u8(TWL4030_MODULE_PIH, &pih_isr,
469 printk(KERN_WARNING "I2C error %d while reading TWL4030"
470 " PIH ISR register.\n", ret);
471 if (++i2c_errors >= max_i2c_errors) {
472 printk(KERN_ERR "Maximum I2C error count"
473 " exceeded. Terminating %s.\n",
480 for (module_irq = IH_TWL4030_BASE; 0 != pih_isr;
481 pih_isr >>= 1, module_irq++) {
483 irq_desc_t *d = irq_desc + module_irq;
487 d->handle_irq(module_irq, d);
493 desc->chip->unmask(irq);
500 * do_twl4030_irq() is the desc->handle method for the twl4030 interrupt.
501 * This is a chained interrupt, so there is no desc->action method for it.
502 * Now we need to query the interrupt controller in the twl4030 to determine
503 * which module is generating the interrupt request. However, we can't do i2c
504 * transactions in interrupt context, so we must defer that work to a kernel
505 * thread. All we do here is acknowledge and mask the interrupt and wakeup
508 static void do_twl4030_irq(unsigned int irq, irq_desc_t *desc)
510 const unsigned int cpu = smp_processor_id();
513 * Earlier this was desc->triggered = 1;
515 desc->status |= IRQ_LEVEL;
518 * Acknowledge, clear _AND_ disable the interrupt.
520 desc->chip->ack(irq);
523 kstat_cpu(cpu).irqs[irq]++;
525 complete(&irq_event);
529 /* attach a client to the adapter */
530 static int twl4030_detect_client(struct i2c_adapter *adapter, unsigned char sid)
533 struct twl4030_client *client;
535 if (unlikely(sid >= TWL4030_NUM_SLAVES)) {
536 pr_err("sid[%d] > MOD_LAST[%d]\n", sid, TWL4030_NUM_SLAVES);
540 /* Check basic functionality */
541 if (!(err = i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA |
542 I2C_FUNC_SMBUS_WRITE_BYTE))) {
543 pr_err("SlaveID=%d functionality check failed\n", sid);
546 client = &(twl4030_modules[sid]);
547 if (unlikely(client->inuse)) {
548 pr_err("Client %s is already in use\n", client->client_name);
552 memset(&(client->client), 0, sizeof(struct i2c_client));
554 client->client.addr = client->address;
555 client->client.adapter = adapter;
556 client->client.driver = &twl4030_driver;
558 memcpy(&(client->client.name), client->client_name,
559 sizeof(TWL_CLIENT_STRING) + 1);
561 pr_info("TWL4030: TRY attach Slave %s on Adapter %s [%x]\n",
562 client->client_name, adapter->name, err);
564 if ((err = i2c_attach_client(&(client->client)))) {
565 pr_err("Couldn't attach Slave %s on Adapter"
566 "%s [%x]\n", client->client_name, adapter->name, err);
568 client->inuse = TWL_CLIENT_USED;
569 init_MUTEX(&client->xfer_lock);
575 /* adapter callback */
576 static int twl4030_attach_adapter(struct i2c_adapter *adapter)
580 static int twl_i2c_adapter = 1;
582 for (i = 0; i < TWL4030_NUM_SLAVES; i++) {
583 /* Check if I need to hook on to this adapter or not */
584 if (twl4030_modules[i].adapter_index == twl_i2c_adapter) {
585 if ((ret = twl4030_detect_client(adapter, i)))
592 * Check if the PIH module is initialized, if yes, then init
593 * the T2 Interrupt subsystem
595 if ((twl4030_modules[twl4030_map[TWL4030_MODULE_PIH].sid].inuse ==
596 TWL_CLIENT_USED) && (twl_irq_used != USED)) {
603 pr_err("TWL_CLIENT(Idx=%d] registration failed[0x%x]\n",i,ret);
605 /* ignore current slave..it never got registered */
608 /* now remove all those from the current adapter... */
609 if (twl4030_modules[i].adapter_index == twl_i2c_adapter)
610 (void)twl4030_detach_client(&(twl4030_modules[i].client));
616 /* adapter's callback */
617 static int twl4030_detach_client(struct i2c_client *iclient)
620 if ((err = i2c_detach_client(iclient))) {
621 pr_err("Client detach failed\n");
627 struct task_struct *start_twl4030_irq_thread(int irq)
629 struct task_struct *thread;
631 init_completion(&irq_event);
632 thread = kthread_run(twl4030_irq_thread, (void *)irq,
633 "twl4030 irq %d", irq);
635 pr_err("%s: could not create twl4030 irq %d thread!\n",
642 * These three functions should be part of Voltage frame work
643 * added here to complete the functionality for now.
645 static int protect_pm_master(void)
649 e = twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, KEY_LOCK,
654 static int unprotect_pm_master(void)
658 e |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, KEY_UNLOCK1,
660 e |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, KEY_UNLOCK2,
665 static int power_companion_init(void)
668 u32 rate, ctrl = HFCLK_FREQ_26_MHZ;
671 osc = clk_get(NULL,"osc_ck");
672 rate = clk_get_rate(osc);
676 case 19200000 : ctrl = HFCLK_FREQ_19p2_MHZ; break;
677 case 26000000 : ctrl = HFCLK_FREQ_26_MHZ; break;
678 case 38400000 : ctrl = HFCLK_FREQ_38p4_MHZ; break;
681 ctrl |= HIGH_PERF_SQ;
682 e |= unprotect_pm_master();
683 /* effect->MADC+USB ck en */
684 e |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, ctrl, R_CFG_BOOT);
685 e |= protect_pm_master();
690 static void twl_init_irq(void)
694 char *msg = "Unable to register interrupt subsystem";
697 * We end up with interrupts from other modules before
698 * they get a chance to handle them...
701 res = twl4030_i2c_write_u8(TWL4030_MODULE_INT, 0xFF, 0x00);
703 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
708 res = twl4030_i2c_write_u8(TWL4030_MODULE_INT, 0xFF, 0x02);
710 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
715 res = twl4030_i2c_write_u8(TWL4030_MODULE_INT, 0xFF, 0x1);
717 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
722 res = twl4030_i2c_write_u8(TWL4030_MODULE_INT, 0xFF, 0x3);
724 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
728 /* Clear off any other pending interrupts on power */
730 res = twl4030_i2c_write_u8(TWL4030_MODULE_INT, 0xFF, 0x00);
732 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
737 res = twl4030_i2c_write_u8(TWL4030_MODULE_INT, 0xFF, 0x02);
739 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
742 /* POWER HACK (END) */
743 /* Slave address 0x4A */
746 res = twl4030_i2c_write_u8(TWL4030_MODULE_INTERRUPTS, 0xFF, 0x3);
748 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
753 res = twl4030_i2c_write_u8(TWL4030_MODULE_INTERRUPTS, 0xFF, 0x4);
755 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
760 res = twl4030_i2c_write_u8(TWL4030_MODULE_INTERRUPTS, 0xFF, 0x7);
762 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
767 res = twl4030_i2c_write_u8(TWL4030_MODULE_INTERRUPTS, 0xFF, 0x8);
769 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
775 res = twl4030_i2c_write_u8(TWL4030_MODULE_MADC, 0xFF, 0x62);
777 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
782 res = twl4030_i2c_write_u8(TWL4030_MODULE_MADC, 0xFF, 0x64);
784 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
790 res = twl4030_i2c_write_u8(TWL4030_MODULE_KEYPAD, 0xFF, (0x12));
792 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
798 twl4030_i2c_read_u8(TWL4030_MODULE_KEYPAD, &clear, 0x11);
799 twl4030_i2c_read_u8(TWL4030_MODULE_KEYPAD, &clear, 0x11);
803 res = twl4030_i2c_write_u8(TWL4030_MODULE_KEYPAD, 0xFF, (0x14));
805 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
809 /* Slave address 0x49 */
811 res = twl4030_i2c_write_u8(TWL4030_MODULE_GPIO, 0xFF, (0x1C));
813 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
818 res = twl4030_i2c_write_u8(TWL4030_MODULE_GPIO, 0xFF, (0x1D));
820 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
825 res = twl4030_i2c_write_u8(TWL4030_MODULE_GPIO, 0xFF, (0x1E));
827 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
832 res = twl4030_i2c_write_u8(TWL4030_MODULE_GPIO, 0xFF, (0x22));
834 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
839 res = twl4030_i2c_write_u8(TWL4030_MODULE_GPIO, 0xFF, (0x23));
841 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
846 res = twl4030_i2c_write_u8(TWL4030_MODULE_GPIO, 0xFF, (0x24));
848 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
852 /* install an irq handler for each of the PIH modules */
853 for (i = IH_TWL4030_BASE; i < IH_TWL4030_END; i++) {
854 set_irq_chip(i, &twl4030_irq_chip);
855 set_irq_handler(i, do_twl4030_module_irq);
856 set_irq_flags(i, IRQF_VALID);
859 /* install an irq handler to demultiplex the TWL4030 interrupt */
860 set_irq_data(TWL4030_IRQNUM, start_twl4030_irq_thread(TWL4030_IRQNUM));
861 set_irq_type(TWL4030_IRQNUM, IRQT_FALLING);
862 set_irq_chained_handler(TWL4030_IRQNUM, do_twl4030_irq);
864 res = power_companion_init();
866 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
870 static int __init twl4030_init(void)
874 if ((res = i2c_add_driver(&twl4030_driver))) {
875 printk(KERN_ERR "TWL4030: Driver registration failed \n");
879 pr_info(KERN_INFO "TWL4030: Driver registration complete.\n");
884 static void __exit twl4030_exit(void)
886 i2c_del_driver(&twl4030_driver);
890 subsys_initcall(twl4030_init);
891 module_exit(twl4030_exit);
893 EXPORT_SYMBOL(twl4030_i2c_write_u8);
894 EXPORT_SYMBOL(twl4030_i2c_read_u8);
895 EXPORT_SYMBOL(twl4030_i2c_read);
896 EXPORT_SYMBOL(twl4030_i2c_write);
898 MODULE_AUTHOR("Texas Instruments, Inc.");
899 MODULE_DESCRIPTION("I2C Core interface for TWL4030");
900 MODULE_LICENSE("GPL");