159da522aSManjunatha Halli /* 259da522aSManjunatha Halli * FM Driver for Connectivity chip of Texas Instruments. 359da522aSManjunatha Halli * This sub-module of FM driver implements FM RX functionality. 459da522aSManjunatha Halli * 559da522aSManjunatha Halli * Copyright (C) 2011 Texas Instruments 659da522aSManjunatha Halli * Author: Raja Mani <raja_mani@ti.com> 759da522aSManjunatha Halli * Author: Manjunatha Halli <manjunatha_halli@ti.com> 859da522aSManjunatha Halli * 959da522aSManjunatha Halli * This program is free software; you can redistribute it and/or modify 1059da522aSManjunatha Halli * it under the terms of the GNU General Public License version 2 as 1159da522aSManjunatha Halli * published by the Free Software Foundation. 1259da522aSManjunatha Halli * 1359da522aSManjunatha Halli * This program is distributed in the hope that it will be useful, 1459da522aSManjunatha Halli * but WITHOUT ANY WARRANTY; without even the implied warranty of 1559da522aSManjunatha Halli * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1659da522aSManjunatha Halli * GNU General Public License for more details. 1759da522aSManjunatha Halli * 1859da522aSManjunatha Halli * You should have received a copy of the GNU General Public License 1959da522aSManjunatha Halli * along with this program; if not, write to the Free Software 2059da522aSManjunatha Halli * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 2159da522aSManjunatha Halli * 2259da522aSManjunatha Halli */ 2359da522aSManjunatha Halli 2459da522aSManjunatha Halli #include "fmdrv.h" 2559da522aSManjunatha Halli #include "fmdrv_common.h" 2659da522aSManjunatha Halli #include "fmdrv_rx.h" 2759da522aSManjunatha Halli 2859da522aSManjunatha Halli void fm_rx_reset_rds_cache(struct fmdev *fmdev) 2959da522aSManjunatha Halli { 3059da522aSManjunatha Halli fmdev->rx.rds.flag = FM_RDS_DISABLE; 3159da522aSManjunatha Halli fmdev->rx.rds.last_blk_idx = 0; 3259da522aSManjunatha Halli fmdev->rx.rds.wr_idx = 0; 3359da522aSManjunatha Halli fmdev->rx.rds.rd_idx = 0; 3459da522aSManjunatha Halli 3559da522aSManjunatha Halli if (fmdev->rx.af_mode == FM_RX_RDS_AF_SWITCH_MODE_ON) 3659da522aSManjunatha Halli fmdev->irq_info.mask |= FM_LEV_EVENT; 3759da522aSManjunatha Halli } 3859da522aSManjunatha Halli 3959da522aSManjunatha Halli void fm_rx_reset_station_info(struct fmdev *fmdev) 4059da522aSManjunatha Halli { 4159da522aSManjunatha Halli fmdev->rx.stat_info.picode = FM_NO_PI_CODE; 4259da522aSManjunatha Halli fmdev->rx.stat_info.afcache_size = 0; 4359da522aSManjunatha Halli fmdev->rx.stat_info.af_list_max = 0; 4459da522aSManjunatha Halli } 4559da522aSManjunatha Halli 46d24674c6SXi Wang int fm_rx_set_freq(struct fmdev *fmdev, u32 freq) 4759da522aSManjunatha Halli { 4859da522aSManjunatha Halli unsigned long timeleft; 4959da522aSManjunatha Halli u16 payload, curr_frq, intr_flag; 5059da522aSManjunatha Halli u32 curr_frq_in_khz; 51d24674c6SXi Wang u32 resp_len; 52d24674c6SXi Wang int ret; 5359da522aSManjunatha Halli 5459da522aSManjunatha Halli if (freq < fmdev->rx.region.bot_freq || freq > fmdev->rx.region.top_freq) { 5559da522aSManjunatha Halli fmerr("Invalid frequency %d\n", freq); 5659da522aSManjunatha Halli return -EINVAL; 5759da522aSManjunatha Halli } 5859da522aSManjunatha Halli 5959da522aSManjunatha Halli /* Set audio enable */ 6059da522aSManjunatha Halli payload = FM_RX_AUDIO_ENABLE_I2S_AND_ANALOG; 6159da522aSManjunatha Halli 6259da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, AUDIO_ENABLE_SET, REG_WR, &payload, 6359da522aSManjunatha Halli sizeof(payload), NULL, NULL); 6459da522aSManjunatha Halli if (ret < 0) 6559da522aSManjunatha Halli return ret; 6659da522aSManjunatha Halli 6759da522aSManjunatha Halli /* Set hilo to automatic selection */ 6859da522aSManjunatha Halli payload = FM_RX_IFFREQ_HILO_AUTOMATIC; 6959da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, HILO_SET, REG_WR, &payload, 7059da522aSManjunatha Halli sizeof(payload), NULL, NULL); 7159da522aSManjunatha Halli if (ret < 0) 7259da522aSManjunatha Halli return ret; 7359da522aSManjunatha Halli 7459da522aSManjunatha Halli /* Calculate frequency index and set*/ 7559da522aSManjunatha Halli payload = (freq - fmdev->rx.region.bot_freq) / FM_FREQ_MUL; 7659da522aSManjunatha Halli 7759da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, FREQ_SET, REG_WR, &payload, 7859da522aSManjunatha Halli sizeof(payload), NULL, NULL); 7959da522aSManjunatha Halli if (ret < 0) 8059da522aSManjunatha Halli return ret; 8159da522aSManjunatha Halli 8259da522aSManjunatha Halli /* Read flags - just to clear any pending interrupts if we had */ 8359da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, FLAG_GET, REG_RD, NULL, 2, NULL, NULL); 8459da522aSManjunatha Halli if (ret < 0) 8559da522aSManjunatha Halli return ret; 8659da522aSManjunatha Halli 8759da522aSManjunatha Halli /* Enable FR, BL interrupts */ 8859da522aSManjunatha Halli intr_flag = fmdev->irq_info.mask; 8959da522aSManjunatha Halli fmdev->irq_info.mask = (FM_FR_EVENT | FM_BL_EVENT); 9059da522aSManjunatha Halli payload = fmdev->irq_info.mask; 9159da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, INT_MASK_SET, REG_WR, &payload, 9259da522aSManjunatha Halli sizeof(payload), NULL, NULL); 9359da522aSManjunatha Halli if (ret < 0) 9459da522aSManjunatha Halli return ret; 9559da522aSManjunatha Halli 9659da522aSManjunatha Halli /* Start tune */ 9759da522aSManjunatha Halli payload = FM_TUNER_PRESET_MODE; 9859da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, TUNER_MODE_SET, REG_WR, &payload, 9959da522aSManjunatha Halli sizeof(payload), NULL, NULL); 10059da522aSManjunatha Halli if (ret < 0) 10159da522aSManjunatha Halli goto exit; 10259da522aSManjunatha Halli 10359da522aSManjunatha Halli /* Wait for tune ended interrupt */ 10459da522aSManjunatha Halli init_completion(&fmdev->maintask_comp); 10559da522aSManjunatha Halli timeleft = wait_for_completion_timeout(&fmdev->maintask_comp, 10659da522aSManjunatha Halli FM_DRV_TX_TIMEOUT); 10759da522aSManjunatha Halli if (!timeleft) { 10859da522aSManjunatha Halli fmerr("Timeout(%d sec),didn't get tune ended int\n", 10959da522aSManjunatha Halli jiffies_to_msecs(FM_DRV_TX_TIMEOUT) / 1000); 11059da522aSManjunatha Halli ret = -ETIMEDOUT; 11159da522aSManjunatha Halli goto exit; 11259da522aSManjunatha Halli } 11359da522aSManjunatha Halli 11459da522aSManjunatha Halli /* Read freq back to confirm */ 11559da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, FREQ_SET, REG_RD, NULL, 2, &curr_frq, &resp_len); 11659da522aSManjunatha Halli if (ret < 0) 11759da522aSManjunatha Halli goto exit; 11859da522aSManjunatha Halli 11959da522aSManjunatha Halli curr_frq = be16_to_cpu(curr_frq); 12059da522aSManjunatha Halli curr_frq_in_khz = (fmdev->rx.region.bot_freq + ((u32)curr_frq * FM_FREQ_MUL)); 12159da522aSManjunatha Halli 12259da522aSManjunatha Halli if (curr_frq_in_khz != freq) { 12359da522aSManjunatha Halli pr_info("Frequency is set to (%d) but " 12459da522aSManjunatha Halli "requested freq is (%d)\n", curr_frq_in_khz, freq); 12559da522aSManjunatha Halli } 12659da522aSManjunatha Halli 12759da522aSManjunatha Halli /* Update local cache */ 12859da522aSManjunatha Halli fmdev->rx.freq = curr_frq_in_khz; 12959da522aSManjunatha Halli exit: 13059da522aSManjunatha Halli /* Re-enable default FM interrupts */ 13159da522aSManjunatha Halli fmdev->irq_info.mask = intr_flag; 13259da522aSManjunatha Halli payload = fmdev->irq_info.mask; 13359da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, INT_MASK_SET, REG_WR, &payload, 13459da522aSManjunatha Halli sizeof(payload), NULL, NULL); 13559da522aSManjunatha Halli if (ret < 0) 13659da522aSManjunatha Halli return ret; 13759da522aSManjunatha Halli 13859da522aSManjunatha Halli /* Reset RDS cache and current station pointers */ 13959da522aSManjunatha Halli fm_rx_reset_rds_cache(fmdev); 14059da522aSManjunatha Halli fm_rx_reset_station_info(fmdev); 14159da522aSManjunatha Halli 14259da522aSManjunatha Halli return ret; 14359da522aSManjunatha Halli } 14459da522aSManjunatha Halli 145d24674c6SXi Wang static int fm_rx_set_channel_spacing(struct fmdev *fmdev, u32 spacing) 14659da522aSManjunatha Halli { 14759da522aSManjunatha Halli u16 payload; 148d24674c6SXi Wang int ret; 14959da522aSManjunatha Halli 15059da522aSManjunatha Halli if (spacing > 0 && spacing <= 50000) 15159da522aSManjunatha Halli spacing = FM_CHANNEL_SPACING_50KHZ; 15259da522aSManjunatha Halli else if (spacing > 50000 && spacing <= 100000) 15359da522aSManjunatha Halli spacing = FM_CHANNEL_SPACING_100KHZ; 15459da522aSManjunatha Halli else 15559da522aSManjunatha Halli spacing = FM_CHANNEL_SPACING_200KHZ; 15659da522aSManjunatha Halli 15759da522aSManjunatha Halli /* set channel spacing */ 15859da522aSManjunatha Halli payload = spacing; 15959da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, CHANL_BW_SET, REG_WR, &payload, 16059da522aSManjunatha Halli sizeof(payload), NULL, NULL); 16159da522aSManjunatha Halli if (ret < 0) 16259da522aSManjunatha Halli return ret; 16359da522aSManjunatha Halli 16459da522aSManjunatha Halli fmdev->rx.region.chanl_space = spacing * FM_FREQ_MUL; 16559da522aSManjunatha Halli 16659da522aSManjunatha Halli return ret; 16759da522aSManjunatha Halli } 16859da522aSManjunatha Halli 169d24674c6SXi Wang int fm_rx_seek(struct fmdev *fmdev, u32 seek_upward, 17059da522aSManjunatha Halli u32 wrap_around, u32 spacing) 17159da522aSManjunatha Halli { 17259da522aSManjunatha Halli u32 resp_len; 17359da522aSManjunatha Halli u16 curr_frq, next_frq, last_frq; 17459da522aSManjunatha Halli u16 payload, int_reason, intr_flag; 17559da522aSManjunatha Halli u16 offset, space_idx; 17659da522aSManjunatha Halli unsigned long timeleft; 177d24674c6SXi Wang int ret; 17859da522aSManjunatha Halli 17959da522aSManjunatha Halli /* Set channel spacing */ 18059da522aSManjunatha Halli ret = fm_rx_set_channel_spacing(fmdev, spacing); 18159da522aSManjunatha Halli if (ret < 0) { 18259da522aSManjunatha Halli fmerr("Failed to set channel spacing\n"); 18359da522aSManjunatha Halli return ret; 18459da522aSManjunatha Halli } 18559da522aSManjunatha Halli 18659da522aSManjunatha Halli /* Read the current frequency from chip */ 18759da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, FREQ_SET, REG_RD, NULL, 18859da522aSManjunatha Halli sizeof(curr_frq), &curr_frq, &resp_len); 18959da522aSManjunatha Halli if (ret < 0) 19059da522aSManjunatha Halli return ret; 19159da522aSManjunatha Halli 19259da522aSManjunatha Halli curr_frq = be16_to_cpu(curr_frq); 19359da522aSManjunatha Halli last_frq = (fmdev->rx.region.top_freq - fmdev->rx.region.bot_freq) / FM_FREQ_MUL; 19459da522aSManjunatha Halli 19559da522aSManjunatha Halli /* Check the offset in order to be aligned to the channel spacing*/ 19659da522aSManjunatha Halli space_idx = fmdev->rx.region.chanl_space / FM_FREQ_MUL; 19759da522aSManjunatha Halli offset = curr_frq % space_idx; 19859da522aSManjunatha Halli 19959da522aSManjunatha Halli next_frq = seek_upward ? curr_frq + space_idx /* Seek Up */ : 20059da522aSManjunatha Halli curr_frq - space_idx /* Seek Down */ ; 20159da522aSManjunatha Halli 20259da522aSManjunatha Halli /* 20359da522aSManjunatha Halli * Add or subtract offset in order to stay aligned to the channel 20459da522aSManjunatha Halli * spacing. 20559da522aSManjunatha Halli */ 20659da522aSManjunatha Halli if ((short)next_frq < 0) 20759da522aSManjunatha Halli next_frq = last_frq - offset; 20859da522aSManjunatha Halli else if (next_frq > last_frq) 20959da522aSManjunatha Halli next_frq = 0 + offset; 21059da522aSManjunatha Halli 21159da522aSManjunatha Halli again: 21259da522aSManjunatha Halli /* Set calculated next frequency to perform seek */ 21359da522aSManjunatha Halli payload = next_frq; 21459da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, FREQ_SET, REG_WR, &payload, 21559da522aSManjunatha Halli sizeof(payload), NULL, NULL); 21659da522aSManjunatha Halli if (ret < 0) 21759da522aSManjunatha Halli return ret; 21859da522aSManjunatha Halli 21959da522aSManjunatha Halli /* Set search direction (0:Seek Down, 1:Seek Up) */ 22059da522aSManjunatha Halli payload = (seek_upward ? FM_SEARCH_DIRECTION_UP : FM_SEARCH_DIRECTION_DOWN); 22159da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, SEARCH_DIR_SET, REG_WR, &payload, 22259da522aSManjunatha Halli sizeof(payload), NULL, NULL); 22359da522aSManjunatha Halli if (ret < 0) 22459da522aSManjunatha Halli return ret; 22559da522aSManjunatha Halli 22659da522aSManjunatha Halli /* Read flags - just to clear any pending interrupts if we had */ 22759da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, FLAG_GET, REG_RD, NULL, 2, NULL, NULL); 22859da522aSManjunatha Halli if (ret < 0) 22959da522aSManjunatha Halli return ret; 23059da522aSManjunatha Halli 23159da522aSManjunatha Halli /* Enable FR, BL interrupts */ 23259da522aSManjunatha Halli intr_flag = fmdev->irq_info.mask; 23359da522aSManjunatha Halli fmdev->irq_info.mask = (FM_FR_EVENT | FM_BL_EVENT); 23459da522aSManjunatha Halli payload = fmdev->irq_info.mask; 23559da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, INT_MASK_SET, REG_WR, &payload, 23659da522aSManjunatha Halli sizeof(payload), NULL, NULL); 23759da522aSManjunatha Halli if (ret < 0) 23859da522aSManjunatha Halli return ret; 23959da522aSManjunatha Halli 24059da522aSManjunatha Halli /* Start seek */ 24159da522aSManjunatha Halli payload = FM_TUNER_AUTONOMOUS_SEARCH_MODE; 24259da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, TUNER_MODE_SET, REG_WR, &payload, 24359da522aSManjunatha Halli sizeof(payload), NULL, NULL); 24459da522aSManjunatha Halli if (ret < 0) 24559da522aSManjunatha Halli return ret; 24659da522aSManjunatha Halli 24759da522aSManjunatha Halli /* Wait for tune ended/band limit reached interrupt */ 24859da522aSManjunatha Halli init_completion(&fmdev->maintask_comp); 24959da522aSManjunatha Halli timeleft = wait_for_completion_timeout(&fmdev->maintask_comp, 25059da522aSManjunatha Halli FM_DRV_RX_SEEK_TIMEOUT); 25159da522aSManjunatha Halli if (!timeleft) { 25259da522aSManjunatha Halli fmerr("Timeout(%d sec),didn't get tune ended int\n", 25359da522aSManjunatha Halli jiffies_to_msecs(FM_DRV_RX_SEEK_TIMEOUT) / 1000); 254*54f6019bSHans Verkuil return -ENODATA; 25559da522aSManjunatha Halli } 25659da522aSManjunatha Halli 25759da522aSManjunatha Halli int_reason = fmdev->irq_info.flag & (FM_TUNE_COMPLETE | FM_BAND_LIMIT); 25859da522aSManjunatha Halli 25959da522aSManjunatha Halli /* Re-enable default FM interrupts */ 26059da522aSManjunatha Halli fmdev->irq_info.mask = intr_flag; 26159da522aSManjunatha Halli payload = fmdev->irq_info.mask; 26259da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, INT_MASK_SET, REG_WR, &payload, 26359da522aSManjunatha Halli sizeof(payload), NULL, NULL); 26459da522aSManjunatha Halli if (ret < 0) 26559da522aSManjunatha Halli return ret; 26659da522aSManjunatha Halli 26759da522aSManjunatha Halli if (int_reason & FM_BL_EVENT) { 26859da522aSManjunatha Halli if (wrap_around == 0) { 26959da522aSManjunatha Halli fmdev->rx.freq = seek_upward ? 27059da522aSManjunatha Halli fmdev->rx.region.top_freq : 27159da522aSManjunatha Halli fmdev->rx.region.bot_freq; 27259da522aSManjunatha Halli } else { 27359da522aSManjunatha Halli fmdev->rx.freq = seek_upward ? 27459da522aSManjunatha Halli fmdev->rx.region.bot_freq : 27559da522aSManjunatha Halli fmdev->rx.region.top_freq; 27659da522aSManjunatha Halli /* Calculate frequency index to write */ 27759da522aSManjunatha Halli next_frq = (fmdev->rx.freq - 27859da522aSManjunatha Halli fmdev->rx.region.bot_freq) / FM_FREQ_MUL; 27959da522aSManjunatha Halli goto again; 28059da522aSManjunatha Halli } 28159da522aSManjunatha Halli } else { 28259da522aSManjunatha Halli /* Read freq to know where operation tune operation stopped */ 28359da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, FREQ_SET, REG_RD, NULL, 2, 28459da522aSManjunatha Halli &curr_frq, &resp_len); 28559da522aSManjunatha Halli if (ret < 0) 28659da522aSManjunatha Halli return ret; 28759da522aSManjunatha Halli 28859da522aSManjunatha Halli curr_frq = be16_to_cpu(curr_frq); 28959da522aSManjunatha Halli fmdev->rx.freq = (fmdev->rx.region.bot_freq + 29059da522aSManjunatha Halli ((u32)curr_frq * FM_FREQ_MUL)); 29159da522aSManjunatha Halli 29259da522aSManjunatha Halli } 29359da522aSManjunatha Halli /* Reset RDS cache and current station pointers */ 29459da522aSManjunatha Halli fm_rx_reset_rds_cache(fmdev); 29559da522aSManjunatha Halli fm_rx_reset_station_info(fmdev); 29659da522aSManjunatha Halli 29759da522aSManjunatha Halli return ret; 29859da522aSManjunatha Halli } 29959da522aSManjunatha Halli 300d24674c6SXi Wang int fm_rx_set_volume(struct fmdev *fmdev, u16 vol_to_set) 30159da522aSManjunatha Halli { 30259da522aSManjunatha Halli u16 payload; 303d24674c6SXi Wang int ret; 30459da522aSManjunatha Halli 30559da522aSManjunatha Halli if (fmdev->curr_fmmode != FM_MODE_RX) 30659da522aSManjunatha Halli return -EPERM; 30759da522aSManjunatha Halli 30859da522aSManjunatha Halli if (vol_to_set < FM_RX_VOLUME_MIN || vol_to_set > FM_RX_VOLUME_MAX) { 30959da522aSManjunatha Halli fmerr("Volume is not within(%d-%d) range\n", 31059da522aSManjunatha Halli FM_RX_VOLUME_MIN, FM_RX_VOLUME_MAX); 31159da522aSManjunatha Halli return -EINVAL; 31259da522aSManjunatha Halli } 31359da522aSManjunatha Halli vol_to_set *= FM_RX_VOLUME_GAIN_STEP; 31459da522aSManjunatha Halli 31559da522aSManjunatha Halli payload = vol_to_set; 31659da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, VOLUME_SET, REG_WR, &payload, 31759da522aSManjunatha Halli sizeof(payload), NULL, NULL); 31859da522aSManjunatha Halli if (ret < 0) 31959da522aSManjunatha Halli return ret; 32059da522aSManjunatha Halli 32159da522aSManjunatha Halli fmdev->rx.volume = vol_to_set; 32259da522aSManjunatha Halli return ret; 32359da522aSManjunatha Halli } 32459da522aSManjunatha Halli 32559da522aSManjunatha Halli /* Get volume */ 326d24674c6SXi Wang int fm_rx_get_volume(struct fmdev *fmdev, u16 *curr_vol) 32759da522aSManjunatha Halli { 32859da522aSManjunatha Halli if (fmdev->curr_fmmode != FM_MODE_RX) 32959da522aSManjunatha Halli return -EPERM; 33059da522aSManjunatha Halli 33159da522aSManjunatha Halli if (curr_vol == NULL) { 33259da522aSManjunatha Halli fmerr("Invalid memory\n"); 33359da522aSManjunatha Halli return -ENOMEM; 33459da522aSManjunatha Halli } 33559da522aSManjunatha Halli 33659da522aSManjunatha Halli *curr_vol = fmdev->rx.volume / FM_RX_VOLUME_GAIN_STEP; 33759da522aSManjunatha Halli 33859da522aSManjunatha Halli return 0; 33959da522aSManjunatha Halli } 34059da522aSManjunatha Halli 34159da522aSManjunatha Halli /* To get current band's bottom and top frequency */ 342d24674c6SXi Wang int fm_rx_get_band_freq_range(struct fmdev *fmdev, u32 *bot_freq, u32 *top_freq) 34359da522aSManjunatha Halli { 34459da522aSManjunatha Halli if (bot_freq != NULL) 34559da522aSManjunatha Halli *bot_freq = fmdev->rx.region.bot_freq; 34659da522aSManjunatha Halli 34759da522aSManjunatha Halli if (top_freq != NULL) 34859da522aSManjunatha Halli *top_freq = fmdev->rx.region.top_freq; 34959da522aSManjunatha Halli 35059da522aSManjunatha Halli return 0; 35159da522aSManjunatha Halli } 35259da522aSManjunatha Halli 35359da522aSManjunatha Halli /* Returns current band index (0-Europe/US; 1-Japan) */ 35459da522aSManjunatha Halli void fm_rx_get_region(struct fmdev *fmdev, u8 *region) 35559da522aSManjunatha Halli { 35659da522aSManjunatha Halli *region = fmdev->rx.region.fm_band; 35759da522aSManjunatha Halli } 35859da522aSManjunatha Halli 35959da522aSManjunatha Halli /* Sets band (0-Europe/US; 1-Japan) */ 360d24674c6SXi Wang int fm_rx_set_region(struct fmdev *fmdev, u8 region_to_set) 36159da522aSManjunatha Halli { 36259da522aSManjunatha Halli u16 payload; 36359da522aSManjunatha Halli u32 new_frq = 0; 364d24674c6SXi Wang int ret; 36559da522aSManjunatha Halli 36659da522aSManjunatha Halli if (region_to_set != FM_BAND_EUROPE_US && 36759da522aSManjunatha Halli region_to_set != FM_BAND_JAPAN) { 36859da522aSManjunatha Halli fmerr("Invalid band\n"); 36959da522aSManjunatha Halli return -EINVAL; 37059da522aSManjunatha Halli } 37159da522aSManjunatha Halli 37259da522aSManjunatha Halli if (fmdev->rx.region.fm_band == region_to_set) { 37359da522aSManjunatha Halli fmerr("Requested band is already configured\n"); 37459da522aSManjunatha Halli return 0; 37559da522aSManjunatha Halli } 37659da522aSManjunatha Halli 37759da522aSManjunatha Halli /* Send cmd to set the band */ 37859da522aSManjunatha Halli payload = (u16)region_to_set; 37959da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, BAND_SET, REG_WR, &payload, 38059da522aSManjunatha Halli sizeof(payload), NULL, NULL); 38159da522aSManjunatha Halli if (ret < 0) 38259da522aSManjunatha Halli return ret; 38359da522aSManjunatha Halli 38459da522aSManjunatha Halli fmc_update_region_info(fmdev, region_to_set); 38559da522aSManjunatha Halli 38659da522aSManjunatha Halli /* Check whether current RX frequency is within band boundary */ 38759da522aSManjunatha Halli if (fmdev->rx.freq < fmdev->rx.region.bot_freq) 38859da522aSManjunatha Halli new_frq = fmdev->rx.region.bot_freq; 38959da522aSManjunatha Halli else if (fmdev->rx.freq > fmdev->rx.region.top_freq) 39059da522aSManjunatha Halli new_frq = fmdev->rx.region.top_freq; 39159da522aSManjunatha Halli 39259da522aSManjunatha Halli if (new_frq) { 39359da522aSManjunatha Halli fmdbg("Current freq is not within band limit boundary," 39459da522aSManjunatha Halli "switching to %d KHz\n", new_frq); 39559da522aSManjunatha Halli /* Current RX frequency is not in range. So, update it */ 39659da522aSManjunatha Halli ret = fm_rx_set_freq(fmdev, new_frq); 39759da522aSManjunatha Halli } 39859da522aSManjunatha Halli 39959da522aSManjunatha Halli return ret; 40059da522aSManjunatha Halli } 40159da522aSManjunatha Halli 40259da522aSManjunatha Halli /* Reads current mute mode (Mute Off/On/Attenuate)*/ 403d24674c6SXi Wang int fm_rx_get_mute_mode(struct fmdev *fmdev, u8 *curr_mute_mode) 40459da522aSManjunatha Halli { 40559da522aSManjunatha Halli if (fmdev->curr_fmmode != FM_MODE_RX) 40659da522aSManjunatha Halli return -EPERM; 40759da522aSManjunatha Halli 40859da522aSManjunatha Halli if (curr_mute_mode == NULL) { 40959da522aSManjunatha Halli fmerr("Invalid memory\n"); 41059da522aSManjunatha Halli return -ENOMEM; 41159da522aSManjunatha Halli } 41259da522aSManjunatha Halli 41359da522aSManjunatha Halli *curr_mute_mode = fmdev->rx.mute_mode; 41459da522aSManjunatha Halli 41559da522aSManjunatha Halli return 0; 41659da522aSManjunatha Halli } 41759da522aSManjunatha Halli 418d24674c6SXi Wang static int fm_config_rx_mute_reg(struct fmdev *fmdev) 41959da522aSManjunatha Halli { 42059da522aSManjunatha Halli u16 payload, muteval; 421d24674c6SXi Wang int ret; 42259da522aSManjunatha Halli 42359da522aSManjunatha Halli muteval = 0; 42459da522aSManjunatha Halli switch (fmdev->rx.mute_mode) { 42559da522aSManjunatha Halli case FM_MUTE_ON: 42659da522aSManjunatha Halli muteval = FM_RX_AC_MUTE_MODE; 42759da522aSManjunatha Halli break; 42859da522aSManjunatha Halli 42959da522aSManjunatha Halli case FM_MUTE_OFF: 43059da522aSManjunatha Halli muteval = FM_RX_UNMUTE_MODE; 43159da522aSManjunatha Halli break; 43259da522aSManjunatha Halli 43359da522aSManjunatha Halli case FM_MUTE_ATTENUATE: 43459da522aSManjunatha Halli muteval = FM_RX_SOFT_MUTE_FORCE_MODE; 43559da522aSManjunatha Halli break; 43659da522aSManjunatha Halli } 43759da522aSManjunatha Halli if (fmdev->rx.rf_depend_mute == FM_RX_RF_DEPENDENT_MUTE_ON) 43859da522aSManjunatha Halli muteval |= FM_RX_RF_DEP_MODE; 43959da522aSManjunatha Halli else 44059da522aSManjunatha Halli muteval &= ~FM_RX_RF_DEP_MODE; 44159da522aSManjunatha Halli 44259da522aSManjunatha Halli payload = muteval; 44359da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, MUTE_STATUS_SET, REG_WR, &payload, 44459da522aSManjunatha Halli sizeof(payload), NULL, NULL); 44559da522aSManjunatha Halli if (ret < 0) 44659da522aSManjunatha Halli return ret; 44759da522aSManjunatha Halli 44859da522aSManjunatha Halli return 0; 44959da522aSManjunatha Halli } 45059da522aSManjunatha Halli 45159da522aSManjunatha Halli /* Configures mute mode (Mute Off/On/Attenuate) */ 452d24674c6SXi Wang int fm_rx_set_mute_mode(struct fmdev *fmdev, u8 mute_mode_toset) 45359da522aSManjunatha Halli { 45459da522aSManjunatha Halli u8 org_state; 455d24674c6SXi Wang int ret; 45659da522aSManjunatha Halli 45759da522aSManjunatha Halli if (fmdev->rx.mute_mode == mute_mode_toset) 45859da522aSManjunatha Halli return 0; 45959da522aSManjunatha Halli 46059da522aSManjunatha Halli org_state = fmdev->rx.mute_mode; 46159da522aSManjunatha Halli fmdev->rx.mute_mode = mute_mode_toset; 46259da522aSManjunatha Halli 46359da522aSManjunatha Halli ret = fm_config_rx_mute_reg(fmdev); 46459da522aSManjunatha Halli if (ret < 0) { 46559da522aSManjunatha Halli fmdev->rx.mute_mode = org_state; 46659da522aSManjunatha Halli return ret; 46759da522aSManjunatha Halli } 46859da522aSManjunatha Halli 46959da522aSManjunatha Halli return 0; 47059da522aSManjunatha Halli } 47159da522aSManjunatha Halli 47259da522aSManjunatha Halli /* Gets RF dependent soft mute mode enable/disable status */ 473d24674c6SXi Wang int fm_rx_get_rfdepend_softmute(struct fmdev *fmdev, u8 *curr_mute_mode) 47459da522aSManjunatha Halli { 47559da522aSManjunatha Halli if (fmdev->curr_fmmode != FM_MODE_RX) 47659da522aSManjunatha Halli return -EPERM; 47759da522aSManjunatha Halli 47859da522aSManjunatha Halli if (curr_mute_mode == NULL) { 47959da522aSManjunatha Halli fmerr("Invalid memory\n"); 48059da522aSManjunatha Halli return -ENOMEM; 48159da522aSManjunatha Halli } 48259da522aSManjunatha Halli 48359da522aSManjunatha Halli *curr_mute_mode = fmdev->rx.rf_depend_mute; 48459da522aSManjunatha Halli 48559da522aSManjunatha Halli return 0; 48659da522aSManjunatha Halli } 48759da522aSManjunatha Halli 48859da522aSManjunatha Halli /* Sets RF dependent soft mute mode */ 489d24674c6SXi Wang int fm_rx_set_rfdepend_softmute(struct fmdev *fmdev, u8 rfdepend_mute) 49059da522aSManjunatha Halli { 49159da522aSManjunatha Halli u8 org_state; 492d24674c6SXi Wang int ret; 49359da522aSManjunatha Halli 49459da522aSManjunatha Halli if (fmdev->curr_fmmode != FM_MODE_RX) 49559da522aSManjunatha Halli return -EPERM; 49659da522aSManjunatha Halli 49759da522aSManjunatha Halli if (rfdepend_mute != FM_RX_RF_DEPENDENT_MUTE_ON && 49859da522aSManjunatha Halli rfdepend_mute != FM_RX_RF_DEPENDENT_MUTE_OFF) { 49959da522aSManjunatha Halli fmerr("Invalid RF dependent soft mute\n"); 50059da522aSManjunatha Halli return -EINVAL; 50159da522aSManjunatha Halli } 50259da522aSManjunatha Halli if (fmdev->rx.rf_depend_mute == rfdepend_mute) 50359da522aSManjunatha Halli return 0; 50459da522aSManjunatha Halli 50559da522aSManjunatha Halli org_state = fmdev->rx.rf_depend_mute; 50659da522aSManjunatha Halli fmdev->rx.rf_depend_mute = rfdepend_mute; 50759da522aSManjunatha Halli 50859da522aSManjunatha Halli ret = fm_config_rx_mute_reg(fmdev); 50959da522aSManjunatha Halli if (ret < 0) { 51059da522aSManjunatha Halli fmdev->rx.rf_depend_mute = org_state; 51159da522aSManjunatha Halli return ret; 51259da522aSManjunatha Halli } 51359da522aSManjunatha Halli 51459da522aSManjunatha Halli return 0; 51559da522aSManjunatha Halli } 51659da522aSManjunatha Halli 51759da522aSManjunatha Halli /* Returns the signal strength level of current channel */ 518d24674c6SXi Wang int fm_rx_get_rssi_level(struct fmdev *fmdev, u16 *rssilvl) 51959da522aSManjunatha Halli { 52059da522aSManjunatha Halli u16 curr_rssi_lel; 52159da522aSManjunatha Halli u32 resp_len; 522d24674c6SXi Wang int ret; 52359da522aSManjunatha Halli 52459da522aSManjunatha Halli if (rssilvl == NULL) { 52559da522aSManjunatha Halli fmerr("Invalid memory\n"); 52659da522aSManjunatha Halli return -ENOMEM; 52759da522aSManjunatha Halli } 52859da522aSManjunatha Halli /* Read current RSSI level */ 52959da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, RSSI_LVL_GET, REG_RD, NULL, 2, 53059da522aSManjunatha Halli &curr_rssi_lel, &resp_len); 53159da522aSManjunatha Halli if (ret < 0) 53259da522aSManjunatha Halli return ret; 53359da522aSManjunatha Halli 53459da522aSManjunatha Halli *rssilvl = be16_to_cpu(curr_rssi_lel); 53559da522aSManjunatha Halli 53659da522aSManjunatha Halli return 0; 53759da522aSManjunatha Halli } 53859da522aSManjunatha Halli 53959da522aSManjunatha Halli /* 54059da522aSManjunatha Halli * Sets the signal strength level that once reached 54159da522aSManjunatha Halli * will stop the auto search process 54259da522aSManjunatha Halli */ 543d24674c6SXi Wang int fm_rx_set_rssi_threshold(struct fmdev *fmdev, short rssi_lvl_toset) 54459da522aSManjunatha Halli { 54559da522aSManjunatha Halli u16 payload; 546d24674c6SXi Wang int ret; 54759da522aSManjunatha Halli 54859da522aSManjunatha Halli if (rssi_lvl_toset < FM_RX_RSSI_THRESHOLD_MIN || 54959da522aSManjunatha Halli rssi_lvl_toset > FM_RX_RSSI_THRESHOLD_MAX) { 55059da522aSManjunatha Halli fmerr("Invalid RSSI threshold level\n"); 55159da522aSManjunatha Halli return -EINVAL; 55259da522aSManjunatha Halli } 55359da522aSManjunatha Halli payload = (u16)rssi_lvl_toset; 55459da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, SEARCH_LVL_SET, REG_WR, &payload, 55559da522aSManjunatha Halli sizeof(payload), NULL, NULL); 55659da522aSManjunatha Halli if (ret < 0) 55759da522aSManjunatha Halli return ret; 55859da522aSManjunatha Halli 55959da522aSManjunatha Halli fmdev->rx.rssi_threshold = rssi_lvl_toset; 56059da522aSManjunatha Halli 56159da522aSManjunatha Halli return 0; 56259da522aSManjunatha Halli } 56359da522aSManjunatha Halli 56459da522aSManjunatha Halli /* Returns current RX RSSI threshold value */ 565d24674c6SXi Wang int fm_rx_get_rssi_threshold(struct fmdev *fmdev, short *curr_rssi_lvl) 56659da522aSManjunatha Halli { 56759da522aSManjunatha Halli if (fmdev->curr_fmmode != FM_MODE_RX) 56859da522aSManjunatha Halli return -EPERM; 56959da522aSManjunatha Halli 57059da522aSManjunatha Halli if (curr_rssi_lvl == NULL) { 57159da522aSManjunatha Halli fmerr("Invalid memory\n"); 57259da522aSManjunatha Halli return -ENOMEM; 57359da522aSManjunatha Halli } 57459da522aSManjunatha Halli 57559da522aSManjunatha Halli *curr_rssi_lvl = fmdev->rx.rssi_threshold; 57659da522aSManjunatha Halli 57759da522aSManjunatha Halli return 0; 57859da522aSManjunatha Halli } 57959da522aSManjunatha Halli 58059da522aSManjunatha Halli /* Sets RX stereo/mono modes */ 581d24674c6SXi Wang int fm_rx_set_stereo_mono(struct fmdev *fmdev, u16 mode) 58259da522aSManjunatha Halli { 58359da522aSManjunatha Halli u16 payload; 584d24674c6SXi Wang int ret; 58559da522aSManjunatha Halli 58659da522aSManjunatha Halli if (mode != FM_STEREO_MODE && mode != FM_MONO_MODE) { 58759da522aSManjunatha Halli fmerr("Invalid mode\n"); 58859da522aSManjunatha Halli return -EINVAL; 58959da522aSManjunatha Halli } 59059da522aSManjunatha Halli 59159da522aSManjunatha Halli /* Set stereo/mono mode */ 59259da522aSManjunatha Halli payload = (u16)mode; 59359da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, MOST_MODE_SET, REG_WR, &payload, 59459da522aSManjunatha Halli sizeof(payload), NULL, NULL); 59559da522aSManjunatha Halli if (ret < 0) 59659da522aSManjunatha Halli return ret; 59759da522aSManjunatha Halli 59859da522aSManjunatha Halli /* Set stereo blending mode */ 59959da522aSManjunatha Halli payload = FM_STEREO_SOFT_BLEND; 60059da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, MOST_BLEND_SET, REG_WR, &payload, 60159da522aSManjunatha Halli sizeof(payload), NULL, NULL); 60259da522aSManjunatha Halli if (ret < 0) 60359da522aSManjunatha Halli return ret; 60459da522aSManjunatha Halli 60559da522aSManjunatha Halli return 0; 60659da522aSManjunatha Halli } 60759da522aSManjunatha Halli 60859da522aSManjunatha Halli /* Gets current RX stereo/mono mode */ 609d24674c6SXi Wang int fm_rx_get_stereo_mono(struct fmdev *fmdev, u16 *mode) 61059da522aSManjunatha Halli { 61159da522aSManjunatha Halli u16 curr_mode; 612d24674c6SXi Wang u32 resp_len; 613d24674c6SXi Wang int ret; 61459da522aSManjunatha Halli 61559da522aSManjunatha Halli if (mode == NULL) { 61659da522aSManjunatha Halli fmerr("Invalid memory\n"); 61759da522aSManjunatha Halli return -ENOMEM; 61859da522aSManjunatha Halli } 61959da522aSManjunatha Halli 62059da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, MOST_MODE_SET, REG_RD, NULL, 2, 62159da522aSManjunatha Halli &curr_mode, &resp_len); 62259da522aSManjunatha Halli if (ret < 0) 62359da522aSManjunatha Halli return ret; 62459da522aSManjunatha Halli 62559da522aSManjunatha Halli *mode = be16_to_cpu(curr_mode); 62659da522aSManjunatha Halli 62759da522aSManjunatha Halli return 0; 62859da522aSManjunatha Halli } 62959da522aSManjunatha Halli 63059da522aSManjunatha Halli /* Choose RX de-emphasis filter mode (50us/75us) */ 631d24674c6SXi Wang int fm_rx_set_deemphasis_mode(struct fmdev *fmdev, u16 mode) 63259da522aSManjunatha Halli { 63359da522aSManjunatha Halli u16 payload; 634d24674c6SXi Wang int ret; 63559da522aSManjunatha Halli 63659da522aSManjunatha Halli if (fmdev->curr_fmmode != FM_MODE_RX) 63759da522aSManjunatha Halli return -EPERM; 63859da522aSManjunatha Halli 63959da522aSManjunatha Halli if (mode != FM_RX_EMPHASIS_FILTER_50_USEC && 64059da522aSManjunatha Halli mode != FM_RX_EMPHASIS_FILTER_75_USEC) { 64159da522aSManjunatha Halli fmerr("Invalid rx de-emphasis mode (%d)\n", mode); 64259da522aSManjunatha Halli return -EINVAL; 64359da522aSManjunatha Halli } 64459da522aSManjunatha Halli 64559da522aSManjunatha Halli payload = mode; 64659da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, DEMPH_MODE_SET, REG_WR, &payload, 64759da522aSManjunatha Halli sizeof(payload), NULL, NULL); 64859da522aSManjunatha Halli if (ret < 0) 64959da522aSManjunatha Halli return ret; 65059da522aSManjunatha Halli 65159da522aSManjunatha Halli fmdev->rx.deemphasis_mode = mode; 65259da522aSManjunatha Halli 65359da522aSManjunatha Halli return 0; 65459da522aSManjunatha Halli } 65559da522aSManjunatha Halli 65659da522aSManjunatha Halli /* Gets current RX de-emphasis filter mode */ 657d24674c6SXi Wang int fm_rx_get_deemph_mode(struct fmdev *fmdev, u16 *curr_deemphasis_mode) 65859da522aSManjunatha Halli { 65959da522aSManjunatha Halli if (fmdev->curr_fmmode != FM_MODE_RX) 66059da522aSManjunatha Halli return -EPERM; 66159da522aSManjunatha Halli 66259da522aSManjunatha Halli if (curr_deemphasis_mode == NULL) { 66359da522aSManjunatha Halli fmerr("Invalid memory\n"); 66459da522aSManjunatha Halli return -ENOMEM; 66559da522aSManjunatha Halli } 66659da522aSManjunatha Halli 66759da522aSManjunatha Halli *curr_deemphasis_mode = fmdev->rx.deemphasis_mode; 66859da522aSManjunatha Halli 66959da522aSManjunatha Halli return 0; 67059da522aSManjunatha Halli } 67159da522aSManjunatha Halli 67259da522aSManjunatha Halli /* Enable/Disable RX RDS */ 673d24674c6SXi Wang int fm_rx_set_rds_mode(struct fmdev *fmdev, u8 rds_en_dis) 67459da522aSManjunatha Halli { 67559da522aSManjunatha Halli u16 payload; 676d24674c6SXi Wang int ret; 67759da522aSManjunatha Halli 67859da522aSManjunatha Halli if (rds_en_dis != FM_RDS_ENABLE && rds_en_dis != FM_RDS_DISABLE) { 67959da522aSManjunatha Halli fmerr("Invalid rds option\n"); 68059da522aSManjunatha Halli return -EINVAL; 68159da522aSManjunatha Halli } 68259da522aSManjunatha Halli 68359da522aSManjunatha Halli if (rds_en_dis == FM_RDS_ENABLE 68459da522aSManjunatha Halli && fmdev->rx.rds.flag == FM_RDS_DISABLE) { 68559da522aSManjunatha Halli /* Turn on RX RDS and RDS circuit */ 68659da522aSManjunatha Halli payload = FM_RX_PWR_SET_FM_AND_RDS_BLK_ON; 68759da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, POWER_SET, REG_WR, &payload, 68859da522aSManjunatha Halli sizeof(payload), NULL, NULL); 68959da522aSManjunatha Halli if (ret < 0) 69059da522aSManjunatha Halli return ret; 69159da522aSManjunatha Halli 69259da522aSManjunatha Halli /* Clear and reset RDS FIFO */ 69359da522aSManjunatha Halli payload = FM_RX_RDS_FLUSH_FIFO; 69459da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, RDS_CNTRL_SET, REG_WR, &payload, 69559da522aSManjunatha Halli sizeof(payload), NULL, NULL); 69659da522aSManjunatha Halli if (ret < 0) 69759da522aSManjunatha Halli return ret; 69859da522aSManjunatha Halli 69959da522aSManjunatha Halli /* Read flags - just to clear any pending interrupts. */ 70059da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, FLAG_GET, REG_RD, NULL, 2, 70159da522aSManjunatha Halli NULL, NULL); 70259da522aSManjunatha Halli if (ret < 0) 70359da522aSManjunatha Halli return ret; 70459da522aSManjunatha Halli 70559da522aSManjunatha Halli /* Set RDS FIFO threshold value */ 70659da522aSManjunatha Halli payload = FM_RX_RDS_FIFO_THRESHOLD; 70759da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, RDS_MEM_SET, REG_WR, &payload, 70859da522aSManjunatha Halli sizeof(payload), NULL, NULL); 70959da522aSManjunatha Halli if (ret < 0) 71059da522aSManjunatha Halli return ret; 71159da522aSManjunatha Halli 71259da522aSManjunatha Halli /* Enable RDS interrupt */ 71359da522aSManjunatha Halli fmdev->irq_info.mask |= FM_RDS_EVENT; 71459da522aSManjunatha Halli payload = fmdev->irq_info.mask; 71559da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, INT_MASK_SET, REG_WR, &payload, 71659da522aSManjunatha Halli sizeof(payload), NULL, NULL); 71759da522aSManjunatha Halli if (ret < 0) { 71859da522aSManjunatha Halli fmdev->irq_info.mask &= ~FM_RDS_EVENT; 71959da522aSManjunatha Halli return ret; 72059da522aSManjunatha Halli } 72159da522aSManjunatha Halli 72259da522aSManjunatha Halli /* Update our local flag */ 72359da522aSManjunatha Halli fmdev->rx.rds.flag = FM_RDS_ENABLE; 72459da522aSManjunatha Halli } else if (rds_en_dis == FM_RDS_DISABLE 72559da522aSManjunatha Halli && fmdev->rx.rds.flag == FM_RDS_ENABLE) { 72659da522aSManjunatha Halli /* Turn off RX RDS */ 72759da522aSManjunatha Halli payload = FM_RX_PWR_SET_FM_ON_RDS_OFF; 72859da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, POWER_SET, REG_WR, &payload, 72959da522aSManjunatha Halli sizeof(payload), NULL, NULL); 73059da522aSManjunatha Halli if (ret < 0) 73159da522aSManjunatha Halli return ret; 73259da522aSManjunatha Halli 73359da522aSManjunatha Halli /* Reset RDS pointers */ 73459da522aSManjunatha Halli fmdev->rx.rds.last_blk_idx = 0; 73559da522aSManjunatha Halli fmdev->rx.rds.wr_idx = 0; 73659da522aSManjunatha Halli fmdev->rx.rds.rd_idx = 0; 73759da522aSManjunatha Halli fm_rx_reset_station_info(fmdev); 73859da522aSManjunatha Halli 73959da522aSManjunatha Halli /* Update RDS local cache */ 74059da522aSManjunatha Halli fmdev->irq_info.mask &= ~(FM_RDS_EVENT); 74159da522aSManjunatha Halli fmdev->rx.rds.flag = FM_RDS_DISABLE; 74259da522aSManjunatha Halli } 74359da522aSManjunatha Halli 74459da522aSManjunatha Halli return 0; 74559da522aSManjunatha Halli } 74659da522aSManjunatha Halli 74759da522aSManjunatha Halli /* Returns current RX RDS enable/disable status */ 748d24674c6SXi Wang int fm_rx_get_rds_mode(struct fmdev *fmdev, u8 *curr_rds_en_dis) 74959da522aSManjunatha Halli { 75059da522aSManjunatha Halli if (fmdev->curr_fmmode != FM_MODE_RX) 75159da522aSManjunatha Halli return -EPERM; 75259da522aSManjunatha Halli 75359da522aSManjunatha Halli if (curr_rds_en_dis == NULL) { 75459da522aSManjunatha Halli fmerr("Invalid memory\n"); 75559da522aSManjunatha Halli return -ENOMEM; 75659da522aSManjunatha Halli } 75759da522aSManjunatha Halli 75859da522aSManjunatha Halli *curr_rds_en_dis = fmdev->rx.rds.flag; 75959da522aSManjunatha Halli 76059da522aSManjunatha Halli return 0; 76159da522aSManjunatha Halli } 76259da522aSManjunatha Halli 76359da522aSManjunatha Halli /* Sets RDS operation mode (RDS/RDBS) */ 764d24674c6SXi Wang int fm_rx_set_rds_system(struct fmdev *fmdev, u8 rds_mode) 76559da522aSManjunatha Halli { 76659da522aSManjunatha Halli u16 payload; 767d24674c6SXi Wang int ret; 76859da522aSManjunatha Halli 76959da522aSManjunatha Halli if (fmdev->curr_fmmode != FM_MODE_RX) 77059da522aSManjunatha Halli return -EPERM; 77159da522aSManjunatha Halli 77259da522aSManjunatha Halli if (rds_mode != FM_RDS_SYSTEM_RDS && rds_mode != FM_RDS_SYSTEM_RBDS) { 77359da522aSManjunatha Halli fmerr("Invalid rds mode\n"); 77459da522aSManjunatha Halli return -EINVAL; 77559da522aSManjunatha Halli } 77659da522aSManjunatha Halli /* Set RDS operation mode */ 77759da522aSManjunatha Halli payload = (u16)rds_mode; 77859da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, RDS_SYSTEM_SET, REG_WR, &payload, 77959da522aSManjunatha Halli sizeof(payload), NULL, NULL); 78059da522aSManjunatha Halli if (ret < 0) 78159da522aSManjunatha Halli return ret; 78259da522aSManjunatha Halli 78359da522aSManjunatha Halli fmdev->rx.rds_mode = rds_mode; 78459da522aSManjunatha Halli 78559da522aSManjunatha Halli return 0; 78659da522aSManjunatha Halli } 78759da522aSManjunatha Halli 78859da522aSManjunatha Halli /* Returns current RDS operation mode */ 789d24674c6SXi Wang int fm_rx_get_rds_system(struct fmdev *fmdev, u8 *rds_mode) 79059da522aSManjunatha Halli { 79159da522aSManjunatha Halli if (fmdev->curr_fmmode != FM_MODE_RX) 79259da522aSManjunatha Halli return -EPERM; 79359da522aSManjunatha Halli 79459da522aSManjunatha Halli if (rds_mode == NULL) { 79559da522aSManjunatha Halli fmerr("Invalid memory\n"); 79659da522aSManjunatha Halli return -ENOMEM; 79759da522aSManjunatha Halli } 79859da522aSManjunatha Halli 79959da522aSManjunatha Halli *rds_mode = fmdev->rx.rds_mode; 80059da522aSManjunatha Halli 80159da522aSManjunatha Halli return 0; 80259da522aSManjunatha Halli } 80359da522aSManjunatha Halli 80459da522aSManjunatha Halli /* Configures Alternate Frequency switch mode */ 805d24674c6SXi Wang int fm_rx_set_af_switch(struct fmdev *fmdev, u8 af_mode) 80659da522aSManjunatha Halli { 80759da522aSManjunatha Halli u16 payload; 808d24674c6SXi Wang int ret; 80959da522aSManjunatha Halli 81059da522aSManjunatha Halli if (fmdev->curr_fmmode != FM_MODE_RX) 81159da522aSManjunatha Halli return -EPERM; 81259da522aSManjunatha Halli 81359da522aSManjunatha Halli if (af_mode != FM_RX_RDS_AF_SWITCH_MODE_ON && 81459da522aSManjunatha Halli af_mode != FM_RX_RDS_AF_SWITCH_MODE_OFF) { 81559da522aSManjunatha Halli fmerr("Invalid af mode\n"); 81659da522aSManjunatha Halli return -EINVAL; 81759da522aSManjunatha Halli } 81859da522aSManjunatha Halli /* Enable/disable low RSSI interrupt based on af_mode */ 81959da522aSManjunatha Halli if (af_mode == FM_RX_RDS_AF_SWITCH_MODE_ON) 82059da522aSManjunatha Halli fmdev->irq_info.mask |= FM_LEV_EVENT; 82159da522aSManjunatha Halli else 82259da522aSManjunatha Halli fmdev->irq_info.mask &= ~FM_LEV_EVENT; 82359da522aSManjunatha Halli 82459da522aSManjunatha Halli payload = fmdev->irq_info.mask; 82559da522aSManjunatha Halli ret = fmc_send_cmd(fmdev, INT_MASK_SET, REG_WR, &payload, 82659da522aSManjunatha Halli sizeof(payload), NULL, NULL); 82759da522aSManjunatha Halli if (ret < 0) 82859da522aSManjunatha Halli return ret; 82959da522aSManjunatha Halli 83059da522aSManjunatha Halli fmdev->rx.af_mode = af_mode; 83159da522aSManjunatha Halli 83259da522aSManjunatha Halli return 0; 83359da522aSManjunatha Halli } 83459da522aSManjunatha Halli 83559da522aSManjunatha Halli /* Returns Alternate Frequency switch status */ 836d24674c6SXi Wang int fm_rx_get_af_switch(struct fmdev *fmdev, u8 *af_mode) 83759da522aSManjunatha Halli { 83859da522aSManjunatha Halli if (fmdev->curr_fmmode != FM_MODE_RX) 83959da522aSManjunatha Halli return -EPERM; 84059da522aSManjunatha Halli 84159da522aSManjunatha Halli if (af_mode == NULL) { 84259da522aSManjunatha Halli fmerr("Invalid memory\n"); 84359da522aSManjunatha Halli return -ENOMEM; 84459da522aSManjunatha Halli } 84559da522aSManjunatha Halli 84659da522aSManjunatha Halli *af_mode = fmdev->rx.af_mode; 84759da522aSManjunatha Halli 84859da522aSManjunatha Halli return 0; 84959da522aSManjunatha Halli } 850