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.
18 #include <linux/delay.h>
20 #include "fmdrv_common.h"
23 int fm_tx_set_stereo_mono(struct fmdev
*fmdev
, u16 mode
)
28 if (fmdev
->tx_data
.aud_mode
== mode
)
31 fmdbg("stereo mode: %d\n", mode
);
33 /* Set Stereo/Mono mode */
35 ret
= fmc_send_cmd(fmdev
, MONO_SET
, REG_WR
, &payload
,
36 sizeof(payload
), NULL
, NULL
);
40 fmdev
->tx_data
.aud_mode
= mode
;
45 static int set_rds_text(struct fmdev
*fmdev
, u8
*rds_text
)
50 ret
= fmc_send_cmd(fmdev
, RDS_DATA_SET
, REG_WR
, rds_text
,
51 strlen(rds_text
), NULL
, NULL
);
57 ret
= fmc_send_cmd(fmdev
, DISPLAY_MODE
, REG_WR
, &payload
,
58 sizeof(payload
), NULL
, NULL
);
65 static int set_rds_data_mode(struct fmdev
*fmdev
, u8 mode
)
70 /* Setting unique PI TODO: how unique? */
71 payload
= (u16
)0xcafe;
72 ret
= fmc_send_cmd(fmdev
, PI_SET
, REG_WR
, &payload
,
73 sizeof(payload
), NULL
, NULL
);
79 ret
= fmc_send_cmd(fmdev
, DI_SET
, REG_WR
, &payload
,
80 sizeof(payload
), NULL
, NULL
);
84 /* TODO: RDS_MODE_GET? */
88 static int set_rds_len(struct fmdev
*fmdev
, u8 type
, u16 len
)
95 ret
= fmc_send_cmd(fmdev
, RDS_CONFIG_DATA_SET
, REG_WR
, &payload
,
96 sizeof(payload
), NULL
, NULL
);
100 /* TODO: LENGTH_GET? */
104 int fm_tx_set_rds_mode(struct fmdev
*fmdev
, u8 rds_en_dis
)
108 u8 rds_text
[] = "Zoom2\n";
110 fmdbg("rds_en_dis:%d(E:%d, D:%d)\n", rds_en_dis
,
111 FM_RDS_ENABLE
, FM_RDS_DISABLE
);
113 if (rds_en_dis
== FM_RDS_ENABLE
) {
115 set_rds_len(fmdev
, 0, strlen(rds_text
));
118 set_rds_text(fmdev
, rds_text
);
121 set_rds_data_mode(fmdev
, 0x0);
124 /* Send command to enable RDS */
125 if (rds_en_dis
== FM_RDS_ENABLE
)
130 ret
= fmc_send_cmd(fmdev
, RDS_DATA_ENB
, REG_WR
, &payload
,
131 sizeof(payload
), NULL
, NULL
);
135 if (rds_en_dis
== FM_RDS_ENABLE
) {
137 set_rds_len(fmdev
, 0, strlen(rds_text
));
140 set_rds_text(fmdev
, rds_text
);
142 fmdev
->tx_data
.rds
.flag
= rds_en_dis
;
147 int fm_tx_set_radio_text(struct fmdev
*fmdev
, u8
*rds_text
, u8 rds_type
)
152 if (fmdev
->curr_fmmode
!= FM_MODE_TX
)
155 fm_tx_set_rds_mode(fmdev
, 0);
158 set_rds_len(fmdev
, rds_type
, strlen(rds_text
));
161 set_rds_text(fmdev
, rds_text
);
164 set_rds_data_mode(fmdev
, 0x0);
167 ret
= fmc_send_cmd(fmdev
, RDS_DATA_ENB
, REG_WR
, &payload
,
168 sizeof(payload
), NULL
, NULL
);
175 int fm_tx_set_af(struct fmdev
*fmdev
, u32 af
)
180 if (fmdev
->curr_fmmode
!= FM_MODE_TX
)
183 fmdbg("AF: %d\n", af
);
185 af
= (af
- 87500) / 100;
187 ret
= fmc_send_cmd(fmdev
, TA_SET
, REG_WR
, &payload
,
188 sizeof(payload
), NULL
, NULL
);
195 int fm_tx_set_region(struct fmdev
*fmdev
, u8 region
)
200 if (region
!= FM_BAND_EUROPE_US
&& region
!= FM_BAND_JAPAN
) {
201 fmerr("Invalid band\n");
205 /* Send command to set the band */
206 payload
= (u16
)region
;
207 ret
= fmc_send_cmd(fmdev
, TX_BAND_SET
, REG_WR
, &payload
,
208 sizeof(payload
), NULL
, NULL
);
215 int fm_tx_set_mute_mode(struct fmdev
*fmdev
, u8 mute_mode_toset
)
220 fmdbg("tx: mute mode %d\n", mute_mode_toset
);
222 payload
= mute_mode_toset
;
223 ret
= fmc_send_cmd(fmdev
, MUTE
, REG_WR
, &payload
,
224 sizeof(payload
), NULL
, NULL
);
231 /* Set TX Audio I/O */
232 static int set_audio_io(struct fmdev
*fmdev
)
234 struct fmtx_data
*tx
= &fmdev
->tx_data
;
238 /* Set Audio I/O Enable */
239 payload
= tx
->audio_io
;
240 ret
= fmc_send_cmd(fmdev
, AUDIO_IO_SET
, REG_WR
, &payload
,
241 sizeof(payload
), NULL
, NULL
);
245 /* TODO: is audio set? */
249 /* Start TX Transmission */
250 static int enable_xmit(struct fmdev
*fmdev
, u8 new_xmit_state
)
252 struct fmtx_data
*tx
= &fmdev
->tx_data
;
253 unsigned long timeleft
;
257 /* Enable POWER_ENB interrupts */
258 payload
= FM_POW_ENB_EVENT
;
259 ret
= fmc_send_cmd(fmdev
, INT_MASK_SET
, REG_WR
, &payload
,
260 sizeof(payload
), NULL
, NULL
);
264 /* Set Power Enable */
265 payload
= new_xmit_state
;
266 ret
= fmc_send_cmd(fmdev
, POWER_ENB_SET
, REG_WR
, &payload
,
267 sizeof(payload
), NULL
, NULL
);
271 /* Wait for Power Enabled */
272 init_completion(&fmdev
->maintask_comp
);
273 timeleft
= wait_for_completion_timeout(&fmdev
->maintask_comp
,
276 fmerr("Timeout(%d sec),didn't get tune ended interrupt\n",
277 jiffies_to_msecs(FM_DRV_TX_TIMEOUT
) / 1000);
281 set_bit(FM_CORE_TX_XMITING
, &fmdev
->flag
);
282 tx
->xmit_state
= new_xmit_state
;
287 /* Set TX power level */
288 int fm_tx_set_pwr_lvl(struct fmdev
*fmdev
, u8 new_pwr_lvl
)
291 struct fmtx_data
*tx
= &fmdev
->tx_data
;
294 if (fmdev
->curr_fmmode
!= FM_MODE_TX
)
296 fmdbg("tx: pwr_level_to_set %ld\n", (long int)new_pwr_lvl
);
298 /* If the core isn't ready update global variable */
299 if (!test_bit(FM_CORE_READY
, &fmdev
->flag
)) {
300 tx
->pwr_lvl
= new_pwr_lvl
;
304 /* Set power level: Application will specify power level value in
305 * units of dB/uV, whereas range and step are specific to FM chip.
306 * For TI's WL chips, convert application specified power level value
307 * to chip specific value by subtracting 122 from it. Refer to TI FM
308 * data sheet for details.
311 payload
= (FM_PWR_LVL_HIGH
- new_pwr_lvl
);
312 ret
= fmc_send_cmd(fmdev
, POWER_LEV_SET
, REG_WR
, &payload
,
313 sizeof(payload
), NULL
, NULL
);
317 /* TODO: is the power level set? */
318 tx
->pwr_lvl
= new_pwr_lvl
;
324 * Sets FM TX pre-emphasis filter value (OFF, 50us, or 75us)
325 * Convert V4L2 specified filter values to chip specific filter values.
327 int fm_tx_set_preemph_filter(struct fmdev
*fmdev
, u32 preemphasis
)
329 struct fmtx_data
*tx
= &fmdev
->tx_data
;
333 if (fmdev
->curr_fmmode
!= FM_MODE_TX
)
336 switch (preemphasis
) {
337 case V4L2_PREEMPHASIS_DISABLED
:
338 payload
= FM_TX_PREEMPH_OFF
;
340 case V4L2_PREEMPHASIS_50_uS
:
341 payload
= FM_TX_PREEMPH_50US
;
343 case V4L2_PREEMPHASIS_75_uS
:
344 payload
= FM_TX_PREEMPH_75US
;
348 ret
= fmc_send_cmd(fmdev
, PREMPH_SET
, REG_WR
, &payload
,
349 sizeof(payload
), NULL
, NULL
);
353 tx
->preemph
= payload
;
358 /* Get the TX tuning capacitor value.*/
359 int fm_tx_get_tune_cap_val(struct fmdev
*fmdev
)
365 if (fmdev
->curr_fmmode
!= FM_MODE_TX
)
368 ret
= fmc_send_cmd(fmdev
, READ_FMANT_TUNE_VALUE
, REG_RD
,
369 NULL
, sizeof(curr_val
), &curr_val
, &resp_len
);
373 curr_val
= be16_to_cpu((__force __be16
)curr_val
);
378 /* Set TX Frequency */
379 int fm_tx_set_freq(struct fmdev
*fmdev
, u32 freq_to_set
)
381 struct fmtx_data
*tx
= &fmdev
->tx_data
;
382 u16 payload
, chanl_index
;
385 if (test_bit(FM_CORE_TX_XMITING
, &fmdev
->flag
)) {
386 enable_xmit(fmdev
, 0);
387 clear_bit(FM_CORE_TX_XMITING
, &fmdev
->flag
);
390 /* Enable FR, BL interrupts */
391 payload
= (FM_FR_EVENT
| FM_BL_EVENT
);
392 ret
= fmc_send_cmd(fmdev
, INT_MASK_SET
, REG_WR
, &payload
,
393 sizeof(payload
), NULL
, NULL
);
397 tx
->tx_frq
= (unsigned long)freq_to_set
;
398 fmdbg("tx: freq_to_set %ld\n", (long int)tx
->tx_frq
);
400 chanl_index
= freq_to_set
/ 10;
402 /* Set current tuner channel */
403 payload
= chanl_index
;
404 ret
= fmc_send_cmd(fmdev
, CHANL_SET
, REG_WR
, &payload
,
405 sizeof(payload
), NULL
, NULL
);
409 fm_tx_set_pwr_lvl(fmdev
, tx
->pwr_lvl
);
410 fm_tx_set_preemph_filter(fmdev
, tx
->preemph
);
412 tx
->audio_io
= 0x01; /* I2S */
415 enable_xmit(fmdev
, 0x01); /* Enable transmission */
417 tx
->aud_mode
= FM_STEREO_MODE
;
418 tx
->rds
.flag
= FM_RDS_DISABLE
;