1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2011 by Amaury Pouly
*
* 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 "system.h"
#include "synaptics-rmi.h"
#include "i2c.h"
static int rmi_cur_page;
static int rmi_i2c_addr;
/* NOTE:
* RMI over i2c supports some special aliases on page 0x2 but this driver don't
* use them */
int rmi_init(int i2c_dev_addr)
{
rmi_i2c_addr = i2c_dev_addr;
rmi_cur_page = 0x4;
return 0;
}
static int rmi_select_page(unsigned char page)
{
/* Lazy page select */
if(page != rmi_cur_page)
{
rmi_cur_page = page;
return i2c_writemem(rmi_i2c_addr, RMI_PAGE_SELECT, &page, 1);
}
else
return 0;
}
int rmi_read(int address, int byte_count, unsigned char *buffer)
{
int ret;
if((ret = rmi_select_page(address >> 8)) < 0)
return ret;
return i2c_readmem(rmi_i2c_addr, address & 0xff, buffer, byte_count);
}
int rmi_read_single(int address)
{
unsigned char c;
int ret = rmi_read(address, 1, &c);
return ret < 0 ? ret : c;
}
int rmi_write(int address, int byte_count, const unsigned char *buffer)
{
int ret;
if((ret = rmi_select_page(address >> 8)) < 0)
return ret;
return i2c_writemem(rmi_i2c_addr, address & 0xff, buffer, byte_count);
}
int rmi_write_single(int address, unsigned char byte)
{
return rmi_write(address, 1, &byte);
}
|