Of course there's no mdelay on c200(v1), so just use udelay
[kugel-rb.git] / firmware / target / arm / s5l8700 / fmradio-i2c-meizu.c
blob02df8f33a1e90f15436b529ed176978796e604e9
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2009 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 FM radio i2c interface, allows the radio driver to talk to the tuner chip.
25 It is implemented using the generic i2c driver, which does "bit-banged"
26 I2C with a couple of GPIO pins.
29 #include "config.h"
31 #include "inttypes.h"
32 #include "s5l8700.h"
33 #include "generic_i2c.h"
34 #include "fmradio_i2c.h"
36 #define I2C_GPIO PDAT3
37 #define I2C_GPIO_DIR PCON3
38 #define I2C_SCL_PIN 4
39 #define I2C_SDA_PIN 2
41 #define SCL_DIR_MASK (0xF<<(4*I2C_SCL_PIN))
42 #define SCL_DIR_OUT (1<<(4*I2C_SCL_PIN))
43 #define SCL_DIR_IN 0
44 #define SDA_DIR_MASK (0xF<<(4*I2C_SDA_PIN))
45 #define SDA_DIR_OUT (1<<(4*I2C_SDA_PIN))
46 #define SDA_DIR_IN 0
48 static int fm_i2c_bus;
50 static void fm_scl_hi(void)
52 I2C_GPIO |= 1 << I2C_SCL_PIN;
55 static void fm_scl_lo(void)
57 I2C_GPIO &= ~(1 << I2C_SCL_PIN);
60 static void fm_sda_hi(void)
62 I2C_GPIO |= 1 << I2C_SDA_PIN;
65 static void fm_sda_lo(void)
67 I2C_GPIO &= ~(1 << I2C_SDA_PIN);
70 static void fm_sda_input(void)
72 I2C_GPIO_DIR = (I2C_GPIO_DIR & ~SDA_DIR_MASK) | SDA_DIR_IN;
75 static void fm_sda_output(void)
77 I2C_GPIO_DIR = (I2C_GPIO_DIR & ~SDA_DIR_MASK) | SDA_DIR_OUT;
80 static void fm_scl_input(void)
82 I2C_GPIO_DIR = (I2C_GPIO_DIR & ~SCL_DIR_MASK) | SCL_DIR_IN;
85 static void fm_scl_output(void)
87 I2C_GPIO_DIR = (I2C_GPIO_DIR & ~SCL_DIR_MASK) | SCL_DIR_OUT;
90 static int fm_sda(void)
92 return (I2C_GPIO & (1 << I2C_SDA_PIN));
95 static int fm_scl(void)
97 return (I2C_GPIO & (1 << I2C_SCL_PIN));
100 /* simple and crude delay, used for all delays in the generic i2c driver */
101 static void fm_delay(void)
103 volatile int i;
105 /* this loop is uncalibrated and could use more sophistication */
106 for (i = 0; i < 20; i++) {
110 /* interface towards the generic i2c driver */
111 static const struct i2c_interface fm_i2c_interface = {
112 .scl_hi = fm_scl_hi,
113 .scl_lo = fm_scl_lo,
114 .sda_hi = fm_sda_hi,
115 .sda_lo = fm_sda_lo,
116 .sda_input = fm_sda_input,
117 .sda_output = fm_sda_output,
118 .scl_input = fm_scl_input,
119 .scl_output = fm_scl_output,
120 .scl = fm_scl,
121 .sda = fm_sda,
123 .delay_hd_sta = fm_delay,
124 .delay_hd_dat = fm_delay,
125 .delay_su_dat = fm_delay,
126 .delay_su_sto = fm_delay,
127 .delay_su_sta = fm_delay,
128 .delay_thigh = fm_delay
131 /* initialise i2c for fmradio */
132 void fmradio_i2c_init(void)
134 fm_i2c_bus = i2c_add_node(&fm_i2c_interface);
137 int fmradio_i2c_write(unsigned char address, const unsigned char* buf, int count)
139 return i2c_write_data(fm_i2c_bus, address, -1, buf, count);
142 int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count)
144 return i2c_read_data(fm_i2c_bus, address, -1, buf, count);