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>
26 #include <linux/clk.h>
28 #include <asm/system.h>
31 #include <asm/mach-types.h>
32 #include <asm/hardware.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>
39 #include <asm/arch/gpio.h>
41 #include "omap-tsc2101.h"
44 #include <../drivers/ssi/omap-uwire.h>
46 #error "Unsupported configuration"
52 static spinlock_t tsc2101_lock = SPIN_LOCK_UNLOCKED;
53 static struct clk * tsc2101_mclk_ck;
55 static int omap_tsc2101_configure(void);
57 /* FIXME: add driver model usage to powerdown the tsc2101 on suspend */
58 /* Clock -Hard coding for the time being */
59 #define CLK_SOFT_REQ_REG_BASE (0xFFFE0800+0x34)
60 #define SOFT_COM_MCK0_REQ_MASK (0x1<<6)
62 int omap_tsc2101_enable(void)
66 spin_lock(&tsc2101_lock);
69 /* set the Mux to provide MCLK to TSC2101 */
70 if (machine_is_omap_h3())
71 ret = omap_cfg_reg(V5_1710_MCLK_ON);
72 else if (machine_is_omap_h2())
73 ret = omap_cfg_reg(R10_1610_MCLK_ON);
74 else if (machine_is_omap_h6300())
75 ret = omap_cfg_reg(R10_1510_MCLK_ON);
77 if (!cpu_is_omap1510 ()) {
79 tsc2101_mclk_ck = clk_get(NULL, "mclk");
80 if (NULL == tsc2101_mclk_ck) {
81 printk(KERN_ERR "Unable to get the clock MCLK!!!\n");;
85 if (clk_set_rate(tsc2101_mclk_ck, 12000000)) {
86 printk(KERN_ERR "Unable to set rate to the MCLK!!!\n");;
90 clk_enable(tsc2101_mclk_ck);
91 } /* if (!cpu_is_omap1510 ()) */
93 ret = omap_tsc2101_configure();
96 if (!ret && !try_module_get(THIS_MODULE)) {
97 printk(KERN_CRIT "Failed to get TSC module\n");
103 spin_unlock(&tsc2101_lock);
107 void omap_tsc2101_disable(void)
109 spin_lock(&tsc2101_lock);
112 /* Remove the Mux to Stop MCLK to TSC2101 */
113 if (machine_is_omap_h3()) {
114 ret = omap_cfg_reg(V5_1710_MCLK_OFF);
116 if (machine_is_omap_h2()) {
117 ret = omap_cfg_reg(R10_1610_MCLK_OFF);
121 if (!cpu_is_omap1510 ()) {
122 /* Release the MCLK */
123 clk_disable(tsc2101_mclk_ck);
124 clk_put(tsc2101_mclk_ck);
125 tsc2101_mclk_ck = NULL;
128 #if defined(CONFIG_MACH_OMAP_H6300)
132 module_put(THIS_MODULE);
134 spin_unlock(&tsc2101_lock);
137 void omap_tsc2101_write(int page, u8 address, u16 data)
142 if (machine_is_omap_h2()) {
144 omap_uwire_data_transfer(1,
145 (((page) << 11) | (address << 5)),
149 "uwire-write returned error for address %x\n",
153 ret = omap_uwire_data_transfer(1, data, 16, 0, NULL, 0);
156 "uwire-write returned error for address %x\n",
161 if (machine_is_omap_h3() || machine_is_omap_h6300()) {
163 if (machine_is_omap_h6300())
164 omap_set_gpio_dataout (8, 0);
167 omap_uwire_data_transfer(0, ((page << 11) | (address << 5)),
171 "uwire-write returned error for address %x\n",
173 if (machine_is_omap_h6300())
174 omap_set_gpio_dataout (8, 1);
177 ret = omap_uwire_data_transfer(0, data, 16, 0, NULL, 0);
180 "uwire-write returned error for address %x\n",
182 if (machine_is_omap_h6300())
183 omap_set_gpio_dataout (8, 1);
187 if (machine_is_omap_h6300())
188 omap_set_gpio_dataout (8, 1);
192 void omap_tsc2101_reads(int page, u8 startaddress, u16 * data, int numregs)
195 if (machine_is_omap_h2()) {
198 if (machine_is_omap_h3() || machine_is_omap_h6300()) {
202 if (machine_is_omap_h6300())
203 omap_set_gpio_dataout(8, 0);
205 (void)omap_uwire_data_transfer(cs, (0x8000 | (page << 11)
206 | (startaddress << 5)),
208 for (i = 0; i < (numregs - 1); i++, data++) {
209 omap_uwire_data_transfer(cs, 0, 0, 16, data, 1);
211 omap_uwire_data_transfer(cs, 0, 0, 16, data, 0);
213 if (machine_is_omap_h6300())
214 omap_set_gpio_dataout(8, 1);
217 u16 omap_tsc2101_read(int page, u8 address)
220 omap_tsc2101_reads(page, address, &ret, 1);
224 /* FIXME: adapt clock divisors for uwire to current ARM xor clock rate */
225 static int omap_tsc2101_configure(void)
227 unsigned long uwire_flags = 0;
229 #ifdef CONFIG_MACH_OMAP_H3
231 u8 ioExpanderVal = 0;
233 if ((err = read_gpio_expa(&ioExpanderVal, 0x24))) {
234 printk(" Error reading from I/O EXPANDER \n");
237 ioExpanderVal |= 0x8;
239 if ((err = write_gpio_expa(ioExpanderVal, 0x24))) {
240 printk(KERN_ERR ": Error writing to I/O EXPANDER \n");
245 if (machine_is_omap_h2()) {
246 uwire_flags = UWIRE_READ_RISING_EDGE | UWIRE_WRITE_RISING_EDGE;
247 omap_cfg_reg(N15_1610_UWIRE_CS1);
248 omap_uwire_configure_mode(1, uwire_flags);
250 if (machine_is_omap_h3()) {
251 uwire_flags = UWIRE_READ_RISING_EDGE | UWIRE_WRITE_RISING_EDGE;
252 omap_cfg_reg(N14_1610_UWIRE_CS0);
253 omap_uwire_configure_mode(0, uwire_flags);
255 if (machine_is_omap_h6300()) {
256 uwire_flags = UWIRE_READ_RISING_EDGE | UWIRE_WRITE_RISING_EDGE;
257 omap_cfg_reg(N14_1510_UWIRE_CS0);
258 omap_uwire_configure_mode(0, uwire_flags);
260 omap_request_gpio(8);
261 omap_set_gpio_dataout(8, 0);
262 omap_set_gpio_direction (8, 0);
265 /* Configure MCLK enable */
266 if (cpu_is_omap16xx() || cpu_is_omap1710())
267 omap_writel(omap_readl(PU_PD_SEL_2) | (1 << 22), PU_PD_SEL_2);
268 if (machine_is_omap_h6300()) {
269 omap_cfg_reg(V19_1510_UWIRE_SCLK);
270 omap_cfg_reg(W21_1510_UWIRE_SDO);
271 omap_cfg_reg(U18_1510_UWIRE_SDI);
277 EXPORT_SYMBOL(omap_tsc2101_enable);
278 EXPORT_SYMBOL(omap_tsc2101_read);
279 EXPORT_SYMBOL(omap_tsc2101_reads);
280 EXPORT_SYMBOL(omap_tsc2101_write);
281 EXPORT_SYMBOL(omap_tsc2101_disable);
283 MODULE_AUTHOR("Texas Instruments");
285 ("Glue audio driver for the TI OMAP1610/OMAP1710 TSC2101 codec.");
286 MODULE_LICENSE("GPL");