2008-12-17 04:38:53 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 by Mark Arigo
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "config.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "kernel.h"
|
2009-06-19 02:48:15 +00:00
|
|
|
#include "button-target.h"
|
2008-12-17 04:38:53 +00:00
|
|
|
|
2009-11-03 16:25:03 +00:00
|
|
|
/*#define LOGF_ENABLE*/
|
2008-12-17 04:38:53 +00:00
|
|
|
#include "logf.h"
|
|
|
|
|
|
|
|
/* Driver for the Synaptics Touchpad based on the "Synaptics Modular Embedded
|
|
|
|
Protocol: 3-Wire Interface Specification" documentation */
|
|
|
|
|
2008-12-19 03:31:26 +00:00
|
|
|
#if defined(MROBE_100)
|
2009-06-19 02:48:15 +00:00
|
|
|
#define INT_ENABLE GPIO_CLEAR_BITWISE(GPIOD_INT_LEV, 0x2);\
|
|
|
|
GPIO_SET_BITWISE(GPIOD_INT_EN, 0x2)
|
|
|
|
#define INT_DISABLE GPIO_CLEAR_BITWISE(GPIOD_INT_EN, 0x2);\
|
|
|
|
GPIO_SET_BITWISE(GPIOD_INT_CLR, 0x2)
|
2009-02-18 02:19:22 +00:00
|
|
|
|
2008-12-17 04:38:53 +00:00
|
|
|
#define ACK (GPIOD_INPUT_VAL & 0x1)
|
2009-06-19 02:48:15 +00:00
|
|
|
#define ACK_HI GPIO_SET_BITWISE(GPIOD_OUTPUT_VAL, 0x1)
|
|
|
|
#define ACK_LO GPIO_CLEAR_BITWISE(GPIOD_OUTPUT_VAL, 0x1)
|
2008-12-17 04:38:53 +00:00
|
|
|
|
|
|
|
#define CLK ((GPIOD_INPUT_VAL & 0x2) >> 1)
|
2009-06-19 02:48:15 +00:00
|
|
|
#define CLK_HI GPIO_SET_BITWISE(GPIOD_OUTPUT_VAL, 0x2)
|
|
|
|
#define CLK_LO GPIO_CLEAR_BITWISE(GPIOD_OUTPUT_VAL, 0x2)
|
2008-12-17 04:38:53 +00:00
|
|
|
|
|
|
|
#define DATA ((GPIOD_INPUT_VAL & 0x4) >> 2)
|
2009-06-19 02:48:15 +00:00
|
|
|
#define DATA_HI GPIO_SET_BITWISE(GPIOD_OUTPUT_EN, 0x4);\
|
|
|
|
GPIO_SET_BITWISE(GPIOD_OUTPUT_VAL, 0x4)
|
|
|
|
#define DATA_LO GPIO_SET_BITWISE(GPIOD_OUTPUT_EN, 0x4);\
|
|
|
|
GPIO_CLEAR_BITWISE(GPIOD_OUTPUT_VAL, 0x4)
|
|
|
|
#define DATA_CL GPIO_CLEAR_BITWISE(GPIOD_OUTPUT_EN, 0x4)
|
2008-12-17 04:38:53 +00:00
|
|
|
|
2009-12-25 04:05:01 +00:00
|
|
|
#elif defined(PHILIPS_HDD1630) || defined(PHILIPS_HDD6330)
|
2009-06-19 02:48:15 +00:00
|
|
|
#define INT_ENABLE GPIO_CLEAR_BITWISE(GPIOA_INT_LEV, 0x20);\
|
|
|
|
GPIO_SET_BITWISE(GPIOA_INT_EN, 0x20)
|
|
|
|
#define INT_DISABLE GPIO_CLEAR_BITWISE(GPIOA_INT_EN, 0x20);\
|
|
|
|
GPIO_SET_BITWISE(GPIOA_INT_CLR, 0x20)
|
2009-02-18 02:19:22 +00:00
|
|
|
|
2008-12-19 03:31:26 +00:00
|
|
|
#define ACK (GPIOD_INPUT_VAL & 0x80)
|
2009-06-19 02:48:15 +00:00
|
|
|
#define ACK_HI GPIO_SET_BITWISE(GPIOD_OUTPUT_VAL, 0x80)
|
|
|
|
#define ACK_LO GPIO_CLEAR_BITWISE(GPIOD_OUTPUT_VAL, 0x80)
|
2008-12-19 03:31:26 +00:00
|
|
|
|
|
|
|
#define CLK ((GPIOA_INPUT_VAL & 0x20) >> 5)
|
2009-06-19 02:48:15 +00:00
|
|
|
#define CLK_HI GPIO_SET_BITWISE(GPIOA_OUTPUT_VAL, 0x20)
|
|
|
|
#define CLK_LO GPIO_CLEAR_BITWISE(GPIOA_OUTPUT_VAL, 0x20)
|
2008-12-19 03:31:26 +00:00
|
|
|
|
|
|
|
#define DATA ((GPIOA_INPUT_VAL & 0x10) >> 4)
|
2009-06-19 02:48:15 +00:00
|
|
|
#define DATA_HI GPIO_SET_BITWISE(GPIOA_OUTPUT_EN, 0x10);\
|
|
|
|
GPIO_SET_BITWISE(GPIOA_OUTPUT_VAL, 0x10)
|
|
|
|
#define DATA_LO GPIO_SET_BITWISE(GPIOA_OUTPUT_EN, 0x10);\
|
|
|
|
GPIO_CLEAR_BITWISE(GPIOA_OUTPUT_VAL, 0x10)
|
|
|
|
#define DATA_CL GPIO_CLEAR_BITWISE(GPIOA_OUTPUT_EN, 0x10)
|
2009-06-19 03:23:38 +00:00
|
|
|
|
|
|
|
#elif defined(PHILIPS_SA9200)
|
|
|
|
#define INT_ENABLE GPIO_CLEAR_BITWISE(GPIOD_INT_LEV, 0x2);\
|
|
|
|
GPIO_SET_BITWISE(GPIOD_INT_EN, 0x2)
|
|
|
|
#define INT_DISABLE GPIO_CLEAR_BITWISE(GPIOD_INT_EN, 0x2);\
|
|
|
|
GPIO_SET_BITWISE(GPIOD_INT_CLR, 0x2)
|
|
|
|
|
|
|
|
#define ACK (GPIOD_INPUT_VAL & 0x8)
|
|
|
|
#define ACK_HI GPIO_SET_BITWISE(GPIOD_OUTPUT_VAL, 0x8)
|
|
|
|
#define ACK_LO GPIO_CLEAR_BITWISE(GPIOD_OUTPUT_VAL, 0x8)
|
|
|
|
|
|
|
|
#define CLK ((GPIOD_INPUT_VAL & 0x2) >> 1)
|
|
|
|
#define CLK_HI GPIO_SET_BITWISE(GPIOD_OUTPUT_VAL, 0x2)
|
|
|
|
#define CLK_LO GPIO_CLEAR_BITWISE(GPIOD_OUTPUT_VAL, 0x2)
|
|
|
|
|
|
|
|
#define DATA ((GPIOD_INPUT_VAL & 0x10) >> 4)
|
|
|
|
#define DATA_HI GPIO_CLEAR_BITWISE(GPIOD_OUTPUT_EN, 0x10)
|
|
|
|
#define DATA_LO GPIO_CLEAR_BITWISE(GPIOD_OUTPUT_VAL, 0x10);\
|
|
|
|
GPIO_SET_BITWISE(GPIOD_OUTPUT_EN, 0x10)
|
|
|
|
#define DATA_CL GPIO_CLEAR_BITWISE(GPIOD_OUTPUT_EN, 0x10)
|
2008-12-19 03:31:26 +00:00
|
|
|
#endif
|
|
|
|
|
2008-12-17 04:38:53 +00:00
|
|
|
#define LO 0
|
|
|
|
#define HI 1
|
|
|
|
|
|
|
|
#define READ_RETRY 8
|
|
|
|
#define READ_ERROR -1
|
|
|
|
|
|
|
|
#define MEP_HELLO_HEADER 0x19
|
|
|
|
#define MEP_HELLO_ID 0x1
|
|
|
|
|
|
|
|
#define MEP_READ 0x1
|
|
|
|
#define MEP_WRITE 0x3
|
|
|
|
|
2009-02-18 02:19:22 +00:00
|
|
|
static unsigned short syn_status = 0;
|
|
|
|
|
2009-06-19 02:48:15 +00:00
|
|
|
static void syn_enable_int(bool enable)
|
|
|
|
{
|
|
|
|
if (enable)
|
|
|
|
{
|
|
|
|
INT_ENABLE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
INT_DISABLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-17 04:38:53 +00:00
|
|
|
static int syn_wait_clk_change(unsigned int val)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 10000; i++)
|
|
|
|
{
|
|
|
|
if (CLK == val)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-19 02:48:15 +00:00
|
|
|
static void syn_set_ack(int val)
|
|
|
|
{
|
|
|
|
if (val == HI)
|
|
|
|
{
|
|
|
|
ACK_HI;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ACK_LO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void syn_set_data(int val)
|
|
|
|
{
|
|
|
|
if (val == HI)
|
|
|
|
{
|
|
|
|
DATA_HI;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DATA_LO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-17 04:38:53 +00:00
|
|
|
static inline int syn_get_data(void)
|
|
|
|
{
|
|
|
|
DATA_CL;
|
|
|
|
return DATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void syn_wait_guest_flush(void)
|
|
|
|
{
|
|
|
|
/* Flush receiving (flushee) state:
|
|
|
|
handshake until DATA goes high during P3 stage */
|
|
|
|
if (CLK == LO)
|
|
|
|
{
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_ack(HI); /* P1 -> P2 */
|
2008-12-17 04:38:53 +00:00
|
|
|
syn_wait_clk_change(HI); /* P2 -> P3 */
|
|
|
|
}
|
|
|
|
|
|
|
|
while (syn_get_data() == LO)
|
|
|
|
{
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_ack(HI); /* P3 -> P0 */
|
2008-12-17 04:38:53 +00:00
|
|
|
syn_wait_clk_change(LO); /* P0 -> P1 */
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_ack(LO); /* P1 -> P2 */
|
2008-12-17 04:38:53 +00:00
|
|
|
syn_wait_clk_change(HI); /* P2 -> P3 */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Continue handshaking until back to P0 */
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_ack(HI); /* P3 -> P0 */
|
2008-12-17 04:38:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void syn_flush(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
logf("syn_flush...");
|
|
|
|
|
|
|
|
/* Flusher holds DATA low for at least 36 handshake cycles */
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_data(LO);
|
2008-12-17 04:38:53 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 36; i++)
|
|
|
|
{
|
|
|
|
syn_wait_clk_change(LO); /* P0 -> P1 */
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_ack(LO); /* P1 -> P2 */
|
2008-12-17 04:38:53 +00:00
|
|
|
syn_wait_clk_change(HI); /* P2 -> P3 */
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_ack(HI); /* P3 -> P0 */
|
2008-12-17 04:38:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Raise DATA in P1 stage */
|
|
|
|
syn_wait_clk_change(LO); /* P0 -> P1 */
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_data(HI);
|
2008-12-17 04:38:53 +00:00
|
|
|
|
|
|
|
/* After a flush, the flushing device enters a flush-receiving (flushee)
|
|
|
|
state */
|
|
|
|
syn_wait_guest_flush();
|
|
|
|
}
|
|
|
|
|
2009-06-19 02:48:15 +00:00
|
|
|
static int syn_send(char *data, int len)
|
2008-12-17 04:38:53 +00:00
|
|
|
{
|
|
|
|
int i, bit;
|
|
|
|
int parity = 0;
|
|
|
|
|
2009-02-18 02:19:22 +00:00
|
|
|
logf("syn_send...");
|
2008-12-17 04:38:53 +00:00
|
|
|
|
|
|
|
/* 1. Lower DATA line to issue a request-to-send to guest */
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_data(LO);
|
2008-12-17 04:38:53 +00:00
|
|
|
|
|
|
|
/* 2. Wait for guest to lower CLK */
|
|
|
|
syn_wait_clk_change(LO);
|
|
|
|
|
|
|
|
/* 3. Lower ACK (with DATA still low) */
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_ack(LO);
|
2008-12-17 04:38:53 +00:00
|
|
|
|
|
|
|
/* 4. Wait for guest to raise CLK */
|
|
|
|
syn_wait_clk_change(HI);
|
|
|
|
|
|
|
|
/* 5. Send data */
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
logf(" sending byte: %d", data[i]);
|
|
|
|
|
|
|
|
bit = 0;
|
|
|
|
while (bit < 8)
|
|
|
|
{
|
|
|
|
/* 5a. Drive data low if bit is 0, or high if bit is 1 */
|
|
|
|
if (data[i] & (1 << bit))
|
|
|
|
{
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_data(HI);
|
2008-12-17 04:38:53 +00:00
|
|
|
parity++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_data(LO);
|
2008-12-17 04:38:53 +00:00
|
|
|
}
|
|
|
|
bit++;
|
|
|
|
|
|
|
|
/* 5b. Invert ACK to indicate that the data bit is ready */
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_ack(HI);
|
2008-12-17 04:38:53 +00:00
|
|
|
|
|
|
|
/* 5c. Wait for guest to invert CLK */
|
|
|
|
syn_wait_clk_change(LO);
|
|
|
|
|
|
|
|
/* Repeat for next bit */
|
|
|
|
if (data[i] & (1 << bit))
|
|
|
|
{
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_data(HI);
|
2008-12-17 04:38:53 +00:00
|
|
|
parity++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_data(LO);
|
2008-12-17 04:38:53 +00:00
|
|
|
}
|
|
|
|
bit++;
|
|
|
|
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_ack(LO);
|
2008-12-17 04:38:53 +00:00
|
|
|
|
|
|
|
syn_wait_clk_change(HI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 7. Transmission termination sequence: */
|
|
|
|
/* 7a. Host may put parity bit on DATA. Hosts that do not generate
|
|
|
|
parity should set DATA high. Parity is 1 if there's an odd
|
|
|
|
number of '1' bits, or 0 if there's an even number of '1' bits. */
|
|
|
|
parity = parity % 2;
|
|
|
|
if (parity)
|
|
|
|
{
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_data(HI);
|
2008-12-17 04:38:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_data(LO);
|
2008-12-17 04:38:53 +00:00
|
|
|
}
|
|
|
|
logf(" send parity = %d", parity);
|
|
|
|
|
|
|
|
/* 7b. Raise ACK to indicate that the optional parity bit is ready */
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_ack(HI);
|
2008-12-17 04:38:53 +00:00
|
|
|
|
|
|
|
/* 7c. Guest lowers CLK */
|
|
|
|
syn_wait_clk_change(LO);
|
|
|
|
|
|
|
|
/* 7d. Pull DATA high (if parity bit was 0) */
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_data(HI);
|
2008-12-17 04:38:53 +00:00
|
|
|
|
|
|
|
/* 7e. Lower ACK to indicate that the stop bit is ready */
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_ack(LO);
|
2008-12-17 04:38:53 +00:00
|
|
|
|
|
|
|
/* 7f. Guest raises CLK */
|
|
|
|
syn_wait_clk_change(HI);
|
|
|
|
|
|
|
|
/* 7g. If DATA is low, guest is flushing this transfer. Host should
|
|
|
|
enter the flushee state. */
|
|
|
|
if (syn_get_data() == LO)
|
|
|
|
{
|
|
|
|
logf(" module flushing");
|
|
|
|
|
|
|
|
syn_wait_guest_flush();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 7h. Host raises ACK and the link enters the idle state */
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_ack(HI);
|
2008-12-17 04:38:53 +00:00
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2009-06-19 02:48:15 +00:00
|
|
|
static int syn_read_data(char *data, int data_len)
|
2008-12-17 04:38:53 +00:00
|
|
|
{
|
2009-06-19 02:48:15 +00:00
|
|
|
int i, len, bit, parity;
|
|
|
|
char *data_ptr, tmp;
|
2008-12-17 04:38:53 +00:00
|
|
|
|
|
|
|
logf("syn_read_data...");
|
|
|
|
|
|
|
|
/* 1. Guest drives CLK low */
|
|
|
|
if (CLK != LO)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* 1a. If the host is willing to receive a packet it lowers ACK */
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_ack(LO);
|
2008-12-17 04:38:53 +00:00
|
|
|
|
|
|
|
/* 2. Guest may issue a request-to-send by lowering DATA. If the
|
|
|
|
guest decides not to transmit a packet, it may abort the
|
|
|
|
transmission by not lowering DATA. */
|
|
|
|
|
|
|
|
/* 3. The guest raises CLK */
|
|
|
|
syn_wait_clk_change(HI);
|
|
|
|
|
|
|
|
/* 4. If the guest is still driving DATA low, the transfer is commited
|
|
|
|
to occur. Otherwise, the transfer is aborted. In either case,
|
|
|
|
the host raises ACK. */
|
|
|
|
if (syn_get_data() == HI)
|
|
|
|
{
|
|
|
|
logf(" read abort");
|
|
|
|
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_ack(HI);
|
2008-12-17 04:38:53 +00:00
|
|
|
return READ_ERROR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_ack(HI);
|
2008-12-17 04:38:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 5. Read the incoming data packet */
|
|
|
|
i = 0;
|
|
|
|
len = 0;
|
|
|
|
parity = 0;
|
|
|
|
while (i <= len)
|
|
|
|
{
|
|
|
|
bit = 0;
|
|
|
|
|
|
|
|
if (i < data_len)
|
|
|
|
data_ptr = &data[i];
|
|
|
|
else
|
|
|
|
data_ptr = &tmp;
|
|
|
|
|
|
|
|
*data_ptr = 0;
|
|
|
|
while (bit < 8)
|
|
|
|
{
|
|
|
|
/* 5b. Guset inverts CLK to indicate that data is ready */
|
|
|
|
syn_wait_clk_change(LO);
|
|
|
|
|
|
|
|
/* 5d. Read the data bit from DATA */
|
|
|
|
if (syn_get_data() == HI)
|
|
|
|
{
|
|
|
|
*data_ptr |= (1 << bit);
|
|
|
|
parity++;
|
|
|
|
}
|
|
|
|
bit++;
|
|
|
|
|
|
|
|
/* 5e. Invert ACK to indicate that data has been read */
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_ack(LO);
|
2008-12-17 04:38:53 +00:00
|
|
|
|
|
|
|
/* Repeat for next bit */
|
|
|
|
syn_wait_clk_change(HI);
|
|
|
|
|
|
|
|
if (syn_get_data() == HI)
|
|
|
|
{
|
|
|
|
*data_ptr |= (1 << bit);
|
|
|
|
parity++;
|
|
|
|
}
|
|
|
|
bit++;
|
|
|
|
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_ack(HI);
|
2008-12-17 04:38:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* First byte is the packet header */
|
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
/* Format control (bit 3) should be 1 */
|
|
|
|
if (*data_ptr & 0x8)
|
|
|
|
{
|
|
|
|
/* Packet length is bits 0:2 */
|
|
|
|
len = *data_ptr & 0x7;
|
|
|
|
logf(" packet length = %d", len);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
logf(" invalid format ctrl bit");
|
|
|
|
return READ_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 7. Transmission termination cycle */
|
|
|
|
/* 7a. The guest generates a parity bit on DATA */
|
|
|
|
/* 7b. The host waits for guest to lower CLK */
|
|
|
|
syn_wait_clk_change(LO);
|
|
|
|
|
|
|
|
/* 7c. The host verifies the parity bit is correct */
|
|
|
|
parity = parity % 2;
|
|
|
|
logf(" parity check: %d / %d", syn_get_data(), parity);
|
|
|
|
|
|
|
|
/* TODO: parity error handling */
|
|
|
|
|
|
|
|
/* 7d. The host lowers ACK */
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_ack(LO);
|
2008-12-17 04:38:53 +00:00
|
|
|
|
|
|
|
/* 7e. The host waits for the guest to raise CLK indicating
|
|
|
|
that the stop bit is ready */
|
|
|
|
syn_wait_clk_change(HI);
|
|
|
|
|
|
|
|
/* 7f. The host reads DATA and verifies that it is 1 */
|
|
|
|
if (syn_get_data() == LO)
|
|
|
|
{
|
|
|
|
logf(" framing error");
|
|
|
|
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_ack(HI);
|
2008-12-17 04:38:53 +00:00
|
|
|
return READ_ERROR;
|
|
|
|
}
|
|
|
|
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_set_ack(HI);
|
2008-12-17 04:38:53 +00:00
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2009-06-19 02:48:15 +00:00
|
|
|
static int syn_read(char *data, int len)
|
2008-12-17 04:38:53 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int ret = READ_ERROR;
|
|
|
|
|
|
|
|
for (i = 0; i < READ_RETRY; i++)
|
|
|
|
{
|
|
|
|
if (syn_wait_clk_change(LO))
|
|
|
|
{
|
|
|
|
/* module is sending data */
|
|
|
|
ret = syn_read_data(data, len);
|
|
|
|
if (ret != READ_ERROR)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
syn_flush();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* module is idle */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-06-19 02:48:15 +00:00
|
|
|
static int syn_reset(void)
|
2008-12-17 04:38:53 +00:00
|
|
|
{
|
|
|
|
int val, id;
|
2009-06-19 02:48:15 +00:00
|
|
|
char data[2];
|
2008-12-17 04:38:53 +00:00
|
|
|
|
|
|
|
logf("syn_reset...");
|
|
|
|
|
|
|
|
/* reset module 0 */
|
2009-06-19 02:48:15 +00:00
|
|
|
data[0] = (0 << 4) | (1 << 3) | 0;
|
|
|
|
syn_send(data, 1);
|
2008-12-17 04:38:53 +00:00
|
|
|
|
2009-02-18 02:19:22 +00:00
|
|
|
val = syn_read(data, 2);
|
2008-12-17 04:38:53 +00:00
|
|
|
if (val == 1)
|
|
|
|
{
|
|
|
|
val = data[0] & 0xff; /* packet header */
|
|
|
|
id = (data[1] >> 4) & 0xf; /* packet id */
|
|
|
|
if ((val == MEP_HELLO_HEADER) && (id == MEP_HELLO_ID))
|
|
|
|
{
|
|
|
|
logf(" module 0 reset");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
logf(" reset failed");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-19 02:48:15 +00:00
|
|
|
int touchpad_init(void)
|
2008-12-17 04:38:53 +00:00
|
|
|
{
|
|
|
|
syn_flush();
|
2009-02-18 02:19:22 +00:00
|
|
|
syn_status = syn_reset();
|
|
|
|
|
|
|
|
if (syn_status)
|
|
|
|
{
|
2009-06-19 02:48:15 +00:00
|
|
|
/* reset interrupts */
|
|
|
|
syn_enable_int(false);
|
|
|
|
syn_enable_int(true);
|
2009-02-18 02:19:22 +00:00
|
|
|
|
|
|
|
CPU_INT_EN |= HI_MASK;
|
|
|
|
CPU_HI_INT_EN |= GPIO0_MASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return syn_status;
|
|
|
|
}
|
|
|
|
|
2009-06-19 02:48:15 +00:00
|
|
|
int touchpad_read_device(char *data, int len)
|
2009-02-18 02:19:22 +00:00
|
|
|
{
|
2009-06-19 02:48:15 +00:00
|
|
|
char tmp[4];
|
|
|
|
int id;
|
|
|
|
int val = 0;
|
2009-02-18 02:19:22 +00:00
|
|
|
|
2009-06-19 02:48:15 +00:00
|
|
|
if (syn_status)
|
2009-02-18 02:19:22 +00:00
|
|
|
{
|
2009-06-19 02:48:15 +00:00
|
|
|
/* disable interrupt while we read the touchpad */
|
|
|
|
syn_enable_int(false);
|
|
|
|
|
|
|
|
val = syn_read(data, len);
|
|
|
|
if (val > 0)
|
|
|
|
{
|
|
|
|
val = data[0] & 0xff; /* packet header */
|
|
|
|
id = (data[1] >> 4) & 0xf; /* packet id */
|
|
|
|
|
|
|
|
logf("syn_read:");
|
|
|
|
logf(" data[0] = 0x%08x", data[0]);
|
|
|
|
logf(" data[1] = 0x%08x", data[1]);
|
|
|
|
logf(" data[2] = 0x%08x", data[2]);
|
|
|
|
logf(" data[3] = 0x%08x", data[3]);
|
|
|
|
|
|
|
|
if ((val == MEP_BUTTON_HEADER) && (id == MEP_BUTTON_ID))
|
|
|
|
{
|
|
|
|
/* an absolute packet should follow which we ignore */
|
|
|
|
syn_read(tmp, 4);
|
|
|
|
}
|
|
|
|
else if (val == MEP_ABSOLUTE_HEADER)
|
|
|
|
{
|
|
|
|
logf(" pos %d", val);
|
|
|
|
logf(" z %d", data[3]);
|
|
|
|
logf(" finger %d", data[1] & 0x1);
|
|
|
|
logf(" gesture %d", data[1] & 0x2);
|
|
|
|
logf(" RelPosVld %d", data[1] & 0x4);
|
|
|
|
|
|
|
|
if (!(data[1] & 0x1))
|
|
|
|
{
|
|
|
|
/* finger is NOT on touch strip */
|
|
|
|
val = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
val = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* re-enable interrupts */
|
|
|
|
syn_enable_int(true);
|
2009-02-18 02:19:22 +00:00
|
|
|
}
|
2009-06-19 02:48:15 +00:00
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
int touchpad_set_buttonlights(int led_mask, char brightness)
|
|
|
|
{
|
|
|
|
char data[6];
|
|
|
|
int val = 0;
|
|
|
|
|
|
|
|
if (syn_status)
|
2009-02-18 02:19:22 +00:00
|
|
|
{
|
2009-06-19 02:48:15 +00:00
|
|
|
syn_enable_int(false);
|
|
|
|
|
|
|
|
/* turn on all touchpad leds */
|
|
|
|
data[0] = 0x05;
|
|
|
|
data[1] = 0x31;
|
|
|
|
data[2] = (brightness & 0xf) << 4;
|
|
|
|
data[3] = 0x00;
|
|
|
|
data[4] = (led_mask >> 8) & 0xff;
|
|
|
|
data[5] = led_mask & 0xff;
|
|
|
|
syn_send(data, 6);
|
|
|
|
|
|
|
|
/* device responds with a single-byte ACK packet */
|
|
|
|
val = syn_read(data, 2);
|
|
|
|
|
|
|
|
syn_enable_int(true);
|
2009-02-18 02:19:22 +00:00
|
|
|
}
|
2009-06-19 02:48:15 +00:00
|
|
|
|
|
|
|
return val;
|
2008-12-17 04:38:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ROCKBOX_HAS_LOGF
|
|
|
|
void syn_info(void)
|
|
|
|
{
|
|
|
|
int i, val;
|
|
|
|
int data[8];
|
|
|
|
|
|
|
|
logf("syn_info...");
|
|
|
|
|
|
|
|
/* module base info */
|
|
|
|
logf("module base info:");
|
|
|
|
data[0] = MEP_READ;
|
|
|
|
data[1] = 0x80;
|
2009-02-18 02:19:22 +00:00
|
|
|
syn_send(data, 2);
|
|
|
|
val = syn_read(data, 8);
|
2008-12-17 04:38:53 +00:00
|
|
|
if (val > 0)
|
|
|
|
{
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
logf(" data[%d] = 0x%02x", i, data[i]);
|
|
|
|
}
|
2009-06-19 02:48:15 +00:00
|
|
|
|
2008-12-17 04:38:53 +00:00
|
|
|
/* module product info */
|
|
|
|
logf("module product info:");
|
|
|
|
data[0] = MEP_READ;
|
|
|
|
data[1] = 0x81;
|
2009-02-18 02:19:22 +00:00
|
|
|
syn_send(data, 2);
|
|
|
|
val = syn_read(data, 8);
|
2008-12-17 04:38:53 +00:00
|
|
|
if (val > 0)
|
|
|
|
{
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
logf(" data[%d] = 0x%02x", i, data[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* module serialization */
|
|
|
|
logf("module serialization:");
|
|
|
|
data[0] = MEP_READ;
|
|
|
|
data[1] = 0x82;
|
2009-02-18 02:19:22 +00:00
|
|
|
syn_send(data, 2);
|
|
|
|
val = syn_read(data, 8);
|
2008-12-17 04:38:53 +00:00
|
|
|
if (val > 0)
|
|
|
|
{
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
logf(" data[%d] = 0x%02x", i, data[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 1-D sensor info */
|
|
|
|
logf("1-d sensor info:");
|
|
|
|
data[0] = MEP_READ;
|
|
|
|
data[1] = 0x80 + 0x20;
|
2009-02-18 02:19:22 +00:00
|
|
|
syn_send(data, 2);
|
|
|
|
val = syn_read(data, 8);
|
2008-12-17 04:38:53 +00:00
|
|
|
if (val > 0)
|
|
|
|
{
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
logf(" data[%d] = 0x%02x", i, data[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|