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>
24 #include "fmdrv_common.h"
27 u32
fm_tx_set_stereo_mono(struct fmdev
*fmdev
, u16 mode
)
32 if (fmdev
->tx_data
.aud_mode
== mode
)
35 fmdbg("stereo mode: %d\n", mode
);
37 /* Set Stereo/Mono mode */
39 ret
= fmc_send_cmd(fmdev
, MONO_SET
, REG_WR
, &payload
,
40 sizeof(payload
), NULL
, NULL
);
44 fmdev
->tx_data
.aud_mode
= mode
;
49 static u32
set_rds_text(struct fmdev
*fmdev
, u8
*rds_text
)
54 ret
= fmc_send_cmd(fmdev
, RDS_DATA_SET
, REG_WR
, rds_text
,
55 strlen(rds_text
), NULL
, NULL
);
61 ret
= fmc_send_cmd(fmdev
, DISPLAY_MODE
, REG_WR
, &payload
,
62 sizeof(payload
), NULL
, NULL
);
69 static u32
set_rds_data_mode(struct fmdev
*fmdev
, u8 mode
)
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
);
83 ret
= fmc_send_cmd(fmdev
, DI_SET
, REG_WR
, &payload
,
84 sizeof(payload
), NULL
, NULL
);
88 /* TODO: RDS_MODE_GET? */
92 static u32
set_rds_len(struct fmdev
*fmdev
, u8 type
, u16 len
)
99 ret
= fmc_send_cmd(fmdev
, RDS_CONFIG_DATA_SET
, REG_WR
, &payload
,
100 sizeof(payload
), NULL
, NULL
);
104 /* TODO: LENGTH_GET? */
108 u32
fm_tx_set_rds_mode(struct fmdev
*fmdev
, u8 rds_en_dis
)
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
) {
119 set_rds_len(fmdev
, 0, strlen(rds_text
));
122 set_rds_text(fmdev
, rds_text
);
125 set_rds_data_mode(fmdev
, 0x0);
128 /* Send command to enable RDS */
129 if (rds_en_dis
== FM_RDS_ENABLE
)
134 ret
= fmc_send_cmd(fmdev
, RDS_DATA_ENB
, REG_WR
, &payload
,
135 sizeof(payload
), NULL
, NULL
);
139 if (rds_en_dis
== FM_RDS_ENABLE
) {
141 set_rds_len(fmdev
, 0, strlen(rds_text
));
144 set_rds_text(fmdev
, rds_text
);
146 fmdev
->tx_data
.rds
.flag
= rds_en_dis
;
151 u32
fm_tx_set_radio_text(struct fmdev
*fmdev
, u8
*rds_text
, u8 rds_type
)
156 if (fmdev
->curr_fmmode
!= FM_MODE_TX
)
159 fm_tx_set_rds_mode(fmdev
, 0);
162 set_rds_len(fmdev
, rds_type
, strlen(rds_text
));
165 set_rds_text(fmdev
, rds_text
);
168 set_rds_data_mode(fmdev
, 0x0);
171 ret
= fmc_send_cmd(fmdev
, RDS_DATA_ENB
, REG_WR
, &payload
,
172 sizeof(payload
), NULL
, NULL
);
179 u32
fm_tx_set_af(struct fmdev
*fmdev
, u32 af
)
184 if (fmdev
->curr_fmmode
!= FM_MODE_TX
)
187 fmdbg("AF: %d\n", af
);
189 af
= (af
- 87500) / 100;
191 ret
= fmc_send_cmd(fmdev
, TA_SET
, REG_WR
, &payload
,
192 sizeof(payload
), NULL
, NULL
);
199 u32
fm_tx_set_region(struct fmdev
*fmdev
, u8 region
)
204 if (region
!= FM_BAND_EUROPE_US
&& region
!= FM_BAND_JAPAN
) {
205 fmerr("Invalid band\n");
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
);
219 u32
fm_tx_set_mute_mode(struct fmdev
*fmdev
, u8 mute_mode_toset
)
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
);
235 /* Set TX Audio I/O */
236 static u32
set_audio_io(struct fmdev
*fmdev
)
238 struct fmtx_data
*tx
= &fmdev
->tx_data
;
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
);
249 /* TODO: is audio set? */
253 /* Start TX Transmission */
254 static u32
enable_xmit(struct fmdev
*fmdev
, u8 new_xmit_state
)
256 struct fmtx_data
*tx
= &fmdev
->tx_data
;
257 unsigned long timeleft
;
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
);
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
);
275 /* Wait for Power Enabled */
276 init_completion(&fmdev
->maintask_comp
);
277 timeleft
= wait_for_completion_timeout(&fmdev
->maintask_comp
,
280 fmerr("Timeout(%d sec),didn't get tune ended interrupt\n",
281 jiffies_to_msecs(FM_DRV_TX_TIMEOUT
) / 1000);
285 set_bit(FM_CORE_TX_XMITING
, &fmdev
->flag
);
286 tx
->xmit_state
= new_xmit_state
;
291 /* Set TX power level */
292 u32
fm_tx_set_pwr_lvl(struct fmdev
*fmdev
, u8 new_pwr_lvl
)
295 struct fmtx_data
*tx
= &fmdev
->tx_data
;
298 if (fmdev
->curr_fmmode
!= FM_MODE_TX
)
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
;
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.
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
);
321 /* TODO: is the power level set? */
322 tx
->pwr_lvl
= new_pwr_lvl
;
328 * Sets FM TX pre-emphasis filter value (OFF, 50us, or 75us)
329 * Convert V4L2 specified filter values to chip specific filter values.
331 u32
fm_tx_set_preemph_filter(struct fmdev
*fmdev
, u32 preemphasis
)
333 struct fmtx_data
*tx
= &fmdev
->tx_data
;
337 if (fmdev
->curr_fmmode
!= FM_MODE_TX
)
340 switch (preemphasis
) {
341 case V4L2_PREEMPHASIS_DISABLED
:
342 payload
= FM_TX_PREEMPH_OFF
;
344 case V4L2_PREEMPHASIS_50_uS
:
345 payload
= FM_TX_PREEMPH_50US
;
347 case V4L2_PREEMPHASIS_75_uS
:
348 payload
= FM_TX_PREEMPH_75US
;
352 ret
= fmc_send_cmd(fmdev
, PREMPH_SET
, REG_WR
, &payload
,
353 sizeof(payload
), NULL
, NULL
);
357 tx
->preemph
= payload
;
362 /* Get the TX tuning capacitor value.*/
363 u32
fm_tx_get_tune_cap_val(struct fmdev
*fmdev
)
368 if (fmdev
->curr_fmmode
!= FM_MODE_TX
)
371 ret
= fmc_send_cmd(fmdev
, READ_FMANT_TUNE_VALUE
, REG_RD
,
372 NULL
, sizeof(curr_val
), &curr_val
, &resp_len
);
376 curr_val
= be16_to_cpu(curr_val
);
381 /* Set TX Frequency */
382 u32
fm_tx_set_freq(struct fmdev
*fmdev
, u32 freq_to_set
)
384 struct fmtx_data
*tx
= &fmdev
->tx_data
;
385 u16 payload
, chanl_index
;
388 if (test_bit(FM_CORE_TX_XMITING
, &fmdev
->flag
)) {
389 enable_xmit(fmdev
, 0);
390 clear_bit(FM_CORE_TX_XMITING
, &fmdev
->flag
);
393 /* Enable FR, BL interrupts */
394 payload
= (FM_FR_EVENT
| FM_BL_EVENT
);
395 ret
= fmc_send_cmd(fmdev
, INT_MASK_SET
, REG_WR
, &payload
,
396 sizeof(payload
), NULL
, NULL
);
400 tx
->tx_frq
= (unsigned long)freq_to_set
;
401 fmdbg("tx: freq_to_set %ld\n", (long int)tx
->tx_frq
);
403 chanl_index
= freq_to_set
/ 10;
405 /* Set current tuner channel */
406 payload
= chanl_index
;
407 ret
= fmc_send_cmd(fmdev
, CHANL_SET
, REG_WR
, &payload
,
408 sizeof(payload
), NULL
, NULL
);
412 fm_tx_set_pwr_lvl(fmdev
, tx
->pwr_lvl
);
413 fm_tx_set_preemph_filter(fmdev
, tx
->preemph
);
415 tx
->audio_io
= 0x01; /* I2S */
418 enable_xmit(fmdev
, 0x01); /* Enable transmission */
420 tx
->aud_mode
= FM_STEREO_MODE
;
421 tx
->rds
.flag
= FM_RDS_DISABLE
;