2010-11-16 12:56:52

by halli manjunatha

[permalink] [raw]
Subject: [PATCH v4 0/6] FM V4L2 drivers for WL128x

From: Manjunatha Halli <[email protected]>

Mauro, Hans and the list,

This is the v4 version of the TI WL128x FM V4L2 drivers patchset.
Texas Instrument's WL128x chipset packs BT, FM, GPS and WLAN in a single
die with BT, FM and GPS being interfaced over a single UART.
This driver works on top of the shared transport line discipline driver.
This driver can also be made use for the WL127x version of the chip which packs
BT, FM and WLAN only.

Comments on the last version of the patches have been taken care,
such as
- New private CID for Channel Spacing added.
- FM Seek Wrap around support is also added.
- Few other style issues also taken care of.

Also,
Can you please also stage this version? Since the files are becoming big
to be posted as patches?
Currently there are few modifications which are supposed to go into videodev2.h
which have been added to generic header file to make it self-contained.

Thanks & Regards,
Manjunatha.

Manjunatha Halli (6):
drivers:staging: ti-st: fmdrv common header file
drivers:staging: ti-st: fmdrv_v4l2 sources
drivers:staging: ti-st: fmdrv_common sources
drivers:staging: ti-st: fmdrv_rx sources
drivers:staging: ti-st: fmdrv_tx sources
drivers:staging: ti-st: Kconfig & Makefile change

drivers/staging/ti-st/Kconfig | 10 +
drivers/staging/ti-st/Makefile | 2 +
drivers/staging/ti-st/fmdrv.h | 259 ++++
drivers/staging/ti-st/fmdrv_common.c | 2141 ++++++++++++++++++++++++++++++++++
drivers/staging/ti-st/fmdrv_common.h | 458 ++++++++
drivers/staging/ti-st/fmdrv_rx.c | 979 ++++++++++++++++
drivers/staging/ti-st/fmdrv_rx.h | 59 +
drivers/staging/ti-st/fmdrv_tx.c | 461 ++++++++
drivers/staging/ti-st/fmdrv_tx.h | 37 +
drivers/staging/ti-st/fmdrv_v4l2.c | 757 ++++++++++++
drivers/staging/ti-st/fmdrv_v4l2.h | 32 +
11 files changed, 5195 insertions(+), 0 deletions(-)
create mode 100644 drivers/staging/ti-st/fmdrv.h
create mode 100644 drivers/staging/ti-st/fmdrv_common.c
create mode 100644 drivers/staging/ti-st/fmdrv_common.h
create mode 100644 drivers/staging/ti-st/fmdrv_rx.c
create mode 100644 drivers/staging/ti-st/fmdrv_rx.h
create mode 100644 drivers/staging/ti-st/fmdrv_tx.c
create mode 100644 drivers/staging/ti-st/fmdrv_tx.h
create mode 100644 drivers/staging/ti-st/fmdrv_v4l2.c
create mode 100644 drivers/staging/ti-st/fmdrv_v4l2.h


2010-11-16 12:57:02

by halli manjunatha

[permalink] [raw]
Subject: [PATCH v4 3/6] drivers:staging: ti-st: fmdrv_common sources

From: Manjunatha Halli <[email protected]>

These are the sources for the common interfaces required by the FM
V4L2 driver for TI WL127x and WL128x chips.

These implement the FM channel-8 protocol communication with
the chip. This makes use of the Shared Transport as its transport.

Signed-off-by: Manjunatha Halli <[email protected]>
---
drivers/staging/ti-st/fmdrv_common.c | 2141 ++++++++++++++++++++++++++++++++++
drivers/staging/ti-st/fmdrv_common.h | 458 ++++++++
2 files changed, 2599 insertions(+), 0 deletions(-)
create mode 100644 drivers/staging/ti-st/fmdrv_common.c
create mode 100644 drivers/staging/ti-st/fmdrv_common.h

diff --git a/drivers/staging/ti-st/fmdrv_common.c b/drivers/staging/ti-st/fmdrv_common.c
new file mode 100644
index 0000000..7b8f2da
--- /dev/null
+++ b/drivers/staging/ti-st/fmdrv_common.c
@@ -0,0 +1,2141 @@
+/*
+ * FM Driver for Connectivity chip of Texas Instruments.
+ *
+ * This sub-module of FM driver is common for FM RX and TX
+ * functionality. This module is responsible for:
+ * 1) Forming group of Channel-8 commands to perform particular
+ * functionality (eg., frequency set require more than
+ * one Channel-8 command to be sent to the chip).
+ * 2) Sending each Channel-8 command to the chip and reading
+ * response back over Shared Transport.
+ * 3) Managing TX and RX Queues and Tasklets.
+ * 4) Handling FM Interrupt packet and taking appropriate action.
+ * 5) Loading FM firmware to the chip (common, FM TX, and FM RX
+ * firmware files based on mode selection)
+ *
+ * Copyright (C) 2010 Texas Instruments
+ * Author: Raja Mani <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/firmware.h>
+#include <linux/delay.h>
+#include "fmdrv.h"
+#include "fmdrv_v4l2.h"
+#include "fmdrv_common.h"
+#include <linux/ti_wilink_st.h>
+#include "fmdrv_rx.h"
+#include "fmdrv_tx.h"
+
+/* FM chip register table */
+static struct fm_reg_table fm_reg_info[] = {
+ /* ----- FM RX registers -------*/
+ /* opcode, type(rd/wr), reg name */
+ {0x00, REG_RD, "STEREO_GET"},
+ {0x01, REG_RD, "RSSI_LVL_GET"},
+ {0x02, REG_RD, "IF_COUNT_GET"},
+ {0x03, REG_RD, "FLAG_GET"},
+ {0x04, REG_RD, "RDS_SYNC_GET"},
+ {0x05, REG_RD, "RDS_DATA_GET"},
+ {0x0a, REG_WR, "FREQ_SET"},
+ {0x0a, REG_RD, "FREQ_GET"},
+ {0x0b, REG_WR, "AF_FREQ_SET"},
+ {0x0b, REG_RD, "AF_FREQ_GET"},
+ {0x0c, REG_WR, "MOST_MODE_SET"},
+ {0x0c, REG_RD, "MOST_MODE_GET"},
+ {0x0d, REG_WR, "MOST_BLEND_SET"},
+ {0x0d, REG_RD, "MOST_BLEND_GET"},
+ {0x0e, REG_WR, "DEMPH_MODE_SET"},
+ {0x0e, REG_RD, "DEMPH_MODE_GET"},
+ {0x0f, REG_WR, "SEARCH_LVL_SET"},
+ {0x0f, REG_RD, "SEARCH_LVL_GET"},
+ {0x10, REG_WR, "RX_BAND_SET"},
+ {0x10, REG_RD, "RX_BAND_GET"},
+ {0x11, REG_WR, "MUTE_STATUS_SET"},
+ {0x11, REG_RD, "MUTE_STATUS_GET"},
+ {0x12, REG_WR, "RDS_PAUSE_LVL_SET"},
+ {0x12, REG_RD, "RDS_PAUSE_LVL_GET"},
+ {0x13, REG_WR, "RDS_PAUSE_DUR_SET"},
+ {0x13, REG_RD, "RDS_PAUSE_DUR_GET"},
+ {0x14, REG_WR, "RDS_MEM_SET"},
+ {0x14, REG_RD, "RDS_MEM_GET"},
+ {0x15, REG_WR, "RDS_BLK_B_SET"},
+ {0x15, REG_RD, "RDS_BLK_B_GET"},
+ {0x16, REG_WR, "RDS_MSK_B_SET"},
+ {0x16, REG_RD, "RDS_MSK_B_GET"},
+ {0x17, REG_WR, "RDS_PI_MASK_SET"},
+ {0x17, REG_RD, "RDS_PI_MASK_GET"},
+ {0x18, REG_WR, "RDS_PI_SET"},
+ {0x18, REG_RD, "RDS_PI_GET"},
+ {0x19, REG_WR, "RDS_SYSTEM_SET"},
+ {0x19, REG_RD, "RDS_SYSTEM_GET"},
+ {0x1a, REG_WR, "INT_MASK_SET"},
+ {0x1a, REG_RD, "INT_MASK_GET"},
+ {0x1b, REG_WR, "SRCH_DIR_SET"},
+ {0x1b, REG_RD, "SRCH_DIR_GET"},
+ {0x1c, REG_WR, "VOLUME_SET"},
+ {0x1c, REG_RD, "VOLUME_GET"},
+ {0x1d, REG_WR, "AUDIO_ENABLE(SET)"},
+ {0x1d, REG_RD, "AUDIO_ENABLE(GET)"},
+ {0x1e, REG_WR, "PCM_MODE_SET"},
+ {0x1e, REG_RD, "PCM_MODE_SET"},
+ {0x1f, REG_WR, "I2S_MD_CFG_SET"},
+ {0x1f, REG_RD, "I2S_MD_CFG_GET"},
+ {0x20, REG_WR, "POWER_SET"},
+ {0x20, REG_RD, "POWER_GET"},
+ {0x21, REG_WR, "INTx_CONFIG_SET"},
+ {0x21, REG_RD, "INTx_CONFIG_GET"},
+ {0x22, REG_WR, "PULL_EN_SET"},
+ {0x22, REG_RD, "PULL_EN_GET"},
+ {0x23, REG_WR, "HILO_SET"},
+ {0x23, REG_RD, "HILO_GET"},
+ {0x24, REG_WR, "SWITCH2FREF"},
+ {0x25, REG_WR, "FREQ_DRIFT_REP"},
+ {0x28, REG_RD, "PCE_GET"},
+ {0x29, REG_RD, "FIRM_VER_GET"},
+ {0x2a, REG_RD, "ASIC_VER_GET"},
+ {0x2b, REG_RD, "ASIC_ID_GET"},
+ {0x2c, REG_RD, "MAIN_ID_GET"},
+ {0x2d, REG_WR, "TUNER_MODE_SET"},
+ {0x2e, REG_WR, "STOP_SEARCH"},
+ {0x2f, REG_WR, "RDS_CNTRL_SET"},
+ {0x64, REG_WR, "WR_HW_REG"},
+ {0x65, REG_WR, "CODE_DOWNLOAD"},
+ {0x66, REG_WR, "RESET"},
+ {0xfe, REG_WR, "FM_POWER_MODE(SET)"},
+ {0xff, REG_RD, "FM_INTERRUPT"},
+
+ /* --- FM TX registers ------ */
+ {0x37, REG_WR, "CHANL_SET"},
+ {0x37, REG_RD, "CHANL_GET"},
+ {0x38, REG_WR, "CHANL_BW_SET"},
+ {0x38, REG_RD, "CHANL_BW_GET"},
+ {0x87, REG_WR, "REF_SET"},
+ {0x87, REG_RD, "REF_GET"},
+ {0x5a, REG_WR, "POWER_ENB_SET"},
+ {0x3a, REG_WR, "POWER_ATT_SET"},
+ {0x3a, REG_RD, "POWER_ATT_GET"},
+ {0x3b, REG_WR, "POWER_LEL_SET"},
+ {0x3b, REG_RD, "POWER_LEL_GET"},
+ {0x3c, REG_WR, "AUDIO_DEV_SET"},
+ {0x3c, REG_RD, "AUDIO_DEV_GET"},
+ {0x3d, REG_WR, "PILOT_DEV_SET"},
+ {0x3d, REG_RD, "PILOT_DEV_GET"},
+ {0x3e, REG_WR, "RDS_DEV_SET"},
+ {0x3e, REG_RD, "RDS_DEV_GET"},
+ {0x5b, REG_WR, "PUPD_SET"},
+ {0x3f, REG_WR, "AUDIO_IO_SET"},
+ {0x40, REG_WR, "PREMPH_SET"},
+ {0x40, REG_RD, "PREMPH_GET"},
+ {0x41, REG_WR, "TX_BAND_SET"},
+ {0x41, REG_RD, "TX_BAND_GET"},
+ {0x42, REG_WR, "MONO_SET"},
+ {0x42, REG_RD, "MONO_GET"},
+ {0x5C, REG_WR, "MUTE"},
+ {0x43, REG_WR, "MPX_LMT_ENABLE"},
+ {0x06, REG_RD, "LOCK_GET"},
+ {0x5d, REG_WR, "REF_ERR_SET"},
+ {0x44, REG_WR, "PI_SET"},
+ {0x44, REG_RD, "PI_GET"},
+ {0x45, REG_WR, "TYPE_SET"},
+ {0x45, REG_RD, "TYPE_GET"},
+ {0x46, REG_WR, "PTY_SET"},
+ {0x46, REG_RD, "PTY_GET"},
+ {0x47, REG_WR, "AF_SET"},
+ {0x47, REG_RD, "AF_GET"},
+ {0x48, REG_WR, "DISPLAY_SIZE_SET"},
+ {0x48, REG_RD, "DISPLAY_SIZE_GET"},
+ {0x49, REG_WR, "RDS_MODE_SET"},
+ {0x49, REG_RD, "RDS_MODE_GET"},
+ {0x4a, REG_WR, "DISPLAY_MODE_SET"},
+ {0x4a, REG_RD, "DISPLAY_MODE_GET"},
+ {0x62, REG_WR, "LENGTH_SET"},
+ {0x4b, REG_RD, "LENGTH_GET"},
+ {0x4c, REG_WR, "TOGGLE_AB_SET"},
+ {0x4c, REG_RD, "TOGGLE_AB_GET"},
+ {0x4d, REG_WR, "RDS_REP_SET"},
+ {0x4d, REG_RD, "RDS_REP_GET"},
+ {0x63, REG_WR, "RDS_DATA_SET"},
+ {0x5e, REG_WR, "RDS_DATA_ENB"},
+ {0x4e, REG_WR, "TA_SET"},
+ {0x4e, REG_RD, "TA_GET"},
+ {0x4f, REG_WR, "TP_SET"},
+ {0x4f, REG_RD, "TP_GET"},
+ {0x50, REG_WR, "DI_SET"},
+ {0x50, REG_RD, "DI_GET"},
+ {0x51, REG_WR, "MS_SET"},
+ {0x51, REG_RD, "MS_GET"},
+ {0x52, REG_WR, "PS_SCROLL_SPEED_SET"},
+ {0x52, REG_RD, "PS_SCROLL_SPEED_GET"},
+ {0x57, REG_WR, "ANT_IMP_SET"},
+ {0x57, REG_RD, "ANT_IMP_GET"},
+};
+
+/* Region info */
+static struct region_info region_configs[] = {
+ /* Europe/US */
+ {
+ .channel_spacing = FM_CHANNEL_SPACING_50KHZ * FM_FREQ_MUL,
+ .bottom_frequency = 87500, /* 87.5 MHz */
+ .top_frequency = 108000, /* 108 MHz */
+ .region_index = 0,
+ },
+ /* Japan */
+ {
+ .channel_spacing = FM_CHANNEL_SPACING_50KHZ * FM_FREQ_MUL,
+ .bottom_frequency = 76000, /* 76 MHz */
+ .top_frequency = 90000, /* 90 MHz */
+ .region_index = 1,
+ },
+};
+
+/* Band selection */
+static unsigned char default_radio_region; /* Europe/US */
+module_param(default_radio_region, byte, 0);
+MODULE_PARM_DESC(default_radio_region, "Region: 0=Europe/US, 1=Japan");
+
+/* RDS buffer blocks */
+static unsigned int default_rds_buf = 300;
+module_param(default_rds_buf, uint, 0444);
+MODULE_PARM_DESC(rds_buf, "RDS buffer entries");
+
+/* Radio Nr */
+static int radio_nr = -1;
+module_param(radio_nr, int, 0444);
+MODULE_PARM_DESC(radio_nr, "Radio Nr");
+
+/* FM irq handlers forward declaration */
+static void fm_irq_send_flag_getcmd(void *);
+static void fm_irq_handle_flag_getcmd_resp(void *);
+static void fm_irq_handle_hw_malfunction(void *);
+static void fm_irq_handle_rds_start(void *);
+static void fm_irq_send_rdsdata_getcmd(void *);
+static void fm_irq_handle_rdsdata_getcmd_resp(void *);
+static void fm_irq_handle_rds_finish(void *);
+static void fm_irq_handle_tune_op_ended(void *);
+static void fm_irq_handle_power_enb(void *);
+static void fm_irq_handle_low_rssi_start(void *);
+static void fm_irq_afjump_set_pi(void *);
+static void fm_irq_handle_set_pi_resp(void *);
+static void fm_irq_afjump_set_pimask(void *);
+static void fm_irq_handle_set_pimask_resp(void *);
+static void fm_irq_afjump_setfreq(void *);
+static void fm_irq_handle_setfreq_resp(void *);
+static void fm_irq_afjump_enableint(void *);
+static void fm_irq_afjump_enableint_resp(void *);
+static void fm_irq_start_afjump(void *);
+static void fm_irq_handle_start_afjump_resp(void *);
+static void fm_irq_afjump_rd_freq(void *);
+static void fm_irq_afjump_rd_freq_resp(void *);
+static void fm_irq_handle_low_rssi_finish(void *);
+static void fm_irq_send_intmsk_cmd(void *);
+static void fm_irq_handle_intmsk_cmd_resp(void *);
+
+/*
+ * When FM common module receives interrupt packet, following handlers
+ * will be executed one after another to service the interrupt(s)
+ */
+enum fmc_irq_handler_index {
+ FM_SEND_FLAG_GETCMD_INDEX,
+ FM_HANDLE_FLAG_GETCMD_RESP_INDEX,
+
+ /* HW malfunction irq handler */
+ FM_HW_MAL_FUNC_INDEX,
+
+ /* RDS threshold reached irq handler */
+ FM_RDS_START_INDEX,
+ FM_RDS_SEND_RDS_GETCMD_INDEX,
+ FM_RDS_HANDLE_RDS_GETCMD_RESP_INDEX,
+ FM_RDS_FINISH_INDEX,
+
+ /* Tune operation ended irq handler */
+ FM_HW_TUNE_OP_ENDED_INDEX,
+
+ /* TX power enable irq handler */
+ FM_HW_POWER_ENB_INDEX,
+
+ /* Low RSSI irq handler */
+ FM_LOW_RSSI_START_INDEX,
+ FM_AF_JUMP_SETPI_INDEX,
+ FM_AF_JUMP_HANDLE_SETPI_RESP_INDEX,
+ FM_AF_JUMP_SETPI_MASK_INDEX,
+ FM_AF_JUMP_HANDLE_SETPI_MASK_RESP_INDEX,
+ FM_AF_JUMP_SET_AF_FREQ_INDEX,
+ FM_AF_JUMP_HENDLE_SET_AFFREQ_RESP_INDEX,
+ FM_AF_JUMP_ENABLE_INT_INDEX,
+ FM_AF_JUMP_ENABLE_INT_RESP_INDEX,
+ FM_AF_JUMP_START_AFJUMP_INDEX,
+ FM_AF_JUMP_HANDLE_START_AFJUMP_RESP_INDEX,
+ FM_AF_JUMP_RD_FREQ_INDEX,
+ FM_AF_JUMP_RD_FREQ_RESP_INDEX,
+ FM_LOW_RSSI_FINISH_INDEX,
+
+ /* Interrupt process post action */
+ FM_SEND_INTMSK_CMD_INDEX,
+ FM_HANDLE_INTMSK_CMD_RESP_INDEX,
+};
+
+/* FM interrupt handler table */
+static int_handler_prototype g_IntHandlerTable[] = {
+ fm_irq_send_flag_getcmd,
+ fm_irq_handle_flag_getcmd_resp,
+ fm_irq_handle_hw_malfunction,
+ fm_irq_handle_rds_start, /* RDS threshold reached irq handler */
+ fm_irq_send_rdsdata_getcmd,
+ fm_irq_handle_rdsdata_getcmd_resp,
+ fm_irq_handle_rds_finish,
+ fm_irq_handle_tune_op_ended,
+ fm_irq_handle_power_enb, /* TX power enable irq handler */
+ fm_irq_handle_low_rssi_start,
+ fm_irq_afjump_set_pi,
+ fm_irq_handle_set_pi_resp,
+ fm_irq_afjump_set_pimask,
+ fm_irq_handle_set_pimask_resp,
+ fm_irq_afjump_setfreq,
+ fm_irq_handle_setfreq_resp,
+ fm_irq_afjump_enableint,
+ fm_irq_afjump_enableint_resp,
+ fm_irq_start_afjump,
+ fm_irq_handle_start_afjump_resp,
+ fm_irq_afjump_rd_freq,
+ fm_irq_afjump_rd_freq_resp,
+ fm_irq_handle_low_rssi_finish,
+ fm_irq_send_intmsk_cmd, /* Interrupt process post action */
+ fm_irq_handle_intmsk_cmd_resp
+};
+
+long (*g_st_write) (struct sk_buff *skb);
+static struct completion wait_for_fmdrv_reg_comp;
+
+#ifdef FM_DUMP_TXRX_PKT
+ /* To dump outgoing FM Channel-8 packets */
+inline void dump_tx_skb_data(struct sk_buff *skb)
+{
+ int len, len_org;
+ char index;
+ struct fm_cmd_msg_hdr *cmd_hdr;
+
+ cmd_hdr = (struct fm_cmd_msg_hdr *)skb->data;
+ printk(KERN_INFO "<<%shdr:%02x len:%02x opcode:%02x type:%s dlen:%02x",
+ fm_cb(skb)->completion ? " " : "*", cmd_hdr->header,
+ cmd_hdr->len, cmd_hdr->fm_opcode,
+ cmd_hdr->rd_wr ? "RD" : "WR", cmd_hdr->dlen);
+
+ len_org = skb->len - FM_CMD_MSG_HDR_SIZE;
+ if (len_org > 0) {
+ printk("\n data(%d): ", cmd_hdr->dlen);
+ len = min(len_org, 14);
+ for (index = 0; index < len; index++)
+ printk("%x ",
+ skb->data[FM_CMD_MSG_HDR_SIZE + index]);
+ printk("%s", (len_org > 14) ? ".." : "");
+ }
+ printk("\n");
+}
+
+ /* To dump incoming FM Channel-8 packets */
+inline void dump_rx_skb_data(struct sk_buff *skb)
+{
+ int len, len_org;
+ char index;
+ struct fm_event_msg_hdr *evt_hdr;
+
+ evt_hdr = (struct fm_event_msg_hdr *)skb->data;
+ printk(KERN_INFO ">> hdr:%02x len:%02x sts:%02x numhci:%02x "
+ "opcode:%02x type:%s dlen:%02x", evt_hdr->header, evt_hdr->len,
+ evt_hdr->status, evt_hdr->num_fm_hci_cmds, evt_hdr->fm_opcode,
+ (evt_hdr->rd_wr) ? "RD" : "WR", evt_hdr->dlen);
+
+ len_org = skb->len - FM_EVT_MSG_HDR_SIZE;
+ if (len_org > 0) {
+ printk("\n data(%d): ", evt_hdr->dlen);
+ len = min(len_org, 14);
+ for (index = 0; index < len; index++)
+ printk("%x ",
+ skb->data[FM_EVT_MSG_HDR_SIZE + index]);
+ printk("%s", (len_org > 14) ? ".." : "");
+ }
+ printk("\n");
+}
+#endif
+
+void fmc_update_region_info(struct fmdrv_ops *fmdev,
+ unsigned char region_to_set)
+{
+ memcpy(&fmdev->rx.region, &region_configs[region_to_set],
+ sizeof(struct region_info));
+}
+
+/*
+ * FM common sub-module will schedule this tasklet whenever it receives
+ * FM packet from ST driver.
+ */
+static void __recv_tasklet(unsigned long arg)
+{
+ struct fmdrv_ops *fmdev;
+ struct fm_event_msg_hdr *fm_evt_hdr;
+ struct sk_buff *skb;
+ unsigned char num_fm_hci_cmds;
+ unsigned long flags;
+
+ fmdev = (struct fmdrv_ops *)arg;
+ /* Process all packets in the RX queue */
+ while ((skb = skb_dequeue(&fmdev->rx_q))) {
+ if (skb->len < sizeof(struct fm_event_msg_hdr)) {
+ pr_err("(fmdrv): skb(%p) has only %d bytes"
+ "atleast need %d bytes to decode\n",
+ skb, skb->len,
+ sizeof(struct fm_event_msg_hdr));
+ kfree_skb(skb);
+ continue;
+ }
+
+ fm_evt_hdr = (void *)skb->data;
+ num_fm_hci_cmds = fm_evt_hdr->num_fm_hci_cmds;
+
+ /* FM interrupt packet? */
+ if (fm_evt_hdr->fm_opcode == fm_reg_info[FM_INTERRUPT].opcode) {
+ /* FM interrupt handler started already? */
+ if (!test_bit(FM_INTTASK_RUNNING, &fmdev->flag)) {
+ set_bit(FM_INTTASK_RUNNING, &fmdev->flag);
+ if (fmdev->irq_info.stage_index != 0) {
+ pr_err("(fmdrv): Invalid stage index,"
+ "resetting to zero\n");
+ fmdev->irq_info.stage_index = 0;
+ }
+
+ /*
+ * Execute first function in interrupt handler
+ * table.
+ */
+ fmdev->irq_info.fm_int_handlers
+ [fmdev->irq_info.stage_index](fmdev);
+ } else {
+ set_bit(FM_INTTASK_SCHEDULE_PENDING,
+ &fmdev->flag);
+ }
+ kfree_skb(skb);
+ }
+ /* Anyone waiting for this with completion handler? */
+ else if (fm_evt_hdr->fm_opcode == fmdev->last_sent_pkt_opcode &&
+ fmdev->response_completion != NULL) {
+ if (fmdev->response_skb != NULL)
+ pr_err("(fmdrv): Response SKB ptr not NULL\n");
+
+ spin_lock_irqsave(&fmdev->resp_skb_lock, flags);
+ fmdev->response_skb = skb;
+ spin_unlock_irqrestore(&fmdev->resp_skb_lock, flags);
+ complete(fmdev->response_completion);
+
+ fmdev->response_completion = NULL;
+ atomic_set(&fmdev->tx_cnt, 1);
+ }
+ /* Is this for interrupt handler? */
+ else if (fm_evt_hdr->fm_opcode == fmdev->last_sent_pkt_opcode &&
+ fmdev->response_completion == NULL) {
+ if (fmdev->response_skb != NULL)
+ pr_err("(fmdrv): Response SKB ptr not NULL\n");
+
+ spin_lock_irqsave(&fmdev->resp_skb_lock, flags);
+ fmdev->response_skb = skb;
+ spin_unlock_irqrestore(&fmdev->resp_skb_lock, flags);
+
+ /* Execute interrupt handler where state index points */
+ fmdev->irq_info.fm_int_handlers
+ [fmdev->irq_info.stage_index](fmdev);
+
+ kfree_skb(skb);
+ atomic_set(&fmdev->tx_cnt, 1);
+ } else {
+ pr_err("(fmdrv): Nobody claimed SKB(%p),purging\n",
+ skb);
+ }
+
+ /*
+ * Check flow control field. If Num_FM_HCI_Commands field is
+ * not zero, schedule FM TX tasklet.
+ */
+ if (num_fm_hci_cmds && atomic_read(&fmdev->tx_cnt)) {
+ if (!skb_queue_empty(&fmdev->tx_q))
+ tasklet_schedule(&fmdev->tx_task);
+ }
+ }
+}
+
+/* FM send tasklet: is scheduled when FM packet has to be sent to chip */
+static void __send_tasklet(unsigned long arg)
+{
+ struct fmdrv_ops *fmdev;
+ struct sk_buff *skb;
+ int len;
+
+ fmdev = (struct fmdrv_ops *)arg;
+ /* Check, is there any timeout happenned to last transmitted packet */
+ if (!atomic_read(&fmdev->tx_cnt) &&
+ ((jiffies - fmdev->last_tx_jiffies) > FM_DRV_TX_TIMEOUT)) {
+ pr_err("(fmdrv): TX timeout occurred\n");
+ atomic_set(&fmdev->tx_cnt, 1);
+ }
+ /* Send queued FM TX packets */
+ if (atomic_read(&fmdev->tx_cnt)) {
+ skb = skb_dequeue(&fmdev->tx_q);
+ if (skb) {
+ atomic_dec(&fmdev->tx_cnt);
+ fmdev->last_sent_pkt_opcode = fm_cb(skb)->fm_opcode;
+
+ if (fmdev->response_completion != NULL)
+ pr_err("(fmdrv): Response completion handler"
+ "is not NULL\n");
+
+ fmdev->response_completion = fm_cb(skb)->completion;
+
+ /* Write FM packet to ST driver */
+ len = g_st_write(skb);
+ if (len < 0) {
+ kfree_skb(skb);
+ fmdev->response_completion = NULL;
+ pr_err("(fmdrv): TX tasklet failed to send"
+ "skb(%p)\n", skb);
+ atomic_set(&fmdev->tx_cnt, 1);
+ } else {
+ fmdev->last_tx_jiffies = jiffies;
+ }
+ }
+ }
+}
+
+/*
+ * Queues FM Channel-8 packet to FM TX queue and schedules FM TX tasklet for
+ * transmission
+ */
+static int __fm_send_cmd(struct fmdrv_ops *fmdev, unsigned char fmreg_index,
+ void *payload, int payload_len,
+ struct completion *wait_completion)
+{
+ struct sk_buff *skb;
+ struct fm_cmd_msg_hdr *cmd_hdr;
+ int size;
+
+
+ if (fmreg_index >= FM_REG_MAX_ENTRIES) {
+ pr_err("(fmdrv): Invalid fm register index\n");
+ return -EINVAL;
+ }
+ if (test_bit(FM_FIRMWARE_DW_INPROGRESS, &fmdev->flag) &&
+ payload == NULL) {
+ pr_err("(fmdrv): Payload data is NULL during fw download\n");
+ return -EINVAL;
+ }
+ if (!test_bit(FM_FIRMWARE_DW_INPROGRESS, &fmdev->flag))
+ size =
+ FM_CMD_MSG_HDR_SIZE + ((payload == NULL) ? 0 : payload_len);
+ else
+ size = payload_len;
+
+ skb = alloc_skb(size, GFP_ATOMIC);
+ if (!skb) {
+ pr_err("(fmdrv): No memory to create new SKB\n");
+ return -ENOMEM;
+ }
+ /*
+ * Don't fill FM header info for the commands which come from
+ * FM firmware file.
+ */
+ if (!test_bit(FM_FIRMWARE_DW_INPROGRESS, &fmdev->flag) ||
+ test_bit(FM_INTTASK_RUNNING, &fmdev->flag)) {
+ /* Fill command header info */
+ cmd_hdr =
+ (struct fm_cmd_msg_hdr *)skb_put(skb, FM_CMD_MSG_HDR_SIZE);
+ cmd_hdr->header = FM_PKT_LOGICAL_CHAN_NUMBER; /* 0x08 */
+ /* 3 (fm_opcode,rd_wr,dlen) + payload len) */
+ cmd_hdr->len = ((payload == NULL) ? 0 : payload_len) + 3;
+ /* FM opcode */
+ cmd_hdr->fm_opcode = fm_reg_info[fmreg_index].opcode;
+ /* read/write type */
+ cmd_hdr->rd_wr = fm_reg_info[fmreg_index].type;
+ cmd_hdr->dlen = payload_len;
+ fm_cb(skb)->fm_opcode = fm_reg_info[fmreg_index].opcode;
+ } else if (payload != NULL) {
+ fm_cb(skb)->fm_opcode = *((char *)payload + 2);
+ }
+ if (payload != NULL)
+ memcpy(skb_put(skb, payload_len), payload, payload_len);
+
+ fm_cb(skb)->completion = wait_completion;
+ skb_queue_tail(&fmdev->tx_q, skb);
+ tasklet_schedule(&fmdev->tx_task);
+
+ return 0;
+}
+
+/* Sends FM Channel-8 command to the chip and waits for the reponse */
+int fmc_send_cmd(struct fmdrv_ops *fmdev, unsigned char fmreg_index,
+ void *payload, int payload_len,
+ struct completion *wait_completion, void *reponse,
+ int *reponse_len)
+{
+ struct sk_buff *skb;
+ struct fm_event_msg_hdr *fm_evt_hdr;
+ unsigned long timeleft;
+ unsigned long flags;
+ int ret;
+
+ init_completion(wait_completion);
+ ret = __fm_send_cmd(fmdev, fmreg_index, payload, payload_len,
+ wait_completion);
+ if (ret < 0)
+ return ret;
+
+ timeleft = wait_for_completion_timeout(wait_completion,
+ FM_DRV_TX_TIMEOUT);
+ if (!timeleft) {
+ pr_err("(fmdrv): Timeout(%d sec),didn't get reg"
+ "completion signal from RX tasklet\n",
+ jiffies_to_msecs(FM_DRV_TX_TIMEOUT) / 1000);
+ return -ETIMEDOUT;
+ }
+ if (!fmdev->response_skb) {
+ pr_err("(fmdrv): Reponse SKB is missing\n");
+ return -EFAULT;
+ }
+ spin_lock_irqsave(&fmdev->resp_skb_lock, flags);
+ skb = fmdev->response_skb;
+ fmdev->response_skb = NULL;
+ spin_unlock_irqrestore(&fmdev->resp_skb_lock, flags);
+
+ fm_evt_hdr = (void *)skb->data;
+ if (fm_evt_hdr->status != 0) {
+ pr_err("(fmdrv): Received event pkt status(%d) is not zero\n",
+ fm_evt_hdr->status);
+ kfree_skb(skb);
+ return -EIO;
+ }
+ /* Send reponse data to caller */
+ if (reponse != NULL && reponse_len != NULL && fm_evt_hdr->dlen) {
+ /* Skip header info and copy only response data */
+ skb_pull(skb, sizeof(struct fm_event_msg_hdr));
+ memcpy(reponse, skb->data, fm_evt_hdr->dlen);
+ *reponse_len = fm_evt_hdr->dlen;
+ } else if (reponse_len != NULL && fm_evt_hdr->dlen == 0) {
+ *reponse_len = 0;
+ }
+ kfree_skb(skb);
+ return 0;
+}
+
+/* --- Helper functions used in FM interrupt handlers ---*/
+static inline int __check_cmdresp_status(struct fmdrv_ops *fmdev,
+ struct sk_buff **skb)
+{
+ struct fm_event_msg_hdr *fm_evt_hdr;
+ unsigned long flags;
+
+ spin_lock_irqsave(&fmdev->resp_skb_lock, flags);
+ *skb = fmdev->response_skb;
+ fmdev->response_skb = NULL;
+ spin_unlock_irqrestore(&fmdev->resp_skb_lock, flags);
+
+ fm_evt_hdr = (void *)(*skb)->data;
+ if (fm_evt_hdr->status != 0) {
+ pr_err("(fmdrv): irq: opcode %x response status is not zero\n",
+ fm_evt_hdr->fm_opcode);
+ return -1;
+ }
+
+ return 0;
+}
+
+/*
+ * Interrupt process timeout handler.
+ * One of the irq handler did not get proper response from the chip. So take
+ * recovery action here. FM interrupts are disabled in the beginning of
+ * interrupt process. Therefore reset stage index to re-enable default
+ * interrupts. So that next interrupt will be processed as usual.
+ */
+static void __int_timeout_handler(unsigned long data)
+{
+ struct fmdrv_ops *fmdev;
+
+ pr_debug("(fmdrv): irq: timeout,trying to re-enable fm interrupts\n");
+ fmdev = (struct fmdrv_ops *)data;
+ fmdev->irq_info.irq_service_timeout_retry++;
+
+ if (fmdev->irq_info.irq_service_timeout_retry <=
+ FM_IRQ_TIMEOUT_RETRY_MAX) {
+ fmdev->irq_info.stage_index = FM_SEND_INTMSK_CMD_INDEX;
+ fmdev->irq_info.fm_int_handlers[fmdev->irq_info.
+ stage_index] (fmdev);
+ } else {
+ /*
+ * Stop recovery action (interrupt reenable process) and
+ * reset stage index & retry count values
+ */
+ fmdev->irq_info.stage_index = 0;
+ fmdev->irq_info.irq_service_timeout_retry = 0;
+ pr_err("(fmdrv): Recovery action failed during"
+ "irq processing, max retry reached\n");
+ }
+}
+
+/* --------- FM interrupt handlers ------------*/
+static void fm_irq_send_flag_getcmd(void *arg)
+{
+ struct fmdrv_ops *fmdev;
+ unsigned short flag;
+ int ret;
+
+ fmdev = arg;
+ /* Send FLAG_GET command , to know the source of interrupt */
+ ret = __fm_send_cmd(fmdev, FLAG_GET, NULL, sizeof(flag), NULL);
+ if (ret)
+ pr_err("(fmdrv): irq: failed to send flag_get command,"
+ "initiating irq recovery process\n");
+ else
+ fmdev->irq_info.stage_index = FM_HANDLE_FLAG_GETCMD_RESP_INDEX;
+
+ mod_timer(&fmdev->irq_info.int_timeout_timer, jiffies +
+ FM_DRV_TX_TIMEOUT);
+}
+
+static void fm_irq_handle_flag_getcmd_resp(void *arg)
+{
+ struct fmdrv_ops *fmdev;
+ struct sk_buff *skb;
+ struct fm_event_msg_hdr *fm_evt_hdr;
+ char ret;
+
+ fmdev = arg;
+ del_timer(&fmdev->irq_info.int_timeout_timer);
+
+ ret = __check_cmdresp_status(fmdev, &skb);
+ if (ret < 0) {
+ pr_err("(fmdrv): Initiating irq recovery process\n");
+ mod_timer(&fmdev->irq_info.int_timeout_timer, jiffies +
+ FM_DRV_TX_TIMEOUT);
+ return;
+ }
+ fm_evt_hdr = (void *)skb->data;
+
+ /* Skip header info and copy only response data */
+ skb_pull(skb, sizeof(struct fm_event_msg_hdr));
+ memcpy(&fmdev->irq_info.flag, skb->data, fm_evt_hdr->dlen);
+
+ FM_STORE_BE16_TO_LE16(fmdev->irq_info.flag, fmdev->irq_info.flag);
+ pr_debug("(fmdrv): irq: flag register(0x%x)\n", fmdev->irq_info.flag);
+
+ /* Continue next function in interrupt handler table */
+ fmdev->irq_info.stage_index = FM_HW_MAL_FUNC_INDEX;
+
+ fmdev->irq_info.fm_int_handlers[fmdev->irq_info.stage_index](fmdev);
+}
+
+static void fm_irq_handle_hw_malfunction(void *arg)
+{
+ struct fmdrv_ops *fmdev;
+
+ fmdev = arg;
+ if (fmdev->irq_info.flag & FM_MAL_EVENT & fmdev->irq_info.mask)
+ pr_err("(fmdrv): irq: HW MAL int received - do nothing\n");
+
+ /* Continue next function in interrupt handler table */
+ fmdev->irq_info.stage_index = FM_RDS_START_INDEX;
+ fmdev->irq_info.fm_int_handlers[fmdev->irq_info.stage_index](fmdev);
+}
+
+static void fm_irq_handle_rds_start(void *arg)
+{
+ struct fmdrv_ops *fmdev;
+
+ fmdev = arg;
+ if (fmdev->irq_info.flag & FM_RDS_EVENT & fmdev->irq_info.mask) {
+ pr_debug("(fmdrv): irq: rds threshold reached\n");
+ fmdev->irq_info.stage_index = FM_RDS_SEND_RDS_GETCMD_INDEX;
+ } else {
+ /* Continue next function in interrupt handler table */
+ fmdev->irq_info.stage_index = FM_HW_TUNE_OP_ENDED_INDEX;
+ }
+ fmdev->irq_info.fm_int_handlers[fmdev->irq_info.stage_index](fmdev);
+}
+
+static void fm_irq_send_rdsdata_getcmd(void *arg)
+{
+ struct fmdrv_ops *fmdev;
+ int ret;
+
+ fmdev = arg;
+ /* Send the command to read RDS data from the chip */
+ ret = __fm_send_cmd(fmdev, RDS_DATA_GET, NULL,
+ (FM_RX_RDS_FIFO_THRESHOLD * 3), NULL);
+ if (ret < 0)
+ pr_err("(fmdrv): irq : failed to send rds get command,"
+ "initiating irq recovery process\n");
+ else
+ fmdev->irq_info.stage_index =
+ FM_RDS_HANDLE_RDS_GETCMD_RESP_INDEX;
+
+ /* Start timer to track timeout */
+ mod_timer(&fmdev->irq_info.int_timeout_timer, jiffies +
+ FM_DRV_TX_TIMEOUT);
+}
+
+/* Keeps track of current RX channel AF (Alternate Frequency) */
+static void __fm_rx_update_af_cache(struct fmdrv_ops *fmdev,
+ unsigned char af)
+{
+ unsigned char index;
+ unsigned int freq;
+
+ /* First AF indicates the number of AF follows. Reset the list */
+ if ((af >= FM_RDS_1_AF_FOLLOWS) && (af <= FM_RDS_25_AF_FOLLOWS)) {
+ fmdev->rx.cur_station_info.af_list_max =
+ (af - FM_RDS_1_AF_FOLLOWS + 1);
+ fmdev->rx.cur_station_info.no_of_items_in_afcache = 0;
+ pr_debug("(fmdrv): No of expected AF : %d\n",
+ fmdev->rx.cur_station_info.af_list_max);
+ } else if (((af >= FM_RDS_MIN_AF)
+ && (fmdev->rx.region.region_index == FM_BAND_EUROPE_US)
+ && (af <= FM_RDS_MAX_AF)) || ((af >= FM_RDS_MIN_AF)
+ && (fmdev->rx.region.
+ region_index ==
+ FM_BAND_JAPAN)
+ && (af <=
+ FM_RDS_MAX_AF_JAPAN))) {
+ freq = fmdev->rx.region.bottom_frequency + (af * 100);
+ if (freq == fmdev->rx.curr_freq) {
+ pr_debug("(fmdrv): Current frequency(%d) is"
+ "matching with received AF(%d)\n",
+ fmdev->rx.curr_freq, freq);
+ return;
+ }
+ /* Do check in AF cache */
+ for (index = 0;
+ index < fmdev->rx.cur_station_info.no_of_items_in_afcache;
+ index++) {
+ if (fmdev->rx.cur_station_info.af_cache[index] == freq)
+ break;
+ }
+ /* Reached the limit of the list - ignore the next AF */
+ if (index == fmdev->rx.cur_station_info.af_list_max) {
+ pr_debug("(fmdrv): AF cache is full\n");
+ return;
+ }
+ /*
+ * If we reached the end of the list then this AF is not
+ * in the list - add it.
+ */
+ if (index == fmdev->rx.cur_station_info.
+ no_of_items_in_afcache) {
+ pr_debug("(fmdrv): Storing AF %d to cache index %d\n",
+ freq, index);
+ fmdev->rx.cur_station_info.af_cache[index] = freq;
+ fmdev->rx.cur_station_info.no_of_items_in_afcache++;
+ }
+ }
+}
+
+/*
+ * Converts RDS buffer data from big endian format
+ * to little endian format.
+ */
+static void __fm_rdsparse_swapbytes(struct fmdrv_ops *fmdev,
+ struct fm_rdsdata_format *rds_format)
+{
+ unsigned char byte1;
+ unsigned char index = 0;
+ char *rds_buff;
+
+ /*
+ * Since in Orca the 2 RDS Data bytes are in little endian and
+ * in Dolphin they are in big endian, the parsing of the RDS data
+ * is chip dependent
+ */
+ if (fmdev->asci_id != 0x6350) {
+ rds_buff = &rds_format->rdsdata.groupdatabuff.rdsbuff[0];
+ while (index + 1 < FM_RX_RDS_INFO_FIELD_MAX) {
+ byte1 = rds_buff[index];
+ rds_buff[index] = rds_buff[index + 1];
+ rds_buff[index + 1] = byte1;
+ index += 2;
+ }
+ }
+}
+
+static void fm_irq_handle_rdsdata_getcmd_resp(void *arg)
+{
+ struct fmdrv_ops *fmdev;
+ struct sk_buff *skb;
+ char *rds_data;
+ char meta_data;
+ unsigned char type, block_index;
+ unsigned long group_index;
+ struct fm_rdsdata_format rds_format;
+ int rds_len, ret;
+ unsigned short cur_picode;
+ unsigned char tmpbuf[3];
+ unsigned long flags;
+
+ fmdev = arg;
+ del_timer(&fmdev->irq_info.int_timeout_timer);
+
+ ret = __check_cmdresp_status(fmdev, &skb);
+ if (ret < 0) {
+ pr_err("(fmdrv): Initiating irq recovery process\n");
+ mod_timer(&fmdev->irq_info.int_timeout_timer, jiffies +
+ FM_DRV_TX_TIMEOUT);
+ return;
+ }
+ /* Skip header info */
+ skb_pull(skb, sizeof(struct fm_event_msg_hdr));
+ rds_data = skb->data;
+ rds_len = skb->len;
+
+ /* Parse the RDS data */
+ while (rds_len >= FM_RDS_BLOCK_SIZE) {
+ meta_data = rds_data[2];
+ /*
+ * Get the type:
+ * 0=A, 1=B, 2=C, 3=C', 4=D, 5=E
+ */
+ type = (meta_data & 0x07);
+
+ /*
+ * Transform the block type into an
+ * index sequence (0, 1, 2, 3, 4)
+ */
+ block_index = (type <= FM_RDS_BLOCK_C ? type : (type - 1));
+ pr_debug("(fmdrv): Block index:%d(%s)\n", block_index,
+ (meta_data & FM_RDS_STATUS_ERROR_MASK) ? "Bad" :
+ "Ok");
+ if (((meta_data & FM_RDS_STATUS_ERROR_MASK) == 0)
+ && (block_index == FM_RDS_BLOCK_INDEX_A
+ || (block_index == fmdev->rx.rds.last_block_index + 1
+ && block_index <= FM_RDS_BLOCK_INDEX_D))) {
+ /*
+ * Skip checkword (control) byte and copy only data
+ * byte
+ */
+ memcpy(&rds_format.rdsdata.groupdatabuff.
+ rdsbuff[block_index * (FM_RDS_BLOCK_SIZE - 1)],
+ rds_data, (FM_RDS_BLOCK_SIZE - 1));
+ fmdev->rx.rds.last_block_index = block_index;
+
+ /* If completed a whole group then handle it */
+ if (block_index == FM_RDS_BLOCK_INDEX_D) {
+ pr_debug("(fmdrv): Good block received\n");
+ __fm_rdsparse_swapbytes(fmdev, &rds_format);
+
+ /*
+ * Extract PI code and store in local cache.
+ * We need this during AF switch processing.
+ */
+ cur_picode =
+ FM_BE16_TO_LE16(rds_format.rdsdata.
+ groupgeneral.pidata);
+ if (fmdev->rx.cur_station_info.picode !=
+ cur_picode)
+ fmdev->rx.cur_station_info.picode =
+ cur_picode;
+ pr_debug("(fmdrv): picode:%d\n", cur_picode);
+
+ group_index =
+ (rds_format.rdsdata.groupgeneral.
+ block_b_byte1 >> 3);
+ pr_debug("(fmdrv):Group:%ld%s\n", group_index/2,
+ (group_index % 2) ? "B" : "A");
+
+ group_index =
+ 1 << (rds_format.rdsdata.groupgeneral.
+ block_b_byte1 >> 3);
+ if (group_index == FM_RDS_GROUP_TYPE_MASK_0A) {
+ __fm_rx_update_af_cache
+ (fmdev, rds_format.rdsdata.
+ group0A.firstaf);
+ __fm_rx_update_af_cache
+ (fmdev, rds_format.
+ rdsdata.group0A.secondaf);
+ }
+ }
+ } else {
+ pr_debug("(fmdrv): Block sequence mismatch\n");
+ fmdev->rx.rds.last_block_index = -1;
+ }
+ rds_len -= FM_RDS_BLOCK_SIZE;
+ rds_data += FM_RDS_BLOCK_SIZE;
+ }
+
+ /* Copy raw rds data to internal rds buffer */
+ rds_data = skb->data;
+ rds_len = skb->len;
+
+ spin_lock_irqsave(&fmdev->rds_buff_lock, flags);
+ while (rds_len > 0) {
+ /*
+ * Fill RDS buffer as per V4L2 specification.
+ * Store control byte
+ */
+ type = (rds_data[2] & 0x07);
+ block_index = (type <= FM_RDS_BLOCK_C ? type : (type - 1));
+ tmpbuf[2] = block_index; /* Offset name */
+ tmpbuf[2] |= block_index << 3; /* Received offset */
+
+ /* Store data byte */
+ tmpbuf[0] = rds_data[0];
+ tmpbuf[1] = rds_data[1];
+
+ memcpy(&fmdev->rx.rds.buffer[fmdev->rx.rds.wr_index], &tmpbuf,
+ FM_RDS_BLOCK_SIZE);
+ fmdev->rx.rds.wr_index =
+ (fmdev->rx.rds.wr_index +
+ FM_RDS_BLOCK_SIZE) % fmdev->rx.rds.buf_size;
+
+ /* Check for overflow & start over */
+ if (fmdev->rx.rds.wr_index == fmdev->rx.rds.rd_index) {
+ pr_debug("(fmdrv): RDS buffer overflow\n");
+ fmdev->rx.rds.wr_index = 0;
+ fmdev->rx.rds.rd_index = 0;
+ break;
+ }
+ rds_len -= FM_RDS_BLOCK_SIZE;
+ rds_data += FM_RDS_BLOCK_SIZE;
+ }
+ spin_unlock_irqrestore(&fmdev->rds_buff_lock, flags);
+
+ /* Wakeup read queue */
+ if (fmdev->rx.rds.wr_index != fmdev->rx.rds.rd_index)
+ wake_up_interruptible(&fmdev->rx.rds.read_queue);
+
+ fmdev->irq_info.stage_index = FM_RDS_FINISH_INDEX;
+ fmdev->irq_info.fm_int_handlers[fmdev->irq_info.stage_index](fmdev);
+}
+
+static void fm_irq_handle_rds_finish(void *arg)
+{
+ struct fmdrv_ops *fmdev;
+
+ fmdev = arg;
+ /* Continue next function in interrupt handler table */
+ fmdev->irq_info.stage_index = FM_HW_TUNE_OP_ENDED_INDEX;
+ fmdev->irq_info.fm_int_handlers[fmdev->irq_info.stage_index](fmdev);
+}
+
+static void fm_irq_handle_tune_op_ended(void *arg)
+{
+ struct fmdrv_ops *fmdev;
+
+ fmdev = arg;
+ if (fmdev->irq_info.flag & (FM_FR_EVENT | FM_BL_EVENT) & fmdev->
+ irq_info.mask) {
+ pr_debug("(fmdrv): irq: tune ended/bandlimit reached\n");
+ if (test_and_clear_bit(FM_AF_SWITCH_INPROGRESS, &fmdev->flag)) {
+ fmdev->irq_info.stage_index = FM_AF_JUMP_RD_FREQ_INDEX;
+ } else {
+ complete(&fmdev->maintask_completion);
+ fmdev->irq_info.stage_index = FM_HW_POWER_ENB_INDEX;
+ }
+ } else
+ fmdev->irq_info.stage_index = FM_HW_POWER_ENB_INDEX;
+
+ fmdev->irq_info.fm_int_handlers[fmdev->irq_info.stage_index](fmdev);
+}
+
+static void fm_irq_handle_power_enb(void *arg)
+{
+ struct fmdrv_ops *fmdev;
+
+ fmdev = arg;
+ if (fmdev->irq_info.flag & FM_POW_ENB_EVENT) {
+ pr_debug("(fmdrv): irq: Power Enabled/Disabled\n");
+ complete(&fmdev->maintask_completion);
+ }
+
+ /* Continue next function in interrupt handler table */
+ fmdev->irq_info.stage_index = FM_LOW_RSSI_START_INDEX;
+ fmdev->irq_info.fm_int_handlers[fmdev->irq_info.stage_index](fmdev);
+}
+
+static void fm_irq_handle_low_rssi_start(void *arg)
+{
+ struct fmdrv_ops *fmdev;
+
+ fmdev = arg;
+ if ((fmdev->rx.af_mode == FM_RX_RDS_AF_SWITCH_MODE_ON) &&
+ (fmdev->irq_info.flag & FM_LEV_EVENT & fmdev->irq_info.mask) &&
+ (fmdev->rx.curr_freq != FM_UNDEFINED_FREQ) &&
+ (fmdev->rx.cur_station_info.no_of_items_in_afcache != 0)) {
+ pr_debug("(fmdrv): irq: rssi level has fallen below"
+ " threshold level\n");
+
+ /* Disable further low RSSI interrupts */
+ fmdev->irq_info.mask &= ~FM_LEV_EVENT;
+
+ fmdev->rx.cur_afjump_index = 0;
+ fmdev->rx.freq_before_jump = fmdev->rx.curr_freq;
+ fmdev->irq_info.stage_index = FM_AF_JUMP_SETPI_INDEX;
+ } else {
+ /* Continue next function in interrupt handler table */
+ fmdev->irq_info.stage_index = FM_SEND_INTMSK_CMD_INDEX;
+ }
+ fmdev->irq_info.fm_int_handlers[fmdev->irq_info.stage_index](fmdev);
+}
+
+static void fm_irq_afjump_set_pi(void *arg)
+{
+ struct fmdrv_ops *fmdev;
+ int ret;
+ unsigned short payload;
+
+ fmdev = arg;
+ /* Set PI code - must be updated if the AF list is not empty */
+ payload = FM_LE16_TO_BE16(fmdev->rx.cur_station_info.picode);
+ ret = __fm_send_cmd(fmdev, RDS_PI_SET, &payload, sizeof(payload),
+ NULL);
+ if (ret < 0)
+ pr_err("(fmdrv): irq : failed to set PI,"
+ "initiating irq recovery process\n");
+ else
+ fmdev->irq_info.stage_index =
+ FM_AF_JUMP_HANDLE_SETPI_RESP_INDEX;
+
+ mod_timer(&fmdev->irq_info.int_timeout_timer, jiffies +
+ FM_DRV_TX_TIMEOUT);
+}
+
+static void fm_irq_handle_set_pi_resp(void *arg)
+{
+ struct fmdrv_ops *fmdev;
+ struct sk_buff *skb;
+ int ret;
+
+ fmdev = arg;
+ del_timer(&fmdev->irq_info.int_timeout_timer);
+
+ ret = __check_cmdresp_status(fmdev, &skb);
+ if (ret < 0) {
+ pr_err("(fmdrv): Initiating irq recovery process\n");
+ mod_timer(&fmdev->irq_info.int_timeout_timer, jiffies +
+ FM_DRV_TX_TIMEOUT);
+ return;
+ }
+ /* Continue next function in interrupt handler table */
+ fmdev->irq_info.stage_index = FM_AF_JUMP_SETPI_MASK_INDEX;
+
+ fmdev->irq_info.fm_int_handlers[fmdev->irq_info.stage_index](fmdev);
+}
+
+/*
+ * Set PI mask.
+ * 0xFFFF = Enable PI code matching
+ * 0x0000 = Disable PI code matching
+ */
+static void fm_irq_afjump_set_pimask(void *arg)
+{
+ struct fmdrv_ops *fmdev;
+ int ret;
+ unsigned short payload;
+
+ fmdev = arg;
+ payload = 0x0000;
+ ret = __fm_send_cmd(fmdev, RDS_PI_MASK_SET, &payload, sizeof(payload),
+ NULL);
+ if (ret < 0)
+ pr_err("(fmdrv): irq: failed to set PI mask, "
+ "initiating irq recovery process\n");
+ else
+ fmdev->irq_info.stage_index =
+ FM_AF_JUMP_HANDLE_SETPI_MASK_RESP_INDEX;
+
+ mod_timer(&fmdev->irq_info.int_timeout_timer, jiffies +
+ FM_DRV_TX_TIMEOUT);
+}
+
+static void fm_irq_handle_set_pimask_resp(void *arg)
+{
+ struct fmdrv_ops *fmdev;
+ struct sk_buff *skb;
+ int ret;
+
+ fmdev = arg;
+ del_timer(&fmdev->irq_info.int_timeout_timer);
+
+ ret = __check_cmdresp_status(fmdev, &skb);
+ if (ret < 0) {
+ pr_err("(fmdrv): Initiating irq recovery process\n");
+ mod_timer(&fmdev->irq_info.int_timeout_timer, jiffies +
+ FM_DRV_TX_TIMEOUT);
+ return;
+ }
+ /* Continue next function in interrupt handler table */
+ fmdev->irq_info.stage_index = FM_AF_JUMP_SET_AF_FREQ_INDEX;
+ fmdev->irq_info.fm_int_handlers[fmdev->irq_info.stage_index](fmdev);
+}
+
+static void fm_irq_afjump_setfreq(void *arg)
+{
+ struct fmdrv_ops *fmdev;
+ unsigned short frq_index;
+ unsigned short payload;
+ int ret;
+
+ fmdev = arg;
+ pr_debug("(fmdrv): Swtiching to %d KHz\n",
+ fmdev->rx.cur_station_info.af_cache[fmdev->rx.cur_afjump_index]);
+ frq_index =
+ (fmdev->rx.cur_station_info.af_cache[fmdev->rx.cur_afjump_index] -
+ fmdev->rx.region.bottom_frequency) / FM_FREQ_MUL;
+
+ FM_STORE_LE16_TO_BE16(payload, frq_index);
+ ret = __fm_send_cmd(fmdev, AF_FREQ_SET, &payload, sizeof(payload),
+ NULL);
+ if (ret < 0)
+ pr_err("(fmdrv): irq : failed to set AF freq, "
+ "initiating irq recovery process\n");
+ else
+ fmdev->irq_info.stage_index =
+ FM_AF_JUMP_HENDLE_SET_AFFREQ_RESP_INDEX;
+
+ mod_timer(&fmdev->irq_info.int_timeout_timer, jiffies +
+ FM_DRV_TX_TIMEOUT);
+}
+
+static void fm_irq_handle_setfreq_resp(void *arg)
+{
+ struct fmdrv_ops *fmdev;
+ struct sk_buff *skb;
+ int ret;
+
+ fmdev = arg;
+ del_timer(&fmdev->irq_info.int_timeout_timer);
+
+ ret = __check_cmdresp_status(fmdev, &skb);
+ if (ret < 0) {
+ pr_err("(fmdrv): Initiating irq recovery process\n");
+ mod_timer(&fmdev->irq_info.int_timeout_timer, jiffies +
+ FM_DRV_TX_TIMEOUT);
+ return;
+ } else {
+ /* Continue next function in interrupt handler table */
+ fmdev->irq_info.stage_index = FM_AF_JUMP_ENABLE_INT_INDEX;
+ }
+ fmdev->irq_info.fm_int_handlers[fmdev->irq_info.stage_index](fmdev);
+}
+
+static void fm_irq_afjump_enableint(void *arg)
+{
+ struct fmdrv_ops *fmdev;
+ unsigned short payload;
+ int ret;
+
+ fmdev = arg;
+ /* Enable FR (tuning operation ended) interrupt */
+ payload = FM_LE16_TO_BE16(FM_FR_EVENT);
+ ret = __fm_send_cmd(fmdev, INT_MASK_SET, &payload, sizeof(payload),
+ NULL);
+ if (ret)
+ pr_err("(fmdrv): irq : failed to enable FR interrupt, "
+ "initiating irq recovery process\n");
+ else
+ fmdev->irq_info.stage_index = FM_AF_JUMP_ENABLE_INT_RESP_INDEX;
+
+ mod_timer(&fmdev->irq_info.int_timeout_timer, jiffies +
+ FM_DRV_TX_TIMEOUT);
+}
+
+static void fm_irq_afjump_enableint_resp(void *arg)
+{
+ struct fmdrv_ops *fmdev;
+ struct sk_buff *skb;
+ int ret;
+
+ fmdev = arg;
+ del_timer(&fmdev->irq_info.int_timeout_timer);
+
+ ret = __check_cmdresp_status(fmdev, &skb);
+ if (ret < 0) {
+ pr_err("(fmdrv): Initiating irq recovery process\n");
+ mod_timer(&fmdev->irq_info.int_timeout_timer, jiffies +
+ FM_DRV_TX_TIMEOUT);
+ return;
+ }
+ /* Continue next function in interrupt handler table */
+ fmdev->irq_info.stage_index = FM_AF_JUMP_START_AFJUMP_INDEX;
+ fmdev->irq_info.fm_int_handlers[fmdev->irq_info.stage_index](fmdev);
+}
+
+static void fm_irq_start_afjump(void *arg)
+{
+ struct fmdrv_ops *fmdev;
+ unsigned short payload;
+ int ret;
+
+ fmdev = arg;
+ FM_STORE_LE16_TO_BE16(payload, FM_TUNER_AF_JUMP_MODE);
+ ret = __fm_send_cmd(fmdev, TUNER_MODE_SET, &payload, sizeof(payload),
+ NULL);
+ if (ret)
+ pr_err("(fmdrv): irq : failed to start af switch, "
+ "initiating irq recovery process\n");
+ else
+ fmdev->irq_info.stage_index =
+ FM_AF_JUMP_HANDLE_START_AFJUMP_RESP_INDEX;
+
+ mod_timer(&fmdev->irq_info.int_timeout_timer, jiffies +
+ FM_DRV_TX_TIMEOUT);
+}
+
+static void fm_irq_handle_start_afjump_resp(void *arg)
+{
+ struct fmdrv_ops *fmdev;
+ struct sk_buff *skb;
+ int ret;
+
+ fmdev = arg;
+ del_timer(&fmdev->irq_info.int_timeout_timer);
+
+ ret = __check_cmdresp_status(fmdev, &skb);
+ if (ret < 0) {
+ pr_err("(fmdrv): Initiating irq recovery process\n");
+ mod_timer(&fmdev->irq_info.int_timeout_timer, jiffies +
+ FM_DRV_TX_TIMEOUT);
+ return;
+ }
+ fmdev->irq_info.stage_index = FM_SEND_FLAG_GETCMD_INDEX;
+ set_bit(FM_AF_SWITCH_INPROGRESS, &fmdev->flag);
+ clear_bit(FM_INTTASK_RUNNING, &fmdev->flag);
+}
+
+static void fm_irq_afjump_rd_freq(void *arg)
+{
+ struct fmdrv_ops *fmdev;
+ unsigned short payload;
+ int ret;
+
+ fmdev = arg;
+ ret = __fm_send_cmd(fmdev, FREQ_GET, NULL, sizeof(payload), NULL);
+ if (ret < 0)
+ pr_err("(fmdrv): irq: failed to read cur freq, "
+ "initiating irq recovery process\n");
+ else
+ fmdev->irq_info.stage_index = FM_AF_JUMP_RD_FREQ_RESP_INDEX;
+
+ /* Start timer to track timeout */
+ mod_timer(&fmdev->irq_info.int_timeout_timer, jiffies +
+ FM_DRV_TX_TIMEOUT);
+}
+
+static void fm_irq_afjump_rd_freq_resp(void *arg)
+{
+ struct fmdrv_ops *fmdev;
+ struct sk_buff *skb;
+ unsigned short read_freq;
+ unsigned int curr_freq, jumped_freq;
+ int ret;
+
+ fmdev = arg;
+ del_timer(&fmdev->irq_info.int_timeout_timer);
+
+ ret = __check_cmdresp_status(fmdev, &skb);
+ if (ret < 0) {
+ pr_err("(fmdrv): Initiating irq recovery process\n");
+ mod_timer(&fmdev->irq_info.int_timeout_timer, jiffies +
+ FM_DRV_TX_TIMEOUT);
+ return;
+ }
+ /* Skip header info and copy only response data */
+ skb_pull(skb, sizeof(struct fm_event_msg_hdr));
+ memcpy(&read_freq, skb->data, sizeof(read_freq));
+ read_freq = FM_BE16_TO_LE16(read_freq);
+ curr_freq = fmdev->rx.region.bottom_frequency +
+ ((unsigned int)read_freq * FM_FREQ_MUL);
+
+ jumped_freq =
+ fmdev->rx.cur_station_info.af_cache[fmdev->rx.cur_afjump_index];
+
+ /* If the frequency was changed the jump succeeded */
+ if ((curr_freq != fmdev->rx.freq_before_jump) &&
+ (curr_freq == jumped_freq)) {
+ pr_debug("(fmdrv): Successfully switched to alternate"
+ "frequency %d\n", curr_freq);
+ fmdev->rx.curr_freq = curr_freq;
+ fm_rx_reset_rds_cache(fmdev);
+
+ /* AF feature is on, enable low level RSSI interrupt */
+ if (fmdev->rx.af_mode == FM_RX_RDS_AF_SWITCH_MODE_ON)
+ fmdev->irq_info.mask |= FM_LEV_EVENT;
+
+ fmdev->irq_info.stage_index = FM_LOW_RSSI_FINISH_INDEX;
+ } else { /* jump to the next freq in the AF list */
+ fmdev->rx.cur_afjump_index++;
+
+ /* If we reached the end of the list - stop searching */
+ if (fmdev->rx.cur_afjump_index >=
+ fmdev->rx.cur_station_info.no_of_items_in_afcache) {
+ pr_debug("(fmdrv): AF switch processing failed\n");
+ fmdev->irq_info.stage_index = FM_LOW_RSSI_FINISH_INDEX;
+ } else { /* AF List is not over - try next one */
+
+ pr_debug("(fmdrv): Trying next freq in AF cache\n");
+ fmdev->irq_info.stage_index = FM_AF_JUMP_SETPI_INDEX;
+ }
+ }
+ fmdev->irq_info.fm_int_handlers[fmdev->irq_info.stage_index](fmdev);
+}
+
+static void fm_irq_handle_low_rssi_finish(void *arg)
+{
+ struct fmdrv_ops *fmdev;
+
+ fmdev = arg;
+ /* Continue next function in interrupt handler table */
+ fmdev->irq_info.stage_index = FM_SEND_INTMSK_CMD_INDEX;
+ fmdev->irq_info.fm_int_handlers[fmdev->irq_info.stage_index](fmdev);
+}
+
+static void fm_irq_send_intmsk_cmd(void *arg)
+{
+ struct fmdrv_ops *fmdev;
+ unsigned short payload;
+ int ret;
+
+ fmdev = arg;
+
+ /* Re-enable FM interrupts */
+ FM_STORE_LE16_TO_BE16(payload, fmdev->irq_info.mask);
+ ret = __fm_send_cmd(fmdev, INT_MASK_SET, &payload, sizeof(payload),
+ NULL);
+ if (ret)
+ pr_err("(fmdrv): irq: failed to send int_mask_set cmd, "
+ "initiating irq recovery process\n");
+ else
+ fmdev->irq_info.stage_index = FM_HANDLE_INTMSK_CMD_RESP_INDEX;
+
+ /* Start timer to track timeout */
+ mod_timer(&fmdev->irq_info.int_timeout_timer, jiffies +
+ FM_DRV_TX_TIMEOUT);
+}
+
+static void fm_irq_handle_intmsk_cmd_resp(void *arg)
+{
+ struct fmdrv_ops *fmdev;
+ struct sk_buff *skb;
+ int ret;
+
+ fmdev = arg;
+ del_timer(&fmdev->irq_info.int_timeout_timer);
+
+ ret = __check_cmdresp_status(fmdev, &skb);
+ if (ret < 0) {
+ pr_err("(fmdrv): Initiating irq recovery process\n");
+ mod_timer(&fmdev->irq_info.int_timeout_timer, jiffies +
+ FM_DRV_TX_TIMEOUT);
+ return;
+ }
+ /*
+ * This is last function in interrupt table to be executed.
+ * So, reset stage index to 0.
+ */
+ fmdev->irq_info.stage_index = FM_SEND_FLAG_GETCMD_INDEX;
+
+ /* Start processing any pending interrupt */
+ if (test_and_clear_bit(FM_INTTASK_SCHEDULE_PENDING, &fmdev->flag)) {
+ fmdev->irq_info.fm_int_handlers[fmdev->irq_info.stage_index]
+ (fmdev);
+ } else
+ clear_bit(FM_INTTASK_RUNNING, &fmdev->flag);
+}
+
+/* Returns availability of RDS data in internel buffer */
+int fmc_is_rds_data_available(struct fmdrv_ops *fmdev, struct file *file,
+ struct poll_table_struct *pts)
+{
+ poll_wait(file, &fmdev->rx.rds.read_queue, pts);
+ if (fmdev->rx.rds.rd_index != fmdev->rx.rds.wr_index)
+ return 0;
+
+ return -EAGAIN;
+}
+
+/* Copies RDS data from internal buffer to user buffer */
+int fmc_transfer_rds_from_internal_buff(struct fmdrv_ops *fmdev,
+ struct file *file,
+ char __user *buf, size_t count)
+{
+ unsigned int block_count;
+ unsigned long flags;
+ int ret;
+
+ if (fmdev->rx.rds.wr_index == fmdev->rx.rds.rd_index) {
+ if (file->f_flags & O_NONBLOCK)
+ return -EWOULDBLOCK;
+
+ ret = wait_event_interruptible(fmdev->rx.rds.read_queue,
+ (fmdev->rx.rds.wr_index !=
+ fmdev->rx.rds.rd_index));
+ if (ret)
+ return -EINTR;
+ }
+
+ /* Calculate block count from byte count */
+ count /= 3;
+ block_count = 0;
+ ret = 0;
+
+ spin_lock_irqsave(&fmdev->rds_buff_lock, flags);
+
+ while (block_count < count) {
+ if (fmdev->rx.rds.wr_index == fmdev->rx.rds.rd_index)
+ break;
+
+ if (copy_to_user
+ (buf, &fmdev->rx.rds.buffer[fmdev->rx.rds.rd_index],
+ FM_RDS_BLOCK_SIZE))
+ break;
+
+ fmdev->rx.rds.rd_index += FM_RDS_BLOCK_SIZE;
+ if (fmdev->rx.rds.rd_index >= fmdev->rx.rds.buf_size)
+ fmdev->rx.rds.rd_index = 0;
+
+ block_count++;
+ buf += FM_RDS_BLOCK_SIZE;
+ ret += FM_RDS_BLOCK_SIZE;
+ }
+ spin_unlock_irqrestore(&fmdev->rds_buff_lock, flags);
+ return ret;
+}
+
+int fmc_set_frequency(struct fmdrv_ops *fmdev, unsigned int freq_to_set)
+{
+ int ret;
+
+ switch (fmdev->curr_fmmode) {
+ case FM_MODE_RX:
+ ret = fm_rx_set_frequency(fmdev, freq_to_set);
+ break;
+
+ case FM_MODE_TX:
+ ret = fm_tx_set_frequency(fmdev, freq_to_set);
+ break;
+
+ default:
+ ret = -EINVAL;
+ }
+ return ret;
+}
+
+int fmc_get_frequency(struct fmdrv_ops *fmdev, unsigned int *cur_tuned_frq)
+{
+ int ret = 0;
+
+ if (fmdev->rx.curr_freq == FM_UNDEFINED_FREQ) {
+ pr_err("(fmdrv): RX frequency is not set\n");
+ return -EPERM;
+ }
+ if (cur_tuned_frq == NULL) {
+ pr_err("(fmdrv): Invalid memory\n");
+ return -ENOMEM;
+ }
+
+ switch (fmdev->curr_fmmode) {
+ case FM_MODE_RX:
+ *cur_tuned_frq = fmdev->rx.curr_freq;
+ break;
+
+ case FM_MODE_TX:
+ *cur_tuned_frq = 0; /* TODO : Change this later */
+ break;
+
+ default:
+ ret = -EINVAL;
+ }
+
+ return ret;
+}
+
+int fmc_set_region(struct fmdrv_ops *fmdev, unsigned char region_to_set)
+{
+ int ret;
+
+ switch (fmdev->curr_fmmode) {
+ case FM_MODE_RX:
+ ret = fm_rx_set_region(fmdev, region_to_set);
+ break;
+
+ case FM_MODE_TX:
+ ret = fm_tx_set_region(fmdev, region_to_set);
+ break;
+
+ default:
+ ret = -EINVAL;
+ }
+ return ret;
+}
+
+int fmc_set_mute_mode(struct fmdrv_ops *fmdev, unsigned char mute_mode_toset)
+{
+ int ret;
+
+ switch (fmdev->curr_fmmode) {
+ case FM_MODE_RX:
+ ret = fm_rx_set_mute_mode(fmdev, mute_mode_toset);
+ break;
+
+ case FM_MODE_TX:
+ ret = fm_tx_set_mute_mode(fmdev, mute_mode_toset);
+ break;
+
+ default:
+ ret = -EINVAL;
+ }
+ return ret;
+}
+
+int fmc_set_stereo_mono(struct fmdrv_ops *fmdev, unsigned short mode)
+{
+ int ret;
+
+ switch (fmdev->curr_fmmode) {
+ case FM_MODE_RX:
+ ret = fm_rx_set_stereo_mono(fmdev, mode);
+ break;
+
+ case FM_MODE_TX:
+ ret = fm_tx_set_stereo_mono(fmdev, mode);
+ break;
+
+ default:
+ ret = -EINVAL;
+ }
+ return ret;
+}
+
+int fmc_set_rds_mode(struct fmdrv_ops *fmdev, unsigned char rds_en_dis)
+{
+ int ret;
+
+ switch (fmdev->curr_fmmode) {
+ case FM_MODE_RX:
+ ret = fm_rx_set_rds_mode(fmdev, rds_en_dis);
+ break;
+
+ case FM_MODE_TX:
+ ret = fm_tx_set_rds_mode(fmdev, rds_en_dis);
+ break;
+
+ default:
+ ret = -EINVAL;
+ }
+ return ret;
+}
+
+/* Sends power off command to the chip */
+static int fm_power_down(struct fmdrv_ops *fmdev)
+{
+ unsigned short payload;
+ int ret = 0;
+
+ if (!test_bit(FM_CORE_READY, &fmdev->flag)) {
+ pr_err("(fmdrv): FM core is not ready\n");
+ return -EPERM;
+ }
+ if (fmdev->curr_fmmode == FM_MODE_OFF) {
+ pr_debug("(fmdrv): FM chip is already in OFF state\n");
+ return ret;
+ }
+
+ FM_STORE_LE16_TO_BE16(payload, 0x0);
+ ret = fmc_send_cmd(fmdev, FM_POWER_MODE, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to send power down command - %d\n",
+ ret);
+ return ret;
+ }
+
+ ret = fmc_release(fmdev);
+ if (ret < 0)
+ pr_err("(fmdrv): FM CORE release failed\n");
+
+ return ret;
+}
+
+/* Reads init command from FM firmware file and loads to the chip */
+static int fm_download_firmware(struct fmdrv_ops *fmdev,
+ const char *firmware_name)
+{
+ const struct firmware *fw_entry;
+ struct bts_header *fw_header;
+ struct bts_action *action;
+ struct bts_action_delay *delay;
+ char *fw_data;
+ int ret, fw_len, cmd_cnt;
+
+ cmd_cnt = 0;
+ set_bit(FM_FIRMWARE_DW_INPROGRESS, &fmdev->flag);
+
+ ret = request_firmware(&fw_entry, firmware_name,
+ &fmdev->radio_dev->dev);
+ if (ret < 0) {
+ pr_err("(fmdrv): Unable to read firmware(%s) content\n",
+ firmware_name);
+ return ret;
+ }
+ pr_debug("(fmdrv): Firmware(%s) length : %d bytes\n", firmware_name,
+ fw_entry->size);
+
+ fw_data = (void *)fw_entry->data;
+ fw_len = fw_entry->size;
+
+ fw_header = (struct bts_header *)fw_data;
+ if (fw_header->magic != FM_FW_FILE_HEADER_MAGIC) {
+ pr_err("(fmdrv): %s not a legal TI firmware file\n",
+ firmware_name);
+ ret = -EINVAL;
+ goto rel_fw;
+ }
+ pr_debug("(fmdrv): Firmware(%s) magic number : 0x%x\n", firmware_name,
+ fw_header->magic);
+
+ /* Skip file header info , we already verified it */
+ fw_data += sizeof(struct bts_header);
+ fw_len -= sizeof(struct bts_header);
+
+ while (fw_data && fw_len > 0) {
+ action = (struct bts_action *)fw_data;
+
+ switch (action->type) {
+ case ACTION_SEND_COMMAND: /* Send */
+ ret = fmc_send_cmd(fmdev, 0, action->data,
+ action->size, &fmdev->maintask_completion,
+ NULL, NULL);
+ if (ret < 0)
+ goto rel_fw;
+
+ cmd_cnt++;
+ break;
+
+ case ACTION_DELAY: /* Delay */
+ delay = (struct bts_action_delay *)action->data;
+ mdelay(delay->msec);
+ break;
+ }
+
+ fw_data += (sizeof(struct bts_action) + (action->size));
+ fw_len -= (sizeof(struct bts_action) + (action->size));
+ }
+ pr_debug("(fmdrv): Firmare commands(%d) loaded to chip\n", cmd_cnt);
+rel_fw:
+ release_firmware(fw_entry);
+ clear_bit(FM_FIRMWARE_DW_INPROGRESS, &fmdev->flag);
+
+ return ret;
+}
+
+/* Loads default RX configuration to the chip */
+static int __load_default_rx_configuration(struct fmdrv_ops *fmdev)
+{
+ int ret;
+
+ ret = fm_rx_set_volume(fmdev, FM_DEFAULT_RX_VOLUME);
+ if (ret < 0)
+ return ret;
+
+ ret = fm_rx_set_rssi_threshold(fmdev, FM_DEFAULT_RSSI_THRESHOLD);
+ return ret;
+}
+
+/* Does FM power on sequence */
+static int fm_power_up(struct fmdrv_ops *fmdev, unsigned char fw_option)
+{
+ unsigned short payload, asic_id, asic_ver;
+ int resp_len, ret;
+ char fw_name[50];
+
+ if (fw_option >= FM_MODE_ENTRY_MAX) {
+ pr_err("(fmdrv): Invalid firmware download option\n");
+ return -EINVAL;
+ }
+
+ /*
+ * Initialize FM common module. FM GPIO toggling is
+ * taken care in Shared Transport driver.
+ */
+ ret = fmc_prepare(fmdev);
+ if (ret < 0) {
+ pr_err("(fmdrv): Unable to prepare FM Common\n");
+ return ret;
+ }
+
+ FM_STORE_LE16_TO_BE16(payload, FM_ENABLE);
+ ret = fmc_send_cmd(fmdev, FM_POWER_MODE, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed enable FM over Channel 8\n");
+ goto rel;
+ }
+
+ /* Allow the chip to settle down in Channel-8 mode */
+ msleep(5);
+
+ ret = fmc_send_cmd(fmdev, ASIC_ID_GET, NULL, sizeof(asic_id),
+ &fmdev->maintask_completion, &asic_id,
+ &resp_len);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed read FM chip ASIC ID\n");
+ goto rel;
+ }
+ ret = fmc_send_cmd(fmdev, ASIC_VER_GET, NULL, sizeof(asic_ver),
+ &fmdev->maintask_completion, &asic_ver,
+ &resp_len);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed read FM chip ASIC Version\n");
+ goto rel;
+ }
+
+ pr_debug("(fmdrv): ASIC ID: 0x%x , ASIC Version: %d\n",
+ FM_BE16_TO_LE16(asic_id), FM_BE16_TO_LE16(asic_ver));
+
+ sprintf(fw_name, "%s_%x.%d.bts", FM_FMC_FW_FILE_START,
+ FM_BE16_TO_LE16(asic_id), FM_BE16_TO_LE16(asic_ver));
+ ret = fm_download_firmware(fmdev, fw_name);
+ if (ret < 0) {
+ pr_debug("(fmdrv): Failed to download firmware file %s\n",
+ fw_name);
+ goto rel;
+ }
+
+ sprintf(fw_name, "%s_%x.%d.bts", (fw_option == FM_MODE_RX) ?
+ FM_RX_FW_FILE_START : FM_TX_FW_FILE_START,
+ FM_BE16_TO_LE16(asic_id), FM_BE16_TO_LE16(asic_ver));
+ ret = fm_download_firmware(fmdev, fw_name);
+ if (ret < 0) {
+ pr_debug("(fmdrv): Failed to download firmware file %s\n",
+ fw_name);
+ goto rel;
+ } else
+ return ret;
+rel:
+ fmc_release(fmdev);
+
+ return ret;
+}
+
+/* Set FM Modes(TX, RX, OFF) */
+int fmc_set_mode(struct fmdrv_ops *fmdev, unsigned char fm_mode)
+{
+ int ret = 0;
+
+ if (fm_mode >= FM_MODE_ENTRY_MAX) {
+ pr_err("(fmdrv): Invalid FM mode\n");
+ return -EINVAL;
+ }
+ if (fmdev->curr_fmmode == fm_mode) {
+ pr_debug("(fmdrv): Already fm is in mode(%d)\n", fm_mode);
+ return ret;
+ }
+
+ switch (fm_mode) {
+ case FM_MODE_OFF: /* OFF Mode */
+ ret = fm_power_down(fmdev);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set OFF mode\n");
+ return ret;
+ }
+ break;
+
+ case FM_MODE_TX: /* TX Mode */
+ case FM_MODE_RX: /* RX Mode */
+ /* Power down before switching to TX or RX mode */
+ if (fmdev->curr_fmmode != FM_MODE_OFF) {
+ ret = fm_power_down(fmdev);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set OFF mode\n");
+ return ret;
+ }
+ msleep(30);
+ }
+ ret = fm_power_up(fmdev, fm_mode);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to load firmware\n");
+ return ret;
+ }
+ }
+ fmdev->curr_fmmode = fm_mode;
+
+ /* Set default configuration */
+ if (fmdev->curr_fmmode == FM_MODE_RX) {
+ pr_debug("(fmdrv): Loading default rx configuration..\n");
+ ret = __load_default_rx_configuration(fmdev);
+ if (ret < 0)
+ pr_err("(fmdrv): Failed to load default values\n");
+ }
+
+ return ret;
+}
+
+/* Returns current FM mode (TX, RX, OFF) */
+int fmc_get_mode(struct fmdrv_ops *fmdev, unsigned char *fmmode)
+{
+ if (!test_bit(FM_CORE_READY, &fmdev->flag)) {
+ pr_err("(fmdrv): FM core is not ready\n");
+ return -EPERM;
+ }
+ if (fmmode == NULL) {
+ pr_err("(fmdrv): Invalid memory\n");
+ return -ENOMEM;
+ }
+
+ *fmmode = fmdev->curr_fmmode;
+ return 0;
+}
+
+/* Called by ST layer when FM packet is available */
+static long fm_st_receive(void *arg, struct sk_buff *skb)
+{
+ struct fmdrv_ops *fmdev;
+
+ fmdev = (struct fmdrv_ops *)arg;
+
+ if (skb == NULL) {
+ pr_err("(fmdrv): Invalid SKB received from ST\n");
+ return -EFAULT;
+ }
+
+ if (skb->cb[0] != FM_PKT_LOGICAL_CHAN_NUMBER) {
+ pr_err("(fmdrv): Received SKB (%p) is not FM Channel 8 pkt\n",
+ skb);
+ return -EINVAL;
+ }
+
+ memcpy(skb_push(skb, 1), &skb->cb[0], 1);
+ skb_queue_tail(&fmdev->rx_q, skb);
+ tasklet_schedule(&fmdev->rx_task);
+
+ return 0;
+}
+
+/*
+ * Called by ST layer to indicate protocol registration completion
+ * status.
+ */
+static void fm_st_reg_comp_cb(void *arg, char data)
+{
+ struct fmdrv_ops *fmdev;
+
+ fmdev = (struct fmdrv_ops *)arg;
+ fmdev->streg_cbdata = data;
+ complete(&wait_for_fmdrv_reg_comp);
+}
+
+/*
+ * This function will be called from FM V4L2 open function.
+ * Register with ST driver and initialize driver data.
+ */
+int fmc_prepare(struct fmdrv_ops *fmdev)
+{
+ static struct st_proto_s fm_st_proto;
+ unsigned long timeleft;
+ int ret = 0;
+
+ if (test_bit(FM_CORE_READY, &fmdev->flag)) {
+ pr_debug("(fmdrv): FM Core is already up\n");
+ return ret;
+ }
+
+ memset(&fm_st_proto, 0, sizeof(fm_st_proto));
+ fm_st_proto.type = ST_FM;
+ fm_st_proto.recv = fm_st_receive;
+ fm_st_proto.match_packet = NULL;
+ fm_st_proto.reg_complete_cb = fm_st_reg_comp_cb;
+ fm_st_proto.write = NULL; /* TI ST driver will fill write pointer */
+ fm_st_proto.priv_data = fmdev;
+
+ ret = st_register(&fm_st_proto);
+ if (ret == -EINPROGRESS) {
+ init_completion(&wait_for_fmdrv_reg_comp);
+ fmdev->streg_cbdata = -EINPROGRESS;
+ pr_debug("(fmdrv): %s waiting for ST reg completion signal\n",
+ __func__);
+
+ timeleft =
+ wait_for_completion_timeout(&wait_for_fmdrv_reg_comp,
+ FM_ST_REGISTER_TIMEOUT);
+
+ if (!timeleft) {
+ pr_err("(fmdrv): Timeout(%d sec), didn't get reg "
+ "completion signal from ST\n",
+ jiffies_to_msecs(FM_ST_REGISTER_TIMEOUT) / 1000);
+ return -ETIMEDOUT;
+ }
+ if (fmdev->streg_cbdata != 0) {
+ pr_err("(fmdrv): ST reg comp CB called with error "
+ "status %d\n", fmdev->streg_cbdata);
+ return -EAGAIN;
+ }
+ ret = 0;
+ } else if (ret == -1) {
+ pr_err("(fmdrv): st_register failed %d\n", ret);
+ return -EAGAIN;
+ }
+
+ if (fm_st_proto.write != NULL) {
+ g_st_write = fm_st_proto.write;
+ } else {
+ pr_err("(fmdrv): Failed to get ST write func pointer\n");
+ ret = st_unregister(ST_FM);
+ if (ret < 0)
+ pr_err("(fmdrv): st_unregister failed %d\n", ret);
+ return -EAGAIN;
+ }
+
+ spin_lock_init(&fmdev->rds_buff_lock);
+ spin_lock_init(&fmdev->resp_skb_lock);
+
+ /* Initialize TX queue and TX tasklet */
+ skb_queue_head_init(&fmdev->tx_q);
+ tasklet_init(&fmdev->tx_task, __send_tasklet, (unsigned long)fmdev);
+
+ /* Initialize RX Queue and RX tasklet */
+ skb_queue_head_init(&fmdev->rx_q);
+ tasklet_init(&fmdev->rx_task, __recv_tasklet, (unsigned long)fmdev);
+
+ fmdev->irq_info.stage_index = 0;
+ atomic_set(&fmdev->tx_cnt, 1);
+ fmdev->response_completion = NULL;
+
+ init_timer(&fmdev->irq_info.int_timeout_timer);
+ fmdev->irq_info.int_timeout_timer.function =
+ &__int_timeout_handler;
+ fmdev->irq_info.int_timeout_timer.data = (unsigned long)fmdev;
+ fmdev->irq_info.mask =
+ FM_MAL_EVENT /*| FM_STIC_EVENT <<Enable this later>> */ ;
+
+ /* Region info */
+ memcpy(&fmdev->rx.region, &region_configs[default_radio_region],
+ sizeof(struct region_info));
+
+ fmdev->rx.curr_mute_mode = FM_MUTE_OFF;
+ fmdev->rx.curr_rf_depend_mute = FM_RX_RF_DEPENDENT_MUTE_OFF;
+ fmdev->rx.rds.flag = FM_RDS_DISABLE;
+ fmdev->rx.curr_freq = FM_UNDEFINED_FREQ;
+ fmdev->rx.rds_mode = FM_RDS_SYSTEM_RDS;
+ fmdev->rx.af_mode = FM_RX_RDS_AF_SWITCH_MODE_OFF;
+ fmdev->irq_info.irq_service_timeout_retry = 0;
+
+ fm_rx_reset_rds_cache(fmdev);
+ init_waitqueue_head(&fmdev->rx.rds.read_queue);
+
+ fm_rx_reset_curr_station_info(fmdev);
+ set_bit(FM_CORE_READY, &fmdev->flag);
+
+ return ret;
+}
+
+/*
+ * This function will be called from FM V4L2 release function.
+ * Unregister from ST driver.
+ */
+int fmc_release(struct fmdrv_ops *fmdev)
+{
+ int ret;
+
+ if (!test_bit(FM_CORE_READY, &fmdev->flag)) {
+ pr_debug("(fmdrv): FM Core is already down\n");
+ return 0;
+ }
+ /* Sevice pending read */
+ wake_up_interruptible(&fmdev->rx.rds.read_queue);
+
+ tasklet_kill(&fmdev->tx_task);
+ tasklet_kill(&fmdev->rx_task);
+
+ skb_queue_purge(&fmdev->tx_q);
+ skb_queue_purge(&fmdev->rx_q);
+
+ fmdev->response_completion = NULL;
+ fmdev->rx.curr_freq = 0;
+
+ ret = st_unregister(ST_FM);
+ if (ret < 0)
+ pr_err("(fmdrv): Failed to de-register FM from ST %d\n", ret);
+ else
+ pr_debug("(fmdrv): Successfully unregistered from ST\n");
+
+ clear_bit(FM_CORE_READY, &fmdev->flag);
+ return ret;
+}
+
+/*
+ * Module init function. Ask FM V4L module to register video device.
+ * Allocate memory for FM driver context and RX RDS buffer.
+ */
+static int __init fm_drv_init(void)
+{
+ struct fmdrv_ops *fmdev = NULL;
+ int ret = -ENOMEM;
+
+ pr_debug("(fmdrv): FM driver version %s\n", FM_DRV_VERSION);
+
+ fmdev = kzalloc(sizeof(struct fmdrv_ops), GFP_KERNEL);
+ if (NULL == fmdev) {
+ pr_err("(fmdrv): Can't allocate operation structure memory\n");
+ return ret;
+ }
+ fmdev->rx.rds.buf_size = default_rds_buf * FM_RDS_BLOCK_SIZE;
+ fmdev->rx.rds.buffer = kzalloc(fmdev->rx.rds.buf_size, GFP_KERNEL);
+ if (NULL == fmdev->rx.rds.buffer) {
+ pr_err("(fmdrv): Can't allocate rds ring buffer\n");
+ goto rel_dev;
+ }
+
+ ret = fm_v4l2_init_video_device(fmdev, radio_nr);
+ if (ret < 0)
+ goto rel_rdsbuf;
+
+ fmdev->irq_info.fm_int_handlers = g_IntHandlerTable;
+ fmdev->curr_fmmode = FM_MODE_OFF;
+ fmdev->tx_data.pwr_lvl = FM_PWR_LVL_DEF;
+ fmdev->tx_data.preemph = FM_TX_PREEMPH_50US;
+ return ret;
+
+rel_rdsbuf:
+ kfree(fmdev->rx.rds.buffer);
+rel_dev:
+ kfree(fmdev);
+
+ return ret;
+}
+
+/* Module exit function. Ask FM V4L module to unregister video device */
+static void __exit fm_drv_exit(void)
+{
+ struct fmdrv_ops *fmdev = NULL;
+
+ fmdev = fm_v4l2_deinit_video_device();
+ if (fmdev != NULL) {
+ kfree(fmdev->rx.rds.buffer);
+ kfree(fmdev);
+ }
+}
+
+module_init(fm_drv_init);
+module_exit(fm_drv_exit);
+
+/* ------------- Module Info ------------- */
+MODULE_AUTHOR("Raja Mani <[email protected]>");
+MODULE_DESCRIPTION("FM Driver for Connectivity chip of Texas Instruments. "
+ FM_DRV_VERSION);
+MODULE_VERSION(FM_DRV_VERSION);
+MODULE_LICENSE("GPL");
diff --git a/drivers/staging/ti-st/fmdrv_common.h b/drivers/staging/ti-st/fmdrv_common.h
new file mode 100644
index 0000000..a2628f4
--- /dev/null
+++ b/drivers/staging/ti-st/fmdrv_common.h
@@ -0,0 +1,458 @@
+/*
+ * FM Driver for Connectivity chip of Texas Instruments.
+ * FM Common module header file
+ *
+ * Copyright (C) 2010 Texas Instruments
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#ifndef _FMDRV_COMMON_H
+#define _FMDRV_COMMON_H
+
+#define FM_ST_REGISTER_TIMEOUT msecs_to_jiffies(6000) /* 6 sec */
+#define FM_PKT_LOGICAL_CHAN_NUMBER 0x08 /* Logical channel 8 */
+
+#define REG_RD 0x1
+#define REG_WR 0x0
+
+struct fm_reg_table {
+ unsigned char opcode;
+ unsigned char type;
+ char *name;
+};
+
+/* FM register index */
+enum fm_reg_index {
+ /* FM RX registers */
+ STEREO_GET,
+ RSSI_LVL_GET,
+ IF_COUNT_GET,
+ FLAG_GET,
+ RDS_SYNC_GET,
+ RDS_DATA_GET,
+ FREQ_SET,
+ FREQ_GET,
+ AF_FREQ_SET,
+ AF_FREQ_GET,
+ MOST_MODE_SET,
+ MOST_MODE_GET,
+ MOST_BLEND_SET,
+ MOST_BLEND_GET,
+ DEMPH_MODE_SET,
+ DEMPH_MODE_GET,
+ SEARCH_LVL_SET,
+ SEARCH_LVL_GET,
+ RX_BAND_SET,
+ RX_BAND_GET,
+ MUTE_STATUS_SET,
+ MUTE_STATUS_GET,
+ RDS_PAUSE_LVL_SET,
+ RDS_PAUSE_LVL_GET,
+ RDS_PAUSE_DUR_SET,
+ RDS_PAUSE_DUR_GET,
+ RDS_MEM_SET,
+ RDS_MEM_GET,
+ RDS_BLK_B_SET,
+ RDS_BLK_B_GET,
+ RDS_MSK_B_SET,
+ RDS_MSK_B_GET,
+ RDS_PI_MASK_SET,
+ RDS_PI_MASK_GET,
+ RDS_PI_SET,
+ RDS_PI_GET,
+ RDS_SYSTEM_SET,
+ RDS_SYSTEM_GET,
+ INT_MASK_SET,
+ INT_MASK_GET,
+ SEARCH_DIR_SET,
+ SEARCH_DIR_GET,
+ VOLUME_SET,
+ VOLUME_GET,
+ AUDIO_ENABLE_SET,
+ AUDIO_ENABLE_GET,
+ PCM_MODE_SET,
+ PCM_MODE_GET,
+ I2S_MODE_CONFIG_SET,
+ I2S_MODE_CONFIG_GET,
+ POWER_SET,
+ POWER_GET,
+ INTx_CONFIG_SET,
+ INTx_CONFIG_GET,
+ PULL_EN_SET,
+ PULL_EN_GET,
+ HILO_SET,
+ HILO_GET,
+ SWITCH2FREF,
+ FREQ_DRIFT_REPORT,
+ PCE_GET,
+ FIRM_VER_GET,
+ ASIC_VER_GET,
+ ASIC_ID_GET,
+ MAIN_ID_GET,
+ TUNER_MODE_SET,
+ STOP_SEARCH,
+ RDS_CNTRL_SET,
+ WRITE_HARDWARE_REG,
+ CODE_DOWNLOAD,
+ RESET,
+ FM_POWER_MODE,
+ FM_INTERRUPT,
+
+ /* FM TX registers */
+ CHANL_SET,
+ CHANL_GET,
+ CHANL_BW_SET,
+ CHANL_BW_GET,
+ REF_SET,
+ REF_GET,
+ POWER_ENB_SET,
+ POWER_ATT_SET,
+ POWER_ATT_GET,
+ POWER_LEL_SET,
+ POWER_LEL_GET,
+ AUDIO_DEV_SET,
+ AUDIO_DEV_GET,
+ PILOT_DEV_SET,
+ PILOT_DEV_GET,
+ RDS_DEV_SET,
+ RDS_DEV_GET,
+ PUPD_SET,
+ AUDIO_IO_SET,
+ PREMPH_SET,
+ PREMPH_GET,
+ TX_BAND_SET,
+ TX_BAND_GET,
+ MONO_SET,
+ MONO_GET,
+ MUTE,
+ MPX_LMT_ENABLE,
+ LOCK_GET,
+ REF_ERR_SET,
+ PI_SET,
+ PI_GET,
+ TYPE_SET,
+ TYPE_GET,
+ PTY_SET,
+ PTY_GET,
+ AF_SET,
+ AF_GET,
+ DISPLAY_SIZE_SET,
+ DISPLAY_SIZE_GET,
+ RDS_MODE_SET,
+ RDS_MODE_GET,
+ DISPLAY_MODE_SET,
+ DISPLAY_MODE_GET,
+ LENGTH_SET,
+ LENGTH_GET,
+ TOGGLE_AB_SET,
+ TOGGLE_AB_GET,
+ RDS_REP_SET,
+ RDS_REP_GET,
+ RDS_DATA_SET,
+ RDS_DATA_ENB,
+ TA_SET,
+ TA_GET,
+ TP_SET,
+ TP_GET,
+ DI_SET,
+ DI_GET,
+ MS_SET,
+ MS_GET,
+ PS_SCROLL_SPEED_SET,
+ PS_SCROLL_SPEED_GET,
+ IMP_SET,
+ IMP_GET,
+
+ FM_REG_MAX_ENTRIES
+};
+
+/* SKB helpers */
+struct fm_skb_cb {
+ __u8 fm_opcode;
+ struct completion *completion;
+};
+
+#define fm_cb(skb) ((struct fm_skb_cb *)(skb->cb))
+
+/* FM Channel-8 command message format */
+struct fm_cmd_msg_hdr {
+ __u8 header; /* Logical Channel-8 */
+ __u8 len; /* Number of bytes follows */
+ __u8 fm_opcode; /* FM Opcode */
+ __u8 rd_wr; /* Read/Write command */
+ __u8 dlen; /* Length of payload */
+} __attribute__ ((packed));
+
+#define FM_CMD_MSG_HDR_SIZE 5 /* sizeof(struct fm_cmd_msg_hdr) */
+
+/* FM Channel-8 event messgage format */
+struct fm_event_msg_hdr {
+ __u8 header; /* Logical Channel-8 */
+ __u8 len; /* Number of bytes follows */
+ __u8 status; /* Event status */
+ __u8 num_fm_hci_cmds; /* Number of pkts the host allowed to send */
+ __u8 fm_opcode; /* FM Opcode */
+ __u8 rd_wr; /* Read/Write command */
+ __u8 dlen; /* Length of payload */
+} __attribute__ ((packed));
+
+#define FM_EVT_MSG_HDR_SIZE 7 /* sizeof(struct fm_event_msg_hdr) */
+
+/* TI's magic number in firmware file */
+#define FM_FW_FILE_HEADER_MAGIC 0x42535442
+
+/* Converts little endian to big endian */
+#define FM_STORE_LE16_TO_BE16(data, value) \
+ (data = ((value >> 8) | ((value & 0xFF) << 8)))
+#define FM_LE16_TO_BE16(value) (((value >> 8) | ((value & 0xFF) << 8)))
+
+/* Converts big endian to little endian */
+#define FM_STORE_BE16_TO_LE16(data, value) \
+ (data = ((value & 0xFF) << 8) | ((value >> 8)))
+#define FM_BE16_TO_LE16(value) (((value & 0xFF) << 8) | ((value >> 8)))
+
+#define FM_ENABLE 1
+#define FM_DISABLE 0
+
+/* FLAG_GET register bits */
+#define FM_FR_EVENT (1 << 0)
+#define FM_BL_EVENT (1 << 1)
+#define FM_RDS_EVENT (1 << 2)
+#define FM_BBLK_EVENT (1 << 3)
+#define FM_LSYNC_EVENT (1 << 4)
+#define FM_LEV_EVENT (1 << 5)
+#define FM_IFFR_EVENT (1 << 6)
+#define FM_PI_EVENT (1 << 7)
+#define FM_PD_EVENT (1 << 8)
+#define FM_STIC_EVENT (1 << 9)
+#define FM_MAL_EVENT (1 << 10)
+#define FM_POW_ENB_EVENT (1 << 11)
+
+/*
+ * Firmware files of FM. ASIC ID and ASIC version will be appened to this,
+ * later.
+ */
+#define FM_FMC_FW_FILE_START ("fmc_ch8")
+#define FM_RX_FW_FILE_START ("fm_rx_ch8")
+#define FM_TX_FW_FILE_START ("fm_tx_ch8")
+
+#define FM_UNDEFINED_FREQ 0xFFFFFFFF
+
+/* Band types */
+#define FM_BAND_EUROPE_US 0
+#define FM_BAND_JAPAN 1
+
+/* Seek directions */
+#define FM_SEARCH_DIRECTION_DOWN 0
+#define FM_SEARCH_DIRECTION_UP 1
+
+/* Tunner modes */
+#define FM_TUNER_STOP_SEARCH_MODE 0
+#define FM_TUNER_PRESET_MODE 1
+#define FM_TUNER_AUTONOMOUS_SEARCH_MODE 2
+#define FM_TUNER_AF_JUMP_MODE 3
+
+/* Min and Max volume */
+#define FM_RX_VOLUME_MIN 0
+#define FM_RX_VOLUME_MAX 70
+
+/* Volume gain step */
+#define FM_RX_VOLUME_GAIN_STEP 0x370
+
+/* Mute modes */
+#define FM_MUTE_OFF 0
+#define FM_MUTE_ON 1
+#define FM_MUTE_ATTENUATE 2
+
+#define FM_RX_MUTE_UNMUTE_MODE 0x00
+#define FM_RX_MUTE_RF_DEP_MODE 0x01
+#define FM_RX_MUTE_AC_MUTE_MODE 0x02
+#define FM_RX_MUTE_HARD_MUTE_LEFT_MODE 0x04
+#define FM_RX_MUTE_HARD_MUTE_RIGHT_MODE 0x08
+#define FM_RX_MUTE_SOFT_MUTE_FORCE_MODE 0x10
+
+/* RF dependent mute mode */
+#define FM_RX_RF_DEPENDENT_MUTE_ON 1
+#define FM_RX_RF_DEPENDENT_MUTE_OFF 0
+
+/* RSSI threshold min and max */
+#define FM_RX_RSSI_THRESHOLD_MIN -128
+#define FM_RX_RSSI_THRESHOLD_MAX 127
+
+/* Stereo/Mono mode */
+#define FM_STEREO_MODE 0
+#define FM_MONO_MODE 1
+#define FM_STEREO_SOFT_BLEND 1
+
+/* FM RX De-emphasis filter modes */
+#define FM_RX_EMPHASIS_FILTER_50_USEC 0
+#define FM_RX_EMPHASIS_FILTER_75_USEC 1
+
+/* FM RDS modes */
+#define FM_RDS_DISABLE 0
+#define FM_RDS_ENABLE 1
+
+#define FM_NO_PI_CODE 0
+
+/* FM and RX RDS block enable/disable */
+#define FM_RX_POWER_SET_FM_ON_RDS_OFF 0x1
+#define FM_RX_POWET_SET_FM_AND_RDS_BLK_ON 0x3
+#define FM_RX_POWET_SET_FM_AND_RDS_BLK_OFF 0x0
+
+/* RX RDS */
+#define FM_RX_RDS_FLUSH_FIFO 0x1
+#define FM_RX_RDS_FIFO_THRESHOLD 64 /* tuples */
+#define FM_RDS_BLOCK_SIZE 3 /* 3 bytes */
+
+/* RDS block types */
+#define FM_RDS_BLOCK_A 0
+#define FM_RDS_BLOCK_B 1
+#define FM_RDS_BLOCK_C 2
+#define FM_RDS_BLOCK_Ctag 3
+#define FM_RDS_BLOCK_D 4
+#define FM_RDS_BLOCK_E 5
+
+#define FM_RDS_BLOCK_INDEX_A 0
+#define FM_RDS_BLOCK_INDEX_B 1
+#define FM_RDS_BLOCK_INDEX_C 2
+#define FM_RDS_BLOCK_INDEX_D 3
+#define FM_RDS_BLOCK_INDEX_UNKNOWN 0xF0
+
+#define FM_RDS_STATUS_ERROR_MASK 0x18
+
+/*
+ * Represents an RDS group type & version.
+ * There are 15 groups, each group has 2 versions: A and B.
+ */
+#define FM_RDS_GROUP_TYPE_MASK_0A ((unsigned long)1<<0)
+#define FM_RDS_GROUP_TYPE_MASK_0B ((unsigned long)1<<1)
+#define FM_RDS_GROUP_TYPE_MASK_1A ((unsigned long)1<<2)
+#define FM_RDS_GROUP_TYPE_MASK_1B ((unsigned long)1<<3)
+#define FM_RDS_GROUP_TYPE_MASK_2A ((unsigned long)1<<4)
+#define FM_RDS_GROUP_TYPE_MASK_2B ((unsigned long)1<<5)
+#define FM_RDS_GROUP_TYPE_MASK_3A ((unsigned long)1<<6)
+#define FM_RDS_GROUP_TYPE_MASK_3B ((unsigned long)1<<7)
+#define FM_RDS_GROUP_TYPE_MASK_4A ((unsigned long)1<<8)
+#define FM_RDS_GROUP_TYPE_MASK_4B ((unsigned long)1<<9)
+#define FM_RDS_GROUP_TYPE_MASK_5A ((unsigned long)1<<10)
+#define FM_RDS_GROUP_TYPE_MASK_5B ((unsigned long)1<<11)
+#define FM_RDS_GROUP_TYPE_MASK_6A ((unsigned long)1<<12)
+#define FM_RDS_GROUP_TYPE_MASK_6B ((unsigned long)1<<13)
+#define FM_RDS_GROUP_TYPE_MASK_7A ((unsigned long)1<<14)
+#define FM_RDS_GROUP_TYPE_MASK_7B ((unsigned long)1<<15)
+#define FM_RDS_GROUP_TYPE_MASK_8A ((unsigned long)1<<16)
+#define FM_RDS_GROUP_TYPE_MASK_8B ((unsigned long)1<<17)
+#define FM_RDS_GROUP_TYPE_MASK_9A ((unsigned long)1<<18)
+#define FM_RDS_GROUP_TYPE_MASK_9B ((unsigned long)1<<19)
+#define FM_RDS_GROUP_TYPE_MASK_10A ((unsigned long)1<<20)
+#define FM_RDS_GROUP_TYPE_MASK_10B ((unsigned long)1<<21)
+#define FM_RDS_GROUP_TYPE_MASK_11A ((unsigned long)1<<22)
+#define FM_RDS_GROUP_TYPE_MASK_11B ((unsigned long)1<<23)
+#define FM_RDS_GROUP_TYPE_MASK_12A ((unsigned long)1<<24)
+#define FM_RDS_GROUP_TYPE_MASK_12B ((unsigned long)1<<25)
+#define FM_RDS_GROUP_TYPE_MASK_13A ((unsigned long)1<<26)
+#define FM_RDS_GROUP_TYPE_MASK_13B ((unsigned long)1<<27)
+#define FM_RDS_GROUP_TYPE_MASK_14A ((unsigned long)1<<28)
+#define FM_RDS_GROUP_TYPE_MASK_14B ((unsigned long)1<<29)
+#define FM_RDS_GROUP_TYPE_MASK_15A ((unsigned long)1<<30)
+#define FM_RDS_GROUP_TYPE_MASK_15B ((unsigned long)1<<31)
+
+/* RX Alternate Frequency info */
+#define FM_RDS_MIN_AF 1
+#define FM_RDS_MAX_AF 204
+#define FM_RDS_MAX_AF_JAPAN 140
+#define FM_RDS_1_AF_FOLLOWS 225
+#define FM_RDS_25_AF_FOLLOWS 249
+
+/* RDS system type (RDS/RBDS) */
+#define FM_RDS_SYSTEM_RDS 0
+#define FM_RDS_SYSTEM_RBDS 1
+
+/* AF on/off */
+#define FM_RX_RDS_AF_SWITCH_MODE_ON 1
+#define FM_RX_RDS_AF_SWITCH_MODE_OFF 0
+
+/* Retry count when interrupt process goes wrong */
+#define FM_IRQ_TIMEOUT_RETRY_MAX 5 /* 5 times */
+
+/* Audio IO set values */
+#define FM_RX_FM_AUDIO_ENABLE_I2S 0x01
+#define FM_RX_FM_AUDIO_ENABLE_ANALOG 0x02
+#define FM_RX_FM_AUDIO_ENABLE_I2S_AND_ANALOG 0x03
+#define FM_RX_FM_AUDIO_ENABLE_DISABLE 0x00
+
+/* HI/LO set values */
+#define FM_RX_IFFREQ_TO_HI_SIDE 0x0
+#define FM_RX_IFFREQ_TO_LO_SIDE 0x1
+#define FM_RX_IFFREQ_HILO_AUTOMATIC 0x2
+
+/*
+ * Default RX mode configuration. Chip will be configured
+ * with this default values after loading RX firmware.
+ */
+#define FM_DEFAULT_RX_VOLUME 10
+#define FM_DEFAULT_RSSI_THRESHOLD 3
+
+/* Range for TX power level in units for dB/uV */
+#define FM_PWR_LVL_LOW 91
+#define FM_PWR_LVL_HIGH 122
+
+/* Chip specific default TX power level value */
+#define FM_PWR_LVL_DEF 4
+
+/* FM TX Pre-emphasis filter values */
+#define FM_TX_PREEMPH_OFF 1
+#define FM_TX_PREEMPH_50US 0
+#define FM_TX_PREEMPH_75US 2
+
+/* FM TX antenna impedence values */
+#define FM_TX_ANT_IMP_50 0
+#define FM_TX_ANT_IMP_200 1
+#define FM_TX_ANT_IMP_500 2
+
+/* Functions exported by FM common sub-module */
+int fmc_prepare(struct fmdrv_ops *);
+int fmc_release(struct fmdrv_ops *);
+
+void fmc_update_region_info(struct fmdrv_ops *, unsigned char);
+int fmc_send_cmd(struct fmdrv_ops *, unsigned char, void *, int,
+ struct completion *, void *, int *);
+int fmc_is_rds_data_available(struct fmdrv_ops *, struct file *,
+ struct poll_table_struct *);
+int fmc_transfer_rds_from_internal_buff(struct fmdrv_ops *, struct file *,
+ char __user *, size_t);
+
+int fmc_set_frequency(struct fmdrv_ops *, unsigned int);
+int fmc_set_mode(struct fmdrv_ops *, unsigned char);
+int fmc_set_region(struct fmdrv_ops *, unsigned char);
+int fmc_set_mute_mode(struct fmdrv_ops *, unsigned char);
+int fmc_set_stereo_mono(struct fmdrv_ops *, unsigned short);
+int fmc_set_rds_mode(struct fmdrv_ops *, unsigned char);
+
+int fmc_get_frequency(struct fmdrv_ops *, unsigned int *);
+int fmc_get_region(struct fmdrv_ops *, unsigned char *);
+int fmc_get_mode(struct fmdrv_ops *, unsigned char *);
+
+/*
+ * channel spacing
+ */
+#define FM_CHANNEL_SPACING_50KHZ 1
+#define FM_CHANNEL_SPACING_100KHZ 2
+#define FM_CHANNEL_SPACING_200KHZ 4
+#define FM_FREQ_MUL 50
+
+#endif
+
--
1.5.6.3

2010-11-16 12:57:12

by halli manjunatha

[permalink] [raw]
Subject: [PATCH v4 6/6] drivers:staging: ti-st: Kconfig & Makefile change

From: Manjunatha Halli <[email protected]>

Add new menu option in Kconfig and compilation option in Makefile
for TI FM driver.

Signed-off-by: Manjunatha Halli <[email protected]>
---
drivers/staging/ti-st/Kconfig | 10 ++++++++++
drivers/staging/ti-st/Makefile | 2 ++
2 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/drivers/staging/ti-st/Kconfig b/drivers/staging/ti-st/Kconfig
index 074b8e8..43b6dea 100644
--- a/drivers/staging/ti-st/Kconfig
+++ b/drivers/staging/ti-st/Kconfig
@@ -11,4 +11,14 @@ config ST_BT
This enables the Bluetooth driver for TI BT/FM/GPS combo devices.
This makes use of shared transport line discipline core driver to
communicate with the BT core of the combo chip.
+
+config ST_FM
+ tristate "fm driver for ST"
+ depends on VIDEO_DEV && RFKILL
+ select TI_ST
+ help
+ This enables the FM driver for TI BT/FM/GPS combo devices.
+ This makes use of shared transport line discipline core driver to
+ communicate with the FM core of the combo chip.
+
endmenu
diff --git a/drivers/staging/ti-st/Makefile b/drivers/staging/ti-st/Makefile
index 5f11b82..330f95b 100644
--- a/drivers/staging/ti-st/Makefile
+++ b/drivers/staging/ti-st/Makefile
@@ -3,3 +3,5 @@
# and its protocol drivers (BT, FM, GPS)
#
obj-$(CONFIG_ST_BT) += bt_drv.o
+obj-$(CONFIG_ST_FM) += fm_drv.o
+fm_drv-objs := fmdrv_common.o fmdrv_rx.o fmdrv_tx.o fmdrv_v4l2.o
--
1.5.6.3

2010-11-16 12:56:57

by halli manjunatha

[permalink] [raw]
Subject: [PATCH v4 1/6] drivers:staging: ti-st: fmdrv common header file

From: Manjunatha Halli <[email protected]>

These are common headers used in FM submodules (FM V4L2, FM common,
FM Rx,and FM TX).

Signed-off-by: Manjunatha Halli <[email protected]>
---
drivers/staging/ti-st/fmdrv.h | 259 +++++++++++++++++++++++++++++++++++++++++
1 files changed, 259 insertions(+), 0 deletions(-)
create mode 100644 drivers/staging/ti-st/fmdrv.h

diff --git a/drivers/staging/ti-st/fmdrv.h b/drivers/staging/ti-st/fmdrv.h
new file mode 100644
index 0000000..68ed44c
--- /dev/null
+++ b/drivers/staging/ti-st/fmdrv.h
@@ -0,0 +1,259 @@
+/*
+ * FM Driver for Connectivity chip of Texas Instruments.
+ *
+ * Common header for all FM driver sub-modules.
+ *
+ * Copyright (C) 2009 Texas Instruments
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#ifndef _FM_DRV_H
+#define _FM_DRV_H
+
+#include <linux/skbuff.h>
+#include <linux/interrupt.h>
+#include <sound/core.h>
+#include <sound/initval.h>
+#include <linux/timer.h>
+#include <linux/version.h>
+
+#define FM_DRV_VERSION "0.01"
+/* Should match with FM_DRV_VERSION */
+#define FM_DRV_RADIO_VERSION KERNEL_VERSION(0, 0, 1)
+#define FM_DRV_NAME "ti_fmdrv"
+#define FM_DRV_CARD_SHORT_NAME "TI FM Radio"
+#define FM_DRV_CARD_LONG_NAME "Texas Instruments FM Radio"
+
+/* Flag info */
+#define FM_INTTASK_RUNNING 0
+#define FM_INTTASK_SCHEDULE_PENDING 1
+#define FM_FIRMWARE_DW_INPROGRESS 2
+#define FM_CORE_READY 3
+#define FM_CORE_TRANSPORT_READY 4
+#define FM_AF_SWITCH_INPROGRESS 5
+#define FM_CORE_TX_XMITING 6
+
+#define FM_TUNE_COMPLETE 0x1
+#define FM_BAND_LIMIT 0x2
+
+#define FM_DRV_TX_TIMEOUT (5*HZ) /* 5 seconds */
+#define FM_DRV_RX_SEEK_TIMEOUT (20*HZ) /* 20 seconds */
+
+#define NO_OF_ENTRIES_IN_ARRAY(array) (sizeof(array) / sizeof(array[0]))
+
+enum {
+ FM_MODE_OFF,
+ FM_MODE_TX,
+ FM_MODE_RX,
+ FM_MODE_ENTRY_MAX
+};
+
+#define FM_RX_RDS_INFO_FIELD_MAX 8 /* 4 Group * 2 Bytes */
+
+/* TODO:
+ * move the following CIDs to videodev2.h upon acceptance
+ */
+#define V4L2_CTRL_CLASS_FM_RX 0x009c0000 /* FM Tuner control class */
+/* FM Tuner class control IDs */
+#define V4L2_CID_FM_RX_CLASS_BASE (V4L2_CTRL_CLASS_FM_RX | 0x900)
+#define V4L2_CID_FM_RX_CLASS (V4L2_CTRL_CLASS_FM_RX | 1)
+#define V4L2_CID_RSSI_THRESHOLD (V4L2_CID_FM_RX_CLASS_BASE + 2)
+#define V4L2_CID_TUNE_AF (V4L2_CID_FM_RX_CLASS_BASE + 3)
+enum v4l2_tune_af {
+ V4L2_FM_AF_OFF = 0,
+ V4L2_FM_AF_ON = 1
+};
+#define V4L2_CID_FM_BAND (V4L2_CID_FM_RX_CLASS_BASE + 1)
+enum v4l2_fm_band {
+ V4L2_FM_BAND_OTHER = 0,
+ V4L2_FM_BAND_JAPAN = 1,
+ V4L2_FM_BAND_OIRT = 2
+};
+
+/*
+ * define private CIDs for V4L2
+ */
+#define V4L2_CID_CHANNEL_SPACING (V4L2_CID_PRIVATE_BASE + 0)
+
+/* RX RDS data format */
+struct fm_rdsdata_format {
+ union {
+ struct {
+ unsigned char rdsbuff[FM_RX_RDS_INFO_FIELD_MAX];
+ } groupdatabuff;
+ struct {
+ unsigned short pidata;
+ unsigned char block_b_byte1;
+ unsigned char block_b_byte2;
+ unsigned char block_c_byte1;
+ unsigned char block_c_byte2;
+ unsigned char block_d_byte1;
+ unsigned char block_d_byte2;
+ } groupgeneral;
+ struct {
+ unsigned short pidata;
+ unsigned char block_b_byte1;
+ unsigned char block_b_byte2;
+ unsigned char firstaf;
+ unsigned char secondaf;
+ unsigned char firstpsbyte;
+ unsigned char secondpsbyte;
+ } group0A;
+
+ struct {
+ unsigned short pidata;
+ unsigned char block_b_byte1;
+ unsigned char block_b_byte2;
+ unsigned short pidata2;
+ unsigned char firstpsbyte;
+ unsigned char secondpsbyte;
+ } group0B;
+ } rdsdata;
+};
+
+/* FM region (Europe/US, Japan) info */
+struct region_info {
+ unsigned int channel_spacing;
+ unsigned int bottom_frequency;
+ unsigned int top_frequency;
+ unsigned char region_index;
+};
+
+typedef void (*int_handler_prototype) (void *);
+
+/* FM Interrupt processing related info */
+struct fm_irq {
+ unsigned char stage_index;
+ unsigned short flag; /* FM interrupt flag */
+ unsigned short mask; /* FM interrupt mask */
+ /* Interrupt process timeout handler */
+ struct timer_list int_timeout_timer;
+ unsigned char irq_service_timeout_retry;
+ int_handler_prototype *fm_int_handlers;
+};
+
+/* RDS info */
+struct fm_rds {
+ unsigned char flag; /* RX RDS on/off status */
+ unsigned char last_block_index; /* Last received RDS block */
+
+ /* RDS buffer */
+ wait_queue_head_t read_queue;
+ unsigned int buf_size; /* Size is always multiple of 3 */
+ unsigned int wr_index;
+ unsigned int rd_index;
+ unsigned char *buffer;
+};
+
+#define FM_RDS_MAX_AF_LIST 25
+
+/*
+ * Current RX channel Alternate Frequency cache.
+ * This info is used to switch to other freq (AF)
+ * when current channel signal strengh is below RSSI threshold.
+ */
+struct tuned_station_info {
+ unsigned short picode;
+ unsigned int af_cache[FM_RDS_MAX_AF_LIST];
+ unsigned char no_of_items_in_afcache;
+ unsigned char af_list_max;
+};
+
+/* FM RX mode info */
+struct fm_rx {
+ struct region_info region; /* Current selected band */
+ unsigned int curr_freq; /* Current RX frquency */
+ unsigned char curr_mute_mode; /* Current mute mode */
+ unsigned char curr_deemphasis_mode; /* Current deemphasis mode */
+ /* RF dependent soft mute mode */
+ unsigned char curr_rf_depend_mute;
+ unsigned short curr_volume; /* Current volume level */
+ short curr_rssi_threshold; /* Current RSSI threshold level */
+ /* Holds the index of the current AF jump */
+ unsigned char cur_afjump_index;
+ /* Will hold the frequency before the jump */
+ unsigned int freq_before_jump;
+ unsigned char rds_mode; /* RDS operation mode (RDS/RDBS) */
+ unsigned char af_mode; /* Alternate frequency on/off */
+ struct tuned_station_info cur_station_info;
+ struct fm_rds rds;
+};
+
+/*
+ * FM TX RDS data
+ *
+ * @ text_type: is the text following PS or RT
+ * @ text: radio text string which could either be PS or RT
+ * @ af_freq: alternate frequency for Tx
+ * TODO: to be declared in application
+ */
+struct tx_rds {
+ unsigned char text_type;
+ unsigned char text[25];
+ unsigned char flag;
+ unsigned int af_freq;
+};
+/*
+ * FM TX global data
+ *
+ * @ pwr_lvl: Power Level of the Transmission from mixer control
+ * @ xmit_state: Transmission state = Updated locally upon Start/Stop
+ * @ audio_io: i2S/Analog
+ * @ tx_frq: Transmission frequency
+ */
+struct fmtx_data {
+ unsigned char pwr_lvl;
+ unsigned char xmit_state;
+ unsigned char audio_io;
+ unsigned char region;
+ unsigned short aud_mode;
+ unsigned int preemph;
+ unsigned long tx_frq;
+ struct tx_rds rds;
+};
+
+/* FM driver operation structure */
+struct fmdrv_ops {
+ struct video_device *radio_dev; /* V4L2 video device pointer */
+ struct snd_card *card; /* Card which holds FM mixer controls */
+ unsigned short asci_id;
+ spinlock_t rds_buff_lock; /* To protect access to RDS buffer */
+ spinlock_t resp_skb_lock; /* To protect access to received SKB */
+
+ long flag; /* FM driver state machine info */
+ char streg_cbdata; /* status of ST registration */
+
+ struct sk_buff_head rx_q; /* RX queue */
+ struct tasklet_struct rx_task; /* RX Tasklet */
+
+ struct sk_buff_head tx_q; /* TX queue */
+ struct tasklet_struct tx_task; /* TX Tasklet */
+ unsigned long last_tx_jiffies; /* Timestamp of last pkt sent */
+ atomic_t tx_cnt; /* Number of packets can send at a time */
+
+ struct sk_buff *response_skb; /* Response from the chip */
+ /* Main task completion handler */
+ struct completion maintask_completion;
+ /* Opcode of last command sent to the chip */
+ unsigned char last_sent_pkt_opcode;
+ /* Handler used for wakeup when response packet is received */
+ struct completion *response_completion;
+ struct fm_irq irq_info;
+ unsigned char curr_fmmode; /* Current FM chip mode (TX, RX, OFF) */
+ struct fm_rx rx; /* FM receiver info */
+ struct fmtx_data tx_data;
+};
+#endif
--
1.5.6.3

2010-11-16 12:57:52

by halli manjunatha

[permalink] [raw]
Subject: [PATCH v4 4/6] drivers:staging: ti-st: fmdrv_rx sources

From: Manjunatha Halli <[email protected]>

This has implementation for FM RX functionality.
It communicates with FM V4l2 module and FM common module.

Signed-off-by: Manjunatha Halli <[email protected]>
---
drivers/staging/ti-st/fmdrv_rx.c | 979 ++++++++++++++++++++++++++++++++++++++
drivers/staging/ti-st/fmdrv_rx.h | 59 +++
2 files changed, 1038 insertions(+), 0 deletions(-)
create mode 100644 drivers/staging/ti-st/fmdrv_rx.c
create mode 100644 drivers/staging/ti-st/fmdrv_rx.h

diff --git a/drivers/staging/ti-st/fmdrv_rx.c b/drivers/staging/ti-st/fmdrv_rx.c
new file mode 100644
index 0000000..5f802da
--- /dev/null
+++ b/drivers/staging/ti-st/fmdrv_rx.c
@@ -0,0 +1,979 @@
+/*
+ * FM Driver for Connectivity chip of Texas Instruments.
+ * This sub-module of FM driver implements FM RX functionality.
+ *
+ * Copyright (C) 2010 Texas Instruments
+ * Author: Raja Mani <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include "fmdrv.h"
+#include "fmdrv_common.h"
+#include "fmdrv_rx.h"
+
+void fm_rx_reset_rds_cache(struct fmdrv_ops *fmdev)
+{
+ fmdev->rx.rds.flag = FM_RDS_DISABLE;
+ fmdev->rx.rds.last_block_index = 0;
+ fmdev->rx.rds.wr_index = 0;
+ fmdev->rx.rds.rd_index = 0;
+
+ if (fmdev->rx.af_mode == FM_RX_RDS_AF_SWITCH_MODE_ON)
+ fmdev->irq_info.mask |= FM_LEV_EVENT;
+}
+
+void fm_rx_reset_curr_station_info(struct fmdrv_ops *fmdev)
+{
+ fmdev->rx.cur_station_info.picode = FM_NO_PI_CODE;
+ fmdev->rx.cur_station_info.no_of_items_in_afcache = 0;
+ fmdev->rx.cur_station_info.af_list_max = 0;
+}
+
+int fm_rx_set_frequency(struct fmdrv_ops *fmdev, unsigned int freq_to_set)
+{
+ unsigned long timeleft;
+ unsigned short payload, curr_frq, frq_index;
+ unsigned int curr_frq_in_khz;
+ int ret, resp_len;
+
+ if (fmdev->curr_fmmode != FM_MODE_RX)
+ return -EPERM;
+
+ if (freq_to_set < fmdev->rx.region.bottom_frequency ||
+ freq_to_set > fmdev->rx.region.top_frequency) {
+ pr_err("(fmdrv): Invalid frequency %d\n", freq_to_set);
+ return -EINVAL;
+ }
+
+ /* Set audio enable */
+ FM_STORE_LE16_TO_BE16(payload, FM_RX_FM_AUDIO_ENABLE_I2S_AND_ANALOG);
+ ret = fmc_send_cmd(fmdev, AUDIO_ENABLE_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set RX audio enable path - %d\n",
+ ret);
+ return ret;
+ }
+
+ /* Set hilo to automatic selection */
+ FM_STORE_LE16_TO_BE16(payload, FM_RX_IFFREQ_HILO_AUTOMATIC);
+ ret = fmc_send_cmd(fmdev, HILO_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set HILO to automatic selection "
+ "- %d\n", ret);
+ return ret;
+ }
+
+ /* Calculate frequency index to write */
+ frq_index = (freq_to_set - fmdev->rx.region.bottom_frequency) /
+ FM_FREQ_MUL;
+
+ /* Set frequency index */
+ FM_STORE_LE16_TO_BE16(payload, frq_index);
+ ret = fmc_send_cmd(fmdev, FREQ_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set frequency index - %d\n", ret);
+ return ret;
+ }
+
+ /* Read flags - just to clear any pending interrupts if we had */
+ ret = fmc_send_cmd(fmdev, FLAG_GET, NULL, 2,
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to read interrupt flag - %d\n", ret);
+ return ret;
+ }
+
+ /* Enable FR, BL interrupts */
+ fmdev->irq_info.mask |= (FM_FR_EVENT | FM_BL_EVENT);
+ FM_STORE_LE16_TO_BE16(payload, fmdev->irq_info.mask);
+ ret = fmc_send_cmd(fmdev, INT_MASK_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set interrupt mask - %d\n", ret);
+ return ret;
+ }
+
+ /* Start tune */
+ FM_STORE_LE16_TO_BE16(payload, FM_TUNER_PRESET_MODE);
+ ret = fmc_send_cmd(fmdev, TUNER_MODE_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to start tune operation - %d\n", ret);
+ return ret;
+ }
+
+ /* Wait for tune ended interrupt */
+ init_completion(&fmdev->maintask_completion);
+ timeleft = wait_for_completion_timeout(&fmdev->maintask_completion,
+ FM_DRV_TX_TIMEOUT);
+ if (!timeleft) {
+ pr_err("(fmdrv): Timeout(%d sec),didn't get tune ended int\n",
+ jiffies_to_msecs(FM_DRV_TX_TIMEOUT) / 1000);
+ return -ETIMEDOUT;
+ }
+
+ /* Read freq back to confirm */
+ ret = fmc_send_cmd(fmdev, FREQ_GET, NULL, 2,
+ &fmdev->maintask_completion, &curr_frq, &resp_len);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to read current frequency - %d\n",
+ ret);
+ return ret;
+ }
+
+ curr_frq = FM_BE16_TO_LE16(curr_frq);
+ curr_frq_in_khz = (fmdev->rx.region.bottom_frequency
+ + ((unsigned int)curr_frq * FM_FREQ_MUL));
+
+ /* Re-enable default FM interrupts */
+ fmdev->irq_info.mask &= ~(FM_FR_EVENT | FM_BL_EVENT);
+ FM_STORE_LE16_TO_BE16(payload, fmdev->irq_info.mask);
+ ret = fmc_send_cmd(fmdev, INT_MASK_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set interrupt mask - %d\n", ret);
+ return ret;
+ }
+
+ if (curr_frq_in_khz != freq_to_set) {
+ pr_info("(fmdrv): Frequency is set to (%d) but"
+ " requested frequency is (%d)\n", curr_frq_in_khz,
+ freq_to_set);
+ }
+
+ /* Update local cache */
+ fmdev->rx.curr_freq = curr_frq_in_khz;
+
+ /* Reset RDS cache and current station pointers */
+ fm_rx_reset_rds_cache(fmdev);
+ fm_rx_reset_curr_station_info(fmdev);
+
+ /* Do we need to reset anything else? */
+
+ return ret;
+}
+
+int fm_rx_seek(struct fmdrv_ops *fmdev, unsigned int seek_upward,
+ unsigned int wrap_around)
+{
+ int resp_len;
+ unsigned short curr_frq, next_frq, last_frq;
+ unsigned short payload, int_reason;
+ char offset, spacing;
+ unsigned long timeleft;
+ int ret;
+
+ if (fmdev->curr_fmmode != FM_MODE_RX)
+ return -EPERM;
+
+ /* Read the current frequency from chip */
+ ret = fmc_send_cmd(fmdev, FREQ_GET, NULL, sizeof(curr_frq),
+ &fmdev->maintask_completion, &curr_frq, &resp_len);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to read current frequency - %d\n",
+ ret);
+ return ret;
+ }
+
+ curr_frq = FM_BE16_TO_LE16(curr_frq);
+ last_frq = (fmdev->rx.region.top_frequency -
+ fmdev->rx.region.bottom_frequency) / FM_FREQ_MUL;
+
+ /* Check the offset in order to be aligned to the channel spacing*/
+ spacing = fmdev->rx.region.channel_spacing / FM_FREQ_MUL;
+ offset = curr_frq % spacing;
+
+ next_frq = seek_upward ? curr_frq + spacing /* Seek Up */ :
+ curr_frq - spacing /* Seek Down */ ;
+
+ /*
+ * Add or subtract offset in order to stay aligned to the channel
+ * spacing.
+ */
+ if ((short)next_frq < 0)
+ next_frq = last_frq - offset;
+ else if (next_frq > last_frq)
+ next_frq = 0 + offset;
+
+again:
+ /* Set calculated next frequency to perform seek */
+ FM_STORE_LE16_TO_BE16(payload, next_frq);
+ ret = fmc_send_cmd(fmdev, FREQ_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set new frequency - %d\n", ret);
+ return ret;
+ }
+
+ /* Set search direction (0:Seek Down, 1:Seek Up) */
+ FM_STORE_LE16_TO_BE16(payload, (seek_upward ? FM_SEARCH_DIRECTION_UP :
+ FM_SEARCH_DIRECTION_DOWN));
+ ret = fmc_send_cmd(fmdev, SEARCH_DIR_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set seek direction - %d\n", ret);
+ return ret;
+ }
+
+ /* Read flags - just to clear any pending interrupts if we had */
+ ret = fmc_send_cmd(fmdev, FLAG_GET, NULL, 2,
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to read interrupt flag - %d\n", ret);
+ return ret;
+ }
+
+ /* Enable FR, BL interrupts */
+ fmdev->irq_info.mask |= (FM_FR_EVENT | FM_BL_EVENT);
+ FM_STORE_LE16_TO_BE16(payload, fmdev->irq_info.mask);
+ ret = fmc_send_cmd(fmdev, INT_MASK_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set interrupt mask - %d\n", ret);
+ return ret;
+ }
+
+ /* Start seek */
+ FM_STORE_LE16_TO_BE16(payload, FM_TUNER_AUTONOMOUS_SEARCH_MODE);
+ ret = fmc_send_cmd(fmdev, TUNER_MODE_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to start seek operation - %d\n", ret);
+ return ret;
+ }
+
+ /* Wait for tune ended/band limit reached interrupt */
+ init_completion(&fmdev->maintask_completion);
+ timeleft = wait_for_completion_timeout(&fmdev->maintask_completion,
+ FM_DRV_RX_SEEK_TIMEOUT);
+ if (!timeleft) {
+ pr_err("(fmdrv): Timeout(%d sec),didn't get tune ended int\n",
+ jiffies_to_msecs(FM_DRV_RX_SEEK_TIMEOUT) / 1000);
+ return -ETIMEDOUT;
+ }
+
+ int_reason = fmdev->irq_info.flag & (FM_TUNE_COMPLETE | FM_BAND_LIMIT);
+
+ /* Re-enable default FM interrupts */
+ fmdev->irq_info.mask &= ~(FM_FR_EVENT | FM_BL_EVENT);
+ FM_STORE_LE16_TO_BE16(payload, fmdev->irq_info.mask);
+ ret = fmc_send_cmd(fmdev, INT_MASK_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set interrupt mask - %d\n", ret);
+ return ret;
+ }
+
+ /* Read freq to know where operation tune operation stopped */
+ ret = fmc_send_cmd(fmdev, FREQ_GET, NULL, 2,
+ &fmdev->maintask_completion, &curr_frq, &resp_len);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to read current frequency - %d\n",
+ ret);
+ return ret;
+ }
+
+ curr_frq = FM_BE16_TO_LE16(curr_frq);
+ fmdev->rx.curr_freq = (fmdev->rx.region.bottom_frequency +
+ ((unsigned int)curr_frq * FM_FREQ_MUL));
+
+ /* Reset RDS cache and current station pointers */
+ fm_rx_reset_rds_cache(fmdev);
+ fm_rx_reset_curr_station_info(fmdev);
+
+ /* Return error if band limit is reached */
+ if (int_reason & FM_BL_EVENT) {
+ if (!wrap_around) {
+ ret = fmdev->rx.region.top_frequency;
+ } else {
+ next_frq = 1;
+ goto again;
+ }
+ }
+
+ return ret;
+}
+
+int fm_rx_set_volume(struct fmdrv_ops *fmdev, unsigned short vol_to_set)
+{
+ unsigned short payload;
+ int ret;
+
+ if (fmdev->curr_fmmode != FM_MODE_RX)
+ return -EPERM;
+
+ if (vol_to_set < FM_RX_VOLUME_MIN || vol_to_set > FM_RX_VOLUME_MAX) {
+ pr_err("(fmdrv): Volume is not within(%d-%d) range\n",
+ FM_RX_VOLUME_MIN, FM_RX_VOLUME_MAX);
+ return -EINVAL;
+ }
+ vol_to_set *= FM_RX_VOLUME_GAIN_STEP;
+
+ FM_STORE_LE16_TO_BE16(payload, vol_to_set);
+ ret = fmc_send_cmd(fmdev, VOLUME_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set RX volume level - %d\n", ret);
+ return ret;
+ }
+
+ fmdev->rx.curr_volume = vol_to_set;
+ return ret;
+}
+
+/* Get volume */
+int fm_rx_get_volume(struct fmdrv_ops *fmdev, unsigned short *curr_vol)
+{
+ if (fmdev->curr_fmmode != FM_MODE_RX)
+ return -EPERM;
+
+ if (curr_vol == NULL) {
+ pr_err("(fmdrv): Invalid memory\n");
+ return -ENOMEM;
+ }
+
+ *curr_vol = fmdev->rx.curr_volume / FM_RX_VOLUME_GAIN_STEP;
+
+ return 0;
+}
+
+/* To get current band's bottom and top frequency */
+int fm_rx_get_currband_freq_range(struct fmdrv_ops *fmdev,
+ unsigned int *bottom_frequency,
+ unsigned int *top_frequency)
+{
+ if (bottom_frequency != NULL)
+ *bottom_frequency = fmdev->rx.region.bottom_frequency;
+
+ if (top_frequency != NULL)
+ *top_frequency = fmdev->rx.region.top_frequency;
+
+ return 0;
+}
+
+/* Returns current band index (0-Europe/US; 1-Japan) */
+void fm_rx_get_region(struct fmdrv_ops *fmdev, unsigned char *region)
+{
+ *region = fmdev->rx.region.region_index;
+}
+
+/* Sets band (0-Europe/US; 1-Japan) */
+int fm_rx_set_region(struct fmdrv_ops *fmdev,
+ unsigned char region_to_set)
+{
+ unsigned short payload;
+ unsigned int new_frq = 0;
+ int ret = -EPERM;
+
+ if (fmdev->curr_fmmode != FM_MODE_RX)
+ return ret;
+
+ if (region_to_set != FM_BAND_EUROPE_US &&
+ region_to_set != FM_BAND_JAPAN) {
+ pr_err("(fmdrv): Invalid band\n");
+ return -EINVAL;
+ }
+
+ if (fmdev->rx.region.region_index == region_to_set) {
+ pr_err("(fmdrv): Requested band is already configured\n");
+ return ret;
+ }
+
+ /* Send cmd to set the band */
+ FM_STORE_LE16_TO_BE16(payload, (unsigned short)region_to_set);
+ ret = fmc_send_cmd(fmdev, RX_BAND_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set FM RX band - %d\n", ret);
+ return ret;
+ }
+
+ fmc_update_region_info(fmdev, region_to_set);
+
+ /* Check whether current RX frequency is within band boundary */
+ if (fmdev->rx.curr_freq < fmdev->rx.region.bottom_frequency)
+ new_frq = fmdev->rx.region.bottom_frequency;
+ else if (fmdev->rx.curr_freq > fmdev->rx.region.top_frequency)
+ new_frq = fmdev->rx.region.top_frequency;
+
+ if (new_frq) {
+ pr_debug("(fmdrv): "
+ "Current freq is not within band limit boundary,"
+ "switching to %d KHz\n", new_frq);
+ /*
+ * Current RX frequency is not within boundary. So,
+ * update it.
+ */
+ ret = fm_rx_set_frequency(fmdev, new_frq);
+ }
+
+ return ret;
+}
+
+/* Reads current mute mode (Mute Off/On/Attenuate)*/
+int fm_rx_get_mute_mode(struct fmdrv_ops *fmdev,
+ unsigned char *curr_mute_mode)
+{
+ if (fmdev->curr_fmmode != FM_MODE_RX)
+ return -EPERM;
+
+ if (curr_mute_mode == NULL) {
+ pr_err("(fmdrv): Invalid memory\n");
+ return -ENOMEM;
+ }
+
+ *curr_mute_mode = fmdev->rx.curr_mute_mode;
+
+ return 0;
+}
+
+static int __fm_config_rx_mute_reg(struct fmdrv_ops *fmdev)
+{
+ unsigned short payload, muteval;
+ int ret;
+
+ muteval = 0;
+ switch (fmdev->rx.curr_mute_mode) {
+ case FM_MUTE_ON:
+ muteval = FM_RX_MUTE_AC_MUTE_MODE;
+ break;
+
+ case FM_MUTE_OFF:
+ muteval = FM_RX_MUTE_UNMUTE_MODE;
+ break;
+
+ case FM_MUTE_ATTENUATE:
+ muteval = FM_RX_MUTE_SOFT_MUTE_FORCE_MODE;
+ break;
+ }
+ if (fmdev->rx.curr_rf_depend_mute == FM_RX_RF_DEPENDENT_MUTE_ON)
+ muteval |= FM_RX_MUTE_RF_DEP_MODE;
+ else
+ muteval &= ~FM_RX_MUTE_RF_DEP_MODE;
+
+ FM_STORE_LE16_TO_BE16(payload, muteval);
+ ret = fmc_send_cmd(fmdev, MUTE_STATUS_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set RX mute state - %d\n", ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+/* Configures mute mode (Mute Off/On/Attenuate) */
+int fm_rx_set_mute_mode(struct fmdrv_ops *fmdev,
+ unsigned char mute_mode_toset)
+{
+ unsigned char org_state;
+ int ret;
+
+ if (fmdev->curr_fmmode != FM_MODE_RX)
+ return -EPERM;
+
+ if (fmdev->rx.curr_mute_mode == mute_mode_toset)
+ return 0;
+
+ org_state = fmdev->rx.curr_mute_mode;
+ fmdev->rx.curr_mute_mode = mute_mode_toset;
+
+ ret = __fm_config_rx_mute_reg(fmdev);
+ if (ret < 0) {
+ fmdev->rx.curr_mute_mode = org_state;
+ return ret;
+ }
+
+ return 0;
+}
+
+/* Gets RF dependent soft mute mode enable/disable status */
+int fm_rx_get_rfdepend_softmute(struct fmdrv_ops *fmdev,
+ unsigned char *curr_mute_mode)
+{
+ if (fmdev->curr_fmmode != FM_MODE_RX)
+ return -EPERM;
+
+ if (curr_mute_mode == NULL) {
+ pr_err("(fmdrv): Invalid memory\n");
+ return -ENOMEM;
+ }
+
+ *curr_mute_mode = fmdev->rx.curr_rf_depend_mute;
+
+ return 0;
+}
+
+/* Sets RF dependent soft mute mode */
+int fm_rx_set_rfdepend_softmute(struct fmdrv_ops *fmdev,
+ unsigned char rfdepend_mute)
+{
+ unsigned char org_state;
+ int ret;
+
+ if (fmdev->curr_fmmode != FM_MODE_RX)
+ return -EPERM;
+
+ if (rfdepend_mute != FM_RX_RF_DEPENDENT_MUTE_ON &&
+ rfdepend_mute != FM_RX_RF_DEPENDENT_MUTE_OFF) {
+ pr_err("(fmdrv): Invalid RF dependent soft mute\n");
+ return -EINVAL;
+ }
+ if (fmdev->rx.curr_rf_depend_mute == rfdepend_mute)
+ return 0;
+
+ org_state = fmdev->rx.curr_rf_depend_mute;
+ fmdev->rx.curr_rf_depend_mute = rfdepend_mute;
+
+ ret = __fm_config_rx_mute_reg(fmdev);
+ if (ret < 0) {
+ fmdev->rx.curr_rf_depend_mute = org_state;
+ return ret;
+ }
+
+ return 0;
+}
+
+/* Returns the signal strength level of current channel */
+int fm_rx_get_rssi_level(struct fmdrv_ops *fmdev,
+ unsigned short *rssilvl)
+{
+ unsigned short curr_rssi_lel;
+ int resp_len;
+ int ret;
+
+ if (fmdev->curr_fmmode != FM_MODE_RX)
+ return -EPERM;
+
+ if (rssilvl == NULL) {
+ pr_err("(fmdrv): Invalid memory\n");
+ return -ENOMEM;
+ }
+ /* Read current RSSI level */
+ ret = fmc_send_cmd(fmdev, RSSI_LVL_GET, NULL, 2,
+ &fmdev->maintask_completion, &curr_rssi_lel, &resp_len);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to get RSSI level - %d\n", ret);
+ return ret;
+ }
+
+ *rssilvl = FM_BE16_TO_LE16(curr_rssi_lel);
+
+ return 0;
+}
+
+/*
+ * Sets the signal strength level that once reached
+ * will stop the auto search process
+ */
+int fm_rx_set_rssi_threshold(struct fmdrv_ops *fmdev,
+ short rssi_lvl_toset)
+{
+ unsigned short payload;
+ int ret;
+
+ if (fmdev->curr_fmmode != FM_MODE_RX)
+ return -EPERM;
+
+ if (rssi_lvl_toset < FM_RX_RSSI_THRESHOLD_MIN ||
+ rssi_lvl_toset > FM_RX_RSSI_THRESHOLD_MAX) {
+ pr_err("(fmdrv): Invalid RSSI threshold level\n");
+ return -EINVAL;
+ }
+ FM_STORE_LE16_TO_BE16(payload, (unsigned short)rssi_lvl_toset);
+ ret = fmc_send_cmd(fmdev, SEARCH_LVL_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set RSSI level - %d\n", ret);
+ return ret;
+ }
+
+ fmdev->rx.curr_rssi_threshold = rssi_lvl_toset;
+ return 0;
+}
+
+/* Returns current RX RSSI threshold value */
+int fm_rx_get_rssi_threshold(struct fmdrv_ops *fmdev, short *curr_rssi_lvl)
+{
+ if (fmdev->curr_fmmode != FM_MODE_RX)
+ return -EPERM;
+
+ if (curr_rssi_lvl == NULL) {
+ pr_err("(fmdrv): Invalid memory\n");
+ return -ENOMEM;
+ }
+
+ *curr_rssi_lvl = fmdev->rx.curr_rssi_threshold;
+
+ return 0;
+}
+
+/* Sets RX stereo/mono modes */
+int fm_rx_set_stereo_mono(struct fmdrv_ops *fmdev, unsigned short mode)
+{
+ unsigned short payload;
+ int ret;
+
+ if (fmdev->curr_fmmode != FM_MODE_RX)
+ return -EPERM;
+
+ if (mode != FM_STEREO_MODE && mode != FM_MONO_MODE) {
+ pr_err("(fmdrv): Invalid mode\n");
+ return -EINVAL;
+ }
+
+ /* Set stereo/mono mode */
+ FM_STORE_LE16_TO_BE16(payload, (unsigned short)mode);
+ ret = fmc_send_cmd(fmdev, MOST_MODE_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set RX stereo/mono mode - %d\n",
+ ret);
+ return ret;
+ }
+
+ /* Set stereo blending mode */
+ FM_STORE_LE16_TO_BE16(payload, FM_STEREO_SOFT_BLEND);
+ ret = fmc_send_cmd(fmdev, MOST_BLEND_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set RX stereo blend - %d\n", ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+/* Gets current RX stereo/mono mode */
+int fm_rx_get_stereo_mono(struct fmdrv_ops *fmdev, unsigned short *mode)
+{
+ unsigned short curr_mode;
+ int ret, resp_len;
+
+ if (fmdev->curr_fmmode != FM_MODE_RX)
+ return -EPERM;
+
+ if (mode == NULL) {
+ pr_err("(fmdrv): Invalid memory\n");
+ return -ENOMEM;
+ }
+
+ ret = fmc_send_cmd(fmdev, MOST_MODE_GET, NULL, 2,
+ &fmdev->maintask_completion, &curr_mode, &resp_len);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to get stereo/mono mode - %d\n", ret);
+ return ret;
+ }
+
+ *mode = FM_BE16_TO_LE16(curr_mode);
+
+ return 0;
+}
+
+/* Choose RX de-emphasis filter mode (50us/75us) */
+int fm_rx_set_deemphasis_mode(struct fmdrv_ops *fmdev, unsigned short mode)
+{
+ unsigned short payload;
+ int ret;
+
+ if (fmdev->curr_fmmode != FM_MODE_RX)
+ return -EPERM;
+
+ if (mode != FM_RX_EMPHASIS_FILTER_50_USEC &&
+ mode != FM_RX_EMPHASIS_FILTER_75_USEC) {
+ pr_err("(fmdrv): Invalid rx de-emphasis mode (%d)\n", mode);
+ return -EINVAL;
+ }
+
+ FM_STORE_LE16_TO_BE16(payload, mode);
+ ret = fmc_send_cmd(fmdev, DEMPH_MODE_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set RX deemphasis filter value - "
+ "%d\n", ret);
+ return ret;
+ }
+ fmdev->rx.curr_deemphasis_mode = mode;
+ return 0;
+}
+
+/* Gets current RX de-emphasis filter mode */
+int fm_rx_get_deemphasis_mode(struct fmdrv_ops *fmdev,
+ unsigned short *curr_deemphasis_mode)
+{
+ if (fmdev->curr_fmmode != FM_MODE_RX)
+ return -EPERM;
+
+ if (curr_deemphasis_mode == NULL) {
+ pr_err("(fmdrv): Invalid memory\n");
+ return -ENOMEM;
+ }
+
+ *curr_deemphasis_mode = fmdev->rx.curr_deemphasis_mode;
+
+ return 0;
+}
+
+/* Enable/Disable RX RDS */
+int fm_rx_set_rds_mode(struct fmdrv_ops *fmdev, unsigned char rds_en_dis)
+{
+ unsigned short payload;
+ int ret;
+
+ if (fmdev->curr_fmmode != FM_MODE_RX)
+ return -EPERM;
+
+ if (rds_en_dis != FM_RDS_ENABLE && rds_en_dis != FM_RDS_DISABLE) {
+ pr_err("(fmdrv): Invalid rds option\n");
+ return -EINVAL;
+ }
+
+ if (rds_en_dis == FM_RDS_ENABLE
+ && fmdev->rx.rds.flag == FM_RDS_DISABLE) {
+ /* Turn on RX RDS and RDS circuit */
+ FM_STORE_LE16_TO_BE16(payload,
+ FM_RX_POWET_SET_FM_AND_RDS_BLK_ON);
+ ret = fmc_send_cmd(fmdev, POWER_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to enable RX RDS - %d\n", ret);
+ return ret;
+ }
+
+ /* Clear and reset RDS FIFO */
+ FM_STORE_LE16_TO_BE16(payload, FM_RX_RDS_FLUSH_FIFO);
+ ret = fmc_send_cmd(fmdev, RDS_CNTRL_SET, &payload,
+ sizeof(payload), &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to flush RX RDS fifo - %d\n",
+ ret);
+ return ret;
+ }
+
+ /* Read flags - just to clear any pending interrupts. */
+ ret = fmc_send_cmd(fmdev, FLAG_GET, NULL, 2,
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to read interrupt flag - %d\n",
+ ret);
+ return ret;
+ }
+
+ /* Set RDS FIFO threshold value */
+ FM_STORE_LE16_TO_BE16(payload, FM_RX_RDS_FIFO_THRESHOLD);
+ ret = fmc_send_cmd(fmdev, RDS_MEM_SET, &payload,
+ sizeof(payload), &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set RX RDS fifo threshold -"
+ " %d\n", ret);
+ return ret;
+ }
+
+ /* Enable RDS interrupt */
+ fmdev->irq_info.mask |= FM_RDS_EVENT;
+ FM_STORE_LE16_TO_BE16(payload, fmdev->irq_info.mask);
+ ret = fmc_send_cmd(fmdev, INT_MASK_SET, &payload,
+ sizeof(payload), &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set interrupt mask- %d\n",
+ ret);
+ fmdev->irq_info.mask &= ~FM_RDS_EVENT;
+ return ret;
+ }
+
+ /* Update our local flag */
+ fmdev->rx.rds.flag = FM_RDS_ENABLE;
+ } else if (rds_en_dis == FM_RDS_DISABLE
+ && fmdev->rx.rds.flag == FM_RDS_ENABLE) {
+ /* Turn off RX RDS */
+ /* Turn off RDS circuit */
+ FM_STORE_LE16_TO_BE16(payload, FM_RX_POWER_SET_FM_ON_RDS_OFF);
+ ret = fmc_send_cmd(fmdev, POWER_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to disable RX RDS - %d\n",
+ ret);
+ return ret;
+ }
+
+ /* Reset RDS pointers */
+ fmdev->rx.rds.last_block_index = 0;
+ fmdev->rx.rds.wr_index = 0;
+ fmdev->rx.rds.rd_index = 0;
+ fm_rx_reset_curr_station_info(fmdev);
+
+ /* Update RDS local cache */
+ fmdev->irq_info.mask &= ~(FM_RDS_EVENT);
+ fmdev->rx.rds.flag = FM_RDS_DISABLE;
+ }
+
+ return 0;
+}
+
+/* Returns current RX RDS enable/disable status */
+int fm_rx_get_rds_mode(struct fmdrv_ops *fmdev,
+ unsigned char *curr_rds_en_dis)
+{
+ if (fmdev->curr_fmmode != FM_MODE_RX)
+ return -EPERM;
+
+ if (curr_rds_en_dis == NULL) {
+ pr_err("(fmdrv): Invalid memory\n");
+ return -ENOMEM;
+ }
+
+ *curr_rds_en_dis = fmdev->rx.rds.flag;
+
+ return 0;
+}
+
+/* Sets RDS operation mode (RDS/RDBS) */
+int fm_rx_set_rds_system(struct fmdrv_ops *fmdev, unsigned char rds_mode)
+{
+ unsigned short payload;
+ int ret;
+
+ if (fmdev->curr_fmmode != FM_MODE_RX)
+ return -EPERM;
+
+ if (rds_mode != FM_RDS_SYSTEM_RDS && rds_mode != FM_RDS_SYSTEM_RBDS) {
+ pr_err("(fmdrv): Invalid rds mode\n");
+ return -EINVAL;
+ }
+ /* Set RDS operation mode */
+ FM_STORE_LE16_TO_BE16(payload, (unsigned short)rds_mode);
+ ret = fmc_send_cmd(fmdev, RDS_SYSTEM_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set RX RDS system - %d\n", ret);
+ return ret;
+ }
+
+ fmdev->rx.rds_mode = rds_mode;
+
+ return 0;
+}
+
+/* Returns current RDS operation mode */
+int fm_rx_get_rds_system(struct fmdrv_ops *fmdev,
+ unsigned char *rds_mode)
+{
+ if (fmdev->curr_fmmode != FM_MODE_RX)
+ return -EPERM;
+
+ if (rds_mode == NULL) {
+ pr_err("(fmdrv): Invalid memory\n");
+ return -ENOMEM;
+ }
+
+ *rds_mode = fmdev->rx.rds_mode;
+
+ return 0;
+}
+
+/* Configures Alternate Frequency switch mode */
+int fm_rx_set_af_switch(struct fmdrv_ops *fmdev, unsigned char af_mode)
+{
+ unsigned short payload;
+ int ret;
+
+ if (fmdev->curr_fmmode != FM_MODE_RX)
+ return -EPERM;
+
+ if (af_mode != FM_RX_RDS_AF_SWITCH_MODE_ON &&
+ af_mode != FM_RX_RDS_AF_SWITCH_MODE_OFF) {
+ pr_err("(fmdrv): Invalid af mode\n");
+ return -EINVAL;
+ }
+ /* Enable/disable low RSSI interrupt based on af_mode */
+ if (af_mode == FM_RX_RDS_AF_SWITCH_MODE_ON)
+ fmdev->irq_info.mask |= FM_LEV_EVENT;
+ else
+ fmdev->irq_info.mask &= ~FM_LEV_EVENT;
+
+ FM_STORE_LE16_TO_BE16(payload, fmdev->irq_info.mask);
+ ret = fmc_send_cmd(fmdev, INT_MASK_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set interrupt mask - %d\n", ret);
+ return ret;
+ }
+
+ fmdev->rx.af_mode = af_mode;
+
+ return 0;
+}
+
+/* Returns Alternate Frequency switch status */
+int fm_rx_get_af_switch(struct fmdrv_ops *fmdev, unsigned char *af_mode)
+{
+ if (fmdev->curr_fmmode != FM_MODE_RX)
+ return -EPERM;
+
+ if (af_mode == NULL) {
+ pr_err("(fmdrv): Invalid memory\n");
+ return -ENOMEM;
+ }
+
+ *af_mode = fmdev->rx.af_mode;
+
+ return 0;
+}
+
+/* Set desired channel spacing */
+int fm_rx_set_chanl_spacing(struct fmdrv_ops *fmdev, unsigned char spacing)
+{
+ unsigned short payload;
+ int ret;
+
+ if (spacing != FM_CHANNEL_SPACING_50KHZ &&
+ spacing != FM_CHANNEL_SPACING_100KHZ &&
+ spacing != FM_CHANNEL_SPACING_200KHZ) {
+ pr_err("Invalid channel spacing");
+ return -EINVAL;
+ }
+
+ /* set channel spacing */
+ FM_STORE_LE16_TO_BE16(payload, spacing);
+
+ ret = fmc_send_cmd(fmdev, CHANL_BW_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0)
+ return ret;
+
+ fmdev->rx.region.channel_spacing = spacing * FM_FREQ_MUL;
+
+ return 0;
+}
+
+/* Get channel spacing */
+int fm_rx_get_chanl_spacing(struct fmdrv_ops *fmdev, unsigned char *spacing)
+{
+ if (fmdev->curr_fmmode != FM_MODE_RX)
+ return -EPERM;
+
+ if (spacing == NULL) {
+ pr_err("Invalid memory");
+ return -ENOMEM;
+ }
+
+ *spacing = fmdev->rx.region.channel_spacing / FM_FREQ_MUL;
+
+ return 0;
+}
diff --git a/drivers/staging/ti-st/fmdrv_rx.h b/drivers/staging/ti-st/fmdrv_rx.h
new file mode 100644
index 0000000..3d1490a
--- /dev/null
+++ b/drivers/staging/ti-st/fmdrv_rx.h
@@ -0,0 +1,59 @@
+/*
+ * FM Driver for Connectivity chip of Texas Instruments.
+ * FM RX module header.
+ *
+ * Copyright (C) 2010 Texas Instruments
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#ifndef _FMDRV_RX_H
+#define _FMDRV_RX_H
+
+int fm_rx_set_frequency(struct fmdrv_ops*, unsigned int);
+int fm_rx_set_mute_mode(struct fmdrv_ops*, unsigned char);
+int fm_rx_set_stereo_mono(struct fmdrv_ops*, unsigned short);
+int fm_rx_set_rds_mode(struct fmdrv_ops*, unsigned char);
+int fm_rx_set_rds_system(struct fmdrv_ops *, unsigned char);
+int fm_rx_set_volume(struct fmdrv_ops*, unsigned short);
+int fm_rx_set_rssi_threshold(struct fmdrv_ops*, short);
+int fm_rx_set_region(struct fmdrv_ops*, unsigned char);
+int fm_rx_set_rfdepend_softmute(struct fmdrv_ops *, unsigned char);
+int fm_rx_set_deemphasis_mode(struct fmdrv_ops *, unsigned short);
+int fm_rx_set_af_switch(struct fmdrv_ops *, unsigned char);
+
+void fm_rx_reset_rds_cache(struct fmdrv_ops *);
+void fm_rx_reset_curr_station_info(struct fmdrv_ops *);
+
+int fm_rx_seek(struct fmdrv_ops*, unsigned int, unsigned int);
+
+int fm_rx_get_rds_mode(struct fmdrv_ops*, unsigned char*);
+int fm_rx_get_rds_system(struct fmdrv_ops *, unsigned char*);
+int fm_rx_get_mute_mode(struct fmdrv_ops*, unsigned char*);
+int fm_rx_get_volume(struct fmdrv_ops*, unsigned short*);
+int fm_rx_get_currband_freq_range(struct fmdrv_ops*,
+ unsigned int*, unsigned int*);
+int fm_rx_get_stereo_mono(struct fmdrv_ops *, unsigned short*);
+int fm_rx_get_rssi_level(struct fmdrv_ops *, unsigned short*);
+int fm_rx_get_rssi_threshold(struct fmdrv_ops *, short*);
+int fm_rx_get_rfdepend_softmute(struct fmdrv_ops *, unsigned char*);
+int fm_rx_get_deemphasis_mode(struct fmdrv_ops *, unsigned short*);
+int fm_rx_get_af_switch(struct fmdrv_ops *, unsigned char *);
+void fm_rx_get_region(struct fmdrv_ops*, unsigned char*);
+
+int fm_rx_set_chanl_spacing(struct fmdrv_ops*, unsigned char);
+int fm_rx_get_chanl_spacing(struct fmdrv_ops*, unsigned char*);
+#endif
+
--
1.5.6.3

2010-11-16 12:57:53

by halli manjunatha

[permalink] [raw]
Subject: [PATCH v4 2/6] drivers:staging: ti-st: fmdrv_v4l2 sources

From: Manjunatha Halli <[email protected]>

This module interfaces V4L2 subsystem and FM common
module. It registers itself with V4L2 as Radio module.

Signed-off-by: Manjunatha Halli <[email protected]>
---
drivers/staging/ti-st/fmdrv_v4l2.c | 757 ++++++++++++++++++++++++++++++++++++
drivers/staging/ti-st/fmdrv_v4l2.h | 32 ++
2 files changed, 789 insertions(+), 0 deletions(-)
create mode 100644 drivers/staging/ti-st/fmdrv_v4l2.c
create mode 100644 drivers/staging/ti-st/fmdrv_v4l2.h

diff --git a/drivers/staging/ti-st/fmdrv_v4l2.c b/drivers/staging/ti-st/fmdrv_v4l2.c
new file mode 100644
index 0000000..687d10f
--- /dev/null
+++ b/drivers/staging/ti-st/fmdrv_v4l2.c
@@ -0,0 +1,757 @@
+/*
+ * FM Driver for Connectivity chip of Texas Instruments.
+ * This file provides interfaces to V4L2 subsystem.
+ *
+ * This module registers with V4L2 subsystem as Radio
+ * data system interface (/dev/radio). During the registration,
+ * it will expose two set of function pointers.
+ *
+ * 1) File operation related API (open, close, read, write, poll...etc).
+ * 2) Set of V4L2 IOCTL complaint API.
+ *
+ * Copyright (C) 2010 Texas Instruments
+ * Author: Raja Mani <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include "fmdrv.h"
+#include "fmdrv_v4l2.h"
+#include "fmdrv_common.h"
+#include "fmdrv_rx.h"
+#include "fmdrv_tx.h"
+
+static struct video_device *gradio_dev;
+static unsigned char radio_disconnected;
+
+/* Query control */
+static struct v4l2_queryctrl fmdrv_v4l2_queryctrl[] = {
+ {
+ .id = V4L2_CID_AUDIO_VOLUME,
+ .type = V4L2_CTRL_TYPE_INTEGER,
+ .name = "Volume",
+ .minimum = FM_RX_VOLUME_MIN,
+ .maximum = FM_RX_VOLUME_MAX,
+ .step = 1,
+ .default_value = FM_DEFAULT_RX_VOLUME,
+ },
+ {
+ .id = V4L2_CID_AUDIO_BALANCE,
+ .flags = V4L2_CTRL_FLAG_DISABLED,
+ },
+ {
+ .id = V4L2_CID_AUDIO_BASS,
+ .flags = V4L2_CTRL_FLAG_DISABLED,
+ },
+ {
+ .id = V4L2_CID_AUDIO_TREBLE,
+ .flags = V4L2_CTRL_FLAG_DISABLED,
+ },
+ {
+ .id = V4L2_CID_AUDIO_MUTE,
+ .type = V4L2_CTRL_TYPE_BOOLEAN,
+ .name = "Mute",
+ .minimum = 0,
+ .maximum = 2,
+ .step = 1,
+ .default_value = FM_MUTE_OFF,
+ },
+ {
+ .id = V4L2_CID_AUDIO_LOUDNESS,
+ .flags = V4L2_CTRL_FLAG_DISABLED,
+ },
+};
+
+/* -- V4L2 RADIO (/dev/radioX) device file operation interfaces --- */
+
+/* Read RX RDS data */
+static ssize_t fm_v4l2_fops_read(struct file *file, char __user * buf,
+ size_t count, loff_t *ppos)
+{
+ unsigned char rds_mode;
+ int ret;
+ struct fmdrv_ops *fmdev;
+
+ fmdev = video_drvdata(file);
+
+ if (!radio_disconnected) {
+ pr_err("(fmdrv): FM device is already disconnected\n");
+ return -EIO;
+ }
+
+ /* Turn on RDS mode , if it is disabled */
+ ret = fm_rx_get_rds_mode(fmdev, &rds_mode);
+ if (ret < 0) {
+ pr_err("(fmdrv): Unable to read current rds mode\n");
+ return ret;
+ }
+
+ if (rds_mode == FM_RDS_DISABLE) {
+ ret = fmc_set_rds_mode(fmdev, FM_RDS_ENABLE);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to enable rds mode\n");
+ return ret;
+ }
+ }
+
+ /* Copy RDS data from internal buffer to user buffer */
+ ret = fmc_transfer_rds_from_internal_buff(fmdev, file, buf, count);
+
+ return ret;
+}
+
+/* Write TX RDS data */
+static ssize_t fm_v4l2_fops_write(struct file *file, const char __user * buf,
+ size_t count, loff_t *ppos)
+{
+ struct tx_rds rds;
+ int ret;
+ struct fmdrv_ops *fmdev;
+
+ ret = copy_from_user(&rds, buf, sizeof(rds));
+ pr_debug("(fmdrv): (%d)type: %d, text %s, af %d\n",
+ ret, rds.text_type, rds.text, rds.af_freq);
+
+ fmdev = video_drvdata(file);
+ fm_tx_set_radio_text(fmdev, rds.text, rds.text_type);
+ fm_tx_set_af(fmdev, rds.af_freq);
+
+ return 0;
+}
+
+static unsigned int fm_v4l2_fops_poll(struct file *file,
+ struct poll_table_struct *pts)
+{
+ int ret;
+ struct fmdrv_ops *fmdev;
+
+ fmdev = video_drvdata(file);
+ ret = fmc_is_rds_data_available(fmdev, file, pts);
+ if (ret < 0)
+ return POLLIN | POLLRDNORM;
+
+ return 0;
+}
+
+/*
+ * Handle open request for "/dev/radioX" device.
+ * Start with FM RX mode as default.
+ */
+static int fm_v4l2_fops_open(struct file *file)
+{
+ int ret;
+ struct fmdrv_ops *fmdev = NULL;
+
+ /* Don't allow multiple open */
+ if (radio_disconnected) {
+ pr_err("(fmdrv): FM device is already opened\n");
+ return -EBUSY;
+ }
+
+ fmdev = video_drvdata(file);
+
+ ret = fmc_prepare(fmdev);
+ if (ret < 0) {
+ pr_err("(fmdrv): Unable to prepare FM CORE\n");
+ return ret;
+ }
+
+ pr_debug("(fmdrv): Load FM RX firmware..\n");
+
+ ret = fmc_set_mode(fmdev, FM_MODE_RX);
+ if (ret < 0) {
+ pr_err("(fmdrv): Unable to load FM RX firmware\n");
+ return ret;
+ }
+ radio_disconnected = 1;
+
+ return ret;
+}
+
+static int fm_v4l2_fops_release(struct file *file)
+{
+ int ret = 0;
+ struct fmdrv_ops *fmdev;
+
+ fmdev = video_drvdata(file);
+ if (!radio_disconnected) {
+ pr_debug("(fmdrv): FM device is already closed\n");
+ return ret;
+ }
+
+ ret = fmc_set_mode(fmdev, FM_MODE_OFF);
+ if (ret < 0) {
+ pr_err("(fmdrv): Unable to turn off the chip\n");
+ return ret;
+ }
+
+ ret = fmc_release(fmdev);
+ if (ret < 0) {
+ pr_err("(fmdrv): FM CORE release failed\n");
+ return ret;
+ }
+ radio_disconnected = 0;
+
+ return ret;
+}
+
+/* V4L2 RADIO (/dev/radioX) device IOCTL interfaces */
+static int fm_v4l2_vidioc_querycap(struct file *file, void *priv,
+ struct v4l2_capability *capability)
+{
+ strlcpy(capability->driver, FM_DRV_NAME, sizeof(capability->driver));
+ strlcpy(capability->card, FM_DRV_CARD_SHORT_NAME,
+ sizeof(capability->card));
+ sprintf(capability->bus_info, "UART");
+ capability->version = FM_DRV_RADIO_VERSION;
+ capability->capabilities = V4L2_CAP_HW_FREQ_SEEK | V4L2_CAP_TUNER |
+ V4L2_CAP_RADIO | V4L2_CAP_MODULATOR |
+ V4L2_CAP_AUDIO | V4L2_CAP_READWRITE |
+ V4L2_CAP_RDS_CAPTURE;
+
+ return 0;
+}
+
+static int fm_v4l2_vidioc_queryctrl(struct file *file, void *priv,
+ struct v4l2_queryctrl *qc)
+{
+ int index;
+ int ret = -EINVAL;
+
+ if (qc->id < V4L2_CID_BASE)
+ return ret;
+
+ /* Search control ID and copy its properties */
+ for (index = 0; index < NO_OF_ENTRIES_IN_ARRAY(fmdrv_v4l2_queryctrl);\
+ index++) {
+ if (qc->id && qc->id == fmdrv_v4l2_queryctrl[index].id) {
+ memcpy(qc, &(fmdrv_v4l2_queryctrl[index]), sizeof(*qc));
+ ret = 0;
+ break;
+ }
+ }
+ return ret;
+}
+
+static int fm_v4l2_vidioc_g_ctrl(struct file *file, void *priv,
+ struct v4l2_control *ctrl)
+{
+ int ret = -EINVAL;
+ unsigned short curr_vol;
+ unsigned char curr_mute_mode;
+ unsigned char chanl_spacing;
+ unsigned char region;
+ unsigned char afreq;
+ short threshold;
+ struct fmdrv_ops *fmdev;
+
+ fmdev = video_drvdata(file);
+
+ switch (ctrl->id) {
+ case V4L2_CID_AUDIO_MUTE: /* get mute mode */
+ ret = fm_rx_get_mute_mode(fmdev, &curr_mute_mode);
+ if (ret < 0)
+ return ret;
+ ctrl->value = curr_mute_mode;
+ break;
+ case V4L2_CID_AUDIO_VOLUME: /* get volume */
+ ret = fm_rx_get_volume(fmdev, &curr_vol);
+ if (ret < 0)
+ return ret;
+ ctrl->value = curr_vol;
+ break;
+ case V4L2_CID_FM_BAND:
+ if (fmdev->curr_fmmode != FM_MODE_RX)
+ break;
+ fm_rx_get_region(fmdev, &region);
+ if (region == FM_BAND_EUROPE_US)
+ ctrl->value = V4L2_FM_BAND_OTHER;
+ else
+ ctrl->value = V4L2_FM_BAND_JAPAN;
+ ret = 0;
+ break;
+ case V4L2_CID_RSSI_THRESHOLD:
+ ret = fm_rx_get_rssi_threshold(fmdev, &threshold);
+ if (ret == 0)
+ ctrl->value = threshold;
+ break;
+
+ case V4L2_CID_TUNE_AF:
+ ret = fm_rx_get_af_switch(fmdev, &afreq);
+ if (ret == 0)
+ ctrl->value = afreq;
+ break;
+
+ case V4L2_CID_TUNE_PREEMPHASIS:
+ ctrl->value = fmdev->tx_data.preemph;
+ break;
+
+ case V4L2_CID_CHANNEL_SPACING: /* channel spacing */
+ ret = fm_rx_get_chanl_spacing(fmdev, &chanl_spacing);
+ ctrl->value = chanl_spacing;
+ break;
+ }
+
+ return ret;
+}
+
+/*
+ * Change the value of specified control.
+ * V4L2_CID_TUNE_POWER_LEVEL: Application will specify power level value in
+ * units of dB/uV, whereas range and step are specific to FM chip. For TI's WL
+ * chips, convert application specified power level value to chip specific
+ * value by subtracting 122 from it. Refer to TI FM data sheet for details.
+ */
+static int fm_v4l2_vidioc_s_ctrl(struct file *file, void *priv,
+ struct v4l2_control *ctrl)
+{
+ struct fmdrv_ops *fmdev = video_drvdata(file);
+ unsigned int emph_filter;
+ unsigned char region;
+ int ret = -EINVAL;
+
+ switch (ctrl->id) {
+ case V4L2_CID_AUDIO_MUTE: /* set mute */
+ ret = fmc_set_mute_mode(fmdev, (unsigned char)ctrl->value);
+ break;
+
+ case V4L2_CID_AUDIO_VOLUME: /* set volume */
+ ret = fm_rx_set_volume(fmdev, (unsigned short)ctrl->value);
+ break;
+
+ case V4L2_CID_TUNE_POWER_LEVEL: /* set TX power level - ext control */
+ if (ctrl->value >= FM_PWR_LVL_LOW &&
+ ctrl->value <= FM_PWR_LVL_HIGH) {
+ ctrl->value = FM_PWR_LVL_HIGH - ctrl->value;
+ ret = fm_tx_set_pwr_lvl(fmdev,
+ (unsigned char)ctrl->value);
+ } else
+ ret = -ERANGE;
+ break;
+
+ case V4L2_CID_FM_BAND:
+ if (ctrl->value < V4L2_FM_BAND_OTHER ||
+ ctrl->value > V4L2_FM_BAND_JAPAN) {
+ ret = -ERANGE;
+ break;
+ }
+ if (ctrl->value == V4L2_FM_BAND_OTHER)
+ region = FM_BAND_EUROPE_US;
+ else
+ region = FM_BAND_JAPAN;
+ ret = fmc_set_region(fmdev, region);
+ break;
+
+ case V4L2_CID_RSSI_THRESHOLD:
+ ret = fm_rx_set_rssi_threshold(fmdev, (short)ctrl->value);
+ break;
+
+ case V4L2_CID_TUNE_AF:
+ ret = fm_rx_set_af_switch(fmdev, (unsigned char)ctrl->value);
+ break;
+
+ case V4L2_CID_TUNE_PREEMPHASIS:
+ if (ctrl->value < V4L2_PREEMPHASIS_DISABLED ||
+ ctrl->value > V4L2_PREEMPHASIS_75_uS) {
+ ret = -EINVAL;
+ break;
+ }
+ if (ctrl->value == V4L2_PREEMPHASIS_DISABLED)
+ emph_filter = FM_TX_PREEMPH_OFF;
+ else if (ctrl->value == V4L2_PREEMPHASIS_50_uS)
+ emph_filter = FM_TX_PREEMPH_50US;
+ else
+ emph_filter = FM_TX_PREEMPH_75US;
+ ret = fm_tx_set_preemph_filter(fmdev, emph_filter);
+ break;
+
+ case V4L2_CID_TUNE_ANTENNA_CAPACITOR:
+ if (ctrl->value == FM_TX_ANT_IMP_50 ||
+ ctrl->value == FM_TX_ANT_IMP_200 ||
+ ctrl->value == FM_TX_ANT_IMP_500)
+ ret = fm_tx_set_ant_imp(fmdev, ctrl->value);
+ else
+ ret = -EINVAL;
+ break;
+
+ case V4L2_CID_CHANNEL_SPACING: /* channel spacing */
+ ret = fm_rx_set_chanl_spacing(fmdev,
+ (unsigned int) ctrl->value);
+ break;
+ }
+
+ return ret;
+}
+
+static int fm_v4l2_vidioc_g_audio(struct file *file, void *priv,
+ struct v4l2_audio *audio)
+{
+ memset(audio, 0, sizeof(*audio));
+ audio->index = 0;
+ strcpy(audio->name, "Radio");
+ audio->capability = V4L2_AUDCAP_STEREO;
+
+ return 0;
+}
+
+static int fm_v4l2_vidioc_s_audio(struct file *file, void *priv,
+ struct v4l2_audio *audio)
+{
+ if (audio->index != 0)
+ return -EINVAL;
+
+ return 0;
+}
+
+/* Get tuner attributes. If current mode is NOT RX, return error */
+static int fm_v4l2_vidioc_g_tuner(struct file *file, void *priv,
+ struct v4l2_tuner *tuner)
+{
+ struct fmdrv_ops *fmdev = video_drvdata(file);
+ unsigned int bottom_frequency;
+ unsigned int top_frequency;
+ unsigned short stereo_mono_mode;
+ unsigned short rssilvl;
+ int ret = -EINVAL;
+
+ if (tuner->index != 0)
+ return ret;
+
+ if (fmdev->curr_fmmode != FM_MODE_RX)
+ return -EPERM;
+
+ ret = fm_rx_get_currband_freq_range(fmdev, &bottom_frequency,
+ &top_frequency);
+ if (ret != 0)
+ return ret;
+
+ ret = fm_rx_get_stereo_mono(fmdev, &stereo_mono_mode);
+ if (ret != 0)
+ return ret;
+
+ ret = fm_rx_get_rssi_level(fmdev, &rssilvl);
+ if (ret != 0)
+ return ret;
+
+ strcpy(tuner->name, "FM");
+ tuner->type = V4L2_TUNER_RADIO;
+ /* Store rangelow and rangehigh freq in unit of 62.5 Hz */
+ tuner->rangelow = bottom_frequency * 16;
+ tuner->rangehigh = top_frequency * 16;
+ tuner->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO |
+ ((fmdev->rx.rds.flag == FM_RDS_ENABLE) ? V4L2_TUNER_SUB_RDS : 0);
+ tuner->capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_RDS |
+ V4L2_TUNER_CAP_LOW;
+ tuner->audmode = (stereo_mono_mode ?
+ V4L2_TUNER_MODE_MONO : V4L2_TUNER_MODE_STEREO);
+
+ /*
+ * Actual rssi value lies in between -128 to +127.
+ * Convert this range from 0 to 255 by adding +128
+ */
+ rssilvl += 128;
+
+ /*
+ * Return signal strength value should be within 0 to 65535.
+ * Find out correct signal radio by multiplying (65535/255) = 257
+ */
+ tuner->signal = rssilvl * 257;
+ tuner->afc = 0;
+
+ return ret;
+}
+
+/*
+ * Set tuner attributes. If current mode is NOT RX, set to RX.
+ * Currently, we set only audio mode (mono/stereo) and RDS state (on/off).
+ * Should we set other tuner attributes, too?
+ */
+static int fm_v4l2_vidioc_s_tuner(struct file *file, void *priv,
+ struct v4l2_tuner *tuner)
+{
+ struct fmdrv_ops *fmdev = video_drvdata(file);
+ unsigned short aud_mode;
+ unsigned char rds_mode;
+ int ret = -EINVAL;
+
+ if (tuner->index != 0)
+ return ret;
+
+ aud_mode = (tuner->audmode == V4L2_TUNER_MODE_STEREO) ?
+ FM_STEREO_MODE : FM_MONO_MODE;
+ rds_mode = (tuner->rxsubchans & V4L2_TUNER_SUB_RDS) ?
+ FM_RDS_ENABLE : FM_RDS_DISABLE;
+
+ if (fmdev->curr_fmmode != FM_MODE_RX) {
+ ret = fmc_set_mode(fmdev, FM_MODE_RX);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set RX mode; unable to "
+ "write tuner attributes\n");
+ return ret;
+ }
+ }
+
+ ret = fmc_set_stereo_mono(fmdev, aud_mode);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set RX stereo/mono mode\n");
+ return ret;
+ }
+
+ ret = fmc_set_rds_mode(fmdev, rds_mode);
+ if (ret < 0)
+ pr_err("(fmdrv): Failed to set RX RDS mode\n");
+
+ return ret;
+}
+
+/* Get tuner or modulator radio frequency */
+static int fm_v4l2_vidioc_g_frequency(struct file *file, void *priv,
+ struct v4l2_frequency *freq)
+{
+ int ret;
+ struct fmdrv_ops *fmdev = video_drvdata(file);
+
+ ret = fmc_get_frequency(fmdev, &freq->frequency);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to get frequency\n");
+ return ret;
+ }
+
+ freq->frequency =
+ (unsigned int) freq->frequency * 16; /* unit of 62.5 Hz*/
+
+ return 0;
+}
+
+/* Set tuner or modulator radio frequency */
+static int fm_v4l2_vidioc_s_frequency(struct file *file, void *priv,
+ struct v4l2_frequency *freq)
+{
+ struct fmdrv_ops *fmdev = video_drvdata(file);
+ int ret;
+
+ /*
+ * As V4L2_TUNER_CAP_LOW is set 1 user sends the frequency
+ * in units of 62.5 Hz.
+ */
+ freq->frequency = (unsigned int)(freq->frequency / 16);
+
+ ret = fmc_set_frequency(fmdev, freq->frequency);
+
+ return ret;
+}
+
+/* Set hardware frequency seek. If current mode is NOT RX, set it RX. */
+static int fm_v4l2_vidioc_s_hw_freq_seek(struct file *file, void *priv,
+ struct v4l2_hw_freq_seek *seek)
+{
+ struct fmdrv_ops *fmdev = video_drvdata(file);
+ int ret;
+
+ if (fmdev->curr_fmmode != FM_MODE_RX) {
+ ret = fmc_set_mode(fmdev, FM_MODE_RX);
+ if (ret != 0) {
+ pr_err("(fmdrv): Failed to set RX mode; unable to "
+ "start HW frequency seek\n");
+ return ret;
+ }
+ }
+
+ ret = fm_rx_seek(fmdev, seek->seek_upward, seek->wrap_around);
+ if (ret < 0)
+ pr_err("(fmdrv): RX seek failed - %d\n", ret);
+
+ return ret;
+}
+
+static int fm_v4l2_vidioc_g_ext_ctrls(struct file *file, void *priv,
+ struct v4l2_ext_controls *ext_ctrls)
+{
+ struct v4l2_control ctrl;
+ int index;
+ int ret = -EINVAL;
+
+ if (V4L2_CTRL_CLASS_FM_TX == ext_ctrls->ctrl_class) {
+ for (index = 0; index < ext_ctrls->count; index++) {
+ ctrl.id = ext_ctrls->controls[index].id;
+ ctrl.value = ext_ctrls->controls[index].value;
+ ret = fm_v4l2_vidioc_g_ctrl(file, priv, &ctrl);
+ if (ret < 0) {
+ ext_ctrls->error_idx = index;
+ break;
+ }
+ ext_ctrls->controls[index].value = ctrl.value;
+ }
+ }
+
+ return ret;
+}
+
+static int fm_v4l2_vidioc_s_ext_ctrls(struct file *file, void *priv,
+ struct v4l2_ext_controls *ext_ctrls)
+{
+ struct v4l2_control ctrl;
+ int index;
+ int ret = -EINVAL;
+
+ if (V4L2_CTRL_CLASS_FM_TX == ext_ctrls->ctrl_class) {
+ for (index = 0; index < ext_ctrls->count; index++) {
+ ctrl.id = ext_ctrls->controls[index].id;
+ ctrl.value = ext_ctrls->controls[index].value;
+ ret = fm_v4l2_vidioc_s_ctrl(file, priv, &ctrl);
+ if (ret < 0) {
+ ext_ctrls->error_idx = index;
+ break;
+ }
+ ext_ctrls->controls[index].value = ctrl.value;
+ }
+ }
+
+ return ret;
+}
+
+/* Get modulator attributes. If mode is not TX, return no attributes. */
+static int fm_v4l2_vidioc_g_modulator(struct file *file, void *priv,
+ struct v4l2_modulator *mod)
+{
+ struct fmdrv_ops *fmdev = video_drvdata(file);;
+
+ if (mod->index != 0)
+ return -EINVAL;
+
+ if (fmdev->curr_fmmode != FM_MODE_TX)
+ return -EPERM;
+
+ mod->txsubchans = ((fmdev->tx_data.aud_mode == FM_STEREO_MODE) ?
+ V4L2_TUNER_SUB_STEREO : V4L2_TUNER_SUB_MONO) |
+ ((fmdev->tx_data.rds.flag == FM_RDS_ENABLE) ? V4L2_TUNER_SUB_RDS : 0);
+
+ mod->capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_RDS;
+
+ return 0;
+}
+
+/* Set modulator attributes. If mode is not TX, set to TX. */
+static int fm_v4l2_vidioc_s_modulator(struct file *file, void *priv,
+ struct v4l2_modulator *mod)
+{
+ struct fmdrv_ops *fmdev = video_drvdata(file);
+ unsigned char rds_mode;
+ unsigned short aud_mode;
+ int ret;
+
+ if (mod->index != 0)
+ return -EINVAL;
+
+ if (fmdev->curr_fmmode != FM_MODE_TX) {
+ ret = fmc_set_mode(fmdev, FM_MODE_TX);
+ if (ret != 0) {
+ pr_err("(fmdrv): Failed to set TX mode; unable to "
+ "set modulator attributes\n");
+ return ret;
+ }
+ }
+
+ aud_mode = (mod->txsubchans & V4L2_TUNER_SUB_STEREO) ?
+ FM_STEREO_MODE : FM_MONO_MODE;
+ rds_mode = (mod->txsubchans & V4L2_TUNER_SUB_RDS) ?
+ FM_RDS_ENABLE : FM_RDS_DISABLE;
+
+ ret = fm_tx_set_stereo_mono(fmdev, aud_mode);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set mono/stereo mode for TX\n");
+ return ret;
+ }
+
+ ret = fm_tx_set_rds_mode(fmdev, rds_mode);
+ if (ret < 0)
+ pr_err("(fmdrv): Failed to set rds mode for TX\n");
+
+ return ret;
+}
+
+static const struct v4l2_file_operations fm_drv_fops = {
+ .owner = THIS_MODULE,
+ .read = fm_v4l2_fops_read,
+ .write = fm_v4l2_fops_write,
+ .poll = fm_v4l2_fops_poll,
+ .ioctl = video_ioctl2,
+ .open = fm_v4l2_fops_open,
+ .release = fm_v4l2_fops_release,
+};
+
+static const struct v4l2_ioctl_ops fm_drv_ioctl_ops = {
+ .vidioc_querycap = fm_v4l2_vidioc_querycap,
+ .vidioc_queryctrl = fm_v4l2_vidioc_queryctrl,
+ .vidioc_g_ctrl = fm_v4l2_vidioc_g_ctrl,
+ .vidioc_s_ctrl = fm_v4l2_vidioc_s_ctrl,
+ .vidioc_g_ext_ctrls = fm_v4l2_vidioc_g_ext_ctrls,
+ .vidioc_s_ext_ctrls = fm_v4l2_vidioc_s_ext_ctrls,
+ .vidioc_g_audio = fm_v4l2_vidioc_g_audio,
+ .vidioc_s_audio = fm_v4l2_vidioc_s_audio,
+ .vidioc_g_tuner = fm_v4l2_vidioc_g_tuner,
+ .vidioc_s_tuner = fm_v4l2_vidioc_s_tuner,
+ .vidioc_g_frequency = fm_v4l2_vidioc_g_frequency,
+ .vidioc_s_frequency = fm_v4l2_vidioc_s_frequency,
+ .vidioc_s_hw_freq_seek = fm_v4l2_vidioc_s_hw_freq_seek,
+ .vidioc_g_modulator = fm_v4l2_vidioc_g_modulator,
+ .vidioc_s_modulator = fm_v4l2_vidioc_s_modulator
+};
+
+/* V4L2 RADIO device parent structure */
+static struct video_device fm_viddev_template = {
+ .fops = &fm_drv_fops,
+ .ioctl_ops = &fm_drv_ioctl_ops,
+ .name = FM_DRV_NAME,
+ .release = video_device_release,
+};
+
+int fm_v4l2_init_video_device(struct fmdrv_ops *fmdev, int radio_nr)
+{
+
+ /* Allocate new video device */
+ gradio_dev = video_device_alloc();
+ if (NULL == gradio_dev) {
+ pr_err("(fmdrv): Can't allocate video device\n");
+ return -ENOMEM;
+ }
+
+ /* Setup FM driver's V4L2 properties */
+ memcpy(gradio_dev, &fm_viddev_template, sizeof(fm_viddev_template));
+
+ video_set_drvdata(gradio_dev, fmdev);
+
+ /* Register with V4L2 subsystem as RADIO device */
+ if (video_register_device(gradio_dev, VFL_TYPE_RADIO, radio_nr)) {
+ video_device_release(gradio_dev);
+ pr_err("(fmdrv): Could not register video device\n");
+ return -ENOMEM;
+ }
+
+ fmdev->radio_dev = gradio_dev;
+
+ return 0;
+}
+
+void *fm_v4l2_deinit_video_device(void)
+{
+ struct fmdrv_ops *fmdev;
+
+ fmdev = video_get_drvdata(gradio_dev);
+ /* Unregister RADIO device from V4L2 subsystem */
+ video_unregister_device(gradio_dev);
+
+ return fmdev;
+}
diff --git a/drivers/staging/ti-st/fmdrv_v4l2.h b/drivers/staging/ti-st/fmdrv_v4l2.h
new file mode 100644
index 0000000..6f0a415
--- /dev/null
+++ b/drivers/staging/ti-st/fmdrv_v4l2.h
@@ -0,0 +1,32 @@
+/*
+ * FM Driver for Connectivity chip of Texas Instruments.
+ *
+ * FM V4L2 module header.
+ *
+ * Copyright (C) 2010 Texas Instruments
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#ifndef _FMDRV_V4L2_H
+#define _FMDRV_V4L2_H
+
+#include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
+
+int fm_v4l2_init_video_device(struct fmdrv_ops *, int);
+void *fm_v4l2_deinit_video_device(void);
+
+#endif
--
1.5.6.3

2010-11-16 12:56:55

by halli manjunatha

[permalink] [raw]
Subject: [PATCH v4 5/6] drivers:staging: ti-st: fmdrv_tx sources

From: Manjunatha Halli <[email protected]>

This has implementation for FM TX functionality.
It communicates with FM V4l2 module and FM common module.

Signed-off-by: Manjunatha Halli <[email protected]>
---
drivers/staging/ti-st/fmdrv_tx.c | 461 ++++++++++++++++++++++++++++++++++++++
drivers/staging/ti-st/fmdrv_tx.h | 37 +++
2 files changed, 498 insertions(+), 0 deletions(-)
create mode 100644 drivers/staging/ti-st/fmdrv_tx.c
create mode 100644 drivers/staging/ti-st/fmdrv_tx.h

diff --git a/drivers/staging/ti-st/fmdrv_tx.c b/drivers/staging/ti-st/fmdrv_tx.c
new file mode 100644
index 0000000..7850d19
--- /dev/null
+++ b/drivers/staging/ti-st/fmdrv_tx.c
@@ -0,0 +1,461 @@
+/*
+ * FM Driver for Connectivity chip of Texas Instruments.
+ * This sub-module of FM driver implements FM TX functionality.
+ *
+ * Copyright (C) 2010 Texas Instruments
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <linux/delay.h>
+#include "fmdrv.h"
+#include "fmdrv_common.h"
+#include "fmdrv_tx.h"
+
+int fm_tx_set_stereo_mono(struct fmdrv_ops *fmdev, unsigned short mode)
+{
+ unsigned short payload;
+ int ret = 0;
+
+ if (fmdev->curr_fmmode != FM_MODE_TX)
+ return -EPERM;
+
+ if (fmdev->tx_data.aud_mode == mode)
+ return ret;
+
+ pr_debug("stereo mode: %d\n", mode);
+
+ /* Set Stereo/Mono mode */
+ FM_STORE_LE16_TO_BE16(payload, (1 - mode));
+ ret = fmc_send_cmd(fmdev, MONO_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set TX stereo/mono mode - %d\n",
+ ret);
+ return ret;
+ }
+
+ fmdev->tx_data.aud_mode = mode;
+
+ return ret;
+}
+
+static int __set_rds_text(struct fmdrv_ops *fmdev, unsigned char *rds_text)
+{
+ unsigned short payload;
+ int ret;
+
+ ret = fmc_send_cmd(fmdev, RDS_DATA_SET, rds_text, strlen(rds_text),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set TX RDS data - %d\n", ret);
+ return ret;
+ }
+
+ /* Scroll mode */
+ FM_STORE_LE16_TO_BE16(payload, (unsigned short)0x1);
+ ret = fmc_send_cmd(fmdev, DISPLAY_MODE_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set RDS display mode - %d\n", ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+static int __set_rds_data_mode(struct fmdrv_ops *fmdev, unsigned char mode)
+{
+ unsigned short payload;
+ int ret;
+
+ /* Setting unique PI TODO: how unique? */
+ FM_STORE_LE16_TO_BE16(payload, (unsigned short)0xcafe);
+ ret = fmc_send_cmd(fmdev, PI_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set PI - %d\n", ret);
+ return ret;
+ }
+
+ /* Set decoder id */
+ FM_STORE_LE16_TO_BE16(payload, (unsigned short)0xa);
+ ret = fmc_send_cmd(fmdev, DI_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set DI - %d\n", ret);
+ return ret;
+ }
+
+ /* TODO: RDS_MODE_GET? */
+ return 0;
+}
+
+static int __set_rds_len(struct fmdrv_ops *fmdev, unsigned char type,
+ unsigned short len)
+{
+ unsigned short payload;
+ int ret;
+
+ len |= type << 8;
+ FM_STORE_LE16_TO_BE16(payload, len);
+ ret = fmc_send_cmd(fmdev, LENGTH_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set RDS data length - %d\n", ret);
+ return ret;
+ }
+
+ /* TODO: LENGTH_GET? */
+ return 0;
+}
+
+int fm_tx_set_rds_mode(struct fmdrv_ops *fmdev, unsigned char rds_en_dis)
+{
+ unsigned short payload;
+ int ret;
+ unsigned char rds_text[] = "Zoom2\n";
+
+ if (fmdev->curr_fmmode != FM_MODE_TX)
+ return -EPERM;
+
+ pr_debug("rds_en_dis:%d(E:%d, D:%d)\n", rds_en_dis,
+ FM_RDS_ENABLE, FM_RDS_DISABLE);
+
+ if (rds_en_dis == FM_RDS_ENABLE) {
+ /* Set RDS length */
+ __set_rds_len(fmdev, 0, strlen(rds_text));
+
+ /* Set RDS text */
+ __set_rds_text(fmdev, rds_text);
+
+ /* Set RDS mode */
+ __set_rds_data_mode(fmdev, 0x0);
+ }
+
+ /* Send command to enable RDS */
+ if (rds_en_dis == FM_RDS_ENABLE)
+ FM_STORE_LE16_TO_BE16(payload, 0x01);
+ else
+ FM_STORE_LE16_TO_BE16(payload, 0x00);
+
+ ret = fmc_send_cmd(fmdev, RDS_DATA_ENB, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set TX RDS state - %d\n", ret);
+ return ret;
+ }
+
+ if (rds_en_dis == FM_RDS_ENABLE) {
+ /* Set RDS length */
+ __set_rds_len(fmdev, 0, strlen(rds_text));
+
+ /* Set RDS text */
+ __set_rds_text(fmdev, rds_text);
+ }
+ fmdev->tx_data.rds.flag = rds_en_dis;
+
+ return 0;
+}
+
+int fm_tx_set_radio_text(struct fmdrv_ops *fmdev,
+ unsigned char *rds_text,
+ unsigned char rds_type)
+{
+ unsigned short payload;
+ int ret;
+
+ if (fmdev->curr_fmmode != FM_MODE_TX)
+ return -EPERM;
+
+ fm_tx_set_rds_mode(fmdev, 0);
+
+ /* Set RDS length */
+ __set_rds_len(fmdev, rds_type, strlen(rds_text));
+
+ /* Set RDS text */
+ __set_rds_text(fmdev, rds_text);
+
+ /* Set RDS mode */
+ __set_rds_data_mode(fmdev, 0x0);
+
+ FM_STORE_LE16_TO_BE16(payload, 1);
+ ret = fmc_send_cmd(fmdev, RDS_DATA_ENB, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to enable TX RDS data - %d\n", ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+int fm_tx_set_af(struct fmdrv_ops *fmdev, unsigned int af)
+{
+ unsigned short payload;
+ int ret;
+
+ if (fmdev->curr_fmmode != FM_MODE_TX)
+ return -EPERM;
+ pr_debug("AF: %d\n", af);
+
+ af = (af - 87500) / 100;
+ FM_STORE_LE16_TO_BE16(payload, (unsigned short)af);
+ ret = fmc_send_cmd(fmdev, TA_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set TX AF - %d\n", ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+int fm_tx_set_region(struct fmdrv_ops *fmdev,
+ unsigned char region_to_set)
+{
+ unsigned short payload;
+ int ret;
+
+ if (region_to_set != FM_BAND_EUROPE_US &&
+ region_to_set != FM_BAND_JAPAN) {
+ pr_err("Invalid band\n");
+ return -EINVAL;
+ }
+
+ /* Send command to set the band */
+ FM_STORE_LE16_TO_BE16(payload, (unsigned short)region_to_set);
+ ret = fmc_send_cmd(fmdev, TX_BAND_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set TX band - %d\n", ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+int fm_tx_set_mute_mode(struct fmdrv_ops *fmdev,
+ unsigned char mute_mode_toset)
+{
+ unsigned short payload;
+ int ret;
+
+ if (fmdev->curr_fmmode != FM_MODE_TX)
+ return -EPERM;
+ pr_debug("tx: mute mode %d\n", mute_mode_toset);
+
+ FM_STORE_LE16_TO_BE16(payload, mute_mode_toset);
+ ret = fmc_send_cmd(fmdev, MUTE, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to TX mute mode - %d\n", ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+/* Set TX Audio I/O */
+static int __set_audio_io(struct fmdrv_ops *fmdev)
+{
+ struct fmtx_data *tx = &fmdev->tx_data;
+ unsigned short payload;
+ int ret;
+
+ /* Set Audio I/O Enable */
+ FM_STORE_LE16_TO_BE16(payload, tx->audio_io);
+ ret = fmc_send_cmd(fmdev, AUDIO_IO_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to enable TX audio I/O - %d\n", ret);
+ return ret;
+ }
+
+ /* TODO: is audio set? */
+ return 0;
+}
+
+/* Start TX Transmission */
+static int __enable_xmit(struct fmdrv_ops *fmdev, unsigned char new_xmit_state)
+{
+ struct fmtx_data *tx = &fmdev->tx_data;
+ unsigned short payload;
+ unsigned long timeleft;
+ int ret;
+
+ /* Enable POWER_ENB interrupts */
+ FM_STORE_LE16_TO_BE16(payload, FM_POW_ENB_EVENT);
+ ret = fmc_send_cmd(fmdev, INT_MASK_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set interrupt mask - %d\n", ret);
+ return ret;
+ }
+
+ /* Set Power Enable */
+ FM_STORE_LE16_TO_BE16(payload, new_xmit_state);
+ ret = fmc_send_cmd(fmdev, POWER_ENB_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to enable transmission - %d\n", ret);
+ return ret;
+ }
+
+ /* Wait for Power Enabled */
+ init_completion(&fmdev->maintask_completion);
+ timeleft = wait_for_completion_timeout(&fmdev->maintask_completion,
+ FM_DRV_TX_TIMEOUT);
+ if (!timeleft) {
+ pr_err("Timeout(%d sec),didn't get tune ended interrupt\n",
+ jiffies_to_msecs(FM_DRV_TX_TIMEOUT) / 1000);
+ return -ETIMEDOUT;
+ }
+
+ set_bit(FM_CORE_TX_XMITING, &fmdev->flag);
+ tx->xmit_state = new_xmit_state;
+
+ return 0;
+}
+
+/* Set TX power level */
+int fm_tx_set_pwr_lvl(struct fmdrv_ops *fmdev, unsigned char new_pwr_lvl)
+{
+ unsigned short payload;
+ struct fmtx_data *tx = &fmdev->tx_data;
+ int ret;
+
+ if (fmdev->curr_fmmode != FM_MODE_TX)
+ return -EPERM;
+ pr_debug("tx: pwr_level_to_set %ld\n", (long int)new_pwr_lvl);
+
+ /* If the core isn't ready update global variable */
+ if (!test_bit(FM_CORE_READY, &fmdev->flag)) {
+ tx->pwr_lvl = new_pwr_lvl;
+ return 0;
+ }
+
+ /* Set power level */
+ FM_STORE_LE16_TO_BE16(payload, new_pwr_lvl);
+ ret = fmc_send_cmd(fmdev, POWER_LEL_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set TX power level - %d\n", ret);
+ return ret;
+ }
+
+ /* TODO: is the power level set? */
+ tx->pwr_lvl = new_pwr_lvl;
+
+ return 0;
+}
+
+/*
+ * Sets FM TX pre-emphasis filter value (OFF, 50us, or 75us)
+ * Convert V4L2 specified filter values to chip specific filter values.
+ */
+int fm_tx_set_preemph_filter(struct fmdrv_ops *fmdev, unsigned int filter)
+{
+ struct fmtx_data *tx = &fmdev->tx_data;
+ unsigned short payload;
+ int ret;
+
+ if (fmdev->curr_fmmode != FM_MODE_TX)
+ return -EPERM;
+
+ FM_STORE_LE16_TO_BE16(payload, filter);
+ ret = fmc_send_cmd(fmdev, PREMPH_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set TX preemphasis filter value -"
+ " %d\n", ret);
+ return ret;
+ }
+
+ tx->preemph = filter;
+
+ return ret;
+}
+
+/* Sets FM TX antenna impedance value */
+int fm_tx_set_ant_imp(struct fmdrv_ops *fmdev, unsigned char imp)
+{
+ unsigned short payload;
+ int ret;
+
+ if (fmdev->curr_fmmode != FM_MODE_TX)
+ return -EPERM;
+
+ FM_STORE_LE16_TO_BE16(payload, imp);
+ ret = fmc_send_cmd(fmdev, IMP_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set TX antenna impedance value -"
+ " %d\n", ret);
+ return ret;
+ }
+
+ return ret;
+}
+
+/* Set TX Frequency */
+int fm_tx_set_frequency(struct fmdrv_ops *fmdev, unsigned int freq_to_set)
+{
+ struct fmtx_data *tx = &fmdev->tx_data;
+ unsigned short payload, chanl_index;
+ int ret;
+
+ if (test_bit(FM_CORE_TX_XMITING, &fmdev->flag)) {
+ __enable_xmit(fmdev, 0);
+ clear_bit(FM_CORE_TX_XMITING, &fmdev->flag);
+ }
+
+ /* Enable FR, BL interrupts */
+ FM_STORE_LE16_TO_BE16(payload, (FM_FR_EVENT | FM_BL_EVENT));
+ ret = fmc_send_cmd(fmdev, INT_MASK_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set interrupt mask %d\n", ret);
+ return ret;
+ }
+
+ tx->tx_frq = (unsigned long)freq_to_set;
+ pr_debug("tx: freq_to_set %ld\n", (long int)tx->tx_frq);
+
+ chanl_index = freq_to_set / 10;
+
+ /* Set current tuner channel */
+ FM_STORE_LE16_TO_BE16(payload, chanl_index);
+ ret = fmc_send_cmd(fmdev, CHANL_SET, &payload, sizeof(payload),
+ &fmdev->maintask_completion, NULL, NULL);
+ if (ret < 0) {
+ pr_err("(fmdrv): Failed to set tunner channel %d\n", ret);
+ return ret;
+ }
+
+ fm_tx_set_pwr_lvl(fmdev, tx->pwr_lvl);
+ fm_tx_set_preemph_filter(fmdev, tx->preemph);
+
+ tx->audio_io = 0x01; /* I2S */
+ __set_audio_io(fmdev);
+
+ __enable_xmit(fmdev, 0x01); /* Enable transmission */
+
+ tx->aud_mode = FM_STEREO_MODE;
+ tx->rds.flag = FM_RDS_DISABLE;
+
+ return 0;
+}
+
diff --git a/drivers/staging/ti-st/fmdrv_tx.h b/drivers/staging/ti-st/fmdrv_tx.h
new file mode 100644
index 0000000..f61dace
--- /dev/null
+++ b/drivers/staging/ti-st/fmdrv_tx.h
@@ -0,0 +1,37 @@
+/*
+ * FM Driver for Connectivity chip of Texas Instruments.
+ * FM TX module header.
+ *
+ * Copyright (C) 2010 Texas Instruments
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#ifndef _FMDRV_TX_H
+#define _FMDRV_TX_H
+
+int fm_tx_set_frequency(struct fmdrv_ops*, unsigned int);
+int fm_tx_set_pwr_lvl(struct fmdrv_ops*, unsigned char);
+int fm_tx_set_region(struct fmdrv_ops*, unsigned char);
+int fm_tx_set_mute_mode(struct fmdrv_ops*, unsigned char);
+int fm_tx_set_stereo_mono(struct fmdrv_ops*, unsigned short);
+int fm_tx_set_rds_mode(struct fmdrv_ops*, unsigned char);
+int fm_tx_set_radio_text(struct fmdrv_ops*, unsigned char*, unsigned char);
+int fm_tx_set_af(struct fmdrv_ops*, unsigned int);
+int fm_tx_set_preemph_filter(struct fmdrv_ops*, unsigned int);
+int fm_tx_set_ant_imp(struct fmdrv_ops*, unsigned char);
+
+#endif
+
--
1.5.6.3

2010-11-17 01:25:03

by Figo.zhang

[permalink] [raw]
Subject: Re: [PATCH v4 2/6] drivers:staging: ti-st: fmdrv_v4l2 sources

?? 11/16/2010 09:18 PM, [email protected] д??:
> From: Manjunatha Halli<[email protected]>
>
> This module interfaces V4L2 subsystem and FM common
> module. It registers itself with V4L2 as Radio module.
>
> Signed-off-by: Manjunatha Halli<[email protected]>
> ---
> drivers/staging/ti-st/fmdrv_v4l2.c | 757 ++++++++++++++++++++++++++++++++++++
> drivers/staging/ti-st/fmdrv_v4l2.h | 32 ++
> 2 files changed, 789 insertions(+), 0 deletions(-)
> create mode 100644 drivers/staging/ti-st/fmdrv_v4l2.c
> create mode 100644 drivers/staging/ti-st/fmdrv_v4l2.h
>
> diff --git a/drivers/staging/ti-st/fmdrv_v4l2.c b/drivers/staging/ti-st/fmdrv_v4l2.c
> new file mode 100644
> index 0000000..687d10f
> --- /dev/null
> +++ b/drivers/staging/ti-st/fmdrv_v4l2.c
> @@ -0,0 +1,757 @@
> +/*
> + * FM Driver for Connectivity chip of Texas Instruments.
> + * This file provides interfaces to V4L2 subsystem.
> + *
> + * This module registers with V4L2 subsystem as Radio
> + * data system interface (/dev/radio). During the registration,
> + * it will expose two set of function pointers.
> + *
> + * 1) File operation related API (open, close, read, write, poll...etc).
> + * 2) Set of V4L2 IOCTL complaint API.
> + *
> + * Copyright (C) 2010 Texas Instruments
> + * Author: Raja Mani<[email protected]>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> + *
> + */
> +
> +#include "fmdrv.h"
> +#include "fmdrv_v4l2.h"
> +#include "fmdrv_common.h"
> +#include "fmdrv_rx.h"
> +#include "fmdrv_tx.h"
> +
> +static struct video_device *gradio_dev;

why are you using global variable here?

2010-11-17 13:02:30

by Ohad Ben Cohen

[permalink] [raw]
Subject: Re: [PATCH v4 0/6] FM V4L2 drivers for WL128x

Hi Manjunatha,

On Tue, Nov 16, 2010 at 3:18 PM, <[email protected]> wrote:
> ?drivers/staging/ti-st/Kconfig ? ? ? ?| ? 10 +
> ?drivers/staging/ti-st/Makefile ? ? ? | ? ?2 +
> ?drivers/staging/ti-st/fmdrv.h ? ? ? ?| ?259 ++++
> ?drivers/staging/ti-st/fmdrv_common.c | 2141 ++++++++++++++++++++++++++++++++++
> ?drivers/staging/ti-st/fmdrv_common.h | ?458 ++++++++
> ?drivers/staging/ti-st/fmdrv_rx.c ? ? | ?979 ++++++++++++++++
> ?drivers/staging/ti-st/fmdrv_rx.h ? ? | ? 59 +
> ?drivers/staging/ti-st/fmdrv_tx.c ? ? | ?461 ++++++++
> ?drivers/staging/ti-st/fmdrv_tx.h ? ? | ? 37 +
> ?drivers/staging/ti-st/fmdrv_v4l2.c ? | ?757 ++++++++++++
> ?drivers/staging/ti-st/fmdrv_v4l2.h ? | ? 32 +
> ?11 files changed, 5195 insertions(+), 0 deletions(-)

Usually when a driver is added to staging, it should also have a TODO
file specifying what needs to be done before the driver can be taken
out of staging (at least as far as the author knows of today).

It helps keeping track of the open issues in the driver, which is good
for everyone - the author, the random contributor/observer, and
probably even the staging maintainer.

Can you please add such a TODO file ?

Thanks,
Ohad.

> ?create mode 100644 drivers/staging/ti-st/fmdrv.h
> ?create mode 100644 drivers/staging/ti-st/fmdrv_common.c
> ?create mode 100644 drivers/staging/ti-st/fmdrv_common.h
> ?create mode 100644 drivers/staging/ti-st/fmdrv_rx.c
> ?create mode 100644 drivers/staging/ti-st/fmdrv_rx.h
> ?create mode 100644 drivers/staging/ti-st/fmdrv_tx.c
> ?create mode 100644 drivers/staging/ti-st/fmdrv_tx.h
> ?create mode 100644 drivers/staging/ti-st/fmdrv_v4l2.c
> ?create mode 100644 drivers/staging/ti-st/fmdrv_v4l2.h
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at ?http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at ?http://www.tux.org/lkml/
>

2010-11-18 05:54:18

by Pavan Savoy

[permalink] [raw]
Subject: Re: [PATCH v4 0/6] FM V4L2 drivers for WL128x

Hans, Mauro, Ohad,

On Wed, Nov 17, 2010 at 6:32 PM, Ohad Ben-Cohen <[email protected]> wrote:
> Hi Manjunatha,
>
> On Tue, Nov 16, 2010 at 3:18 PM,  <[email protected]> wrote:
>>  drivers/staging/ti-st/Kconfig        |   10 +
>>  drivers/staging/ti-st/Makefile       |    2 +
>>  drivers/staging/ti-st/fmdrv.h        |  259 ++++
>>  drivers/staging/ti-st/fmdrv_common.c | 2141 ++++++++++++++++++++++++++++++++++
>>  drivers/staging/ti-st/fmdrv_common.h |  458 ++++++++
>>  drivers/staging/ti-st/fmdrv_rx.c     |  979 ++++++++++++++++
>>  drivers/staging/ti-st/fmdrv_rx.h     |   59 +
>>  drivers/staging/ti-st/fmdrv_tx.c     |  461 ++++++++
>>  drivers/staging/ti-st/fmdrv_tx.h     |   37 +
>>  drivers/staging/ti-st/fmdrv_v4l2.c   |  757 ++++++++++++
>>  drivers/staging/ti-st/fmdrv_v4l2.h   |   32 +
>>  11 files changed, 5195 insertions(+), 0 deletions(-)
>
> Usually when a driver is added to staging, it should also have a TODO
> file specifying what needs to be done before the driver can be taken
> out of staging (at least as far as the author knows of today).
>
> It helps keeping track of the open issues in the driver, which is good
> for everyone - the author, the random contributor/observer, and
> probably even the staging maintainer.
>
> Can you please add such a TODO file ?
>
> Thanks,
> Ohad.

Thanks Ohad, for the comments, We do have an internal TODO.
In terms of functionality we have stuff like TX RDS which already has
few CIDs in the extended controls.
extend V4L2 for complete-scan, add in stop search during hw_seek .. etc...
But I just wanted to ask whether this is good enough to be staged.
Because as we begin to implement and add in the items in TODO - the
patch set will keep continuing to grow.

So Hans, Mauro, What do you think ?
It would be real helpful - if this can be staged, it is becoming
difficult to maintain for us.

Thanks,
Pavan

>>  create mode 100644 drivers/staging/ti-st/fmdrv.h
>>  create mode 100644 drivers/staging/ti-st/fmdrv_common.c
>>  create mode 100644 drivers/staging/ti-st/fmdrv_common.h
>>  create mode 100644 drivers/staging/ti-st/fmdrv_rx.c
>>  create mode 100644 drivers/staging/ti-st/fmdrv_rx.h
>>  create mode 100644 drivers/staging/ti-st/fmdrv_tx.c
>>  create mode 100644 drivers/staging/ti-st/fmdrv_tx.h
>>  create mode 100644 drivers/staging/ti-st/fmdrv_v4l2.c
>>  create mode 100644 drivers/staging/ti-st/fmdrv_v4l2.h
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>> the body of a message to [email protected]
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>> Please read the FAQ at  http://www.tux.org/lkml/
>>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>
>
>

2010-11-18 07:17:49

by Hans Verkuil

[permalink] [raw]
Subject: Re: [PATCH v4 0/6] FM V4L2 drivers for WL128x

On Thursday, November 18, 2010 06:54:16 Pavan Savoy wrote:
> Hans, Mauro, Ohad,
>
> On Wed, Nov 17, 2010 at 6:32 PM, Ohad Ben-Cohen <[email protected]> wrote:
> > Hi Manjunatha,
> >
> > On Tue, Nov 16, 2010 at 3:18 PM, <[email protected]> wrote:
> >> drivers/staging/ti-st/Kconfig | 10 +
> >> drivers/staging/ti-st/Makefile | 2 +
> >> drivers/staging/ti-st/fmdrv.h | 259 ++++
> >> drivers/staging/ti-st/fmdrv_common.c | 2141 ++++++++++++++++++++++++++++++++++
> >> drivers/staging/ti-st/fmdrv_common.h | 458 ++++++++
> >> drivers/staging/ti-st/fmdrv_rx.c | 979 ++++++++++++++++
> >> drivers/staging/ti-st/fmdrv_rx.h | 59 +
> >> drivers/staging/ti-st/fmdrv_tx.c | 461 ++++++++
> >> drivers/staging/ti-st/fmdrv_tx.h | 37 +
> >> drivers/staging/ti-st/fmdrv_v4l2.c | 757 ++++++++++++
> >> drivers/staging/ti-st/fmdrv_v4l2.h | 32 +
> >> 11 files changed, 5195 insertions(+), 0 deletions(-)
> >
> > Usually when a driver is added to staging, it should also have a TODO
> > file specifying what needs to be done before the driver can be taken
> > out of staging (at least as far as the author knows of today).
> >
> > It helps keeping track of the open issues in the driver, which is good
> > for everyone - the author, the random contributor/observer, and
> > probably even the staging maintainer.
> >
> > Can you please add such a TODO file ?
> >
> > Thanks,
> > Ohad.
>
> Thanks Ohad, for the comments, We do have an internal TODO.
> In terms of functionality we have stuff like TX RDS which already has
> few CIDs in the extended controls.
> extend V4L2 for complete-scan, add in stop search during hw_seek .. etc...
> But I just wanted to ask whether this is good enough to be staged.
> Because as we begin to implement and add in the items in TODO - the
> patch set will keep continuing to grow.
>
> So Hans, Mauro, What do you think ?
> It would be real helpful - if this can be staged, it is becoming
> difficult to maintain for us.

I have no problem with it going to staging. It is not yet ready for the
mainline. I'll try to do a quick review and point out what needs to be
changed.

Regards,

Hans

--
Hans Verkuil - video4linux developer - sponsored by Cisco

2010-11-18 07:44:41

by Hans Verkuil

[permalink] [raw]
Subject: Re: [PATCH v4 1/6] drivers:staging: ti-st: fmdrv common header file

On Tuesday, November 16, 2010 14:18:09 [email protected] wrote:
> From: Manjunatha Halli <[email protected]>
>
> These are common headers used in FM submodules (FM V4L2, FM common,
> FM Rx,and FM TX).
>
> Signed-off-by: Manjunatha Halli <[email protected]>
> ---
> drivers/staging/ti-st/fmdrv.h | 259 +++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 259 insertions(+), 0 deletions(-)
> create mode 100644 drivers/staging/ti-st/fmdrv.h
>
> diff --git a/drivers/staging/ti-st/fmdrv.h b/drivers/staging/ti-st/fmdrv.h
> new file mode 100644
> index 0000000..68ed44c
> --- /dev/null
> +++ b/drivers/staging/ti-st/fmdrv.h
> @@ -0,0 +1,259 @@
> +/*
> + * FM Driver for Connectivity chip of Texas Instruments.
> + *
> + * Common header for all FM driver sub-modules.
> + *
> + * Copyright (C) 2009 Texas Instruments
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> + *
> + */
> +
> +#ifndef _FM_DRV_H
> +#define _FM_DRV_H
> +
> +#include <linux/skbuff.h>
> +#include <linux/interrupt.h>
> +#include <sound/core.h>
> +#include <sound/initval.h>
> +#include <linux/timer.h>
> +#include <linux/version.h>
> +
> +#define FM_DRV_VERSION "0.01"
> +/* Should match with FM_DRV_VERSION */
> +#define FM_DRV_RADIO_VERSION KERNEL_VERSION(0, 0, 1)
> +#define FM_DRV_NAME "ti_fmdrv"
> +#define FM_DRV_CARD_SHORT_NAME "TI FM Radio"
> +#define FM_DRV_CARD_LONG_NAME "Texas Instruments FM Radio"
> +
> +/* Flag info */
> +#define FM_INTTASK_RUNNING 0
> +#define FM_INTTASK_SCHEDULE_PENDING 1
> +#define FM_FIRMWARE_DW_INPROGRESS 2
> +#define FM_CORE_READY 3
> +#define FM_CORE_TRANSPORT_READY 4
> +#define FM_AF_SWITCH_INPROGRESS 5
> +#define FM_CORE_TX_XMITING 6
> +
> +#define FM_TUNE_COMPLETE 0x1
> +#define FM_BAND_LIMIT 0x2
> +
> +#define FM_DRV_TX_TIMEOUT (5*HZ) /* 5 seconds */
> +#define FM_DRV_RX_SEEK_TIMEOUT (20*HZ) /* 20 seconds */
> +
> +#define NO_OF_ENTRIES_IN_ARRAY(array) (sizeof(array) / sizeof(array[0]))
> +
> +enum {
> + FM_MODE_OFF,
> + FM_MODE_TX,
> + FM_MODE_RX,
> + FM_MODE_ENTRY_MAX
> +};
> +
> +#define FM_RX_RDS_INFO_FIELD_MAX 8 /* 4 Group * 2 Bytes */
> +
> +/* TODO:
> + * move the following CIDs to videodev2.h upon acceptance
> + */
> +#define V4L2_CTRL_CLASS_FM_RX 0x009c0000 /* FM Tuner control class */
> +/* FM Tuner class control IDs */
> +#define V4L2_CID_FM_RX_CLASS_BASE (V4L2_CTRL_CLASS_FM_RX | 0x900)
> +#define V4L2_CID_FM_RX_CLASS (V4L2_CTRL_CLASS_FM_RX | 1)
> +#define V4L2_CID_RSSI_THRESHOLD (V4L2_CID_FM_RX_CLASS_BASE + 2)
> +#define V4L2_CID_TUNE_AF (V4L2_CID_FM_RX_CLASS_BASE + 3)

Please post an RFC describing these new controls.

> +enum v4l2_tune_af {
> + V4L2_FM_AF_OFF = 0,
> + V4L2_FM_AF_ON = 1
> +};

Huh? If it is an on/off type of controls, then it should be a boolean.

> +#define V4L2_CID_FM_BAND (V4L2_CID_FM_RX_CLASS_BASE + 1)
> +enum v4l2_fm_band {
> + V4L2_FM_BAND_OTHER = 0,
> + V4L2_FM_BAND_JAPAN = 1,
> + V4L2_FM_BAND_OIRT = 2

This was proposed and rejected for the wl1273 driver. Instead the driver should
hide this complexity. See the wl1273 driver.

> +};
> +
> +/*
> + * define private CIDs for V4L2
> + */
> +#define V4L2_CID_CHANNEL_SPACING (V4L2_CID_PRIVATE_BASE + 0)

The wl1273 driver has defined a new standard channel spacing control. So that
should be used.

> +
> +/* RX RDS data format */
> +struct fm_rdsdata_format {
> + union {
> + struct {
> + unsigned char rdsbuff[FM_RX_RDS_INFO_FIELD_MAX];
> + } groupdatabuff;
> + struct {
> + unsigned short pidata;
> + unsigned char block_b_byte1;
> + unsigned char block_b_byte2;
> + unsigned char block_c_byte1;
> + unsigned char block_c_byte2;
> + unsigned char block_d_byte1;
> + unsigned char block_d_byte2;
> + } groupgeneral;
> + struct {
> + unsigned short pidata;
> + unsigned char block_b_byte1;
> + unsigned char block_b_byte2;
> + unsigned char firstaf;
> + unsigned char secondaf;
> + unsigned char firstpsbyte;
> + unsigned char secondpsbyte;
> + } group0A;
> +
> + struct {
> + unsigned short pidata;
> + unsigned char block_b_byte1;
> + unsigned char block_b_byte2;
> + unsigned short pidata2;
> + unsigned char firstpsbyte;
> + unsigned char secondpsbyte;
> + } group0B;
> + } rdsdata;
> +};
> +
> +/* FM region (Europe/US, Japan) info */
> +struct region_info {
> + unsigned int channel_spacing;
> + unsigned int bottom_frequency;
> + unsigned int top_frequency;
> + unsigned char region_index;
> +};
> +
> +typedef void (*int_handler_prototype) (void *);
> +
> +/* FM Interrupt processing related info */
> +struct fm_irq {
> + unsigned char stage_index;
> + unsigned short flag; /* FM interrupt flag */
> + unsigned short mask; /* FM interrupt mask */
> + /* Interrupt process timeout handler */
> + struct timer_list int_timeout_timer;
> + unsigned char irq_service_timeout_retry;
> + int_handler_prototype *fm_int_handlers;
> +};
> +
> +/* RDS info */
> +struct fm_rds {
> + unsigned char flag; /* RX RDS on/off status */
> + unsigned char last_block_index; /* Last received RDS block */
> +
> + /* RDS buffer */
> + wait_queue_head_t read_queue;
> + unsigned int buf_size; /* Size is always multiple of 3 */
> + unsigned int wr_index;
> + unsigned int rd_index;
> + unsigned char *buffer;
> +};
> +
> +#define FM_RDS_MAX_AF_LIST 25
> +
> +/*
> + * Current RX channel Alternate Frequency cache.
> + * This info is used to switch to other freq (AF)
> + * when current channel signal strengh is below RSSI threshold.
> + */
> +struct tuned_station_info {
> + unsigned short picode;
> + unsigned int af_cache[FM_RDS_MAX_AF_LIST];
> + unsigned char no_of_items_in_afcache;
> + unsigned char af_list_max;
> +};
> +
> +/* FM RX mode info */
> +struct fm_rx {
> + struct region_info region; /* Current selected band */
> + unsigned int curr_freq; /* Current RX frquency */
> + unsigned char curr_mute_mode; /* Current mute mode */
> + unsigned char curr_deemphasis_mode; /* Current deemphasis mode */
> + /* RF dependent soft mute mode */
> + unsigned char curr_rf_depend_mute;
> + unsigned short curr_volume; /* Current volume level */
> + short curr_rssi_threshold; /* Current RSSI threshold level */
> + /* Holds the index of the current AF jump */
> + unsigned char cur_afjump_index;
> + /* Will hold the frequency before the jump */
> + unsigned int freq_before_jump;
> + unsigned char rds_mode; /* RDS operation mode (RDS/RDBS) */
> + unsigned char af_mode; /* Alternate frequency on/off */
> + struct tuned_station_info cur_station_info;
> + struct fm_rds rds;
> +};
> +
> +/*
> + * FM TX RDS data
> + *
> + * @ text_type: is the text following PS or RT
> + * @ text: radio text string which could either be PS or RT
> + * @ af_freq: alternate frequency for Tx
> + * TODO: to be declared in application
> + */
> +struct tx_rds {
> + unsigned char text_type;
> + unsigned char text[25];
> + unsigned char flag;
> + unsigned int af_freq;
> +};
> +/*
> + * FM TX global data
> + *
> + * @ pwr_lvl: Power Level of the Transmission from mixer control
> + * @ xmit_state: Transmission state = Updated locally upon Start/Stop
> + * @ audio_io: i2S/Analog
> + * @ tx_frq: Transmission frequency
> + */
> +struct fmtx_data {
> + unsigned char pwr_lvl;
> + unsigned char xmit_state;
> + unsigned char audio_io;
> + unsigned char region;
> + unsigned short aud_mode;
> + unsigned int preemph;
> + unsigned long tx_frq;
> + struct tx_rds rds;
> +};
> +
> +/* FM driver operation structure */
> +struct fmdrv_ops {
> + struct video_device *radio_dev; /* V4L2 video device pointer */
> + struct snd_card *card; /* Card which holds FM mixer controls */
> + unsigned short asci_id;
> + spinlock_t rds_buff_lock; /* To protect access to RDS buffer */
> + spinlock_t resp_skb_lock; /* To protect access to received SKB */
> +
> + long flag; /* FM driver state machine info */
> + char streg_cbdata; /* status of ST registration */
> +
> + struct sk_buff_head rx_q; /* RX queue */
> + struct tasklet_struct rx_task; /* RX Tasklet */
> +
> + struct sk_buff_head tx_q; /* TX queue */
> + struct tasklet_struct tx_task; /* TX Tasklet */
> + unsigned long last_tx_jiffies; /* Timestamp of last pkt sent */
> + atomic_t tx_cnt; /* Number of packets can send at a time */
> +
> + struct sk_buff *response_skb; /* Response from the chip */
> + /* Main task completion handler */
> + struct completion maintask_completion;
> + /* Opcode of last command sent to the chip */
> + unsigned char last_sent_pkt_opcode;
> + /* Handler used for wakeup when response packet is received */
> + struct completion *response_completion;
> + struct fm_irq irq_info;
> + unsigned char curr_fmmode; /* Current FM chip mode (TX, RX, OFF) */
> + struct fm_rx rx; /* FM receiver info */
> + struct fmtx_data tx_data;
> +};
> +#endif
>

--
Hans Verkuil - video4linux developer - sponsored by Cisco

2010-11-18 07:49:15

by Hans Verkuil

[permalink] [raw]
Subject: Re: [PATCH v4 2/6] drivers:staging: ti-st: fmdrv_v4l2 sources

On Tuesday, November 16, 2010 14:18:10 [email protected] wrote:
> From: Manjunatha Halli <[email protected]>
>
> This module interfaces V4L2 subsystem and FM common
> module. It registers itself with V4L2 as Radio module.
>
> Signed-off-by: Manjunatha Halli <[email protected]>
> ---
> drivers/staging/ti-st/fmdrv_v4l2.c | 757 ++++++++++++++++++++++++++++++++++++
> drivers/staging/ti-st/fmdrv_v4l2.h | 32 ++
> 2 files changed, 789 insertions(+), 0 deletions(-)
> create mode 100644 drivers/staging/ti-st/fmdrv_v4l2.c
> create mode 100644 drivers/staging/ti-st/fmdrv_v4l2.h
>
> diff --git a/drivers/staging/ti-st/fmdrv_v4l2.c b/drivers/staging/ti-st/fmdrv_v4l2.c
> new file mode 100644
> index 0000000..687d10f
> --- /dev/null
> +++ b/drivers/staging/ti-st/fmdrv_v4l2.c
> @@ -0,0 +1,757 @@
> +/*
> + * FM Driver for Connectivity chip of Texas Instruments.
> + * This file provides interfaces to V4L2 subsystem.
> + *
> + * This module registers with V4L2 subsystem as Radio
> + * data system interface (/dev/radio). During the registration,
> + * it will expose two set of function pointers.
> + *
> + * 1) File operation related API (open, close, read, write, poll...etc).
> + * 2) Set of V4L2 IOCTL complaint API.
> + *
> + * Copyright (C) 2010 Texas Instruments
> + * Author: Raja Mani <[email protected]>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> + *
> + */
> +
> +#include "fmdrv.h"
> +#include "fmdrv_v4l2.h"
> +#include "fmdrv_common.h"
> +#include "fmdrv_rx.h"
> +#include "fmdrv_tx.h"
> +
> +static struct video_device *gradio_dev;
> +static unsigned char radio_disconnected;
> +
> +/* Query control */
> +static struct v4l2_queryctrl fmdrv_v4l2_queryctrl[] = {
> + {
> + .id = V4L2_CID_AUDIO_VOLUME,
> + .type = V4L2_CTRL_TYPE_INTEGER,
> + .name = "Volume",
> + .minimum = FM_RX_VOLUME_MIN,
> + .maximum = FM_RX_VOLUME_MAX,
> + .step = 1,
> + .default_value = FM_DEFAULT_RX_VOLUME,
> + },
> + {
> + .id = V4L2_CID_AUDIO_BALANCE,
> + .flags = V4L2_CTRL_FLAG_DISABLED,
> + },
> + {
> + .id = V4L2_CID_AUDIO_BASS,
> + .flags = V4L2_CTRL_FLAG_DISABLED,
> + },
> + {
> + .id = V4L2_CID_AUDIO_TREBLE,
> + .flags = V4L2_CTRL_FLAG_DISABLED,
> + },
> + {
> + .id = V4L2_CID_AUDIO_MUTE,
> + .type = V4L2_CTRL_TYPE_BOOLEAN,
> + .name = "Mute",
> + .minimum = 0,
> + .maximum = 2,
> + .step = 1,
> + .default_value = FM_MUTE_OFF,
> + },
> + {
> + .id = V4L2_CID_AUDIO_LOUDNESS,
> + .flags = V4L2_CTRL_FLAG_DISABLED,
> + },
> +};

Please use the control framework. See Documentation/video4linux/v4l2-controls.txt.
It's much easier to use and should be used for new drivers.

Regards,

Hans

--
Hans Verkuil - video4linux developer - sponsored by Cisco

2010-11-18 08:19:35

by Hans Verkuil

[permalink] [raw]
Subject: Re: [PATCH v4 3/6] drivers:staging: ti-st: fmdrv_common sources

On Tuesday, November 16, 2010 14:18:11 [email protected] wrote:
> From: Manjunatha Halli <[email protected]>
>
> These are the sources for the common interfaces required by the FM
> V4L2 driver for TI WL127x and WL128x chips.
>
> These implement the FM channel-8 protocol communication with
> the chip. This makes use of the Shared Transport as its transport.
>
> Signed-off-by: Manjunatha Halli <[email protected]>
> ---
> drivers/staging/ti-st/fmdrv_common.c | 2141 ++++++++++++++++++++++++++++++++++
> drivers/staging/ti-st/fmdrv_common.h | 458 ++++++++
> 2 files changed, 2599 insertions(+), 0 deletions(-)
> create mode 100644 drivers/staging/ti-st/fmdrv_common.c
> create mode 100644 drivers/staging/ti-st/fmdrv_common.h
>
> diff --git a/drivers/staging/ti-st/fmdrv_common.c b/drivers/staging/ti-st/fmdrv_common.c
> new file mode 100644
> index 0000000..7b8f2da
> --- /dev/null
> +++ b/drivers/staging/ti-st/fmdrv_common.c
> @@ -0,0 +1,2141 @@
> +/*
> + * FM Driver for Connectivity chip of Texas Instruments.
> + *
> + * This sub-module of FM driver is common for FM RX and TX
> + * functionality. This module is responsible for:
> + * 1) Forming group of Channel-8 commands to perform particular
> + * functionality (eg., frequency set require more than
> + * one Channel-8 command to be sent to the chip).
> + * 2) Sending each Channel-8 command to the chip and reading
> + * response back over Shared Transport.
> + * 3) Managing TX and RX Queues and Tasklets.
> + * 4) Handling FM Interrupt packet and taking appropriate action.
> + * 5) Loading FM firmware to the chip (common, FM TX, and FM RX
> + * firmware files based on mode selection)
> + *
> + * Copyright (C) 2010 Texas Instruments
> + * Author: Raja Mani <[email protected]>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> + *
> + */
> +
> +#include <linux/module.h>
> +#include <linux/firmware.h>
> +#include <linux/delay.h>
> +#include "fmdrv.h"
> +#include "fmdrv_v4l2.h"
> +#include "fmdrv_common.h"
> +#include <linux/ti_wilink_st.h>
> +#include "fmdrv_rx.h"
> +#include "fmdrv_tx.h"
> +
> +/* FM chip register table */
> +static struct fm_reg_table fm_reg_info[] = {
> + /* ----- FM RX registers -------*/
> + /* opcode, type(rd/wr), reg name */
> + {0x00, REG_RD, "STEREO_GET"},
> + {0x01, REG_RD, "RSSI_LVL_GET"},
> + {0x02, REG_RD, "IF_COUNT_GET"},
> + {0x03, REG_RD, "FLAG_GET"},
> + {0x04, REG_RD, "RDS_SYNC_GET"},
> + {0x05, REG_RD, "RDS_DATA_GET"},
> + {0x0a, REG_WR, "FREQ_SET"},
> + {0x0a, REG_RD, "FREQ_GET"},
> + {0x0b, REG_WR, "AF_FREQ_SET"},
> + {0x0b, REG_RD, "AF_FREQ_GET"},
> + {0x0c, REG_WR, "MOST_MODE_SET"},
> + {0x0c, REG_RD, "MOST_MODE_GET"},
> + {0x0d, REG_WR, "MOST_BLEND_SET"},
> + {0x0d, REG_RD, "MOST_BLEND_GET"},
> + {0x0e, REG_WR, "DEMPH_MODE_SET"},
> + {0x0e, REG_RD, "DEMPH_MODE_GET"},
> + {0x0f, REG_WR, "SEARCH_LVL_SET"},
> + {0x0f, REG_RD, "SEARCH_LVL_GET"},
> + {0x10, REG_WR, "RX_BAND_SET"},
> + {0x10, REG_RD, "RX_BAND_GET"},
> + {0x11, REG_WR, "MUTE_STATUS_SET"},
> + {0x11, REG_RD, "MUTE_STATUS_GET"},
> + {0x12, REG_WR, "RDS_PAUSE_LVL_SET"},
> + {0x12, REG_RD, "RDS_PAUSE_LVL_GET"},
> + {0x13, REG_WR, "RDS_PAUSE_DUR_SET"},
> + {0x13, REG_RD, "RDS_PAUSE_DUR_GET"},
> + {0x14, REG_WR, "RDS_MEM_SET"},
> + {0x14, REG_RD, "RDS_MEM_GET"},
> + {0x15, REG_WR, "RDS_BLK_B_SET"},
> + {0x15, REG_RD, "RDS_BLK_B_GET"},
> + {0x16, REG_WR, "RDS_MSK_B_SET"},
> + {0x16, REG_RD, "RDS_MSK_B_GET"},
> + {0x17, REG_WR, "RDS_PI_MASK_SET"},
> + {0x17, REG_RD, "RDS_PI_MASK_GET"},
> + {0x18, REG_WR, "RDS_PI_SET"},
> + {0x18, REG_RD, "RDS_PI_GET"},
> + {0x19, REG_WR, "RDS_SYSTEM_SET"},
> + {0x19, REG_RD, "RDS_SYSTEM_GET"},
> + {0x1a, REG_WR, "INT_MASK_SET"},
> + {0x1a, REG_RD, "INT_MASK_GET"},
> + {0x1b, REG_WR, "SRCH_DIR_SET"},
> + {0x1b, REG_RD, "SRCH_DIR_GET"},
> + {0x1c, REG_WR, "VOLUME_SET"},
> + {0x1c, REG_RD, "VOLUME_GET"},
> + {0x1d, REG_WR, "AUDIO_ENABLE(SET)"},
> + {0x1d, REG_RD, "AUDIO_ENABLE(GET)"},
> + {0x1e, REG_WR, "PCM_MODE_SET"},
> + {0x1e, REG_RD, "PCM_MODE_SET"},
> + {0x1f, REG_WR, "I2S_MD_CFG_SET"},
> + {0x1f, REG_RD, "I2S_MD_CFG_GET"},
> + {0x20, REG_WR, "POWER_SET"},
> + {0x20, REG_RD, "POWER_GET"},
> + {0x21, REG_WR, "INTx_CONFIG_SET"},
> + {0x21, REG_RD, "INTx_CONFIG_GET"},
> + {0x22, REG_WR, "PULL_EN_SET"},
> + {0x22, REG_RD, "PULL_EN_GET"},
> + {0x23, REG_WR, "HILO_SET"},
> + {0x23, REG_RD, "HILO_GET"},
> + {0x24, REG_WR, "SWITCH2FREF"},
> + {0x25, REG_WR, "FREQ_DRIFT_REP"},
> + {0x28, REG_RD, "PCE_GET"},
> + {0x29, REG_RD, "FIRM_VER_GET"},
> + {0x2a, REG_RD, "ASIC_VER_GET"},
> + {0x2b, REG_RD, "ASIC_ID_GET"},
> + {0x2c, REG_RD, "MAIN_ID_GET"},
> + {0x2d, REG_WR, "TUNER_MODE_SET"},
> + {0x2e, REG_WR, "STOP_SEARCH"},
> + {0x2f, REG_WR, "RDS_CNTRL_SET"},
> + {0x64, REG_WR, "WR_HW_REG"},
> + {0x65, REG_WR, "CODE_DOWNLOAD"},
> + {0x66, REG_WR, "RESET"},
> + {0xfe, REG_WR, "FM_POWER_MODE(SET)"},
> + {0xff, REG_RD, "FM_INTERRUPT"},
> +
> + /* --- FM TX registers ------ */
> + {0x37, REG_WR, "CHANL_SET"},
> + {0x37, REG_RD, "CHANL_GET"},
> + {0x38, REG_WR, "CHANL_BW_SET"},
> + {0x38, REG_RD, "CHANL_BW_GET"},
> + {0x87, REG_WR, "REF_SET"},
> + {0x87, REG_RD, "REF_GET"},
> + {0x5a, REG_WR, "POWER_ENB_SET"},
> + {0x3a, REG_WR, "POWER_ATT_SET"},
> + {0x3a, REG_RD, "POWER_ATT_GET"},
> + {0x3b, REG_WR, "POWER_LEL_SET"},
> + {0x3b, REG_RD, "POWER_LEL_GET"},
> + {0x3c, REG_WR, "AUDIO_DEV_SET"},
> + {0x3c, REG_RD, "AUDIO_DEV_GET"},
> + {0x3d, REG_WR, "PILOT_DEV_SET"},
> + {0x3d, REG_RD, "PILOT_DEV_GET"},
> + {0x3e, REG_WR, "RDS_DEV_SET"},
> + {0x3e, REG_RD, "RDS_DEV_GET"},
> + {0x5b, REG_WR, "PUPD_SET"},
> + {0x3f, REG_WR, "AUDIO_IO_SET"},
> + {0x40, REG_WR, "PREMPH_SET"},
> + {0x40, REG_RD, "PREMPH_GET"},
> + {0x41, REG_WR, "TX_BAND_SET"},
> + {0x41, REG_RD, "TX_BAND_GET"},
> + {0x42, REG_WR, "MONO_SET"},
> + {0x42, REG_RD, "MONO_GET"},
> + {0x5C, REG_WR, "MUTE"},
> + {0x43, REG_WR, "MPX_LMT_ENABLE"},
> + {0x06, REG_RD, "LOCK_GET"},
> + {0x5d, REG_WR, "REF_ERR_SET"},
> + {0x44, REG_WR, "PI_SET"},
> + {0x44, REG_RD, "PI_GET"},
> + {0x45, REG_WR, "TYPE_SET"},
> + {0x45, REG_RD, "TYPE_GET"},
> + {0x46, REG_WR, "PTY_SET"},
> + {0x46, REG_RD, "PTY_GET"},
> + {0x47, REG_WR, "AF_SET"},
> + {0x47, REG_RD, "AF_GET"},
> + {0x48, REG_WR, "DISPLAY_SIZE_SET"},
> + {0x48, REG_RD, "DISPLAY_SIZE_GET"},
> + {0x49, REG_WR, "RDS_MODE_SET"},
> + {0x49, REG_RD, "RDS_MODE_GET"},
> + {0x4a, REG_WR, "DISPLAY_MODE_SET"},
> + {0x4a, REG_RD, "DISPLAY_MODE_GET"},
> + {0x62, REG_WR, "LENGTH_SET"},
> + {0x4b, REG_RD, "LENGTH_GET"},
> + {0x4c, REG_WR, "TOGGLE_AB_SET"},
> + {0x4c, REG_RD, "TOGGLE_AB_GET"},
> + {0x4d, REG_WR, "RDS_REP_SET"},
> + {0x4d, REG_RD, "RDS_REP_GET"},
> + {0x63, REG_WR, "RDS_DATA_SET"},
> + {0x5e, REG_WR, "RDS_DATA_ENB"},
> + {0x4e, REG_WR, "TA_SET"},
> + {0x4e, REG_RD, "TA_GET"},
> + {0x4f, REG_WR, "TP_SET"},
> + {0x4f, REG_RD, "TP_GET"},
> + {0x50, REG_WR, "DI_SET"},
> + {0x50, REG_RD, "DI_GET"},
> + {0x51, REG_WR, "MS_SET"},
> + {0x51, REG_RD, "MS_GET"},
> + {0x52, REG_WR, "PS_SCROLL_SPEED_SET"},
> + {0x52, REG_RD, "PS_SCROLL_SPEED_GET"},
> + {0x57, REG_WR, "ANT_IMP_SET"},
> + {0x57, REG_RD, "ANT_IMP_GET"},

This array seems way overkill. The name is not used at all, so why waste the
space? Make it a comment instead.

It is also a bit weird: the enum fm_reg_index maps into this array and is
used to obtain the opcode, which looks suspiciously like a register address
to me. Are you sure you shouldn't be using the opcode directly?

> +};
> +
> +/* Region info */
> +static struct region_info region_configs[] = {
> + /* Europe/US */
> + {
> + .channel_spacing = FM_CHANNEL_SPACING_50KHZ * FM_FREQ_MUL,
> + .bottom_frequency = 87500, /* 87.5 MHz */
> + .top_frequency = 108000, /* 108 MHz */
> + .region_index = 0,
> + },
> + /* Japan */
> + {
> + .channel_spacing = FM_CHANNEL_SPACING_50KHZ * FM_FREQ_MUL,
> + .bottom_frequency = 76000, /* 76 MHz */
> + .top_frequency = 90000, /* 90 MHz */
> + .region_index = 1,
> + },
> +};
> +
> +/* Band selection */
> +static unsigned char default_radio_region; /* Europe/US */
> +module_param(default_radio_region, byte, 0);
> +MODULE_PARM_DESC(default_radio_region, "Region: 0=Europe/US, 1=Japan");
> +
> +/* RDS buffer blocks */
> +static unsigned int default_rds_buf = 300;
> +module_param(default_rds_buf, uint, 0444);
> +MODULE_PARM_DESC(rds_buf, "RDS buffer entries");
> +
> +/* Radio Nr */
> +static int radio_nr = -1;
> +module_param(radio_nr, int, 0444);
> +MODULE_PARM_DESC(radio_nr, "Radio Nr");
> +
> +/* FM irq handlers forward declaration */
> +static void fm_irq_send_flag_getcmd(void *);
> +static void fm_irq_handle_flag_getcmd_resp(void *);
> +static void fm_irq_handle_hw_malfunction(void *);
> +static void fm_irq_handle_rds_start(void *);
> +static void fm_irq_send_rdsdata_getcmd(void *);
> +static void fm_irq_handle_rdsdata_getcmd_resp(void *);
> +static void fm_irq_handle_rds_finish(void *);
> +static void fm_irq_handle_tune_op_ended(void *);
> +static void fm_irq_handle_power_enb(void *);
> +static void fm_irq_handle_low_rssi_start(void *);
> +static void fm_irq_afjump_set_pi(void *);
> +static void fm_irq_handle_set_pi_resp(void *);
> +static void fm_irq_afjump_set_pimask(void *);
> +static void fm_irq_handle_set_pimask_resp(void *);
> +static void fm_irq_afjump_setfreq(void *);
> +static void fm_irq_handle_setfreq_resp(void *);
> +static void fm_irq_afjump_enableint(void *);
> +static void fm_irq_afjump_enableint_resp(void *);
> +static void fm_irq_start_afjump(void *);
> +static void fm_irq_handle_start_afjump_resp(void *);
> +static void fm_irq_afjump_rd_freq(void *);
> +static void fm_irq_afjump_rd_freq_resp(void *);
> +static void fm_irq_handle_low_rssi_finish(void *);
> +static void fm_irq_send_intmsk_cmd(void *);
> +static void fm_irq_handle_intmsk_cmd_resp(void *);
> +
> +/*
> + * When FM common module receives interrupt packet, following handlers
> + * will be executed one after another to service the interrupt(s)
> + */
> +enum fmc_irq_handler_index {
> + FM_SEND_FLAG_GETCMD_INDEX,
> + FM_HANDLE_FLAG_GETCMD_RESP_INDEX,
> +
> + /* HW malfunction irq handler */
> + FM_HW_MAL_FUNC_INDEX,
> +
> + /* RDS threshold reached irq handler */
> + FM_RDS_START_INDEX,
> + FM_RDS_SEND_RDS_GETCMD_INDEX,
> + FM_RDS_HANDLE_RDS_GETCMD_RESP_INDEX,
> + FM_RDS_FINISH_INDEX,
> +
> + /* Tune operation ended irq handler */
> + FM_HW_TUNE_OP_ENDED_INDEX,
> +
> + /* TX power enable irq handler */
> + FM_HW_POWER_ENB_INDEX,
> +
> + /* Low RSSI irq handler */
> + FM_LOW_RSSI_START_INDEX,
> + FM_AF_JUMP_SETPI_INDEX,
> + FM_AF_JUMP_HANDLE_SETPI_RESP_INDEX,
> + FM_AF_JUMP_SETPI_MASK_INDEX,
> + FM_AF_JUMP_HANDLE_SETPI_MASK_RESP_INDEX,
> + FM_AF_JUMP_SET_AF_FREQ_INDEX,
> + FM_AF_JUMP_HENDLE_SET_AFFREQ_RESP_INDEX,
> + FM_AF_JUMP_ENABLE_INT_INDEX,
> + FM_AF_JUMP_ENABLE_INT_RESP_INDEX,
> + FM_AF_JUMP_START_AFJUMP_INDEX,
> + FM_AF_JUMP_HANDLE_START_AFJUMP_RESP_INDEX,
> + FM_AF_JUMP_RD_FREQ_INDEX,
> + FM_AF_JUMP_RD_FREQ_RESP_INDEX,
> + FM_LOW_RSSI_FINISH_INDEX,
> +
> + /* Interrupt process post action */
> + FM_SEND_INTMSK_CMD_INDEX,
> + FM_HANDLE_INTMSK_CMD_RESP_INDEX,
> +};
> +
> +/* FM interrupt handler table */
> +static int_handler_prototype g_IntHandlerTable[] = {
> + fm_irq_send_flag_getcmd,
> + fm_irq_handle_flag_getcmd_resp,
> + fm_irq_handle_hw_malfunction,
> + fm_irq_handle_rds_start, /* RDS threshold reached irq handler */
> + fm_irq_send_rdsdata_getcmd,
> + fm_irq_handle_rdsdata_getcmd_resp,
> + fm_irq_handle_rds_finish,
> + fm_irq_handle_tune_op_ended,
> + fm_irq_handle_power_enb, /* TX power enable irq handler */
> + fm_irq_handle_low_rssi_start,
> + fm_irq_afjump_set_pi,
> + fm_irq_handle_set_pi_resp,
> + fm_irq_afjump_set_pimask,
> + fm_irq_handle_set_pimask_resp,
> + fm_irq_afjump_setfreq,
> + fm_irq_handle_setfreq_resp,
> + fm_irq_afjump_enableint,
> + fm_irq_afjump_enableint_resp,
> + fm_irq_start_afjump,
> + fm_irq_handle_start_afjump_resp,
> + fm_irq_afjump_rd_freq,
> + fm_irq_afjump_rd_freq_resp,
> + fm_irq_handle_low_rssi_finish,
> + fm_irq_send_intmsk_cmd, /* Interrupt process post action */
> + fm_irq_handle_intmsk_cmd_resp
> +};
> +
> +long (*g_st_write) (struct sk_buff *skb);
> +static struct completion wait_for_fmdrv_reg_comp;
> +
> +#ifdef FM_DUMP_TXRX_PKT
> + /* To dump outgoing FM Channel-8 packets */
> +inline void dump_tx_skb_data(struct sk_buff *skb)
> +{
> + int len, len_org;
> + char index;
> + struct fm_cmd_msg_hdr *cmd_hdr;
> +
> + cmd_hdr = (struct fm_cmd_msg_hdr *)skb->data;
> + printk(KERN_INFO "<<%shdr:%02x len:%02x opcode:%02x type:%s dlen:%02x",
> + fm_cb(skb)->completion ? " " : "*", cmd_hdr->header,
> + cmd_hdr->len, cmd_hdr->fm_opcode,
> + cmd_hdr->rd_wr ? "RD" : "WR", cmd_hdr->dlen);
> +
> + len_org = skb->len - FM_CMD_MSG_HDR_SIZE;
> + if (len_org > 0) {
> + printk("\n data(%d): ", cmd_hdr->dlen);
> + len = min(len_org, 14);
> + for (index = 0; index < len; index++)
> + printk("%x ",
> + skb->data[FM_CMD_MSG_HDR_SIZE + index]);
> + printk("%s", (len_org > 14) ? ".." : "");
> + }
> + printk("\n");
> +}
> +
> + /* To dump incoming FM Channel-8 packets */
> +inline void dump_rx_skb_data(struct sk_buff *skb)
> +{
> + int len, len_org;
> + char index;
> + struct fm_event_msg_hdr *evt_hdr;
> +
> + evt_hdr = (struct fm_event_msg_hdr *)skb->data;
> + printk(KERN_INFO ">> hdr:%02x len:%02x sts:%02x numhci:%02x "
> + "opcode:%02x type:%s dlen:%02x", evt_hdr->header, evt_hdr->len,
> + evt_hdr->status, evt_hdr->num_fm_hci_cmds, evt_hdr->fm_opcode,
> + (evt_hdr->rd_wr) ? "RD" : "WR", evt_hdr->dlen);
> +
> + len_org = skb->len - FM_EVT_MSG_HDR_SIZE;
> + if (len_org > 0) {
> + printk("\n data(%d): ", evt_hdr->dlen);
> + len = min(len_org, 14);
> + for (index = 0; index < len; index++)
> + printk("%x ",
> + skb->data[FM_EVT_MSG_HDR_SIZE + index]);
> + printk("%s", (len_org > 14) ? ".." : "");
> + }
> + printk("\n");
> +}
> +#endif
> +
> +void fmc_update_region_info(struct fmdrv_ops *fmdev,
> + unsigned char region_to_set)
> +{
> + memcpy(&fmdev->rx.region, &region_configs[region_to_set],
> + sizeof(struct region_info));
> +}
> +
> +/*
> + * FM common sub-module will schedule this tasklet whenever it receives
> + * FM packet from ST driver.
> + */
> +static void __recv_tasklet(unsigned long arg)
> +{
> + struct fmdrv_ops *fmdev;
> + struct fm_event_msg_hdr *fm_evt_hdr;
> + struct sk_buff *skb;
> + unsigned char num_fm_hci_cmds;
> + unsigned long flags;
> +
> + fmdev = (struct fmdrv_ops *)arg;
> + /* Process all packets in the RX queue */
> + while ((skb = skb_dequeue(&fmdev->rx_q))) {
> + if (skb->len < sizeof(struct fm_event_msg_hdr)) {
> + pr_err("(fmdrv): skb(%p) has only %d bytes"
> + "atleast need %d bytes to decode\n",
> + skb, skb->len,
> + sizeof(struct fm_event_msg_hdr));
> + kfree_skb(skb);
> + continue;
> + }
> +
> + fm_evt_hdr = (void *)skb->data;
> + num_fm_hci_cmds = fm_evt_hdr->num_fm_hci_cmds;
> +
> + /* FM interrupt packet? */
> + if (fm_evt_hdr->fm_opcode == fm_reg_info[FM_INTERRUPT].opcode) {
> + /* FM interrupt handler started already? */
> + if (!test_bit(FM_INTTASK_RUNNING, &fmdev->flag)) {
> + set_bit(FM_INTTASK_RUNNING, &fmdev->flag);
> + if (fmdev->irq_info.stage_index != 0) {
> + pr_err("(fmdrv): Invalid stage index,"
> + "resetting to zero\n");
> + fmdev->irq_info.stage_index = 0;
> + }
> +
> + /*
> + * Execute first function in interrupt handler
> + * table.
> + */
> + fmdev->irq_info.fm_int_handlers
> + [fmdev->irq_info.stage_index](fmdev);
> + } else {
> + set_bit(FM_INTTASK_SCHEDULE_PENDING,
> + &fmdev->flag);
> + }
> + kfree_skb(skb);
> + }
> + /* Anyone waiting for this with completion handler? */
> + else if (fm_evt_hdr->fm_opcode == fmdev->last_sent_pkt_opcode &&
> + fmdev->response_completion != NULL) {
> + if (fmdev->response_skb != NULL)
> + pr_err("(fmdrv): Response SKB ptr not NULL\n");
> +
> + spin_lock_irqsave(&fmdev->resp_skb_lock, flags);
> + fmdev->response_skb = skb;
> + spin_unlock_irqrestore(&fmdev->resp_skb_lock, flags);
> + complete(fmdev->response_completion);
> +
> + fmdev->response_completion = NULL;
> + atomic_set(&fmdev->tx_cnt, 1);
> + }
> + /* Is this for interrupt handler? */
> + else if (fm_evt_hdr->fm_opcode == fmdev->last_sent_pkt_opcode &&
> + fmdev->response_completion == NULL) {
> + if (fmdev->response_skb != NULL)
> + pr_err("(fmdrv): Response SKB ptr not NULL\n");
> +
> + spin_lock_irqsave(&fmdev->resp_skb_lock, flags);
> + fmdev->response_skb = skb;
> + spin_unlock_irqrestore(&fmdev->resp_skb_lock, flags);
> +
> + /* Execute interrupt handler where state index points */
> + fmdev->irq_info.fm_int_handlers
> + [fmdev->irq_info.stage_index](fmdev);
> +
> + kfree_skb(skb);
> + atomic_set(&fmdev->tx_cnt, 1);
> + } else {
> + pr_err("(fmdrv): Nobody claimed SKB(%p),purging\n",
> + skb);
> + }
> +
> + /*
> + * Check flow control field. If Num_FM_HCI_Commands field is
> + * not zero, schedule FM TX tasklet.
> + */
> + if (num_fm_hci_cmds && atomic_read(&fmdev->tx_cnt)) {
> + if (!skb_queue_empty(&fmdev->tx_q))
> + tasklet_schedule(&fmdev->tx_task);
> + }
> + }
> +}
> +
> +/* FM send tasklet: is scheduled when FM packet has to be sent to chip */
> +static void __send_tasklet(unsigned long arg)
> +{
> + struct fmdrv_ops *fmdev;
> + struct sk_buff *skb;
> + int len;
> +
> + fmdev = (struct fmdrv_ops *)arg;
> + /* Check, is there any timeout happenned to last transmitted packet */
> + if (!atomic_read(&fmdev->tx_cnt) &&
> + ((jiffies - fmdev->last_tx_jiffies) > FM_DRV_TX_TIMEOUT)) {
> + pr_err("(fmdrv): TX timeout occurred\n");
> + atomic_set(&fmdev->tx_cnt, 1);
> + }
> + /* Send queued FM TX packets */
> + if (atomic_read(&fmdev->tx_cnt)) {
> + skb = skb_dequeue(&fmdev->tx_q);
> + if (skb) {
> + atomic_dec(&fmdev->tx_cnt);
> + fmdev->last_sent_pkt_opcode = fm_cb(skb)->fm_opcode;
> +
> + if (fmdev->response_completion != NULL)
> + pr_err("(fmdrv): Response completion handler"
> + "is not NULL\n");
> +
> + fmdev->response_completion = fm_cb(skb)->completion;
> +
> + /* Write FM packet to ST driver */
> + len = g_st_write(skb);
> + if (len < 0) {
> + kfree_skb(skb);
> + fmdev->response_completion = NULL;
> + pr_err("(fmdrv): TX tasklet failed to send"
> + "skb(%p)\n", skb);
> + atomic_set(&fmdev->tx_cnt, 1);
> + } else {
> + fmdev->last_tx_jiffies = jiffies;
> + }
> + }
> + }
> +}
> +
> +/*
> + * Queues FM Channel-8 packet to FM TX queue and schedules FM TX tasklet for
> + * transmission
> + */
> +static int __fm_send_cmd(struct fmdrv_ops *fmdev, unsigned char fmreg_index,
> + void *payload, int payload_len,
> + struct completion *wait_completion)
> +{
> + struct sk_buff *skb;
> + struct fm_cmd_msg_hdr *cmd_hdr;
> + int size;
> +
> +
> + if (fmreg_index >= FM_REG_MAX_ENTRIES) {
> + pr_err("(fmdrv): Invalid fm register index\n");
> + return -EINVAL;
> + }
> + if (test_bit(FM_FIRMWARE_DW_INPROGRESS, &fmdev->flag) &&
> + payload == NULL) {
> + pr_err("(fmdrv): Payload data is NULL during fw download\n");
> + return -EINVAL;
> + }
> + if (!test_bit(FM_FIRMWARE_DW_INPROGRESS, &fmdev->flag))
> + size =
> + FM_CMD_MSG_HDR_SIZE + ((payload == NULL) ? 0 : payload_len);
> + else
> + size = payload_len;
> +
> + skb = alloc_skb(size, GFP_ATOMIC);
> + if (!skb) {
> + pr_err("(fmdrv): No memory to create new SKB\n");
> + return -ENOMEM;
> + }
> + /*
> + * Don't fill FM header info for the commands which come from
> + * FM firmware file.
> + */
> + if (!test_bit(FM_FIRMWARE_DW_INPROGRESS, &fmdev->flag) ||
> + test_bit(FM_INTTASK_RUNNING, &fmdev->flag)) {
> + /* Fill command header info */
> + cmd_hdr =
> + (struct fm_cmd_msg_hdr *)skb_put(skb, FM_CMD_MSG_HDR_SIZE);
> + cmd_hdr->header = FM_PKT_LOGICAL_CHAN_NUMBER; /* 0x08 */
> + /* 3 (fm_opcode,rd_wr,dlen) + payload len) */
> + cmd_hdr->len = ((payload == NULL) ? 0 : payload_len) + 3;
> + /* FM opcode */
> + cmd_hdr->fm_opcode = fm_reg_info[fmreg_index].opcode;
> + /* read/write type */
> + cmd_hdr->rd_wr = fm_reg_info[fmreg_index].type;
> + cmd_hdr->dlen = payload_len;
> + fm_cb(skb)->fm_opcode = fm_reg_info[fmreg_index].opcode;
> + } else if (payload != NULL) {
> + fm_cb(skb)->fm_opcode = *((char *)payload + 2);
> + }
> + if (payload != NULL)
> + memcpy(skb_put(skb, payload_len), payload, payload_len);
> +
> + fm_cb(skb)->completion = wait_completion;
> + skb_queue_tail(&fmdev->tx_q, skb);
> + tasklet_schedule(&fmdev->tx_task);
> +
> + return 0;
> +}
> +
> +/* Sends FM Channel-8 command to the chip and waits for the reponse */
> +int fmc_send_cmd(struct fmdrv_ops *fmdev, unsigned char fmreg_index,
> + void *payload, int payload_len,
> + struct completion *wait_completion, void *reponse,
> + int *reponse_len)
> +{
> + struct sk_buff *skb;
> + struct fm_event_msg_hdr *fm_evt_hdr;
> + unsigned long timeleft;
> + unsigned long flags;
> + int ret;
> +
> + init_completion(wait_completion);
> + ret = __fm_send_cmd(fmdev, fmreg_index, payload, payload_len,
> + wait_completion);
> + if (ret < 0)
> + return ret;
> +
> + timeleft = wait_for_completion_timeout(wait_completion,
> + FM_DRV_TX_TIMEOUT);
> + if (!timeleft) {
> + pr_err("(fmdrv): Timeout(%d sec),didn't get reg"
> + "completion signal from RX tasklet\n",
> + jiffies_to_msecs(FM_DRV_TX_TIMEOUT) / 1000);
> + return -ETIMEDOUT;
> + }
> + if (!fmdev->response_skb) {
> + pr_err("(fmdrv): Reponse SKB is missing\n");
> + return -EFAULT;
> + }
> + spin_lock_irqsave(&fmdev->resp_skb_lock, flags);
> + skb = fmdev->response_skb;
> + fmdev->response_skb = NULL;
> + spin_unlock_irqrestore(&fmdev->resp_skb_lock, flags);
> +
> + fm_evt_hdr = (void *)skb->data;
> + if (fm_evt_hdr->status != 0) {
> + pr_err("(fmdrv): Received event pkt status(%d) is not zero\n",
> + fm_evt_hdr->status);
> + kfree_skb(skb);
> + return -EIO;
> + }
> + /* Send reponse data to caller */
> + if (reponse != NULL && reponse_len != NULL && fm_evt_hdr->dlen) {
> + /* Skip header info and copy only response data */
> + skb_pull(skb, sizeof(struct fm_event_msg_hdr));
> + memcpy(reponse, skb->data, fm_evt_hdr->dlen);
> + *reponse_len = fm_evt_hdr->dlen;
> + } else if (reponse_len != NULL && fm_evt_hdr->dlen == 0) {
> + *reponse_len = 0;
> + }
> + kfree_skb(skb);
> + return 0;
> +}
> +
> +/* --- Helper functions used in FM interrupt handlers ---*/
> +static inline int __check_cmdresp_status(struct fmdrv_ops *fmdev,
> + struct sk_buff **skb)
> +{
> + struct fm_event_msg_hdr *fm_evt_hdr;
> + unsigned long flags;
> +
> + spin_lock_irqsave(&fmdev->resp_skb_lock, flags);
> + *skb = fmdev->response_skb;
> + fmdev->response_skb = NULL;
> + spin_unlock_irqrestore(&fmdev->resp_skb_lock, flags);
> +
> + fm_evt_hdr = (void *)(*skb)->data;
> + if (fm_evt_hdr->status != 0) {
> + pr_err("(fmdrv): irq: opcode %x response status is not zero\n",
> + fm_evt_hdr->fm_opcode);
> + return -1;
> + }
> +
> + return 0;
> +}
> +
> +/*
> + * Interrupt process timeout handler.
> + * One of the irq handler did not get proper response from the chip. So take
> + * recovery action here. FM interrupts are disabled in the beginning of
> + * interrupt process. Therefore reset stage index to re-enable default
> + * interrupts. So that next interrupt will be processed as usual.
> + */
> +static void __int_timeout_handler(unsigned long data)
> +{
> + struct fmdrv_ops *fmdev;
> +
> + pr_debug("(fmdrv): irq: timeout,trying to re-enable fm interrupts\n");
> + fmdev = (struct fmdrv_ops *)data;
> + fmdev->irq_info.irq_service_timeout_retry++;
> +
> + if (fmdev->irq_info.irq_service_timeout_retry <=
> + FM_IRQ_TIMEOUT_RETRY_MAX) {
> + fmdev->irq_info.stage_index = FM_SEND_INTMSK_CMD_INDEX;
> + fmdev->irq_info.fm_int_handlers[fmdev->irq_info.
> + stage_index] (fmdev);
> + } else {
> + /*
> + * Stop recovery action (interrupt reenable process) and
> + * reset stage index & retry count values
> + */
> + fmdev->irq_info.stage_index = 0;
> + fmdev->irq_info.irq_service_timeout_retry = 0;
> + pr_err("(fmdrv): Recovery action failed during"
> + "irq processing, max retry reached\n");
> + }
> +}
> +
> +/* --------- FM interrupt handlers ------------*/
> +static void fm_irq_send_flag_getcmd(void *arg)
> +{
> + struct fmdrv_ops *fmdev;
> + unsigned short flag;
> + int ret;
> +
> + fmdev = arg;
> + /* Send FLAG_GET command , to know the source of interrupt */
> + ret = __fm_send_cmd(fmdev, FLAG_GET, NULL, sizeof(flag), NULL);
> + if (ret)
> + pr_err("(fmdrv): irq: failed to send flag_get command,"
> + "initiating irq recovery process\n");
> + else
> + fmdev->irq_info.stage_index = FM_HANDLE_FLAG_GETCMD_RESP_INDEX;
> +
> + mod_timer(&fmdev->irq_info.int_timeout_timer, jiffies +
> + FM_DRV_TX_TIMEOUT);
> +}
> +
> +static void fm_irq_handle_flag_getcmd_resp(void *arg)
> +{
> + struct fmdrv_ops *fmdev;
> + struct sk_buff *skb;
> + struct fm_event_msg_hdr *fm_evt_hdr;
> + char ret;
> +
> + fmdev = arg;
> + del_timer(&fmdev->irq_info.int_timeout_timer);
> +
> + ret = __check_cmdresp_status(fmdev, &skb);
> + if (ret < 0) {
> + pr_err("(fmdrv): Initiating irq recovery process\n");
> + mod_timer(&fmdev->irq_info.int_timeout_timer, jiffies +
> + FM_DRV_TX_TIMEOUT);
> + return;
> + }
> + fm_evt_hdr = (void *)skb->data;
> +
> + /* Skip header info and copy only response data */
> + skb_pull(skb, sizeof(struct fm_event_msg_hdr));
> + memcpy(&fmdev->irq_info.flag, skb->data, fm_evt_hdr->dlen);
> +
> + FM_STORE_BE16_TO_LE16(fmdev->irq_info.flag, fmdev->irq_info.flag);
> + pr_debug("(fmdrv): irq: flag register(0x%x)\n", fmdev->irq_info.flag);
> +
> + /* Continue next function in interrupt handler table */
> + fmdev->irq_info.stage_index = FM_HW_MAL_FUNC_INDEX;
> +
> + fmdev->irq_info.fm_int_handlers[fmdev->irq_info.stage_index](fmdev);
> +}

OK, I think the way interrupts are handled should be revamped. It is way too
complex IMHO. All these action/response handlers have a similar structure,
particularly for the response handlers as this part of the code is the same
for all as far as I can tell:

del_timer(&fmdev->irq_info.int_timeout_timer);

ret = __check_cmdresp_status(fmdev, &skb);
if (ret < 0) {
pr_err("(fmdrv): Initiating irq recovery process\n");
mod_timer(&fmdev->irq_info.int_timeout_timer, jiffies +
FM_DRV_TX_TIMEOUT);
return;
}

What I think should happen is that rather than having each handler chain the
other there is one core handler that is taking care of that. So the boilerplate
code is in that core handler and it is calling the other handlers. So e.g. the
hw_malfunction handler below could become something like this:

static int fm_irq_handle_hw_malfunction(struct fmdrv_ops *fmdev, unsigned events)
{
if (!(events & FM_MAL_EVENT))
pr_err("(fmdrv): irq: HW MAL int received - do nothing\n");
return FM_RDS_START_INDEX;
}

And unsigned events is set to fmdev->irq_info.flag & fmdev->irq_info.mask.

This would refactor out a lot of code.

> +static void fm_irq_handle_hw_malfunction(void *arg)
> +{
> + struct fmdrv_ops *fmdev;
> +
> + fmdev = arg;
> + if (fmdev->irq_info.flag & FM_MAL_EVENT & fmdev->irq_info.mask)
> + pr_err("(fmdrv): irq: HW MAL int received - do nothing\n");
> +
> + /* Continue next function in interrupt handler table */
> + fmdev->irq_info.stage_index = FM_RDS_START_INDEX;
> + fmdev->irq_info.fm_int_handlers[fmdev->irq_info.stage_index](fmdev);
> +}

Regards,

Hans

--
Hans Verkuil - video4linux developer - sponsored by Cisco

2010-11-18 08:35:16

by Hans Verkuil

[permalink] [raw]
Subject: Re: [PATCH v4 4/6] drivers:staging: ti-st: fmdrv_rx sources

On Tuesday, November 16, 2010 14:18:12 [email protected] wrote:
> From: Manjunatha Halli <[email protected]>
>
> This has implementation for FM RX functionality.
> It communicates with FM V4l2 module and FM common module.
>
> Signed-off-by: Manjunatha Halli <[email protected]>
> ---
> drivers/staging/ti-st/fmdrv_rx.c | 979 ++++++++++++++++++++++++++++++++++++++
> drivers/staging/ti-st/fmdrv_rx.h | 59 +++
> 2 files changed, 1038 insertions(+), 0 deletions(-)
> create mode 100644 drivers/staging/ti-st/fmdrv_rx.c
> create mode 100644 drivers/staging/ti-st/fmdrv_rx.h
>
> diff --git a/drivers/staging/ti-st/fmdrv_rx.c b/drivers/staging/ti-st/fmdrv_rx.c
> new file mode 100644
> index 0000000..5f802da
> --- /dev/null
> +++ b/drivers/staging/ti-st/fmdrv_rx.c
> @@ -0,0 +1,979 @@
> +/*
> + * FM Driver for Connectivity chip of Texas Instruments.
> + * This sub-module of FM driver implements FM RX functionality.
> + *
> + * Copyright (C) 2010 Texas Instruments
> + * Author: Raja Mani <[email protected]>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> + *
> + */
> +
> +#include "fmdrv.h"
> +#include "fmdrv_common.h"
> +#include "fmdrv_rx.h"
> +
> +void fm_rx_reset_rds_cache(struct fmdrv_ops *fmdev)
> +{
> + fmdev->rx.rds.flag = FM_RDS_DISABLE;
> + fmdev->rx.rds.last_block_index = 0;
> + fmdev->rx.rds.wr_index = 0;
> + fmdev->rx.rds.rd_index = 0;
> +
> + if (fmdev->rx.af_mode == FM_RX_RDS_AF_SWITCH_MODE_ON)
> + fmdev->irq_info.mask |= FM_LEV_EVENT;
> +}
> +
> +void fm_rx_reset_curr_station_info(struct fmdrv_ops *fmdev)
> +{
> + fmdev->rx.cur_station_info.picode = FM_NO_PI_CODE;
> + fmdev->rx.cur_station_info.no_of_items_in_afcache = 0;
> + fmdev->rx.cur_station_info.af_list_max = 0;
> +}
> +
> +int fm_rx_set_frequency(struct fmdrv_ops *fmdev, unsigned int freq_to_set)
> +{
> + unsigned long timeleft;
> + unsigned short payload, curr_frq, frq_index;
> + unsigned int curr_frq_in_khz;
> + int ret, resp_len;
> +
> + if (fmdev->curr_fmmode != FM_MODE_RX)
> + return -EPERM;
> +
> + if (freq_to_set < fmdev->rx.region.bottom_frequency ||
> + freq_to_set > fmdev->rx.region.top_frequency) {
> + pr_err("(fmdrv): Invalid frequency %d\n", freq_to_set);
> + return -EINVAL;
> + }
> +
> + /* Set audio enable */
> + FM_STORE_LE16_TO_BE16(payload, FM_RX_FM_AUDIO_ENABLE_I2S_AND_ANALOG);

Why do this? You should use the cpu_to_be16 function instead. This code makes
the incorrect assumption that this will always run on a little-endian machine.
That's not necessarily true. The kernel macros do the right thing.

> + ret = fmc_send_cmd(fmdev, AUDIO_ENABLE_SET, &payload, sizeof(payload),
> + &fmdev->maintask_completion, NULL, NULL);

Actually, shouldn't fmc_send_cmd do this conversion instead of requiring all
callers to do it?

For that matter, is fmc_send_cmd ever called with a different completion pointer?
If it always uses maintask_completion, then that argument can be omitted.

> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to set RX audio enable path - %d\n",
> + ret);

Is it possible to move this error into fmc_send_cmd? That will again save a
lot of repetitive code. Something like: pr_err("(fmdrv): Command %d failed\n", cmd);

By and large I find that this driver seems to be bigger than it really needs
to be. Some tightening of the code is definitely required. It will look better
for it.

> + return ret;
> + }
> +
> + /* Set hilo to automatic selection */
> + FM_STORE_LE16_TO_BE16(payload, FM_RX_IFFREQ_HILO_AUTOMATIC);
> + ret = fmc_send_cmd(fmdev, HILO_SET, &payload, sizeof(payload),
> + &fmdev->maintask_completion, NULL, NULL);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to set HILO to automatic selection "
> + "- %d\n", ret);
> + return ret;
> + }
> +
> + /* Calculate frequency index to write */
> + frq_index = (freq_to_set - fmdev->rx.region.bottom_frequency) /
> + FM_FREQ_MUL;
> +
> + /* Set frequency index */
> + FM_STORE_LE16_TO_BE16(payload, frq_index);
> + ret = fmc_send_cmd(fmdev, FREQ_SET, &payload, sizeof(payload),
> + &fmdev->maintask_completion, NULL, NULL);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to set frequency index - %d\n", ret);
> + return ret;
> + }
> +
> + /* Read flags - just to clear any pending interrupts if we had */
> + ret = fmc_send_cmd(fmdev, FLAG_GET, NULL, 2,
> + &fmdev->maintask_completion, NULL, NULL);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to read interrupt flag - %d\n", ret);
> + return ret;
> + }
> +
> + /* Enable FR, BL interrupts */
> + fmdev->irq_info.mask |= (FM_FR_EVENT | FM_BL_EVENT);
> + FM_STORE_LE16_TO_BE16(payload, fmdev->irq_info.mask);
> + ret = fmc_send_cmd(fmdev, INT_MASK_SET, &payload, sizeof(payload),
> + &fmdev->maintask_completion, NULL, NULL);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to set interrupt mask - %d\n", ret);
> + return ret;
> + }
> +
> + /* Start tune */
> + FM_STORE_LE16_TO_BE16(payload, FM_TUNER_PRESET_MODE);
> + ret = fmc_send_cmd(fmdev, TUNER_MODE_SET, &payload, sizeof(payload),
> + &fmdev->maintask_completion, NULL, NULL);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to start tune operation - %d\n", ret);
> + return ret;
> + }
> +
> + /* Wait for tune ended interrupt */
> + init_completion(&fmdev->maintask_completion);
> + timeleft = wait_for_completion_timeout(&fmdev->maintask_completion,
> + FM_DRV_TX_TIMEOUT);
> + if (!timeleft) {
> + pr_err("(fmdrv): Timeout(%d sec),didn't get tune ended int\n",
> + jiffies_to_msecs(FM_DRV_TX_TIMEOUT) / 1000);
> + return -ETIMEDOUT;
> + }
> +
> + /* Read freq back to confirm */
> + ret = fmc_send_cmd(fmdev, FREQ_GET, NULL, 2,
> + &fmdev->maintask_completion, &curr_frq, &resp_len);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to read current frequency - %d\n",
> + ret);
> + return ret;
> + }
> +
> + curr_frq = FM_BE16_TO_LE16(curr_frq);
> + curr_frq_in_khz = (fmdev->rx.region.bottom_frequency
> + + ((unsigned int)curr_frq * FM_FREQ_MUL));
> +
> + /* Re-enable default FM interrupts */
> + fmdev->irq_info.mask &= ~(FM_FR_EVENT | FM_BL_EVENT);
> + FM_STORE_LE16_TO_BE16(payload, fmdev->irq_info.mask);
> + ret = fmc_send_cmd(fmdev, INT_MASK_SET, &payload, sizeof(payload),
> + &fmdev->maintask_completion, NULL, NULL);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to set interrupt mask - %d\n", ret);
> + return ret;
> + }
> +
> + if (curr_frq_in_khz != freq_to_set) {
> + pr_info("(fmdrv): Frequency is set to (%d) but"
> + " requested frequency is (%d)\n", curr_frq_in_khz,
> + freq_to_set);
> + }
> +
> + /* Update local cache */
> + fmdev->rx.curr_freq = curr_frq_in_khz;
> +
> + /* Reset RDS cache and current station pointers */
> + fm_rx_reset_rds_cache(fmdev);
> + fm_rx_reset_curr_station_info(fmdev);
> +
> + /* Do we need to reset anything else? */
> +
> + return ret;
> +}
> +
> +int fm_rx_seek(struct fmdrv_ops *fmdev, unsigned int seek_upward,
> + unsigned int wrap_around)
> +{
> + int resp_len;
> + unsigned short curr_frq, next_frq, last_frq;
> + unsigned short payload, int_reason;
> + char offset, spacing;
> + unsigned long timeleft;
> + int ret;
> +
> + if (fmdev->curr_fmmode != FM_MODE_RX)
> + return -EPERM;
> +
> + /* Read the current frequency from chip */
> + ret = fmc_send_cmd(fmdev, FREQ_GET, NULL, sizeof(curr_frq),
> + &fmdev->maintask_completion, &curr_frq, &resp_len);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to read current frequency - %d\n",
> + ret);
> + return ret;
> + }
> +
> + curr_frq = FM_BE16_TO_LE16(curr_frq);
> + last_frq = (fmdev->rx.region.top_frequency -
> + fmdev->rx.region.bottom_frequency) / FM_FREQ_MUL;
> +
> + /* Check the offset in order to be aligned to the channel spacing*/
> + spacing = fmdev->rx.region.channel_spacing / FM_FREQ_MUL;
> + offset = curr_frq % spacing;
> +
> + next_frq = seek_upward ? curr_frq + spacing /* Seek Up */ :
> + curr_frq - spacing /* Seek Down */ ;
> +
> + /*
> + * Add or subtract offset in order to stay aligned to the channel
> + * spacing.
> + */
> + if ((short)next_frq < 0)
> + next_frq = last_frq - offset;
> + else if (next_frq > last_frq)
> + next_frq = 0 + offset;
> +
> +again:
> + /* Set calculated next frequency to perform seek */
> + FM_STORE_LE16_TO_BE16(payload, next_frq);
> + ret = fmc_send_cmd(fmdev, FREQ_SET, &payload, sizeof(payload),
> + &fmdev->maintask_completion, NULL, NULL);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to set new frequency - %d\n", ret);
> + return ret;
> + }
> +
> + /* Set search direction (0:Seek Down, 1:Seek Up) */
> + FM_STORE_LE16_TO_BE16(payload, (seek_upward ? FM_SEARCH_DIRECTION_UP :
> + FM_SEARCH_DIRECTION_DOWN));
> + ret = fmc_send_cmd(fmdev, SEARCH_DIR_SET, &payload, sizeof(payload),
> + &fmdev->maintask_completion, NULL, NULL);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to set seek direction - %d\n", ret);
> + return ret;
> + }
> +
> + /* Read flags - just to clear any pending interrupts if we had */
> + ret = fmc_send_cmd(fmdev, FLAG_GET, NULL, 2,
> + &fmdev->maintask_completion, NULL, NULL);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to read interrupt flag - %d\n", ret);
> + return ret;
> + }
> +
> + /* Enable FR, BL interrupts */
> + fmdev->irq_info.mask |= (FM_FR_EVENT | FM_BL_EVENT);
> + FM_STORE_LE16_TO_BE16(payload, fmdev->irq_info.mask);
> + ret = fmc_send_cmd(fmdev, INT_MASK_SET, &payload, sizeof(payload),
> + &fmdev->maintask_completion, NULL, NULL);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to set interrupt mask - %d\n", ret);
> + return ret;
> + }
> +
> + /* Start seek */
> + FM_STORE_LE16_TO_BE16(payload, FM_TUNER_AUTONOMOUS_SEARCH_MODE);
> + ret = fmc_send_cmd(fmdev, TUNER_MODE_SET, &payload, sizeof(payload),
> + &fmdev->maintask_completion, NULL, NULL);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to start seek operation - %d\n", ret);
> + return ret;
> + }
> +
> + /* Wait for tune ended/band limit reached interrupt */
> + init_completion(&fmdev->maintask_completion);
> + timeleft = wait_for_completion_timeout(&fmdev->maintask_completion,
> + FM_DRV_RX_SEEK_TIMEOUT);
> + if (!timeleft) {
> + pr_err("(fmdrv): Timeout(%d sec),didn't get tune ended int\n",
> + jiffies_to_msecs(FM_DRV_RX_SEEK_TIMEOUT) / 1000);
> + return -ETIMEDOUT;
> + }
> +
> + int_reason = fmdev->irq_info.flag & (FM_TUNE_COMPLETE | FM_BAND_LIMIT);
> +
> + /* Re-enable default FM interrupts */
> + fmdev->irq_info.mask &= ~(FM_FR_EVENT | FM_BL_EVENT);
> + FM_STORE_LE16_TO_BE16(payload, fmdev->irq_info.mask);
> + ret = fmc_send_cmd(fmdev, INT_MASK_SET, &payload, sizeof(payload),
> + &fmdev->maintask_completion, NULL, NULL);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to set interrupt mask - %d\n", ret);
> + return ret;
> + }
> +
> + /* Read freq to know where operation tune operation stopped */
> + ret = fmc_send_cmd(fmdev, FREQ_GET, NULL, 2,
> + &fmdev->maintask_completion, &curr_frq, &resp_len);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to read current frequency - %d\n",
> + ret);
> + return ret;
> + }
> +
> + curr_frq = FM_BE16_TO_LE16(curr_frq);
> + fmdev->rx.curr_freq = (fmdev->rx.region.bottom_frequency +
> + ((unsigned int)curr_frq * FM_FREQ_MUL));
> +
> + /* Reset RDS cache and current station pointers */
> + fm_rx_reset_rds_cache(fmdev);
> + fm_rx_reset_curr_station_info(fmdev);
> +
> + /* Return error if band limit is reached */
> + if (int_reason & FM_BL_EVENT) {
> + if (!wrap_around) {
> + ret = fmdev->rx.region.top_frequency;
> + } else {
> + next_frq = 1;
> + goto again;
> + }
> + }
> +
> + return ret;
> +}
> +
> +int fm_rx_set_volume(struct fmdrv_ops *fmdev, unsigned short vol_to_set)
> +{
> + unsigned short payload;
> + int ret;
> +
> + if (fmdev->curr_fmmode != FM_MODE_RX)
> + return -EPERM;
> +
> + if (vol_to_set < FM_RX_VOLUME_MIN || vol_to_set > FM_RX_VOLUME_MAX) {
> + pr_err("(fmdrv): Volume is not within(%d-%d) range\n",
> + FM_RX_VOLUME_MIN, FM_RX_VOLUME_MAX);
> + return -EINVAL;
> + }
> + vol_to_set *= FM_RX_VOLUME_GAIN_STEP;
> +
> + FM_STORE_LE16_TO_BE16(payload, vol_to_set);
> + ret = fmc_send_cmd(fmdev, VOLUME_SET, &payload, sizeof(payload),
> + &fmdev->maintask_completion, NULL, NULL);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to set RX volume level - %d\n", ret);
> + return ret;
> + }
> +
> + fmdev->rx.curr_volume = vol_to_set;
> + return ret;
> +}
> +
> +/* Get volume */
> +int fm_rx_get_volume(struct fmdrv_ops *fmdev, unsigned short *curr_vol)
> +{
> + if (fmdev->curr_fmmode != FM_MODE_RX)
> + return -EPERM;
> +
> + if (curr_vol == NULL) {
> + pr_err("(fmdrv): Invalid memory\n");
> + return -ENOMEM;
> + }
> +
> + *curr_vol = fmdev->rx.curr_volume / FM_RX_VOLUME_GAIN_STEP;
> +
> + return 0;
> +}
> +
> +/* To get current band's bottom and top frequency */
> +int fm_rx_get_currband_freq_range(struct fmdrv_ops *fmdev,
> + unsigned int *bottom_frequency,
> + unsigned int *top_frequency)
> +{
> + if (bottom_frequency != NULL)
> + *bottom_frequency = fmdev->rx.region.bottom_frequency;
> +
> + if (top_frequency != NULL)
> + *top_frequency = fmdev->rx.region.top_frequency;
> +
> + return 0;
> +}
> +
> +/* Returns current band index (0-Europe/US; 1-Japan) */
> +void fm_rx_get_region(struct fmdrv_ops *fmdev, unsigned char *region)
> +{
> + *region = fmdev->rx.region.region_index;
> +}
> +
> +/* Sets band (0-Europe/US; 1-Japan) */
> +int fm_rx_set_region(struct fmdrv_ops *fmdev,
> + unsigned char region_to_set)
> +{
> + unsigned short payload;
> + unsigned int new_frq = 0;
> + int ret = -EPERM;
> +
> + if (fmdev->curr_fmmode != FM_MODE_RX)
> + return ret;
> +
> + if (region_to_set != FM_BAND_EUROPE_US &&
> + region_to_set != FM_BAND_JAPAN) {
> + pr_err("(fmdrv): Invalid band\n");
> + return -EINVAL;
> + }
> +
> + if (fmdev->rx.region.region_index == region_to_set) {
> + pr_err("(fmdrv): Requested band is already configured\n");
> + return ret;
> + }
> +
> + /* Send cmd to set the band */
> + FM_STORE_LE16_TO_BE16(payload, (unsigned short)region_to_set);
> + ret = fmc_send_cmd(fmdev, RX_BAND_SET, &payload, sizeof(payload),
> + &fmdev->maintask_completion, NULL, NULL);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to set FM RX band - %d\n", ret);
> + return ret;
> + }
> +
> + fmc_update_region_info(fmdev, region_to_set);
> +
> + /* Check whether current RX frequency is within band boundary */
> + if (fmdev->rx.curr_freq < fmdev->rx.region.bottom_frequency)
> + new_frq = fmdev->rx.region.bottom_frequency;
> + else if (fmdev->rx.curr_freq > fmdev->rx.region.top_frequency)
> + new_frq = fmdev->rx.region.top_frequency;
> +
> + if (new_frq) {
> + pr_debug("(fmdrv): "
> + "Current freq is not within band limit boundary,"
> + "switching to %d KHz\n", new_frq);
> + /*
> + * Current RX frequency is not within boundary. So,
> + * update it.
> + */
> + ret = fm_rx_set_frequency(fmdev, new_frq);
> + }
> +
> + return ret;
> +}
> +
> +/* Reads current mute mode (Mute Off/On/Attenuate)*/
> +int fm_rx_get_mute_mode(struct fmdrv_ops *fmdev,
> + unsigned char *curr_mute_mode)
> +{
> + if (fmdev->curr_fmmode != FM_MODE_RX)
> + return -EPERM;
> +
> + if (curr_mute_mode == NULL) {
> + pr_err("(fmdrv): Invalid memory\n");
> + return -ENOMEM;
> + }
> +
> + *curr_mute_mode = fmdev->rx.curr_mute_mode;
> +
> + return 0;
> +}
> +
> +static int __fm_config_rx_mute_reg(struct fmdrv_ops *fmdev)
> +{
> + unsigned short payload, muteval;
> + int ret;
> +
> + muteval = 0;
> + switch (fmdev->rx.curr_mute_mode) {
> + case FM_MUTE_ON:
> + muteval = FM_RX_MUTE_AC_MUTE_MODE;
> + break;
> +
> + case FM_MUTE_OFF:
> + muteval = FM_RX_MUTE_UNMUTE_MODE;
> + break;
> +
> + case FM_MUTE_ATTENUATE:
> + muteval = FM_RX_MUTE_SOFT_MUTE_FORCE_MODE;
> + break;
> + }
> + if (fmdev->rx.curr_rf_depend_mute == FM_RX_RF_DEPENDENT_MUTE_ON)
> + muteval |= FM_RX_MUTE_RF_DEP_MODE;
> + else
> + muteval &= ~FM_RX_MUTE_RF_DEP_MODE;
> +
> + FM_STORE_LE16_TO_BE16(payload, muteval);
> + ret = fmc_send_cmd(fmdev, MUTE_STATUS_SET, &payload, sizeof(payload),
> + &fmdev->maintask_completion, NULL, NULL);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to set RX mute state - %d\n", ret);
> + return ret;
> + }
> +
> + return 0;
> +}
> +
> +/* Configures mute mode (Mute Off/On/Attenuate) */
> +int fm_rx_set_mute_mode(struct fmdrv_ops *fmdev,
> + unsigned char mute_mode_toset)
> +{
> + unsigned char org_state;
> + int ret;
> +
> + if (fmdev->curr_fmmode != FM_MODE_RX)
> + return -EPERM;
> +
> + if (fmdev->rx.curr_mute_mode == mute_mode_toset)
> + return 0;
> +
> + org_state = fmdev->rx.curr_mute_mode;
> + fmdev->rx.curr_mute_mode = mute_mode_toset;
> +
> + ret = __fm_config_rx_mute_reg(fmdev);
> + if (ret < 0) {
> + fmdev->rx.curr_mute_mode = org_state;
> + return ret;
> + }
> +
> + return 0;
> +}
> +
> +/* Gets RF dependent soft mute mode enable/disable status */
> +int fm_rx_get_rfdepend_softmute(struct fmdrv_ops *fmdev,
> + unsigned char *curr_mute_mode)
> +{
> + if (fmdev->curr_fmmode != FM_MODE_RX)
> + return -EPERM;
> +
> + if (curr_mute_mode == NULL) {
> + pr_err("(fmdrv): Invalid memory\n");
> + return -ENOMEM;
> + }
> +
> + *curr_mute_mode = fmdev->rx.curr_rf_depend_mute;
> +
> + return 0;
> +}
> +
> +/* Sets RF dependent soft mute mode */
> +int fm_rx_set_rfdepend_softmute(struct fmdrv_ops *fmdev,
> + unsigned char rfdepend_mute)
> +{
> + unsigned char org_state;
> + int ret;
> +
> + if (fmdev->curr_fmmode != FM_MODE_RX)
> + return -EPERM;
> +
> + if (rfdepend_mute != FM_RX_RF_DEPENDENT_MUTE_ON &&
> + rfdepend_mute != FM_RX_RF_DEPENDENT_MUTE_OFF) {
> + pr_err("(fmdrv): Invalid RF dependent soft mute\n");
> + return -EINVAL;
> + }
> + if (fmdev->rx.curr_rf_depend_mute == rfdepend_mute)
> + return 0;
> +
> + org_state = fmdev->rx.curr_rf_depend_mute;
> + fmdev->rx.curr_rf_depend_mute = rfdepend_mute;
> +
> + ret = __fm_config_rx_mute_reg(fmdev);
> + if (ret < 0) {
> + fmdev->rx.curr_rf_depend_mute = org_state;
> + return ret;
> + }
> +
> + return 0;
> +}
> +
> +/* Returns the signal strength level of current channel */
> +int fm_rx_get_rssi_level(struct fmdrv_ops *fmdev,
> + unsigned short *rssilvl)
> +{
> + unsigned short curr_rssi_lel;
> + int resp_len;
> + int ret;
> +
> + if (fmdev->curr_fmmode != FM_MODE_RX)
> + return -EPERM;
> +
> + if (rssilvl == NULL) {
> + pr_err("(fmdrv): Invalid memory\n");
> + return -ENOMEM;
> + }
> + /* Read current RSSI level */
> + ret = fmc_send_cmd(fmdev, RSSI_LVL_GET, NULL, 2,
> + &fmdev->maintask_completion, &curr_rssi_lel, &resp_len);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to get RSSI level - %d\n", ret);
> + return ret;
> + }
> +
> + *rssilvl = FM_BE16_TO_LE16(curr_rssi_lel);
> +
> + return 0;
> +}
> +
> +/*
> + * Sets the signal strength level that once reached
> + * will stop the auto search process
> + */
> +int fm_rx_set_rssi_threshold(struct fmdrv_ops *fmdev,
> + short rssi_lvl_toset)
> +{
> + unsigned short payload;
> + int ret;
> +
> + if (fmdev->curr_fmmode != FM_MODE_RX)
> + return -EPERM;
> +
> + if (rssi_lvl_toset < FM_RX_RSSI_THRESHOLD_MIN ||
> + rssi_lvl_toset > FM_RX_RSSI_THRESHOLD_MAX) {
> + pr_err("(fmdrv): Invalid RSSI threshold level\n");
> + return -EINVAL;
> + }
> + FM_STORE_LE16_TO_BE16(payload, (unsigned short)rssi_lvl_toset);
> + ret = fmc_send_cmd(fmdev, SEARCH_LVL_SET, &payload, sizeof(payload),
> + &fmdev->maintask_completion, NULL, NULL);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to set RSSI level - %d\n", ret);
> + return ret;
> + }
> +
> + fmdev->rx.curr_rssi_threshold = rssi_lvl_toset;
> + return 0;
> +}
> +
> +/* Returns current RX RSSI threshold value */
> +int fm_rx_get_rssi_threshold(struct fmdrv_ops *fmdev, short *curr_rssi_lvl)
> +{
> + if (fmdev->curr_fmmode != FM_MODE_RX)
> + return -EPERM;
> +
> + if (curr_rssi_lvl == NULL) {
> + pr_err("(fmdrv): Invalid memory\n");
> + return -ENOMEM;
> + }
> +
> + *curr_rssi_lvl = fmdev->rx.curr_rssi_threshold;
> +
> + return 0;
> +}
> +
> +/* Sets RX stereo/mono modes */
> +int fm_rx_set_stereo_mono(struct fmdrv_ops *fmdev, unsigned short mode)
> +{
> + unsigned short payload;
> + int ret;
> +
> + if (fmdev->curr_fmmode != FM_MODE_RX)
> + return -EPERM;
> +
> + if (mode != FM_STEREO_MODE && mode != FM_MONO_MODE) {
> + pr_err("(fmdrv): Invalid mode\n");
> + return -EINVAL;
> + }
> +
> + /* Set stereo/mono mode */
> + FM_STORE_LE16_TO_BE16(payload, (unsigned short)mode);
> + ret = fmc_send_cmd(fmdev, MOST_MODE_SET, &payload, sizeof(payload),
> + &fmdev->maintask_completion, NULL, NULL);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to set RX stereo/mono mode - %d\n",
> + ret);
> + return ret;
> + }
> +
> + /* Set stereo blending mode */
> + FM_STORE_LE16_TO_BE16(payload, FM_STEREO_SOFT_BLEND);
> + ret = fmc_send_cmd(fmdev, MOST_BLEND_SET, &payload, sizeof(payload),
> + &fmdev->maintask_completion, NULL, NULL);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to set RX stereo blend - %d\n", ret);
> + return ret;
> + }
> +
> + return 0;
> +}
> +
> +/* Gets current RX stereo/mono mode */
> +int fm_rx_get_stereo_mono(struct fmdrv_ops *fmdev, unsigned short *mode)
> +{
> + unsigned short curr_mode;
> + int ret, resp_len;
> +
> + if (fmdev->curr_fmmode != FM_MODE_RX)
> + return -EPERM;
> +
> + if (mode == NULL) {
> + pr_err("(fmdrv): Invalid memory\n");
> + return -ENOMEM;
> + }
> +
> + ret = fmc_send_cmd(fmdev, MOST_MODE_GET, NULL, 2,
> + &fmdev->maintask_completion, &curr_mode, &resp_len);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to get stereo/mono mode - %d\n", ret);
> + return ret;
> + }
> +
> + *mode = FM_BE16_TO_LE16(curr_mode);
> +
> + return 0;
> +}
> +
> +/* Choose RX de-emphasis filter mode (50us/75us) */
> +int fm_rx_set_deemphasis_mode(struct fmdrv_ops *fmdev, unsigned short mode)
> +{
> + unsigned short payload;
> + int ret;
> +
> + if (fmdev->curr_fmmode != FM_MODE_RX)
> + return -EPERM;
> +
> + if (mode != FM_RX_EMPHASIS_FILTER_50_USEC &&
> + mode != FM_RX_EMPHASIS_FILTER_75_USEC) {
> + pr_err("(fmdrv): Invalid rx de-emphasis mode (%d)\n", mode);
> + return -EINVAL;
> + }
> +
> + FM_STORE_LE16_TO_BE16(payload, mode);
> + ret = fmc_send_cmd(fmdev, DEMPH_MODE_SET, &payload, sizeof(payload),
> + &fmdev->maintask_completion, NULL, NULL);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to set RX deemphasis filter value - "
> + "%d\n", ret);
> + return ret;
> + }
> + fmdev->rx.curr_deemphasis_mode = mode;
> + return 0;
> +}
> +
> +/* Gets current RX de-emphasis filter mode */
> +int fm_rx_get_deemphasis_mode(struct fmdrv_ops *fmdev,
> + unsigned short *curr_deemphasis_mode)
> +{
> + if (fmdev->curr_fmmode != FM_MODE_RX)
> + return -EPERM;
> +
> + if (curr_deemphasis_mode == NULL) {
> + pr_err("(fmdrv): Invalid memory\n");
> + return -ENOMEM;
> + }
> +
> + *curr_deemphasis_mode = fmdev->rx.curr_deemphasis_mode;
> +
> + return 0;
> +}
> +
> +/* Enable/Disable RX RDS */
> +int fm_rx_set_rds_mode(struct fmdrv_ops *fmdev, unsigned char rds_en_dis)
> +{
> + unsigned short payload;
> + int ret;
> +
> + if (fmdev->curr_fmmode != FM_MODE_RX)
> + return -EPERM;
> +
> + if (rds_en_dis != FM_RDS_ENABLE && rds_en_dis != FM_RDS_DISABLE) {
> + pr_err("(fmdrv): Invalid rds option\n");
> + return -EINVAL;
> + }
> +
> + if (rds_en_dis == FM_RDS_ENABLE
> + && fmdev->rx.rds.flag == FM_RDS_DISABLE) {
> + /* Turn on RX RDS and RDS circuit */
> + FM_STORE_LE16_TO_BE16(payload,
> + FM_RX_POWET_SET_FM_AND_RDS_BLK_ON);
> + ret = fmc_send_cmd(fmdev, POWER_SET, &payload, sizeof(payload),
> + &fmdev->maintask_completion, NULL, NULL);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to enable RX RDS - %d\n", ret);
> + return ret;
> + }
> +
> + /* Clear and reset RDS FIFO */
> + FM_STORE_LE16_TO_BE16(payload, FM_RX_RDS_FLUSH_FIFO);
> + ret = fmc_send_cmd(fmdev, RDS_CNTRL_SET, &payload,
> + sizeof(payload), &fmdev->maintask_completion, NULL, NULL);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to flush RX RDS fifo - %d\n",
> + ret);
> + return ret;
> + }
> +
> + /* Read flags - just to clear any pending interrupts. */
> + ret = fmc_send_cmd(fmdev, FLAG_GET, NULL, 2,
> + &fmdev->maintask_completion, NULL, NULL);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to read interrupt flag - %d\n",
> + ret);
> + return ret;
> + }
> +
> + /* Set RDS FIFO threshold value */
> + FM_STORE_LE16_TO_BE16(payload, FM_RX_RDS_FIFO_THRESHOLD);
> + ret = fmc_send_cmd(fmdev, RDS_MEM_SET, &payload,
> + sizeof(payload), &fmdev->maintask_completion, NULL, NULL);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to set RX RDS fifo threshold -"
> + " %d\n", ret);
> + return ret;
> + }
> +
> + /* Enable RDS interrupt */
> + fmdev->irq_info.mask |= FM_RDS_EVENT;
> + FM_STORE_LE16_TO_BE16(payload, fmdev->irq_info.mask);
> + ret = fmc_send_cmd(fmdev, INT_MASK_SET, &payload,
> + sizeof(payload), &fmdev->maintask_completion, NULL, NULL);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to set interrupt mask- %d\n",
> + ret);
> + fmdev->irq_info.mask &= ~FM_RDS_EVENT;
> + return ret;
> + }
> +
> + /* Update our local flag */
> + fmdev->rx.rds.flag = FM_RDS_ENABLE;
> + } else if (rds_en_dis == FM_RDS_DISABLE
> + && fmdev->rx.rds.flag == FM_RDS_ENABLE) {
> + /* Turn off RX RDS */
> + /* Turn off RDS circuit */
> + FM_STORE_LE16_TO_BE16(payload, FM_RX_POWER_SET_FM_ON_RDS_OFF);
> + ret = fmc_send_cmd(fmdev, POWER_SET, &payload, sizeof(payload),
> + &fmdev->maintask_completion, NULL, NULL);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to disable RX RDS - %d\n",
> + ret);
> + return ret;
> + }
> +
> + /* Reset RDS pointers */
> + fmdev->rx.rds.last_block_index = 0;
> + fmdev->rx.rds.wr_index = 0;
> + fmdev->rx.rds.rd_index = 0;
> + fm_rx_reset_curr_station_info(fmdev);
> +
> + /* Update RDS local cache */
> + fmdev->irq_info.mask &= ~(FM_RDS_EVENT);
> + fmdev->rx.rds.flag = FM_RDS_DISABLE;
> + }
> +
> + return 0;
> +}
> +
> +/* Returns current RX RDS enable/disable status */
> +int fm_rx_get_rds_mode(struct fmdrv_ops *fmdev,
> + unsigned char *curr_rds_en_dis)
> +{
> + if (fmdev->curr_fmmode != FM_MODE_RX)
> + return -EPERM;
> +
> + if (curr_rds_en_dis == NULL) {
> + pr_err("(fmdrv): Invalid memory\n");
> + return -ENOMEM;
> + }
> +
> + *curr_rds_en_dis = fmdev->rx.rds.flag;
> +
> + return 0;
> +}
> +
> +/* Sets RDS operation mode (RDS/RDBS) */
> +int fm_rx_set_rds_system(struct fmdrv_ops *fmdev, unsigned char rds_mode)
> +{
> + unsigned short payload;
> + int ret;
> +
> + if (fmdev->curr_fmmode != FM_MODE_RX)
> + return -EPERM;
> +
> + if (rds_mode != FM_RDS_SYSTEM_RDS && rds_mode != FM_RDS_SYSTEM_RBDS) {
> + pr_err("(fmdrv): Invalid rds mode\n");
> + return -EINVAL;
> + }
> + /* Set RDS operation mode */
> + FM_STORE_LE16_TO_BE16(payload, (unsigned short)rds_mode);
> + ret = fmc_send_cmd(fmdev, RDS_SYSTEM_SET, &payload, sizeof(payload),
> + &fmdev->maintask_completion, NULL, NULL);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to set RX RDS system - %d\n", ret);
> + return ret;
> + }
> +
> + fmdev->rx.rds_mode = rds_mode;
> +
> + return 0;
> +}
> +
> +/* Returns current RDS operation mode */
> +int fm_rx_get_rds_system(struct fmdrv_ops *fmdev,
> + unsigned char *rds_mode)
> +{
> + if (fmdev->curr_fmmode != FM_MODE_RX)
> + return -EPERM;
> +
> + if (rds_mode == NULL) {
> + pr_err("(fmdrv): Invalid memory\n");
> + return -ENOMEM;
> + }
> +
> + *rds_mode = fmdev->rx.rds_mode;
> +
> + return 0;
> +}
> +
> +/* Configures Alternate Frequency switch mode */
> +int fm_rx_set_af_switch(struct fmdrv_ops *fmdev, unsigned char af_mode)
> +{
> + unsigned short payload;
> + int ret;
> +
> + if (fmdev->curr_fmmode != FM_MODE_RX)
> + return -EPERM;
> +
> + if (af_mode != FM_RX_RDS_AF_SWITCH_MODE_ON &&
> + af_mode != FM_RX_RDS_AF_SWITCH_MODE_OFF) {
> + pr_err("(fmdrv): Invalid af mode\n");
> + return -EINVAL;
> + }
> + /* Enable/disable low RSSI interrupt based on af_mode */
> + if (af_mode == FM_RX_RDS_AF_SWITCH_MODE_ON)
> + fmdev->irq_info.mask |= FM_LEV_EVENT;
> + else
> + fmdev->irq_info.mask &= ~FM_LEV_EVENT;
> +
> + FM_STORE_LE16_TO_BE16(payload, fmdev->irq_info.mask);
> + ret = fmc_send_cmd(fmdev, INT_MASK_SET, &payload, sizeof(payload),
> + &fmdev->maintask_completion, NULL, NULL);
> + if (ret < 0) {
> + pr_err("(fmdrv): Failed to set interrupt mask - %d\n", ret);
> + return ret;
> + }
> +
> + fmdev->rx.af_mode = af_mode;
> +
> + return 0;
> +}
> +
> +/* Returns Alternate Frequency switch status */
> +int fm_rx_get_af_switch(struct fmdrv_ops *fmdev, unsigned char *af_mode)
> +{
> + if (fmdev->curr_fmmode != FM_MODE_RX)
> + return -EPERM;
> +
> + if (af_mode == NULL) {
> + pr_err("(fmdrv): Invalid memory\n");
> + return -ENOMEM;
> + }
> +
> + *af_mode = fmdev->rx.af_mode;
> +
> + return 0;
> +}
> +
> +/* Set desired channel spacing */
> +int fm_rx_set_chanl_spacing(struct fmdrv_ops *fmdev, unsigned char spacing)
> +{
> + unsigned short payload;
> + int ret;
> +
> + if (spacing != FM_CHANNEL_SPACING_50KHZ &&
> + spacing != FM_CHANNEL_SPACING_100KHZ &&
> + spacing != FM_CHANNEL_SPACING_200KHZ) {
> + pr_err("Invalid channel spacing");
> + return -EINVAL;
> + }
> +
> + /* set channel spacing */
> + FM_STORE_LE16_TO_BE16(payload, spacing);
> +
> + ret = fmc_send_cmd(fmdev, CHANL_BW_SET, &payload, sizeof(payload),
> + &fmdev->maintask_completion, NULL, NULL);
> + if (ret < 0)
> + return ret;
> +
> + fmdev->rx.region.channel_spacing = spacing * FM_FREQ_MUL;
> +
> + return 0;
> +}
> +
> +/* Get channel spacing */
> +int fm_rx_get_chanl_spacing(struct fmdrv_ops *fmdev, unsigned char *spacing)
> +{
> + if (fmdev->curr_fmmode != FM_MODE_RX)
> + return -EPERM;
> +
> + if (spacing == NULL) {
> + pr_err("Invalid memory");
> + return -ENOMEM;
> + }
> +
> + *spacing = fmdev->rx.region.channel_spacing / FM_FREQ_MUL;
> +
> + return 0;
> +}
> diff --git a/drivers/staging/ti-st/fmdrv_rx.h b/drivers/staging/ti-st/fmdrv_rx.h
> new file mode 100644
> index 0000000..3d1490a
> --- /dev/null
> +++ b/drivers/staging/ti-st/fmdrv_rx.h
> @@ -0,0 +1,59 @@
> +/*
> + * FM Driver for Connectivity chip of Texas Instruments.
> + * FM RX module header.
> + *
> + * Copyright (C) 2010 Texas Instruments
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> + *
> + */
> +
> +#ifndef _FMDRV_RX_H
> +#define _FMDRV_RX_H
> +
> +int fm_rx_set_frequency(struct fmdrv_ops*, unsigned int);

Coding style: space before '*'

> +int fm_rx_set_mute_mode(struct fmdrv_ops*, unsigned char);
> +int fm_rx_set_stereo_mono(struct fmdrv_ops*, unsigned short);
> +int fm_rx_set_rds_mode(struct fmdrv_ops*, unsigned char);
> +int fm_rx_set_rds_system(struct fmdrv_ops *, unsigned char);
> +int fm_rx_set_volume(struct fmdrv_ops*, unsigned short);
> +int fm_rx_set_rssi_threshold(struct fmdrv_ops*, short);
> +int fm_rx_set_region(struct fmdrv_ops*, unsigned char);
> +int fm_rx_set_rfdepend_softmute(struct fmdrv_ops *, unsigned char);
> +int fm_rx_set_deemphasis_mode(struct fmdrv_ops *, unsigned short);
> +int fm_rx_set_af_switch(struct fmdrv_ops *, unsigned char);
> +
> +void fm_rx_reset_rds_cache(struct fmdrv_ops *);
> +void fm_rx_reset_curr_station_info(struct fmdrv_ops *);
> +
> +int fm_rx_seek(struct fmdrv_ops*, unsigned int, unsigned int);
> +
> +int fm_rx_get_rds_mode(struct fmdrv_ops*, unsigned char*);
> +int fm_rx_get_rds_system(struct fmdrv_ops *, unsigned char*);
> +int fm_rx_get_mute_mode(struct fmdrv_ops*, unsigned char*);
> +int fm_rx_get_volume(struct fmdrv_ops*, unsigned short*);
> +int fm_rx_get_currband_freq_range(struct fmdrv_ops*,
> + unsigned int*, unsigned int*);
> +int fm_rx_get_stereo_mono(struct fmdrv_ops *, unsigned short*);
> +int fm_rx_get_rssi_level(struct fmdrv_ops *, unsigned short*);
> +int fm_rx_get_rssi_threshold(struct fmdrv_ops *, short*);
> +int fm_rx_get_rfdepend_softmute(struct fmdrv_ops *, unsigned char*);
> +int fm_rx_get_deemphasis_mode(struct fmdrv_ops *, unsigned short*);
> +int fm_rx_get_af_switch(struct fmdrv_ops *, unsigned char *);
> +void fm_rx_get_region(struct fmdrv_ops*, unsigned char*);
> +
> +int fm_rx_set_chanl_spacing(struct fmdrv_ops*, unsigned char);
> +int fm_rx_get_chanl_spacing(struct fmdrv_ops*, unsigned char*);
> +#endif
> +
>

--
Hans Verkuil - video4linux developer - sponsored by Cisco

2010-11-18 08:36:18

by Ohad Ben Cohen

[permalink] [raw]
Subject: Re: [PATCH v4 0/6] FM V4L2 drivers for WL128x

Hi Pavan,

> On Wed, Nov 17, 2010 at 6:32 PM, Ohad Ben-Cohen <[email protected]> wrote:
>>> ?drivers/staging/ti-st/Kconfig ? ? ? ?| ? 10 +
>>> ?drivers/staging/ti-st/Makefile ? ? ? | ? ?2 +
>>> ?drivers/staging/ti-st/fmdrv.h ? ? ? ?| ?259 ++++
>>> ?drivers/staging/ti-st/fmdrv_common.c | 2141 ++++++++++++++++++++++++++++++++++
>>> ?drivers/staging/ti-st/fmdrv_common.h | ?458 ++++++++
>>> ?drivers/staging/ti-st/fmdrv_rx.c ? ? | ?979 ++++++++++++++++
>>> ?drivers/staging/ti-st/fmdrv_rx.h ? ? | ? 59 +
>>> ?drivers/staging/ti-st/fmdrv_tx.c ? ? | ?461 ++++++++
>>> ?drivers/staging/ti-st/fmdrv_tx.h ? ? | ? 37 +
>>> ?drivers/staging/ti-st/fmdrv_v4l2.c ? | ?757 ++++++++++++
>>> ?drivers/staging/ti-st/fmdrv_v4l2.h ? | ? 32 +
>>> ?11 files changed, 5195 insertions(+), 0 deletions(-)
>>
>> Usually when a driver is added to staging, it should also have a TODO
>> file specifying what needs to be done before the driver can be taken
>> out of staging (at least as far as the author knows of today).
>>
>> It helps keeping track of the open issues in the driver, which is good
>> for everyone - the author, the random contributor/observer, and
>> probably even the staging maintainer.
>>
>> Can you please add such a TODO file ?
...
> Thanks Ohad, for the comments, We do have an internal TODO.
> In terms of functionality we have stuff like TX RDS which already has
> few CIDs in the extended controls.
> extend V4L2 for complete-scan, add in stop search during hw_seek .. etc...

You need to understand and list the reasons why this driver cannot go
directly to mainline; missing functionality is usually not the
culprit.

> But I just wanted to ask whether this is good enough to be staged.
> Because as we begin to implement and add in the items in TODO - the
> patch set will keep continuing to grow.
>
> So Hans, Mauro, What do you think ?
> It would be real helpful - if this can be staged, it is becoming
> difficult to maintain for us.

Greg has mentioned that staging acceptance rules are:

1. Code compiles
2. Is self sustained (does not touch code out of staging)
3. Has a clear roadmap out of staging (that TODO file)
4. Is maintained

But I really think you should always prefer to upstream your code
directly to mainline. Submit the code, have it reviewed by the
relevant maintainers and upstream developers, and fix it appropriately
until it is accepted.

Only if you feel (/know) it would take substantial cleanup/redesign
efforts until it is accepted upstream, then staging is indeed the way
to go. But then you should know what gates it from upstream merger,
and focus on that (rather than on adding functionality) until it is
taken out of staging. IMHO adding functionality will just make it
harder for you to take it out of staging eventually. Usually the
opposite road is taken: first get a minimal driver accepted upstream,
and then gradually add the missing functionality.

Good luck,
Ohad.

2010-11-18 10:26:43

by Pavan Savoy

[permalink] [raw]
Subject: RE: [PATCH v4 0/6] FM V4L2 drivers for WL128x

Ohad,

> -----Original Message-----
> From: Ohad Ben-Cohen [mailto:[email protected]]
> Sent: Thursday, November 18, 2010 2:36 AM
> To: Savoy, Pavan
> Cc: [email protected]; [email protected]; Halli, Manjunatha; linux-
> [email protected]; [email protected]; Greg KH
> Subject: Re: [PATCH v4 0/6] FM V4L2 drivers for WL128x
>
> Hi Pavan,
>
> > On Wed, Nov 17, 2010 at 6:32 PM, Ohad Ben-Cohen <[email protected]> wrote:
> >>> ?drivers/staging/ti-st/Kconfig ? ? ? ?| ? 10 +
> >>> ?drivers/staging/ti-st/Makefile ? ? ? | ? ?2 +
> >>> ?drivers/staging/ti-st/fmdrv.h ? ? ? ?| ?259 ++++
> >>> ?drivers/staging/ti-st/fmdrv_common.c | 2141
> ++++++++++++++++++++++++++++++++++
> >>> ?drivers/staging/ti-st/fmdrv_common.h | ?458 ++++++++
> >>> ?drivers/staging/ti-st/fmdrv_rx.c ? ? | ?979 ++++++++++++++++
> >>> ?drivers/staging/ti-st/fmdrv_rx.h ? ? | ? 59 +
> >>> ?drivers/staging/ti-st/fmdrv_tx.c ? ? | ?461 ++++++++
> >>> ?drivers/staging/ti-st/fmdrv_tx.h ? ? | ? 37 +
> >>> ?drivers/staging/ti-st/fmdrv_v4l2.c ? | ?757 ++++++++++++
> >>> ?drivers/staging/ti-st/fmdrv_v4l2.h ? | ? 32 +
> >>> ?11 files changed, 5195 insertions(+), 0 deletions(-)
> >>
> >> Usually when a driver is added to staging, it should also have a TODO
> >> file specifying what needs to be done before the driver can be taken
> >> out of staging (at least as far as the author knows of today).
> >>
> >> It helps keeping track of the open issues in the driver, which is good
> >> for everyone - the author, the random contributor/observer, and
> >> probably even the staging maintainer.
> >>
> >> Can you please add such a TODO file ?
> ...
> > Thanks Ohad, for the comments, We do have an internal TODO.
> > In terms of functionality we have stuff like TX RDS which already has
> > few CIDs in the extended controls.
> > extend V4L2 for complete-scan, add in stop search during hw_seek .. etc...
>
> You need to understand and list the reasons why this driver cannot go
> directly to mainline; missing functionality is usually not the
> culprit.

I don't.
I always doubt I would get all the answers from the maintainers if I keep posting 10 files with 200 lines of code in each of them every time.

> > But I just wanted to ask whether this is good enough to be staged.
> > Because as we begin to implement and add in the items in TODO - the
> > patch set will keep continuing to grow.
> >
> > So Hans, Mauro, What do you think ?
> > It would be real helpful - if this can be staged, it is becoming
> > difficult to maintain for us.
>
> Greg has mentioned that staging acceptance rules are:
>
> 1. Code compiles
> 2. Is self sustained (does not touch code out of staging)
> 3. Has a clear roadmap out of staging (that TODO file)
> 4. Is maintained
>
> But I really think you should always prefer to upstream your code
> directly to mainline. Submit the code, have it reviewed by the
> relevant maintainers and upstream developers, and fix it appropriately
> until it is accepted.

Yes, I would love to do that too, however this is the problem we have with
submission of functionally completed code.

> Only if you feel (/know) it would take substantial cleanup/redesign
> efforts until it is accepted upstream, then staging is indeed the way
> to go. But then you should know what gates it from upstream merger,
> and focus on that (rather than on adding functionality) until it is
> taken out of staging. IMHO adding functionality will just make it
> harder for you to take it out of staging eventually. Usually the
> opposite road is taken: first get a minimal driver accepted upstream,
> and then gradually add the missing functionality.

Yes, hence inputs from Hans, Mauro and you too are welcome in suggesting as
To whether it is good enough for staging, and once staged, you are also
Welcome to add on to list of TODOs which we will take care :)

Thanks,
Pavan

> Good luck,
> Ohad.

2010-12-10 06:19:09

by halli manjunatha

[permalink] [raw]
Subject: Re: [PATCH v4 3/6] drivers:staging: ti-st: fmdrv_common sources

Hans,

On Thu, Nov 18, 2010 at 1:49 PM, Hans Verkuil <[email protected]> wrote:
>
> >
> > These are the sources for the common interfaces required by the FM
> > V4L2 driver for TI WL127x and WL128x chips.
> >
<snip...>
>
> OK, I think the way interrupts are handled should be revamped. It is way too
> complex IMHO. All these action/response handlers have a similar structure,
> particularly for the response handlers as this part of the code is the same
> for all as far as I can tell:
>
> ? ? ? ?del_timer(&fmdev->irq_info.int_timeout_timer);
>
> ? ? ? ?ret = __check_cmdresp_status(fmdev, &skb);
> ? ? ? ?if (ret < 0) {
> ? ? ? ? ? ? ? ?pr_err("(fmdrv): Initiating irq recovery process\n");
> ? ? ? ? ? ? ? ?mod_timer(&fmdev->irq_info.int_timeout_timer, jiffies +
> ? ? ? ? ? ? ? ? ? ? ? ? ?FM_DRV_TX_TIMEOUT);
> ? ? ? ? ? ? ? ?return;
> ? ? ? ?}
>
> What I think should happen is that rather than having each handler chain the
> other there is one core handler that is taking care of that. So the boilerplate
> code is in that core handler and it is calling the other handlers. So e.g. the
> hw_malfunction handler below could become something like this:
>
> static int fm_irq_handle_hw_malfunction(struct fmdrv_ops *fmdev, unsigned events)
> {
> ? ? ? ?if (!(events & FM_MAL_EVENT))
> ? ? ? ? ? ? ? ?pr_err("(fmdrv): irq: HW MAL int received - do nothing\n");
> ? ? ? ?return FM_RDS_START_INDEX;
> }
>
> And unsigned events is set to fmdev->irq_info.flag & fmdev->irq_info.mask.
>
> This would refactor out a lot of code.

I tried out similar ways of handling interrupts and also tried out
having a single unified
interrupt handler/core handler and branching out onto various handlers
based on the
events received.
However, the way chip tends to send interrupts is slightly more complex here.

We have cases where 2 or more events are combined together which would
cause the FM interrupt, So when I do a FLAG_GET to request the cause
of interrupt, I will have to always check for each of the individual
bits (13 bits...)
More over when a bit is set say, RDS, and I am in the middle of doing
a GET_RDS, I have more interrupts coming in, which requires me to do a
FLAG_GET (generally a lot of low rssi, stereo/mono events..)

So at the moment all we can do is push the following into a function
and thereby reduce a bit of code size - But not complexity.

> del_timer(&fmdev->irq_info.int_timeout_timer);
>
> ret = __check_cmdresp_status(fmdev, &skb);
> if (ret < 0) {
> pr_err("(fmdrv): Initiating irq recovery process\n");
> mod_timer(&fmdev->irq_info.int_timeout_timer, jiffies +
> FM_DRV_TX_TIMEOUT);
> return;
> }

So, Please suggest on how best such situation where multiple events
have caused 1 interrupt
can be handled ?

example:
After checking HW_MAL function, I begin to check for RDS - this is
where the handler branches out,

check hw malfunction
|
check rds-----------------
| |
<true> <false>--- check for tune_op_ended ---- check
for Tx power enabled
|
send rds get command
|
rds data response
|
rds finish ------------ check for tune_op_ended.------- check for Tx
power enabled...

regards,
Manjunatha,

> > +static void fm_irq_handle_hw_malfunction(void *arg)
> > +{
> > + ? ? struct fmdrv_ops *fmdev;
> > +
> > + ? ? fmdev = arg;
> > + ? ? if (fmdev->irq_info.flag & FM_MAL_EVENT & fmdev->irq_info.mask)
> > + ? ? ? ? ? ? pr_err("(fmdrv): irq: HW MAL int received - do nothing\n");
> > +
> > + ? ? /* Continue next function in interrupt handler table */
> > + ? ? fmdev->irq_info.stage_index = FM_RDS_START_INDEX;
> > + ? ? fmdev->irq_info.fm_int_handlers[fmdev->irq_info.stage_index](fmdev);
> > +}
>
> Regards,
>
> ? ? ? ?Hans
>
> --
> Hans Verkuil - video4linux developer - sponsored by Cisco
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to [email protected]
> More majordomo info at ?http://vger.kernel.org/majordomo-info.html