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/mutex.h>
36 #include <linux/interrupt.h>
37 #include <linux/random.h>
38 #include <linux/syscalls.h>
39 #include <linux/kthread.h>
41 #include <linux/i2c.h>
42 #include <linux/i2c/twl4030.h>
43 #include <linux/slab.h>
44 #include <linux/clk.h>
45 #include <linux/device.h>
46 #include <linux/irq.h>
48 #include <asm/mach/irq.h>
50 #include <asm/arch/gpio.h>
51 #include <asm/arch/mux.h>
53 #define DRIVER_NAME "twl4030"
55 /* Macro Definitions */
56 #define TWL_CLIENT_STRING "TWL4030-ID"
57 #define TWL_CLIENT_USED 1
58 #define TWL_CLIENT_FREE 0
64 /* Primary Interrupt Handler on TWL4030 Registers */
66 /* Register Definitions */
68 #define REG_PIH_ISR_P1 (0x1)
69 #define REG_PIH_ISR_P2 (0x2)
70 #define REG_PIH_SIR (0x3)
72 /* Triton Core internal information (BEGIN) */
74 /* Last - for index max*/
75 #define TWL4030_MODULE_LAST TWL4030_MODULE_SECURED_REG
78 #define TWL4030_NUM_SLAVES 0x04
79 #define TWL4030_SLAVENUM_NUM0 0x00
80 #define TWL4030_SLAVENUM_NUM1 0x01
81 #define TWL4030_SLAVENUM_NUM2 0x02
82 #define TWL4030_SLAVENUM_NUM3 0x03
83 #define TWL4030_SLAVEID_ID0 0x48
84 #define TWL4030_SLAVEID_ID1 0x49
85 #define TWL4030_SLAVEID_ID2 0x4A
86 #define TWL4030_SLAVEID_ID3 0x4B
88 /* Base Address defns */
90 #define TWL4030_BASEADD_USB 0x0000
92 #define TWL4030_BASEADD_AUDIO_VOICE 0x0000
93 #define TWL4030_BASEADD_GPIO 0x0098
95 #define TWL4030_BASEADD_INTBR 0x0085
96 #define TWL4030_BASEADD_PIH 0x0080
97 #define TWL4030_BASEADD_TEST 0x004C
99 #define TWL4030_BASEADD_INTERRUPTS 0x00B9
100 #define TWL4030_BASEADD_LED 0x00EE
101 #define TWL4030_BASEADD_MADC 0x0000
102 #define TWL4030_BASEADD_MAIN_CHARGE 0x0074
103 #define TWL4030_BASEADD_PRECHARGE 0x00AA
104 #define TWL4030_BASEADD_PWM0 0x00F8
105 #define TWL4030_BASEADD_PWM1 0x00FB
106 #define TWL4030_BASEADD_PWMA 0x00EF
107 #define TWL4030_BASEADD_PWMB 0x00F1
108 #define TWL4030_BASEADD_KEYPAD 0x00D2
110 #define TWL4030_BASEADD_BACKUP 0x0014
111 #define TWL4030_BASEADD_INT 0x002E
112 #define TWL4030_BASEADD_PM_MASTER 0x0036
113 #define TWL4030_BASEADD_PM_RECEIVER 0x005B
114 #define TWL4030_BASEADD_RTC 0x001C
115 #define TWL4030_BASEADD_SECURED_REG 0x0000
117 /* Triton Core internal information (END) */
119 /* Few power values */
120 #define R_CFG_BOOT 0x05
121 #define R_PROTECT_KEY 0x0E
124 #define KEY_UNLOCK1 0xce
125 #define KEY_UNLOCK2 0xec
126 #define KEY_LOCK 0x00
128 #define HFCLK_FREQ_19p2_MHZ (1 << 0)
129 #define HFCLK_FREQ_26_MHZ (2 << 0)
130 #define HFCLK_FREQ_38p4_MHZ (3 << 0)
131 #define HIGH_PERF_SQ (1 << 3)
133 /* on I2C-1 for 2430SDP */
134 #define CONFIG_I2C_TWL4030_ID 1
136 /* Helper functions */
138 twl4030_detect_client(struct i2c_adapter *adapter, unsigned char sid);
139 static int twl4030_attach_adapter(struct i2c_adapter *adapter);
140 static int twl4030_detach_client(struct i2c_client *client);
141 static void do_twl4030_irq(unsigned int irq, irq_desc_t *desc);
143 static void twl_init_irq(void);
145 /* Data Structures */
146 /* To have info on T2 IRQ substem activated or not */
147 static unsigned char twl_irq_used = FREE;
148 static struct completion irq_event;
150 /* Structure to define on TWL4030 Slave ID */
151 struct twl4030_client {
152 struct i2c_client client;
153 const char client_name[sizeof(TWL_CLIENT_STRING) + 1];
154 const unsigned char address;
155 const char adapter_index;
158 /* max numb of i2c_msg required is for read =2 */
159 struct i2c_msg xfer_msg[2];
161 /* To lock access to xfer_msg */
162 struct mutex xfer_lock;
166 struct twl4030mapping {
167 unsigned char sid; /* Slave ID */
168 unsigned char base; /* base address */
171 /* mapping the module id to slave id and base address */
172 static struct twl4030mapping twl4030_map[TWL4030_MODULE_LAST + 1] = {
173 { TWL4030_SLAVENUM_NUM0, TWL4030_BASEADD_USB },
174 { TWL4030_SLAVENUM_NUM1, TWL4030_BASEADD_AUDIO_VOICE },
175 { TWL4030_SLAVENUM_NUM1, TWL4030_BASEADD_GPIO },
176 { TWL4030_SLAVENUM_NUM1, TWL4030_BASEADD_INTBR },
177 { TWL4030_SLAVENUM_NUM1, TWL4030_BASEADD_PIH },
178 { TWL4030_SLAVENUM_NUM1, TWL4030_BASEADD_TEST },
179 { TWL4030_SLAVENUM_NUM2, TWL4030_BASEADD_KEYPAD },
180 { TWL4030_SLAVENUM_NUM2, TWL4030_BASEADD_MADC },
181 { TWL4030_SLAVENUM_NUM2, TWL4030_BASEADD_INTERRUPTS },
182 { TWL4030_SLAVENUM_NUM2, TWL4030_BASEADD_LED },
183 { TWL4030_SLAVENUM_NUM2, TWL4030_BASEADD_MAIN_CHARGE },
184 { TWL4030_SLAVENUM_NUM2, TWL4030_BASEADD_PRECHARGE },
185 { TWL4030_SLAVENUM_NUM2, TWL4030_BASEADD_PWM0 },
186 { TWL4030_SLAVENUM_NUM2, TWL4030_BASEADD_PWM1 },
187 { TWL4030_SLAVENUM_NUM2, TWL4030_BASEADD_PWMA },
188 { TWL4030_SLAVENUM_NUM2, TWL4030_BASEADD_PWMB },
189 { TWL4030_SLAVENUM_NUM3, TWL4030_BASEADD_BACKUP },
190 { TWL4030_SLAVENUM_NUM3, TWL4030_BASEADD_INT },
191 { TWL4030_SLAVENUM_NUM3, TWL4030_BASEADD_PM_MASTER },
192 { TWL4030_SLAVENUM_NUM3, TWL4030_BASEADD_PM_RECEIVER },
193 { TWL4030_SLAVENUM_NUM3, TWL4030_BASEADD_RTC },
194 { TWL4030_SLAVENUM_NUM3, TWL4030_BASEADD_SECURED_REG },
197 static struct twl4030_client twl4030_modules[TWL4030_NUM_SLAVES] = {
199 .address = TWL4030_SLAVEID_ID0,
200 .client_name = TWL_CLIENT_STRING "0",
201 .adapter_index = CONFIG_I2C_TWL4030_ID,
204 .address = TWL4030_SLAVEID_ID1,
205 .client_name = TWL_CLIENT_STRING "1",
206 .adapter_index = CONFIG_I2C_TWL4030_ID,
209 .address = TWL4030_SLAVEID_ID2,
210 .client_name = TWL_CLIENT_STRING "2",
211 .adapter_index = CONFIG_I2C_TWL4030_ID,
214 .address = TWL4030_SLAVEID_ID3,
215 .client_name = TWL_CLIENT_STRING "3",
216 .adapter_index = CONFIG_I2C_TWL4030_ID,
220 /* One Client Driver , 4 Clients */
221 static struct i2c_driver twl4030_driver = {
224 .owner = THIS_MODULE,
226 .attach_adapter = twl4030_attach_adapter,
227 .detach_client = twl4030_detach_client,
231 * TWL4030 doesn't have PIH mask, hence dummy function for mask
235 static void twl4030_i2c_ackirq(unsigned int irq) {}
236 static void twl4030_i2c_disableint(unsigned int irq) {}
237 static void twl4030_i2c_enableint(unsigned int irq) {}
239 /* information for processing in the Work Item */
240 static struct irq_chip twl4030_irq_chip = {
241 .ack = twl4030_i2c_ackirq,
242 .mask = twl4030_i2c_disableint,
243 .unmask = twl4030_i2c_enableint,
246 /* Global Functions */
248 * @brief twl4030_i2c_write - Writes a n bit register in TWL4030
250 * @param mod_no - module number
251 * @param *value - an array of num_bytes+1 containing data to write
252 * IMPORTANT - Allocate value num_bytes+1 and valid data starts at
254 * @param reg - register address (just offset will do)
255 * @param num_bytes - number of bytes to transfer
257 * @return result of operation - 0 is success
259 int twl4030_i2c_write(u8 mod_no, u8 *value, u8 reg, u8 num_bytes)
263 struct twl4030_client *twl;
266 if (unlikely(mod_no > TWL4030_MODULE_LAST)) {
267 pr_err("Invalid module Number\n");
270 sid = twl4030_map[mod_no].sid;
271 twl = &twl4030_modules[sid];
273 if (unlikely(twl->inuse != TWL_CLIENT_USED)) {
274 pr_err("I2C Client[%d] is not initialized[%d]\n",
278 mutex_lock(&twl->xfer_lock);
280 * [MSG1]: fill the register address data
281 * fill the data Tx buffer
283 msg = &twl->xfer_msg[0];
284 msg->addr = twl->address;
285 msg->len = num_bytes + 1;
288 /* over write the first byte of buffer with the register address */
289 *value = twl4030_map[mod_no].base + reg;
290 ret = i2c_transfer(twl->client.adapter, twl->xfer_msg, 1);
291 mutex_unlock(&twl->xfer_lock);
293 /* i2cTransfer returns num messages.translate it pls.. */
298 EXPORT_SYMBOL(twl4030_i2c_write);
301 * @brief twl4030_i2c_read - Reads a n bit register in TWL4030
303 * @param mod_no - module number
304 * @param *value - an array of num_bytes containing data to be read
305 * @param reg - register address (just offset will do)
306 * @param num_bytes - number of bytes to transfer
308 * @return result of operation - num_bytes is success else failure.
310 int twl4030_i2c_read(u8 mod_no, u8 *value, u8 reg, u8 num_bytes)
315 struct twl4030_client *twl;
318 if (unlikely(mod_no > TWL4030_MODULE_LAST)) {
319 pr_err("Invalid module Number\n");
322 sid = twl4030_map[mod_no].sid;
323 twl = &twl4030_modules[sid];
325 if (unlikely(twl->inuse != TWL_CLIENT_USED)) {
326 pr_err("I2C Client[%d] is not initialized[%d]\n", sid,
330 mutex_lock(&twl->xfer_lock);
331 /* [MSG1] fill the register address data */
332 msg = &twl->xfer_msg[0];
333 msg->addr = twl->address;
335 msg->flags = 0; /* Read the register value */
336 val = twl4030_map[mod_no].base + reg;
338 /* [MSG2] fill the data rx buffer */
339 msg = &twl->xfer_msg[1];
340 msg->addr = twl->address;
341 msg->flags = I2C_M_RD; /* Read the register value */
342 msg->len = num_bytes; /* only n bytes */
344 ret = i2c_transfer(twl->client.adapter, twl->xfer_msg, 2);
345 mutex_unlock(&twl->xfer_lock);
347 /* i2cTransfer returns num messages.translate it pls.. */
352 EXPORT_SYMBOL(twl4030_i2c_read);
355 * @brief twl4030_i2c_write_u8 - Writes a 8 bit register in TWL4030
357 * @param mod_no - module number
358 * @param value - the value to be written 8 bit
359 * @param reg - register address (just offset will do)
361 * @return result of operation - 0 is success
363 int twl4030_i2c_write_u8(u8 mod_no, u8 value, u8 reg)
366 /* 2 bytes offset 1 contains the data offset 0 is used by i2c_write */
367 u8 temp_buffer[2] = { 0 };
368 /* offset 1 contains the data */
369 temp_buffer[1] = value;
370 return twl4030_i2c_write(mod_no, temp_buffer, reg, 1);
372 EXPORT_SYMBOL(twl4030_i2c_write_u8);
375 * @brief twl4030_i2c_read_u8 - Reads a 8 bit register from TWL4030
377 * @param mod_no - module number
378 * @param *value - the value read 8 bit
379 * @param reg - register address (just offset will do)
381 * @return result of operation - 0 is success
383 int twl4030_i2c_read_u8(u8 mod_no, u8 *value, u8 reg)
385 return twl4030_i2c_read(mod_no, value, reg, 1);
387 EXPORT_SYMBOL(twl4030_i2c_read_u8);
389 /* Helper Functions */
392 * do_twl4030_module_irq() is the desc->handle method for each of the twl4030
393 * module interrupts. It executes in kernel thread context.
394 * On entry, cpu interrupts are disabled.
396 static void do_twl4030_module_irq(unsigned int irq, irq_desc_t *desc)
398 struct irqaction *action;
399 const unsigned int cpu = smp_processor_id();
402 * Earlier this was desc->triggered = 1;
404 desc->status |= IRQ_LEVEL;
407 * The desc->handle method would normally call the desc->chip->ack
408 * method here, but we won't bother since our ack method is NULL.
412 kstat_cpu(cpu).irqs[irq]++;
414 action = desc->action;
423 /* Call the ISR with cpu interrupts enabled */
424 ret = action->handler(irq, action->dev_id);
425 if (ret == IRQ_HANDLED)
426 status |= action->flags;
428 action = action->next;
431 if (status & IRQF_SAMPLE_RANDOM)
432 add_interrupt_randomness(irq);
436 if (retval != IRQ_HANDLED)
437 printk(KERN_ERR "ISR for TWL4030 module"
438 " irq %d can't handle interrupt\n",
442 * Here is where we should call the unmask method, but
443 * again we won't bother since it is NULL.
446 printk(KERN_CRIT "TWL4030 module irq %d has no ISR"
447 " but can't be masked!\n", irq);
449 printk(KERN_CRIT "TWL4030 module irq %d is disabled but can't"
450 " be masked!\n", irq);
454 * twl4030_irq_thread() runs as a kernel thread. It queries the twl4030
455 * interrupt controller to see which modules are generating interrupt requests
456 * and then calls the desc->handle method for each module requesting service.
458 static int twl4030_irq_thread(void *data)
461 irq_desc_t *desc = irq_desc + irq;
462 static unsigned i2c_errors;
463 const static unsigned max_i2c_errors = 100;
465 daemonize("twl4030-irq");
466 current->flags |= PF_NOFREEZE;
468 while (!kthread_should_stop()) {
473 wait_for_completion_interruptible(&irq_event);
475 ret = twl4030_i2c_read_u8(TWL4030_MODULE_PIH, &pih_isr,
478 printk(KERN_WARNING "I2C error %d while reading TWL4030"
479 " PIH ISR register.\n", ret);
480 if (++i2c_errors >= max_i2c_errors) {
481 printk(KERN_ERR "Maximum I2C error count"
482 " exceeded. Terminating %s.\n",
489 for (module_irq = TWL4030_IRQ_BASE; 0 != pih_isr;
490 pih_isr >>= 1, module_irq++) {
492 irq_desc_t *d = irq_desc + module_irq;
496 d->handle_irq(module_irq, d);
502 desc->chip->unmask(irq);
509 * do_twl4030_irq() is the desc->handle method for the twl4030 interrupt.
510 * This is a chained interrupt, so there is no desc->action method for it.
511 * Now we need to query the interrupt controller in the twl4030 to determine
512 * which module is generating the interrupt request. However, we can't do i2c
513 * transactions in interrupt context, so we must defer that work to a kernel
514 * thread. All we do here is acknowledge and mask the interrupt and wakeup
517 static void do_twl4030_irq(unsigned int irq, irq_desc_t *desc)
519 const unsigned int cpu = smp_processor_id();
522 * Earlier this was desc->triggered = 1;
524 desc->status |= IRQ_LEVEL;
527 * Acknowledge, clear _AND_ disable the interrupt.
529 desc->chip->ack(irq);
532 kstat_cpu(cpu).irqs[irq]++;
534 complete(&irq_event);
538 /* attach a client to the adapter */
539 static int twl4030_detect_client(struct i2c_adapter *adapter, unsigned char sid)
542 struct twl4030_client *twl;
544 if (unlikely(sid >= TWL4030_NUM_SLAVES)) {
545 pr_err("sid[%d] > MOD_LAST[%d]\n", sid, TWL4030_NUM_SLAVES);
549 /* Check basic functionality */
550 err = i2c_check_functionality(adapter,
551 I2C_FUNC_SMBUS_WORD_DATA
552 | I2C_FUNC_SMBUS_WRITE_BYTE);
554 pr_err("SlaveID=%d functionality check failed\n", sid);
557 twl = &twl4030_modules[sid];
558 if (unlikely(twl->inuse)) {
559 pr_err("Client %s is already in use\n", twl->client_name);
563 memset(&twl->client, 0, sizeof(struct i2c_client));
565 twl->client.addr = twl->address;
566 twl->client.adapter = adapter;
567 twl->client.driver = &twl4030_driver;
569 memcpy(&twl->client.name, twl->client_name,
570 sizeof(TWL_CLIENT_STRING) + 1);
572 pr_info("TWL4030: TRY attach Slave %s on Adapter %s [%x]\n",
573 twl->client_name, adapter->name, err);
575 err = i2c_attach_client(&twl->client);
577 pr_err("Couldn't attach Slave %s on Adapter"
578 "%s [%x]\n", twl->client_name, adapter->name, err);
580 twl->inuse = TWL_CLIENT_USED;
581 mutex_init(&twl->xfer_lock);
587 /* adapter callback */
588 static int twl4030_attach_adapter(struct i2c_adapter *adapter)
592 static int twl_i2c_adapter = 1;
594 for (i = 0; i < TWL4030_NUM_SLAVES; i++) {
595 /* Check if I need to hook on to this adapter or not */
596 if (twl4030_modules[i].adapter_index == twl_i2c_adapter) {
597 ret = twl4030_detect_client(adapter, i);
605 * Check if the PIH module is initialized, if yes, then init
606 * the T2 Interrupt subsystem
608 if ((twl4030_modules[twl4030_map[TWL4030_MODULE_PIH].sid].inuse ==
609 TWL_CLIENT_USED) && (twl_irq_used != USED)) {
616 pr_err("TWL_CLIENT(Idx=%d] registration failed[0x%x]\n", i, ret);
618 /* ignore current slave..it never got registered */
621 /* now remove all those from the current adapter... */
622 if (twl4030_modules[i].adapter_index == twl_i2c_adapter)
623 (void)twl4030_detach_client(&twl4030_modules[i].client);
629 /* adapter's callback */
630 static int twl4030_detach_client(struct i2c_client *client)
633 err = i2c_detach_client(client);
635 pr_err("Client detach failed\n");
641 static struct task_struct *start_twl4030_irq_thread(int irq)
643 struct task_struct *thread;
645 init_completion(&irq_event);
646 thread = kthread_run(twl4030_irq_thread, (void *)irq,
647 "twl4030 irq %d", irq);
649 pr_err("%s: could not create twl4030 irq %d thread!\n",
656 * These three functions should be part of Voltage frame work
657 * added here to complete the functionality for now.
659 static int protect_pm_master(void)
663 e = twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, KEY_LOCK,
668 static int unprotect_pm_master(void)
672 e |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, KEY_UNLOCK1,
674 e |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, KEY_UNLOCK2,
679 static int power_companion_init(void)
683 u8 ctrl = HFCLK_FREQ_26_MHZ;
686 if (cpu_is_omap2430())
687 osc = clk_get(NULL, "osc_ck");
689 osc = clk_get(NULL, "osc_sys_ck");
691 printk(KERN_WARNING "Skipping twl3040 internal clock init and "
692 "using bootloader value (unknown osc rate)\n");
696 rate = clk_get_rate(osc);
700 case 19200000 : ctrl = HFCLK_FREQ_19p2_MHZ; break;
701 case 26000000 : ctrl = HFCLK_FREQ_26_MHZ; break;
702 case 38400000 : ctrl = HFCLK_FREQ_38p4_MHZ; break;
705 ctrl |= HIGH_PERF_SQ;
706 e |= unprotect_pm_master();
707 /* effect->MADC+USB ck en */
708 e |= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, ctrl, R_CFG_BOOT);
709 e |= protect_pm_master();
714 static void twl_init_irq(void)
718 char *msg = "Unable to register interrupt subsystem";
721 * We end up with interrupts from other modules before
722 * they get a chance to handle them...
725 res = twl4030_i2c_write_u8(TWL4030_MODULE_INT, 0xFF, 0x00);
727 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
732 res = twl4030_i2c_write_u8(TWL4030_MODULE_INT, 0xFF, 0x02);
734 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
739 res = twl4030_i2c_write_u8(TWL4030_MODULE_INT, 0xFF, 0x1);
741 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
746 res = twl4030_i2c_write_u8(TWL4030_MODULE_INT, 0xFF, 0x3);
748 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
752 /* Clear off any other pending interrupts on power */
754 res = twl4030_i2c_write_u8(TWL4030_MODULE_INT, 0xFF, 0x00);
756 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
761 res = twl4030_i2c_write_u8(TWL4030_MODULE_INT, 0xFF, 0x02);
763 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
766 /* POWER HACK (END) */
767 /* Slave address 0x4A */
770 res = twl4030_i2c_write_u8(TWL4030_MODULE_INTERRUPTS, 0xFF, 0x3);
772 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
777 res = twl4030_i2c_write_u8(TWL4030_MODULE_INTERRUPTS, 0xFF, 0x4);
779 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
784 res = twl4030_i2c_write_u8(TWL4030_MODULE_INTERRUPTS, 0xFF, 0x7);
786 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
791 res = twl4030_i2c_write_u8(TWL4030_MODULE_INTERRUPTS, 0xFF, 0x8);
793 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
799 res = twl4030_i2c_write_u8(TWL4030_MODULE_MADC, 0xFF, 0x62);
801 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
806 res = twl4030_i2c_write_u8(TWL4030_MODULE_MADC, 0xFF, 0x64);
808 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
814 res = twl4030_i2c_write_u8(TWL4030_MODULE_KEYPAD, 0xFF, (0x12));
816 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
822 twl4030_i2c_read_u8(TWL4030_MODULE_KEYPAD, &clear, 0x11);
823 twl4030_i2c_read_u8(TWL4030_MODULE_KEYPAD, &clear, 0x11);
827 res = twl4030_i2c_write_u8(TWL4030_MODULE_KEYPAD, 0xFF, (0x14));
829 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
833 /* Slave address 0x49 */
835 res = twl4030_i2c_write_u8(TWL4030_MODULE_GPIO, 0xFF, (0x1C));
837 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
842 res = twl4030_i2c_write_u8(TWL4030_MODULE_GPIO, 0xFF, (0x1D));
844 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
849 res = twl4030_i2c_write_u8(TWL4030_MODULE_GPIO, 0xFF, (0x1E));
851 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
856 res = twl4030_i2c_write_u8(TWL4030_MODULE_GPIO, 0xFF, (0x22));
858 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
863 res = twl4030_i2c_write_u8(TWL4030_MODULE_GPIO, 0xFF, (0x23));
865 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
870 res = twl4030_i2c_write_u8(TWL4030_MODULE_GPIO, 0xFF, (0x24));
872 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
876 /* install an irq handler for each of the PIH modules */
877 for (i = TWL4030_IRQ_BASE; i < TWL4030_IRQ_END; i++) {
878 set_irq_chip(i, &twl4030_irq_chip);
879 set_irq_handler(i, do_twl4030_module_irq);
880 set_irq_flags(i, IRQF_VALID);
883 /* install an irq handler to demultiplex the TWL4030 interrupt */
884 set_irq_data(TWL4030_IRQNUM, start_twl4030_irq_thread(TWL4030_IRQNUM));
885 set_irq_type(TWL4030_IRQNUM, IRQT_FALLING);
886 set_irq_chained_handler(TWL4030_IRQNUM, do_twl4030_irq);
888 res = power_companion_init();
890 pr_err("%s[%d][%d]\n", msg, res, __LINE__);
893 static int __init twl4030_init(void)
895 return i2c_add_driver(&twl4030_driver);
898 static void __exit twl4030_exit(void)
900 i2c_del_driver(&twl4030_driver);
904 subsys_initcall(twl4030_init);
905 module_exit(twl4030_exit);
907 MODULE_AUTHOR("Texas Instruments, Inc.");
908 MODULE_DESCRIPTION("I2C Core interface for TWL4030");
909 MODULE_LICENSE("GPL");