summaryrefslogtreecommitdiff
path: root/firmware/target/arm
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm')
-rw-r--r--firmware/target/arm/s5l8700/fmradio-i2c-meizu.c146
1 files changed, 146 insertions, 0 deletions
diff --git a/firmware/target/arm/s5l8700/fmradio-i2c-meizu.c b/firmware/target/arm/s5l8700/fmradio-i2c-meizu.c
new file mode 100644
index 0000000000..5a4113a6a5
--- /dev/null
+++ b/firmware/target/arm/s5l8700/fmradio-i2c-meizu.c
@@ -0,0 +1,146 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2008 by Bertrik Sikken
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22/*
23 FM radio i2c interface, allows the radio driver to talk to the tuner chip.
24
25 It is implemented using the generic i2c driver, which does "bit-banged"
26 I2C with a couple of GPIO pins.
27 */
28
29#include "config.h"
30
31#include "inttypes.h"
32#include "s5l8700.h"
33#include "generic_i2c.h"
34#include "fmradio_i2c.h"
35
36#define I2C_GPIO PDAT3
37#define I2C_GPIO_DIR PCON3
38#define I2C_SCL_PIN 4
39#define I2C_SDA_PIN 2
40
41#define SCL_DIR_MASK (3<<(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 (3<<(4*I2C_SDA_PIN))
45#define SDA_DIR_OUT (1<<(4*I2C_SDA_PIN))
46#define SDA_DIR_IN 0
47
48static int fm_i2c_bus;
49
50static void fm_scl_hi(void)
51{
52 I2C_GPIO |= 1 << I2C_SCL_PIN;
53}
54
55static void fm_scl_lo(void)
56{
57 I2C_GPIO &= ~(1 << I2C_SCL_PIN);
58}
59
60static void fm_sda_hi(void)
61{
62 I2C_GPIO |= 1 << I2C_SDA_PIN;
63}
64
65static void fm_sda_lo(void)
66{
67 I2C_GPIO &= ~(1 << I2C_SDA_PIN);
68}
69
70static void fm_sda_input(void)
71{
72 I2C_GPIO_DIR = (I2C_GPIO_DIR & ~SDA_DIR_MASK) | SDA_DIR_IN;
73}
74
75static void fm_sda_output(void)
76{
77 I2C_GPIO_DIR = (I2C_GPIO_DIR & ~SDA_DIR_MASK) | SDA_DIR_OUT;
78}
79
80static void fm_scl_input(void)
81{
82 I2C_GPIO_DIR = (I2C_GPIO_DIR & ~SCL_DIR_MASK) | SCL_DIR_IN;
83}
84
85static void fm_scl_output(void)
86{
87 I2C_GPIO_DIR = (I2C_GPIO_DIR & ~SCL_DIR_MASK) | SCL_DIR_OUT;
88}
89
90static int fm_sda(void)
91{
92 return (I2C_GPIO & (1 << I2C_SDA_PIN));
93}
94
95static int fm_scl(void)
96{
97 return (I2C_GPIO & (1 << I2C_SCL_PIN));
98}
99
100/* simple and crude delay, used for all delays in the generic i2c driver */
101static void fm_delay(void)
102{
103 volatile int i;
104
105 /* this loop is uncalibrated and could use more sophistication */
106 for (i = 0; i < 20; i++) {
107 }
108}
109
110/* interface towards the generic i2c driver */
111static 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,
122
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
129};
130
131/* initialise i2c for fmradio */
132void fmradio_i2c_init(void)
133{
134 fm_i2c_bus = i2c_add_node(&fm_i2c_interface);
135}
136
137int fmradio_i2c_write(unsigned char address, const unsigned char* buf, int count)
138{
139 return i2c_write_data(fm_i2c_bus, address, -1, buf, count);
140}
141
142int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count)
143{
144 return i2c_read_data(fm_i2c_bus, address, -1, buf, count);
145}
146