18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * FM Driver for Connectivity chip of Texas Instruments. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Common header for all FM driver sub-modules. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Copyright (C) 2011 Texas Instruments 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#ifndef _FM_DRV_H 118c2ecf20Sopenharmony_ci#define _FM_DRV_H 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <linux/skbuff.h> 148c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 158c2ecf20Sopenharmony_ci#include <sound/core.h> 168c2ecf20Sopenharmony_ci#include <sound/initval.h> 178c2ecf20Sopenharmony_ci#include <linux/timer.h> 188c2ecf20Sopenharmony_ci#include <media/v4l2-ioctl.h> 198c2ecf20Sopenharmony_ci#include <media/v4l2-common.h> 208c2ecf20Sopenharmony_ci#include <media/v4l2-device.h> 218c2ecf20Sopenharmony_ci#include <media/v4l2-ctrls.h> 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define FM_DRV_VERSION "0.1.1" 248c2ecf20Sopenharmony_ci#define FM_DRV_NAME "ti_fmdrv" 258c2ecf20Sopenharmony_ci#define FM_DRV_CARD_SHORT_NAME "TI FM Radio" 268c2ecf20Sopenharmony_ci#define FM_DRV_CARD_LONG_NAME "Texas Instruments FM Radio" 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci/* Flag info */ 298c2ecf20Sopenharmony_ci#define FM_INTTASK_RUNNING 0 308c2ecf20Sopenharmony_ci#define FM_INTTASK_SCHEDULE_PENDING 1 318c2ecf20Sopenharmony_ci#define FM_FW_DW_INPROGRESS 2 328c2ecf20Sopenharmony_ci#define FM_CORE_READY 3 338c2ecf20Sopenharmony_ci#define FM_CORE_TRANSPORT_READY 4 348c2ecf20Sopenharmony_ci#define FM_AF_SWITCH_INPROGRESS 5 358c2ecf20Sopenharmony_ci#define FM_CORE_TX_XMITING 6 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci#define FM_TUNE_COMPLETE 0x1 388c2ecf20Sopenharmony_ci#define FM_BAND_LIMIT 0x2 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci#define FM_DRV_TX_TIMEOUT (5*HZ) /* 5 seconds */ 418c2ecf20Sopenharmony_ci#define FM_DRV_RX_SEEK_TIMEOUT (20*HZ) /* 20 seconds */ 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci#define fmerr(format, ...) \ 448c2ecf20Sopenharmony_ci printk(KERN_ERR "fmdrv: " format, ## __VA_ARGS__) 458c2ecf20Sopenharmony_ci#define fmwarn(format, ...) \ 468c2ecf20Sopenharmony_ci printk(KERN_WARNING "fmdrv: " format, ##__VA_ARGS__) 478c2ecf20Sopenharmony_ci#ifdef DEBUG 488c2ecf20Sopenharmony_ci#define fmdbg(format, ...) \ 498c2ecf20Sopenharmony_ci printk(KERN_DEBUG "fmdrv: " format, ## __VA_ARGS__) 508c2ecf20Sopenharmony_ci#else /* DEBUG */ 518c2ecf20Sopenharmony_ci#define fmdbg(format, ...) do {} while(0) 528c2ecf20Sopenharmony_ci#endif 538c2ecf20Sopenharmony_cienum { 548c2ecf20Sopenharmony_ci FM_MODE_OFF, 558c2ecf20Sopenharmony_ci FM_MODE_TX, 568c2ecf20Sopenharmony_ci FM_MODE_RX, 578c2ecf20Sopenharmony_ci FM_MODE_ENTRY_MAX 588c2ecf20Sopenharmony_ci}; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci#define FM_RX_RDS_INFO_FIELD_MAX 8 /* 4 Group * 2 Bytes */ 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci/* RX RDS data format */ 638c2ecf20Sopenharmony_cistruct fm_rdsdata_format { 648c2ecf20Sopenharmony_ci union { 658c2ecf20Sopenharmony_ci struct { 668c2ecf20Sopenharmony_ci u8 buff[FM_RX_RDS_INFO_FIELD_MAX]; 678c2ecf20Sopenharmony_ci } groupdatabuff; 688c2ecf20Sopenharmony_ci struct { 698c2ecf20Sopenharmony_ci u16 pidata; 708c2ecf20Sopenharmony_ci u8 blk_b[2]; 718c2ecf20Sopenharmony_ci u8 blk_c[2]; 728c2ecf20Sopenharmony_ci u8 blk_d[2]; 738c2ecf20Sopenharmony_ci } groupgeneral; 748c2ecf20Sopenharmony_ci struct { 758c2ecf20Sopenharmony_ci u16 pidata; 768c2ecf20Sopenharmony_ci u8 blk_b[2]; 778c2ecf20Sopenharmony_ci u8 af[2]; 788c2ecf20Sopenharmony_ci u8 ps[2]; 798c2ecf20Sopenharmony_ci } group0A; 808c2ecf20Sopenharmony_ci struct { 818c2ecf20Sopenharmony_ci u16 pi[2]; 828c2ecf20Sopenharmony_ci u8 blk_b[2]; 838c2ecf20Sopenharmony_ci u8 ps[2]; 848c2ecf20Sopenharmony_ci } group0B; 858c2ecf20Sopenharmony_ci } data; 868c2ecf20Sopenharmony_ci}; 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci/* FM region (Europe/US, Japan) info */ 898c2ecf20Sopenharmony_cistruct region_info { 908c2ecf20Sopenharmony_ci u32 chanl_space; 918c2ecf20Sopenharmony_ci u32 bot_freq; 928c2ecf20Sopenharmony_ci u32 top_freq; 938c2ecf20Sopenharmony_ci u8 fm_band; 948c2ecf20Sopenharmony_ci}; 958c2ecf20Sopenharmony_cistruct fmdev; 968c2ecf20Sopenharmony_citypedef void (*int_handler_prototype) (struct fmdev *); 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci/* FM Interrupt processing related info */ 998c2ecf20Sopenharmony_cistruct fm_irq { 1008c2ecf20Sopenharmony_ci u8 stage; 1018c2ecf20Sopenharmony_ci u16 flag; /* FM interrupt flag */ 1028c2ecf20Sopenharmony_ci u16 mask; /* FM interrupt mask */ 1038c2ecf20Sopenharmony_ci /* Interrupt process timeout handler */ 1048c2ecf20Sopenharmony_ci struct timer_list timer; 1058c2ecf20Sopenharmony_ci u8 retry; 1068c2ecf20Sopenharmony_ci int_handler_prototype *handlers; 1078c2ecf20Sopenharmony_ci}; 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci/* RDS info */ 1108c2ecf20Sopenharmony_cistruct fm_rds { 1118c2ecf20Sopenharmony_ci u8 flag; /* RX RDS on/off status */ 1128c2ecf20Sopenharmony_ci u8 last_blk_idx; /* Last received RDS block */ 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci /* RDS buffer */ 1158c2ecf20Sopenharmony_ci wait_queue_head_t read_queue; 1168c2ecf20Sopenharmony_ci u32 buf_size; /* Size is always multiple of 3 */ 1178c2ecf20Sopenharmony_ci u32 wr_idx; 1188c2ecf20Sopenharmony_ci u32 rd_idx; 1198c2ecf20Sopenharmony_ci u8 *buff; 1208c2ecf20Sopenharmony_ci}; 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci#define FM_RDS_MAX_AF_LIST 25 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci/* 1258c2ecf20Sopenharmony_ci * Current RX channel Alternate Frequency cache. 1268c2ecf20Sopenharmony_ci * This info is used to switch to other freq (AF) 1278c2ecf20Sopenharmony_ci * when current channel signal strength is below RSSI threshold. 1288c2ecf20Sopenharmony_ci */ 1298c2ecf20Sopenharmony_cistruct tuned_station_info { 1308c2ecf20Sopenharmony_ci u16 picode; 1318c2ecf20Sopenharmony_ci u32 af_cache[FM_RDS_MAX_AF_LIST]; 1328c2ecf20Sopenharmony_ci u8 afcache_size; 1338c2ecf20Sopenharmony_ci u8 af_list_max; 1348c2ecf20Sopenharmony_ci}; 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci/* FM RX mode info */ 1378c2ecf20Sopenharmony_cistruct fm_rx { 1388c2ecf20Sopenharmony_ci struct region_info region; /* Current selected band */ 1398c2ecf20Sopenharmony_ci u32 freq; /* Current RX frquency */ 1408c2ecf20Sopenharmony_ci u8 mute_mode; /* Current mute mode */ 1418c2ecf20Sopenharmony_ci u8 deemphasis_mode; /* Current deemphasis mode */ 1428c2ecf20Sopenharmony_ci /* RF dependent soft mute mode */ 1438c2ecf20Sopenharmony_ci u8 rf_depend_mute; 1448c2ecf20Sopenharmony_ci u16 volume; /* Current volume level */ 1458c2ecf20Sopenharmony_ci u16 rssi_threshold; /* Current RSSI threshold level */ 1468c2ecf20Sopenharmony_ci /* Holds the index of the current AF jump */ 1478c2ecf20Sopenharmony_ci u8 afjump_idx; 1488c2ecf20Sopenharmony_ci /* Will hold the frequency before the jump */ 1498c2ecf20Sopenharmony_ci u32 freq_before_jump; 1508c2ecf20Sopenharmony_ci u8 rds_mode; /* RDS operation mode (RDS/RDBS) */ 1518c2ecf20Sopenharmony_ci u8 af_mode; /* Alternate frequency on/off */ 1528c2ecf20Sopenharmony_ci struct tuned_station_info stat_info; 1538c2ecf20Sopenharmony_ci struct fm_rds rds; 1548c2ecf20Sopenharmony_ci}; 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci#define FMTX_RDS_TXT_STR_SIZE 25 1578c2ecf20Sopenharmony_ci/* 1588c2ecf20Sopenharmony_ci * FM TX RDS data 1598c2ecf20Sopenharmony_ci * 1608c2ecf20Sopenharmony_ci * @ text_type: is the text following PS or RT 1618c2ecf20Sopenharmony_ci * @ text: radio text string which could either be PS or RT 1628c2ecf20Sopenharmony_ci * @ af_freq: alternate frequency for Tx 1638c2ecf20Sopenharmony_ci * TODO: to be declared in application 1648c2ecf20Sopenharmony_ci */ 1658c2ecf20Sopenharmony_cistruct tx_rds { 1668c2ecf20Sopenharmony_ci u8 text_type; 1678c2ecf20Sopenharmony_ci u8 text[FMTX_RDS_TXT_STR_SIZE]; 1688c2ecf20Sopenharmony_ci u8 flag; 1698c2ecf20Sopenharmony_ci u32 af_freq; 1708c2ecf20Sopenharmony_ci}; 1718c2ecf20Sopenharmony_ci/* 1728c2ecf20Sopenharmony_ci * FM TX global data 1738c2ecf20Sopenharmony_ci * 1748c2ecf20Sopenharmony_ci * @ pwr_lvl: Power Level of the Transmission from mixer control 1758c2ecf20Sopenharmony_ci * @ xmit_state: Transmission state = Updated locally upon Start/Stop 1768c2ecf20Sopenharmony_ci * @ audio_io: i2S/Analog 1778c2ecf20Sopenharmony_ci * @ tx_frq: Transmission frequency 1788c2ecf20Sopenharmony_ci */ 1798c2ecf20Sopenharmony_cistruct fmtx_data { 1808c2ecf20Sopenharmony_ci u8 pwr_lvl; 1818c2ecf20Sopenharmony_ci u8 xmit_state; 1828c2ecf20Sopenharmony_ci u8 audio_io; 1838c2ecf20Sopenharmony_ci u8 region; 1848c2ecf20Sopenharmony_ci u16 aud_mode; 1858c2ecf20Sopenharmony_ci u32 preemph; 1868c2ecf20Sopenharmony_ci u32 tx_frq; 1878c2ecf20Sopenharmony_ci struct tx_rds rds; 1888c2ecf20Sopenharmony_ci}; 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci/* FM driver operation structure */ 1918c2ecf20Sopenharmony_cistruct fmdev { 1928c2ecf20Sopenharmony_ci struct video_device *radio_dev; /* V4L2 video device pointer */ 1938c2ecf20Sopenharmony_ci struct v4l2_device v4l2_dev; /* V4L2 top level struct */ 1948c2ecf20Sopenharmony_ci struct snd_card *card; /* Card which holds FM mixer controls */ 1958c2ecf20Sopenharmony_ci u16 asci_id; 1968c2ecf20Sopenharmony_ci spinlock_t rds_buff_lock; /* To protect access to RDS buffer */ 1978c2ecf20Sopenharmony_ci spinlock_t resp_skb_lock; /* To protect access to received SKB */ 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci long flag; /* FM driver state machine info */ 2008c2ecf20Sopenharmony_ci int streg_cbdata; /* status of ST registration */ 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ci struct sk_buff_head rx_q; /* RX queue */ 2038c2ecf20Sopenharmony_ci struct tasklet_struct rx_task; /* RX Tasklet */ 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci struct sk_buff_head tx_q; /* TX queue */ 2068c2ecf20Sopenharmony_ci struct tasklet_struct tx_task; /* TX Tasklet */ 2078c2ecf20Sopenharmony_ci unsigned long last_tx_jiffies; /* Timestamp of last pkt sent */ 2088c2ecf20Sopenharmony_ci atomic_t tx_cnt; /* Number of packets can send at a time */ 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ci struct sk_buff *resp_skb; /* Response from the chip */ 2118c2ecf20Sopenharmony_ci /* Main task completion handler */ 2128c2ecf20Sopenharmony_ci struct completion maintask_comp; 2138c2ecf20Sopenharmony_ci /* Opcode of last command sent to the chip */ 2148c2ecf20Sopenharmony_ci u8 pre_op; 2158c2ecf20Sopenharmony_ci /* Handler used for wakeup when response packet is received */ 2168c2ecf20Sopenharmony_ci struct completion *resp_comp; 2178c2ecf20Sopenharmony_ci struct fm_irq irq_info; 2188c2ecf20Sopenharmony_ci u8 curr_fmmode; /* Current FM chip mode (TX, RX, OFF) */ 2198c2ecf20Sopenharmony_ci struct fm_rx rx; /* FM receiver info */ 2208c2ecf20Sopenharmony_ci struct fmtx_data tx_data; 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_ci /* V4L2 ctrl framework handler*/ 2238c2ecf20Sopenharmony_ci struct v4l2_ctrl_handler ctrl_handler; 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci /* For core assisted locking */ 2268c2ecf20Sopenharmony_ci struct mutex mutex; 2278c2ecf20Sopenharmony_ci}; 2288c2ecf20Sopenharmony_ci#endif 229