1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2011 by Amaury Pouly
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 ****************************************************************************/
22 #include "generic_i2c.h"
23 #include "synaptics-rmi.h"
25 static int rmi_cur_page
;
26 static int rmi_i2c_addr
;
27 static int rmi_i2c_bus
;
30 * RMI over i2c supports some special aliases on page 0x2 but this driver don't
33 int rmi_init(int i2c_bus_index
, int i2c_dev_addr
)
35 rmi_i2c_bus
= i2c_bus_index
;
36 rmi_i2c_addr
= i2c_dev_addr
;
41 static int rmi_select_page(unsigned char page
)
43 /* Lazy page select */
44 if(page
!= rmi_cur_page
)
47 return i2c_write_data(rmi_i2c_bus
, rmi_i2c_addr
, RMI_PAGE_SELECT
, &page
, 1);
53 int rmi_read(int address
, int byte_count
, unsigned char *buffer
)
55 if(rmi_select_page(address
>> 8) < 0)
57 return i2c_read_data(rmi_i2c_bus
, rmi_i2c_addr
, address
& 0xff, buffer
, byte_count
);
60 int rmi_read_single(int address
)
63 int ret
= rmi_read(address
, 1, &c
);
64 return ret
< 0 ? ret
: c
;
67 int rmi_write(int address
, int byte_count
, const unsigned char *buffer
)
69 if(rmi_select_page(address
>> 8) < 0)
71 return i2c_write_data(rmi_i2c_bus
, rmi_i2c_addr
, address
& 0xff, buffer
, byte_count
);
74 int rmi_write_single(int address
, unsigned char byte
)
76 return rmi_write(address
, 1, &byte
);