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 "synaptics-rmi.h"
25 static int rmi_cur_page
;
26 static int rmi_i2c_addr
;
29 * RMI over i2c supports some special aliases on page 0x2 but this driver don't
32 int rmi_init(int i2c_dev_addr
)
34 rmi_i2c_addr
= i2c_dev_addr
;
39 static int rmi_select_page(unsigned char page
)
41 /* Lazy page select */
42 if(page
!= rmi_cur_page
)
45 return i2c_writemem(rmi_i2c_addr
, RMI_PAGE_SELECT
, &page
, 1);
51 int rmi_read(int address
, int byte_count
, unsigned char *buffer
)
54 if((ret
= rmi_select_page(address
>> 8)) < 0)
56 return i2c_readmem(rmi_i2c_addr
, address
& 0xff, buffer
, byte_count
);
59 int rmi_read_single(int address
)
62 int ret
= rmi_read(address
, 1, &c
);
63 return ret
< 0 ? ret
: c
;
66 int rmi_write(int address
, int byte_count
, const unsigned char *buffer
)
69 if((ret
= rmi_select_page(address
>> 8)) < 0)
71 return i2c_writemem(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
);