diff options
author | Amaury Pouly <amaury.pouly@gmail.com> | 2013-11-19 20:39:10 +0000 |
---|---|---|
committer | Amaury Pouly <amaury.pouly@gmail.com> | 2013-11-19 20:39:10 +0000 |
commit | 446f352abda2dbc9de90c35a02100ed5e9aad77c (patch) | |
tree | 7ee2b4dae98376e0380b0b8bc44e1e688d10ede2 /firmware/target/arm/imx233/fmradio-imx233.c | |
parent | c2c2274e0adacc1a0c5bdb57fa1367badb7b047f (diff) | |
download | rockbox-446f352abda2dbc9de90c35a02100ed5e9aad77c.tar.gz rockbox-446f352abda2dbc9de90c35a02100ed5e9aad77c.zip |
imx233: factor fmradio i2c and tuner power code
Choices are limited for those: i2c is either generic software or imx233
hardware and power is either none or with a gpio. So factor ever possible
combination in a single common file and use fmradio-target.h to supply the
required parameters. This will remove a bunch of duplicate code.
Change-Id: If12faeb2e371631cd39cc18a4c1d859812007934
Diffstat (limited to 'firmware/target/arm/imx233/fmradio-imx233.c')
-rw-r--r-- | firmware/target/arm/imx233/fmradio-imx233.c | 162 |
1 files changed, 162 insertions, 0 deletions
diff --git a/firmware/target/arm/imx233/fmradio-imx233.c b/firmware/target/arm/imx233/fmradio-imx233.c new file mode 100644 index 0000000000..28ac4a4893 --- /dev/null +++ b/firmware/target/arm/imx233/fmradio-imx233.c | |||
@@ -0,0 +1,162 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2013 by Amaury Pouly | ||
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 | #include "fmradio-imx233.h" | ||
22 | #include "fmradio-target.h" | ||
23 | #include "pinctrl-imx233.h" | ||
24 | #include "i2c.h" | ||
25 | #include "generic_i2c.h" | ||
26 | |||
27 | #ifndef IMX233_FMRADIO_I2C | ||
28 | #error You must define IMX233_FMRADIO_I2C in fmradio-target.h | ||
29 | #endif | ||
30 | |||
31 | #ifndef IMX233_FMRADIO_POWER | ||
32 | #error You must define IMX233_FMRADIO_POWER in fmradio-target.h | ||
33 | #endif | ||
34 | |||
35 | /** Hardware I2C */ | ||
36 | #if IMX233_FMRADIO_I2C == FMI_HW | ||
37 | void fmradio_i2c_init(void) | ||
38 | { | ||
39 | } | ||
40 | |||
41 | int fmradio_i2c_write(unsigned char address, const unsigned char* buf, int count) | ||
42 | { | ||
43 | return i2c_write(address, buf, count); | ||
44 | } | ||
45 | |||
46 | int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count) | ||
47 | { | ||
48 | return i2c_read(address, buf, count); | ||
49 | } | ||
50 | /** Software I2C */ | ||
51 | #elif IMX233_FMRADIO_I2C == FMI_SW | ||
52 | #if !defined(FMI_SW_SDA_BANK) || !defined(FMI_SW_SDA_PIN) || \ | ||
53 | !defined(FMI_SW_SCL_BANK) || !defined(FMI_SW_SCL_PIN) | ||
54 | #error You must define FMI_SW_SDA_BANK, FMI_SW_SDA_PIN, FMI_SW_SCL_BANK and FMI_SW_SCL_PIN | ||
55 | #endif | ||
56 | static int fmradio_i2c_bus = -1; | ||
57 | |||
58 | static void i2c_scl_dir(bool out) | ||
59 | { | ||
60 | imx233_pinctrl_enable_gpio(FMI_SW_SCL_BANK, FMI_SW_SCL_PIN, out); | ||
61 | } | ||
62 | |||
63 | static void i2c_sda_dir(bool out) | ||
64 | { | ||
65 | imx233_pinctrl_enable_gpio(FMI_SW_SDA_BANK, FMI_SW_SDA_PIN, out); | ||
66 | } | ||
67 | |||
68 | static void i2c_scl_out(bool high) | ||
69 | { | ||
70 | imx233_pinctrl_set_gpio(FMI_SW_SCL_BANK, FMI_SW_SCL_PIN, high); | ||
71 | } | ||
72 | |||
73 | static void i2c_sda_out(bool high) | ||
74 | { | ||
75 | imx233_pinctrl_set_gpio(FMI_SW_SDA_BANK, FMI_SW_SDA_PIN, high); | ||
76 | } | ||
77 | |||
78 | static bool i2c_scl_in(void) | ||
79 | { | ||
80 | return imx233_pinctrl_get_gpio(FMI_SW_SCL_BANK, FMI_SW_SCL_PIN); | ||
81 | } | ||
82 | |||
83 | static bool i2c_sda_in(void) | ||
84 | { | ||
85 | return imx233_pinctrl_get_gpio(FMI_SW_SDA_BANK, FMI_SW_SDA_PIN); | ||
86 | } | ||
87 | |||
88 | static void i2c_delay(int d) | ||
89 | { | ||
90 | udelay(d); | ||
91 | } | ||
92 | |||
93 | struct i2c_interface fmradio_i2c = | ||
94 | { | ||
95 | .scl_dir = i2c_scl_dir, | ||
96 | .sda_dir = i2c_sda_dir, | ||
97 | .scl_out = i2c_scl_out, | ||
98 | .sda_out = i2c_sda_out, | ||
99 | .scl_in = i2c_scl_in, | ||
100 | .sda_in = i2c_sda_in, | ||
101 | .delay = i2c_delay, | ||
102 | .delay_hd_sta = 4, | ||
103 | .delay_hd_dat = 5, | ||
104 | .delay_su_dat = 1, | ||
105 | .delay_su_sto = 4, | ||
106 | .delay_su_sta = 5, | ||
107 | .delay_thigh = 4 | ||
108 | }; | ||
109 | |||
110 | void fmradio_i2c_init(void) | ||
111 | { | ||
112 | imx233_pinctrl_acquire(FMI_SW_SDA_BANK, FMI_SW_SDA_PIN, "fmradio_i2c_sda"); | ||
113 | imx233_pinctrl_acquire(FMI_SW_SCL_BANK, FMI_SW_SCL_BANK, "fmradio_i2c_scl"); | ||
114 | imx233_pinctrl_set_function(FMI_SW_SDA_BANK, FMI_SW_SDA_PIN, PINCTRL_FUNCTION_GPIO); | ||
115 | imx233_pinctrl_set_function(FMI_SW_SCL_BANK, FMI_SW_SCL_BANK, PINCTRL_FUNCTION_GPIO); | ||
116 | fmradio_i2c_bus = i2c_add_node(&fmradio_i2c); | ||
117 | } | ||
118 | |||
119 | int fmradio_i2c_write(unsigned char address, const unsigned char* buf, int count) | ||
120 | { | ||
121 | return i2c_write_data(fmradio_i2c_bus, address, -1, buf, count); | ||
122 | } | ||
123 | |||
124 | int fmradio_i2c_read(unsigned char address, unsigned char* buf, int count) | ||
125 | { | ||
126 | return i2c_read_data(fmradio_i2c_bus, address, -1, buf, count); | ||
127 | } | ||
128 | #else | ||
129 | #error Invalid value for IMX233_FMRADIO_I2C | ||
130 | #endif | ||
131 | |||
132 | static bool tuner_enable = false; | ||
133 | |||
134 | bool tuner_power(bool enable) | ||
135 | { | ||
136 | if(enable != tuner_enable) | ||
137 | { | ||
138 | tuner_enable = enable; | ||
139 | #if IMX233_FMRADIO_POWER == FMP_GPIO | ||
140 | static bool init = false; | ||
141 | if(!init) | ||
142 | { | ||
143 | /* CE is B0P29 (active high) */ | ||
144 | imx233_pinctrl_acquire(FMP_GPIO_BANK, FMP_GPIO_PIN, "tuner_power"); | ||
145 | imx233_pinctrl_set_function(FMP_GPIO_BANK, FMP_GPIO_PIN, PINCTRL_FUNCTION_GPIO); | ||
146 | imx233_pinctrl_enable_gpio(FMP_GPIO_BANK, FMP_GPIO_PIN, true); | ||
147 | } | ||
148 | imx233_pinctrl_set_gpio(FMP_GPIO_BANK, FMP_GPIO_PIN, enable); | ||
149 | /* power up delay */ | ||
150 | sleep(FMP_GPIO_DELAY); | ||
151 | #elif IMX233_FMRADIO_POWER == FMP_NONE | ||
152 | #else | ||
153 | #error Invalid value for IMX233_FMRADIO_POWER | ||
154 | #endif | ||
155 | } | ||
156 | return tuner_enable; | ||
157 | } | ||
158 | |||
159 | bool tuner_powered(void) | ||
160 | { | ||
161 | return tuner_enable; | ||
162 | } | ||