1 // SPDX-License-Identifier: GPL-2.0-only
3 * FM Driver for Connectivity chip of Texas Instruments.
4 * This sub-module of FM driver implements FM TX functionality.
6 * Copyright (C) 2011 Texas Instruments
9 #include <linux/delay.h>
11 #include "fmdrv_common.h"
14 int fm_tx_set_stereo_mono(struct fmdev
*fmdev
, u16 mode
)
19 if (fmdev
->tx_data
.aud_mode
== mode
)
22 fmdbg("stereo mode: %d\n", mode
);
24 /* Set Stereo/Mono mode */
26 ret
= fmc_send_cmd(fmdev
, MONO_SET
, REG_WR
, &payload
,
27 sizeof(payload
), NULL
, NULL
);
31 fmdev
->tx_data
.aud_mode
= mode
;
36 static int set_rds_text(struct fmdev
*fmdev
, u8
*rds_text
)
41 ret
= fmc_send_cmd(fmdev
, RDS_DATA_SET
, REG_WR
, rds_text
,
42 strlen(rds_text
), NULL
, NULL
);
48 ret
= fmc_send_cmd(fmdev
, DISPLAY_MODE
, REG_WR
, &payload
,
49 sizeof(payload
), NULL
, NULL
);
56 static int set_rds_data_mode(struct fmdev
*fmdev
, u8 mode
)
61 /* Setting unique PI TODO: how unique? */
62 payload
= (u16
)0xcafe;
63 ret
= fmc_send_cmd(fmdev
, PI_SET
, REG_WR
, &payload
,
64 sizeof(payload
), NULL
, NULL
);
70 ret
= fmc_send_cmd(fmdev
, DI_SET
, REG_WR
, &payload
,
71 sizeof(payload
), NULL
, NULL
);
75 /* TODO: RDS_MODE_GET? */
79 static int set_rds_len(struct fmdev
*fmdev
, u8 type
, u16 len
)
86 ret
= fmc_send_cmd(fmdev
, RDS_CONFIG_DATA_SET
, REG_WR
, &payload
,
87 sizeof(payload
), NULL
, NULL
);
91 /* TODO: LENGTH_GET? */
95 int fm_tx_set_rds_mode(struct fmdev
*fmdev
, u8 rds_en_dis
)
99 u8 rds_text
[] = "Zoom2\n";
101 fmdbg("rds_en_dis:%d(E:%d, D:%d)\n", rds_en_dis
,
102 FM_RDS_ENABLE
, FM_RDS_DISABLE
);
104 if (rds_en_dis
== FM_RDS_ENABLE
) {
106 set_rds_len(fmdev
, 0, strlen(rds_text
));
109 set_rds_text(fmdev
, rds_text
);
112 set_rds_data_mode(fmdev
, 0x0);
115 /* Send command to enable RDS */
116 if (rds_en_dis
== FM_RDS_ENABLE
)
121 ret
= fmc_send_cmd(fmdev
, RDS_DATA_ENB
, REG_WR
, &payload
,
122 sizeof(payload
), NULL
, NULL
);
126 if (rds_en_dis
== FM_RDS_ENABLE
) {
128 set_rds_len(fmdev
, 0, strlen(rds_text
));
131 set_rds_text(fmdev
, rds_text
);
133 fmdev
->tx_data
.rds
.flag
= rds_en_dis
;
138 int fm_tx_set_radio_text(struct fmdev
*fmdev
, u8
*rds_text
, u8 rds_type
)
143 if (fmdev
->curr_fmmode
!= FM_MODE_TX
)
146 fm_tx_set_rds_mode(fmdev
, 0);
149 set_rds_len(fmdev
, rds_type
, strlen(rds_text
));
152 set_rds_text(fmdev
, rds_text
);
155 set_rds_data_mode(fmdev
, 0x0);
158 ret
= fmc_send_cmd(fmdev
, RDS_DATA_ENB
, REG_WR
, &payload
,
159 sizeof(payload
), NULL
, NULL
);
166 int fm_tx_set_af(struct fmdev
*fmdev
, u32 af
)
171 if (fmdev
->curr_fmmode
!= FM_MODE_TX
)
174 fmdbg("AF: %d\n", af
);
176 af
= (af
- 87500) / 100;
178 ret
= fmc_send_cmd(fmdev
, TA_SET
, REG_WR
, &payload
,
179 sizeof(payload
), NULL
, NULL
);
186 int fm_tx_set_region(struct fmdev
*fmdev
, u8 region
)
191 if (region
!= FM_BAND_EUROPE_US
&& region
!= FM_BAND_JAPAN
) {
192 fmerr("Invalid band\n");
196 /* Send command to set the band */
197 payload
= (u16
)region
;
198 ret
= fmc_send_cmd(fmdev
, TX_BAND_SET
, REG_WR
, &payload
,
199 sizeof(payload
), NULL
, NULL
);
206 int fm_tx_set_mute_mode(struct fmdev
*fmdev
, u8 mute_mode_toset
)
211 fmdbg("tx: mute mode %d\n", mute_mode_toset
);
213 payload
= mute_mode_toset
;
214 ret
= fmc_send_cmd(fmdev
, MUTE
, REG_WR
, &payload
,
215 sizeof(payload
), NULL
, NULL
);
222 /* Set TX Audio I/O */
223 static int set_audio_io(struct fmdev
*fmdev
)
225 struct fmtx_data
*tx
= &fmdev
->tx_data
;
229 /* Set Audio I/O Enable */
230 payload
= tx
->audio_io
;
231 ret
= fmc_send_cmd(fmdev
, AUDIO_IO_SET
, REG_WR
, &payload
,
232 sizeof(payload
), NULL
, NULL
);
236 /* TODO: is audio set? */
240 /* Start TX Transmission */
241 static int enable_xmit(struct fmdev
*fmdev
, u8 new_xmit_state
)
243 struct fmtx_data
*tx
= &fmdev
->tx_data
;
244 unsigned long timeleft
;
248 /* Enable POWER_ENB interrupts */
249 payload
= FM_POW_ENB_EVENT
;
250 ret
= fmc_send_cmd(fmdev
, INT_MASK_SET
, REG_WR
, &payload
,
251 sizeof(payload
), NULL
, NULL
);
255 /* Set Power Enable */
256 payload
= new_xmit_state
;
257 ret
= fmc_send_cmd(fmdev
, POWER_ENB_SET
, REG_WR
, &payload
,
258 sizeof(payload
), NULL
, NULL
);
262 /* Wait for Power Enabled */
263 init_completion(&fmdev
->maintask_comp
);
264 timeleft
= wait_for_completion_timeout(&fmdev
->maintask_comp
,
267 fmerr("Timeout(%d sec),didn't get tune ended interrupt\n",
268 jiffies_to_msecs(FM_DRV_TX_TIMEOUT
) / 1000);
272 set_bit(FM_CORE_TX_XMITING
, &fmdev
->flag
);
273 tx
->xmit_state
= new_xmit_state
;
278 /* Set TX power level */
279 int fm_tx_set_pwr_lvl(struct fmdev
*fmdev
, u8 new_pwr_lvl
)
282 struct fmtx_data
*tx
= &fmdev
->tx_data
;
285 if (fmdev
->curr_fmmode
!= FM_MODE_TX
)
287 fmdbg("tx: pwr_level_to_set %ld\n", (long int)new_pwr_lvl
);
289 /* If the core isn't ready update global variable */
290 if (!test_bit(FM_CORE_READY
, &fmdev
->flag
)) {
291 tx
->pwr_lvl
= new_pwr_lvl
;
295 /* Set power level: Application will specify power level value in
296 * units of dB/uV, whereas range and step are specific to FM chip.
297 * For TI's WL chips, convert application specified power level value
298 * to chip specific value by subtracting 122 from it. Refer to TI FM
299 * data sheet for details.
302 payload
= (FM_PWR_LVL_HIGH
- new_pwr_lvl
);
303 ret
= fmc_send_cmd(fmdev
, POWER_LEV_SET
, REG_WR
, &payload
,
304 sizeof(payload
), NULL
, NULL
);
308 /* TODO: is the power level set? */
309 tx
->pwr_lvl
= new_pwr_lvl
;
315 * Sets FM TX pre-emphasis filter value (OFF, 50us, or 75us)
316 * Convert V4L2 specified filter values to chip specific filter values.
318 int fm_tx_set_preemph_filter(struct fmdev
*fmdev
, u32 preemphasis
)
320 struct fmtx_data
*tx
= &fmdev
->tx_data
;
324 if (fmdev
->curr_fmmode
!= FM_MODE_TX
)
327 switch (preemphasis
) {
328 case V4L2_PREEMPHASIS_DISABLED
:
329 payload
= FM_TX_PREEMPH_OFF
;
331 case V4L2_PREEMPHASIS_50_uS
:
332 payload
= FM_TX_PREEMPH_50US
;
334 case V4L2_PREEMPHASIS_75_uS
:
335 payload
= FM_TX_PREEMPH_75US
;
339 ret
= fmc_send_cmd(fmdev
, PREMPH_SET
, REG_WR
, &payload
,
340 sizeof(payload
), NULL
, NULL
);
344 tx
->preemph
= payload
;
349 /* Get the TX tuning capacitor value.*/
350 int fm_tx_get_tune_cap_val(struct fmdev
*fmdev
)
356 if (fmdev
->curr_fmmode
!= FM_MODE_TX
)
359 ret
= fmc_send_cmd(fmdev
, READ_FMANT_TUNE_VALUE
, REG_RD
,
360 NULL
, sizeof(curr_val
), &curr_val
, &resp_len
);
364 curr_val
= be16_to_cpu((__force __be16
)curr_val
);
369 /* Set TX Frequency */
370 int fm_tx_set_freq(struct fmdev
*fmdev
, u32 freq_to_set
)
372 struct fmtx_data
*tx
= &fmdev
->tx_data
;
373 u16 payload
, chanl_index
;
376 if (test_bit(FM_CORE_TX_XMITING
, &fmdev
->flag
)) {
377 enable_xmit(fmdev
, 0);
378 clear_bit(FM_CORE_TX_XMITING
, &fmdev
->flag
);
381 /* Enable FR, BL interrupts */
382 payload
= (FM_FR_EVENT
| FM_BL_EVENT
);
383 ret
= fmc_send_cmd(fmdev
, INT_MASK_SET
, REG_WR
, &payload
,
384 sizeof(payload
), NULL
, NULL
);
388 tx
->tx_frq
= (unsigned long)freq_to_set
;
389 fmdbg("tx: freq_to_set %ld\n", (long int)tx
->tx_frq
);
391 chanl_index
= freq_to_set
/ 10;
393 /* Set current tuner channel */
394 payload
= chanl_index
;
395 ret
= fmc_send_cmd(fmdev
, CHANL_SET
, REG_WR
, &payload
,
396 sizeof(payload
), NULL
, NULL
);
400 fm_tx_set_pwr_lvl(fmdev
, tx
->pwr_lvl
);
401 fm_tx_set_preemph_filter(fmdev
, tx
->preemph
);
403 tx
->audio_io
= 0x01; /* I2S */
406 enable_xmit(fmdev
, 0x01); /* Enable transmission */
408 tx
->aud_mode
= FM_STEREO_MODE
;
409 tx
->rds
.flag
= FM_RDS_DISABLE
;