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