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 <asm/hardware.h>
20 #include <asm/mach-types.h>
22 #include <asm/arch/ssp.h>
23 #include <asm/arch/pxa-regs.h>
26 static DEFINE_SPINLOCK(corgi_ssp_lock);
27 static struct ssp_dev corgi_ssp_dev;
28 static struct ssp_state corgi_ssp_state;
29 static struct corgissp_machinfo *ssp_machinfo;
32 * There are three devices connected to the SSP interface:
33 * 1. A touchscreen controller (TI ADS7846 compatible)
34 * 2. An LCD contoller (with some Backlight functionality)
35 * 3. A battery monitoring IC (Maxim MAX1111)
37 * Each device uses a different speed/mode of communication.
39 * The touchscreen is very sensitive and the most frequently used
40 * so the port is left configured for this.
42 * Devices are selected using Chip Selects on GPIOs.
48 unsigned long corgi_ssp_ads7846_putget(ulong data)
53 spin_lock_irqsave(&corgi_ssp_lock, flag);
54 if (ssp_machinfo->cs_ads7846 >= 0)
55 GPCR(ssp_machinfo->cs_ads7846) = GPIO_bit(ssp_machinfo->cs_ads7846);
57 ssp_write_word(&corgi_ssp_dev,data);
58 ssp_read_word(&corgi_ssp_dev, &ret);
60 if (ssp_machinfo->cs_ads7846 >= 0)
61 GPSR(ssp_machinfo->cs_ads7846) = GPIO_bit(ssp_machinfo->cs_ads7846);
62 spin_unlock_irqrestore(&corgi_ssp_lock, flag);
68 * NOTE: These functions should always be called in interrupt context
69 * and use the _lock and _unlock functions. They are very time sensitive.
71 void corgi_ssp_ads7846_lock(void)
73 spin_lock(&corgi_ssp_lock);
74 if (ssp_machinfo->cs_ads7846 >= 0)
75 GPCR(ssp_machinfo->cs_ads7846) = GPIO_bit(ssp_machinfo->cs_ads7846);
78 void corgi_ssp_ads7846_unlock(void)
80 if (ssp_machinfo->cs_ads7846 >= 0)
81 GPSR(ssp_machinfo->cs_ads7846) = GPIO_bit(ssp_machinfo->cs_ads7846);
82 spin_unlock(&corgi_ssp_lock);
85 void corgi_ssp_ads7846_put(ulong data)
87 ssp_write_word(&corgi_ssp_dev,data);
90 unsigned long corgi_ssp_ads7846_get(void)
93 ssp_read_word(&corgi_ssp_dev, &ret);
97 EXPORT_SYMBOL(corgi_ssp_ads7846_putget);
98 EXPORT_SYMBOL(corgi_ssp_ads7846_lock);
99 EXPORT_SYMBOL(corgi_ssp_ads7846_unlock);
100 EXPORT_SYMBOL(corgi_ssp_ads7846_put);
101 EXPORT_SYMBOL(corgi_ssp_ads7846_get);
105 * LCD/Backlight Routines
107 unsigned long corgi_ssp_dac_put(ulong data)
109 unsigned long flag, sscr1 = SSCR1_SPH;
112 spin_lock_irqsave(&corgi_ssp_lock, flag);
114 if (machine_is_spitz() || machine_is_akita() || machine_is_borzoi())
117 ssp_disable(&corgi_ssp_dev);
118 ssp_config(&corgi_ssp_dev, (SSCR0_Motorola | (SSCR0_DSS & 0x07 )), sscr1, 0, SSCR0_SerClkDiv(ssp_machinfo->clk_lcdcon));
119 ssp_enable(&corgi_ssp_dev);
121 if (ssp_machinfo->cs_lcdcon >= 0)
122 GPCR(ssp_machinfo->cs_lcdcon) = GPIO_bit(ssp_machinfo->cs_lcdcon);
123 ssp_write_word(&corgi_ssp_dev,data);
124 /* Read null data back from device to prevent SSP overflow */
125 ssp_read_word(&corgi_ssp_dev, &tmp);
126 if (ssp_machinfo->cs_lcdcon >= 0)
127 GPSR(ssp_machinfo->cs_lcdcon) = GPIO_bit(ssp_machinfo->cs_lcdcon);
129 ssp_disable(&corgi_ssp_dev);
130 ssp_config(&corgi_ssp_dev, (SSCR0_National | (SSCR0_DSS & 0x0b )), 0, 0, SSCR0_SerClkDiv(ssp_machinfo->clk_ads7846));
131 ssp_enable(&corgi_ssp_dev);
133 spin_unlock_irqrestore(&corgi_ssp_lock, flag);
138 void corgi_ssp_lcdtg_send(u8 adrs, u8 data)
140 corgi_ssp_dac_put(((adrs & 0x07) << 5) | (data & 0x1f));
143 void corgi_ssp_blduty_set(int duty)
145 corgi_ssp_lcdtg_send(0x02,duty);
148 EXPORT_SYMBOL(corgi_ssp_lcdtg_send);
149 EXPORT_SYMBOL(corgi_ssp_blduty_set);
154 int corgi_ssp_max1111_get(ulong data)
157 long voltage = 0, voltage1 = 0, voltage2 = 0;
159 spin_lock_irqsave(&corgi_ssp_lock, flag);
160 if (ssp_machinfo->cs_max1111 >= 0)
161 GPCR(ssp_machinfo->cs_max1111) = GPIO_bit(ssp_machinfo->cs_max1111);
162 ssp_disable(&corgi_ssp_dev);
163 ssp_config(&corgi_ssp_dev, (SSCR0_Motorola | (SSCR0_DSS & 0x07 )), 0, 0, SSCR0_SerClkDiv(ssp_machinfo->clk_max1111));
164 ssp_enable(&corgi_ssp_dev);
169 ssp_write_word(&corgi_ssp_dev,data);
170 ssp_read_word(&corgi_ssp_dev, (u32*)&voltage1); /* null read */
173 ssp_write_word(&corgi_ssp_dev,0);
174 ssp_read_word(&corgi_ssp_dev, (u32*)&voltage1);
177 ssp_write_word(&corgi_ssp_dev,0);
178 ssp_read_word(&corgi_ssp_dev, (u32*)&voltage2);
180 ssp_disable(&corgi_ssp_dev);
181 ssp_config(&corgi_ssp_dev, (SSCR0_National | (SSCR0_DSS & 0x0b )), 0, 0, SSCR0_SerClkDiv(ssp_machinfo->clk_ads7846));
182 ssp_enable(&corgi_ssp_dev);
183 if (ssp_machinfo->cs_max1111 >= 0)
184 GPSR(ssp_machinfo->cs_max1111) = GPIO_bit(ssp_machinfo->cs_max1111);
185 spin_unlock_irqrestore(&corgi_ssp_lock, flag);
187 if (voltage1 & 0xc0 || voltage2 & 0x3f)
190 voltage = ((voltage1 << 2) & 0xfc) | ((voltage2 >> 6) & 0x03);
195 EXPORT_SYMBOL(corgi_ssp_max1111_get);
201 void __init corgi_ssp_set_machinfo(struct corgissp_machinfo *machinfo)
203 ssp_machinfo = machinfo;
206 static int __init corgi_ssp_probe(struct platform_device *dev)
210 /* Chip Select - Disable All */
211 if (ssp_machinfo->cs_lcdcon >= 0)
212 pxa_gpio_mode(ssp_machinfo->cs_lcdcon | GPIO_OUT | GPIO_DFLT_HIGH);
213 if (ssp_machinfo->cs_max1111 >= 0)
214 pxa_gpio_mode(ssp_machinfo->cs_max1111 | GPIO_OUT | GPIO_DFLT_HIGH);
215 if (ssp_machinfo->cs_ads7846 >= 0)
216 pxa_gpio_mode(ssp_machinfo->cs_ads7846 | GPIO_OUT | GPIO_DFLT_HIGH);
218 ret = ssp_init(&corgi_ssp_dev, ssp_machinfo->port, 0);
221 printk(KERN_ERR "Unable to register SSP handler!\n");
223 ssp_disable(&corgi_ssp_dev);
224 ssp_config(&corgi_ssp_dev, (SSCR0_National | (SSCR0_DSS & 0x0b )), 0, 0, SSCR0_SerClkDiv(ssp_machinfo->clk_ads7846));
225 ssp_enable(&corgi_ssp_dev);
231 static int corgi_ssp_remove(struct platform_device *dev)
233 ssp_exit(&corgi_ssp_dev);
237 static int corgi_ssp_suspend(struct platform_device *dev, pm_message_t state)
239 ssp_flush(&corgi_ssp_dev);
240 ssp_save_state(&corgi_ssp_dev,&corgi_ssp_state);
245 static int corgi_ssp_resume(struct platform_device *dev)
247 if (ssp_machinfo->cs_lcdcon >= 0)
248 GPSR(ssp_machinfo->cs_lcdcon) = GPIO_bit(ssp_machinfo->cs_lcdcon); /* High - Disable LCD Control/Timing Gen */
249 if (ssp_machinfo->cs_max1111 >= 0)
250 GPSR(ssp_machinfo->cs_max1111) = GPIO_bit(ssp_machinfo->cs_max1111); /* High - Disable MAX1111*/
251 if (ssp_machinfo->cs_ads7846 >= 0)
252 GPSR(ssp_machinfo->cs_ads7846) = GPIO_bit(ssp_machinfo->cs_ads7846); /* High - Disable ADS7846*/
253 ssp_restore_state(&corgi_ssp_dev,&corgi_ssp_state);
254 ssp_enable(&corgi_ssp_dev);
259 static struct platform_driver corgissp_driver = {
260 .probe = corgi_ssp_probe,
261 .remove = corgi_ssp_remove,
262 .suspend = corgi_ssp_suspend,
263 .resume = corgi_ssp_resume,
269 int __init corgi_ssp_init(void)
271 return platform_driver_register(&corgissp_driver);
274 arch_initcall(corgi_ssp_init);