]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/ssi/omap-tsc2101.c
h63xx: mux and microwire configurations.
[linux-2.6-omap-h63xx.git] / drivers / ssi / omap-tsc2101.c
1 /*
2  * linux/drivers/ssi/omap-tsc2101.c
3  *
4  * TSC2101 codec interface driver for the OMAP platform
5  *
6  * Copyright (C) 2004 Texas Instruments, Inc.
7  *
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.
11  *
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.
15  *
16  * History:
17  *
18  * 2004/11/07   Nishanth Menon - Modified for common hooks for Audio and Touchscreen
19  */
20
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>
27
28 #include <asm/system.h>
29 #include <asm/irq.h>
30 #include <asm/io.h>
31 #include <asm/mach-types.h>
32 #include <asm/hardware.h>
33
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>
40
41 #include "omap-tsc2101.h"
42
43 #if CONFIG_ARCH_OMAP1
44 #include <../drivers/ssi/omap-uwire.h>
45 #else
46 #error "Unsupported configuration"
47 #endif
48
49 #define SPIO 1
50
51 static int count;
52 static spinlock_t tsc2101_lock = SPIN_LOCK_UNLOCKED;
53 static struct clk  * tsc2101_mclk_ck;
54
55 static int omap_tsc2101_configure(void);
56
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)
61
62 int omap_tsc2101_enable(void)
63 {
64         int ret = 0;
65
66         spin_lock(&tsc2101_lock);
67         if (count++ == 0) {
68                 int ret = 0;
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);
76
77                 if (!cpu_is_omap1510 ()) {
78                         /* Get the MCLK */
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");;
82                                 ret = -EPERM;
83                                 goto done;
84                         }
85                         if (clk_set_rate(tsc2101_mclk_ck, 12000000)) {
86                                 printk(KERN_ERR "Unable to set rate to the MCLK!!!\n");;
87                                 ret = -EPERM;
88                                 goto done;
89                         }
90                         clk_enable(tsc2101_mclk_ck);
91                 } /* if (!cpu_is_omap1510 ()) */
92
93                 ret = omap_tsc2101_configure();
94
95                 /* Lock the module */
96                 if (!ret && !try_module_get(THIS_MODULE)) {
97                         printk(KERN_CRIT "Failed to get TSC module\n");
98                         ret = -ESTALE;
99                 }
100         }
101
102 done:
103         spin_unlock(&tsc2101_lock);
104         return ret;
105 }
106
107 void omap_tsc2101_disable(void)
108 {
109         spin_lock(&tsc2101_lock);
110         if (--count == 0) {
111                 int ret = 0;
112                 /* Remove the Mux to Stop MCLK to TSC2101 */
113                 if (machine_is_omap_h3()) {
114                         ret = omap_cfg_reg(V5_1710_MCLK_OFF);
115                 } else {
116                         if (machine_is_omap_h2()) {
117                                 ret = omap_cfg_reg(R10_1610_MCLK_OFF);
118                         }
119                 }
120
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;
126                 }
127
128 #if defined(CONFIG_MACH_OMAP_H6300)
129                 omap_free_gpio(8);
130 #endif
131
132                 module_put(THIS_MODULE);
133         }
134         spin_unlock(&tsc2101_lock);
135 }
136
137 void omap_tsc2101_write(int page, u8 address, u16 data)
138 {
139
140         int ret = 0;
141
142         if (machine_is_omap_h2()) {
143                 ret =
144                     omap_uwire_data_transfer(1, 
145                                              (((page) << 11) | (address << 5)),
146                                              16, 0, NULL, 1);
147                 if (ret) {
148                         printk(KERN_ERR
149                                "uwire-write returned error for address %x\n",
150                                address);
151                         return;
152                 }
153                 ret = omap_uwire_data_transfer(1, data, 16, 0, NULL, 0);
154                 if (ret) {
155                         printk(KERN_ERR
156                                "uwire-write returned error for address %x\n",
157                                address);
158                         return;
159                 }
160         }
161         if (machine_is_omap_h3() || machine_is_omap_h6300()) {
162
163                 if (machine_is_omap_h6300())
164                         omap_set_gpio_dataout (8, 0);
165
166                 ret =
167                     omap_uwire_data_transfer(0, ((page << 11) | (address << 5)),
168                                              16, 0, NULL, 1);
169                 if (ret) {
170                         printk(KERN_ERR
171                                "uwire-write returned error for address %x\n",
172                                address);
173                 if (machine_is_omap_h6300())
174                         omap_set_gpio_dataout (8, 1);
175                         return;
176                 }
177                 ret = omap_uwire_data_transfer(0, data, 16, 0, NULL, 0);
178                 if (ret) {
179                         printk(KERN_ERR
180                                "uwire-write returned error for address %x\n",
181                                address);
182                         if (machine_is_omap_h6300())
183                                 omap_set_gpio_dataout (8, 1);
184                         return;
185                 }
186
187                 if (machine_is_omap_h6300())
188                         omap_set_gpio_dataout (8, 1);
189         }
190 }
191
192 void omap_tsc2101_reads(int page, u8 startaddress, u16 * data, int numregs)
193 {
194         int cs = 0, i;
195         if (machine_is_omap_h2()) {
196                 cs = 1;
197         }
198         if (machine_is_omap_h3() || machine_is_omap_h6300()) {
199                 cs = 0;
200         }
201
202         if (machine_is_omap_h6300())
203                 omap_set_gpio_dataout(8, 0);
204
205         (void)omap_uwire_data_transfer(cs, (0x8000 | (page << 11)
206                                             | (startaddress << 5)),
207                                        16, 0, NULL, 1);
208         for (i = 0; i < (numregs - 1); i++, data++) {
209                 omap_uwire_data_transfer(cs, 0, 0, 16, data, 1);
210         }
211         omap_uwire_data_transfer(cs, 0, 0, 16, data, 0);
212
213         if (machine_is_omap_h6300())
214                 omap_set_gpio_dataout(8, 1);
215 }
216
217 u16 omap_tsc2101_read(int page, u8 address)
218 {
219         u16 ret;
220         omap_tsc2101_reads(page, address, &ret, 1);
221         return ret;
222 }
223
224 /* FIXME: adapt clock divisors for uwire to current ARM xor clock rate */
225 static int omap_tsc2101_configure(void)
226 {
227         unsigned long uwire_flags = 0;
228
229 #ifdef CONFIG_MACH_OMAP_H3
230         int err = 0;
231         u8 ioExpanderVal = 0;
232
233         if ((err = read_gpio_expa(&ioExpanderVal, 0x24))) {
234                 printk(" Error reading from I/O EXPANDER \n");
235                 return err;
236         }
237         ioExpanderVal |= 0x8;
238
239         if ((err = write_gpio_expa(ioExpanderVal, 0x24))) {
240                 printk(KERN_ERR ": Error writing to I/O EXPANDER \n");
241                 return err;
242         }
243 #endif
244
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);
249         }
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);
254         }
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);
259
260                 omap_request_gpio(8);
261                 omap_set_gpio_dataout(8, 0);
262                 omap_set_gpio_direction (8, 0);
263         }
264
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);
272         }
273
274         return 0;
275 }
276
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);
282
283 MODULE_AUTHOR("Texas Instruments");
284 MODULE_DESCRIPTION
285     ("Glue audio driver for the TI OMAP1610/OMAP1710 TSC2101 codec.");
286 MODULE_LICENSE("GPL");