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
= {
242 .ack
= twl4030_i2c_ackirq
,
243 .mask
= twl4030_i2c_disableint
,
244 .unmask
= twl4030_i2c_enableint
,
247 /* Global Functions */
249 * @brief twl4030_i2c_write - Writes a n bit register in TWL4030
251 * @param mod_no - module number
252 * @param *value - an array of num_bytes+1 containing data to write
253 * IMPORTANT - Allocate value num_bytes+1 and valid data starts at
255 * @param reg - register address (just offset will do)
256 * @param num_bytes - number of bytes to transfer
258 * @return result of operation - 0 is success
260 int twl4030_i2c_write(u8 mod_no
, u8
*value
, u8 reg
, u8 num_bytes
)
264 struct twl4030_client
*twl
;
267 if (unlikely(mod_no
> TWL4030_MODULE_LAST
)) {
268 pr_err("Invalid module Number\n");
271 sid
= twl4030_map
[mod_no
].sid
;
272 twl
= &twl4030_modules
[sid
];
274 if (unlikely(twl
->inuse
!= TWL_CLIENT_USED
)) {
275 pr_err("I2C Client[%d] is not initialized[%d]\n",
279 mutex_lock(&twl
->xfer_lock
);
281 * [MSG1]: fill the register address data
282 * fill the data Tx buffer
284 msg
= &twl
->xfer_msg
[0];
285 msg
->addr
= twl
->address
;
286 msg
->len
= num_bytes
+ 1;
289 /* over write the first byte of buffer with the register address */
290 *value
= twl4030_map
[mod_no
].base
+ reg
;
291 ret
= i2c_transfer(twl
->client
.adapter
, twl
->xfer_msg
, 1);
292 mutex_unlock(&twl
->xfer_lock
);
294 /* i2cTransfer returns num messages.translate it pls.. */
299 EXPORT_SYMBOL(twl4030_i2c_write
);
302 * @brief twl4030_i2c_read - Reads a n bit register in TWL4030
304 * @param mod_no - module number
305 * @param *value - an array of num_bytes containing data to be read
306 * @param reg - register address (just offset will do)
307 * @param num_bytes - number of bytes to transfer
309 * @return result of operation - num_bytes is success else failure.
311 int twl4030_i2c_read(u8 mod_no
, u8
*value
, u8 reg
, u8 num_bytes
)
316 struct twl4030_client
*twl
;
319 if (unlikely(mod_no
> TWL4030_MODULE_LAST
)) {
320 pr_err("Invalid module Number\n");
323 sid
= twl4030_map
[mod_no
].sid
;
324 twl
= &twl4030_modules
[sid
];
326 if (unlikely(twl
->inuse
!= TWL_CLIENT_USED
)) {
327 pr_err("I2C Client[%d] is not initialized[%d]\n", sid
,
331 mutex_lock(&twl
->xfer_lock
);
332 /* [MSG1] fill the register address data */
333 msg
= &twl
->xfer_msg
[0];
334 msg
->addr
= twl
->address
;
336 msg
->flags
= 0; /* Read the register value */
337 val
= twl4030_map
[mod_no
].base
+ reg
;
339 /* [MSG2] fill the data rx buffer */
340 msg
= &twl
->xfer_msg
[1];
341 msg
->addr
= twl
->address
;
342 msg
->flags
= I2C_M_RD
; /* Read the register value */
343 msg
->len
= num_bytes
; /* only n bytes */
345 ret
= i2c_transfer(twl
->client
.adapter
, twl
->xfer_msg
, 2);
346 mutex_unlock(&twl
->xfer_lock
);
348 /* i2cTransfer returns num messages.translate it pls.. */
353 EXPORT_SYMBOL(twl4030_i2c_read
);
356 * @brief twl4030_i2c_write_u8 - Writes a 8 bit register in TWL4030
358 * @param mod_no - module number
359 * @param value - the value to be written 8 bit
360 * @param reg - register address (just offset will do)
362 * @return result of operation - 0 is success
364 int twl4030_i2c_write_u8(u8 mod_no
, u8 value
, u8 reg
)
367 /* 2 bytes offset 1 contains the data offset 0 is used by i2c_write */
368 u8 temp_buffer
[2] = { 0 };
369 /* offset 1 contains the data */
370 temp_buffer
[1] = value
;
371 return twl4030_i2c_write(mod_no
, temp_buffer
, reg
, 1);
373 EXPORT_SYMBOL(twl4030_i2c_write_u8
);
376 * @brief twl4030_i2c_read_u8 - Reads a 8 bit register from TWL4030
378 * @param mod_no - module number
379 * @param *value - the value read 8 bit
380 * @param reg - register address (just offset will do)
382 * @return result of operation - 0 is success
384 int twl4030_i2c_read_u8(u8 mod_no
, u8
*value
, u8 reg
)
386 return twl4030_i2c_read(mod_no
, value
, reg
, 1);
388 EXPORT_SYMBOL(twl4030_i2c_read_u8
);
390 /* Helper Functions */
393 * do_twl4030_module_irq() is the desc->handle method for each of the twl4030
394 * module interrupts. It executes in kernel thread context.
395 * On entry, cpu interrupts are disabled.
397 static void do_twl4030_module_irq(unsigned int irq
, irq_desc_t
*desc
)
399 struct irqaction
*action
;
400 const unsigned int cpu
= smp_processor_id();
403 * Earlier this was desc->triggered = 1;
405 desc
->status
|= IRQ_LEVEL
;
408 * The desc->handle method would normally call the desc->chip->ack
409 * method here, but we won't bother since our ack method is NULL.
413 kstat_cpu(cpu
).irqs
[irq
]++;
415 action
= desc
->action
;
424 /* Call the ISR with cpu interrupts enabled */
425 ret
= action
->handler(irq
, action
->dev_id
);
426 if (ret
== IRQ_HANDLED
)
427 status
|= action
->flags
;
429 action
= action
->next
;
432 if (status
& IRQF_SAMPLE_RANDOM
)
433 add_interrupt_randomness(irq
);
437 if (retval
!= IRQ_HANDLED
)
438 printk(KERN_ERR
"ISR for TWL4030 module"
439 " irq %d can't handle interrupt\n",
443 * Here is where we should call the unmask method, but
444 * again we won't bother since it is NULL.
447 printk(KERN_CRIT
"TWL4030 module irq %d has no ISR"
448 " but can't be masked!\n", irq
);
450 printk(KERN_CRIT
"TWL4030 module irq %d is disabled but can't"
451 " be masked!\n", irq
);
455 * twl4030_irq_thread() runs as a kernel thread. It queries the twl4030
456 * interrupt controller to see which modules are generating interrupt requests
457 * and then calls the desc->handle method for each module requesting service.
459 static int twl4030_irq_thread(void *data
)
462 irq_desc_t
*desc
= irq_desc
+ irq
;
463 static unsigned i2c_errors
;
464 const static unsigned max_i2c_errors
= 100;
466 daemonize("twl4030-irq");
467 current
->flags
|= PF_NOFREEZE
;
469 while (!kthread_should_stop()) {
474 wait_for_completion_interruptible(&irq_event
);
476 ret
= twl4030_i2c_read_u8(TWL4030_MODULE_PIH
, &pih_isr
,
479 printk(KERN_WARNING
"I2C error %d while reading TWL4030"
480 " PIH ISR register.\n", ret
);
481 if (++i2c_errors
>= max_i2c_errors
) {
482 printk(KERN_ERR
"Maximum I2C error count"
483 " exceeded. Terminating %s.\n",
490 for (module_irq
= TWL4030_IRQ_BASE
; 0 != pih_isr
;
491 pih_isr
>>= 1, module_irq
++) {
493 irq_desc_t
*d
= irq_desc
+ module_irq
;
497 d
->handle_irq(module_irq
, d
);
503 desc
->chip
->unmask(irq
);
510 * do_twl4030_irq() is the desc->handle method for the twl4030 interrupt.
511 * This is a chained interrupt, so there is no desc->action method for it.
512 * Now we need to query the interrupt controller in the twl4030 to determine
513 * which module is generating the interrupt request. However, we can't do i2c
514 * transactions in interrupt context, so we must defer that work to a kernel
515 * thread. All we do here is acknowledge and mask the interrupt and wakeup
518 static void do_twl4030_irq(unsigned int irq
, irq_desc_t
*desc
)
520 const unsigned int cpu
= smp_processor_id();
523 * Earlier this was desc->triggered = 1;
525 desc
->status
|= IRQ_LEVEL
;
528 * Acknowledge, clear _AND_ disable the interrupt.
530 desc
->chip
->ack(irq
);
533 kstat_cpu(cpu
).irqs
[irq
]++;
535 complete(&irq_event
);
539 /* attach a client to the adapter */
540 static int twl4030_detect_client(struct i2c_adapter
*adapter
, unsigned char sid
)
543 struct twl4030_client
*twl
;
545 if (unlikely(sid
>= TWL4030_NUM_SLAVES
)) {
546 pr_err("sid[%d] > MOD_LAST[%d]\n", sid
, TWL4030_NUM_SLAVES
);
550 /* Check basic functionality */
551 err
= i2c_check_functionality(adapter
,
552 I2C_FUNC_SMBUS_WORD_DATA
553 | I2C_FUNC_SMBUS_WRITE_BYTE
);
555 pr_err("SlaveID=%d functionality check failed\n", sid
);
558 twl
= &twl4030_modules
[sid
];
559 if (unlikely(twl
->inuse
)) {
560 pr_err("Client %s is already in use\n", twl
->client_name
);
564 memset(&twl
->client
, 0, sizeof(struct i2c_client
));
566 twl
->client
.addr
= twl
->address
;
567 twl
->client
.adapter
= adapter
;
568 twl
->client
.driver
= &twl4030_driver
;
570 memcpy(&twl
->client
.name
, twl
->client_name
,
571 sizeof(TWL_CLIENT_STRING
) + 1);
573 pr_info("TWL4030: TRY attach Slave %s on Adapter %s [%x]\n",
574 twl
->client_name
, adapter
->name
, err
);
576 err
= i2c_attach_client(&twl
->client
);
578 pr_err("Couldn't attach Slave %s on Adapter"
579 "%s [%x]\n", twl
->client_name
, adapter
->name
, err
);
581 twl
->inuse
= TWL_CLIENT_USED
;
582 mutex_init(&twl
->xfer_lock
);
588 /* adapter callback */
589 static int twl4030_attach_adapter(struct i2c_adapter
*adapter
)
593 static int twl_i2c_adapter
= 1;
595 for (i
= 0; i
< TWL4030_NUM_SLAVES
; i
++) {
596 /* Check if I need to hook on to this adapter or not */
597 if (twl4030_modules
[i
].adapter_index
== twl_i2c_adapter
) {
598 ret
= twl4030_detect_client(adapter
, i
);
606 * Check if the PIH module is initialized, if yes, then init
607 * the T2 Interrupt subsystem
609 if ((twl4030_modules
[twl4030_map
[TWL4030_MODULE_PIH
].sid
].inuse
==
610 TWL_CLIENT_USED
) && (twl_irq_used
!= USED
)) {
617 pr_err("TWL_CLIENT(Idx=%d] registration failed[0x%x]\n", i
, ret
);
619 /* ignore current slave..it never got registered */
622 /* now remove all those from the current adapter... */
623 if (twl4030_modules
[i
].adapter_index
== twl_i2c_adapter
)
624 (void)twl4030_detach_client(&twl4030_modules
[i
].client
);
630 /* adapter's callback */
631 static int twl4030_detach_client(struct i2c_client
*client
)
634 err
= i2c_detach_client(client
);
636 pr_err("Client detach failed\n");
642 static struct task_struct
*start_twl4030_irq_thread(int irq
)
644 struct task_struct
*thread
;
646 init_completion(&irq_event
);
647 thread
= kthread_run(twl4030_irq_thread
, (void *)irq
,
648 "twl4030 irq %d", irq
);
650 pr_err("%s: could not create twl4030 irq %d thread!\n",
657 * These three functions should be part of Voltage frame work
658 * added here to complete the functionality for now.
660 static int protect_pm_master(void)
664 e
= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER
, KEY_LOCK
,
669 static int unprotect_pm_master(void)
673 e
|= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER
, KEY_UNLOCK1
,
675 e
|= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER
, KEY_UNLOCK2
,
680 static int power_companion_init(void)
684 u8 ctrl
= HFCLK_FREQ_26_MHZ
;
687 if (cpu_is_omap2430())
688 osc
= clk_get(NULL
, "osc_ck");
690 osc
= clk_get(NULL
, "osc_sys_ck");
692 printk(KERN_WARNING
"Skipping twl3040 internal clock init and "
693 "using bootloader value (unknown osc rate)\n");
697 rate
= clk_get_rate(osc
);
701 case 19200000 : ctrl
= HFCLK_FREQ_19p2_MHZ
; break;
702 case 26000000 : ctrl
= HFCLK_FREQ_26_MHZ
; break;
703 case 38400000 : ctrl
= HFCLK_FREQ_38p4_MHZ
; break;
706 ctrl
|= HIGH_PERF_SQ
;
707 e
|= unprotect_pm_master();
708 /* effect->MADC+USB ck en */
709 e
|= twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER
, ctrl
, R_CFG_BOOT
);
710 e
|= protect_pm_master();
715 static void twl_init_irq(void)
719 char *msg
= "Unable to register interrupt subsystem";
720 unsigned int irq_num
;
723 * We end up with interrupts from other modules before
724 * they get a chance to handle them...
727 res
= twl4030_i2c_write_u8(TWL4030_MODULE_INT
, 0xFF, 0x00);
729 pr_err("%s[%d][%d]\n", msg
, res
, __LINE__
);
734 res
= twl4030_i2c_write_u8(TWL4030_MODULE_INT
, 0xFF, 0x02);
736 pr_err("%s[%d][%d]\n", msg
, res
, __LINE__
);
741 res
= twl4030_i2c_write_u8(TWL4030_MODULE_INT
, 0xFF, 0x1);
743 pr_err("%s[%d][%d]\n", msg
, res
, __LINE__
);
748 res
= twl4030_i2c_write_u8(TWL4030_MODULE_INT
, 0xFF, 0x3);
750 pr_err("%s[%d][%d]\n", msg
, res
, __LINE__
);
754 /* Clear off any other pending interrupts on power */
756 res
= twl4030_i2c_write_u8(TWL4030_MODULE_INT
, 0xFF, 0x00);
758 pr_err("%s[%d][%d]\n", msg
, res
, __LINE__
);
763 res
= twl4030_i2c_write_u8(TWL4030_MODULE_INT
, 0xFF, 0x02);
765 pr_err("%s[%d][%d]\n", msg
, res
, __LINE__
);
768 /* POWER HACK (END) */
769 /* Slave address 0x4A */
772 res
= twl4030_i2c_write_u8(TWL4030_MODULE_INTERRUPTS
, 0xFF, 0x3);
774 pr_err("%s[%d][%d]\n", msg
, res
, __LINE__
);
779 res
= twl4030_i2c_write_u8(TWL4030_MODULE_INTERRUPTS
, 0xFF, 0x4);
781 pr_err("%s[%d][%d]\n", msg
, res
, __LINE__
);
786 res
= twl4030_i2c_write_u8(TWL4030_MODULE_INTERRUPTS
, 0xFF, 0x7);
788 pr_err("%s[%d][%d]\n", msg
, res
, __LINE__
);
793 res
= twl4030_i2c_write_u8(TWL4030_MODULE_INTERRUPTS
, 0xFF, 0x8);
795 pr_err("%s[%d][%d]\n", msg
, res
, __LINE__
);
801 res
= twl4030_i2c_write_u8(TWL4030_MODULE_MADC
, 0xFF, 0x62);
803 pr_err("%s[%d][%d]\n", msg
, res
, __LINE__
);
808 res
= twl4030_i2c_write_u8(TWL4030_MODULE_MADC
, 0xFF, 0x64);
810 pr_err("%s[%d][%d]\n", msg
, res
, __LINE__
);
816 res
= twl4030_i2c_write_u8(TWL4030_MODULE_KEYPAD
, 0xFF, (0x12));
818 pr_err("%s[%d][%d]\n", msg
, res
, __LINE__
);
824 twl4030_i2c_read_u8(TWL4030_MODULE_KEYPAD
, &clear
, 0x11);
825 twl4030_i2c_read_u8(TWL4030_MODULE_KEYPAD
, &clear
, 0x11);
829 res
= twl4030_i2c_write_u8(TWL4030_MODULE_KEYPAD
, 0xFF, (0x14));
831 pr_err("%s[%d][%d]\n", msg
, res
, __LINE__
);
835 /* Slave address 0x49 */
837 res
= twl4030_i2c_write_u8(TWL4030_MODULE_GPIO
, 0xFF, (0x1C));
839 pr_err("%s[%d][%d]\n", msg
, res
, __LINE__
);
844 res
= twl4030_i2c_write_u8(TWL4030_MODULE_GPIO
, 0xFF, (0x1D));
846 pr_err("%s[%d][%d]\n", msg
, res
, __LINE__
);
851 res
= twl4030_i2c_write_u8(TWL4030_MODULE_GPIO
, 0xFF, (0x1E));
853 pr_err("%s[%d][%d]\n", msg
, res
, __LINE__
);
858 res
= twl4030_i2c_write_u8(TWL4030_MODULE_GPIO
, 0xFF, (0x22));
860 pr_err("%s[%d][%d]\n", msg
, res
, __LINE__
);
865 res
= twl4030_i2c_write_u8(TWL4030_MODULE_GPIO
, 0xFF, (0x23));
867 pr_err("%s[%d][%d]\n", msg
, res
, __LINE__
);
872 res
= twl4030_i2c_write_u8(TWL4030_MODULE_GPIO
, 0xFF, (0x24));
874 pr_err("%s[%d][%d]\n", msg
, res
, __LINE__
);
878 /* install an irq handler for each of the PIH modules */
879 for (i
= TWL4030_IRQ_BASE
; i
< TWL4030_IRQ_END
; i
++) {
880 set_irq_chip(i
, &twl4030_irq_chip
);
881 set_irq_handler(i
, do_twl4030_module_irq
);
882 set_irq_flags(i
, IRQF_VALID
);
885 irq_num
= (cpu_is_omap2430()) ? INT_24XX_SYS_NIRQ
: INT_34XX_SYS_NIRQ
;
887 /* install an irq handler to demultiplex the TWL4030 interrupt */
888 set_irq_data(irq_num
, start_twl4030_irq_thread(irq_num
));
889 set_irq_type(irq_num
, IRQT_FALLING
);
890 set_irq_chained_handler(irq_num
, do_twl4030_irq
);
892 res
= power_companion_init();
894 pr_err("%s[%d][%d]\n", msg
, res
, __LINE__
);
897 static int __init
twl4030_init(void)
899 return i2c_add_driver(&twl4030_driver
);
902 static void __exit
twl4030_exit(void)
904 i2c_del_driver(&twl4030_driver
);
908 subsys_initcall(twl4030_init
);
909 module_exit(twl4030_exit
);
911 MODULE_AUTHOR("Texas Instruments, Inc.");
912 MODULE_DESCRIPTION("I2C Core interface for TWL4030");
913 MODULE_LICENSE("GPL");