1*1802d0beSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
259da522aSManjunatha Halli /*
359da522aSManjunatha Halli * FM Driver for Connectivity chip of Texas Instruments.
459da522aSManjunatha Halli * This sub-module of FM driver implements FM RX functionality.
559da522aSManjunatha Halli *
659da522aSManjunatha Halli * Copyright (C) 2011 Texas Instruments
759da522aSManjunatha Halli * Author: Raja Mani <raja_mani@ti.com>
859da522aSManjunatha Halli * Author: Manjunatha Halli <manjunatha_halli@ti.com>
959da522aSManjunatha Halli */
1059da522aSManjunatha Halli
1159da522aSManjunatha Halli #include "fmdrv.h"
1259da522aSManjunatha Halli #include "fmdrv_common.h"
1359da522aSManjunatha Halli #include "fmdrv_rx.h"
1459da522aSManjunatha Halli
fm_rx_reset_rds_cache(struct fmdev * fmdev)1559da522aSManjunatha Halli void fm_rx_reset_rds_cache(struct fmdev *fmdev)
1659da522aSManjunatha Halli {
1759da522aSManjunatha Halli fmdev->rx.rds.flag = FM_RDS_DISABLE;
1859da522aSManjunatha Halli fmdev->rx.rds.last_blk_idx = 0;
1959da522aSManjunatha Halli fmdev->rx.rds.wr_idx = 0;
2059da522aSManjunatha Halli fmdev->rx.rds.rd_idx = 0;
2159da522aSManjunatha Halli
2259da522aSManjunatha Halli if (fmdev->rx.af_mode == FM_RX_RDS_AF_SWITCH_MODE_ON)
2359da522aSManjunatha Halli fmdev->irq_info.mask |= FM_LEV_EVENT;
2459da522aSManjunatha Halli }
2559da522aSManjunatha Halli
fm_rx_reset_station_info(struct fmdev * fmdev)2659da522aSManjunatha Halli void fm_rx_reset_station_info(struct fmdev *fmdev)
2759da522aSManjunatha Halli {
2859da522aSManjunatha Halli fmdev->rx.stat_info.picode = FM_NO_PI_CODE;
2959da522aSManjunatha Halli fmdev->rx.stat_info.afcache_size = 0;
3059da522aSManjunatha Halli fmdev->rx.stat_info.af_list_max = 0;
3159da522aSManjunatha Halli }
3259da522aSManjunatha Halli
fm_rx_set_freq(struct fmdev * fmdev,u32 freq)33d24674c6SXi Wang int fm_rx_set_freq(struct fmdev *fmdev, u32 freq)
3459da522aSManjunatha Halli {
3559da522aSManjunatha Halli unsigned long timeleft;
3659da522aSManjunatha Halli u16 payload, curr_frq, intr_flag;
3759da522aSManjunatha Halli u32 curr_frq_in_khz;
38d24674c6SXi Wang u32 resp_len;
39d24674c6SXi Wang int ret;
4059da522aSManjunatha Halli
4159da522aSManjunatha Halli if (freq < fmdev->rx.region.bot_freq || freq > fmdev->rx.region.top_freq) {
4259da522aSManjunatha Halli fmerr("Invalid frequency %d\n", freq);
4359da522aSManjunatha Halli return -EINVAL;
4459da522aSManjunatha Halli }
4559da522aSManjunatha Halli
4659da522aSManjunatha Halli /* Set audio enable */
4759da522aSManjunatha Halli payload = FM_RX_AUDIO_ENABLE_I2S_AND_ANALOG;
4859da522aSManjunatha Halli
4959da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, AUDIO_ENABLE_SET, REG_WR, &payload,
5059da522aSManjunatha Halli sizeof(payload), NULL, NULL);
5159da522aSManjunatha Halli if (ret < 0)
5259da522aSManjunatha Halli return ret;
5359da522aSManjunatha Halli
5459da522aSManjunatha Halli /* Set hilo to automatic selection */
5559da522aSManjunatha Halli payload = FM_RX_IFFREQ_HILO_AUTOMATIC;
5659da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, HILO_SET, REG_WR, &payload,
5759da522aSManjunatha Halli sizeof(payload), NULL, NULL);
5859da522aSManjunatha Halli if (ret < 0)
5959da522aSManjunatha Halli return ret;
6059da522aSManjunatha Halli
6159da522aSManjunatha Halli /* Calculate frequency index and set*/
6259da522aSManjunatha Halli payload = (freq - fmdev->rx.region.bot_freq) / FM_FREQ_MUL;
6359da522aSManjunatha Halli
6459da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, FREQ_SET, REG_WR, &payload,
6559da522aSManjunatha Halli sizeof(payload), NULL, NULL);
6659da522aSManjunatha Halli if (ret < 0)
6759da522aSManjunatha Halli return ret;
6859da522aSManjunatha Halli
6959da522aSManjunatha Halli /* Read flags - just to clear any pending interrupts if we had */
7059da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, FLAG_GET, REG_RD, NULL, 2, NULL, NULL);
7159da522aSManjunatha Halli if (ret < 0)
7259da522aSManjunatha Halli return ret;
7359da522aSManjunatha Halli
7459da522aSManjunatha Halli /* Enable FR, BL interrupts */
7559da522aSManjunatha Halli intr_flag = fmdev->irq_info.mask;
7659da522aSManjunatha Halli fmdev->irq_info.mask = (FM_FR_EVENT | FM_BL_EVENT);
7759da522aSManjunatha Halli payload = fmdev->irq_info.mask;
7859da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, INT_MASK_SET, REG_WR, &payload,
7959da522aSManjunatha Halli sizeof(payload), NULL, NULL);
8059da522aSManjunatha Halli if (ret < 0)
8159da522aSManjunatha Halli return ret;
8259da522aSManjunatha Halli
8359da522aSManjunatha Halli /* Start tune */
8459da522aSManjunatha Halli payload = FM_TUNER_PRESET_MODE;
8559da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, TUNER_MODE_SET, REG_WR, &payload,
8659da522aSManjunatha Halli sizeof(payload), NULL, NULL);
8759da522aSManjunatha Halli if (ret < 0)
8859da522aSManjunatha Halli goto exit;
8959da522aSManjunatha Halli
9059da522aSManjunatha Halli /* Wait for tune ended interrupt */
9159da522aSManjunatha Halli init_completion(&fmdev->maintask_comp);
9259da522aSManjunatha Halli timeleft = wait_for_completion_timeout(&fmdev->maintask_comp,
9359da522aSManjunatha Halli FM_DRV_TX_TIMEOUT);
9459da522aSManjunatha Halli if (!timeleft) {
9559da522aSManjunatha Halli fmerr("Timeout(%d sec),didn't get tune ended int\n",
9659da522aSManjunatha Halli jiffies_to_msecs(FM_DRV_TX_TIMEOUT) / 1000);
9759da522aSManjunatha Halli ret = -ETIMEDOUT;
9859da522aSManjunatha Halli goto exit;
9959da522aSManjunatha Halli }
10059da522aSManjunatha Halli
10159da522aSManjunatha Halli /* Read freq back to confirm */
10259da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, FREQ_SET, REG_RD, NULL, 2, &curr_frq, &resp_len);
10359da522aSManjunatha Halli if (ret < 0)
10459da522aSManjunatha Halli goto exit;
10559da522aSManjunatha Halli
1062a8b7e58SHans Verkuil curr_frq = be16_to_cpu((__force __be16)curr_frq);
10759da522aSManjunatha Halli curr_frq_in_khz = (fmdev->rx.region.bot_freq + ((u32)curr_frq * FM_FREQ_MUL));
10859da522aSManjunatha Halli
10959da522aSManjunatha Halli if (curr_frq_in_khz != freq) {
110e84541f0SMauro Carvalho Chehab pr_info("Frequency is set to (%d) but requested freq is (%d)\n",
111e84541f0SMauro Carvalho Chehab curr_frq_in_khz, freq);
11259da522aSManjunatha Halli }
11359da522aSManjunatha Halli
11459da522aSManjunatha Halli /* Update local cache */
11559da522aSManjunatha Halli fmdev->rx.freq = curr_frq_in_khz;
11659da522aSManjunatha Halli exit:
11759da522aSManjunatha Halli /* Re-enable default FM interrupts */
11859da522aSManjunatha Halli fmdev->irq_info.mask = intr_flag;
11959da522aSManjunatha Halli payload = fmdev->irq_info.mask;
12059da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, INT_MASK_SET, REG_WR, &payload,
12159da522aSManjunatha Halli sizeof(payload), NULL, NULL);
12259da522aSManjunatha Halli if (ret < 0)
12359da522aSManjunatha Halli return ret;
12459da522aSManjunatha Halli
12559da522aSManjunatha Halli /* Reset RDS cache and current station pointers */
12659da522aSManjunatha Halli fm_rx_reset_rds_cache(fmdev);
12759da522aSManjunatha Halli fm_rx_reset_station_info(fmdev);
12859da522aSManjunatha Halli
12959da522aSManjunatha Halli return ret;
13059da522aSManjunatha Halli }
13159da522aSManjunatha Halli
fm_rx_set_channel_spacing(struct fmdev * fmdev,u32 spacing)132d24674c6SXi Wang static int fm_rx_set_channel_spacing(struct fmdev *fmdev, u32 spacing)
13359da522aSManjunatha Halli {
13459da522aSManjunatha Halli u16 payload;
135d24674c6SXi Wang int ret;
13659da522aSManjunatha Halli
13759da522aSManjunatha Halli if (spacing > 0 && spacing <= 50000)
13859da522aSManjunatha Halli spacing = FM_CHANNEL_SPACING_50KHZ;
13959da522aSManjunatha Halli else if (spacing > 50000 && spacing <= 100000)
14059da522aSManjunatha Halli spacing = FM_CHANNEL_SPACING_100KHZ;
14159da522aSManjunatha Halli else
14259da522aSManjunatha Halli spacing = FM_CHANNEL_SPACING_200KHZ;
14359da522aSManjunatha Halli
14459da522aSManjunatha Halli /* set channel spacing */
14559da522aSManjunatha Halli payload = spacing;
14659da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, CHANL_BW_SET, REG_WR, &payload,
14759da522aSManjunatha Halli sizeof(payload), NULL, NULL);
14859da522aSManjunatha Halli if (ret < 0)
14959da522aSManjunatha Halli return ret;
15059da522aSManjunatha Halli
15159da522aSManjunatha Halli fmdev->rx.region.chanl_space = spacing * FM_FREQ_MUL;
15259da522aSManjunatha Halli
15359da522aSManjunatha Halli return ret;
15459da522aSManjunatha Halli }
15559da522aSManjunatha Halli
fm_rx_seek(struct fmdev * fmdev,u32 seek_upward,u32 wrap_around,u32 spacing)156d24674c6SXi Wang int fm_rx_seek(struct fmdev *fmdev, u32 seek_upward,
15759da522aSManjunatha Halli u32 wrap_around, u32 spacing)
15859da522aSManjunatha Halli {
15959da522aSManjunatha Halli u32 resp_len;
16059da522aSManjunatha Halli u16 curr_frq, next_frq, last_frq;
16159da522aSManjunatha Halli u16 payload, int_reason, intr_flag;
16259da522aSManjunatha Halli u16 offset, space_idx;
16359da522aSManjunatha Halli unsigned long timeleft;
164d24674c6SXi Wang int ret;
16559da522aSManjunatha Halli
16659da522aSManjunatha Halli /* Set channel spacing */
16759da522aSManjunatha Halli ret = fm_rx_set_channel_spacing(fmdev, spacing);
16859da522aSManjunatha Halli if (ret < 0) {
16959da522aSManjunatha Halli fmerr("Failed to set channel spacing\n");
17059da522aSManjunatha Halli return ret;
17159da522aSManjunatha Halli }
17259da522aSManjunatha Halli
17359da522aSManjunatha Halli /* Read the current frequency from chip */
17459da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, FREQ_SET, REG_RD, NULL,
17559da522aSManjunatha Halli sizeof(curr_frq), &curr_frq, &resp_len);
17659da522aSManjunatha Halli if (ret < 0)
17759da522aSManjunatha Halli return ret;
17859da522aSManjunatha Halli
1792a8b7e58SHans Verkuil curr_frq = be16_to_cpu((__force __be16)curr_frq);
18059da522aSManjunatha Halli last_frq = (fmdev->rx.region.top_freq - fmdev->rx.region.bot_freq) / FM_FREQ_MUL;
18159da522aSManjunatha Halli
18259da522aSManjunatha Halli /* Check the offset in order to be aligned to the channel spacing*/
18359da522aSManjunatha Halli space_idx = fmdev->rx.region.chanl_space / FM_FREQ_MUL;
18459da522aSManjunatha Halli offset = curr_frq % space_idx;
18559da522aSManjunatha Halli
18659da522aSManjunatha Halli next_frq = seek_upward ? curr_frq + space_idx /* Seek Up */ :
18759da522aSManjunatha Halli curr_frq - space_idx /* Seek Down */ ;
18859da522aSManjunatha Halli
18959da522aSManjunatha Halli /*
19059da522aSManjunatha Halli * Add or subtract offset in order to stay aligned to the channel
19159da522aSManjunatha Halli * spacing.
19259da522aSManjunatha Halli */
19359da522aSManjunatha Halli if ((short)next_frq < 0)
19459da522aSManjunatha Halli next_frq = last_frq - offset;
19559da522aSManjunatha Halli else if (next_frq > last_frq)
19659da522aSManjunatha Halli next_frq = 0 + offset;
19759da522aSManjunatha Halli
19859da522aSManjunatha Halli again:
19959da522aSManjunatha Halli /* Set calculated next frequency to perform seek */
20059da522aSManjunatha Halli payload = next_frq;
20159da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, FREQ_SET, REG_WR, &payload,
20259da522aSManjunatha Halli sizeof(payload), NULL, NULL);
20359da522aSManjunatha Halli if (ret < 0)
20459da522aSManjunatha Halli return ret;
20559da522aSManjunatha Halli
20659da522aSManjunatha Halli /* Set search direction (0:Seek Down, 1:Seek Up) */
20759da522aSManjunatha Halli payload = (seek_upward ? FM_SEARCH_DIRECTION_UP : FM_SEARCH_DIRECTION_DOWN);
20859da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, SEARCH_DIR_SET, REG_WR, &payload,
20959da522aSManjunatha Halli sizeof(payload), NULL, NULL);
21059da522aSManjunatha Halli if (ret < 0)
21159da522aSManjunatha Halli return ret;
21259da522aSManjunatha Halli
21359da522aSManjunatha Halli /* Read flags - just to clear any pending interrupts if we had */
21459da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, FLAG_GET, REG_RD, NULL, 2, NULL, NULL);
21559da522aSManjunatha Halli if (ret < 0)
21659da522aSManjunatha Halli return ret;
21759da522aSManjunatha Halli
21859da522aSManjunatha Halli /* Enable FR, BL interrupts */
21959da522aSManjunatha Halli intr_flag = fmdev->irq_info.mask;
22059da522aSManjunatha Halli fmdev->irq_info.mask = (FM_FR_EVENT | FM_BL_EVENT);
22159da522aSManjunatha Halli payload = fmdev->irq_info.mask;
22259da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, INT_MASK_SET, REG_WR, &payload,
22359da522aSManjunatha Halli sizeof(payload), NULL, NULL);
22459da522aSManjunatha Halli if (ret < 0)
22559da522aSManjunatha Halli return ret;
22659da522aSManjunatha Halli
22759da522aSManjunatha Halli /* Start seek */
22859da522aSManjunatha Halli payload = FM_TUNER_AUTONOMOUS_SEARCH_MODE;
22959da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, TUNER_MODE_SET, REG_WR, &payload,
23059da522aSManjunatha Halli sizeof(payload), NULL, NULL);
23159da522aSManjunatha Halli if (ret < 0)
23259da522aSManjunatha Halli return ret;
23359da522aSManjunatha Halli
23459da522aSManjunatha Halli /* Wait for tune ended/band limit reached interrupt */
23559da522aSManjunatha Halli init_completion(&fmdev->maintask_comp);
23659da522aSManjunatha Halli timeleft = wait_for_completion_timeout(&fmdev->maintask_comp,
23759da522aSManjunatha Halli FM_DRV_RX_SEEK_TIMEOUT);
23859da522aSManjunatha Halli if (!timeleft) {
23959da522aSManjunatha Halli fmerr("Timeout(%d sec),didn't get tune ended int\n",
24059da522aSManjunatha Halli jiffies_to_msecs(FM_DRV_RX_SEEK_TIMEOUT) / 1000);
24154f6019bSHans Verkuil return -ENODATA;
24259da522aSManjunatha Halli }
24359da522aSManjunatha Halli
24459da522aSManjunatha Halli int_reason = fmdev->irq_info.flag & (FM_TUNE_COMPLETE | FM_BAND_LIMIT);
24559da522aSManjunatha Halli
24659da522aSManjunatha Halli /* Re-enable default FM interrupts */
24759da522aSManjunatha Halli fmdev->irq_info.mask = intr_flag;
24859da522aSManjunatha Halli payload = fmdev->irq_info.mask;
24959da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, INT_MASK_SET, REG_WR, &payload,
25059da522aSManjunatha Halli sizeof(payload), NULL, NULL);
25159da522aSManjunatha Halli if (ret < 0)
25259da522aSManjunatha Halli return ret;
25359da522aSManjunatha Halli
25459da522aSManjunatha Halli if (int_reason & FM_BL_EVENT) {
25559da522aSManjunatha Halli if (wrap_around == 0) {
25659da522aSManjunatha Halli fmdev->rx.freq = seek_upward ?
25759da522aSManjunatha Halli fmdev->rx.region.top_freq :
25859da522aSManjunatha Halli fmdev->rx.region.bot_freq;
25959da522aSManjunatha Halli } else {
26059da522aSManjunatha Halli fmdev->rx.freq = seek_upward ?
26159da522aSManjunatha Halli fmdev->rx.region.bot_freq :
26259da522aSManjunatha Halli fmdev->rx.region.top_freq;
26359da522aSManjunatha Halli /* Calculate frequency index to write */
26459da522aSManjunatha Halli next_frq = (fmdev->rx.freq -
26559da522aSManjunatha Halli fmdev->rx.region.bot_freq) / FM_FREQ_MUL;
26659da522aSManjunatha Halli goto again;
26759da522aSManjunatha Halli }
26859da522aSManjunatha Halli } else {
26959da522aSManjunatha Halli /* Read freq to know where operation tune operation stopped */
27059da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, FREQ_SET, REG_RD, NULL, 2,
27159da522aSManjunatha Halli &curr_frq, &resp_len);
27259da522aSManjunatha Halli if (ret < 0)
27359da522aSManjunatha Halli return ret;
27459da522aSManjunatha Halli
2752a8b7e58SHans Verkuil curr_frq = be16_to_cpu((__force __be16)curr_frq);
27659da522aSManjunatha Halli fmdev->rx.freq = (fmdev->rx.region.bot_freq +
27759da522aSManjunatha Halli ((u32)curr_frq * FM_FREQ_MUL));
27859da522aSManjunatha Halli
27959da522aSManjunatha Halli }
28059da522aSManjunatha Halli /* Reset RDS cache and current station pointers */
28159da522aSManjunatha Halli fm_rx_reset_rds_cache(fmdev);
28259da522aSManjunatha Halli fm_rx_reset_station_info(fmdev);
28359da522aSManjunatha Halli
28459da522aSManjunatha Halli return ret;
28559da522aSManjunatha Halli }
28659da522aSManjunatha Halli
fm_rx_set_volume(struct fmdev * fmdev,u16 vol_to_set)287d24674c6SXi Wang int fm_rx_set_volume(struct fmdev *fmdev, u16 vol_to_set)
28859da522aSManjunatha Halli {
28959da522aSManjunatha Halli u16 payload;
290d24674c6SXi Wang int ret;
29159da522aSManjunatha Halli
29259da522aSManjunatha Halli if (fmdev->curr_fmmode != FM_MODE_RX)
29359da522aSManjunatha Halli return -EPERM;
29459da522aSManjunatha Halli
2955a3ef810SMauro Carvalho Chehab if (vol_to_set > FM_RX_VOLUME_MAX) {
29659da522aSManjunatha Halli fmerr("Volume is not within(%d-%d) range\n",
29759da522aSManjunatha Halli FM_RX_VOLUME_MIN, FM_RX_VOLUME_MAX);
29859da522aSManjunatha Halli return -EINVAL;
29959da522aSManjunatha Halli }
30059da522aSManjunatha Halli vol_to_set *= FM_RX_VOLUME_GAIN_STEP;
30159da522aSManjunatha Halli
30259da522aSManjunatha Halli payload = vol_to_set;
30359da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, VOLUME_SET, REG_WR, &payload,
30459da522aSManjunatha Halli sizeof(payload), NULL, NULL);
30559da522aSManjunatha Halli if (ret < 0)
30659da522aSManjunatha Halli return ret;
30759da522aSManjunatha Halli
30859da522aSManjunatha Halli fmdev->rx.volume = vol_to_set;
30959da522aSManjunatha Halli return ret;
31059da522aSManjunatha Halli }
31159da522aSManjunatha Halli
31259da522aSManjunatha Halli /* Get volume */
fm_rx_get_volume(struct fmdev * fmdev,u16 * curr_vol)313d24674c6SXi Wang int fm_rx_get_volume(struct fmdev *fmdev, u16 *curr_vol)
31459da522aSManjunatha Halli {
31559da522aSManjunatha Halli if (fmdev->curr_fmmode != FM_MODE_RX)
31659da522aSManjunatha Halli return -EPERM;
31759da522aSManjunatha Halli
31859da522aSManjunatha Halli if (curr_vol == NULL) {
31959da522aSManjunatha Halli fmerr("Invalid memory\n");
32059da522aSManjunatha Halli return -ENOMEM;
32159da522aSManjunatha Halli }
32259da522aSManjunatha Halli
32359da522aSManjunatha Halli *curr_vol = fmdev->rx.volume / FM_RX_VOLUME_GAIN_STEP;
32459da522aSManjunatha Halli
32559da522aSManjunatha Halli return 0;
32659da522aSManjunatha Halli }
32759da522aSManjunatha Halli
32859da522aSManjunatha Halli /* To get current band's bottom and top frequency */
fm_rx_get_band_freq_range(struct fmdev * fmdev,u32 * bot_freq,u32 * top_freq)329d24674c6SXi Wang int fm_rx_get_band_freq_range(struct fmdev *fmdev, u32 *bot_freq, u32 *top_freq)
33059da522aSManjunatha Halli {
33159da522aSManjunatha Halli if (bot_freq != NULL)
33259da522aSManjunatha Halli *bot_freq = fmdev->rx.region.bot_freq;
33359da522aSManjunatha Halli
33459da522aSManjunatha Halli if (top_freq != NULL)
33559da522aSManjunatha Halli *top_freq = fmdev->rx.region.top_freq;
33659da522aSManjunatha Halli
33759da522aSManjunatha Halli return 0;
33859da522aSManjunatha Halli }
33959da522aSManjunatha Halli
34059da522aSManjunatha Halli /* Returns current band index (0-Europe/US; 1-Japan) */
fm_rx_get_region(struct fmdev * fmdev,u8 * region)34159da522aSManjunatha Halli void fm_rx_get_region(struct fmdev *fmdev, u8 *region)
34259da522aSManjunatha Halli {
34359da522aSManjunatha Halli *region = fmdev->rx.region.fm_band;
34459da522aSManjunatha Halli }
34559da522aSManjunatha Halli
34659da522aSManjunatha Halli /* Sets band (0-Europe/US; 1-Japan) */
fm_rx_set_region(struct fmdev * fmdev,u8 region_to_set)347d24674c6SXi Wang int fm_rx_set_region(struct fmdev *fmdev, u8 region_to_set)
34859da522aSManjunatha Halli {
34959da522aSManjunatha Halli u16 payload;
35059da522aSManjunatha Halli u32 new_frq = 0;
351d24674c6SXi Wang int ret;
35259da522aSManjunatha Halli
35359da522aSManjunatha Halli if (region_to_set != FM_BAND_EUROPE_US &&
35459da522aSManjunatha Halli region_to_set != FM_BAND_JAPAN) {
35559da522aSManjunatha Halli fmerr("Invalid band\n");
35659da522aSManjunatha Halli return -EINVAL;
35759da522aSManjunatha Halli }
35859da522aSManjunatha Halli
35959da522aSManjunatha Halli if (fmdev->rx.region.fm_band == region_to_set) {
36059da522aSManjunatha Halli fmerr("Requested band is already configured\n");
36159da522aSManjunatha Halli return 0;
36259da522aSManjunatha Halli }
36359da522aSManjunatha Halli
36459da522aSManjunatha Halli /* Send cmd to set the band */
36559da522aSManjunatha Halli payload = (u16)region_to_set;
36659da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, BAND_SET, REG_WR, &payload,
36759da522aSManjunatha Halli sizeof(payload), NULL, NULL);
36859da522aSManjunatha Halli if (ret < 0)
36959da522aSManjunatha Halli return ret;
37059da522aSManjunatha Halli
37159da522aSManjunatha Halli fmc_update_region_info(fmdev, region_to_set);
37259da522aSManjunatha Halli
37359da522aSManjunatha Halli /* Check whether current RX frequency is within band boundary */
37459da522aSManjunatha Halli if (fmdev->rx.freq < fmdev->rx.region.bot_freq)
37559da522aSManjunatha Halli new_frq = fmdev->rx.region.bot_freq;
37659da522aSManjunatha Halli else if (fmdev->rx.freq > fmdev->rx.region.top_freq)
37759da522aSManjunatha Halli new_frq = fmdev->rx.region.top_freq;
37859da522aSManjunatha Halli
37959da522aSManjunatha Halli if (new_frq) {
380e84541f0SMauro Carvalho Chehab fmdbg("Current freq is not within band limit boundary,switching to %d KHz\n",
381e84541f0SMauro Carvalho Chehab new_frq);
38259da522aSManjunatha Halli /* Current RX frequency is not in range. So, update it */
38359da522aSManjunatha Halli ret = fm_rx_set_freq(fmdev, new_frq);
38459da522aSManjunatha Halli }
38559da522aSManjunatha Halli
38659da522aSManjunatha Halli return ret;
38759da522aSManjunatha Halli }
38859da522aSManjunatha Halli
38959da522aSManjunatha Halli /* Reads current mute mode (Mute Off/On/Attenuate)*/
fm_rx_get_mute_mode(struct fmdev * fmdev,u8 * curr_mute_mode)390d24674c6SXi Wang int fm_rx_get_mute_mode(struct fmdev *fmdev, u8 *curr_mute_mode)
39159da522aSManjunatha Halli {
39259da522aSManjunatha Halli if (fmdev->curr_fmmode != FM_MODE_RX)
39359da522aSManjunatha Halli return -EPERM;
39459da522aSManjunatha Halli
39559da522aSManjunatha Halli if (curr_mute_mode == NULL) {
39659da522aSManjunatha Halli fmerr("Invalid memory\n");
39759da522aSManjunatha Halli return -ENOMEM;
39859da522aSManjunatha Halli }
39959da522aSManjunatha Halli
40059da522aSManjunatha Halli *curr_mute_mode = fmdev->rx.mute_mode;
40159da522aSManjunatha Halli
40259da522aSManjunatha Halli return 0;
40359da522aSManjunatha Halli }
40459da522aSManjunatha Halli
fm_config_rx_mute_reg(struct fmdev * fmdev)405d24674c6SXi Wang static int fm_config_rx_mute_reg(struct fmdev *fmdev)
40659da522aSManjunatha Halli {
40759da522aSManjunatha Halli u16 payload, muteval;
408d24674c6SXi Wang int ret;
40959da522aSManjunatha Halli
41059da522aSManjunatha Halli muteval = 0;
41159da522aSManjunatha Halli switch (fmdev->rx.mute_mode) {
41259da522aSManjunatha Halli case FM_MUTE_ON:
41359da522aSManjunatha Halli muteval = FM_RX_AC_MUTE_MODE;
41459da522aSManjunatha Halli break;
41559da522aSManjunatha Halli
41659da522aSManjunatha Halli case FM_MUTE_OFF:
41759da522aSManjunatha Halli muteval = FM_RX_UNMUTE_MODE;
41859da522aSManjunatha Halli break;
41959da522aSManjunatha Halli
42059da522aSManjunatha Halli case FM_MUTE_ATTENUATE:
42159da522aSManjunatha Halli muteval = FM_RX_SOFT_MUTE_FORCE_MODE;
42259da522aSManjunatha Halli break;
42359da522aSManjunatha Halli }
42459da522aSManjunatha Halli if (fmdev->rx.rf_depend_mute == FM_RX_RF_DEPENDENT_MUTE_ON)
42559da522aSManjunatha Halli muteval |= FM_RX_RF_DEP_MODE;
42659da522aSManjunatha Halli else
42759da522aSManjunatha Halli muteval &= ~FM_RX_RF_DEP_MODE;
42859da522aSManjunatha Halli
42959da522aSManjunatha Halli payload = muteval;
43059da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, MUTE_STATUS_SET, REG_WR, &payload,
43159da522aSManjunatha Halli sizeof(payload), NULL, NULL);
43259da522aSManjunatha Halli if (ret < 0)
43359da522aSManjunatha Halli return ret;
43459da522aSManjunatha Halli
43559da522aSManjunatha Halli return 0;
43659da522aSManjunatha Halli }
43759da522aSManjunatha Halli
43859da522aSManjunatha Halli /* Configures mute mode (Mute Off/On/Attenuate) */
fm_rx_set_mute_mode(struct fmdev * fmdev,u8 mute_mode_toset)439d24674c6SXi Wang int fm_rx_set_mute_mode(struct fmdev *fmdev, u8 mute_mode_toset)
44059da522aSManjunatha Halli {
44159da522aSManjunatha Halli u8 org_state;
442d24674c6SXi Wang int ret;
44359da522aSManjunatha Halli
44459da522aSManjunatha Halli if (fmdev->rx.mute_mode == mute_mode_toset)
44559da522aSManjunatha Halli return 0;
44659da522aSManjunatha Halli
44759da522aSManjunatha Halli org_state = fmdev->rx.mute_mode;
44859da522aSManjunatha Halli fmdev->rx.mute_mode = mute_mode_toset;
44959da522aSManjunatha Halli
45059da522aSManjunatha Halli ret = fm_config_rx_mute_reg(fmdev);
45159da522aSManjunatha Halli if (ret < 0) {
45259da522aSManjunatha Halli fmdev->rx.mute_mode = org_state;
45359da522aSManjunatha Halli return ret;
45459da522aSManjunatha Halli }
45559da522aSManjunatha Halli
45659da522aSManjunatha Halli return 0;
45759da522aSManjunatha Halli }
45859da522aSManjunatha Halli
45959da522aSManjunatha Halli /* Gets RF dependent soft mute mode enable/disable status */
fm_rx_get_rfdepend_softmute(struct fmdev * fmdev,u8 * curr_mute_mode)460d24674c6SXi Wang int fm_rx_get_rfdepend_softmute(struct fmdev *fmdev, u8 *curr_mute_mode)
46159da522aSManjunatha Halli {
46259da522aSManjunatha Halli if (fmdev->curr_fmmode != FM_MODE_RX)
46359da522aSManjunatha Halli return -EPERM;
46459da522aSManjunatha Halli
46559da522aSManjunatha Halli if (curr_mute_mode == NULL) {
46659da522aSManjunatha Halli fmerr("Invalid memory\n");
46759da522aSManjunatha Halli return -ENOMEM;
46859da522aSManjunatha Halli }
46959da522aSManjunatha Halli
47059da522aSManjunatha Halli *curr_mute_mode = fmdev->rx.rf_depend_mute;
47159da522aSManjunatha Halli
47259da522aSManjunatha Halli return 0;
47359da522aSManjunatha Halli }
47459da522aSManjunatha Halli
47559da522aSManjunatha Halli /* Sets RF dependent soft mute mode */
fm_rx_set_rfdepend_softmute(struct fmdev * fmdev,u8 rfdepend_mute)476d24674c6SXi Wang int fm_rx_set_rfdepend_softmute(struct fmdev *fmdev, u8 rfdepend_mute)
47759da522aSManjunatha Halli {
47859da522aSManjunatha Halli u8 org_state;
479d24674c6SXi Wang int ret;
48059da522aSManjunatha Halli
48159da522aSManjunatha Halli if (fmdev->curr_fmmode != FM_MODE_RX)
48259da522aSManjunatha Halli return -EPERM;
48359da522aSManjunatha Halli
48459da522aSManjunatha Halli if (rfdepend_mute != FM_RX_RF_DEPENDENT_MUTE_ON &&
48559da522aSManjunatha Halli rfdepend_mute != FM_RX_RF_DEPENDENT_MUTE_OFF) {
48659da522aSManjunatha Halli fmerr("Invalid RF dependent soft mute\n");
48759da522aSManjunatha Halli return -EINVAL;
48859da522aSManjunatha Halli }
48959da522aSManjunatha Halli if (fmdev->rx.rf_depend_mute == rfdepend_mute)
49059da522aSManjunatha Halli return 0;
49159da522aSManjunatha Halli
49259da522aSManjunatha Halli org_state = fmdev->rx.rf_depend_mute;
49359da522aSManjunatha Halli fmdev->rx.rf_depend_mute = rfdepend_mute;
49459da522aSManjunatha Halli
49559da522aSManjunatha Halli ret = fm_config_rx_mute_reg(fmdev);
49659da522aSManjunatha Halli if (ret < 0) {
49759da522aSManjunatha Halli fmdev->rx.rf_depend_mute = org_state;
49859da522aSManjunatha Halli return ret;
49959da522aSManjunatha Halli }
50059da522aSManjunatha Halli
50159da522aSManjunatha Halli return 0;
50259da522aSManjunatha Halli }
50359da522aSManjunatha Halli
50459da522aSManjunatha Halli /* Returns the signal strength level of current channel */
fm_rx_get_rssi_level(struct fmdev * fmdev,u16 * rssilvl)505d24674c6SXi Wang int fm_rx_get_rssi_level(struct fmdev *fmdev, u16 *rssilvl)
50659da522aSManjunatha Halli {
5072a8b7e58SHans Verkuil __be16 curr_rssi_lel;
50859da522aSManjunatha Halli u32 resp_len;
509d24674c6SXi Wang int ret;
51059da522aSManjunatha Halli
51159da522aSManjunatha Halli if (rssilvl == NULL) {
51259da522aSManjunatha Halli fmerr("Invalid memory\n");
51359da522aSManjunatha Halli return -ENOMEM;
51459da522aSManjunatha Halli }
51559da522aSManjunatha Halli /* Read current RSSI level */
51659da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, RSSI_LVL_GET, REG_RD, NULL, 2,
51759da522aSManjunatha Halli &curr_rssi_lel, &resp_len);
51859da522aSManjunatha Halli if (ret < 0)
51959da522aSManjunatha Halli return ret;
52059da522aSManjunatha Halli
52159da522aSManjunatha Halli *rssilvl = be16_to_cpu(curr_rssi_lel);
52259da522aSManjunatha Halli
52359da522aSManjunatha Halli return 0;
52459da522aSManjunatha Halli }
52559da522aSManjunatha Halli
52659da522aSManjunatha Halli /*
52759da522aSManjunatha Halli * Sets the signal strength level that once reached
52859da522aSManjunatha Halli * will stop the auto search process
52959da522aSManjunatha Halli */
fm_rx_set_rssi_threshold(struct fmdev * fmdev,short rssi_lvl_toset)530d24674c6SXi Wang int fm_rx_set_rssi_threshold(struct fmdev *fmdev, short rssi_lvl_toset)
53159da522aSManjunatha Halli {
53259da522aSManjunatha Halli u16 payload;
533d24674c6SXi Wang int ret;
53459da522aSManjunatha Halli
53559da522aSManjunatha Halli if (rssi_lvl_toset < FM_RX_RSSI_THRESHOLD_MIN ||
53659da522aSManjunatha Halli rssi_lvl_toset > FM_RX_RSSI_THRESHOLD_MAX) {
53759da522aSManjunatha Halli fmerr("Invalid RSSI threshold level\n");
53859da522aSManjunatha Halli return -EINVAL;
53959da522aSManjunatha Halli }
54059da522aSManjunatha Halli payload = (u16)rssi_lvl_toset;
54159da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, SEARCH_LVL_SET, REG_WR, &payload,
54259da522aSManjunatha Halli sizeof(payload), NULL, NULL);
54359da522aSManjunatha Halli if (ret < 0)
54459da522aSManjunatha Halli return ret;
54559da522aSManjunatha Halli
54659da522aSManjunatha Halli fmdev->rx.rssi_threshold = rssi_lvl_toset;
54759da522aSManjunatha Halli
54859da522aSManjunatha Halli return 0;
54959da522aSManjunatha Halli }
55059da522aSManjunatha Halli
55159da522aSManjunatha Halli /* Returns current RX RSSI threshold value */
fm_rx_get_rssi_threshold(struct fmdev * fmdev,short * curr_rssi_lvl)552d24674c6SXi Wang int fm_rx_get_rssi_threshold(struct fmdev *fmdev, short *curr_rssi_lvl)
55359da522aSManjunatha Halli {
55459da522aSManjunatha Halli if (fmdev->curr_fmmode != FM_MODE_RX)
55559da522aSManjunatha Halli return -EPERM;
55659da522aSManjunatha Halli
55759da522aSManjunatha Halli if (curr_rssi_lvl == NULL) {
55859da522aSManjunatha Halli fmerr("Invalid memory\n");
55959da522aSManjunatha Halli return -ENOMEM;
56059da522aSManjunatha Halli }
56159da522aSManjunatha Halli
56259da522aSManjunatha Halli *curr_rssi_lvl = fmdev->rx.rssi_threshold;
56359da522aSManjunatha Halli
56459da522aSManjunatha Halli return 0;
56559da522aSManjunatha Halli }
56659da522aSManjunatha Halli
56759da522aSManjunatha Halli /* Sets RX stereo/mono modes */
fm_rx_set_stereo_mono(struct fmdev * fmdev,u16 mode)568d24674c6SXi Wang int fm_rx_set_stereo_mono(struct fmdev *fmdev, u16 mode)
56959da522aSManjunatha Halli {
57059da522aSManjunatha Halli u16 payload;
571d24674c6SXi Wang int ret;
57259da522aSManjunatha Halli
57359da522aSManjunatha Halli if (mode != FM_STEREO_MODE && mode != FM_MONO_MODE) {
57459da522aSManjunatha Halli fmerr("Invalid mode\n");
57559da522aSManjunatha Halli return -EINVAL;
57659da522aSManjunatha Halli }
57759da522aSManjunatha Halli
57859da522aSManjunatha Halli /* Set stereo/mono mode */
57959da522aSManjunatha Halli payload = (u16)mode;
58059da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, MOST_MODE_SET, REG_WR, &payload,
58159da522aSManjunatha Halli sizeof(payload), NULL, NULL);
58259da522aSManjunatha Halli if (ret < 0)
58359da522aSManjunatha Halli return ret;
58459da522aSManjunatha Halli
58559da522aSManjunatha Halli /* Set stereo blending mode */
58659da522aSManjunatha Halli payload = FM_STEREO_SOFT_BLEND;
58759da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, MOST_BLEND_SET, REG_WR, &payload,
58859da522aSManjunatha Halli sizeof(payload), NULL, NULL);
58959da522aSManjunatha Halli if (ret < 0)
59059da522aSManjunatha Halli return ret;
59159da522aSManjunatha Halli
59259da522aSManjunatha Halli return 0;
59359da522aSManjunatha Halli }
59459da522aSManjunatha Halli
59559da522aSManjunatha Halli /* Gets current RX stereo/mono mode */
fm_rx_get_stereo_mono(struct fmdev * fmdev,u16 * mode)596d24674c6SXi Wang int fm_rx_get_stereo_mono(struct fmdev *fmdev, u16 *mode)
59759da522aSManjunatha Halli {
5982a8b7e58SHans Verkuil __be16 curr_mode;
599d24674c6SXi Wang u32 resp_len;
600d24674c6SXi Wang int ret;
60159da522aSManjunatha Halli
60259da522aSManjunatha Halli if (mode == NULL) {
60359da522aSManjunatha Halli fmerr("Invalid memory\n");
60459da522aSManjunatha Halli return -ENOMEM;
60559da522aSManjunatha Halli }
60659da522aSManjunatha Halli
60759da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, MOST_MODE_SET, REG_RD, NULL, 2,
60859da522aSManjunatha Halli &curr_mode, &resp_len);
60959da522aSManjunatha Halli if (ret < 0)
61059da522aSManjunatha Halli return ret;
61159da522aSManjunatha Halli
61259da522aSManjunatha Halli *mode = be16_to_cpu(curr_mode);
61359da522aSManjunatha Halli
61459da522aSManjunatha Halli return 0;
61559da522aSManjunatha Halli }
61659da522aSManjunatha Halli
61759da522aSManjunatha Halli /* Choose RX de-emphasis filter mode (50us/75us) */
fm_rx_set_deemphasis_mode(struct fmdev * fmdev,u16 mode)618d24674c6SXi Wang int fm_rx_set_deemphasis_mode(struct fmdev *fmdev, u16 mode)
61959da522aSManjunatha Halli {
62059da522aSManjunatha Halli u16 payload;
621d24674c6SXi Wang int ret;
62259da522aSManjunatha Halli
62359da522aSManjunatha Halli if (fmdev->curr_fmmode != FM_MODE_RX)
62459da522aSManjunatha Halli return -EPERM;
62559da522aSManjunatha Halli
62659da522aSManjunatha Halli if (mode != FM_RX_EMPHASIS_FILTER_50_USEC &&
62759da522aSManjunatha Halli mode != FM_RX_EMPHASIS_FILTER_75_USEC) {
62859da522aSManjunatha Halli fmerr("Invalid rx de-emphasis mode (%d)\n", mode);
62959da522aSManjunatha Halli return -EINVAL;
63059da522aSManjunatha Halli }
63159da522aSManjunatha Halli
63259da522aSManjunatha Halli payload = mode;
63359da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, DEMPH_MODE_SET, REG_WR, &payload,
63459da522aSManjunatha Halli sizeof(payload), NULL, NULL);
63559da522aSManjunatha Halli if (ret < 0)
63659da522aSManjunatha Halli return ret;
63759da522aSManjunatha Halli
63859da522aSManjunatha Halli fmdev->rx.deemphasis_mode = mode;
63959da522aSManjunatha Halli
64059da522aSManjunatha Halli return 0;
64159da522aSManjunatha Halli }
64259da522aSManjunatha Halli
64359da522aSManjunatha Halli /* Gets current RX de-emphasis filter mode */
fm_rx_get_deemph_mode(struct fmdev * fmdev,u16 * curr_deemphasis_mode)644d24674c6SXi Wang int fm_rx_get_deemph_mode(struct fmdev *fmdev, u16 *curr_deemphasis_mode)
64559da522aSManjunatha Halli {
64659da522aSManjunatha Halli if (fmdev->curr_fmmode != FM_MODE_RX)
64759da522aSManjunatha Halli return -EPERM;
64859da522aSManjunatha Halli
64959da522aSManjunatha Halli if (curr_deemphasis_mode == NULL) {
65059da522aSManjunatha Halli fmerr("Invalid memory\n");
65159da522aSManjunatha Halli return -ENOMEM;
65259da522aSManjunatha Halli }
65359da522aSManjunatha Halli
65459da522aSManjunatha Halli *curr_deemphasis_mode = fmdev->rx.deemphasis_mode;
65559da522aSManjunatha Halli
65659da522aSManjunatha Halli return 0;
65759da522aSManjunatha Halli }
65859da522aSManjunatha Halli
65959da522aSManjunatha Halli /* Enable/Disable RX RDS */
fm_rx_set_rds_mode(struct fmdev * fmdev,u8 rds_en_dis)660d24674c6SXi Wang int fm_rx_set_rds_mode(struct fmdev *fmdev, u8 rds_en_dis)
66159da522aSManjunatha Halli {
66259da522aSManjunatha Halli u16 payload;
663d24674c6SXi Wang int ret;
66459da522aSManjunatha Halli
66559da522aSManjunatha Halli if (rds_en_dis != FM_RDS_ENABLE && rds_en_dis != FM_RDS_DISABLE) {
66659da522aSManjunatha Halli fmerr("Invalid rds option\n");
66759da522aSManjunatha Halli return -EINVAL;
66859da522aSManjunatha Halli }
66959da522aSManjunatha Halli
67059da522aSManjunatha Halli if (rds_en_dis == FM_RDS_ENABLE
67159da522aSManjunatha Halli && fmdev->rx.rds.flag == FM_RDS_DISABLE) {
67259da522aSManjunatha Halli /* Turn on RX RDS and RDS circuit */
67359da522aSManjunatha Halli payload = FM_RX_PWR_SET_FM_AND_RDS_BLK_ON;
67459da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, POWER_SET, REG_WR, &payload,
67559da522aSManjunatha Halli sizeof(payload), NULL, NULL);
67659da522aSManjunatha Halli if (ret < 0)
67759da522aSManjunatha Halli return ret;
67859da522aSManjunatha Halli
67959da522aSManjunatha Halli /* Clear and reset RDS FIFO */
68059da522aSManjunatha Halli payload = FM_RX_RDS_FLUSH_FIFO;
68159da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, RDS_CNTRL_SET, REG_WR, &payload,
68259da522aSManjunatha Halli sizeof(payload), NULL, NULL);
68359da522aSManjunatha Halli if (ret < 0)
68459da522aSManjunatha Halli return ret;
68559da522aSManjunatha Halli
68659da522aSManjunatha Halli /* Read flags - just to clear any pending interrupts. */
68759da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, FLAG_GET, REG_RD, NULL, 2,
68859da522aSManjunatha Halli NULL, NULL);
68959da522aSManjunatha Halli if (ret < 0)
69059da522aSManjunatha Halli return ret;
69159da522aSManjunatha Halli
69259da522aSManjunatha Halli /* Set RDS FIFO threshold value */
69359da522aSManjunatha Halli payload = FM_RX_RDS_FIFO_THRESHOLD;
69459da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, RDS_MEM_SET, REG_WR, &payload,
69559da522aSManjunatha Halli sizeof(payload), NULL, NULL);
69659da522aSManjunatha Halli if (ret < 0)
69759da522aSManjunatha Halli return ret;
69859da522aSManjunatha Halli
69959da522aSManjunatha Halli /* Enable RDS interrupt */
70059da522aSManjunatha Halli fmdev->irq_info.mask |= FM_RDS_EVENT;
70159da522aSManjunatha Halli payload = fmdev->irq_info.mask;
70259da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, INT_MASK_SET, REG_WR, &payload,
70359da522aSManjunatha Halli sizeof(payload), NULL, NULL);
70459da522aSManjunatha Halli if (ret < 0) {
70559da522aSManjunatha Halli fmdev->irq_info.mask &= ~FM_RDS_EVENT;
70659da522aSManjunatha Halli return ret;
70759da522aSManjunatha Halli }
70859da522aSManjunatha Halli
70959da522aSManjunatha Halli /* Update our local flag */
71059da522aSManjunatha Halli fmdev->rx.rds.flag = FM_RDS_ENABLE;
71159da522aSManjunatha Halli } else if (rds_en_dis == FM_RDS_DISABLE
71259da522aSManjunatha Halli && fmdev->rx.rds.flag == FM_RDS_ENABLE) {
71359da522aSManjunatha Halli /* Turn off RX RDS */
71459da522aSManjunatha Halli payload = FM_RX_PWR_SET_FM_ON_RDS_OFF;
71559da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, POWER_SET, REG_WR, &payload,
71659da522aSManjunatha Halli sizeof(payload), NULL, NULL);
71759da522aSManjunatha Halli if (ret < 0)
71859da522aSManjunatha Halli return ret;
71959da522aSManjunatha Halli
72059da522aSManjunatha Halli /* Reset RDS pointers */
72159da522aSManjunatha Halli fmdev->rx.rds.last_blk_idx = 0;
72259da522aSManjunatha Halli fmdev->rx.rds.wr_idx = 0;
72359da522aSManjunatha Halli fmdev->rx.rds.rd_idx = 0;
72459da522aSManjunatha Halli fm_rx_reset_station_info(fmdev);
72559da522aSManjunatha Halli
72659da522aSManjunatha Halli /* Update RDS local cache */
72759da522aSManjunatha Halli fmdev->irq_info.mask &= ~(FM_RDS_EVENT);
72859da522aSManjunatha Halli fmdev->rx.rds.flag = FM_RDS_DISABLE;
72959da522aSManjunatha Halli }
73059da522aSManjunatha Halli
73159da522aSManjunatha Halli return 0;
73259da522aSManjunatha Halli }
73359da522aSManjunatha Halli
73459da522aSManjunatha Halli /* Returns current RX RDS enable/disable status */
fm_rx_get_rds_mode(struct fmdev * fmdev,u8 * curr_rds_en_dis)735d24674c6SXi Wang int fm_rx_get_rds_mode(struct fmdev *fmdev, u8 *curr_rds_en_dis)
73659da522aSManjunatha Halli {
73759da522aSManjunatha Halli if (fmdev->curr_fmmode != FM_MODE_RX)
73859da522aSManjunatha Halli return -EPERM;
73959da522aSManjunatha Halli
74059da522aSManjunatha Halli if (curr_rds_en_dis == NULL) {
74159da522aSManjunatha Halli fmerr("Invalid memory\n");
74259da522aSManjunatha Halli return -ENOMEM;
74359da522aSManjunatha Halli }
74459da522aSManjunatha Halli
74559da522aSManjunatha Halli *curr_rds_en_dis = fmdev->rx.rds.flag;
74659da522aSManjunatha Halli
74759da522aSManjunatha Halli return 0;
74859da522aSManjunatha Halli }
74959da522aSManjunatha Halli
75059da522aSManjunatha Halli /* Sets RDS operation mode (RDS/RDBS) */
fm_rx_set_rds_system(struct fmdev * fmdev,u8 rds_mode)751d24674c6SXi Wang int fm_rx_set_rds_system(struct fmdev *fmdev, u8 rds_mode)
75259da522aSManjunatha Halli {
75359da522aSManjunatha Halli u16 payload;
754d24674c6SXi Wang int ret;
75559da522aSManjunatha Halli
75659da522aSManjunatha Halli if (fmdev->curr_fmmode != FM_MODE_RX)
75759da522aSManjunatha Halli return -EPERM;
75859da522aSManjunatha Halli
75959da522aSManjunatha Halli if (rds_mode != FM_RDS_SYSTEM_RDS && rds_mode != FM_RDS_SYSTEM_RBDS) {
76059da522aSManjunatha Halli fmerr("Invalid rds mode\n");
76159da522aSManjunatha Halli return -EINVAL;
76259da522aSManjunatha Halli }
76359da522aSManjunatha Halli /* Set RDS operation mode */
76459da522aSManjunatha Halli payload = (u16)rds_mode;
76559da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, RDS_SYSTEM_SET, REG_WR, &payload,
76659da522aSManjunatha Halli sizeof(payload), NULL, NULL);
76759da522aSManjunatha Halli if (ret < 0)
76859da522aSManjunatha Halli return ret;
76959da522aSManjunatha Halli
77059da522aSManjunatha Halli fmdev->rx.rds_mode = rds_mode;
77159da522aSManjunatha Halli
77259da522aSManjunatha Halli return 0;
77359da522aSManjunatha Halli }
77459da522aSManjunatha Halli
77559da522aSManjunatha Halli /* Configures Alternate Frequency switch mode */
fm_rx_set_af_switch(struct fmdev * fmdev,u8 af_mode)776d24674c6SXi Wang int fm_rx_set_af_switch(struct fmdev *fmdev, u8 af_mode)
77759da522aSManjunatha Halli {
77859da522aSManjunatha Halli u16 payload;
779d24674c6SXi Wang int ret;
78059da522aSManjunatha Halli
78159da522aSManjunatha Halli if (fmdev->curr_fmmode != FM_MODE_RX)
78259da522aSManjunatha Halli return -EPERM;
78359da522aSManjunatha Halli
78459da522aSManjunatha Halli if (af_mode != FM_RX_RDS_AF_SWITCH_MODE_ON &&
78559da522aSManjunatha Halli af_mode != FM_RX_RDS_AF_SWITCH_MODE_OFF) {
78659da522aSManjunatha Halli fmerr("Invalid af mode\n");
78759da522aSManjunatha Halli return -EINVAL;
78859da522aSManjunatha Halli }
78959da522aSManjunatha Halli /* Enable/disable low RSSI interrupt based on af_mode */
79059da522aSManjunatha Halli if (af_mode == FM_RX_RDS_AF_SWITCH_MODE_ON)
79159da522aSManjunatha Halli fmdev->irq_info.mask |= FM_LEV_EVENT;
79259da522aSManjunatha Halli else
79359da522aSManjunatha Halli fmdev->irq_info.mask &= ~FM_LEV_EVENT;
79459da522aSManjunatha Halli
79559da522aSManjunatha Halli payload = fmdev->irq_info.mask;
79659da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, INT_MASK_SET, REG_WR, &payload,
79759da522aSManjunatha Halli sizeof(payload), NULL, NULL);
79859da522aSManjunatha Halli if (ret < 0)
79959da522aSManjunatha Halli return ret;
80059da522aSManjunatha Halli
80159da522aSManjunatha Halli fmdev->rx.af_mode = af_mode;
80259da522aSManjunatha Halli
80359da522aSManjunatha Halli return 0;
80459da522aSManjunatha Halli }
80559da522aSManjunatha Halli
80659da522aSManjunatha Halli /* Returns Alternate Frequency switch status */
fm_rx_get_af_switch(struct fmdev * fmdev,u8 * af_mode)807d24674c6SXi Wang int fm_rx_get_af_switch(struct fmdev *fmdev, u8 *af_mode)
80859da522aSManjunatha Halli {
80959da522aSManjunatha Halli if (fmdev->curr_fmmode != FM_MODE_RX)
81059da522aSManjunatha Halli return -EPERM;
81159da522aSManjunatha Halli
81259da522aSManjunatha Halli if (af_mode == NULL) {
81359da522aSManjunatha Halli fmerr("Invalid memory\n");
81459da522aSManjunatha Halli return -ENOMEM;
81559da522aSManjunatha Halli }
81659da522aSManjunatha Halli
81759da522aSManjunatha Halli *af_mode = fmdev->rx.af_mode;
81859da522aSManjunatha Halli
81959da522aSManjunatha Halli return 0;
82059da522aSManjunatha Halli }
821