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 moinitoring 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)
50 unsigned long ret,flag;
52 spin_lock_irqsave(&corgi_ssp_lock, flag);
53 GPCR(ssp_machinfo->cs_ads7846) = GPIO_bit(ssp_machinfo->cs_ads7846);
55 ssp_write_word(&corgi_ssp_dev,data);
56 ret = ssp_read_word(&corgi_ssp_dev);
58 GPSR(ssp_machinfo->cs_ads7846) = GPIO_bit(ssp_machinfo->cs_ads7846);
59 spin_unlock_irqrestore(&corgi_ssp_lock, flag);
65 * NOTE: These functions should always be called in interrupt context
66 * and use the _lock and _unlock functions. They are very time sensitive.
68 void corgi_ssp_ads7846_lock(void)
70 spin_lock(&corgi_ssp_lock);
71 GPCR(ssp_machinfo->cs_ads7846) = GPIO_bit(ssp_machinfo->cs_ads7846);
74 void corgi_ssp_ads7846_unlock(void)
76 GPSR(ssp_machinfo->cs_ads7846) = GPIO_bit(ssp_machinfo->cs_ads7846);
77 spin_unlock(&corgi_ssp_lock);
80 void corgi_ssp_ads7846_put(ulong data)
82 ssp_write_word(&corgi_ssp_dev,data);
85 unsigned long corgi_ssp_ads7846_get(void)
87 return ssp_read_word(&corgi_ssp_dev);
90 EXPORT_SYMBOL(corgi_ssp_ads7846_putget);
91 EXPORT_SYMBOL(corgi_ssp_ads7846_lock);
92 EXPORT_SYMBOL(corgi_ssp_ads7846_unlock);
93 EXPORT_SYMBOL(corgi_ssp_ads7846_put);
94 EXPORT_SYMBOL(corgi_ssp_ads7846_get);
98 * LCD/Backlight Routines
100 unsigned long corgi_ssp_dac_put(ulong data)
102 unsigned long flag, sscr1 = SSCR1_SPH;
104 spin_lock_irqsave(&corgi_ssp_lock, flag);
106 if (machine_is_spitz() || machine_is_akita() || machine_is_borzoi())
109 ssp_disable(&corgi_ssp_dev);
110 ssp_config(&corgi_ssp_dev, (SSCR0_Motorola | (SSCR0_DSS & 0x07 )), sscr1, 0, SSCR0_SerClkDiv(ssp_machinfo->clk_lcdcon));
111 ssp_enable(&corgi_ssp_dev);
113 GPCR(ssp_machinfo->cs_lcdcon) = GPIO_bit(ssp_machinfo->cs_lcdcon);
114 ssp_write_word(&corgi_ssp_dev,data);
115 /* Read null data back from device to prevent SSP overflow */
116 ssp_read_word(&corgi_ssp_dev);
117 GPSR(ssp_machinfo->cs_lcdcon) = GPIO_bit(ssp_machinfo->cs_lcdcon);
119 ssp_disable(&corgi_ssp_dev);
120 ssp_config(&corgi_ssp_dev, (SSCR0_National | (SSCR0_DSS & 0x0b )), 0, 0, SSCR0_SerClkDiv(ssp_machinfo->clk_ads7846));
121 ssp_enable(&corgi_ssp_dev);
123 spin_unlock_irqrestore(&corgi_ssp_lock, flag);
128 void corgi_ssp_lcdtg_send(u8 adrs, u8 data)
130 corgi_ssp_dac_put(((adrs & 0x07) << 5) | (data & 0x1f));
133 void corgi_ssp_blduty_set(int duty)
135 corgi_ssp_lcdtg_send(0x02,duty);
138 EXPORT_SYMBOL(corgi_ssp_lcdtg_send);
139 EXPORT_SYMBOL(corgi_ssp_blduty_set);
144 int corgi_ssp_max1111_get(ulong data)
147 int voltage,voltage1,voltage2;
149 spin_lock_irqsave(&corgi_ssp_lock, flag);
150 GPCR(ssp_machinfo->cs_max1111) = GPIO_bit(ssp_machinfo->cs_max1111);
151 ssp_disable(&corgi_ssp_dev);
152 ssp_config(&corgi_ssp_dev, (SSCR0_Motorola | (SSCR0_DSS & 0x07 )), 0, 0, SSCR0_SerClkDiv(ssp_machinfo->clk_max1111));
153 ssp_enable(&corgi_ssp_dev);
158 ssp_write_word(&corgi_ssp_dev,data);
159 ssp_read_word(&corgi_ssp_dev); /* null read */
162 ssp_write_word(&corgi_ssp_dev,0);
163 voltage1=ssp_read_word(&corgi_ssp_dev);
166 ssp_write_word(&corgi_ssp_dev,0);
167 voltage2=ssp_read_word(&corgi_ssp_dev);
169 ssp_disable(&corgi_ssp_dev);
170 ssp_config(&corgi_ssp_dev, (SSCR0_National | (SSCR0_DSS & 0x0b )), 0, 0, SSCR0_SerClkDiv(ssp_machinfo->clk_ads7846));
171 ssp_enable(&corgi_ssp_dev);
172 GPSR(ssp_machinfo->cs_max1111) = GPIO_bit(ssp_machinfo->cs_max1111);
173 spin_unlock_irqrestore(&corgi_ssp_lock, flag);
175 if (voltage1 & 0xc0 || voltage2 & 0x3f)
178 voltage = ((voltage1 << 2) & 0xfc) | ((voltage2 >> 6) & 0x03);
183 EXPORT_SYMBOL(corgi_ssp_max1111_get);
189 void __init corgi_ssp_set_machinfo(struct corgissp_machinfo *machinfo)
191 ssp_machinfo = machinfo;
194 static int __init corgi_ssp_probe(struct platform_device *dev)
198 /* Chip Select - Disable All */
199 GPDR(ssp_machinfo->cs_lcdcon) |= GPIO_bit(ssp_machinfo->cs_lcdcon); /* output */
200 GPSR(ssp_machinfo->cs_lcdcon) = GPIO_bit(ssp_machinfo->cs_lcdcon); /* High - Disable LCD Control/Timing Gen */
201 GPDR(ssp_machinfo->cs_max1111) |= GPIO_bit(ssp_machinfo->cs_max1111); /* output */
202 GPSR(ssp_machinfo->cs_max1111) = GPIO_bit(ssp_machinfo->cs_max1111); /* High - Disable MAX1111*/
203 GPDR(ssp_machinfo->cs_ads7846) |= GPIO_bit(ssp_machinfo->cs_ads7846); /* output */
204 GPSR(ssp_machinfo->cs_ads7846) = GPIO_bit(ssp_machinfo->cs_ads7846); /* High - Disable ADS7846*/
206 ret = ssp_init(&corgi_ssp_dev, ssp_machinfo->port, 0);
209 printk(KERN_ERR "Unable to register SSP handler!\n");
211 ssp_disable(&corgi_ssp_dev);
212 ssp_config(&corgi_ssp_dev, (SSCR0_National | (SSCR0_DSS & 0x0b )), 0, 0, SSCR0_SerClkDiv(ssp_machinfo->clk_ads7846));
213 ssp_enable(&corgi_ssp_dev);
219 static int corgi_ssp_remove(struct platform_device *dev)
221 ssp_exit(&corgi_ssp_dev);
225 static int corgi_ssp_suspend(struct platform_device *dev, pm_message_t state)
227 ssp_flush(&corgi_ssp_dev);
228 ssp_save_state(&corgi_ssp_dev,&corgi_ssp_state);
233 static int corgi_ssp_resume(struct platform_device *dev)
235 GPSR(ssp_machinfo->cs_lcdcon) = GPIO_bit(ssp_machinfo->cs_lcdcon); /* High - Disable LCD Control/Timing Gen */
236 GPSR(ssp_machinfo->cs_max1111) = GPIO_bit(ssp_machinfo->cs_max1111); /* High - Disable MAX1111*/
237 GPSR(ssp_machinfo->cs_ads7846) = GPIO_bit(ssp_machinfo->cs_ads7846); /* High - Disable ADS7846*/
238 ssp_restore_state(&corgi_ssp_dev,&corgi_ssp_state);
239 ssp_enable(&corgi_ssp_dev);
244 static struct platform_driver corgissp_driver = {
245 .probe = corgi_ssp_probe,
246 .remove = corgi_ssp_remove,
247 .suspend = corgi_ssp_suspend,
248 .resume = corgi_ssp_resume,
254 int __init corgi_ssp_init(void)
256 return platform_driver_register(&corgissp_driver);
259 arch_initcall(corgi_ssp_init);