Rework MediaButtonReceiver a bit:
[kugel-rb.git] / firmware / drivers / synaptics-rmi.c
blobc6a1bae168180d28569b57741a12390c2674e63b
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
21 #include "system.h"
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;
29 /* NOTE:
30 * RMI over i2c supports some special aliases on page 0x2 but this driver don't
31 * use them */
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;
37 rmi_cur_page = 0x4;
38 return 0;
41 static int rmi_select_page(unsigned char page)
43 /* Lazy page select */
44 if(page != rmi_cur_page)
46 rmi_cur_page = page;
47 return i2c_write_data(rmi_i2c_bus, rmi_i2c_addr, RMI_PAGE_SELECT, &page, 1);
49 else
50 return 0;
53 int rmi_read(int address, int byte_count, unsigned char *buffer)
55 if(rmi_select_page(address >> 8) < 0)
56 return -1;
57 return i2c_read_data(rmi_i2c_bus, rmi_i2c_addr, address & 0xff, buffer, byte_count);
60 int rmi_read_single(int address)
62 unsigned char c;
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)
70 return -1;
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);