Staging: cpc-usb: add driver to the build
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / arm / mach-pxa / corgi_ssp.c
bloba5ee70735e04ab4b45f62c99dad2b7976c1bde42
1 /*
2 * SSP control code for Sharp Corgi devices
4 * Copyright (c) 2004-2005 Richard Purdie
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/kernel.h>
15 #include <linux/sched.h>
16 #include <linux/slab.h>
17 #include <linux/delay.h>
18 #include <linux/platform_device.h>
19 #include <mach/hardware.h>
20 #include <asm/mach-types.h>
22 #include <mach/ssp.h>
23 #include <mach/pxa2xx-gpio.h>
24 #include <mach/regs-ssp.h>
25 #include "sharpsl.h"
27 static DEFINE_SPINLOCK(corgi_ssp_lock);
28 static struct ssp_dev corgi_ssp_dev;
29 static struct ssp_state corgi_ssp_state;
30 static struct corgissp_machinfo *ssp_machinfo;
33 * There are three devices connected to the SSP interface:
34 * 1. A touchscreen controller (TI ADS7846 compatible)
35 * 2. An LCD controller (with some Backlight functionality)
36 * 3. A battery monitoring IC (Maxim MAX1111)
38 * Each device uses a different speed/mode of communication.
40 * The touchscreen is very sensitive and the most frequently used
41 * so the port is left configured for this.
43 * Devices are selected using Chip Selects on GPIOs.
47 * ADS7846 Routines
49 unsigned long corgi_ssp_ads7846_putget(ulong data)
51 unsigned long flag;
52 u32 ret = 0;
54 spin_lock_irqsave(&corgi_ssp_lock, flag);
55 if (ssp_machinfo->cs_ads7846 >= 0)
56 GPCR(ssp_machinfo->cs_ads7846) = GPIO_bit(ssp_machinfo->cs_ads7846);
58 ssp_write_word(&corgi_ssp_dev,data);
59 ssp_read_word(&corgi_ssp_dev, &ret);
61 if (ssp_machinfo->cs_ads7846 >= 0)
62 GPSR(ssp_machinfo->cs_ads7846) = GPIO_bit(ssp_machinfo->cs_ads7846);
63 spin_unlock_irqrestore(&corgi_ssp_lock, flag);
65 return ret;
69 * NOTE: These functions should always be called in interrupt context
70 * and use the _lock and _unlock functions. They are very time sensitive.
72 void corgi_ssp_ads7846_lock(void)
74 spin_lock(&corgi_ssp_lock);
75 if (ssp_machinfo->cs_ads7846 >= 0)
76 GPCR(ssp_machinfo->cs_ads7846) = GPIO_bit(ssp_machinfo->cs_ads7846);
79 void corgi_ssp_ads7846_unlock(void)
81 if (ssp_machinfo->cs_ads7846 >= 0)
82 GPSR(ssp_machinfo->cs_ads7846) = GPIO_bit(ssp_machinfo->cs_ads7846);
83 spin_unlock(&corgi_ssp_lock);
86 void corgi_ssp_ads7846_put(ulong data)
88 ssp_write_word(&corgi_ssp_dev,data);
91 unsigned long corgi_ssp_ads7846_get(void)
93 u32 ret = 0;
94 ssp_read_word(&corgi_ssp_dev, &ret);
95 return ret;
98 EXPORT_SYMBOL(corgi_ssp_ads7846_putget);
99 EXPORT_SYMBOL(corgi_ssp_ads7846_lock);
100 EXPORT_SYMBOL(corgi_ssp_ads7846_unlock);
101 EXPORT_SYMBOL(corgi_ssp_ads7846_put);
102 EXPORT_SYMBOL(corgi_ssp_ads7846_get);
106 * LCD/Backlight Routines
108 unsigned long corgi_ssp_dac_put(ulong data)
110 unsigned long flag, sscr1 = SSCR1_SPH;
111 u32 tmp;
113 spin_lock_irqsave(&corgi_ssp_lock, flag);
115 if (machine_is_spitz() || machine_is_akita() || machine_is_borzoi())
116 sscr1 = 0;
118 ssp_disable(&corgi_ssp_dev);
119 ssp_config(&corgi_ssp_dev, (SSCR0_Motorola | (SSCR0_DSS & 0x07 )), sscr1, 0, SSCR0_SerClkDiv(ssp_machinfo->clk_lcdcon));
120 ssp_enable(&corgi_ssp_dev);
122 if (ssp_machinfo->cs_lcdcon >= 0)
123 GPCR(ssp_machinfo->cs_lcdcon) = GPIO_bit(ssp_machinfo->cs_lcdcon);
124 ssp_write_word(&corgi_ssp_dev,data);
125 /* Read null data back from device to prevent SSP overflow */
126 ssp_read_word(&corgi_ssp_dev, &tmp);
127 if (ssp_machinfo->cs_lcdcon >= 0)
128 GPSR(ssp_machinfo->cs_lcdcon) = GPIO_bit(ssp_machinfo->cs_lcdcon);
130 ssp_disable(&corgi_ssp_dev);
131 ssp_config(&corgi_ssp_dev, (SSCR0_National | (SSCR0_DSS & 0x0b )), 0, 0, SSCR0_SerClkDiv(ssp_machinfo->clk_ads7846));
132 ssp_enable(&corgi_ssp_dev);
134 spin_unlock_irqrestore(&corgi_ssp_lock, flag);
136 return 0;
139 void corgi_ssp_lcdtg_send(u8 adrs, u8 data)
141 corgi_ssp_dac_put(((adrs & 0x07) << 5) | (data & 0x1f));
144 void corgi_ssp_blduty_set(int duty)
146 corgi_ssp_lcdtg_send(0x02,duty);
149 EXPORT_SYMBOL(corgi_ssp_lcdtg_send);
150 EXPORT_SYMBOL(corgi_ssp_blduty_set);
153 * Max1111 Routines
155 int corgi_ssp_max1111_get(ulong data)
157 unsigned long flag;
158 long voltage = 0, voltage1 = 0, voltage2 = 0;
160 spin_lock_irqsave(&corgi_ssp_lock, flag);
161 if (ssp_machinfo->cs_max1111 >= 0)
162 GPCR(ssp_machinfo->cs_max1111) = GPIO_bit(ssp_machinfo->cs_max1111);
163 ssp_disable(&corgi_ssp_dev);
164 ssp_config(&corgi_ssp_dev, (SSCR0_Motorola | (SSCR0_DSS & 0x07 )), 0, 0, SSCR0_SerClkDiv(ssp_machinfo->clk_max1111));
165 ssp_enable(&corgi_ssp_dev);
167 udelay(1);
169 /* TB1/RB1 */
170 ssp_write_word(&corgi_ssp_dev,data);
171 ssp_read_word(&corgi_ssp_dev, (u32*)&voltage1); /* null read */
173 /* TB12/RB2 */
174 ssp_write_word(&corgi_ssp_dev,0);
175 ssp_read_word(&corgi_ssp_dev, (u32*)&voltage1);
177 /* TB13/RB3*/
178 ssp_write_word(&corgi_ssp_dev,0);
179 ssp_read_word(&corgi_ssp_dev, (u32*)&voltage2);
181 ssp_disable(&corgi_ssp_dev);
182 ssp_config(&corgi_ssp_dev, (SSCR0_National | (SSCR0_DSS & 0x0b )), 0, 0, SSCR0_SerClkDiv(ssp_machinfo->clk_ads7846));
183 ssp_enable(&corgi_ssp_dev);
184 if (ssp_machinfo->cs_max1111 >= 0)
185 GPSR(ssp_machinfo->cs_max1111) = GPIO_bit(ssp_machinfo->cs_max1111);
186 spin_unlock_irqrestore(&corgi_ssp_lock, flag);
188 if (voltage1 & 0xc0 || voltage2 & 0x3f)
189 voltage = -1;
190 else
191 voltage = ((voltage1 << 2) & 0xfc) | ((voltage2 >> 6) & 0x03);
193 return voltage;
196 EXPORT_SYMBOL(corgi_ssp_max1111_get);
199 * Support Routines
202 void __init corgi_ssp_set_machinfo(struct corgissp_machinfo *machinfo)
204 ssp_machinfo = machinfo;
207 static int __init corgi_ssp_probe(struct platform_device *dev)
209 int ret;
211 /* Chip Select - Disable All */
212 if (ssp_machinfo->cs_lcdcon >= 0)
213 pxa_gpio_mode(ssp_machinfo->cs_lcdcon | GPIO_OUT | GPIO_DFLT_HIGH);
214 if (ssp_machinfo->cs_max1111 >= 0)
215 pxa_gpio_mode(ssp_machinfo->cs_max1111 | GPIO_OUT | GPIO_DFLT_HIGH);
216 if (ssp_machinfo->cs_ads7846 >= 0)
217 pxa_gpio_mode(ssp_machinfo->cs_ads7846 | GPIO_OUT | GPIO_DFLT_HIGH);
219 ret = ssp_init(&corgi_ssp_dev, ssp_machinfo->port, 0);
221 if (ret)
222 printk(KERN_ERR "Unable to register SSP handler!\n");
223 else {
224 ssp_disable(&corgi_ssp_dev);
225 ssp_config(&corgi_ssp_dev, (SSCR0_National | (SSCR0_DSS & 0x0b )), 0, 0, SSCR0_SerClkDiv(ssp_machinfo->clk_ads7846));
226 ssp_enable(&corgi_ssp_dev);
229 return ret;
232 static int corgi_ssp_remove(struct platform_device *dev)
234 ssp_exit(&corgi_ssp_dev);
235 return 0;
238 static int corgi_ssp_suspend(struct platform_device *dev, pm_message_t state)
240 ssp_flush(&corgi_ssp_dev);
241 ssp_save_state(&corgi_ssp_dev,&corgi_ssp_state);
243 return 0;
246 static int corgi_ssp_resume(struct platform_device *dev)
248 if (ssp_machinfo->cs_lcdcon >= 0)
249 GPSR(ssp_machinfo->cs_lcdcon) = GPIO_bit(ssp_machinfo->cs_lcdcon); /* High - Disable LCD Control/Timing Gen */
250 if (ssp_machinfo->cs_max1111 >= 0)
251 GPSR(ssp_machinfo->cs_max1111) = GPIO_bit(ssp_machinfo->cs_max1111); /* High - Disable MAX1111*/
252 if (ssp_machinfo->cs_ads7846 >= 0)
253 GPSR(ssp_machinfo->cs_ads7846) = GPIO_bit(ssp_machinfo->cs_ads7846); /* High - Disable ADS7846*/
254 ssp_restore_state(&corgi_ssp_dev,&corgi_ssp_state);
255 ssp_enable(&corgi_ssp_dev);
257 return 0;
260 static struct platform_driver corgissp_driver = {
261 .probe = corgi_ssp_probe,
262 .remove = corgi_ssp_remove,
263 .suspend = corgi_ssp_suspend,
264 .resume = corgi_ssp_resume,
265 .driver = {
266 .name = "corgi-ssp",
270 int __init corgi_ssp_init(void)
272 return platform_driver_register(&corgissp_driver);
275 arch_initcall(corgi_ssp_init);