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>
24 #include <asm/arch/regs-ssp.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.
49 unsigned long corgi_ssp_ads7846_putget(ulong data
)
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
);
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)
94 ssp_read_word(&corgi_ssp_dev
, &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
;
113 spin_lock_irqsave(&corgi_ssp_lock
, flag
);
115 if (machine_is_spitz() || machine_is_akita() || machine_is_borzoi())
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
);
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
);
155 int corgi_ssp_max1111_get(ulong data
)
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
);
170 ssp_write_word(&corgi_ssp_dev
,data
);
171 ssp_read_word(&corgi_ssp_dev
, (u32
*)&voltage1
); /* null read */
174 ssp_write_word(&corgi_ssp_dev
,0);
175 ssp_read_word(&corgi_ssp_dev
, (u32
*)&voltage1
);
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)
191 voltage
= ((voltage1
<< 2) & 0xfc) | ((voltage2
>> 6) & 0x03);
196 EXPORT_SYMBOL(corgi_ssp_max1111_get
);
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
)
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);
222 printk(KERN_ERR
"Unable to register SSP handler!\n");
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
);
232 static int corgi_ssp_remove(struct platform_device
*dev
)
234 ssp_exit(&corgi_ssp_dev
);
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
);
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
);
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
,
270 int __init
corgi_ssp_init(void)
272 return platform_driver_register(&corgissp_driver
);
275 arch_initcall(corgi_ssp_init
);