2 * linux/drivers/ssi/omap-tsc2101.c
4 * TSC2101 codec interface driver for the OMAP platform
6 * Copyright (C) 2004 Texas Instruments, Inc.
8 * This package is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 * 2004/11/07 Nishanth Menon - Modified for common hooks for Audio and Touchscreen
21 #include <linux/module.h>
22 #include <linux/init.h>
23 #include <linux/sched.h>
24 #include <linux/errno.h>
25 #include <linux/delay.h>
27 #include <asm/system.h>
30 #include <asm/mach-types.h>
31 #include <asm/hardware.h>
32 #include <asm/hardware/clock.h>
34 #include <asm/arch/mux.h>
35 #include <asm/arch/io.h>
36 #include <asm/arch/hardware.h>
37 #include <asm/hardware/tsc2101.h>
38 #include <asm/arch/gpioexpander.h>
40 #include "omap-tsc2101.h"
42 #if CONFIG_ARCH_OMAP16XX
43 #include <../drivers/ssi/omap-uwire.h>
45 #error "Unsupported configuration"
51 static spinlock_t tsc2101_lock = SPIN_LOCK_UNLOCKED;
52 static struct clk * tsc2101_mclk_ck;
54 static int omap_tsc2101_configure(void);
56 /* FIXME: add driver model usage to powerdown the tsc2101 on suspend */
57 /* Clock -Hard coding for the time being */
58 #define CLK_SOFT_REQ_REG_BASE (0xFFFE0800+0x34)
59 #define SOFT_COM_MCK0_REQ_MASK (0x1<<6)
61 int omap_tsc2101_enable(void)
65 spin_lock(&tsc2101_lock);
68 /* set the Mux to provide MCLK to TSC2101 */
69 if (machine_is_omap_h3()) {
70 ret = omap_cfg_reg(V5_1710_MCLK_ON);
72 if (machine_is_omap_h2()) {
73 ret = omap_cfg_reg(R10_1610_MCLK_ON);
78 tsc2101_mclk_ck = clk_get(NULL, "mclk");
79 if (NULL == tsc2101_mclk_ck) {
80 printk(KERN_ERR "Unable to get the clock MCLK!!!\n");;
84 if (clk_set_rate(tsc2101_mclk_ck, 12000000)) {
85 printk(KERN_ERR "Unable to set rate to the MCLK!!!\n");;
89 clk_enable(tsc2101_mclk_ck);
91 ret = omap_tsc2101_configure();
94 if (!ret && !try_module_get(THIS_MODULE)) {
95 printk(KERN_CRIT "Failed to get TSC module\n");
101 spin_unlock(&tsc2101_lock);
105 void omap_tsc2101_disable(void)
107 spin_lock(&tsc2101_lock);
110 /* Remove the Mux to Stop MCLK to TSC2101 */
111 if (machine_is_omap_h3()) {
112 ret = omap_cfg_reg(V5_1710_MCLK_OFF);
114 if (machine_is_omap_h2()) {
115 ret = omap_cfg_reg(R10_1610_MCLK_OFF);
119 /* Release the MCLK */
120 clk_disable(tsc2101_mclk_ck);
121 clk_put(tsc2101_mclk_ck);
122 tsc2101_mclk_ck = NULL;
124 module_put(THIS_MODULE);
126 spin_unlock(&tsc2101_lock);
129 void omap_tsc2101_write(int page, u8 address, u16 data)
134 if (machine_is_omap_h2()) {
136 omap_uwire_data_transfer(1,
137 (((page) << 11) | (address << 5)),
141 "uwire-write returned error for address %x\n",
145 ret = omap_uwire_data_transfer(1, data, 16, 0, NULL, 0);
148 "uwire-write returned error for address %x\n",
153 if (machine_is_omap_h3()) {
156 omap_uwire_data_transfer(0, ((page << 11) | (address << 5)),
160 "uwire-write returned error for address %x\n",
164 ret = omap_uwire_data_transfer(0, data, 16, 0, NULL, 0);
167 "uwire-write returned error for address %x\n",
175 void omap_tsc2101_reads(int page, u8 startaddress, u16 * data, int numregs)
178 if (machine_is_omap_h2()) {
181 if (machine_is_omap_h3()) {
184 (void)omap_uwire_data_transfer(cs, (0x8000 | (page << 11)
185 | (startaddress << 5)),
187 for (i = 0; i < (numregs - 1); i++, data++) {
188 omap_uwire_data_transfer(cs, 0, 0, 16, data, 1);
190 omap_uwire_data_transfer(cs, 0, 0, 16, data, 0);
193 u16 omap_tsc2101_read(int page, u8 address)
196 omap_tsc2101_reads(page, address, &ret, 1);
200 /* FIXME: adapt clock divisors for uwire to current ARM xor clock rate */
201 static int omap_tsc2101_configure(void)
203 unsigned long uwire_flags = 0;
205 #if CONFIG_MACH_OMAP_H3
207 u8 ioExpanderVal = 0;
209 if ((err = read_gpio_expa(&ioExpanderVal, 0x24))) {
210 printk(" Error reading from I/O EXPANDER \n");
213 ioExpanderVal |= 0x8;
215 if ((err = write_gpio_expa(ioExpanderVal, 0x24))) {
216 printk(KERN_ERR ": Error writing to I/O EXPANDER \n");
221 if (machine_is_omap_h2()) {
222 uwire_flags = UWIRE_READ_RISING_EDGE | UWIRE_WRITE_RISING_EDGE;
223 omap_cfg_reg(N15_1610_UWIRE_CS1);
224 omap_uwire_configure_mode(1, uwire_flags);
226 if (machine_is_omap_h3()) {
227 uwire_flags = UWIRE_READ_RISING_EDGE | UWIRE_WRITE_RISING_EDGE;
228 omap_cfg_reg(N14_1610_UWIRE_CS0);
229 omap_uwire_configure_mode(0, uwire_flags);
232 /* Configure MCLK enable */
233 omap_writel(omap_readl(PU_PD_SEL_2) | (1 << 22), PU_PD_SEL_2);
238 EXPORT_SYMBOL(omap_tsc2101_enable);
239 EXPORT_SYMBOL(omap_tsc2101_read);
240 EXPORT_SYMBOL(omap_tsc2101_reads);
241 EXPORT_SYMBOL(omap_tsc2101_write);
242 EXPORT_SYMBOL(omap_tsc2101_disable);
244 MODULE_AUTHOR("Texas Instruments");
246 ("Glue audio driver for the TI OMAP1610/OMAP1710 TSC2101 codec.");
247 MODULE_LICENSE("GPL");