sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / drivers / media / radio / wl128x / fmdrv_tx.c
blob839970b0f313522a31edfc0430f0d15652f47526
1 /*
2 * FM Driver for Connectivity chip of Texas Instruments.
3 * This sub-module of FM driver implements FM TX functionality.
5 * Copyright (C) 2011 Texas Instruments
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <linux/delay.h>
23 #include "fmdrv.h"
24 #include "fmdrv_common.h"
25 #include "fmdrv_tx.h"
27 int fm_tx_set_stereo_mono(struct fmdev *fmdev, u16 mode)
29 u16 payload;
30 int ret;
32 if (fmdev->tx_data.aud_mode == mode)
33 return 0;
35 fmdbg("stereo mode: %d\n", mode);
37 /* Set Stereo/Mono mode */
38 payload = (1 - mode);
39 ret = fmc_send_cmd(fmdev, MONO_SET, REG_WR, &payload,
40 sizeof(payload), NULL, NULL);
41 if (ret < 0)
42 return ret;
44 fmdev->tx_data.aud_mode = mode;
46 return ret;
49 static int set_rds_text(struct fmdev *fmdev, u8 *rds_text)
51 u16 payload;
52 int ret;
54 ret = fmc_send_cmd(fmdev, RDS_DATA_SET, REG_WR, rds_text,
55 strlen(rds_text), NULL, NULL);
56 if (ret < 0)
57 return ret;
59 /* Scroll mode */
60 payload = (u16)0x1;
61 ret = fmc_send_cmd(fmdev, DISPLAY_MODE, REG_WR, &payload,
62 sizeof(payload), NULL, NULL);
63 if (ret < 0)
64 return ret;
66 return 0;
69 static int set_rds_data_mode(struct fmdev *fmdev, u8 mode)
71 u16 payload;
72 int ret;
74 /* Setting unique PI TODO: how unique? */
75 payload = (u16)0xcafe;
76 ret = fmc_send_cmd(fmdev, PI_SET, REG_WR, &payload,
77 sizeof(payload), NULL, NULL);
78 if (ret < 0)
79 return ret;
81 /* Set decoder id */
82 payload = (u16)0xa;
83 ret = fmc_send_cmd(fmdev, DI_SET, REG_WR, &payload,
84 sizeof(payload), NULL, NULL);
85 if (ret < 0)
86 return ret;
88 /* TODO: RDS_MODE_GET? */
89 return 0;
92 static int set_rds_len(struct fmdev *fmdev, u8 type, u16 len)
94 u16 payload;
95 int ret;
97 len |= type << 8;
98 payload = len;
99 ret = fmc_send_cmd(fmdev, RDS_CONFIG_DATA_SET, REG_WR, &payload,
100 sizeof(payload), NULL, NULL);
101 if (ret < 0)
102 return ret;
104 /* TODO: LENGTH_GET? */
105 return 0;
108 int fm_tx_set_rds_mode(struct fmdev *fmdev, u8 rds_en_dis)
110 u16 payload;
111 int ret;
112 u8 rds_text[] = "Zoom2\n";
114 fmdbg("rds_en_dis:%d(E:%d, D:%d)\n", rds_en_dis,
115 FM_RDS_ENABLE, FM_RDS_DISABLE);
117 if (rds_en_dis == FM_RDS_ENABLE) {
118 /* Set RDS length */
119 set_rds_len(fmdev, 0, strlen(rds_text));
121 /* Set RDS text */
122 set_rds_text(fmdev, rds_text);
124 /* Set RDS mode */
125 set_rds_data_mode(fmdev, 0x0);
128 /* Send command to enable RDS */
129 if (rds_en_dis == FM_RDS_ENABLE)
130 payload = 0x01;
131 else
132 payload = 0x00;
134 ret = fmc_send_cmd(fmdev, RDS_DATA_ENB, REG_WR, &payload,
135 sizeof(payload), NULL, NULL);
136 if (ret < 0)
137 return ret;
139 if (rds_en_dis == FM_RDS_ENABLE) {
140 /* Set RDS length */
141 set_rds_len(fmdev, 0, strlen(rds_text));
143 /* Set RDS text */
144 set_rds_text(fmdev, rds_text);
146 fmdev->tx_data.rds.flag = rds_en_dis;
148 return 0;
151 int fm_tx_set_radio_text(struct fmdev *fmdev, u8 *rds_text, u8 rds_type)
153 u16 payload;
154 int ret;
156 if (fmdev->curr_fmmode != FM_MODE_TX)
157 return -EPERM;
159 fm_tx_set_rds_mode(fmdev, 0);
161 /* Set RDS length */
162 set_rds_len(fmdev, rds_type, strlen(rds_text));
164 /* Set RDS text */
165 set_rds_text(fmdev, rds_text);
167 /* Set RDS mode */
168 set_rds_data_mode(fmdev, 0x0);
170 payload = 1;
171 ret = fmc_send_cmd(fmdev, RDS_DATA_ENB, REG_WR, &payload,
172 sizeof(payload), NULL, NULL);
173 if (ret < 0)
174 return ret;
176 return 0;
179 int fm_tx_set_af(struct fmdev *fmdev, u32 af)
181 u16 payload;
182 int ret;
184 if (fmdev->curr_fmmode != FM_MODE_TX)
185 return -EPERM;
187 fmdbg("AF: %d\n", af);
189 af = (af - 87500) / 100;
190 payload = (u16)af;
191 ret = fmc_send_cmd(fmdev, TA_SET, REG_WR, &payload,
192 sizeof(payload), NULL, NULL);
193 if (ret < 0)
194 return ret;
196 return 0;
199 int fm_tx_set_region(struct fmdev *fmdev, u8 region)
201 u16 payload;
202 int ret;
204 if (region != FM_BAND_EUROPE_US && region != FM_BAND_JAPAN) {
205 fmerr("Invalid band\n");
206 return -EINVAL;
209 /* Send command to set the band */
210 payload = (u16)region;
211 ret = fmc_send_cmd(fmdev, TX_BAND_SET, REG_WR, &payload,
212 sizeof(payload), NULL, NULL);
213 if (ret < 0)
214 return ret;
216 return 0;
219 int fm_tx_set_mute_mode(struct fmdev *fmdev, u8 mute_mode_toset)
221 u16 payload;
222 int ret;
224 fmdbg("tx: mute mode %d\n", mute_mode_toset);
226 payload = mute_mode_toset;
227 ret = fmc_send_cmd(fmdev, MUTE, REG_WR, &payload,
228 sizeof(payload), NULL, NULL);
229 if (ret < 0)
230 return ret;
232 return 0;
235 /* Set TX Audio I/O */
236 static int set_audio_io(struct fmdev *fmdev)
238 struct fmtx_data *tx = &fmdev->tx_data;
239 u16 payload;
240 int ret;
242 /* Set Audio I/O Enable */
243 payload = tx->audio_io;
244 ret = fmc_send_cmd(fmdev, AUDIO_IO_SET, REG_WR, &payload,
245 sizeof(payload), NULL, NULL);
246 if (ret < 0)
247 return ret;
249 /* TODO: is audio set? */
250 return 0;
253 /* Start TX Transmission */
254 static int enable_xmit(struct fmdev *fmdev, u8 new_xmit_state)
256 struct fmtx_data *tx = &fmdev->tx_data;
257 unsigned long timeleft;
258 u16 payload;
259 int ret;
261 /* Enable POWER_ENB interrupts */
262 payload = FM_POW_ENB_EVENT;
263 ret = fmc_send_cmd(fmdev, INT_MASK_SET, REG_WR, &payload,
264 sizeof(payload), NULL, NULL);
265 if (ret < 0)
266 return ret;
268 /* Set Power Enable */
269 payload = new_xmit_state;
270 ret = fmc_send_cmd(fmdev, POWER_ENB_SET, REG_WR, &payload,
271 sizeof(payload), NULL, NULL);
272 if (ret < 0)
273 return ret;
275 /* Wait for Power Enabled */
276 init_completion(&fmdev->maintask_comp);
277 timeleft = wait_for_completion_timeout(&fmdev->maintask_comp,
278 FM_DRV_TX_TIMEOUT);
279 if (!timeleft) {
280 fmerr("Timeout(%d sec),didn't get tune ended interrupt\n",
281 jiffies_to_msecs(FM_DRV_TX_TIMEOUT) / 1000);
282 return -ETIMEDOUT;
285 set_bit(FM_CORE_TX_XMITING, &fmdev->flag);
286 tx->xmit_state = new_xmit_state;
288 return 0;
291 /* Set TX power level */
292 int fm_tx_set_pwr_lvl(struct fmdev *fmdev, u8 new_pwr_lvl)
294 u16 payload;
295 struct fmtx_data *tx = &fmdev->tx_data;
296 int ret;
298 if (fmdev->curr_fmmode != FM_MODE_TX)
299 return -EPERM;
300 fmdbg("tx: pwr_level_to_set %ld\n", (long int)new_pwr_lvl);
302 /* If the core isn't ready update global variable */
303 if (!test_bit(FM_CORE_READY, &fmdev->flag)) {
304 tx->pwr_lvl = new_pwr_lvl;
305 return 0;
308 /* Set power level: Application will specify power level value in
309 * units of dB/uV, whereas range and step are specific to FM chip.
310 * For TI's WL chips, convert application specified power level value
311 * to chip specific value by subtracting 122 from it. Refer to TI FM
312 * data sheet for details.
313 * */
315 payload = (FM_PWR_LVL_HIGH - new_pwr_lvl);
316 ret = fmc_send_cmd(fmdev, POWER_LEV_SET, REG_WR, &payload,
317 sizeof(payload), NULL, NULL);
318 if (ret < 0)
319 return ret;
321 /* TODO: is the power level set? */
322 tx->pwr_lvl = new_pwr_lvl;
324 return 0;
328 * Sets FM TX pre-emphasis filter value (OFF, 50us, or 75us)
329 * Convert V4L2 specified filter values to chip specific filter values.
331 int fm_tx_set_preemph_filter(struct fmdev *fmdev, u32 preemphasis)
333 struct fmtx_data *tx = &fmdev->tx_data;
334 u16 payload;
335 int ret;
337 if (fmdev->curr_fmmode != FM_MODE_TX)
338 return -EPERM;
340 switch (preemphasis) {
341 case V4L2_PREEMPHASIS_DISABLED:
342 payload = FM_TX_PREEMPH_OFF;
343 break;
344 case V4L2_PREEMPHASIS_50_uS:
345 payload = FM_TX_PREEMPH_50US;
346 break;
347 case V4L2_PREEMPHASIS_75_uS:
348 payload = FM_TX_PREEMPH_75US;
349 break;
352 ret = fmc_send_cmd(fmdev, PREMPH_SET, REG_WR, &payload,
353 sizeof(payload), NULL, NULL);
354 if (ret < 0)
355 return ret;
357 tx->preemph = payload;
359 return ret;
362 /* Get the TX tuning capacitor value.*/
363 int fm_tx_get_tune_cap_val(struct fmdev *fmdev)
365 u16 curr_val;
366 u32 resp_len;
367 int ret;
369 if (fmdev->curr_fmmode != FM_MODE_TX)
370 return -EPERM;
372 ret = fmc_send_cmd(fmdev, READ_FMANT_TUNE_VALUE, REG_RD,
373 NULL, sizeof(curr_val), &curr_val, &resp_len);
374 if (ret < 0)
375 return ret;
377 curr_val = be16_to_cpu((__force __be16)curr_val);
379 return curr_val;
382 /* Set TX Frequency */
383 int fm_tx_set_freq(struct fmdev *fmdev, u32 freq_to_set)
385 struct fmtx_data *tx = &fmdev->tx_data;
386 u16 payload, chanl_index;
387 int ret;
389 if (test_bit(FM_CORE_TX_XMITING, &fmdev->flag)) {
390 enable_xmit(fmdev, 0);
391 clear_bit(FM_CORE_TX_XMITING, &fmdev->flag);
394 /* Enable FR, BL interrupts */
395 payload = (FM_FR_EVENT | FM_BL_EVENT);
396 ret = fmc_send_cmd(fmdev, INT_MASK_SET, REG_WR, &payload,
397 sizeof(payload), NULL, NULL);
398 if (ret < 0)
399 return ret;
401 tx->tx_frq = (unsigned long)freq_to_set;
402 fmdbg("tx: freq_to_set %ld\n", (long int)tx->tx_frq);
404 chanl_index = freq_to_set / 10;
406 /* Set current tuner channel */
407 payload = chanl_index;
408 ret = fmc_send_cmd(fmdev, CHANL_SET, REG_WR, &payload,
409 sizeof(payload), NULL, NULL);
410 if (ret < 0)
411 return ret;
413 fm_tx_set_pwr_lvl(fmdev, tx->pwr_lvl);
414 fm_tx_set_preemph_filter(fmdev, tx->preemph);
416 tx->audio_io = 0x01; /* I2S */
417 set_audio_io(fmdev);
419 enable_xmit(fmdev, 0x01); /* Enable transmission */
421 tx->aud_mode = FM_STEREO_MODE;
422 tx->rds.flag = FM_RDS_DISABLE;
424 return 0;