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.
32 #include "generic_i2c.h"
33 #include "fmradio_i2c.h"
35 #if defined(SANSA_CLIP) || defined(SANSA_C200V2)
36 #define I2C_SCL_GPIO(x) GPIOB_PIN(x)
37 #define I2C_SDA_GPIO(x) GPIOB_PIN(x)
38 #define I2C_SCL_GPIO_DIR GPIOB_DIR
39 #define I2C_SDA_GPIO_DIR GPIOB_DIR
43 #elif defined(SANSA_CLIPV2) || defined(SANSA_CLIPPLUS)
44 #define I2C_SCL_GPIO(x) GPIOB_PIN(x)
45 #define I2C_SDA_GPIO(x) GPIOB_PIN(x)
46 #define I2C_SCL_GPIO_DIR GPIOB_DIR
47 #define I2C_SDA_GPIO_DIR GPIOB_DIR
51 #elif defined(SANSA_M200V4)
52 #define I2C_SCL_GPIO(x) GPIOD_PIN(x)
53 #define I2C_SDA_GPIO(x) GPIOD_PIN(x)
54 #define I2C_SCL_GPIO_DIR GPIOD_DIR
55 #define I2C_SDA_GPIO_DIR GPIOD_DIR
59 #elif defined(SANSA_FUZE) || defined(SANSA_E200V2)
60 #define I2C_SCL_GPIO(x) GPIOA_PIN(x)
61 #define I2C_SDA_GPIO(x) GPIOA_PIN(x)
62 #define I2C_SCL_GPIO_DIR GPIOA_DIR
63 #define I2C_SDA_GPIO_DIR GPIOA_DIR
67 #elif defined(SANSA_FUZEV2)
68 #define I2C_SCL_GPIO(x) GPIOB_PIN(x)
69 #define I2C_SDA_GPIO(x) GPIOA_PIN(x)
70 #define I2C_SCL_GPIO_DIR GPIOB_DIR
71 #define I2C_SDA_GPIO_DIR GPIOA_DIR
76 #error no FM I2C GPIOPIN defines
79 static int fm_i2c_bus
;
81 static void fm_scl_dir(bool out
)
84 I2C_SCL_GPIO_DIR
|= 1 << I2C_SCL_PIN
;
86 I2C_SCL_GPIO_DIR
&= ~(1 << I2C_SCL_PIN
);
90 static void fm_sda_dir(bool out
)
93 I2C_SDA_GPIO_DIR
|= 1 << I2C_SDA_PIN
;
95 I2C_SDA_GPIO_DIR
&= ~(1 << I2C_SDA_PIN
);
99 static void fm_scl_out(bool level
)
102 I2C_SCL_GPIO(I2C_SCL_PIN
) = 1 << I2C_SCL_PIN
;
104 I2C_SCL_GPIO(I2C_SCL_PIN
) = 0;
108 static void fm_sda_out(bool level
)
111 I2C_SDA_GPIO(I2C_SDA_PIN
) = 1 << I2C_SDA_PIN
;
113 I2C_SDA_GPIO(I2C_SDA_PIN
) = 0;
117 static bool fm_scl_in(void)
119 return I2C_SCL_GPIO(I2C_SCL_PIN
);
122 static bool fm_sda_in(void)
124 return I2C_SDA_GPIO(I2C_SDA_PIN
);
127 static void fm_delay(int delay
)
134 /* interface towards the generic i2c driver */
135 static const struct i2c_interface fm_i2c_interface
= {
136 .scl_out
= fm_scl_out
,
137 .scl_dir
= fm_scl_dir
,
138 .sda_out
= fm_sda_out
,
139 .sda_dir
= fm_sda_dir
,
152 /* initialise i2c for fmradio */
153 void fmradio_i2c_init(void)
155 fm_i2c_bus
= i2c_add_node(&fm_i2c_interface
);
158 int fmradio_i2c_write(unsigned char address
, const unsigned char* buf
, int count
)
163 int ret
= i2c_write_data(fm_i2c_bus
, address
, -1, buf
, count
);
170 int fmradio_i2c_read(unsigned char address
, unsigned char* buf
, int count
)
175 int ret
= i2c_read_data(fm_i2c_bus
, address
, -1, buf
, count
);