1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2008 by Mark Arigo
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
31 /* Driver for the Synaptics Touchpad based on the "Synaptics Modular Embedded
32 Protocol: 3-Wire Interface Specification" documentation */
34 #if defined(MROBE_100)
35 #define INT_ENABLE GPIOD_INT_LEV &= ~0x2; GPIOD_INT_EN |= 0x2
36 #define INT_DISABLE GPIOD_INT_EN &= ~0x2; GPIOD_INT_CLR |= 0x2
38 #define ACK (GPIOD_INPUT_VAL & 0x1)
39 #define ACK_HI GPIOD_OUTPUT_VAL |= 0x1
40 #define ACK_LO GPIOD_OUTPUT_VAL &= ~0x1
42 #define CLK ((GPIOD_INPUT_VAL & 0x2) >> 1)
43 #define CLK_HI GPIOD_OUTPUT_VAL |= 0x2
44 #define CLK_LO GPIOD_OUTPUT_VAL &= ~0x2
46 #define DATA ((GPIOD_INPUT_VAL & 0x4) >> 2)
47 #define DATA_HI GPIOD_OUTPUT_EN |= 0x4; GPIOD_OUTPUT_VAL |= 0x4
48 #define DATA_LO GPIOD_OUTPUT_EN |= 0x4; GPIOD_OUTPUT_VAL &= ~0x4
49 #define DATA_CL GPIOD_OUTPUT_EN &= ~0x4
51 #elif defined(PHILIPS_HDD1630)
52 #define INT_ENABLE GPIOA_INT_LEV &= ~0x20; GPIOA_INT_EN |= 0x20
53 #define INT_DISABLE GPIOA_INT_EN &= ~0x20; GPIOA_INT_CLR |= 0x20
55 #define ACK (GPIOD_INPUT_VAL & 0x80)
56 #define ACK_HI GPIOD_OUTPUT_VAL |= 0x80
57 #define ACK_LO GPIOD_OUTPUT_VAL &= ~0x80
59 #define CLK ((GPIOA_INPUT_VAL & 0x20) >> 5)
60 #define CLK_HI GPIOA_OUTPUT_VAL |= 0x20
61 #define CLK_LO GPIOA_OUTPUT_VAL &= ~0x20
63 #define DATA ((GPIOA_INPUT_VAL & 0x10) >> 4)
64 #define DATA_HI GPIOA_OUTPUT_EN |= 0x10; GPIOA_OUTPUT_VAL |= 0x10
65 #define DATA_LO GPIOA_OUTPUT_EN |= 0x10; GPIOA_OUTPUT_VAL &= ~0x10
66 #define DATA_CL GPIOA_OUTPUT_EN &= ~0x10
75 #define MEP_HELLO_HEADER 0x19
76 #define MEP_HELLO_ID 0x1
81 static unsigned short syn_status
= 0;
83 static int syn_wait_clk_change(unsigned int val
)
87 for (i
= 0; i
< 10000; i
++)
96 static inline int syn_get_data(void)
102 static void syn_wait_guest_flush(void)
104 /* Flush receiving (flushee) state:
105 handshake until DATA goes high during P3 stage */
108 ACK_HI
; /* P1 -> P2 */
109 syn_wait_clk_change(HI
); /* P2 -> P3 */
112 while (syn_get_data() == LO
)
114 ACK_HI
; /* P3 -> P0 */
115 syn_wait_clk_change(LO
); /* P0 -> P1 */
116 ACK_LO
; /* P1 -> P2 */
117 syn_wait_clk_change(HI
); /* P2 -> P3 */
120 /* Continue handshaking until back to P0 */
121 ACK_HI
; /* P3 -> P0 */
124 static void syn_flush(void)
128 logf("syn_flush...");
130 /* Flusher holds DATA low for at least 36 handshake cycles */
133 for (i
= 0; i
< 36; i
++)
135 syn_wait_clk_change(LO
); /* P0 -> P1 */
136 ACK_LO
; /* P1 -> P2 */
137 syn_wait_clk_change(HI
); /* P2 -> P3 */
138 ACK_HI
; /* P3 -> P0 */
141 /* Raise DATA in P1 stage */
142 syn_wait_clk_change(LO
); /* P0 -> P1 */
145 /* After a flush, the flushing device enters a flush-receiving (flushee)
147 syn_wait_guest_flush();
150 int syn_send(int *data
, int len
)
157 /* 1. Lower DATA line to issue a request-to-send to guest */
160 /* 2. Wait for guest to lower CLK */
161 syn_wait_clk_change(LO
);
163 /* 3. Lower ACK (with DATA still low) */
166 /* 4. Wait for guest to raise CLK */
167 syn_wait_clk_change(HI
);
170 for (i
= 0; i
< len
; i
++)
172 logf(" sending byte: %d", data
[i
]);
177 /* 5a. Drive data low if bit is 0, or high if bit is 1 */
178 if (data
[i
] & (1 << bit
))
189 /* 5b. Invert ACK to indicate that the data bit is ready */
192 /* 5c. Wait for guest to invert CLK */
193 syn_wait_clk_change(LO
);
195 /* Repeat for next bit */
196 if (data
[i
] & (1 << bit
))
209 syn_wait_clk_change(HI
);
213 /* 7. Transmission termination sequence: */
214 /* 7a. Host may put parity bit on DATA. Hosts that do not generate
215 parity should set DATA high. Parity is 1 if there's an odd
216 number of '1' bits, or 0 if there's an even number of '1' bits. */
226 logf(" send parity = %d", parity
);
228 /* 7b. Raise ACK to indicate that the optional parity bit is ready */
231 /* 7c. Guest lowers CLK */
232 syn_wait_clk_change(LO
);
234 /* 7d. Pull DATA high (if parity bit was 0) */
237 /* 7e. Lower ACK to indicate that the stop bit is ready */
240 /* 7f. Guest raises CLK */
241 syn_wait_clk_change(HI
);
243 /* 7g. If DATA is low, guest is flushing this transfer. Host should
244 enter the flushee state. */
245 if (syn_get_data() == LO
)
247 logf(" module flushing");
249 syn_wait_guest_flush();
253 /* 7h. Host raises ACK and the link enters the idle state */
259 static int syn_read_data(int *data
, int data_len
)
261 int i
, len
, bit
, parity
, tmp
;
264 logf("syn_read_data...");
266 /* 1. Guest drives CLK low */
270 /* 1a. If the host is willing to receive a packet it lowers ACK */
273 /* 2. Guest may issue a request-to-send by lowering DATA. If the
274 guest decides not to transmit a packet, it may abort the
275 transmission by not lowering DATA. */
277 /* 3. The guest raises CLK */
278 syn_wait_clk_change(HI
);
280 /* 4. If the guest is still driving DATA low, the transfer is commited
281 to occur. Otherwise, the transfer is aborted. In either case,
282 the host raises ACK. */
283 if (syn_get_data() == HI
)
295 /* 5. Read the incoming data packet */
311 /* 5b. Guset inverts CLK to indicate that data is ready */
312 syn_wait_clk_change(LO
);
314 /* 5d. Read the data bit from DATA */
315 if (syn_get_data() == HI
)
317 *data_ptr
|= (1 << bit
);
322 /* 5e. Invert ACK to indicate that data has been read */
325 /* Repeat for next bit */
326 syn_wait_clk_change(HI
);
328 if (syn_get_data() == HI
)
330 *data_ptr
|= (1 << bit
);
338 /* First byte is the packet header */
341 /* Format control (bit 3) should be 1 */
344 /* Packet length is bits 0:2 */
345 len
= *data_ptr
& 0x7;
346 logf(" packet length = %d", len
);
350 logf(" invalid format ctrl bit");
358 /* 7. Transmission termination cycle */
359 /* 7a. The guest generates a parity bit on DATA */
360 /* 7b. The host waits for guest to lower CLK */
361 syn_wait_clk_change(LO
);
363 /* 7c. The host verifies the parity bit is correct */
365 logf(" parity check: %d / %d", syn_get_data(), parity
);
367 /* TODO: parity error handling */
369 /* 7d. The host lowers ACK */
372 /* 7e. The host waits for the guest to raise CLK indicating
373 that the stop bit is ready */
374 syn_wait_clk_change(HI
);
376 /* 7f. The host reads DATA and verifies that it is 1 */
377 if (syn_get_data() == LO
)
379 logf(" framing error");
390 int syn_read(int *data
, int len
)
393 int ret
= READ_ERROR
;
395 for (i
= 0; i
< READ_RETRY
; i
++)
397 if (syn_wait_clk_change(LO
))
399 /* module is sending data */
400 ret
= syn_read_data(data
, len
);
401 if (ret
!= READ_ERROR
)
421 logf("syn_reset...");
424 val
= (0 << 4) | (1 << 3) | 0;
427 val
= syn_read(data
, 2);
430 val
= data
[0] & 0xff; /* packet header */
431 id
= (data
[1] >> 4) & 0xf; /* packet id */
432 if ((val
== MEP_HELLO_HEADER
) && (id
== MEP_HELLO_ID
))
434 logf(" module 0 reset");
439 logf(" reset failed");
446 syn_status
= syn_reset();
453 CPU_INT_EN
|= HI_MASK
;
454 CPU_HI_INT_EN
|= GPIO0_MASK
;
460 int syn_get_status(void)
465 void syn_int_enable(bool enable
)
477 #ifdef ROCKBOX_HAS_LOGF
485 /* module base info */
486 logf("module base info:");
490 val
= syn_read(data
, 8);
493 for (i
= 0; i
< 8; i
++)
494 logf(" data[%d] = 0x%02x", i
, data
[i
]);
497 /* module product info */
498 logf("module product info:");
502 val
= syn_read(data
, 8);
505 for (i
= 0; i
< 8; i
++)
506 logf(" data[%d] = 0x%02x", i
, data
[i
]);
509 /* module serialization */
510 logf("module serialization:");
514 val
= syn_read(data
, 8);
517 for (i
= 0; i
< 8; i
++)
518 logf(" data[%d] = 0x%02x", i
, data
[i
]);
521 /* 1-D sensor info */
522 logf("1-d sensor info:");
524 data
[1] = 0x80 + 0x20;
526 val
= syn_read(data
, 8);
529 for (i
= 0; i
< 8; i
++)
530 logf(" data[%d] = 0x%02x", i
, data
[i
]);