FS#8961 - Anti-Aliased Fonts.
[kugel-rb.git] / firmware / target / arm / as3525 / fmradio-i2c-as3525.c
blob99b9bdff0251ddf562fb2189e4f21ec3fe14b1c5
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2008 by Bertrik Sikken
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 ****************************************************************************/
23 This is the fmradio_i2c interface, used by the radio driver
24 to communicate with the radio tuner chip.
26 It is implemented using the generic i2c driver, which does "bit-banged"
27 I2C with a couple of GPIO pins.
30 #include "as3525.h"
31 #include "generic_i2c.h"
32 #include "fmradio_i2c.h"
34 #if defined(SANSA_CLIP) || defined(SANSA_C200V2)
35 #define I2C_GPIO(x) GPIOB_PIN(x)
36 #define I2C_GPIO_DIR GPIOB_DIR
37 #define I2C_SCL_PIN 4
38 #define I2C_SDA_PIN 5
40 #elif defined(SANSA_M200V4)
41 #define I2C_GPIO(x) GPIOD_PIN(x)
42 #define I2C_GPIO_DIR GPIOD_DIR
43 #define I2C_SCL_PIN 7
44 #define I2C_SDA_PIN 6
46 #elif defined(SANSA_FUZE) || defined(SANSA_E200V2)
47 #define I2C_GPIO(x) GPIOA_PIN(x)
48 #define I2C_GPIO_DIR GPIOA_DIR
49 #define I2C_SCL_PIN 6
50 #define I2C_SDA_PIN 7
52 #elif
53 #error no FM I2C GPIOPIN defines
54 #endif
56 static int fm_i2c_bus;
58 static void fm_scl_hi(void)
60 I2C_GPIO(I2C_SCL_PIN) = 1 << I2C_SCL_PIN;
63 static void fm_scl_lo(void)
65 I2C_GPIO(I2C_SCL_PIN) = 0;
68 static void fm_sda_hi(void)
70 I2C_GPIO(I2C_SDA_PIN) = 1 << I2C_SDA_PIN;
73 static void fm_sda_lo(void)
75 I2C_GPIO(I2C_SDA_PIN) = 0;
78 static void fm_sda_input(void)
80 I2C_GPIO_DIR &= ~(1 << I2C_SDA_PIN);
83 static void fm_sda_output(void)
85 I2C_GPIO_DIR |= 1 << I2C_SDA_PIN;
88 static void fm_scl_input(void)
90 I2C_GPIO_DIR &= ~(1 << I2C_SCL_PIN);
93 static void fm_scl_output(void)
95 I2C_GPIO_DIR |= 1 << I2C_SCL_PIN;
98 static int fm_sda(void)
100 return I2C_GPIO(I2C_SDA_PIN);
103 static int fm_scl(void)
105 return I2C_GPIO(I2C_SCL_PIN);
108 /* simple and crude delay, used for all delays in the generic i2c driver */
109 static void fm_delay(void)
111 volatile int i;
113 /* this loop is uncalibrated and could use more sophistication */
114 for (i = 0; i < 20; i++) {
118 /* interface towards the generic i2c driver */
119 static const struct i2c_interface fm_i2c_interface = {
120 .scl_hi = fm_scl_hi,
121 .scl_lo = fm_scl_lo,
122 .sda_hi = fm_sda_hi,
123 .sda_lo = fm_sda_lo,
124 .sda_input = fm_sda_input,
125 .sda_output = fm_sda_output,
126 .scl_input = fm_scl_input,
127 .scl_output = fm_scl_output,
128 .scl = fm_scl,
129 .sda = fm_sda,
131 .delay_hd_sta = fm_delay,
132 .delay_hd_dat = fm_delay,
133 .delay_su_dat = fm_delay,
134 .delay_su_sto = fm_delay,
135 .delay_su_sta = fm_delay,
136 .delay_thigh = fm_delay
139 /* initialise i2c for fmradio */
140 void fmradio_i2c_init(void)
142 fm_i2c_bus = i2c_add_node(&fm_i2c_interface);
145 int fmradio_i2c_write(unsigned char address, const unsigned char* buf, int count)
147 return i2c_write_data(fm_i2c_bus, address, -1, buf, count);
150 int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count)
152 return i2c_read_data(fm_i2c_bus, address, -1, buf, count);