1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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.
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
40 #elif defined(SANSA_CLIPV2)
41 #define I2C_GPIO(x) GPIOB_PIN(x)
42 #define I2C_GPIO_DIR GPIOB_DIR
46 #elif defined(SANSA_M200V4)
47 #define I2C_GPIO(x) GPIOD_PIN(x)
48 #define I2C_GPIO_DIR GPIOD_DIR
52 #elif defined(SANSA_FUZE) || defined(SANSA_E200V2)
53 #define I2C_GPIO(x) GPIOA_PIN(x)
54 #define I2C_GPIO_DIR GPIOA_DIR
59 #error no FM I2C GPIOPIN defines
62 static int fm_i2c_bus
;
64 static void fm_scl_hi(void)
66 I2C_GPIO(I2C_SCL_PIN
) = 1 << I2C_SCL_PIN
;
69 static void fm_scl_lo(void)
71 I2C_GPIO(I2C_SCL_PIN
) = 0;
74 static void fm_sda_hi(void)
76 I2C_GPIO(I2C_SDA_PIN
) = 1 << I2C_SDA_PIN
;
79 static void fm_sda_lo(void)
81 I2C_GPIO(I2C_SDA_PIN
) = 0;
84 static void fm_sda_input(void)
86 I2C_GPIO_DIR
&= ~(1 << I2C_SDA_PIN
);
89 static void fm_sda_output(void)
91 I2C_GPIO_DIR
|= 1 << I2C_SDA_PIN
;
94 static void fm_scl_input(void)
96 I2C_GPIO_DIR
&= ~(1 << I2C_SCL_PIN
);
99 static void fm_scl_output(void)
101 I2C_GPIO_DIR
|= 1 << I2C_SCL_PIN
;
104 static int fm_sda(void)
106 return I2C_GPIO(I2C_SDA_PIN
);
109 static int fm_scl(void)
111 return I2C_GPIO(I2C_SCL_PIN
);
114 /* simple and crude delay, used for all delays in the generic i2c driver */
115 static void fm_delay(void)
119 /* this loop is uncalibrated and could use more sophistication */
120 for (i
= 0; i
< 20; i
++) {
124 /* interface towards the generic i2c driver */
125 static const struct i2c_interface fm_i2c_interface
= {
130 .sda_input
= fm_sda_input
,
131 .sda_output
= fm_sda_output
,
132 .scl_input
= fm_scl_input
,
133 .scl_output
= fm_scl_output
,
137 .delay_hd_sta
= fm_delay
,
138 .delay_hd_dat
= fm_delay
,
139 .delay_su_dat
= fm_delay
,
140 .delay_su_sto
= fm_delay
,
141 .delay_su_sta
= fm_delay
,
142 .delay_thigh
= fm_delay
145 /* initialise i2c for fmradio */
146 void fmradio_i2c_init(void)
148 fm_i2c_bus
= i2c_add_node(&fm_i2c_interface
);
151 int fmradio_i2c_write(unsigned char address
, const unsigned char* buf
, int count
)
153 return i2c_write_data(fm_i2c_bus
, address
, -1, buf
, count
);
156 int fmradio_i2c_read(unsigned char address
, unsigned char* buf
, int count
)
158 return i2c_read_data(fm_i2c_bus
, address
, -1, buf
, count
);