viafb: removed duplicated #include's
[linux-2.6/mini2440.git] / arch / arm / mach-pxa / corgi_ssp.c
blob8e2f2215c4bac609529fed84388a7142b9e420ed
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/pxa-regs.h>
24 #include <mach/pxa2xx-gpio.h>
25 #include <mach/regs-ssp.h>
26 #include "sharpsl.h"
28 static DEFINE_SPINLOCK(corgi_ssp_lock);
29 static struct ssp_dev corgi_ssp_dev;
30 static struct ssp_state corgi_ssp_state;
31 static struct corgissp_machinfo *ssp_machinfo;
34 * There are three devices connected to the SSP interface:
35 * 1. A touchscreen controller (TI ADS7846 compatible)
36 * 2. An LCD controller (with some Backlight functionality)
37 * 3. A battery monitoring IC (Maxim MAX1111)
39 * Each device uses a different speed/mode of communication.
41 * The touchscreen is very sensitive and the most frequently used
42 * so the port is left configured for this.
44 * Devices are selected using Chip Selects on GPIOs.
48 * ADS7846 Routines
50 unsigned long corgi_ssp_ads7846_putget(ulong data)
52 unsigned long flag;
53 u32 ret = 0;
55 spin_lock_irqsave(&corgi_ssp_lock, flag);
56 if (ssp_machinfo->cs_ads7846 >= 0)
57 GPCR(ssp_machinfo->cs_ads7846) = GPIO_bit(ssp_machinfo->cs_ads7846);
59 ssp_write_word(&corgi_ssp_dev,data);
60 ssp_read_word(&corgi_ssp_dev, &ret);
62 if (ssp_machinfo->cs_ads7846 >= 0)
63 GPSR(ssp_machinfo->cs_ads7846) = GPIO_bit(ssp_machinfo->cs_ads7846);
64 spin_unlock_irqrestore(&corgi_ssp_lock, flag);
66 return ret;
70 * NOTE: These functions should always be called in interrupt context
71 * and use the _lock and _unlock functions. They are very time sensitive.
73 void corgi_ssp_ads7846_lock(void)
75 spin_lock(&corgi_ssp_lock);
76 if (ssp_machinfo->cs_ads7846 >= 0)
77 GPCR(ssp_machinfo->cs_ads7846) = GPIO_bit(ssp_machinfo->cs_ads7846);
80 void corgi_ssp_ads7846_unlock(void)
82 if (ssp_machinfo->cs_ads7846 >= 0)
83 GPSR(ssp_machinfo->cs_ads7846) = GPIO_bit(ssp_machinfo->cs_ads7846);
84 spin_unlock(&corgi_ssp_lock);
87 void corgi_ssp_ads7846_put(ulong data)
89 ssp_write_word(&corgi_ssp_dev,data);
92 unsigned long corgi_ssp_ads7846_get(void)
94 u32 ret = 0;
95 ssp_read_word(&corgi_ssp_dev, &ret);
96 return ret;
99 EXPORT_SYMBOL(corgi_ssp_ads7846_putget);
100 EXPORT_SYMBOL(corgi_ssp_ads7846_lock);
101 EXPORT_SYMBOL(corgi_ssp_ads7846_unlock);
102 EXPORT_SYMBOL(corgi_ssp_ads7846_put);
103 EXPORT_SYMBOL(corgi_ssp_ads7846_get);
107 * LCD/Backlight Routines
109 unsigned long corgi_ssp_dac_put(ulong data)
111 unsigned long flag, sscr1 = SSCR1_SPH;
112 u32 tmp;
114 spin_lock_irqsave(&corgi_ssp_lock, flag);
116 if (machine_is_spitz() || machine_is_akita() || machine_is_borzoi())
117 sscr1 = 0;
119 ssp_disable(&corgi_ssp_dev);
120 ssp_config(&corgi_ssp_dev, (SSCR0_Motorola | (SSCR0_DSS & 0x07 )), sscr1, 0, SSCR0_SerClkDiv(ssp_machinfo->clk_lcdcon));
121 ssp_enable(&corgi_ssp_dev);
123 if (ssp_machinfo->cs_lcdcon >= 0)
124 GPCR(ssp_machinfo->cs_lcdcon) = GPIO_bit(ssp_machinfo->cs_lcdcon);
125 ssp_write_word(&corgi_ssp_dev,data);
126 /* Read null data back from device to prevent SSP overflow */
127 ssp_read_word(&corgi_ssp_dev, &tmp);
128 if (ssp_machinfo->cs_lcdcon >= 0)
129 GPSR(ssp_machinfo->cs_lcdcon) = GPIO_bit(ssp_machinfo->cs_lcdcon);
131 ssp_disable(&corgi_ssp_dev);
132 ssp_config(&corgi_ssp_dev, (SSCR0_National | (SSCR0_DSS & 0x0b )), 0, 0, SSCR0_SerClkDiv(ssp_machinfo->clk_ads7846));
133 ssp_enable(&corgi_ssp_dev);
135 spin_unlock_irqrestore(&corgi_ssp_lock, flag);
137 return 0;
140 void corgi_ssp_lcdtg_send(u8 adrs, u8 data)
142 corgi_ssp_dac_put(((adrs & 0x07) << 5) | (data & 0x1f));
145 void corgi_ssp_blduty_set(int duty)
147 corgi_ssp_lcdtg_send(0x02,duty);
150 EXPORT_SYMBOL(corgi_ssp_lcdtg_send);
151 EXPORT_SYMBOL(corgi_ssp_blduty_set);
154 * Max1111 Routines
156 int corgi_ssp_max1111_get(ulong data)
158 unsigned long flag;
159 long voltage = 0, voltage1 = 0, voltage2 = 0;
161 spin_lock_irqsave(&corgi_ssp_lock, flag);
162 if (ssp_machinfo->cs_max1111 >= 0)
163 GPCR(ssp_machinfo->cs_max1111) = GPIO_bit(ssp_machinfo->cs_max1111);
164 ssp_disable(&corgi_ssp_dev);
165 ssp_config(&corgi_ssp_dev, (SSCR0_Motorola | (SSCR0_DSS & 0x07 )), 0, 0, SSCR0_SerClkDiv(ssp_machinfo->clk_max1111));
166 ssp_enable(&corgi_ssp_dev);
168 udelay(1);
170 /* TB1/RB1 */
171 ssp_write_word(&corgi_ssp_dev,data);
172 ssp_read_word(&corgi_ssp_dev, (u32*)&voltage1); /* null read */
174 /* TB12/RB2 */
175 ssp_write_word(&corgi_ssp_dev,0);
176 ssp_read_word(&corgi_ssp_dev, (u32*)&voltage1);
178 /* TB13/RB3*/
179 ssp_write_word(&corgi_ssp_dev,0);
180 ssp_read_word(&corgi_ssp_dev, (u32*)&voltage2);
182 ssp_disable(&corgi_ssp_dev);
183 ssp_config(&corgi_ssp_dev, (SSCR0_National | (SSCR0_DSS & 0x0b )), 0, 0, SSCR0_SerClkDiv(ssp_machinfo->clk_ads7846));
184 ssp_enable(&corgi_ssp_dev);
185 if (ssp_machinfo->cs_max1111 >= 0)
186 GPSR(ssp_machinfo->cs_max1111) = GPIO_bit(ssp_machinfo->cs_max1111);
187 spin_unlock_irqrestore(&corgi_ssp_lock, flag);
189 if (voltage1 & 0xc0 || voltage2 & 0x3f)
190 voltage = -1;
191 else
192 voltage = ((voltage1 << 2) & 0xfc) | ((voltage2 >> 6) & 0x03);
194 return voltage;
197 EXPORT_SYMBOL(corgi_ssp_max1111_get);
200 * Support Routines
203 void __init corgi_ssp_set_machinfo(struct corgissp_machinfo *machinfo)
205 ssp_machinfo = machinfo;
208 static int __init corgi_ssp_probe(struct platform_device *dev)
210 int ret;
212 /* Chip Select - Disable All */
213 if (ssp_machinfo->cs_lcdcon >= 0)
214 pxa_gpio_mode(ssp_machinfo->cs_lcdcon | GPIO_OUT | GPIO_DFLT_HIGH);
215 if (ssp_machinfo->cs_max1111 >= 0)
216 pxa_gpio_mode(ssp_machinfo->cs_max1111 | GPIO_OUT | GPIO_DFLT_HIGH);
217 if (ssp_machinfo->cs_ads7846 >= 0)
218 pxa_gpio_mode(ssp_machinfo->cs_ads7846 | GPIO_OUT | GPIO_DFLT_HIGH);
220 ret = ssp_init(&corgi_ssp_dev, ssp_machinfo->port, 0);
222 if (ret)
223 printk(KERN_ERR "Unable to register SSP handler!\n");
224 else {
225 ssp_disable(&corgi_ssp_dev);
226 ssp_config(&corgi_ssp_dev, (SSCR0_National | (SSCR0_DSS & 0x0b )), 0, 0, SSCR0_SerClkDiv(ssp_machinfo->clk_ads7846));
227 ssp_enable(&corgi_ssp_dev);
230 return ret;
233 static int corgi_ssp_remove(struct platform_device *dev)
235 ssp_exit(&corgi_ssp_dev);
236 return 0;
239 static int corgi_ssp_suspend(struct platform_device *dev, pm_message_t state)
241 ssp_flush(&corgi_ssp_dev);
242 ssp_save_state(&corgi_ssp_dev,&corgi_ssp_state);
244 return 0;
247 static int corgi_ssp_resume(struct platform_device *dev)
249 if (ssp_machinfo->cs_lcdcon >= 0)
250 GPSR(ssp_machinfo->cs_lcdcon) = GPIO_bit(ssp_machinfo->cs_lcdcon); /* High - Disable LCD Control/Timing Gen */
251 if (ssp_machinfo->cs_max1111 >= 0)
252 GPSR(ssp_machinfo->cs_max1111) = GPIO_bit(ssp_machinfo->cs_max1111); /* High - Disable MAX1111*/
253 if (ssp_machinfo->cs_ads7846 >= 0)
254 GPSR(ssp_machinfo->cs_ads7846) = GPIO_bit(ssp_machinfo->cs_ads7846); /* High - Disable ADS7846*/
255 ssp_restore_state(&corgi_ssp_dev,&corgi_ssp_state);
256 ssp_enable(&corgi_ssp_dev);
258 return 0;
261 static struct platform_driver corgissp_driver = {
262 .probe = corgi_ssp_probe,
263 .remove = corgi_ssp_remove,
264 .suspend = corgi_ssp_suspend,
265 .resume = corgi_ssp_resume,
266 .driver = {
267 .name = "corgi-ssp",
271 int __init corgi_ssp_init(void)
273 return platform_driver_register(&corgissp_driver);
276 arch_initcall(corgi_ssp_init);