2 * arch/arm/mac-sa1100/jornada720_ssp.c
4 * Copyright (C) 2006/2007 Kristoffer Ericson <Kristoffer.Ericson@gmail.com>
5 * Copyright (C) 2006 Filip Zyzniewski <filip.zyzniewski@tefnet.pl>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * SSP driver for the HP Jornada 710/720/728
14 #include <linux/delay.h>
15 #include <linux/errno.h>
16 #include <linux/init.h>
17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/platform_device.h>
20 #include <linux/sched.h>
22 #include <mach/hardware.h>
23 #include <mach/jornada720.h>
24 #include <asm/hardware/ssp.h>
26 static DEFINE_SPINLOCK(jornada_ssp_lock
);
27 static unsigned long jornada_ssp_flags
;
30 * jornada_ssp_reverse - reverses input byte
32 * we need to reverse all data we receive from the mcu due to its physical location
33 * returns : 01110111 -> 11101110
35 u8
inline jornada_ssp_reverse(u8 byte
)
38 ((0x80 & byte
) >> 7) |
39 ((0x40 & byte
) >> 5) |
40 ((0x20 & byte
) >> 3) |
41 ((0x10 & byte
) >> 1) |
42 ((0x08 & byte
) << 1) |
43 ((0x04 & byte
) << 3) |
44 ((0x02 & byte
) << 5) |
47 EXPORT_SYMBOL(jornada_ssp_reverse
);
50 * jornada_ssp_byte - waits for ready ssp bus and sends byte
52 * waits for fifo buffer to clear and then transmits, if it doesn't then we will
53 * timeout after <timeout> rounds. Needs mcu running before its called.
55 * returns : %mcu output on success
56 * : %-ETIMEDOUT on timeout
58 int jornada_ssp_byte(u8 byte
)
63 while ((GPLR
& GPIO_GPIO10
)) {
65 printk(KERN_WARNING
"SSP: timeout while waiting for transmit\n");
71 ret
= jornada_ssp_reverse(byte
) << 8;
76 return jornada_ssp_reverse(ret
);
78 EXPORT_SYMBOL(jornada_ssp_byte
);
81 * jornada_ssp_inout - decide if input is command or trading byte
83 * returns : (jornada_ssp_byte(byte)) on success
84 * : %-ETIMEDOUT on timeout failure
86 int jornada_ssp_inout(u8 byte
)
90 /* true means command byte */
91 if (byte
!= TXDUMMY
) {
92 ret
= jornada_ssp_byte(byte
);
93 /* Proper return to commands is TxDummy */
95 for (i
= 0; i
< 256; i
++)/* flushing bus */
96 if (jornada_ssp_byte(TXDUMMY
) == -1)
100 } else /* Exchange TxDummy for data */
101 ret
= jornada_ssp_byte(TXDUMMY
);
105 EXPORT_SYMBOL(jornada_ssp_inout
);
108 * jornada_ssp_start - enable mcu
111 void jornada_ssp_start(void)
113 spin_lock_irqsave(&jornada_ssp_lock
, jornada_ssp_flags
);
118 EXPORT_SYMBOL(jornada_ssp_start
);
121 * jornada_ssp_end - disable mcu and turn off lock
124 void jornada_ssp_end(void)
127 spin_unlock_irqrestore(&jornada_ssp_lock
, jornada_ssp_flags
);
130 EXPORT_SYMBOL(jornada_ssp_end
);
132 static int __devinit
jornada_ssp_probe(struct platform_device
*dev
)
140 /* worked fine, lets not bother with anything else */
142 printk(KERN_INFO
"SSP: device initialized with irq\n");
146 printk(KERN_WARNING
"SSP: initialization failed, trying non-irq solution \n");
148 /* init of Serial 4 port */
153 /* clear out any left over data */
159 /* see if return value makes sense */
160 ret
= jornada_ssp_inout(GETBRIGHTNESS
);
162 /* seems like it worked, just feed it with TxDummy to get rid of data */
164 jornada_ssp_inout(TXDUMMY
);
168 /* failed, lets just kill everything */
169 if (ret
== -ETIMEDOUT
) {
170 printk(KERN_WARNING
"SSP: attempts failed, bailing\n");
176 printk(KERN_INFO
"SSP: device initialized\n");
180 static int jornada_ssp_remove(struct platform_device
*dev
)
182 /* Note that this doesn't actually remove the driver, since theres nothing to remove
183 * It just makes sure everything is turned off */
189 struct platform_driver jornadassp_driver
= {
190 .probe
= jornada_ssp_probe
,
191 .remove
= jornada_ssp_remove
,
193 .name
= "jornada_ssp",
197 static int __init
jornada_ssp_init(void)
199 return platform_driver_register(&jornadassp_driver
);
202 module_init(jornada_ssp_init
);