]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/ssi/omap-tsc2101.c
Add various OMAP SSI drivers
[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
27 #include <asm/system.h>
28 #include <asm/irq.h>
29 #include <asm/io.h>
30 #include <asm/mach-types.h>
31 #include <asm/hardware.h>
32 #include <asm/hardware/clock.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
40 #include "omap-tsc2101.h"
41
42 #if CONFIG_ARCH_OMAP16XX
43 #include <../drivers/ssi/omap-uwire.h>
44 #else
45 #error "Unsupported configuration"
46 #endif
47
48 #define SPIO 1
49
50 static int count;
51 static spinlock_t tsc2101_lock = SPIN_LOCK_UNLOCKED;
52 static struct clk  * tsc2101_mclk_ck;
53
54 static int omap_tsc2101_configure(void);
55
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)
60
61 int omap_tsc2101_enable(void)
62 {
63         int ret = 0;
64
65         spin_lock(&tsc2101_lock);
66         if (count++ == 0) {
67                 int ret = 0;
68                 /* set the Mux to provide MCLK to TSC2101 */
69                 if (machine_is_omap_h3()) {
70                         ret = omap_cfg_reg(V5_1710_MCLK_ON);
71                 } else {
72                         if (machine_is_omap_h2()) {
73                                 ret = omap_cfg_reg(R10_1610_MCLK_ON);
74                         }
75                 }
76
77                 /* Get the MCLK */
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");;
81                         ret = -EPERM;
82                         goto done;
83                 }
84                 if (clk_set_rate(tsc2101_mclk_ck, 12000000)) {
85                         printk(KERN_ERR "Unable to set rate to the MCLK!!!\n");;
86                         ret = -EPERM;
87                         goto done;
88                 }
89                 clk_enable(tsc2101_mclk_ck);
90
91                 ret = omap_tsc2101_configure();
92
93                 /* Lock the module */
94                 if (!ret && !try_module_get(THIS_MODULE)) {
95                         printk(KERN_CRIT "Failed to get TSC module\n");
96                         ret = -ESTALE;
97                 }
98         }
99
100 done:
101         spin_unlock(&tsc2101_lock);
102         return ret;
103 }
104
105 void omap_tsc2101_disable(void)
106 {
107         spin_lock(&tsc2101_lock);
108         if (--count == 0) {
109                 int ret = 0;
110                 /* Remove the Mux to Stop MCLK to TSC2101 */
111                 if (machine_is_omap_h3()) {
112                         ret = omap_cfg_reg(V5_1710_MCLK_OFF);
113                 } else {
114                         if (machine_is_omap_h2()) {
115                                 ret = omap_cfg_reg(R10_1610_MCLK_OFF);
116                         }
117                 }
118
119                 /* Release the MCLK */
120                 clk_disable(tsc2101_mclk_ck);
121                 clk_put(tsc2101_mclk_ck);
122                 tsc2101_mclk_ck = NULL;
123
124                 module_put(THIS_MODULE);
125         }
126         spin_unlock(&tsc2101_lock);
127 }
128
129 void omap_tsc2101_write(int page, u8 address, u16 data)
130 {
131
132         int ret = 0;
133
134         if (machine_is_omap_h2()) {
135                 ret =
136                     omap_uwire_data_transfer(1, 
137                                              (((page) << 11) | (address << 5)),
138                                              16, 0, NULL, 1);
139                 if (ret) {
140                         printk(KERN_ERR
141                                "uwire-write returned error for address %x\n",
142                                address);
143                         return;
144                 }
145                 ret = omap_uwire_data_transfer(1, data, 16, 0, NULL, 0);
146                 if (ret) {
147                         printk(KERN_ERR
148                                "uwire-write returned error for address %x\n",
149                                address);
150                         return;
151                 }
152         }
153         if (machine_is_omap_h3()) {
154
155                 ret =
156                     omap_uwire_data_transfer(0, ((page << 11) | (address << 5)),
157                                              16, 0, NULL, 1);
158                 if (ret) {
159                         printk(KERN_ERR
160                                "uwire-write returned error for address %x\n",
161                                address);
162                         return;
163                 }
164                 ret = omap_uwire_data_transfer(0, data, 16, 0, NULL, 0);
165                 if (ret) {
166                         printk(KERN_ERR
167                                "uwire-write returned error for address %x\n",
168                                address);
169                         return;
170                 }
171         }
172
173 }
174
175 void omap_tsc2101_reads(int page, u8 startaddress, u16 * data, int numregs)
176 {
177         int cs = 0, i;
178         if (machine_is_omap_h2()) {
179                 cs = 1;
180         }
181         if (machine_is_omap_h3()) {
182                 cs = 0;
183         }
184         (void)omap_uwire_data_transfer(cs, (0x8000 | (page << 11)
185                                             | (startaddress << 5)),
186                                        16, 0, NULL, 1);
187         for (i = 0; i < (numregs - 1); i++, data++) {
188                 omap_uwire_data_transfer(cs, 0, 0, 16, data, 1);
189         }
190         omap_uwire_data_transfer(cs, 0, 0, 16, data, 0);
191 }
192
193 u16 omap_tsc2101_read(int page, u8 address)
194 {
195         u16 ret;
196         omap_tsc2101_reads(page, address, &ret, 1);
197         return ret;
198 }
199
200 /* FIXME: adapt clock divisors for uwire to current ARM xor clock rate */
201 static int omap_tsc2101_configure(void)
202 {
203         unsigned long uwire_flags = 0;
204
205 #if CONFIG_MACH_OMAP_H3
206         int err = 0;
207         u8 ioExpanderVal = 0;
208
209         if ((err = read_gpio_expa(&ioExpanderVal, 0x24))) {
210                 printk(" Error reading from I/O EXPANDER \n");
211                 return err;
212         }
213         ioExpanderVal |= 0x8;
214
215         if ((err = write_gpio_expa(ioExpanderVal, 0x24))) {
216                 printk(KERN_ERR ": Error writing to I/O EXPANDER \n");
217                 return err;
218         }
219 #endif
220
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);
225         }
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);
230         }
231
232         /* Configure MCLK enable */
233         omap_writel(omap_readl(PU_PD_SEL_2) | (1 << 22), PU_PD_SEL_2);  
234
235         return 0;
236 }
237
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);
243
244 MODULE_AUTHOR("Texas Instruments");
245 MODULE_DESCRIPTION
246     ("Glue audio driver for the TI OMAP1610/OMAP1710 TSC2101 codec.");
247 MODULE_LICENSE("GPL");