aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/isdbt/fc8150
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/isdbt/fc8150')
-rw-r--r--drivers/media/isdbt/fc8150/Makefile18
-rw-r--r--drivers/media/isdbt/fc8150/bbm.c287
-rw-r--r--drivers/media/isdbt/fc8150/bbm.h60
-rw-r--r--drivers/media/isdbt/fc8150/fc8150.c525
-rw-r--r--drivers/media/isdbt/fc8150/fc8150.h120
-rw-r--r--drivers/media/isdbt/fc8150/fc8150_bb.c789
-rw-r--r--drivers/media/isdbt/fc8150/fc8150_bb.h22
-rw-r--r--drivers/media/isdbt/fc8150/fc8150_hpi.c197
-rw-r--r--drivers/media/isdbt/fc8150/fc8150_hpi.h33
-rw-r--r--drivers/media/isdbt/fc8150/fc8150_i2c.c237
-rw-r--r--drivers/media/isdbt/fc8150/fc8150_i2c.h33
-rw-r--r--drivers/media/isdbt/fc8150/fc8150_isr.c47
-rw-r--r--drivers/media/isdbt/fc8150/fc8150_isr.h22
-rw-r--r--drivers/media/isdbt/fc8150/fc8150_ppi.c212
-rw-r--r--drivers/media/isdbt/fc8150/fc8150_ppi.h33
-rw-r--r--drivers/media/isdbt/fc8150/fc8150_regs.h136
-rw-r--r--drivers/media/isdbt/fc8150/fc8150_spi.c293
-rw-r--r--drivers/media/isdbt/fc8150/fc8150_spi.h33
-rw-r--r--drivers/media/isdbt/fc8150/fc8150_spib.c210
-rw-r--r--drivers/media/isdbt/fc8150/fc8150_spib.h34
-rw-r--r--drivers/media/isdbt/fc8150/fc8150_tun.c393
-rw-r--r--drivers/media/isdbt/fc8150/fc8150_tun.h26
-rw-r--r--drivers/media/isdbt/fc8150/fc8151_tun.c413
-rw-r--r--drivers/media/isdbt/fc8150/fc8151_tun.h26
-rw-r--r--drivers/media/isdbt/fc8150/fci_bypass.c39
-rw-r--r--drivers/media/isdbt/fc8150/fci_bypass.h34
-rw-r--r--drivers/media/isdbt/fc8150/fci_hal.c245
-rw-r--r--drivers/media/isdbt/fc8150/fci_hal.h37
-rw-r--r--drivers/media/isdbt/fc8150/fci_i2c.c226
-rw-r--r--drivers/media/isdbt/fc8150/fci_i2c.h29
-rw-r--r--drivers/media/isdbt/fc8150/fci_oal.c50
-rw-r--r--drivers/media/isdbt/fc8150/fci_oal.h28
-rw-r--r--drivers/media/isdbt/fc8150/fci_ringbuffer.c271
-rw-r--r--drivers/media/isdbt/fc8150/fci_ringbuffer.h89
-rw-r--r--drivers/media/isdbt/fc8150/fci_tun.c204
-rw-r--r--drivers/media/isdbt/fc8150/fci_tun.h46
-rw-r--r--drivers/media/isdbt/fc8150/fci_types.h61
37 files changed, 5558 insertions, 0 deletions
diff --git a/drivers/media/isdbt/fc8150/Makefile b/drivers/media/isdbt/fc8150/Makefile
new file mode 100644
index 0000000..baf3d0e
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/Makefile
@@ -0,0 +1,18 @@
+obj-y += bbm.o
+obj-y += fc8150.o
+obj-y += fc8150_bb.o
+obj-y += fc8150_hpi.o
+obj-y += fc8150_i2c.o
+obj-y += fc8150_isr.o
+obj-y += fc8150_ppi.o
+obj-y += fc8150_spi.o
+obj-y += fc8150_spib.o
+obj-y += fc8150_tun.o
+obj-y += fci_bypass.o
+obj-y += fci_hal.o
+obj-y += fci_i2c.o
+obj-y += fci_oal.o
+obj-y += fci_ringbuffer.o
+obj-y += fci_tun.o
+
+#ccflags-y += -Idrivers/media/isdbt
diff --git a/drivers/media/isdbt/fc8150/bbm.c b/drivers/media/isdbt/fc8150/bbm.c
new file mode 100644
index 0000000..c9ad7b0
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/bbm.c
@@ -0,0 +1,287 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : bbm.c
+
+ Description : API of 1-SEG baseband module
+
+*******************************************************************************/
+
+#include "fci_types.h"
+#include "fci_tun.h"
+#include "fci_hal.h"
+#include "fc8150_bb.h"
+#include "fc8150_isr.h"
+
+int BBM_RESET(HANDLE hDevice)
+{
+ int res;
+
+ res = fc8150_reset(hDevice);
+
+ return res;
+}
+
+int BBM_PROBE(HANDLE hDevice)
+{
+ int res;
+
+ res = fc8150_probe(hDevice);
+
+ return res;
+}
+
+int BBM_INIT(HANDLE hDevice)
+{
+ int res;
+
+ res = fc8150_init(hDevice);
+
+ return res;
+}
+
+int BBM_DEINIT(HANDLE hDevice)
+{
+ int res;
+
+ res = fc8150_deinit(hDevice);
+
+ return res;
+}
+
+int BBM_READ(HANDLE hDevice, u16 addr, u8 *data)
+{
+ int res;
+
+ res = bbm_read(hDevice, addr, data);
+
+ return res;
+}
+
+int BBM_BYTE_READ(HANDLE hDevice, u16 addr, u8 *data)
+{
+ int res;
+
+ res = bbm_byte_read(hDevice, addr, data);
+
+ return res;
+}
+
+int BBM_WORD_READ(HANDLE hDevice, u16 addr, u16 *data)
+{
+ int res;
+
+ res = bbm_word_read(hDevice, addr, data);
+
+ return res;
+}
+
+int BBM_LONG_READ(HANDLE hDevice, u16 addr, u32 *data)
+{
+ int res;
+
+ res = bbm_long_read(hDevice, addr, data);
+
+ return BBM_OK;
+}
+
+int BBM_BULK_READ(HANDLE hDevice, u16 addr, u8 *data, u16 size)
+{
+ int res;
+
+ res = bbm_bulk_read(hDevice, addr, data, size);
+
+ return res;
+}
+
+int BBM_DATA(HANDLE hDevice, u16 addr, u8 *data, u32 size)
+{
+ int res;
+
+ res = bbm_data(hDevice, addr, data, size);
+
+ return res;
+}
+
+int BBM_WRITE(HANDLE hDevice, u16 addr, u8 data)
+{
+ int res;
+
+ res = bbm_write(hDevice, addr, data);
+
+ return res;
+}
+
+int BBM_BYTE_WRITE(HANDLE hDevice, u16 addr, u8 data)
+{
+ int res;
+
+ res = bbm_byte_write(hDevice, addr, data);
+
+ return res;
+}
+
+int BBM_WORD_WRITE(HANDLE hDevice, u16 addr, u16 data)
+{
+ int res;
+
+ res = bbm_word_write(hDevice, addr, data);
+
+ return res;
+}
+
+int BBM_LONG_WRITE(HANDLE hDevice, u16 addr, u32 data)
+{
+ int res;
+
+ res = bbm_long_write(hDevice, addr, data);
+
+ return res;
+}
+
+int BBM_BULK_WRITE(HANDLE hDevice, u16 addr, u8 *data, u16 size)
+{
+ int res;
+
+ res = bbm_bulk_write(hDevice, addr, data, size);
+
+ return res;
+}
+
+int BBM_I2C_INIT(HANDLE hDevice, u32 type)
+{
+ int res;
+
+ res = tuner_ctrl_select(hDevice, type);
+
+ return res;
+}
+
+int BBM_I2C_DEINIT(HANDLE hDevice)
+{
+ int res;
+
+ res = tuner_ctrl_deselect(hDevice);
+
+ return res;
+}
+
+int BBM_TUNER_READ(HANDLE hDevice, u8 addr, u8 alen, u8 *buffer, u8 len)
+{
+ int res;
+
+ res = tuner_i2c_read(hDevice, addr, alen, buffer, len);
+
+ return res;
+}
+
+int BBM_TUNER_WRITE(HANDLE hDevice, u8 addr, u8 alen, u8 *buffer, u8 len)
+{
+ int res;
+
+ res = tuner_i2c_write(hDevice, addr, alen, buffer, len);
+
+ return res;
+}
+
+int BBM_TUNER_SET_FREQ(HANDLE hDevice, u32 freq)
+{
+ int res;
+
+ res = tuner_set_freq(hDevice, freq);
+
+ return res;
+}
+
+int BBM_TUNER_SELECT(HANDLE hDevice, u32 product, u32 band)
+{
+ int res;
+
+ res = tuner_select(hDevice, product, band);
+
+ return res;
+}
+
+int BBM_TUNER_DESELECT(HANDLE hDevice)
+{
+ int res;
+
+ res = tuner_deselect(hDevice);
+
+ return res;
+}
+
+int BBM_TUNER_GET_RSSI(HANDLE hDevice, s32 *rssi)
+{
+ int res;
+
+ res = tuner_get_rssi(hDevice, rssi);
+
+ return res;
+}
+
+int BBM_SCAN_STATUS(HANDLE hDevice)
+{
+ int res;
+
+ res = fc8150_scan_status(hDevice);
+
+ return res;
+}
+
+void BBM_ISR(HANDLE hDevice)
+{
+ fc8150_isr(hDevice);
+}
+
+int BBM_HOSTIF_SELECT(HANDLE hDevice, u8 hostif)
+{
+ int res;
+
+ res = bbm_hostif_select(hDevice, hostif);
+
+ return res;
+}
+
+int BBM_HOSTIF_DESELECT(HANDLE hDevice)
+{
+ int res;
+
+ res = bbm_hostif_deselect(hDevice);
+
+ return res;
+}
+
+int BBM_TS_CALLBACK_REGISTER(u32 userdata
+ , int (*callback)(u32 userdata, u8 *data, int length))
+{
+ gTSUserData = userdata;
+ pTSCallback = callback;
+
+ return BBM_OK;
+}
+
+int BBM_TS_CALLBACK_DEREGISTER(void)
+{
+ gTSUserData = 0;
+ pTSCallback = NULL;
+
+ return BBM_OK;
+}
+
+int BBM_AC_CALLBACK_REGISTER(u32 userData
+ , int (*callback)(u32 userdata, u8 *data, int length))
+{
+ gACUserData = userData;
+ pACCallback = callback;
+
+ return BBM_OK;
+}
+
+int BBM_AC_CALLBACK_DEREGISTER(void)
+{
+ gACUserData = 0;
+ pACCallback = NULL;
+
+ return BBM_OK;
+}
diff --git a/drivers/media/isdbt/fc8150/bbm.h b/drivers/media/isdbt/fc8150/bbm.h
new file mode 100644
index 0000000..2543681
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/bbm.h
@@ -0,0 +1,60 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : bbm.h
+
+ Description : API of 1-SEG baseband module
+
+*******************************************************************************/
+#ifndef __BBM_H__
+#define __BBM_H__
+
+#include "fci_types.h"
+
+#define DRIVER_VER "VER 2.20.1"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int BBM_RESET(HANDLE hDevice);
+extern int BBM_PROBE(HANDLE hDevice);
+extern int BBM_INIT(HANDLE hDevice);
+extern int BBM_DEINIT(HANDLE hDevice);
+extern int BBM_READ(HANDLE hDevice, u16 addr, u8 *data);
+extern int BBM_BYTE_READ(HANDLE hDevice, u16 addr, u8 *data);
+extern int BBM_WORD_READ(HANDLE hDevice, u16 addr, u16 *data);
+extern int BBM_LONG_READ(HANDLE hDevice, u16 addr, u32 *data);
+extern int BBM_BULK_READ(HANDLE hDevice, u16 addr, u8 *data, u16 size);
+extern int BBM_DATA(HANDLE hDevice, u16 addr, u8 *data, u32 size);
+extern int BBM_WRITE(HANDLE hDevice, u16 addr, u8 data);
+extern int BBM_BYTE_WRITE(HANDLE hDevice, u16 addr, u8 data);
+extern int BBM_WORD_WRITE(HANDLE hDevice, u16 addr, u16 data);
+extern int BBM_LONG_WRITE(HANDLE hDevice, u16 addr, u32 data);
+extern int BBM_BULK_WRITE(HANDLE hDevice, u16 addr, u8 *data, u16 size);
+extern int BBM_I2C_INIT(HANDLE hDevice, u32 type);
+extern int BBM_I2C_DEINIT(HANDLE hDevice);
+extern int BBM_TUNER_SELECT(HANDLE hDevice, u32 product, u32 band);
+extern int BBM_TUNER_DESELECT(HANDLE hDevice);
+extern int BBM_TUNER_READ(HANDLE hDevice, u8 addr
+ , u8 alen, u8 *buffer, u8 len);
+extern int BBM_TUNER_WRITE(HANDLE hDevice, u8 addr
+ , u8 alen, u8 *buffer, u8 len);
+extern int BBM_TUNER_SET_FREQ(HANDLE hDevice, u32 freq);
+extern int BBM_TUNER_GET_RSSI(HANDLE hDevice, s32 *rssi);
+extern int BBM_SCAN_STATUS(HANDLE hDevice);
+extern int BBM_HOSTIF_SELECT(HANDLE hDevice, u8 hostif);
+extern int BBM_HOSTIF_DESELECT(HANDLE hDevice);
+extern int BBM_TS_CALLBACK_REGISTER(u32 userdata
+ , int (*callback)(u32 userdata, u8 *data, int length));
+extern int BBM_TS_CALLBACK_DEREGISTER(void);
+extern int BBM_AC_CALLBACK_REGISTER(u32 userData
+ , int (*callback)(u32 userdata, u8 *data, int length));
+extern int BBM_AC_CALLBACK_DEREGISTER(void);
+extern void BBM_ISR(HANDLE hDevice);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BBM_H__ */
diff --git a/drivers/media/isdbt/fc8150/fc8150.c b/drivers/media/isdbt/fc8150/fc8150.c
new file mode 100644
index 0000000..f6b829f
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fc8150.c
@@ -0,0 +1,525 @@
+#include <linux/miscdevice.h>
+#include <linux/interrupt.h>
+#include <linux/kthread.h>
+#include <linux/poll.h>
+#include <linux/vmalloc.h>
+#include <linux/irq.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/gpio.h>
+
+#include <linux/io.h>
+
+#include <mach/gpio.h>
+
+#include "fc8150.h"
+#include "bbm.h"
+#include "fci_oal.h"
+#include "fci_tun.h"
+#include "fc8150_regs.h"
+#include "fc8150_isr.h"
+#include "fci_hal.h"
+
+struct ISDBT_INIT_INFO_T *hInit;
+
+#define RING_BUFFER_SIZE (128 * 1024) /* kmalloc max 128k */
+
+/* GPIO(RESET & INTRRUPT) Setting */
+#define FC8150_NAME "isdbt"
+
+/*
+#define GPIO_ISDBT_IRQ 0x24
+#define GPIO_ISDBT_PWR_EN 1
+#define GPIO_ISDBT_RST 2
+*/
+#define GPIO_ISDBT_IRQ_FC8150 EXYNOS4_GPC0(4)
+#define GPIO_ISDBT_PWR_EN_FC8150 EXYNOS4_GPC0(2)
+#define GPIO_ISDBT_RST_FC8150 EXYNOS4_GPC0(0)
+
+static DECLARE_WAIT_QUEUE_HEAD(isdbt_isr_wait);
+
+static u8 isdbt_isr_sig;
+static struct task_struct *isdbt_kthread;
+
+static irqreturn_t isdbt_irq(int irq, void *dev_id)
+{
+ isdbt_isr_sig = 1;
+ wake_up_interruptible(&isdbt_isr_wait);
+
+ return IRQ_HANDLED;
+}
+
+int isdbt_hw_setting(void)
+{
+ int err;
+ PRINTF(0, "isdbt_hw_setting\n");
+
+ err = gpio_request(GPIO_ISDBT_PWR_EN_FC8150, "isdbt_en");
+ if (err) {
+ PRINTF(0, "isdbt_hw_setting: Couldn't request isdbt_en\n");
+ goto gpio_isdbt_en;
+ }
+ gpio_direction_output(GPIO_ISDBT_PWR_EN_FC8150, 0);
+
+ err = gpio_request(GPIO_ISDBT_RST_FC8150, "isdbt_rst");
+ if (err) {
+ PRINTF(0, "isdbt_hw_setting: Couldn't request isdbt_rst\n");
+ goto gpio_isdbt_rst;
+ }
+ gpio_direction_output(GPIO_ISDBT_RST_FC8150, 1);
+
+ err = gpio_request(GPIO_ISDBT_IRQ_FC8150, "isdbt_irq");
+ if (err) {
+ PRINTF(0, "isdbt_hw_setting: Couldn't request isdbt_irq\n");
+ goto gpio_isdbt_rst;
+ }
+ gpio_direction_input(GPIO_ISDBT_IRQ_FC8150);
+
+ err = request_irq(gpio_to_irq(GPIO_ISDBT_IRQ_FC8150), isdbt_irq
+ , IRQF_DISABLED | IRQF_TRIGGER_RISING, FC8150_NAME, NULL);
+
+ if (err < 0) {
+ PRINTF(0, "isdbt_hw_setting: couldn't request gpio");
+ PRINTF(0, "interrupt %d reason(%d)\n"
+ , gpio_to_irq(GPIO_ISDBT_IRQ_FC8150), err);
+ goto request_isdbt_irq;
+ }
+ return 0;
+request_isdbt_irq:
+ gpio_free(GPIO_ISDBT_IRQ_FC8150);
+gpio_isdbt_rst:
+ gpio_free(GPIO_ISDBT_PWR_EN_FC8150);
+gpio_isdbt_en:
+ return err;
+}
+
+/*POWER_ON & HW_RESET & INTERRUPT_CLEAR */
+void isdbt_hw_init(void)
+{
+ PRINTF(0, "isdbt_hw_init\n");
+ gpio_set_value(GPIO_ISDBT_PWR_EN_FC8150, 1);
+ gpio_set_value(GPIO_ISDBT_RST_FC8150, 1);
+ mdelay(5);
+ gpio_set_value(GPIO_ISDBT_RST_FC8150, 0);
+ mdelay(1);
+ gpio_set_value(GPIO_ISDBT_RST_FC8150, 1);
+}
+
+/*POWER_OFF */
+void isdbt_hw_deinit(void)
+{
+ PRINTF(0, "isdbt_hw_deinit\n");
+ gpio_set_value(GPIO_ISDBT_PWR_EN_FC8150, 0);
+}
+
+int data_callback(u32 hDevice, u8 *data, int len)
+{
+ struct ISDBT_INIT_INFO_T *hInit;
+ struct list_head *temp;
+ hInit = (struct ISDBT_INIT_INFO_T *)hDevice;
+
+ list_for_each(temp, &(hInit->hHead))
+ {
+ struct ISDBT_OPEN_INFO_T *hOpen;
+
+ hOpen = list_entry(temp, struct ISDBT_OPEN_INFO_T, hList);
+
+ if (hOpen->isdbttype == TS_TYPE) {
+ if (fci_ringbuffer_free(&hOpen->RingBuffer) < (len+2)) {
+ /*PRINTF(hDevice, "f"); */
+ return 0;
+ }
+
+ FCI_RINGBUFFER_WRITE_BYTE(&hOpen->RingBuffer, len >> 8);
+ FCI_RINGBUFFER_WRITE_BYTE(&hOpen->RingBuffer,
+ len & 0xff);
+
+ fci_ringbuffer_write(&hOpen->RingBuffer, data, len);
+
+ wake_up_interruptible(&(hOpen->RingBuffer.queue));
+ }
+ }
+
+ return 0;
+}
+
+static int isdbt_thread(void *hDevice)
+{
+ static DEFINE_MUTEX(thread_lock);
+
+ struct ISDBT_INIT_INFO_T *hInit = (struct ISDBT_INIT_INFO_T *)hDevice;
+
+ set_user_nice(current, -20);
+
+ PRINTF(hInit, "isdbt_kthread enter\n");
+
+ BBM_TS_CALLBACK_REGISTER((u32)hInit, data_callback);
+
+ while (1) {
+ wait_event_interruptible(isdbt_isr_wait,
+ isdbt_isr_sig || kthread_should_stop());
+
+ isdbt_isr_sig = 0;
+
+ BBM_ISR(hInit);
+
+ if (kthread_should_stop())
+ break;
+ }
+
+ BBM_TS_CALLBACK_DEREGISTER();
+
+ PRINTF(hInit, "isdbt_kthread exit\n");
+
+ return 0;
+}
+
+const struct file_operations isdbt_fops = {
+ .owner = THIS_MODULE,
+ .unlocked_ioctl = isdbt_ioctl,
+ .open = isdbt_open,
+ .read = isdbt_read,
+ .release = isdbt_release,
+};
+
+static struct miscdevice fc8150_misc_device = {
+ .minor = MISC_DYNAMIC_MINOR,
+ .name = FC8150_NAME,
+ .fops = &isdbt_fops,
+};
+
+int isdbt_open(struct inode *inode, struct file *filp)
+{
+ struct ISDBT_OPEN_INFO_T *hOpen;
+
+ PRINTF(hInit, "isdbt open\n");
+
+ hOpen = kmalloc(sizeof(struct ISDBT_OPEN_INFO_T), GFP_KERNEL);
+
+ hOpen->buf = kmalloc(RING_BUFFER_SIZE, GFP_KERNEL);
+ hOpen->isdbttype = 0;
+
+ list_add(&(hOpen->hList), &(hInit->hHead));
+
+ hOpen->hInit = (HANDLE *)hInit;
+
+ if (hOpen->buf == NULL) {
+ PRINTF(hInit, "ring buffer malloc error\n");
+ return -ENOMEM;
+ }
+
+ fci_ringbuffer_init(&hOpen->RingBuffer, hOpen->buf, RING_BUFFER_SIZE);
+
+ filp->private_data = hOpen;
+
+ return 0;
+}
+
+ssize_t isdbt_read(struct file *filp, char *buf, size_t count, loff_t *f_pos)
+{
+ s32 avail;
+ s32 non_blocking = filp->f_flags & O_NONBLOCK;
+ struct ISDBT_OPEN_INFO_T *hOpen
+ = (struct ISDBT_OPEN_INFO_T *)filp->private_data;
+ struct fci_ringbuffer *cibuf = &hOpen->RingBuffer;
+ ssize_t len;
+
+ if (!cibuf->data || !count) {
+ /*PRINTF(hInit, " return 0\n"); */
+ return 0;
+ }
+
+ if (non_blocking && (fci_ringbuffer_empty(cibuf))) {
+ /*PRINTF(hInit, "return EWOULDBLOCK\n"); */
+ return -EWOULDBLOCK;
+ }
+
+ if (wait_event_interruptible(cibuf->queue,
+ !fci_ringbuffer_empty(cibuf))) {
+ PRINTF(hInit, "return ERESTARTSYS\n");
+ return -ERESTARTSYS;
+ }
+
+ avail = fci_ringbuffer_avail(cibuf);
+
+ if (avail < 4) {
+ PRINTF(hInit, "return 00\n");
+ return 0;
+ }
+
+ len = FCI_RINGBUFFER_PEEK(cibuf, 0) << 8;
+ len |= FCI_RINGBUFFER_PEEK(cibuf, 1);
+
+ if (avail < len + 2 || count < len) {
+ PRINTF(hInit, "return EINVAL\n");
+ return -EINVAL;
+ }
+
+ FCI_RINGBUFFER_SKIP(cibuf, 2);
+
+ return fci_ringbuffer_read_user(cibuf, buf, len);
+}
+
+int isdbt_release(struct inode *inode, struct file *filp)
+{
+ struct ISDBT_OPEN_INFO_T *hOpen;
+
+ PRINTF(hInit, "isdbt_release\n");
+
+ hOpen = filp->private_data;
+
+ hOpen->isdbttype = 0;
+
+ list_del(&(hOpen->hList));
+ kfree(hOpen->buf);
+ kfree(hOpen);
+
+ return 0;
+}
+
+int fc8150_if_test(void)
+{
+ int res = 0;
+ int i;
+ u16 wdata = 0;
+ u32 ldata = 0;
+ u8 data = 0;
+ u8 temp = 0;
+
+ PRINTF(0, "fc8150_if_test Start!!!\n");
+ for (i = 0 ; i < 100 ; i++) {
+ BBM_BYTE_WRITE(0, 0xa4, i & 0xff);
+ BBM_BYTE_READ(0, 0xa4, &data);
+ if ((i & 0xff) != data) {
+ PRINTF(0, "fc8150_if_btest! i=0x%x, data=0x%x\n"
+ , i & 0xff, data);
+ res = 1;
+ }
+ }
+
+ for (i = 0 ; i < 100 ; i++) {
+ BBM_WORD_WRITE(0, 0xa4, i & 0xffff);
+ BBM_WORD_READ(0, 0xa4, &wdata);
+ if ((i & 0xffff) != wdata) {
+ PRINTF(0, "fc8150_if_wtest! i=0x%x, data=0x%x\n"
+ , i & 0xffff, wdata);
+ res = 1;
+ }
+ }
+
+ for (i = 0 ; i < 100 ; i++) {
+ BBM_LONG_WRITE(0, 0xa4, i & 0xffffffff);
+ BBM_LONG_READ(0, 0xa4, &ldata);
+ if ((i & 0xffffffff) != ldata) {
+ PRINTF(0, "fc8150_if_ltest! i=0x%x, data=0x%x\n"
+ , i & 0xffffffff, ldata);
+ res = 1;
+ }
+ }
+
+ for (i = 0 ; i < 100 ; i++) {
+ temp = i & 0xff;
+ BBM_TUNER_WRITE(NULL, 0x52, 0x01, &temp, 0x01);
+ BBM_TUNER_READ(NULL, 0x52, 0x01, &data, 0x01);
+ if ((i & 0xff) != data)
+ PRINTF(0, "FC8150 tuner test (0x%x,0x%x)\n"
+ , i & 0xff, data);
+ }
+
+ PRINTF(0, "fc8150_if_test End!!!\n");
+
+ return res;
+}
+
+
+long isdbt_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
+{
+ s32 res = BBM_NOK;
+ s32 err = 0;
+ s32 size = 0;
+ struct ISDBT_OPEN_INFO_T *hOpen;
+
+ struct ioctl_info info;
+
+ if (_IOC_TYPE(cmd) != IOCTL_MAGIC)
+ return -EINVAL;
+ if (_IOC_NR(cmd) >= IOCTL_MAXNR)
+ return -EINVAL;
+
+ hOpen = filp->private_data;
+
+ size = _IOC_SIZE(cmd);
+
+ switch (cmd) {
+ case IOCTL_ISDBT_RESET:
+ res = BBM_RESET(hInit);
+ break;
+ case IOCTL_ISDBT_INIT:
+ res = BBM_I2C_INIT(hInit, FCI_I2C_TYPE);
+ res |= BBM_PROBE(hInit);
+ if (res) {
+ PRINTF(hInit, "FC8150 Initialize Fail\n");
+ break;
+ }
+ res |= BBM_INIT(hInit);
+ break;
+ case IOCTL_ISDBT_BYTE_READ:
+ err = copy_from_user((void *)&info, (void *)arg, size);
+ res = BBM_BYTE_READ(hInit, (u16)info.buff[0]
+ , (u8 *)(&info.buff[1]));
+ err |= copy_to_user((void *)arg, (void *)&info, size);
+ break;
+ case IOCTL_ISDBT_WORD_READ:
+ err = copy_from_user((void *)&info, (void *)arg, size);
+ res = BBM_WORD_READ(hInit, (u16)info.buff[0]
+ , (u16 *)(&info.buff[1]));
+ err |= copy_to_user((void *)arg, (void *)&info, size);
+ break;
+ case IOCTL_ISDBT_LONG_READ:
+ err = copy_from_user((void *)&info, (void *)arg, size);
+ res = BBM_LONG_READ(hInit, (u16)info.buff[0]
+ , (u32 *)(&info.buff[1]));
+ err |= copy_to_user((void *)arg, (void *)&info, size);
+ break;
+ case IOCTL_ISDBT_BULK_READ:
+ err = copy_from_user((void *)&info, (void *)arg, size);
+ res = BBM_BULK_READ(hInit, (u16)info.buff[0]
+ , (u8 *)(&info.buff[2]), info.buff[1]);
+ err |= copy_to_user((void *)arg, (void *)&info, size);
+ break;
+ case IOCTL_ISDBT_BYTE_WRITE:
+ err = copy_from_user((void *)&info, (void *)arg, size);
+ res = BBM_BYTE_WRITE(hInit, (u16)info.buff[0]
+ , (u8)info.buff[1]);
+ break;
+ case IOCTL_ISDBT_WORD_WRITE:
+ err = copy_from_user((void *)&info, (void *)arg, size);
+ res = BBM_WORD_WRITE(hInit, (u16)info.buff[0]
+ , (u16)info.buff[1]);
+ break;
+ case IOCTL_ISDBT_LONG_WRITE:
+ err = copy_from_user((void *)&info, (void *)arg, size);
+ res = BBM_LONG_WRITE(hInit, (u16)info.buff[0]
+ , (u32)info.buff[1]);
+ break;
+ case IOCTL_ISDBT_BULK_WRITE:
+ err = copy_from_user((void *)&info, (void *)arg, size);
+ res = BBM_BULK_WRITE(hInit, (u16)info.buff[0]
+ , (u8 *)(&info.buff[2]), info.buff[1]);
+ break;
+ case IOCTL_ISDBT_TUNER_READ:
+ err = copy_from_user((void *)&info, (void *)arg, size);
+ res = BBM_TUNER_READ(hInit, (u8)info.buff[0]
+ , (u8)info.buff[1], (u8 *)(&info.buff[3])
+ , (u8)info.buff[2]);
+ err |= copy_to_user((void *)arg, (void *)&info, size);
+ break;
+ case IOCTL_ISDBT_TUNER_WRITE:
+ err = copy_from_user((void *)&info, (void *)arg, size);
+ res = BBM_TUNER_WRITE(hInit, (u8)info.buff[0]
+ , (u8)info.buff[1], (u8 *)(&info.buff[3])
+ , (u8)info.buff[2]);
+ break;
+ case IOCTL_ISDBT_TUNER_SET_FREQ:
+ {
+ u32 f_rf;
+ err = copy_from_user((void *)&info, (void *)arg, size);
+
+ f_rf = ((u32)info.buff[0] - 13) * 6000 + 473143;
+ res = BBM_TUNER_SET_FREQ(hInit, f_rf);
+ }
+ break;
+ case IOCTL_ISDBT_TUNER_SELECT:
+ err = copy_from_user((void *)&info, (void *)arg, size);
+ res = BBM_TUNER_SELECT(hInit, (u32)info.buff[0], 0);
+ break;
+ case IOCTL_ISDBT_TS_START:
+ hOpen->isdbttype = TS_TYPE;
+ break;
+ case IOCTL_ISDBT_TS_STOP:
+ hOpen->isdbttype = 0;
+ break;
+ case IOCTL_ISDBT_POWER_ON:
+ isdbt_hw_init();
+ break;
+ case IOCTL_ISDBT_POWER_OFF:
+ isdbt_hw_deinit();
+ break;
+ case IOCTL_ISDBT_SCAN_STATUS:
+ res = BBM_SCAN_STATUS(hInit);
+ break;
+ default:
+ PRINTF(hInit, "isdbt ioctl error!\n");
+ res = BBM_NOK;
+ break;
+ }
+
+ if (err < 0) {
+ PRINTF(hInit, "copy to/from user fail : %d", err);
+ res = BBM_NOK;
+ }
+ return res;
+}
+
+int isdbt_init(void)
+{
+ s32 res;
+
+ PRINTF(hInit, "isdbt_init\n");
+
+ res = misc_register(&fc8150_misc_device);
+
+ if (res < 0) {
+ PRINTF(hInit, "isdbt init fail : %d\n", res);
+ return res;
+ }
+
+ isdbt_hw_setting();
+
+ isdbt_hw_init();
+
+ hInit = kmalloc(sizeof(struct ISDBT_INIT_INFO_T), GFP_KERNEL);
+
+ res = BBM_HOSTIF_SELECT(hInit, BBM_SPI);
+
+ if (res)
+ PRINTF(hInit, "isdbt host interface select fail!\n");
+
+ isdbt_hw_deinit();
+
+ if (!isdbt_kthread) {
+ PRINTF(hInit, "kthread run\n");
+ isdbt_kthread = kthread_run(isdbt_thread
+ , (void *)hInit, "isdbt_thread");
+ }
+
+ INIT_LIST_HEAD(&(hInit->hHead));
+
+ return 0;
+}
+
+void isdbt_exit(void)
+{
+ PRINTF(hInit, "isdbt isdbt_exit\n");
+
+ free_irq(gpio_to_irq(GPIO_ISDBT_IRQ_FC8150), NULL);
+ gpio_free(GPIO_ISDBT_IRQ_FC8150);
+ gpio_free(GPIO_ISDBT_RST_FC8150);
+ gpio_free(GPIO_ISDBT_PWR_EN_FC8150);
+
+ kthread_stop(isdbt_kthread);
+ isdbt_kthread = NULL;
+
+ BBM_HOSTIF_DESELECT(hInit);
+
+ isdbt_hw_deinit();
+
+ misc_deregister(&fc8150_misc_device);
+
+ kfree(hInit);
+}
+
+module_init(isdbt_init);
+module_exit(isdbt_exit);
+
+MODULE_LICENSE("Dual BSD/GPL");
diff --git a/drivers/media/isdbt/fc8150/fc8150.h b/drivers/media/isdbt/fc8150/fc8150.h
new file mode 100644
index 0000000..787cc0f
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fc8150.h
@@ -0,0 +1,120 @@
+/*****************************************************************************
+ Copyright(c) 2009 FCI Inc. All Rights Reserved
+
+ File name : bbm.c
+
+ Description : API of dmb baseband module
+
+ History :
+ ----------------------------------------------------------------------
+ 2009/08/29 jason initial
+*******************************************************************************/
+
+#ifndef __ISDBT_H__
+#define __ISDBT_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <linux/list.h>
+
+#include "fci_types.h"
+#include "fci_ringbuffer.h"
+
+#define CTL_TYPE 0
+#define TS_TYPE 1
+
+#define MAX_OPEN_NUM 8
+
+#define IOCTL_MAGIC 't'
+
+struct ioctl_info {
+ unsigned long size;
+ unsigned long buff[128];
+};
+
+#define IOCTL_MAXNR 25
+
+#define IOCTL_ISDBT_RESET \
+ _IO(IOCTL_MAGIC, 0)
+#define IOCTL_ISDBT_PROBE \
+ _IO(IOCTL_MAGIC, 1)
+#define IOCTL_ISDBT_INIT \
+ _IO(IOCTL_MAGIC, 2)
+#define IOCTL_ISDBT_DEINIT \
+ _IO(IOCTL_MAGIC, 3)
+
+#define IOCTL_ISDBT_BYTE_READ \
+ _IOWR(IOCTL_MAGIC, 4, struct ioctl_info)
+#define IOCTL_ISDBT_WORD_READ \
+ _IOWR(IOCTL_MAGIC, 5, struct ioctl_info)
+#define IOCTL_ISDBT_LONG_READ \
+ _IOWR(IOCTL_MAGIC, 6, struct ioctl_info)
+#define IOCTL_ISDBT_BULK_READ \
+ _IOWR(IOCTL_MAGIC, 7, struct ioctl_info)
+
+#define IOCTL_ISDBT_BYTE_WRITE \
+ _IOW(IOCTL_MAGIC, 8, struct ioctl_info)
+#define IOCTL_ISDBT_WORD_WRITE \
+ _IOW(IOCTL_MAGIC, 9, struct ioctl_info)
+#define IOCTL_ISDBT_LONG_WRITE \
+ _IOW(IOCTL_MAGIC, 10, struct ioctl_info)
+#define IOCTL_ISDBT_BULK_WRITE \
+ _IOW(IOCTL_MAGIC, 11, struct ioctl_info)
+
+#define IOCTL_ISDBT_TUNER_READ \
+ _IOWR(IOCTL_MAGIC, 12, struct ioctl_info)
+#define IOCTL_ISDBT_TUNER_WRITE \
+ _IOW(IOCTL_MAGIC, 13, struct ioctl_info)
+
+#define IOCTL_ISDBT_TUNER_SET_FREQ \
+ _IOW(IOCTL_MAGIC, 14, struct ioctl_info)
+#define IOCTL_ISDBT_TUNER_SELECT \
+ _IOW(IOCTL_MAGIC, 15, struct ioctl_info)
+#define IOCTL_ISDBT_TUNER_DESELECT \
+ _IO(IOCTL_MAGIC, 16)
+
+#define IOCTL_ISDBT_SCAN_STATUS \
+ _IO(IOCTL_MAGIC, 17)
+#define IOCTL_ISDBT_TS_START \
+ _IO(IOCTL_MAGIC, 18)
+#define IOCTL_ISDBT_TS_STOP \
+ _IO(IOCTL_MAGIC, 19)
+
+#define IOCTL_ISDBT_TUNER_GET_RSSI \
+ _IOWR(IOCTL_MAGIC, 20, struct ioctl_info)
+
+#define IOCTL_ISDBT_HOSTIF_SELECT \
+ _IOW(IOCTL_MAGIC, 21, struct ioctl_info)
+#define IOCTL_ISDBT_HOSTIF_DESELECT \
+ _IO(IOCTL_MAGIC, 22)
+
+#define IOCTL_ISDBT_POWER_ON \
+ _IO(IOCTL_MAGIC, 23)
+#define IOCTL_ISDBT_POWER_OFF \
+ _IO(IOCTL_MAGIC, 24)
+
+struct ISDBT_OPEN_INFO_T {
+ HANDLE *hInit;
+ struct list_head hList;
+ struct fci_ringbuffer RingBuffer;
+ u8 *buf;
+ u8 isdbttype;
+};
+
+struct ISDBT_INIT_INFO_T {
+ struct list_head hHead;
+};
+
+extern int isdbt_open(struct inode *inode, struct file *filp);
+extern long isdbt_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
+extern int isdbt_release(struct inode *inode, struct file *filp);
+extern ssize_t isdbt_read(struct file *filp
+ , char *buf, size_t count, loff_t *f_pos);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/drivers/media/isdbt/fc8150/fc8150_bb.c b/drivers/media/isdbt/fc8150/fc8150_bb.c
new file mode 100644
index 0000000..e696716
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fc8150_bb.c
@@ -0,0 +1,789 @@
+/*****************************************************************************
+
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : fc8150_bb.c
+
+ Description : API of 1-SEG baseband module
+
+*******************************************************************************/
+
+#include "fci_types.h"
+#include "fci_oal.h"
+#include "fci_hal.h"
+#include "fci_tun.h"
+#include "fc8150_regs.h"
+
+static u8 filter_coef_6M[7][16] = {
+ { 0x00, 0x00, 0x00, 0x07, 0x0f, 0x01, 0x03, 0x04
+ , 0x01, 0x19, 0x14, 0x18, 0x0a, 0x26, 0x40, 0x4a},
+ /*xtal_in : 24,16,32 (adc clk = 4.0000)*/
+ { 0x00, 0x07, 0x07, 0x00, 0x01, 0x03, 0x03, 0x01
+ , 0x1c, 0x17, 0x16, 0x1e, 0x10, 0x27, 0x3b, 0x43},
+ /*xtal_in : 26 (adc clk = 4.3333)*/
+ { 0x00, 0x07, 0x07, 0x00, 0x01, 0x03, 0x03, 0x00
+ , 0x1b, 0x16, 0x16, 0x1f, 0x11, 0x27, 0x3a, 0x41},
+ /*xtal_in : 27,18 (adc clk = 4.5000)*/
+ { 0x00, 0x00, 0x07, 0x07, 0x00, 0x02, 0x03, 0x03
+ , 0x1f, 0x18, 0x14, 0x1a, 0x0c, 0x26, 0x3e, 0x47},
+ /*xtal_in : 16.384, 24.576 (adc clk = 4.0960)*/
+ { 0x00, 0x07, 0x07, 0x00, 0x02, 0x03, 0x02, 0x0f
+ , 0x1a, 0x16, 0x18, 0x02, 0x13, 0x27, 0x38, 0x3e},
+ /*xtal_in : 19.2, 38.4 (adc clk = 4.8000)*/
+ { 0x00, 0x07, 0x07, 0x00, 0x01, 0x03, 0x03, 0x00
+ , 0x1b, 0x16, 0x16, 0x1f, 0x11, 0x27, 0x3a, 0x41},
+ /*xtal_in : 27.12 (adc clk = 4.5200)*/
+ { 0x00, 0x07, 0x07, 0x00, 0x02, 0x03, 0x03, 0x00
+ , 0x1a, 0x16, 0x17, 0x01, 0x12, 0x27, 0x39, 0x3f}
+ /*xtal_in : 37.4 (adc clk = 4.6750)*/
+};
+
+#if 0
+static u8 filter_coef_7M[7][16] = {
+ { 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0e, 0x00, 0x04, 0x05
+ , 0x1f, 0x15, 0x12, 0x01, 0x22, 0x45, 0x55},
+ /*xtal_in : 24,16,32 (adc clk = 4.0000)*/
+ { 0x00, 0x00, 0x00, 0x07, 0x0e, 0x0f, 0x02, 0x05, 0x04
+ , 0x1c, 0x14, 0x14, 0x05, 0x24, 0x43, 0x50},
+ /*xtal_in : 26 (adc clk = 4.3333)*/
+ { 0x00, 0x00, 0x00, 0x07, 0x0f, 0x00, 0x03, 0x05, 0x02
+ , 0x1b, 0x14, 0x16, 0x07, 0x25, 0x42, 0x4d},
+ /*xtal_in : 27,18 (adc clk = 4.5000)*/
+ { 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x01, 0x04, 0x05
+ , 0x1e, 0x15, 0x13, 0x02, 0x23, 0x44, 0x53},
+ /*xtal_in : 16.384, 24.576 (adc clk = 4.0960)*/
+ { 0x00, 0x00, 0x07, 0x07, 0x00, 0x02, 0x04, 0x03, 0x1f
+ , 0x18, 0x14, 0x1a, 0x0c, 0x26, 0x3e, 0x47},
+ /*xtal_in : 19.2, 38.4 (adc clk = 4.8000)*/
+ { 0x00, 0x00, 0x00, 0x07, 0x0f, 0x00, 0x03, 0x05, 0x02
+ , 0x1b, 0x14, 0x16, 0x07, 0x25, 0x41, 0x4d},
+ /*xtal_in : 27.12 (adc clk = 4.5200)*/
+ { 0x00, 0x00, 0x00, 0x07, 0x0f, 0x01, 0x03, 0x04, 0x00
+ , 0x19, 0x14, 0x18, 0x0a, 0x26, 0x3f, 0x4a}
+ /*xtal_in : 37.4 (adc clk = 4.6750)*/
+};
+
+static u8 filter_coef_8M[7][16] = {
+ { 0x00, 0x00, 0x00, 0x01, 0x01, 0x0f, 0x0d, 0x0f, 0x05
+ , 0x06, 0x1d, 0x10, 0xf6, 0x1a, 0x4b, 0x62},
+ /*xtal_in : 24,16,32 (adc clk = 4.0000)*/
+ { 0x00, 0x00, 0x00, 0x01, 0x00, 0x0e, 0x0e, 0x02, 0x06
+ , 0x04, 0x19, 0x10, 0xfb, 0x1e, 0x48, 0x5b},
+ /*xtal_in : 26 (adc clk = 4.3333)*/
+ { 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0e, 0x00, 0x03, 0x05
+ , 0x00, 0x16, 0x11, 0xff, 0x21, 0x46, 0x56},
+ /*xtal_in : 27,18 (adc clk = 4.5000)*/
+ { 0x00, 0x00, 0x00, 0x01, 0x00, 0x0f, 0x0d, 0x00, 0x05
+ , 0x06, 0x1c, 0x10, 0xf7, 0x1b, 0x4a, 0x60},
+ /*xtal_in : 16.384, 24.576 (adc clk = 4.0960)*/
+ { 0x00, 0x00, 0x00, 0x07, 0x0e, 0x0f, 0x01, 0x05, 0x04
+ , 0x1d, 0x14, 0x13, 0x04, 0x23, 0x44, 0x51},
+ /*xtal_in : 19.2, 38.4 (adc clk = 4.8000)*/
+ { 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0e, 0x00, 0x04, 0x05
+ , 0x00, 0x16, 0x12, 0x00, 0x21, 0x46, 0x56},
+ /*xtal_in : 27.12 (adc clk = 4.5200)*/
+ { 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x01, 0x04, 0x05
+ , 0x1e, 0x15, 0x13, 0x02, 0x23, 0x44, 0x53}
+ /*xtal_in : 37.4 (adc clk = 4.6750)*/
+};
+#endif
+
+static void fc8150_clock_mode(HANDLE hDevice)
+{
+ int i;
+
+#if (BBM_XTAL_FREQ == 16000)
+ bbm_write(hDevice, 0x0016, 0);
+
+#if (BBM_BAND_WIDTH == 6)
+ bbm_word_write(hDevice, 0x1032, 0x30a4);
+
+ bbm_long_write(hDevice, 0x103c, 0x1f800000);
+
+ bbm_write(hDevice, 0x200a, 0x04);
+ bbm_write(hDevice, 0x2009, 0x10);
+ bbm_write(hDevice, 0x2008, 0x41);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_6M[0][i]);
+
+#elif (BBM_BAND_WIDTH == 7)
+ bbm_word_write(hDevice, 0x1032, 0x30a4);
+
+ bbm_long_write(hDevice, 0x103c, 0x1b000000);
+
+ bbm_write(hDevice, 0x200a, 0x04);
+ bbm_write(hDevice, 0x2009, 0xbd);
+ bbm_write(hDevice, 0x2008, 0xa1);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_7M[0][i]);
+
+#else
+ bbm_word_write(hDevice, 0x1032, 0x3ae1);
+
+ bbm_long_write(hDevice, 0x103c, 0x17a00000);
+
+ bbm_write(hDevice, 0x200a, 0x05);
+ bbm_write(hDevice, 0x2009, 0x6b);
+ bbm_write(hDevice, 0x2008, 0x01);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_8M[0][i]);
+
+#endif
+
+#elif (BBM_XTAL_FREQ == 16384)
+ bbm_write(hDevice, 0x0016, 0);
+
+#if (BBM_BAND_WIDTH == 6)
+ bbm_word_write(hDevice, 0x1032, 0x2f80);
+
+ bbm_long_write(hDevice, 0x103c, 0x20418937);
+
+ bbm_write(hDevice, 0x200a, 0x03);
+ bbm_write(hDevice, 0x2009, 0xf7);
+ bbm_write(hDevice, 0x2008, 0xdf);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_6M[3][i]);
+
+#elif (BBM_BAND_WIDTH == 7)
+ bbm_word_write(hDevice, 0x1032, 0x2f80);
+
+ bbm_long_write(hDevice, 0x103c, 0x1ba5e354);
+
+ bbm_write(hDevice, 0x200a, 0x04);
+ bbm_write(hDevice, 0x2009, 0xa1);
+ bbm_write(hDevice, 0x2008, 0x2f);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_7M[3][i]);
+
+#else
+ bbm_word_write(hDevice, 0x1032, 0x3980);
+
+ bbm_long_write(hDevice, 0x103c, 0x183126e9);
+
+ bbm_write(hDevice, 0x200a, 0x05);
+ bbm_write(hDevice, 0x2009, 0x4a);
+ bbm_write(hDevice, 0x2008, 0x7f);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_8M[3][i]);
+#endif
+
+#elif (BBM_XTAL_FREQ == 18000)
+ bbm_write(hDevice, 0x0016, 0);
+
+#if (BBM_BAND_WIDTH == 6)
+ bbm_word_write(hDevice, 0x1032, 0x2b3c);
+
+ bbm_long_write(hDevice, 0x103c, 0x23700000);
+
+ bbm_write(hDevice, 0x200a, 0x03);
+ bbm_write(hDevice, 0x2009, 0x9c);
+ bbm_write(hDevice, 0x2008, 0xac);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_6M[2][i]);
+
+#elif (BBM_BAND_WIDTH == 7)
+ bbm_word_write(hDevice, 0x1032, 0x2b3c);
+
+ bbm_long_write(hDevice, 0x103c, 0x1e600000);
+
+ bbm_write(hDevice, 0x200a, 0x04);
+ bbm_write(hDevice, 0x2009, 0x36);
+ bbm_write(hDevice, 0x2008, 0xc8);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_7M[2][i]);
+
+#else
+ bbm_word_write(hDevice, 0x1032, 0x3456);
+
+ bbm_long_write(hDevice, 0x103c, 0x1a940000);
+
+ bbm_write(hDevice, 0x200a, 0x04);
+ bbm_write(hDevice, 0x2009, 0xd0);
+ bbm_write(hDevice, 0x2008, 0xe5);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_8M[2][i]);
+
+#endif
+
+#elif (BBM_XTAL_FREQ == 19200)
+ bbm_write(hDevice, 0x0016, 0);
+
+#if (BBM_BAND_WIDTH == 6)
+ bbm_word_write(hDevice, 0x1032, 0x2889);
+
+ bbm_long_write(hDevice, 0x103c, 0x25cccccd);
+
+ bbm_write(hDevice, 0x200a, 0x03);
+ bbm_write(hDevice, 0x2009, 0x62);
+ bbm_write(hDevice, 0x2008, 0xe1);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_6M[4][i]);
+
+#elif (BBM_BAND_WIDTH == 7)
+ bbm_word_write(hDevice, 0x1032, 0x2889);
+
+ bbm_long_write(hDevice, 0x103c, 0x20666666);
+
+ bbm_write(hDevice, 0x200a, 0x03);
+ bbm_write(hDevice, 0x2009, 0xf3);
+ bbm_write(hDevice, 0x2008, 0x5c);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_7M[4][i]);
+
+#else
+ bbm_word_write(hDevice, 0x1032, 0x3111);
+
+ bbm_long_write(hDevice, 0x103c, 0x1c59999a);
+
+ bbm_write(hDevice, 0x200a, 0x04);
+ bbm_write(hDevice, 0x2009, 0x83);
+ bbm_write(hDevice, 0x2008, 0xd6);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_8M[4][i]);
+
+#endif
+
+#elif (BBM_XTAL_FREQ == 24000)
+ bbm_write(hDevice, 0x0016, 2);
+
+#if (BBM_BAND_WIDTH == 6)
+ bbm_word_write(hDevice, 0x1032, 0x30a4);
+
+ bbm_long_write(hDevice, 0x103c, 0x1f800000);
+
+ bbm_write(hDevice, 0x200a, 0x04);
+ bbm_write(hDevice, 0x2009, 0x10);
+ bbm_write(hDevice, 0x2008, 0x41);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_6M[0][i]);
+
+#elif (BBM_BAND_WIDTH == 7)
+ bbm_word_write(hDevice, 0x1032, 0x30a4);
+
+ bbm_long_write(hDevice, 0x103c, 0x1b000000);
+
+ bbm_write(hDevice, 0x200a, 0x04);
+ bbm_write(hDevice, 0x2009, 0xbd);
+ bbm_write(hDevice, 0x2008, 0xa1);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_7M[0][i]);
+
+#else
+ bbm_word_write(hDevice, 0x1032, 0x3ae1);
+
+ bbm_long_write(hDevice, 0x103c, 0x17a00000);
+
+ bbm_write(hDevice, 0x200a, 0x05);
+ bbm_write(hDevice, 0x2009, 0x6b);
+ bbm_write(hDevice, 0x2008, 0x01);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_8M[0][i]);
+
+#endif
+
+#elif (BBM_XTAL_FREQ == 26000)
+ bbm_write(hDevice, 0x0016, 2);
+
+#if (BBM_BAND_WIDTH == 6)
+ bbm_word_write(hDevice, 0x1032, 0x2ce6);
+
+ bbm_long_write(hDevice, 0x103c, 0x221fffd4);
+
+ bbm_write(hDevice, 0x200a, 0x03);
+ bbm_write(hDevice, 0x2009, 0xc0);
+ bbm_write(hDevice, 0x2008, 0x3c);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_6M[1][i]);
+
+#elif (BBM_BAND_WIDTH == 7)
+ bbm_word_write(hDevice, 0x1032, 0x2ce6);
+
+ bbm_long_write(hDevice, 0x103c, 0x1d3fffda);
+
+ bbm_write(hDevice, 0x200a, 0x04);
+ bbm_write(hDevice, 0x2009, 0x60);
+ bbm_write(hDevice, 0x2008, 0x46);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_7M[1][i]);
+
+#else
+ bbm_word_write(hDevice, 0x1032, 0x365a);
+
+ bbm_long_write(hDevice, 0x103c, 0x1997ffdf);
+
+ bbm_write(hDevice, 0x200a, 0x05);
+ bbm_write(hDevice, 0x2009, 0x00);
+ bbm_write(hDevice, 0x2008, 0x50);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_8M[1][i]);
+
+#endif
+
+#elif (BBM_XTAL_FREQ == 27000)
+ bbm_write(hDevice, 0x0016, 2);
+
+#if (BBM_BAND_WIDTH == 6)
+ bbm_word_write(hDevice, 0x1032, 0x2b3c);
+
+ bbm_long_write(hDevice, 0x103c, 0x23700000);
+
+ bbm_write(hDevice, 0x200a, 0x03);
+ bbm_write(hDevice, 0x2009, 0x9c);
+ bbm_write(hDevice, 0x2008, 0xac);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_6M[2][i]);
+
+#elif (BBM_BAND_WIDTH == 7)
+ bbm_word_write(hDevice, 0x1032, 0x2b3c);
+
+ bbm_long_write(hDevice, 0x103c, 0x1e600000);
+
+ bbm_write(hDevice, 0x200a, 0x04);
+ bbm_write(hDevice, 0x2009, 0x36);
+ bbm_write(hDevice, 0x2008, 0xc8);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_7M[2][i]);
+#else
+ bbm_word_write(hDevice, 0x1032, 0x3456);
+
+ bbm_long_write(hDevice, 0x103c, 0x1a940000);
+
+ bbm_write(hDevice, 0x200a, 0x04);
+ bbm_write(hDevice, 0x2009, 0xd0);
+ bbm_write(hDevice, 0x2008, 0xe5);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_8M[2][i]);
+#endif
+
+#elif (BBM_XTAL_FREQ == 27120)
+ bbm_write(hDevice, 0x0016, 2);
+
+#if (BBM_BAND_WIDTH == 6)
+ bbm_word_write(hDevice, 0x1032, 0x2b0b);
+
+ bbm_long_write(hDevice, 0x103c, 0x239851ec);
+
+ bbm_write(hDevice, 0x200a, 0x03);
+ bbm_write(hDevice, 0x2009, 0x98);
+ bbm_write(hDevice, 0x2008, 0x94);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_6M[5][i]);
+
+#elif (BBM_BAND_WIDTH == 7)
+ bbm_word_write(hDevice, 0x1032, 0x2b0b);
+
+ bbm_long_write(hDevice, 0x103c, 0x1e828f5c);
+
+ bbm_write(hDevice, 0x200a, 0x04);
+ bbm_write(hDevice, 0x2009, 0x32);
+ bbm_write(hDevice, 0x2008, 0x02);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_7M[5][i]);
+
+#else
+ bbm_word_write(hDevice, 0x1032, 0x341b);
+
+ bbm_long_write(hDevice, 0x103c, 0x1ab23d71);
+
+ bbm_write(hDevice, 0x200a, 0x04);
+ bbm_write(hDevice, 0x2009, 0xcb);
+ bbm_write(hDevice, 0x2008, 0x70);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_8M[5][i]);
+
+#endif
+
+#elif (BBM_XTAL_FREQ == 24576)
+ bbm_write(hDevice, 0x0016, 2);
+
+#if (BBM_BAND_WIDTH == 6)
+ bbm_word_write(hDevice, 0x1032, 0x2f80);
+
+ bbm_long_write(hDevice, 0x103c, 0x20418937);
+
+ bbm_write(hDevice, 0x200a, 0x03);
+ bbm_write(hDevice, 0x2009, 0xf7);
+ bbm_write(hDevice, 0x2008, 0xdf);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_6M[3][i]);
+
+#elif (BBM_BAND_WIDTH == 7)
+ bbm_word_write(hDevice, 0x1032, 0x2f80);
+
+ bbm_long_write(hDevice, 0x103c, 0x1ba5e354);
+
+ bbm_write(hDevice, 0x200a, 0x04);
+ bbm_write(hDevice, 0x2009, 0xa1);
+ bbm_write(hDevice, 0x2008, 0x2f);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_7M[3][i]);
+
+#else
+ bbm_word_write(hDevice, 0x1032, 0x3980);
+
+ bbm_long_write(hDevice, 0x103c, 0x183126e9);
+
+ bbm_write(hDevice, 0x200a, 0x05);
+ bbm_write(hDevice, 0x2009, 0x4a);
+ bbm_write(hDevice, 0x2008, 0x7f);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_8M[3][i]);
+
+#endif
+
+#elif (BBM_XTAL_FREQ == 32000)
+ /* Default Clock */
+ bbm_write(hDevice, 0x0016, 1);
+
+#if (BBM_BAND_WIDTH == 6)
+ /* Default Band-width */
+ bbm_word_write(hDevice, 0x1032, 0x30a4);
+
+ bbm_long_write(hDevice, 0x103c, 0x1f800000);
+
+ bbm_write(hDevice, 0x200a, 0x04);
+ bbm_write(hDevice, 0x2009, 0x10);
+ bbm_write(hDevice, 0x2008, 0x41);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_6M[0][i]);
+
+#elif (BBM_BAND_WIDTH == 7)
+ bbm_word_write(hDevice, 0x1032, 0x30a4);
+
+ bbm_long_write(hDevice, 0x103c, 0x1b000000);
+
+ bbm_write(hDevice, 0x200a, 0x04);
+ bbm_write(hDevice, 0x2009, 0xbd);
+ bbm_write(hDevice, 0x2008, 0xa1);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_7M[0][i]);
+
+#else
+ bbm_word_write(hDevice, 0x1032, 0x3ae1);
+
+ bbm_long_write(hDevice, 0x103c, 0x17a00000);
+
+ bbm_write(hDevice, 0x200a, 0x05);
+ bbm_write(hDevice, 0x2009, 0x6b);
+ bbm_write(hDevice, 0x2008, 0x01);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_8M[0][i]);
+
+#endif
+
+#elif (BBM_XTAL_FREQ == 37400)
+ bbm_write(hDevice, 0x0016, 1);
+
+#if (BBM_BAND_WIDTH == 6)
+ bbm_word_write(hDevice, 0x1032, 0x299e);
+
+ bbm_long_write(hDevice, 0x103c, 0x24d0cccd);
+
+ bbm_write(hDevice, 0x200a, 0x03);
+ bbm_write(hDevice, 0x2009, 0x7a);
+ bbm_write(hDevice, 0x2008, 0x0f);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_6M[6][i]);
+
+#elif (BBM_BAND_WIDTH == 7)
+ bbm_word_write(hDevice, 0x1032, 0x299e);
+
+ bbm_long_write(hDevice, 0x103c, 0x1f8e6666);
+
+ bbm_write(hDevice, 0x200a, 0x04);
+ bbm_write(hDevice, 0x2009, 0x0e);
+ bbm_write(hDevice, 0x2008, 0x66);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_7M[6][i]);
+
+#else
+ bbm_word_write(hDevice, 0x1032, 0x3261);
+
+ bbm_long_write(hDevice, 0x103c, 0x1b9c999a);
+
+ bbm_write(hDevice, 0x200a, 0x04);
+ bbm_write(hDevice, 0x2009, 0xa2);
+ bbm_write(hDevice, 0x2008, 0xbe);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_8M[6][i]);
+
+#endif
+
+#elif (BBM_XTAL_FREQ == 38400)
+ bbm_write(hDevice, 0x0016, 1);
+
+#if (BBM_BAND_WIDTH == 6)
+ bbm_word_write(hDevice, 0x1032, 0x2889);
+
+ bbm_long_write(hDevice, 0x103c, 0x25cccccd);
+
+ bbm_write(hDevice, 0x200a, 0x03);
+ bbm_write(hDevice, 0x2009, 0x62);
+ bbm_write(hDevice, 0x2008, 0xe1);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_6M[4][i]);
+
+#elif (BBM_BAND_WIDTH == 7)
+ bbm_word_write(hDevice, 0x1032, 0x2889);
+
+ bbm_long_write(hDevice, 0x103c, 0x20666666);
+
+ bbm_write(hDevice, 0x200a, 0x03);
+ bbm_write(hDevice, 0x2009, 0xf3);
+ bbm_write(hDevice, 0x2008, 0x5c);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_7M[4][i]);
+
+#else
+ bbm_word_write(hDevice, 0x1032, 0x3111);
+
+ bbm_long_write(hDevice, 0x103c, 0x1c59999a);
+
+ bbm_write(hDevice, 0x200a, 0x04);
+ bbm_write(hDevice, 0x2009, 0x83);
+ bbm_write(hDevice, 0x2008, 0xd6);
+
+ for (i = 0; i < 16; i++)
+ bbm_write(hDevice, 0x1040+i, filter_coef_8M[4][i]);
+
+#endif
+#endif
+}
+
+int fc8150_reset(HANDLE hDevice)
+{
+ bbm_write(hDevice, BBM_SW_RESET, 0x7f);
+ bbm_write(hDevice, BBM_SW_RESET, 0xff);
+
+ return BBM_OK;
+}
+
+int fc8150_probe(HANDLE hDevice)
+{
+ u16 ver;
+ bbm_word_read(hDevice, BBM_CHIP_ID_L, &ver);
+
+ return (ver == 0x8150) ? BBM_OK : BBM_NOK;
+}
+
+int fc8150_init(HANDLE hDevice)
+{
+ bbm_write(hDevice, 0x00b0, 0x03);
+ bbm_write(hDevice, 0x00b1, 0x00);
+ bbm_write(hDevice, 0x00b2, 0x14);
+
+ fc8150_reset(hDevice);
+ fc8150_clock_mode(hDevice);
+
+ bbm_write(hDevice, 0x1000, 0x27);
+ bbm_write(hDevice, 0x1004, 0x4d);
+ bbm_write(hDevice, 0x1069, 0x09);
+ bbm_write(hDevice, 0x1075, 0x00);
+
+ bbm_word_write(hDevice, 0x00b4, 0x0000);
+ /*bbm_write(hDevice, 0x00b6, 0x03);*/ /* Default 0x03, 0x00, 0x07*/
+ bbm_write(hDevice, 0x00b9, 0x00);
+ bbm_write(hDevice, 0x00ba, 0x01);
+
+ bbm_write(hDevice, 0x2004, 0x41);
+ bbm_write(hDevice, 0x2106, 0x1f);
+
+ bbm_write(hDevice, 0x5010, 0x00);
+ bbm_write(hDevice, BBM_RS_FAIL_TX, 0x00); /* RS FAILURE TX: 0x02*/
+
+ bbm_word_write(hDevice, BBM_BUF_TS_START, TS_BUF_START);
+ bbm_word_write(hDevice, BBM_BUF_TS_END, TS_BUF_END);
+ bbm_word_write(hDevice, BBM_BUF_TS_THR, TS_BUF_THR);
+
+ /*bbm_word_write(hDevice, BBM_BUF_AC_START, AC_BUF_START);*/
+ /*bbm_word_write(hDevice, BBM_BUF_AC_END, AC_BUF_END);*/
+ /*bbm_word_write(hDevice, BBM_BUF_AC_THR, AC_BUF_THR);*/
+
+ /*bbm_write(hDevice, BBM_INT_POLAR_SEL, 0x00);*/
+ /*bbm_write(hDevice, BBM_INT_AUTO_CLEAR, 0x01);*/
+ /*bbm_write(hDevice, BBM_STATUS_AUTO_CLEAR_EN, 0x00);*/
+
+ bbm_write(hDevice, BBM_BUF_ENABLE, 0x01);
+ bbm_write(hDevice, BBM_BUF_INT, 0x01);
+
+ bbm_write(hDevice, BBM_INT_MASK, 0x07);
+ bbm_write(hDevice, BBM_INT_STS_EN, 0x01);
+
+ return BBM_OK;
+}
+
+int fc8150_deinit(HANDLE hDevice)
+{
+ bbm_write(hDevice, BBM_SW_RESET, 0x00);
+
+ return BBM_OK;
+}
+
+int fc8150_scan_status(HANDLE hDevice)
+{
+ u32 ifagc_timeout = 7;
+ u32 ofdm_timeout = 16;
+ u32 ffs_lock_timeout = 10;
+ u32 dagc_timeout = 100; /* always done*/
+ u32 cfs_timeout = 12;
+ u32 tmcc_timeout = 105;
+ u32 ts_err_free_timeout = 0;
+ int rssi;
+ u8 data, data1;
+ u8 lay0_mod, lay0_cr;
+ int i;
+
+ for (i = 0; i < ifagc_timeout; i++) {
+ bbm_read(hDevice, 0x3025, &data);
+
+ if (data & 0x01)
+ break;
+
+ msWait(10);
+ }
+
+ if (i == ifagc_timeout)
+ return BBM_NOK;
+
+ tuner_get_rssi(hDevice, &rssi);
+
+ if (rssi < -107)
+ return BBM_NOK;
+
+ for (; i < ofdm_timeout; i++) {
+ bbm_read(hDevice, 0x3025, &data);
+
+ if (data & 0x08)
+ break;
+
+ msWait(10);
+ }
+
+ if (i == ofdm_timeout)
+ return BBM_NOK;
+
+ if (0 == (data & 0x04))
+ return BBM_NOK;
+
+ for (; i < ffs_lock_timeout; i++) {
+ bbm_read(hDevice, 0x3026, &data);
+
+ if (data & 0x10)
+ break;
+
+ msWait(10);
+ }
+
+ if (i == ffs_lock_timeout)
+ return BBM_NOK;
+
+ /* DAGC Lock*/
+ for (i = 0; i < dagc_timeout; i++) {
+ bbm_read(hDevice, 0x3026, &data);
+
+ if (data & 0x01)
+ break;
+
+ msWait(10);
+ }
+
+ if (i == dagc_timeout)
+ return BBM_NOK;
+
+ for (i = 0; i < cfs_timeout; i++) {
+ bbm_read(hDevice, 0x3025, &data);
+
+ if (data & 0x40)
+ break;
+
+ msWait(10);
+ }
+
+ if (i == cfs_timeout)
+ return BBM_NOK;
+
+ bbm_read(hDevice, 0x2023, &data1);
+ if (data1 & 1)
+ return BBM_NOK;
+
+ for (i = 0; i < tmcc_timeout; i++) {
+ bbm_read(hDevice, 0x3026, &data);
+ if (data & 0x02)
+ break;
+
+ msWait(10);
+ }
+
+ if (i == tmcc_timeout)
+ return BBM_NOK;
+
+ bbm_read(hDevice, 0x4113, &data);
+ bbm_read(hDevice, 0x4114, &data1);
+
+ if (((data >> 3) & 0x1) == 0)
+ return BBM_NOK;
+
+ lay0_mod = ((data & 0x10) >> 2) |
+ ((data & 0x20) >> 4) |
+ ((data & 0x40) >> 6);
+
+ lay0_cr = ((data & 0x80) >> 5) |
+ ((data1 & 0x01) << 1) |
+ ((data1 & 0x02) >> 1);
+
+ if (!((lay0_mod == 1) || (lay0_mod == 2)))
+ return BBM_NOK;
+
+ if (((0x70 & data) == 0x40) && ((0x1c & data1) == 0x18))
+ ts_err_free_timeout = 400;
+ else
+ ts_err_free_timeout = 650;
+
+ for (i = 0; i < ts_err_free_timeout; i++) {
+ bbm_read(hDevice, 0x5053, &data);
+ if (data & 0x01)
+ break;
+
+ msWait(10);
+ }
+
+ if (i == ts_err_free_timeout)
+ return BBM_NOK;
+
+ return BBM_OK;
+}
diff --git a/drivers/media/isdbt/fc8150/fc8150_bb.h b/drivers/media/isdbt/fc8150/fc8150_bb.h
new file mode 100644
index 0000000..696c621
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fc8150_bb.h
@@ -0,0 +1,22 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : fc8150_bb.h
+
+ Description : API of 1-SEG baseband module
+
+*******************************************************************************/
+
+
+#ifndef __FC8150_BB__
+#define __FC8150_BB__
+
+#include "fci_types.h"
+
+extern int fc8150_reset(HANDLE hDevice);
+extern int fc8150_probe(HANDLE hDevice);
+extern int fc8150_init(HANDLE hDevice);
+extern int fc8150_deinit(HANDLE hDevice);
+extern int fc8150_scan_status(HANDLE hDevice);
+
+#endif
diff --git a/drivers/media/isdbt/fc8150/fc8150_hpi.c b/drivers/media/isdbt/fc8150/fc8150_hpi.c
new file mode 100644
index 0000000..67d8484
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fc8150_hpi.c
@@ -0,0 +1,197 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : fc8150_hpi.c
+
+ Description : fc8150 host interface
+
+*******************************************************************************/
+#include "linux/io.h"
+
+#include "fci_types.h"
+#include "fc8150_regs.h"
+#include "fci_oal.h"
+
+#define HPIC_READ 0x01 /* read command */
+#define HPIC_WRITE 0x02 /* write command */
+#define HPIC_AINC 0x04 /* address increment */
+#define HPIC_BMODE 0x00 /* byte mode */
+#define HPIC_WMODE 0x10 /* word mode */
+#define HPIC_LMODE 0x20 /* long mode */
+#define HPIC_ENDIAN 0x00 /* little endian */
+#define HPIC_CLEAR 0x80 /* currently not used */
+
+#define BBM_BASE_ADDR 0
+#define BBM_BASE_OFFSET 0
+
+#define FC8150_ADDR_REG(x) outb(x, (BBM_BASE_ADDR \
+ + (BBM_ADDRESS_REG << BBM_BASE_OFFSET)))
+#define FC8150_CMD_REG(x) outb(x, (BBM_BASE_ADDR \
+ + (BBM_COMMAND_REG << BBM_BASE_OFFSET)))
+#define FC8150_DATA_REG_OUT(x) outb(x, (BBM_BASE_ADDR \
+ + (BBM_DATA_REG << BBM_BASE_OFFSET)))
+#define FC8150_DATA_REG_IN inb(BBM_BASE_ADDR \
+ + (BBM_DATA_REG << BBM_BASE_OFFSET))
+
+int fc8150_hpi_init(HANDLE hDevice, u16 param1, u16 param2)
+{
+ OAL_CREATE_SEMAPHORE();
+
+ return BBM_OK;
+}
+
+int fc8150_hpi_byteread(HANDLE hDevice, u16 addr, u8 *data)
+{
+ u8 command = HPIC_READ | HPIC_BMODE | HPIC_ENDIAN;
+
+ OAL_OBTAIN_SEMAPHORE();
+ FC8150_ADDR_REG(addr & 0xff);
+ FC8150_ADDR_REG((addr & 0xff00) >> 8);
+ FC8150_CMD_REG(command);
+
+ *data = FC8150_DATA_REG_IN;
+ OAL_RELEASE_SEMAPHORE();
+
+ return BBM_OK;
+}
+
+int fc8150_hpi_wordread(HANDLE hDevice, u16 addr, u16 *data)
+{
+ u8 command = HPIC_READ | HPIC_AINC | HPIC_BMODE | HPIC_ENDIAN;
+
+ OAL_OBTAIN_SEMAPHORE();
+ FC8150_ADDR_REG(addr & 0xff);
+ FC8150_ADDR_REG((addr & 0xff00) >> 8);
+ FC8150_CMD_REG(command);
+
+ *data = FC8150_DATA_REG_IN;
+ *data |= FC8150_DATA_REG_IN << 8;
+ OAL_RELEASE_SEMAPHORE();
+
+ return BBM_OK;
+}
+
+int fc8150_hpi_longread(HANDLE hDevice, u16 addr, u32 *data)
+{
+ u8 command = HPIC_READ | HPIC_AINC | HPIC_BMODE | HPIC_ENDIAN;
+
+ OAL_OBTAIN_SEMAPHORE();
+ FC8150_ADDR_REG(addr & 0xff);
+ FC8150_ADDR_REG((addr & 0xff00) >> 8);
+ FC8150_CMD_REG(command);
+
+ *data = FC8150_DATA_REG_IN;
+ *data |= FC8150_DATA_REG_IN << 8;
+ *data |= FC8150_DATA_REG_IN << 16;
+ *data |= FC8150_DATA_REG_IN << 24;
+ OAL_RELEASE_SEMAPHORE();
+
+ return BBM_OK;
+}
+
+int fc8150_hpi_bulkread(HANDLE hDevice, u16 addr, u8 *data, u16 length)
+{
+ s32 i;
+ u8 command = HPIC_READ | HPIC_AINC | HPIC_BMODE | HPIC_ENDIAN;
+
+ OAL_OBTAIN_SEMAPHORE();
+ FC8150_ADDR_REG(addr & 0xff);
+ FC8150_ADDR_REG((addr & 0xff00) >> 8);
+ FC8150_CMD_REG(command);
+
+ for (i = 0; i < length; i++)
+ data[i] = FC8150_DATA_REG_IN;
+
+ OAL_RELEASE_SEMAPHORE();
+
+ return BBM_OK;
+}
+
+int fc8150_hpi_bytewrite(HANDLE hDevice, u16 addr, u8 data)
+{
+ u8 command = HPIC_WRITE | HPIC_BMODE | HPIC_ENDIAN;
+
+ OAL_OBTAIN_SEMAPHORE();
+ FC8150_ADDR_REG(addr & 0xff);
+ FC8150_ADDR_REG((addr & 0xff00) >> 8);
+ FC8150_CMD_REG(command);
+ FC8150_DATA_REG_OUT(data);
+ OAL_RELEASE_SEMAPHORE();
+
+ return BBM_OK;
+}
+
+int fc8150_hpi_wordwrite(HANDLE hDevice, u16 addr, u16 data)
+{
+ u8 command = HPIC_WRITE | HPIC_BMODE | HPIC_ENDIAN | HPIC_AINC;
+
+ OAL_OBTAIN_SEMAPHORE();
+ FC8150_ADDR_REG(addr & 0xff);
+ FC8150_ADDR_REG((addr & 0xff00) >> 8);
+ FC8150_CMD_REG(command);
+ FC8150_DATA_REG_OUT(data & 0xff);
+ FC8150_DATA_REG_OUT((data & 0xff00) >> 8);
+ OAL_RELEASE_SEMAPHORE();
+
+ return BBM_OK;
+}
+
+int fc8150_hpi_longwrite(HANDLE hDevice, u16 addr, u32 data)
+{
+ u8 command = HPIC_WRITE | HPIC_BMODE | HPIC_ENDIAN | HPIC_AINC;
+
+ OAL_OBTAIN_SEMAPHORE();
+ FC8150_ADDR_REG(addr & 0xff);
+ FC8150_ADDR_REG((addr & 0xff00) >> 8);
+ FC8150_CMD_REG(command);
+
+ FC8150_DATA_REG_OUT(data & 0xff);
+ FC8150_DATA_REG_OUT((data & 0xff00) >> 8);
+ FC8150_DATA_REG_OUT((data & 0xff0000) >> 16);
+ FC8150_DATA_REG_OUT((data & 0xff000000) >> 24);
+ OAL_RELEASE_SEMAPHORE();
+
+ return BBM_OK;
+}
+
+int fc8150_hpi_bulkwrite(HANDLE hDevice, u16 addr, u8 *data, u16 length)
+{
+ s32 i;
+ u8 command = HPIC_WRITE | HPIC_BMODE | HPIC_ENDIAN | HPIC_AINC;
+
+ OAL_OBTAIN_SEMAPHORE();
+ FC8150_ADDR_REG(addr & 0xff);
+ FC8150_ADDR_REG((addr & 0xff00) >> 8);
+ FC8150_CMD_REG(command);
+ for (i = 0; i < length; i++)
+ FC8150_DATA_REG_OUT(data[i]);
+
+ OAL_RELEASE_SEMAPHORE();
+
+ return BBM_OK;
+}
+
+int fc8150_hpi_dataread(HANDLE hDevice, u16 addr, u8 *data, u32 length)
+{
+ s32 i;
+ u8 command = HPIC_READ | HPIC_BMODE | HPIC_ENDIAN;
+
+ OAL_OBTAIN_SEMAPHORE();
+ FC8150_ADDR_REG(addr & 0xff);
+ FC8150_ADDR_REG((addr & 0xff00) >> 8);
+ FC8150_CMD_REG(command);
+
+ for (i = 0; i < length; i++)
+ data[i] = FC8150_DATA_REG_IN;
+
+ OAL_RELEASE_SEMAPHORE();
+
+ return BBM_OK;
+}
+
+int fc8150_hpi_deinit(HANDLE hDevice)
+{
+ OAL_DELETE_SEMAPHORE();
+
+ return BBM_OK;
+}
diff --git a/drivers/media/isdbt/fc8150/fc8150_hpi.h b/drivers/media/isdbt/fc8150/fc8150_hpi.h
new file mode 100644
index 0000000..b99921a
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fc8150_hpi.h
@@ -0,0 +1,33 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : fc8150_hpi.c
+
+ Description : API of 1-SEG baseband module
+
+*******************************************************************************/
+
+#ifndef __FC8150_HPI_H__
+#define __FC8150_HPI_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int fc8150_hpi_init(HANDLE hDevice, u16 param1, u16 param2);
+extern int fc8150_hpi_byteread(HANDLE hDevice, u16 addr, u8 *data);
+extern int fc8150_hpi_wordread(HANDLE hDevice, u16 addr, u16 *data);
+extern int fc8150_hpi_longread(HANDLE hDevice, u16 addr, u32 *data);
+extern int fc8150_hpi_bulkread(HANDLE hDevice, u16 addr, u8 *data, u16 length);
+extern int fc8150_hpi_bytewrite(HANDLE hDevice, u16 addr, u8 data);
+extern int fc8150_hpi_wordwrite(HANDLE hDevice, u16 addr, u16 data);
+extern int fc8150_hpi_longwrite(HANDLE hDevice, u16 addr, u32 data);
+extern int fc8150_hpi_bulkwrite(HANDLE hDevice, u16 addr, u8 *data, u16 length);
+extern int fc8150_hpi_dataread(HANDLE hDevice, u16 addr, u8 *data, u32 length);
+extern int fc8150_hpi_deinit(HANDLE hDevice);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/drivers/media/isdbt/fc8150/fc8150_i2c.c b/drivers/media/isdbt/fc8150/fc8150_i2c.c
new file mode 100644
index 0000000..5d264c1
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fc8150_i2c.c
@@ -0,0 +1,237 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : fc8150_i2c.c
+
+ Description : fc8150 host interface
+
+*******************************************************************************/
+
+#include "fci_types.h"
+#include "fc8150_regs.h"
+#include "fci_oal.h"
+#include "fci_hal.h"
+
+#define HPIC_READ 0x01 /* read command */
+#define HPIC_WRITE 0x02 /* write command */
+#define HPIC_AINC 0x04 /* address increment */
+#define HPIC_BMODE 0x00 /* byte mode */
+#define HPIC_WMODE 0x10 /* word mode */
+#define HPIC_LMODE 0x20 /* long mode */
+#define HPIC_ENDIAN 0x00 /* little endian */
+#define HPIC_CLEAR 0x80 /* currently not used */
+
+#define CHIP_ADDR 0x58
+
+static int i2c_bulkread(HANDLE hDevice, u8 chip, u8 addr, u8 *data, u16 length)
+{
+ /* Write your own i2c driver code here for read operation. */
+
+ return BBM_OK;
+}
+
+static int i2c_bulkwrite(HANDLE hDevice, u8 chip, u8 addr, u8 *data, u16 length)
+{
+ /* Write your own i2c driver code here for Write operation. */
+
+ return BBM_OK;
+}
+
+static int i2c_dataread(HANDLE hDevice, u8 chip, u8 addr, u8 *data, u32 length)
+{
+ return i2c_bulkread(hDevice, chip, addr, data, length);
+}
+
+int fc8150_bypass_read(HANDLE hDevice, u8 chip, u8 addr, u8 *data, u16 length)
+{
+ int res;
+ u8 bypass_addr = 0x03;
+ u8 bypass_data = 1;
+ u8 bypass_len = 1;
+
+ OAL_OBTAIN_SEMAPHORE();
+ res = i2c_bulkwrite(hDevice, CHIP_ADDR, bypass_addr
+ , &bypass_data, bypass_len);
+ res |= i2c_bulkread(hDevice, chip, addr, data, length);
+ OAL_RELEASE_SEMAPHORE();
+
+ return res;
+}
+
+int fc8150_bypass_write(HANDLE hDevice, u8 chip, u8 addr, u8 *data, u16 length)
+{
+ int res;
+ u8 bypass_addr = 0x03;
+ u8 bypass_data = 1;
+ u8 bypass_len = 1;
+
+ OAL_OBTAIN_SEMAPHORE();
+ res = i2c_bulkwrite(hDevice, CHIP_ADDR, bypass_addr
+ , &bypass_data, bypass_len);
+ res |= i2c_bulkwrite(hDevice, chip, addr, data, length);
+ OAL_RELEASE_SEMAPHORE();
+
+ return res;
+}
+
+int fc8150_i2c_init(HANDLE hDevice, u16 param1, u16 param2)
+{
+ OAL_CREATE_SEMAPHORE();
+
+ /* for TSIF, you can call here your own TSIF initialization function. */
+ /* tsif_initialize(); */
+
+ bbm_write(hDevice, BBM_TS_CLK_DIV, 0x04);
+ bbm_write(hDevice, BBM_TS_PAUSE, 0x80);
+
+ bbm_write(hDevice, BBM_TS_CTRL, 0x02);
+ bbm_write(hDevice, BBM_TS_SEL, 0x84);
+
+ return BBM_OK;
+}
+
+int fc8150_i2c_byteread(HANDLE hDevice, u16 addr, u8 *data)
+{
+ int res;
+ u8 command = HPIC_READ | HPIC_BMODE | HPIC_ENDIAN;
+
+ OAL_OBTAIN_SEMAPHORE();
+ res = i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_ADDRESS_REG
+ , (u8 *)&addr, 2);
+ res |= i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_COMMAND_REG, &command, 1);
+ res |= i2c_bulkread(hDevice, CHIP_ADDR, BBM_DATA_REG, data, 1);
+ OAL_RELEASE_SEMAPHORE();
+
+ return res;
+}
+
+int fc8150_i2c_wordread(HANDLE hDevice, u16 addr, u16 *data)
+{
+ int res;
+ u8 command = HPIC_READ | HPIC_AINC | HPIC_BMODE | HPIC_ENDIAN;
+
+ OAL_OBTAIN_SEMAPHORE();
+ res = i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_ADDRESS_REG
+ , (u8 *)&addr, 2);
+ res |= i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_COMMAND_REG, &command, 1);
+ res |= i2c_bulkread(hDevice, CHIP_ADDR, BBM_DATA_REG, (u8 *)data, 2);
+ OAL_RELEASE_SEMAPHORE();
+
+ return res;
+}
+
+int fc8150_i2c_longread(HANDLE hDevice, u16 addr, u32 *data)
+{
+ int res;
+ u8 command = HPIC_READ | HPIC_AINC | HPIC_BMODE | HPIC_ENDIAN;
+
+ OAL_OBTAIN_SEMAPHORE();
+ res = i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_ADDRESS_REG
+ , (u8 *)&addr, 2);
+ res |= i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_COMMAND_REG, &command, 1);
+ res |= i2c_bulkread(hDevice, CHIP_ADDR, BBM_DATA_REG, (u8 *)data, 4);
+ OAL_RELEASE_SEMAPHORE();
+
+ return res;
+}
+
+int fc8150_i2c_bulkread(HANDLE hDevice, u16 addr, u8 *data, u16 length)
+{
+ int res;
+ u8 command = HPIC_READ | HPIC_AINC | HPIC_BMODE | HPIC_ENDIAN;
+
+ OAL_OBTAIN_SEMAPHORE();
+ res = i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_ADDRESS_REG
+ , (u8 *)&addr, 2);
+ res |= i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_COMMAND_REG, &command, 1);
+ res |= i2c_bulkread(hDevice, CHIP_ADDR, BBM_DATA_REG, data, length);
+ OAL_RELEASE_SEMAPHORE();
+
+ return res;
+}
+
+int fc8150_i2c_bytewrite(HANDLE hDevice, u16 addr, u8 data)
+{
+ int res;
+ u8 command = HPIC_WRITE | HPIC_BMODE | HPIC_ENDIAN;
+
+ OAL_OBTAIN_SEMAPHORE();
+ res = i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_ADDRESS_REG
+ , (u8 *)&addr, 2);
+ res |= i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_COMMAND_REG, &command, 1);
+ res |= i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_DATA_REG, (u8 *)&data, 1);
+ OAL_RELEASE_SEMAPHORE();
+
+ return res;
+}
+
+int fc8150_i2c_wordwrite(HANDLE hDevice, u16 addr, u16 data)
+{
+ int res;
+ u8 command = HPIC_WRITE | HPIC_AINC | HPIC_BMODE | HPIC_ENDIAN;
+
+ OAL_OBTAIN_SEMAPHORE();
+ res = i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_ADDRESS_REG
+ , (u8 *)&addr, 2);
+ res |= i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_COMMAND_REG, &command, 1);
+ res |= i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_DATA_REG, (u8 *)&data, 2);
+ OAL_RELEASE_SEMAPHORE();
+
+ return res;
+}
+
+int fc8150_i2c_longwrite(HANDLE hDevice, u16 addr, u32 data)
+{
+ int res;
+ u8 command = HPIC_WRITE | HPIC_AINC | HPIC_BMODE | HPIC_ENDIAN;
+
+ OAL_OBTAIN_SEMAPHORE();
+ res = i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_ADDRESS_REG
+ , (u8 *)&addr, 2);
+ res |= i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_COMMAND_REG, &command, 1);
+ res |= i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_DATA_REG, (u8 *)&data, 4);
+ OAL_RELEASE_SEMAPHORE();
+
+ return res;
+}
+
+int fc8150_i2c_bulkwrite(HANDLE hDevice, u16 addr, u8 *data, u16 length)
+{
+ int res;
+ u8 command = HPIC_WRITE | HPIC_AINC | HPIC_BMODE | HPIC_ENDIAN;
+
+ OAL_OBTAIN_SEMAPHORE();
+ res = i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_ADDRESS_REG
+ , (u8 *)&addr, 2);
+ res |= i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_COMMAND_REG, &command, 1);
+ res |= i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_DATA_REG, data, length);
+ OAL_RELEASE_SEMAPHORE();
+
+ return res;
+}
+
+int fc8150_i2c_dataread(HANDLE hDevice, u16 addr, u8 *data, u32 length)
+{
+ int res;
+ u8 command = HPIC_READ | HPIC_BMODE | HPIC_ENDIAN;
+
+ OAL_OBTAIN_SEMAPHORE();
+ res = i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_ADDRESS_REG
+ , (u8 *)&addr, 2);
+ res |= i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_COMMAND_REG, &command, 1);
+ res |= i2c_dataread(hDevice, CHIP_ADDR, BBM_DATA_REG, data, length);
+ OAL_RELEASE_SEMAPHORE();
+
+ return res;
+}
+
+int fc8150_i2c_deinit(HANDLE hDevice)
+{
+ bbm_write(hDevice, BBM_TS_SEL, 0x00);
+
+ /* tsif_disable(); */
+
+ OAL_DELETE_SEMAPHORE();
+
+ return BBM_OK;
+}
diff --git a/drivers/media/isdbt/fc8150/fc8150_i2c.h b/drivers/media/isdbt/fc8150/fc8150_i2c.h
new file mode 100644
index 0000000..64d69de
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fc8150_i2c.h
@@ -0,0 +1,33 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : fc8150_i2c.c
+
+ Description : API of 1-SEG baseband module
+
+*******************************************************************************/
+
+#ifndef __FC8150_I2C_H__
+#define __FC8150_I2C_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int fc8150_i2c_init(HANDLE hDevice, u16 param1, u16 param2);
+extern int fc8150_i2c_byteread(HANDLE hDevice, u16 addr, u8 *data);
+extern int fc8150_i2c_wordread(HANDLE hDevice, u16 addr, u16 *data);
+extern int fc8150_i2c_longread(HANDLE hDevice, u16 addr, u32 *data);
+extern int fc8150_i2c_bulkread(HANDLE hDevice, u16 addr, u8 *data, u16 length);
+extern int fc8150_i2c_bytewrite(HANDLE hDevice, u16 addr, u8 data);
+extern int fc8150_i2c_wordwrite(HANDLE hDevice, u16 addr, u16 data);
+extern int fc8150_i2c_longwrite(HANDLE hDevice, u16 addr, u32 data);
+extern int fc8150_i2c_bulkwrite(HANDLE hDevice, u16 addr, u8 *data, u16 length);
+extern int fc8150_i2c_dataread(HANDLE hDevice, u16 addr, u8 *data, u32 length);
+extern int fc8150_i2c_deinit(HANDLE hDevice);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/drivers/media/isdbt/fc8150/fc8150_isr.c b/drivers/media/isdbt/fc8150/fc8150_isr.c
new file mode 100644
index 0000000..259576b
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fc8150_isr.c
@@ -0,0 +1,47 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : fc8150_isr.c
+
+ Description : fc8150 interrupt service routine
+
+*******************************************************************************/
+#include "fci_types.h"
+#include "fci_hal.h"
+#include "fci_oal.h"
+#include "fc8150_regs.h"
+
+int (*pTSCallback)(u32 userdata, u8 *data, int length) = NULL;
+int (*pACCallback)(u32 userdata, u8 *data, int length) = NULL;
+
+u32 gTSUserData;
+u32 gACUserData;
+
+/* static u8 acBuffer[AC_BUF_THR]; */
+static u8 tsBuffer[TS_BUF_SIZE];
+
+static void fc8150_data(HANDLE hDevice, u8 bufIntStatus)
+{
+ if (bufIntStatus & 0x01) { /* TS */
+ bbm_data(hDevice, BBM_TS_DATA, &tsBuffer[0], TS_BUF_SIZE/2);
+
+ if (pTSCallback)
+ (*pTSCallback)(gTSUserData
+ , &tsBuffer[0], TS_BUF_SIZE/2);
+ }
+}
+
+void fc8150_isr(HANDLE hDevice)
+{
+ u8 IntStatus = 0;
+ u8 bufIntStatus = 0;
+
+ bbm_read(hDevice, BBM_INT_STATUS, &IntStatus);
+ bbm_write(hDevice, BBM_INT_STATUS, IntStatus);
+
+ bbm_read(hDevice, BBM_BUF_STATUS, &bufIntStatus);
+ if (bufIntStatus) {
+ bbm_write(hDevice, BBM_BUF_STATUS, bufIntStatus);
+ fc8150_data(hDevice, bufIntStatus);
+ }
+}
diff --git a/drivers/media/isdbt/fc8150/fc8150_isr.h b/drivers/media/isdbt/fc8150/fc8150_isr.h
new file mode 100644
index 0000000..d7f1098
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fc8150_isr.h
@@ -0,0 +1,22 @@
+
+#ifndef __FC8150_ISR__
+#define __FC8150_ISR__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "fci_types.h"
+
+extern u32 gACUserData;
+extern u32 gTSUserData;
+
+extern int (*pACCallback)(u32 userdata, u8 *data, int length);
+extern int (*pTSCallback)(u32 userdata, u8 *data, int length);
+
+extern void fc8150_isr(HANDLE hDevice);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/drivers/media/isdbt/fc8150/fc8150_ppi.c b/drivers/media/isdbt/fc8150/fc8150_ppi.c
new file mode 100644
index 0000000..7c9fc07
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fc8150_ppi.c
@@ -0,0 +1,212 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : fc8150_ppi.c
+
+ Description : fc8150 host interface
+
+*******************************************************************************/
+#include "linux/io.h"
+
+#include "fci_types.h"
+#include "fc8150_regs.h"
+#include "fci_oal.h"
+
+#define BBM_BASE_ADDR 0x00
+
+#define PPI_BMODE 0x00
+#define PPI_WMODE 0x10
+#define PPI_LMODE 0x20
+#define PPI_READ 0x40
+#define PPI_WRITE 0x00
+#define PPI_AINC 0x80
+
+#define FC8150_PPI_REG_OUT(x) outb(x, BBM_BASE_ADDR)
+#define FC8150_PPI_REG_IN inb(BBM_BASE_ADDR)
+
+int fc8150_ppi_init(HANDLE hDevice, u16 param1, u16 param2)
+{
+ OAL_CREATE_SEMAPHORE();
+
+ return BBM_OK;
+}
+
+int fc8150_ppi_byteread(HANDLE hDevice, u16 addr, u8 *data)
+{
+ u32 length = 1;
+
+ OAL_OBTAIN_SEMAPHORE();
+ FC8150_PPI_REG_OUT(addr & 0xff);
+ FC8150_PPI_REG_OUT((addr & 0xff00) >> 8);
+ FC8150_PPI_REG_OUT(PPI_READ | ((length & 0x0f0000) >> 16));
+ FC8150_PPI_REG_OUT((length & 0xff00) >> 8);
+ FC8150_PPI_REG_OUT(length & 0xff);
+
+ *data = FC8150_PPI_REG_IN;
+ OAL_RELEASE_SEMAPHORE();
+ return BBM_OK;
+}
+
+int fc8150_ppi_wordread(HANDLE hDevice, u16 addr, u16 *data)
+{
+ u32 length = 2;
+ u8 command = PPI_AINC | PPI_READ | PPI_BMODE;
+
+ OAL_OBTAIN_SEMAPHORE();
+ FC8150_PPI_REG_OUT(addr & 0xff);
+ FC8150_PPI_REG_OUT((addr & 0xff00) >> 8);
+ FC8150_PPI_REG_OUT(command | ((length & 0x0f0000) >> 16));
+ FC8150_PPI_REG_OUT((length & 0xff00) >> 8);
+ FC8150_PPI_REG_OUT(length & 0xff);
+
+ *data = FC8150_PPI_REG_IN;
+ *data |= FC8150_PPI_REG_IN << 8;
+ OAL_RELEASE_SEMAPHORE();
+
+ return BBM_OK;
+}
+
+int fc8150_ppi_longread(HANDLE hDevice, u16 addr, u32 *data)
+{
+ u32 length = 4;
+ u8 command = PPI_AINC | PPI_READ | PPI_BMODE;
+
+ OAL_OBTAIN_SEMAPHORE();
+ FC8150_PPI_REG_OUT(addr & 0xff);
+ FC8150_PPI_REG_OUT((addr & 0xff00) >> 8);
+ FC8150_PPI_REG_OUT(command | ((length & 0x0f0000) >> 16));
+ FC8150_PPI_REG_OUT((length & 0xff00) >> 8);
+ FC8150_PPI_REG_OUT(length & 0xff);
+
+ *data = FC8150_PPI_REG_IN;
+ *data |= FC8150_PPI_REG_IN << 8;
+ *data |= FC8150_PPI_REG_IN << 16;
+ *data |= FC8150_PPI_REG_IN << 24;
+ OAL_RELEASE_SEMAPHORE();
+
+ return BBM_OK;
+}
+
+int fc8150_ppi_bulkread(HANDLE hDevice, u16 addr, u8 *data, u16 length)
+{
+ int i;
+ u8 command = PPI_AINC | PPI_READ | PPI_BMODE;
+
+ OAL_OBTAIN_SEMAPHORE();
+ FC8150_PPI_REG_OUT(addr & 0xff);
+ FC8150_PPI_REG_OUT((addr & 0xff00) >> 8);
+ FC8150_PPI_REG_OUT(command | ((length & 0x0f0000) >> 16));
+ FC8150_PPI_REG_OUT((length & 0xff00) >> 8);
+ FC8150_PPI_REG_OUT(length & 0xff);
+
+ for (i = 0; i < length; i++)
+ data[i] = FC8150_PPI_REG_IN;
+
+ OAL_RELEASE_SEMAPHORE();
+
+ return BBM_OK;
+}
+
+int fc8150_ppi_bytewrite(HANDLE hDevice, u16 addr, u8 data)
+{
+ u32 length = 1;
+
+ OAL_OBTAIN_SEMAPHORE();
+ FC8150_PPI_REG_OUT(addr & 0xff);
+ FC8150_PPI_REG_OUT((addr & 0xff00) >> 8);
+ FC8150_PPI_REG_OUT(PPI_WRITE | ((length & 0x0f0000) >> 16));
+ FC8150_PPI_REG_OUT((length & 0xff00) >> 8);
+ FC8150_PPI_REG_OUT(length & 0xff);
+
+ FC8150_PPI_REG_OUT(data);
+ OAL_RELEASE_SEMAPHORE();
+
+ return BBM_OK;
+}
+
+int fc8150_ppi_wordwrite(HANDLE hDevice, u16 addr, u16 data)
+{
+ u32 length = 2;
+ u8 command = PPI_AINC | PPI_WRITE | PPI_BMODE;
+
+ OAL_OBTAIN_SEMAPHORE();
+ FC8150_PPI_REG_OUT(addr & 0xff);
+ FC8150_PPI_REG_OUT((addr & 0xff00) >> 8);
+ FC8150_PPI_REG_OUT(command | ((length & 0x0f0000) >> 16));
+ FC8150_PPI_REG_OUT((length & 0xff00) >> 8);
+ FC8150_PPI_REG_OUT(length & 0xff);
+
+ FC8150_PPI_REG_OUT(data & 0xff);
+ FC8150_PPI_REG_OUT((data & 0xff00) >> 8);
+ OAL_RELEASE_SEMAPHORE();
+
+ return BBM_OK;
+}
+
+int fc8150_ppi_longwrite(HANDLE hDevice, u16 addr, u32 data)
+{
+ u32 length = 4;
+ u8 command = PPI_AINC | PPI_WRITE | PPI_BMODE;
+
+ OAL_OBTAIN_SEMAPHORE();
+ FC8150_PPI_REG_OUT(addr & 0xff);
+ FC8150_PPI_REG_OUT((addr & 0xff00) >> 8);
+ FC8150_PPI_REG_OUT(command | ((length & 0x0f0000) >> 16));
+ FC8150_PPI_REG_OUT((length & 0xff00) >> 8);
+ FC8150_PPI_REG_OUT(length & 0xff);
+
+ FC8150_PPI_REG_OUT(data & 0x000000ff);
+ FC8150_PPI_REG_OUT((data & 0x0000ff00) >> 8);
+ FC8150_PPI_REG_OUT((data & 0x00ff0000) >> 16);
+ FC8150_PPI_REG_OUT((data & 0xff000000) >> 24);
+ OAL_RELEASE_SEMAPHORE();
+
+ return BBM_OK;
+}
+
+int fc8150_ppi_bulkwrite(HANDLE hDevice, u16 addr, u8 *data, u16 length)
+{
+ int i;
+ u8 command = PPI_AINC | PPI_WRITE | PPI_BMODE;
+
+ OAL_OBTAIN_SEMAPHORE();
+ FC8150_PPI_REG_OUT(addr & 0xff);
+ FC8150_PPI_REG_OUT((addr & 0xff00) >> 8);
+ FC8150_PPI_REG_OUT(command | ((length & 0x0f0000) >> 16));
+ FC8150_PPI_REG_OUT((length & 0xff00) >> 8);
+ FC8150_PPI_REG_OUT(length & 0xff);
+
+ for (i = 0; i < length; i++)
+ FC8150_PPI_REG_OUT(data[i]);
+
+ OAL_RELEASE_SEMAPHORE();
+
+ return BBM_OK;
+}
+
+int fc8150_ppi_dataread(HANDLE hDevice, u16 addr, u8 *data, u32 length)
+{
+ int i;
+ u8 command = PPI_READ | PPI_BMODE;
+
+ OAL_OBTAIN_SEMAPHORE();
+ FC8150_PPI_REG_OUT(addr & 0xff);
+ FC8150_PPI_REG_OUT((addr & 0xff00) >> 8);
+ FC8150_PPI_REG_OUT(command | ((length & 0x0f0000) >> 16));
+ FC8150_PPI_REG_OUT((length & 0xff00) >> 8);
+ FC8150_PPI_REG_OUT(length & 0xff);
+
+ for (i = 0; i < length; i++)
+ data[i] = FC8150_PPI_REG_IN;
+
+ OAL_RELEASE_SEMAPHORE();
+
+ return BBM_OK;
+}
+
+int fc8150_ppi_deinit(HANDLE hDevice)
+{
+ OAL_DELETE_SEMAPHORE();
+
+ return BBM_OK;
+}
diff --git a/drivers/media/isdbt/fc8150/fc8150_ppi.h b/drivers/media/isdbt/fc8150/fc8150_ppi.h
new file mode 100644
index 0000000..b7d5322
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fc8150_ppi.h
@@ -0,0 +1,33 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : fc8150_ppi.c
+
+ Description : API of 1-SEG baseband module
+
+*******************************************************************************/
+
+#ifndef __FC8150_PPI_H__
+#define __FC8150_PPI_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int fc8150_ppi_init(HANDLE hDevice, u16 param1, u16 param2);
+extern int fc8150_ppi_byteread(HANDLE hDevice, u16 addr, u8 *data);
+extern int fc8150_ppi_wordread(HANDLE hDevice, u16 addr, u16 *data);
+extern int fc8150_ppi_longread(HANDLE hDevice, u16 addr, u32 *data);
+extern int fc8150_ppi_bulkread(HANDLE hDevice, u16 addr, u8 *data, u16 length);
+extern int fc8150_ppi_bytewrite(HANDLE hDevice, u16 addr, u8 data);
+extern int fc8150_ppi_wordwrite(HANDLE hDevice, u16 addr, u16 data);
+extern int fc8150_ppi_longwrite(HANDLE hDevice, u16 addr, u32 data);
+extern int fc8150_ppi_bulkwrite(HANDLE hDevice, u16 addr, u8 *data, u16 length);
+extern int fc8150_ppi_dataread(HANDLE hDevice, u16 addr, u8 *data, u32 length);
+extern int fc8150_ppi_deinit(HANDLE hDevice);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/drivers/media/isdbt/fc8150/fc8150_regs.h b/drivers/media/isdbt/fc8150/fc8150_regs.h
new file mode 100644
index 0000000..235e703
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fc8150_regs.h
@@ -0,0 +1,136 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : fc8150_regs.h
+
+ Description : Baseband register header
+
+*******************************************************************************/
+
+#ifndef __FC8150_REGS_H__
+#define __FC8150_REGS_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* #define BBM_XTAL_FREQ 16000 */
+/* #define BBM_XTAL_FREQ 16384 */
+/* #define BBM_XTAL_FREQ 18000 */
+/* #define BBM_XTAL_FREQ 19200 */
+#define BBM_XTAL_FREQ 24000
+/* #define BBM_XTAL_FREQ 26000 */
+/* #define BBM_XTAL_FREQ 27000 */
+/* #define BBM_XTAL_FREQ 27120 */
+/* #define BBM_XTAL_FREQ 24576 */
+/* #define BBM_XTAL_FREQ 32000 */
+/* #define BBM_XTAL_FREQ 37400 */
+/* #define BBM_XTAL_FREQ 38400 */
+
+#define BBM_BAND_WIDTH 6 /* BW = 6M */
+/* #define BBM_BAND_WIDTH 7 */ /* BW = 7M */
+/* #define BBM_BAND_WIDTH 8 */ /* BW = 8M */
+
+ /* Host register */
+#define BBM_ADDRESS_REG 0x00
+#define BBM_COMMAND_REG 0x01
+#define BBM_DATA_REG 0x02
+
+ /* Common */
+#define BBM_AP2APB_LT 0x0000
+#define BBM_SW_RESET 0x0001
+#define BBM_INT_STATUS 0x0002
+#define BBM_INT_MASK 0x0003
+#define BBM_INT_STS_EN 0x0006
+#define BBM_AC_DATA 0x0007
+#define BBM_TS_DATA 0x0008
+#define BBM_TS_CLK_DIV 0x0010
+#define BBM_TS_CTRL 0x0011
+#define BBM_MD_MISO 0x0012
+#define BBM_TS_SEL 0x0013
+#define BBM_TS_PAUSE 0x0014
+#define BBM_RF_DEVID 0x0015
+#define BBM_INT_AUTO_CLEAR 0x0017
+#define BBM_INT_PERIOD 0x0018
+#define BBM_NON_AUTO_INT_PERIOD 0x0019
+#define BBM_STATUS_AUTO_CLEAR_EN 0x001a
+#define BBM_INT_POLAR_SEL 0x0020
+#define BBM_PATTERN_MODE 0x0021
+#define BBM_CHIP_ID_L 0x0026
+#define BBM_CHIP_VERSION 0x0028
+#define BBM_TS_PAT_L 0x00a0
+#define BBM_AC_PAT_L 0x00a2
+#define BBM_VERIFY_TEST 0x00a4
+
+ /* I2C */
+#define BBM_I2C_PR_L 0x0030
+#define BBM_I2C_PR_H 0x0031
+#define BBM_I2C_CTR 0x0032
+#define BBM_I2C_RXR 0x0033
+#define BBM_I2C_SR 0x0034
+#define BBM_I2C_TXR 0x0035
+#define BBM_I2C_CR 0x0036
+
+ /* DM Control */
+#define BBM_DM_AUTO_ENABLE 0x0040
+#define BBM_DM_READ_SIZE 0x0041
+#define BBM_DM_START_ADDR 0x0042
+#define BBM_DM_TIMER_GAP 0x0043
+#define BBM_DM_BUSY 0x0044
+
+ /* RSSI */
+#define BBM_RSSI 0x0100
+
+ /* CE */
+#define BBM_WSCN_MSQ 0x4063
+
+ /* FEC */
+#define BBM_REQ_BER 0x5000
+#define BBM_MAIN_BER_RXD_RSPS 0x5020
+#define BBM_MAIN_BER_ERR_RSPS 0x5022
+#define BBM_MAIN_BER_ERR_BITS 0x5024
+#define BBM_BER_RXD_RSPS 0x5030
+#define BBM_BER_ERR_RSPS 0x5032
+#define BBM_BER_ERR_BITS 0x5034
+#define BBM_DMP_BER_RXD_BITS 0x5040
+#define BBM_DMP_BER_ERR_BITS 0x5044
+
+ /* Buffer */
+#define BBM_BUF_STATUS 0x8000
+#define BBM_BUF_OVERRUN 0x8001
+#define BBM_BUF_ENABLE 0x8002
+#define BBM_BUF_INT 0x8003
+#define BBM_RS_FAIL_TX 0x8004
+
+#define BBM_SYNC_RELATED_INT_STATUS 0x8006
+#define BBM_SYNC_RELATED_INT_ENABLE 0x8007
+#define BBM_HANGING_TS 0x800A
+#define BBM_HANGING_AC 0x800B
+#define BBM_HANGING_ENABLE 0x800C
+
+#define BBM_BUF_TS_START 0x8010
+#define BBM_BUF_AC_START 0x8012
+#define BBM_BUF_TS_END 0x8020
+#define BBM_BUF_AC_END 0x8022
+#define BBM_BUF_TS_THR 0x8030
+#define BBM_BUF_AC_THR 0x8032
+
+ /* DM */
+#define BBM_DM_DATA 0xf001
+
+ /* Buffer Configuration */
+#define TS_BUF_SIZE (188*32*2)
+#define TS_BUF_START (0)
+#define TS_BUF_END (TS_BUF_START+TS_BUF_SIZE-1)
+#define TS_BUF_THR ((TS_BUF_SIZE>>1)-1)
+
+#define AC_BUF_SIZE (204*2)
+#define AC_BUF_START (TS_BUF_START+TS_BUF_SIZE)
+#define AC_BUF_END (AC_BUF_START+AC_BUF_SIZE-1)
+#define AC_BUF_THR ((AC_BUF_SIZE>>1)-1)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/drivers/media/isdbt/fc8150/fc8150_spi.c b/drivers/media/isdbt/fc8150/fc8150_spi.c
new file mode 100644
index 0000000..9903fc8
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fc8150_spi.c
@@ -0,0 +1,293 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : fc8150_spi.c
+
+ Description : fc8150 host interface
+
+*******************************************************************************/
+#include <linux/spi/spi.h>
+#include <linux/slab.h>
+
+#include "fci_types.h"
+#include "fc8150_regs.h"
+#include "fci_oal.h"
+
+#define SPI_BMODE 0x00
+#define SPI_WMODE 0x10
+#define SPI_LMODE 0x20
+#define SPI_READ 0x40
+#define SPI_WRITE 0x00
+#define SPI_AINC 0x80
+#define CHIPID (0 << 3)
+
+#define DRIVER_NAME "fc8150_spi"
+
+struct spi_device *fc8150_spi;
+
+static u8 tx_data[10];
+static u8 rdata_buf[8192];
+static u8 wdata_buf[8192];
+
+static DEFINE_MUTEX(lock);
+
+static int __devinit fc8150_spi_probe(struct spi_device *spi)
+{
+ s32 ret;
+
+ PRINTF(0, "fc8150_spi_probe\n");
+
+ spi->max_speed_hz = 24000000;
+ spi->bits_per_word = 8;
+ spi->mode = SPI_MODE_0;
+
+ ret = spi_setup(spi);
+
+ if (ret < 0)
+ return ret;
+
+ fc8150_spi = spi;
+
+ return ret;
+}
+
+static int fc8150_spi_remove(struct spi_device *spi)
+{
+
+ return 0;
+}
+
+static struct spi_driver fc8150_spi_driver = {
+ .driver = {
+ .name = DRIVER_NAME,
+ .owner = THIS_MODULE,
+ },
+ .probe = fc8150_spi_probe,
+ .remove = __devexit_p(fc8150_spi_remove),
+};
+
+static int fc8150_spi_write_then_read(struct spi_device *spi
+ , u8 *txbuf, u16 tx_length, u8 *rxbuf, u16 rx_length)
+{
+ int res = 0;
+
+ struct spi_message message;
+ struct spi_transfer x;
+
+ spi_message_init(&message);
+ memset(&x, 0, sizeof x);
+
+ spi_message_add_tail(&x, &message);
+
+ memcpy(&wdata_buf[0], txbuf, tx_length);
+
+ x.tx_buf = &wdata_buf[0];
+ x.rx_buf = &rdata_buf[0];
+ x.len = tx_length + rx_length;
+ x.cs_change = 0;
+ x.bits_per_word = 8;
+ res = spi_sync(spi, &message);
+
+ memcpy(rxbuf, x.rx_buf + tx_length, rx_length);
+
+ return res;
+}
+
+static int spi_bulkread(HANDLE hDevice, u16 addr
+ , u8 command, u8 *data, u16 length)
+{
+ int res;
+
+ tx_data[0] = addr & 0xff;
+ tx_data[1] = (addr >> 8) & 0xff;
+ tx_data[2] = (command & 0xf0) | CHIPID | ((length >> 16) & 0x07);
+ tx_data[3] = (length >> 8) & 0xff;
+ tx_data[4] = length & 0xff;
+
+ res = fc8150_spi_write_then_read(fc8150_spi, &tx_data[0]
+ , 5, data, length);
+
+ if (res) {
+ PRINTF(0, "fc8150_spi_bulkread fail : %d\n", res);
+ return BBM_NOK;
+ }
+
+ return BBM_OK;
+}
+
+static int spi_bulkwrite(HANDLE hDevice, u16 addr
+ , u8 command, u8 *data, u16 length)
+{
+ int i;
+ int res;
+
+ tx_data[0] = addr & 0xff;
+ tx_data[1] = (addr >> 8) & 0xff;
+ tx_data[2] = (command & 0xf0) | CHIPID | ((length >> 16) & 0x07);
+ tx_data[3] = (length >> 8) & 0xff;
+ tx_data[4] = length & 0xff;
+
+ for (i = 0; i < length; i++)
+ tx_data[5+i] = data[i];
+
+ res = fc8150_spi_write_then_read(fc8150_spi
+ , &tx_data[0], length+5, NULL, 0);
+
+ if (res) {
+ PRINTF(0, "fc8150_spi_bulkwrite fail : %d\n", res);
+ return BBM_NOK;
+ }
+
+ return BBM_OK;
+}
+
+static int spi_dataread(HANDLE hDevice, u16 addr
+ , u8 command, u8 *data, u32 length)
+{
+ int res;
+
+ tx_data[0] = addr & 0xff;
+ tx_data[1] = (addr >> 8) & 0xff;
+ tx_data[2] = (command & 0xf0) | CHIPID | ((length >> 16) & 0x07);
+ tx_data[3] = (length >> 8) & 0xff;
+ tx_data[4] = length & 0xff;
+
+ res = fc8150_spi_write_then_read(fc8150_spi
+ , &tx_data[0], 5, data, length);
+
+ if (res) {
+ PRINTF(0, "fc8150_spi_dataread fail : %d\n", res);
+ return BBM_NOK;
+ }
+
+ return BBM_OK;
+}
+
+int fc8150_spi_init(HANDLE hDevice, u16 param1, u16 param2)
+{
+ int res = 0;
+
+ PRINTF(0, "fc8150_spi_init : %d\n", res);
+
+ res = spi_register_driver(&fc8150_spi_driver);
+
+ if (res) {
+ PRINTF(0, "fc8150_spi register fail : %d\n", res);
+ return BBM_NOK;
+ }
+
+ return res;
+}
+
+int fc8150_spi_byteread(HANDLE hDevice, u16 addr, u8 *data)
+{
+ int res;
+ u8 command = SPI_READ;
+
+ mutex_lock(&lock);
+ res = spi_bulkread(hDevice, addr, command, data, 1);
+ mutex_unlock(&lock);
+
+ return res;
+}
+
+int fc8150_spi_wordread(HANDLE hDevice, u16 addr, u16 *data)
+{
+ int res;
+ u8 command = SPI_READ | SPI_AINC;
+
+ mutex_lock(&lock);
+ res = spi_bulkread(hDevice, addr, command, (u8 *)data, 2);
+ mutex_unlock(&lock);
+
+ return res;
+}
+
+int fc8150_spi_longread(HANDLE hDevice, u16 addr, u32 *data)
+{
+ int res;
+ u8 command = SPI_READ | SPI_AINC;
+
+ mutex_lock(&lock);
+ res = spi_bulkread(hDevice, addr, command, (u8 *)data, 4);
+ mutex_unlock(&lock);
+
+ return res;
+}
+
+int fc8150_spi_bulkread(HANDLE hDevice, u16 addr, u8 *data, u16 length)
+{
+ int res;
+ u8 command = SPI_READ | SPI_AINC;
+
+ mutex_lock(&lock);
+ res = spi_bulkread(hDevice, addr, command, data, length);
+ mutex_unlock(&lock);
+
+ return res;
+}
+
+int fc8150_spi_bytewrite(HANDLE hDevice, u16 addr, u8 data)
+{
+ int res;
+ u8 command = SPI_WRITE;
+
+ mutex_lock(&lock);
+ res = spi_bulkwrite(hDevice, addr, command, (u8 *)&data, 1);
+ mutex_unlock(&lock);
+
+ return res;
+}
+
+int fc8150_spi_wordwrite(HANDLE hDevice, u16 addr, u16 data)
+{
+ int res;
+ u8 command = SPI_WRITE | SPI_AINC;
+
+ mutex_lock(&lock);
+ res = spi_bulkwrite(hDevice, addr, command, (u8 *)&data, 2);
+ mutex_unlock(&lock);
+
+ return res;
+}
+
+int fc8150_spi_longwrite(HANDLE hDevice, u16 addr, u32 data)
+{
+ int res;
+ u8 command = SPI_WRITE | SPI_AINC;
+
+ mutex_lock(&lock);
+ res = spi_bulkwrite(hDevice, addr, command, (u8 *)&data, 4);
+ mutex_unlock(&lock);
+
+ return res;
+}
+
+int fc8150_spi_bulkwrite(HANDLE hDevice, u16 addr, u8 *data, u16 length)
+{
+ int res;
+ u8 command = SPI_WRITE | SPI_AINC;
+
+ mutex_lock(&lock);
+ res = spi_bulkwrite(hDevice, addr, command, data, length);
+ mutex_unlock(&lock);
+
+ return res;
+}
+
+int fc8150_spi_dataread(HANDLE hDevice, u16 addr, u8 *data, u32 length)
+{
+ int res;
+ u8 command = SPI_READ;
+
+ mutex_lock(&lock);
+ res = spi_dataread(hDevice, addr, command, data, length);
+ mutex_unlock(&lock);
+
+ return res;
+}
+
+int fc8150_spi_deinit(HANDLE hDevice)
+{
+ return BBM_OK;
+}
diff --git a/drivers/media/isdbt/fc8150/fc8150_spi.h b/drivers/media/isdbt/fc8150/fc8150_spi.h
new file mode 100644
index 0000000..6fd96d1
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fc8150_spi.h
@@ -0,0 +1,33 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : fc8150_spi.c
+
+ Description : API of 1-SEG baseband module
+
+*******************************************************************************/
+
+#ifndef __FC8150_SPI__
+#define __FC8150_SPI__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int fc8150_spi_init(HANDLE hDevice, u16 param1, u16 param2);
+extern int fc8150_spi_byteread(HANDLE hDevice, u16 addr, u8 *data);
+extern int fc8150_spi_wordread(HANDLE hDevice, u16 addr, u16 *data);
+extern int fc8150_spi_longread(HANDLE hDevice, u16 addr, u32 *data);
+extern int fc8150_spi_bulkread(HANDLE hDevice, u16 addr, u8 *data, u16 length);
+extern int fc8150_spi_bytewrite(HANDLE hDevice, u16 addr, u8 data);
+extern int fc8150_spi_wordwrite(HANDLE hDevice, u16 addr, u16 data);
+extern int fc8150_spi_longwrite(HANDLE hDevice, u16 addr, u32 data);
+extern int fc8150_spi_bulkwrite(HANDLE hDevice, u16 addr, u8 *data, u16 length);
+extern int fc8150_spi_dataread(HANDLE hDevice, u16 addr, u8 *data, u32 length);
+extern int fc8150_spi_deinit(HANDLE hDevice);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/drivers/media/isdbt/fc8150/fc8150_spib.c b/drivers/media/isdbt/fc8150/fc8150_spib.c
new file mode 100644
index 0000000..b2feccb
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fc8150_spib.c
@@ -0,0 +1,210 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : fc8150_spib.c
+
+ Description : fc8150 host interface
+
+*******************************************************************************/
+#include "fci_types.h"
+#include "fc8150_regs.h"
+#include "fci_oal.h"
+
+#define SPI_BMODE 0x00
+#define SPI_WMODE 0x10
+#define SPI_LMODE 0x20
+#define SPI_READ 0x40
+#define SPI_WRITE 0x00
+#define SPI_AINC 0x80
+#define CHIPID (0 << 3)
+
+static int spi_bulkread(HANDLE hDevice, u16 addr
+, u8 command, u8 *data, u16 length)
+{
+ /*unsigned char *cmd;
+
+ cmd = g_SpiCmd;
+
+ cmd[0] = addr & 0xff;
+ cmd[1] = (addr >> 8) & 0xff;
+ cmd[2] = (command & 0xf0) | CHIPID | ((length >> 16) & 0x07);
+ cmd[3] = (length >> 8) & 0xff;
+ cmd[4] = length & 0xff;
+
+ spi_cmd.pCmd = cmd;
+ spi_cmd.cmdSize = 5;
+ spi_cmd.pData = g_SpiData;
+ spi_cmd.dataSize = length;
+
+ // Send Command and data through the SPI
+ if (SPID_SendCommand_ByteRead(&spid, &spi_cmd))
+ return BBM_NOK;
+
+ memcpy(data, g_SpiData, length);*/
+
+ return BBM_OK;
+}
+
+static int spi_bulkwrite(HANDLE hDevice, u16 addr
+ , u8 command, u8 *data, u16 length)
+{
+ /*unsigned char *cmd;
+
+ cmd = g_SpiCmd;
+
+ cmd[0] = addr & 0xff;
+ cmd[1] = (addr >> 8) & 0xff;
+ cmd[2] = (command & 0xf0) | CHIPID | ((length >> 16) & 0x07);
+ cmd[3] = (length >> 8) & 0xff;
+ cmd[4] = length & 0xff;
+
+ spi_cmd.pCmd = cmd;
+ spi_cmd.cmdSize = 5;
+ spi_cmd.pData = g_SpiData;
+ memcpy(g_SpiData, data, length);
+ spi_cmd.dataSize = length;
+
+ // Send Command and data through the SPI
+ if (SPID_SendCommand_ByteWrite(&spid, &spi_cmd))
+ return BBM_NOK;*/
+
+ return BBM_OK;
+}
+
+static int spi_dataread(HANDLE hDevice, u16 addr
+ , u8 command, u8 *data, u32 length)
+{
+ /*unsigned char *cmd;
+
+ cmd = g_SpiCmd;
+
+ cmd[0] = addr & 0xff;
+ cmd[1] = (addr >> 8) & 0xff;
+ cmd[2] = (command & 0xf0) | CHIPID | ((length >> 16) & 0x07);
+ cmd[3] = (length >> 8) & 0xff;
+ cmd[4] = length & 0xff;
+
+ spi_cmd.pCmd = cmd;
+ spi_cmd.cmdSize = 5;
+ spi_cmd.pData = data;
+ spi_cmd.dataSize = length;
+
+ // Send Command and data through the SPI
+ if (SPID_SendCommand_ByteRead(&spid, &spi_cmd))
+ return BBM_NOK;*/
+
+ return BBM_OK;
+}
+
+int fc8150_spib_init(HANDLE hDevice, u16 param1, u16 param2)
+{
+ OAL_CREATE_SEMAPHORE();
+
+ return BBM_OK;
+}
+
+int fc8150_spib_byteread(HANDLE hDevice, u16 addr, u8 *data)
+{
+ int res;
+ u8 command = SPI_READ;
+
+ OAL_OBTAIN_SEMAPHORE();
+ res = spi_bulkread(hDevice, addr, command, data, 1);
+ OAL_RELEASE_SEMAPHORE();
+ return res;
+}
+
+int fc8150_spib_wordread(HANDLE hDevice, u16 addr, u16 *data)
+{
+ int res;
+ u8 command = SPI_READ | SPI_AINC;
+
+ OAL_OBTAIN_SEMAPHORE();
+ res = spi_bulkread(hDevice, addr, command, (u8 *)data, 2);
+ OAL_RELEASE_SEMAPHORE();
+ return res;
+}
+
+int fc8150_spib_longread(HANDLE hDevice, u16 addr, u32 *data)
+{
+ int res;
+ u8 command = SPI_READ | SPI_AINC;
+
+ OAL_OBTAIN_SEMAPHORE();
+ res = spi_bulkread(hDevice, addr, command, (u8 *)data, 4);
+ OAL_RELEASE_SEMAPHORE();
+ return res;
+}
+
+int fc8150_spib_bulkread(HANDLE hDevice, u16 addr, u8 *data, u16 length)
+{
+ int res;
+ u8 command = SPI_READ | SPI_AINC;
+
+ OAL_OBTAIN_SEMAPHORE();
+ res = spi_bulkread(hDevice, addr, command, data, length);
+ OAL_RELEASE_SEMAPHORE();
+ return res;
+}
+
+int fc8150_spib_bytewrite(HANDLE hDevice, u16 addr, u8 data)
+{
+ int res;
+ u8 command = SPI_WRITE;
+
+ OAL_OBTAIN_SEMAPHORE();
+ res = spi_bulkwrite(hDevice, addr, command, (u8 *)&data, 1);
+ OAL_RELEASE_SEMAPHORE();
+ return res;
+}
+
+int fc8150_spib_wordwrite(HANDLE hDevice, u16 addr, u32 data)
+{
+ int res;
+ u8 command = SPI_WRITE | SPI_AINC;
+
+ OAL_OBTAIN_SEMAPHORE();
+ res = spi_bulkwrite(hDevice, addr, command, (u8 *)&data, 2);
+ OAL_RELEASE_SEMAPHORE();
+ return res;
+}
+
+int fc8150_spib_longwrite(HANDLE hDevice, u16 addr, u32 data)
+{
+ int res;
+ u8 command = SPI_WRITE | SPI_AINC;
+
+ OAL_OBTAIN_SEMAPHORE();
+ res = spi_bulkwrite(hDevice, addr, command, (u8 *)&data, 4);
+ OAL_RELEASE_SEMAPHORE();
+ return res;
+}
+
+int fc8150_spib_bulkwrite(HANDLE hDevice, u16 addr, u8 *data, u16 length)
+{
+ int res;
+ u8 command = SPI_WRITE | SPI_AINC;
+
+ OAL_OBTAIN_SEMAPHORE();
+ res = spi_bulkwrite(hDevice, addr, command, data, length);
+ OAL_RELEASE_SEMAPHORE();
+ return res;
+}
+
+int fc8150_spib_dataread(HANDLE hDevice, u16 addr, u8 *data, u32 length)
+{
+ int res;
+ u8 command = SPI_READ;
+
+ OAL_OBTAIN_SEMAPHORE();
+ res = spi_dataread(hDevice, addr, command, data, length);
+ OAL_RELEASE_SEMAPHORE();
+ return res;
+}
+
+int fc8150_spib_deinit(HANDLE hDevice)
+{
+ OAL_DELETE_SEMAPHORE();
+
+ return BBM_OK;
+}
diff --git a/drivers/media/isdbt/fc8150/fc8150_spib.h b/drivers/media/isdbt/fc8150/fc8150_spib.h
new file mode 100644
index 0000000..86b28eb
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fc8150_spib.h
@@ -0,0 +1,34 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : fc8150_spib.c
+
+ Description : API of 1-SEG baseband module
+
+*******************************************************************************/
+
+#ifndef __FC8150_SPIB__
+#define __FC8150_SPIB__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int fc8150_spib_init(HANDLE hDevice, u16 param1, u16 param2);
+extern int fc8150_spib_byteread(HANDLE hDevice, u16 addr, u8 *data);
+extern int fc8150_spib_wordread(HANDLE hDevice, u16 addr, u16 *data);
+extern int fc8150_spib_longread(HANDLE hDevice, u16 addr, u32 *data);
+extern int fc8150_spib_bulkread(HANDLE hDevice, u16 addr, u8 *data, u16 length);
+extern int fc8150_spib_bytewrite(HANDLE hDevice, u16 addr, u8 data);
+extern int fc8150_spib_wordwrite(HANDLE hDevice, u16 addr, u16 data);
+extern int fc8150_spib_longwrite(HANDLE hDevice, u16 addr, u32 data);
+extern int fc8150_spib_bulkwrite(HANDLE hDevice, u16 addr
+ , u8 *data, u16 length);
+extern int fc8150_spib_dataread(HANDLE hDevice, u16 addr, u8 *data, u32 length);
+extern int fc8150_spib_deinit(HANDLE hDevice);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/drivers/media/isdbt/fc8150/fc8150_tun.c b/drivers/media/isdbt/fc8150/fc8150_tun.c
new file mode 100644
index 0000000..644bf42
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fc8150_tun.c
@@ -0,0 +1,393 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : fc8150_tun.c (BGA & QFN)
+
+ Description : fc8150 tuner driver
+
+ History :
+ ----------------------------------------------------------------------
+ 2012/01/20 initial 0.1 version
+ 2012/01/25 initial 0.3 version
+ 2012/01/27 initial 0.5 version
+ 2012/01/31 initial 1.0 version
+ 2012/01/31 initial 1.1 version
+ 2012/02/06 initial 1.2 version
+ 2012/02/09 initial 1.3 Version
+ 2012/02/15 initial 1.4 Version
+ 2012/02/15 initial 2.0 Version
+ 2012/02/24 initial 2.01 Version
+ 2012/03/30 initial 3.0 Version
+ 2012/06/07 pre SLR Version
+ 2012/06/11 pre SLR Version
+ 2012/06/15
+ 2012/06/17 SLR 0.3 version
+ 2012/06/19 SLR 0.4 version
+ 2012/06/20
+ 2012/07/04
+ 2012/07/09
+ 2012/07/10
+ 2012/07/15
+*******************************************************************************/
+
+#include "fci_types.h"
+#include "fci_oal.h"
+#include "fci_tun.h"
+#include "fc8150_regs.h"
+#include "fci_hal.h"
+
+#define FC8150_FREQ_XTAL BBM_XTAL_FREQ /* 32MHZ */
+
+static int fc8150_write(HANDLE hDevice, u8 addr, u8 data)
+{
+ int res;
+ u8 tmp;
+
+ tmp = data;
+ res = tuner_i2c_write(hDevice, addr, 1, &tmp, 1);
+
+ return res;
+}
+
+static int fc8150_read(HANDLE hDevice, u8 addr, u8 *data)
+{
+ int res;
+
+ res = tuner_i2c_read(hDevice, addr, 1, data, 1);
+
+ return res;
+}
+
+static int fc8150_bb_read(HANDLE hDevice, u16 addr, u8 *data)
+{
+ int res;
+
+ res = bbm_read(hDevice, addr, data);
+
+ return res;
+}
+
+#if 0
+static int fc8150_bb_write(HANDLE hDevice, u16 addr, u8 data)
+{
+ int res;
+
+ res = bbm_write(hDevice, addr, data);
+
+ return res;
+}
+#endif
+
+static int fc8150_set_filter(HANDLE hDevice)
+{
+ int i;
+ u8 cal_mon = 0;
+
+#if (FC8150_FREQ_XTAL == 16000)
+ fc8150_write(hDevice, 0x3B, 0x01);
+ fc8150_write(hDevice, 0x3D, 0x20);
+ fc8150_write(hDevice, 0x3B, 0x00);
+#elif (FC8150_FREQ_XTAL == 16384)
+ fc8150_write(hDevice, 0x3B, 0x01);
+ fc8150_write(hDevice, 0x3D, 0x21);
+ fc8150_write(hDevice, 0x3B, 0x00);
+#elif (FC8150_FREQ_XTAL == 18000)
+ fc8150_write(hDevice, 0x3B, 0x01);
+ fc8150_write(hDevice, 0x3D, 0x24);
+ fc8150_write(hDevice, 0x3B, 0x00);
+#elif (FC8150_FREQ_XTAL == 19200)
+ fc8150_write(hDevice, 0x3B, 0x01);
+ fc8150_write(hDevice, 0x3D, 0x26);
+ fc8150_write(hDevice, 0x3B, 0x00);
+#elif (FC8150_FREQ_XTAL == 24000)
+ fc8150_write(hDevice, 0x3B, 0x01);
+ fc8150_write(hDevice, 0x3D, 0x30);
+ fc8150_write(hDevice, 0x3B, 0x00);
+#elif (FC8150_FREQ_XTAL == 24576)
+ fc8150_write(hDevice, 0x3B, 0x01);
+ fc8150_write(hDevice, 0x3D, 0x31);
+ fc8150_write(hDevice, 0x3B, 0x00);
+#elif (FC8150_FREQ_XTAL == 26000)
+ fc8150_write(hDevice, 0x3B, 0x01);
+ fc8150_write(hDevice, 0x3D, 0x34);
+ fc8150_write(hDevice, 0x3B, 0x00);
+#elif (FC8150_FREQ_XTAL == 27000)
+ fc8150_write(hDevice, 0x3B, 0x01);
+ fc8150_write(hDevice, 0x3D, 0x36);
+ fc8150_write(hDevice, 0x3B, 0x00);
+#elif (FC8150_FREQ_XTAL == 27120)
+ fc8150_write(hDevice, 0x3B, 0x01);
+ fc8150_write(hDevice, 0x3D, 0x36);
+ fc8150_write(hDevice, 0x3B, 0x00);
+#elif (FC8150_FREQ_XTAL == 32000)
+ fc8150_write(hDevice, 0x3B, 0x01);
+ fc8150_write(hDevice, 0x3D, 0x40);
+ fc8150_write(hDevice, 0x3B, 0x00);
+#elif (FC8150_FREQ_XTAL == 37400)
+ fc8150_write(hDevice, 0x3B, 0x01);
+ fc8150_write(hDevice, 0x3D, 0x4B);
+ fc8150_write(hDevice, 0x3B, 0x00);
+#elif (FC8150_FREQ_XTAL == 38400)
+ fc8150_write(hDevice, 0x3B, 0x01);
+ fc8150_write(hDevice, 0x3D, 0x4D);
+ fc8150_write(hDevice, 0x3B, 0x00);
+#else
+ return BBM_NOK;
+#endif
+
+ for (i = 0; i < 10; i++) {
+ msWait(5);
+ fc8150_read(hDevice, 0x33, &cal_mon);
+ if ((cal_mon & 0xC0) == 0xC0)
+ break;
+ fc8150_write(hDevice, 0x32, 0x01);
+ fc8150_write(hDevice, 0x32, 0x09);
+ }
+
+ fc8150_write(hDevice, 0x32, 0x01);
+
+ return BBM_OK;
+}
+
+int fc8150_tuner_init(HANDLE hDevice, u32 band)
+{
+ int i;
+ int n_RFAGC_PD1_AVG, n_RFAGC_PD2_AVG;
+ u8 RFPD_REF;
+ u8 RFAGC_PD2[6], RFAGC_PD2_AVG, RFAGC_PD2_MAX, RFAGC_PD2_MIN;
+ u8 RFAGC_PD1[6], RFAGC_PD1_AVG, RFAGC_PD1_MAX, RFAGC_PD1_MIN;
+
+ int res = BBM_OK;
+
+ PRINTF(hDevice, "fc8150_init\n");
+
+ fc8150_write(hDevice, 0x00, 0x00);
+ fc8150_write(hDevice, 0x02, 0x81);
+
+ fc8150_write(hDevice, 0x15, 0x02);
+ fc8150_write(hDevice, 0x20, 0x33);
+ fc8150_write(hDevice, 0x28, 0x62);
+ fc8150_write(hDevice, 0x35, 0xAA);
+ fc8150_write(hDevice, 0x38, 0x28);
+
+ fc8150_write(hDevice, 0x3B, 0x01);
+
+ fc8150_set_filter(hDevice);
+
+ fc8150_write(hDevice, 0x3B, 0x00);
+
+ fc8150_write(hDevice, 0x56, 0x01);
+ fc8150_write(hDevice, 0x57, 0x86);
+ fc8150_write(hDevice, 0x58, 0xA7);
+ fc8150_write(hDevice, 0x59, 0x4D);
+
+ fc8150_write(hDevice, 0x80, 0x17);
+ fc8150_write(hDevice, 0xAB, 0x48);
+
+ fc8150_write(hDevice, 0xA0, 0xC0);
+ fc8150_write(hDevice, 0xD0, 0x00);
+
+ fc8150_write(hDevice, 0xA5, 0x65);
+
+ RFAGC_PD1[0] = 0;
+ RFAGC_PD1[1] = 0;
+ RFAGC_PD1[2] = 0;
+ RFAGC_PD1[3] = 0;
+ RFAGC_PD1[4] = 0;
+ RFAGC_PD1[5] = 0;
+ RFAGC_PD1_MAX = 0;
+ RFAGC_PD1_MIN = 255;
+
+ for (i = 0; i < 6 ; i++) {
+ fc8150_read(hDevice, 0xD8 , &RFAGC_PD1[i]);
+
+ if (RFAGC_PD1[i] >= RFAGC_PD1_MAX)
+ RFAGC_PD1_MAX = RFAGC_PD1[i];
+ if (RFAGC_PD1[i] <= RFAGC_PD1_MIN)
+ RFAGC_PD1_MIN = RFAGC_PD1[i];
+ }
+ n_RFAGC_PD1_AVG = (RFAGC_PD1[0] + RFAGC_PD1[1] + RFAGC_PD1[2]
+ + RFAGC_PD1[3] + RFAGC_PD1[4] + RFAGC_PD1[5]
+ - RFAGC_PD1_MAX - RFAGC_PD1_MIN) / 4;
+ RFAGC_PD1_AVG = (unsigned char) n_RFAGC_PD1_AVG;
+
+ fc8150_write(hDevice, 0x7F , RFAGC_PD1_AVG);
+
+ RFAGC_PD2[0] = 0;
+ RFAGC_PD2[1] = 0;
+ RFAGC_PD2[2] = 0;
+ RFAGC_PD2[3] = 0;
+ RFAGC_PD2[4] = 0;
+ RFAGC_PD2[5] = 0;
+
+ RFAGC_PD2_MAX = 0;
+ RFAGC_PD2_MIN = 255;
+
+ for (i = 0; i < 6; i++) {
+ fc8150_read(hDevice, 0xD6, &RFAGC_PD2[i]);
+
+ if (RFAGC_PD2[i] >= RFAGC_PD2_MAX)
+ RFAGC_PD2_MAX = RFAGC_PD2[i];
+ if (RFAGC_PD2[i] <= RFAGC_PD2_MIN)
+ RFAGC_PD2_MIN = RFAGC_PD2[i];
+ }
+ n_RFAGC_PD2_AVG = (RFAGC_PD2[0] + RFAGC_PD2[1] + RFAGC_PD2[2]
+ + RFAGC_PD2[3] + RFAGC_PD2[4] + RFAGC_PD2[5]
+ - RFAGC_PD2_MAX - RFAGC_PD2_MIN) / 4;
+ RFAGC_PD2_AVG = (unsigned char) n_RFAGC_PD2_AVG;
+
+ fc8150_write(hDevice, 0x7E , RFAGC_PD2_AVG);
+
+ res = fc8150_read(hDevice, 0xD6, &RFPD_REF);
+
+ if (0x86 <= RFPD_REF)
+ fc8150_write(hDevice, 0x7B, 0x8F);
+ else if (RFPD_REF < 0x86)
+ fc8150_write(hDevice, 0x7B, 0x88);
+
+ fc8150_write(hDevice, 0x79, 0x32);
+ fc8150_write(hDevice, 0x7A, 0x2C);
+ fc8150_write(hDevice, 0x7C, 0x10);
+ fc8150_write(hDevice, 0x7D, 0x0C);
+ fc8150_write(hDevice, 0x81, 0x0A);
+ fc8150_write(hDevice, 0x84, 0x00);
+
+ fc8150_write(hDevice, 0x02, 0x81);
+
+ return BBM_OK;
+}
+
+
+int fc8150_set_freq(HANDLE hDevice, enum band_type band, u32 rf_kHz)
+{
+ unsigned long f_diff, f_diff_shifted, n_val, k_val;
+ unsigned long f_vco, f_comp;
+ unsigned char r_val, data_0x56;
+ unsigned char pre_shift_bits = 4;
+
+ f_vco = (rf_kHz) << 2;
+ if (f_vco < FC8150_FREQ_XTAL*40)
+ r_val = 2;
+ else
+ r_val = 1;
+
+ f_comp = FC8150_FREQ_XTAL / r_val;
+
+ n_val = f_vco / f_comp;
+ f_diff = f_vco - f_comp * n_val;
+
+ f_diff_shifted = f_diff << (20 - pre_shift_bits);
+
+ k_val = (f_diff_shifted) / (f_comp >> pre_shift_bits);
+ k_val = (k_val | 1);
+
+ if (470000 < rf_kHz && rf_kHz <= 473143) {
+ fc8150_write(hDevice, 0x1E, 0x04);
+ fc8150_write(hDevice, 0x1F, 0x36);
+ fc8150_write(hDevice, 0x14, 0x84);
+ } else if (473143 < rf_kHz && rf_kHz <= 485143) {
+ fc8150_write(hDevice, 0x1E, 0x03);
+ fc8150_write(hDevice, 0x1F, 0x3E);
+ fc8150_write(hDevice, 0x14, 0x84);
+ } else if (485143 < rf_kHz && rf_kHz <= 551143) {
+ fc8150_write(hDevice, 0x1E, 0x04);
+ fc8150_write(hDevice, 0x1F, 0x36);
+ fc8150_write(hDevice, 0x14, 0x84);
+ } else if (551143 < rf_kHz && rf_kHz <= 563143) {
+ fc8150_write(hDevice, 0x1E, 0x03);
+ fc8150_write(hDevice, 0x1F, 0x3E);
+ fc8150_write(hDevice, 0x14, 0xC4);
+ } else if (563143 < rf_kHz && rf_kHz <= 593143) {
+ fc8150_write(hDevice, 0x1E, 0x02);
+ fc8150_write(hDevice, 0x1F, 0x3E);
+ fc8150_write(hDevice, 0x14, 0xC4);
+ } else if (593143 < rf_kHz && rf_kHz <= 659143) {
+ fc8150_write(hDevice, 0x1E, 0x02);
+ fc8150_write(hDevice, 0x1F, 0x36);
+ fc8150_write(hDevice, 0x14, 0x84);
+ } else if (659143 < rf_kHz && rf_kHz <= 767143) {
+ fc8150_write(hDevice, 0x1E, 0x01);
+ fc8150_write(hDevice, 0x1F, 0x36);
+ fc8150_write(hDevice, 0x14, 0x84);
+ } else if (767143 < rf_kHz) {
+ fc8150_write(hDevice, 0x1E, 0x00);
+ fc8150_write(hDevice, 0x1F, 0x36);
+ fc8150_write(hDevice, 0x14, 0x84);
+ } else {
+ fc8150_write(hDevice, 0x1E, 0x05);
+ fc8150_write(hDevice, 0x1F, 0x36);
+ fc8150_write(hDevice, 0x14, 0x84);
+ }
+
+ data_0x56 = ((r_val == 1) ? 0 : 0x10) + (unsigned char)(k_val>>16);
+ fc8150_write(hDevice, 0x56, data_0x56);
+ fc8150_write(hDevice, 0x57, (unsigned char)((k_val>>8)&0xFF));
+ fc8150_write(hDevice, 0x58, (unsigned char)(((k_val)&0xFF)));
+ fc8150_write(hDevice, 0x59, (unsigned char) n_val);
+
+ if (rf_kHz < 525000)
+ fc8150_write(hDevice, 0x55, 0x0E);
+ else if (525000 <= rf_kHz && rf_kHz < 600000)
+ fc8150_write(hDevice, 0x55, 0x0C);
+ else if (600000 <= rf_kHz && rf_kHz < 700000)
+ fc8150_write(hDevice, 0x55, 0x08);
+ else if (700000 < rf_kHz)
+ fc8150_write(hDevice, 0x55, 0x06);
+
+ if (rf_kHz <= 491143) {
+ fc8150_write(hDevice, 0x79, 0x28);
+ fc8150_write(hDevice, 0x7A, 0x24);
+ } else if (491143 < rf_kHz && rf_kHz <= 659143) {
+ fc8150_write(hDevice, 0x79, 0x2A);
+ fc8150_write(hDevice, 0x7A, 0x26);
+ } else if (659143 < rf_kHz && rf_kHz <= 773143) {
+ fc8150_write(hDevice, 0x79, 0x2C);
+ fc8150_write(hDevice, 0x7A, 0x28);
+ } else if (773143 < rf_kHz) {
+ fc8150_write(hDevice, 0x79, 0x2F);
+ fc8150_write(hDevice, 0x7A, 0x2B);
+ }
+
+ if (rf_kHz <= 707143) {
+ fc8150_write(hDevice, 0x54, 0x00);
+ fc8150_write(hDevice, 0x53, 0x5F);
+ } else if (707143 < rf_kHz) {
+ fc8150_write(hDevice, 0x54, 0x04);
+ fc8150_write(hDevice, 0x53, 0x9F);
+ }
+
+ return BBM_OK;
+}
+
+int fc8150_get_rssi(HANDLE hDevice, int *rssi)
+{
+ int res = BBM_OK;
+ u8 LNA, RFVGA, CSF, PREAMP_PGA = 0x00;
+ int K = -101.25;
+ int PGA = 0;
+
+ res = fc8150_read(hDevice, 0xA3, &LNA);
+ res = fc8150_read(hDevice, 0xA4, &RFVGA);
+ res = fc8150_read(hDevice, 0xA8, &CSF);
+ res = fc8150_bb_read(hDevice, 0x106E, &PREAMP_PGA);
+
+ if (res != BBM_OK)
+ return res;
+
+ if (127 < PREAMP_PGA)
+ PGA = -1 * ((256 - PREAMP_PGA) + 1);
+ else if (PREAMP_PGA <= 127)
+ PGA = PREAMP_PGA;
+
+ /* *rssi = (LNA & 0x07) * 6 + (RFVGA & 0x1F)
+ + ((CSF & 0x03)+((CSF & 0x70) >> 4) ) * 6 - PGA * 0.25f + K ; */
+ *rssi = (LNA & 0x07) * 6 + (RFVGA & 0x1F)
+ + ((CSF & 0x03) + ((CSF & 0x70) >> 4)) * 6 - PGA / 4 + K;
+
+ return BBM_OK;
+}
+
+int fc8150_tuner_deinit(HANDLE hDevice)
+{
+ return BBM_OK;
+}
diff --git a/drivers/media/isdbt/fc8150/fc8150_tun.h b/drivers/media/isdbt/fc8150/fc8150_tun.h
new file mode 100644
index 0000000..64a715c
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fc8150_tun.h
@@ -0,0 +1,26 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : fc8150_tun.c
+
+ Description : fc8150 tuner control driver
+
+*******************************************************************************/
+
+#ifndef __FC8150_TUN__
+#define __FC8150_TUN__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int fc8150_tuner_init(HANDLE hDevice, enum band_type band);
+extern int fc8150_set_freq(HANDLE hDevice, enum band_type band, u32 f_lo);
+extern int fc8150_get_rssi(HANDLE hDevice, int *rssi);
+extern int fc8150_tuner_deinit(HANDLE hDevice);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/drivers/media/isdbt/fc8150/fc8151_tun.c b/drivers/media/isdbt/fc8150/fc8151_tun.c
new file mode 100644
index 0000000..e17b4b9
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fc8151_tun.c
@@ -0,0 +1,413 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : fc8151_tun.c (WLCSP)
+
+ Description : fc8150 tuner driver
+
+ History :
+ ----------------------------------------------------------------------
+ 2012/01/20 initial 0.1 version
+ 2012/01/25 initial 0.3 version
+ 2012/01/27 initial 0.5 version
+ 2012/01/31 initial 1.0 version
+ 2012/01/31 initial 1.1 version
+ 2012/02/06 initial 1.2 version
+ 2012/02/09 initial 1.3 Version
+ 2012/02/15 initial 1.4 Version
+ 2012/02/15 initial 2.0 Version
+ 2012/02/24 initial 2.01 Version
+ 2012/03/30 initial 3.0 Version
+*******************************************************************************/
+
+#include "fci_types.h"
+#include "fci_oal.h"
+#include "fci_tun.h"
+#include "fc8150_regs.h"
+#include "fci_hal.h"
+
+#define FC8150_FREQ_XTAL BBM_XTAL_FREQ /* 26MHZ */
+
+static int high_crnt_mode = 1;
+
+static int fc8151_write(HANDLE hDevice, u8 addr, u8 data)
+{
+ int res;
+ u8 tmp;
+
+ tmp = data;
+ res = tuner_i2c_write(hDevice, addr, 1, &tmp, 1);
+
+ return res;
+}
+
+static int fc8151_read(HANDLE hDevice, u8 addr, u8 *data)
+{
+ int res;
+
+ res = tuner_i2c_read(hDevice, addr, 1, data, 1);
+
+ return res;
+}
+
+static int fc8151_bb_read(HANDLE hDevice, u16 addr, u8 *data)
+{
+ int res;
+
+ res = bbm_read(hDevice, addr, data);
+
+ return res;
+}
+
+static int fc8151_bb_write(HANDLE hDevice, u16 addr, u8 data)
+{
+ return BBM_OK;
+}
+
+
+static int KbdFunc(HANDLE hDevice)
+{
+ int i = 0;
+
+ u8 CSF = 0x00;
+ int res = BBM_OK;
+ int crnt_mode[5] = {0, 0, 0, 0, 0};
+ int pre_crnt_mode = 0;
+
+ high_crnt_mode = 2;
+ fc8151_write(hDevice, 0x13, 0xF4);
+ fc8151_write(hDevice, 0x1F, 0x06);
+ fc8151_write(hDevice, 0x33, 0x08);
+ fc8151_write(hDevice, 0x34, 0x68);
+ fc8151_write(hDevice, 0x35, 0x0A);
+
+ while (1) {
+ while (1) {
+ for (i = 0; i < 5; i++) {
+ msWait(100);
+ res = fc8151_read(hDevice, 0xA6, &CSF);
+ if (CSF < 4)
+ crnt_mode[i] = 2;
+ if (CSF == 4)
+ crnt_mode[i] = 1;
+ if (4 < CSF)
+ crnt_mode[i] = 0;
+ }
+
+ pre_crnt_mode = high_crnt_mode;
+
+ if ((crnt_mode[0] + crnt_mode[1] + crnt_mode[2]
+ + crnt_mode[3] + crnt_mode[4]) == 10)
+ high_crnt_mode = 2;
+ else if ((crnt_mode[0] + crnt_mode[1] + crnt_mode[2]
+ + crnt_mode[3] + crnt_mode[4]) == 5)
+ high_crnt_mode = 1;
+ else if ((crnt_mode[0] + crnt_mode[1] + crnt_mode[2]
+ + crnt_mode[3] + crnt_mode[4]) == 0)
+ high_crnt_mode = 0;
+ else
+ high_crnt_mode = pre_crnt_mode;
+
+ if (!(high_crnt_mode == pre_crnt_mode))
+ break;
+ }
+
+ if (high_crnt_mode == 2) {
+ fc8151_write(hDevice, 0x13, 0xF4);
+ fc8151_write(hDevice, 0x1F, 0x06);
+ fc8151_write(hDevice, 0x33, 0x08);
+ fc8151_write(hDevice, 0x34, 0x68);
+ fc8151_write(hDevice, 0x35, 0x0A);
+ } else if (high_crnt_mode == 1) {
+ fc8151_write(hDevice, 0x13, 0x44);
+ fc8151_write(hDevice, 0x1F, 0x06);
+ fc8151_write(hDevice, 0x33, 0x08);
+ fc8151_write(hDevice, 0x34, 0x68);
+ fc8151_write(hDevice, 0x35, 0x0A);
+ } else if (high_crnt_mode == 0) {
+ fc8151_write(hDevice, 0x13, 0x44);
+ fc8151_write(hDevice, 0x1F, 0x02);
+ fc8151_write(hDevice, 0x33, 0x04);
+ fc8151_write(hDevice, 0x34, 0x48);
+ fc8151_write(hDevice, 0x35, 0x0C);
+ }
+ }
+
+ return res;
+
+}
+
+static int fc8151_set_filter(HANDLE hDevice)
+{
+ int i;
+ u8 cal_mon = 0;
+
+#if (FC8151_FREQ_XTAL == 16000)
+ fc8151_write(hDevice, 0x3B, 0x01);
+ fc8151_write(hDevice, 0x3D, 0x20);
+ fc8151_write(hDevice, 0x3B, 0x00);
+#elif (FC8150_FREQ_XTAL == 16384)
+ fc8151_write(hDevice, 0x3B, 0x01);
+ fc8151_write(hDevice, 0x3D, 0x21);
+ fc8151_write(hDevice, 0x3B, 0x00);
+#elif (FC8150_FREQ_XTAL == 18000)
+ fc8151_write(hDevice, 0x3B, 0x01);
+ fc8151_write(hDevice, 0x3D, 0x24);
+ fc8151_write(hDevice, 0x3B, 0x00);
+#elif (FC8150_FREQ_XTAL == 19200)
+ fc8151_write(hDevice, 0x3B, 0x01);
+ fc8151_write(hDevice, 0x3D, 0x26);
+ fc8151_write(hDevice, 0x3B, 0x00);
+#elif (FC8150_FREQ_XTAL == 24000)
+ fc8151_write(hDevice, 0x3B, 0x01);
+ fc8151_write(hDevice, 0x3D, 0x30);
+ fc8151_write(hDevice, 0x3B, 0x00);
+#elif (FC8150_FREQ_XTAL == 24576)
+ fc8151_write(hDevice, 0x3B, 0x01);
+ fc8151_write(hDevice, 0x3D, 0x31);
+ fc8151_write(hDevice, 0x3B, 0x00);
+#elif (FC8150_FREQ_XTAL == 26000)
+ fc8151_write(hDevice, 0x3B, 0x01);
+ fc8151_write(hDevice, 0x3D, 0x34);
+ fc8151_write(hDevice, 0x3B, 0x00);
+#elif (FC8150_FREQ_XTAL == 27000)
+ fc8151_write(hDevice, 0x3B, 0x01);
+ fc8151_write(hDevice, 0x3D, 0x36);
+ fc8151_write(hDevice, 0x3B, 0x00);
+#elif (FC8150_FREQ_XTAL == 27120)
+ fc8151_write(hDevice, 0x3B, 0x01);
+ fc8151_write(hDevice, 0x3D, 0x36);
+ fc8151_write(hDevice, 0x3B, 0x00);
+#elif (FC8150_FREQ_XTAL == 32000)
+ fc8151_write(hDevice, 0x3B, 0x01);
+ fc8151_write(hDevice, 0x3D, 0x40);
+ fc8151_write(hDevice, 0x3B, 0x00);
+#elif (FC8150_FREQ_XTAL == 37400)
+ fc8151_write(hDevice, 0x3B, 0x01);
+ fc8151_write(hDevice, 0x3D, 0x4B);
+ fc8151_write(hDevice, 0x3B, 0x00);
+#elif (FC8150_FREQ_XTAL == 38400)
+ fc8151_write(hDevice, 0x3B, 0x01);
+ fc8151_write(hDevice, 0x3D, 0x4D);
+ fc8151_write(hDevice, 0x3B, 0x00);
+#else
+ return BBM_NOK;
+#endif
+
+ for (i = 0; i < 10; i++) {
+ msWait(5);
+ fc8151_read(hDevice, 0x33, &cal_mon);
+ if ((cal_mon & 0xC0) == 0xC0)
+ break;
+ fc8151_write(hDevice, 0x32, 0x01);
+ fc8151_write(hDevice, 0x32, 0x09);
+ }
+
+ fc8151_write(hDevice, 0x32, 0x01);
+
+ return BBM_OK;
+}
+
+int fc8151_tuner_init(HANDLE hDevice, u32 band)
+{
+ u8 RFPD_REF, MIXPD_REF;
+ int res = BBM_OK;
+
+ PRINTF(hDevice, "fc8151_init\n");
+
+ fc8151_write(hDevice, 0x00, 0x00);
+ fc8151_write(hDevice, 0x02, 0x81);
+
+ fc8151_write(hDevice, 0x13, 0xF4);
+ fc8151_write(hDevice, 0x30, 0x0A);
+ fc8151_write(hDevice, 0x3B, 0x01);
+
+ fc8151_set_filter(hDevice);
+
+ fc8151_write(hDevice, 0x3B, 0x00);
+
+ fc8151_write(hDevice, 0x34, 0x68);
+ fc8151_write(hDevice, 0x36, 0xFF);
+ fc8151_write(hDevice, 0x37, 0xFF);
+ fc8151_write(hDevice, 0x39, 0x11);
+ fc8151_write(hDevice, 0x3A, 0x00);
+
+ fc8151_write(hDevice, 0x52, 0x20);
+ fc8151_write(hDevice, 0x53, 0x5F);
+ fc8151_write(hDevice, 0x54, 0x00);
+ fc8151_write(hDevice, 0x5E, 0x00);
+ fc8151_write(hDevice, 0x63, 0x30);
+
+ fc8151_write(hDevice, 0x56, 0x0F);
+ fc8151_write(hDevice, 0x57, 0x1F);
+ fc8151_write(hDevice, 0x58, 0x09);
+ fc8151_write(hDevice, 0x59, 0x5E);
+
+ fc8151_write(hDevice, 0x29, 0x00);
+
+ fc8151_write(hDevice, 0x94, 0x00);
+ fc8151_write(hDevice, 0x95, 0x01);
+ fc8151_write(hDevice, 0x96, 0x11);
+ fc8151_write(hDevice, 0x97, 0x21);
+ fc8151_write(hDevice, 0x98, 0x31);
+ fc8151_write(hDevice, 0x99, 0x32);
+ fc8151_write(hDevice, 0x9A, 0x42);
+ fc8151_write(hDevice, 0x9B, 0x52);
+ fc8151_write(hDevice, 0x9C, 0x53);
+ fc8151_write(hDevice, 0x9D, 0x63);
+ fc8151_write(hDevice, 0x9E, 0x63);
+ fc8151_write(hDevice, 0x9F, 0x63);
+
+ fc8151_write(hDevice, 0x79, 0x2A);
+ fc8151_write(hDevice, 0x7A, 0x24);
+ fc8151_write(hDevice, 0x7B, 0xFF);
+ fc8151_write(hDevice, 0x7C, 0x16);
+ fc8151_write(hDevice, 0x7D, 0x12);
+ fc8151_write(hDevice, 0x84, 0x00);
+ fc8151_write(hDevice, 0x85, 0x08);
+ fc8151_write(hDevice, 0x86, 0x00);
+ fc8151_write(hDevice, 0x87, 0x08);
+ fc8151_write(hDevice, 0x88, 0x00);
+ fc8151_write(hDevice, 0x89, 0x08);
+ fc8151_write(hDevice, 0x8A, 0x00);
+ fc8151_write(hDevice, 0x8B, 0x08);
+ fc8151_write(hDevice, 0x8C, 0x00);
+ fc8151_write(hDevice, 0x8D, 0x1D);
+ fc8151_write(hDevice, 0x8E, 0x13);
+ fc8151_write(hDevice, 0x8F, 0x1D);
+ fc8151_write(hDevice, 0x90, 0x13);
+ fc8151_write(hDevice, 0x91, 0x1D);
+ fc8151_write(hDevice, 0x92, 0x13);
+ fc8151_write(hDevice, 0x93, 0x1D);
+ fc8151_write(hDevice, 0x80, 0x1F);
+ fc8151_write(hDevice, 0x81, 0x0A);
+ fc8151_write(hDevice, 0x82, 0x40);
+ fc8151_write(hDevice, 0x83, 0x0A);
+
+ fc8151_write(hDevice, 0xA0, 0xC0);
+ fc8151_write(hDevice, 0x7E, 0x7F);
+ fc8151_write(hDevice, 0x7F, 0x7F);
+ fc8151_write(hDevice, 0xD0, 0x0A);
+ fc8151_write(hDevice, 0xD2, 0x28);
+ fc8151_write(hDevice, 0xD4, 0x28);
+
+ /* _beginthread(KbdFunc,0,&x); */
+
+ fc8151_write(hDevice, 0xA0, 0x17);
+ fc8151_write(hDevice, 0xD0, 0x00);
+ fc8151_write(hDevice, 0xA1, 0x1D);
+
+ msWait(100);
+
+ res = fc8151_read(hDevice, 0xD6, &RFPD_REF);
+ res = fc8151_read(hDevice, 0xD8, &MIXPD_REF);
+
+ fc8151_write(hDevice, 0xA0, 0xD7);
+ fc8151_write(hDevice, 0xD0, 0x0A);
+
+ fc8151_write(hDevice, 0x7E, RFPD_REF);
+ fc8151_write(hDevice, 0x7F, MIXPD_REF);
+
+ fc8151_write(hDevice, 0xA0, 0xC0);
+ fc8151_write(hDevice, 0xA1, 0x00);
+
+ return res;
+}
+
+
+int fc8151_set_freq(HANDLE hDevice, band_type band, u32 rf_kHz)
+{
+ int res = BBM_OK;
+ int n_captune = 0;
+ unsigned long f_diff, f_diff_shifted, n_val, k_val;
+ unsigned long f_vco, f_comp;
+ unsigned char r_val, data_0x56;
+ unsigned char pre_shift_bits = 4;
+
+ f_vco = (rf_kHz) << 2;
+ if (f_vco < FC8150_FREQ_XTAL*40)
+ r_val = 2;
+ else
+ r_val = 1;
+
+ f_comp = FC8150_FREQ_XTAL / r_val;
+
+ n_val = f_vco / f_comp;
+ f_diff = f_vco - f_comp * n_val;
+
+ f_diff_shifted = f_diff << (20 - pre_shift_bits);
+
+ k_val = (f_diff_shifted + (f_comp >> (pre_shift_bits+1)))
+ / (f_comp >> pre_shift_bits);
+ k_val = (k_val | 1);
+
+ if (470000 < rf_kHz && rf_kHz <= 505000)
+ n_captune = 4;
+ else if (505000 < rf_kHz && rf_kHz <= 545000)
+ n_captune = 3;
+ else if (545000 < rf_kHz && rf_kHz <= 610000)
+ n_captune = 2;
+ else if (610000 < rf_kHz && rf_kHz <= 695000)
+ n_captune = 1;
+ else if (695000 < rf_kHz)
+ n_captune = 0;
+
+ fc8151_write(hDevice, 0x1E, (unsigned char)n_captune);
+
+ data_0x56 = ((r_val == 1) ? 0 : 0x10) + (unsigned char)(k_val >> 16);
+ fc8151_write(hDevice, 0x56, data_0x56);
+ fc8151_write(hDevice, 0x57, (unsigned char)((k_val >> 8) & 0xFF));
+ fc8151_write(hDevice, 0x58, (unsigned char)(((k_val) & 0xFF)));
+ fc8151_write(hDevice, 0x59, (unsigned char) n_val);
+
+ if (rf_kHz <= 600000)
+ fc8151_write(hDevice, 0x55, 0x07);
+ else
+ fc8151_write(hDevice, 0x55, 0x05);
+
+ if ((490000 < rf_kHz) && (560000 >= rf_kHz))
+ fc8151_write(hDevice, 0x1F, 0x0E);
+ else
+ fc8151_write(hDevice, 0x1F, 0x06);
+
+ return res;
+}
+
+int fc8151_get_rssi(HANDLE hDevice, int *rssi)
+{
+ int res = BBM_OK;
+ u8 LNA, RFVGA, CSF, PREAMP_PGA = 0x00;
+ int K = -101.25;
+ float Gain_diff = 0;
+ int PGA = 0;
+
+ res |= fc8151_read(hDevice, 0xA3, &LNA);
+ res |= fc8151_read(hDevice, 0xA4, &RFVGA);
+ res |= fc8151_read(hDevice, 0xA6, &CSF);
+ res |= fc8151_bb_read(hDevice, 0x106E, &PREAMP_PGA);
+
+ if (res != BBM_OK)
+ return res;
+
+ if (127 < PREAMP_PGA)
+ PGA = -1 * ((256 - PREAMP_PGA) + 1);
+ else if (PREAMP_PGA <= 127)
+ PGA = PREAMP_PGA;
+
+ if (high_crnt_mode == 2)
+ Gain_diff = 0;
+ else if (high_crnt_mode == 1)
+ Gain_diff = 0;
+ else if (high_crnt_mode == 0)
+ Gain_diff = -3.5;
+
+ *rssi = (LNA & 0x07) * 6 + (RFVGA)
+ + (CSF & 0x0F) * 6 - PGA * 0.25f + K - Gain_diff;
+
+ return BBM_OK;
+}
+
+int fc8151_tuner_deinit(HANDLE hDevice)
+{
+ return BBM_OK;
+}
diff --git a/drivers/media/isdbt/fc8150/fc8151_tun.h b/drivers/media/isdbt/fc8150/fc8151_tun.h
new file mode 100644
index 0000000..4147fa6
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fc8151_tun.h
@@ -0,0 +1,26 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : fc8151_tun.c
+
+ Description : fc8151 tuner control driver
+
+*******************************************************************************/
+
+#ifndef __FC8151_TUN__
+#define __FC8151_TUN__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int fc8151_tuner_init(HANDLE hDevice, band_type band);
+extern int fc8151_set_freq(HANDLE hDevice, band_type band, u32 f_lo);
+extern int fc8151_get_rssi(HANDLE hDevice, int *rssi);
+extern int fc8151_tuner_deinit(HANDLE hDevice);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/drivers/media/isdbt/fc8150/fci_bypass.c b/drivers/media/isdbt/fc8150/fci_bypass.c
new file mode 100644
index 0000000..f3104cb
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fci_bypass.c
@@ -0,0 +1,39 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : fci_bypass.c
+
+ Description : fci i2c driver
+*******************************************************************************/
+#include "fci_bypass.h"
+#include "fci_types.h"
+
+
+int fci_bypass_init(HANDLE hDevice, int speed, int slaveaddr)
+{
+ return BBM_OK;
+}
+
+int fci_bypass_read(HANDLE hDevice, u8 chip, u8 addr, u8 alen, u8 *data, u8 len)
+{
+ int res;
+
+ res = fc8150_bypass_read(hDevice, chip, addr, data, len);
+
+ return res;
+}
+
+int fci_bypass_write(HANDLE hDevice, u8 chip, u8 addr
+ , u8 alen, u8 *data, u8 len)
+{
+ int res;
+
+ res = fc8150_bypass_write(hDevice, chip, addr, data, len);
+
+ return res;
+}
+
+int fci_bypass_deinit(HANDLE hDevice)
+{
+ return BBM_OK;
+}
diff --git a/drivers/media/isdbt/fc8150/fci_bypass.h b/drivers/media/isdbt/fc8150/fci_bypass.h
new file mode 100644
index 0000000..dda0e64
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fci_bypass.h
@@ -0,0 +1,34 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : fci_bypass.h
+
+ Description : fci i2c driver header
+*******************************************************************************/
+
+#ifndef __FCI_BYPASS_H__
+#define __FCI_BYPASS_H__
+
+#include "fci_types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int fci_bypass_init(HANDLE hDevice, int speed, int slaveaddr);
+extern int fci_bypass_read(HANDLE hDevice, u8 chip, u8 addr
+ , u8 alen, u8 *data, u8 len);
+extern int fci_bypass_write(HANDLE hDevice, u8 chip, u8 addr
+ , u8 alen, u8 *data, u8 len);
+extern int fci_bypass_deinit(HANDLE hDevice);
+
+extern int fc8150_bypass_read(HANDLE hDevice, u8 chip
+ , u8 addr, u8 *data, u16 length);
+extern int fc8150_bypass_write(HANDLE hDevice, u8 chip
+ , u8 addr, u8 *data, u16 length);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/drivers/media/isdbt/fc8150/fci_hal.c b/drivers/media/isdbt/fc8150/fci_hal.c
new file mode 100644
index 0000000..b70f5eb
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fci_hal.c
@@ -0,0 +1,245 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : fci_hal.c
+
+ Description : fc8150 host interface
+
+*******************************************************************************/
+
+#include "fci_types.h"
+#include "fci_hal.h"
+#include "fc8150_hpi.h"
+#include "fc8150_spi.h"
+#include "fc8150_ppi.h"
+#include "fc8150_i2c.h"
+#include "fc8150_spib.h"
+
+struct IF_PORT {
+ int (*init)(HANDLE hDevice, u16 param1, u16 param2);
+
+ int (*byteread)(HANDLE hDevice, u16 addr, u8 *data);
+ int (*wordread)(HANDLE hDevice, u16 addr, u16 *data);
+ int (*longread)(HANDLE hDevice, u16 addr, u32 *data);
+ int (*bulkread)(HANDLE hDevice, u16 addr, u8 *data, u16 length);
+
+ int (*bytewrite)(HANDLE hDevice, u16 addr, u8 data);
+ int (*wordwrite)(HANDLE hDevice, u16 addr, u16 data);
+ int (*longwrite)(HANDLE hDevice, u16 addr, u32 data);
+ int (*bulkwrite)(HANDLE hDevice, u16 addr, u8 *data, u16 length);
+
+ int (*dataread)(HANDLE hDevice, u16 addr, u8 *data, u32 length);
+
+ int (*deinit)(HANDLE hDevice);
+};
+
+static struct IF_PORT hpiif = {
+ &fc8150_hpi_init,
+
+ &fc8150_hpi_byteread,
+ &fc8150_hpi_wordread,
+ &fc8150_hpi_longread,
+ &fc8150_hpi_bulkread,
+
+ &fc8150_hpi_bytewrite,
+ &fc8150_hpi_wordwrite,
+ &fc8150_hpi_longwrite,
+ &fc8150_hpi_bulkwrite,
+
+ &fc8150_hpi_dataread,
+
+ &fc8150_hpi_deinit
+};
+
+static struct IF_PORT spiif = {
+ &fc8150_spi_init,
+
+ &fc8150_spi_byteread,
+ &fc8150_spi_wordread,
+ &fc8150_spi_longread,
+ &fc8150_spi_bulkread,
+
+ &fc8150_spi_bytewrite,
+ &fc8150_spi_wordwrite,
+ &fc8150_spi_longwrite,
+ &fc8150_spi_bulkwrite,
+
+ &fc8150_spi_dataread,
+
+ &fc8150_spi_deinit
+};
+
+static struct IF_PORT spibif = {
+ &fc8150_spib_init,
+
+ &fc8150_spib_byteread,
+ &fc8150_spib_wordread,
+ &fc8150_spib_longread,
+ &fc8150_spib_bulkread,
+
+ &fc8150_spib_bytewrite,
+ &fc8150_spib_wordwrite,
+ &fc8150_spib_longwrite,
+ &fc8150_spib_bulkwrite,
+
+ &fc8150_spib_dataread,
+
+ &fc8150_spib_deinit
+};
+
+static struct IF_PORT ppiif = {
+ &fc8150_ppi_init,
+
+ &fc8150_ppi_byteread,
+ &fc8150_ppi_wordread,
+ &fc8150_ppi_longread,
+ &fc8150_ppi_bulkread,
+
+ &fc8150_ppi_bytewrite,
+ &fc8150_ppi_wordwrite,
+ &fc8150_ppi_longwrite,
+ &fc8150_ppi_bulkwrite,
+
+ &fc8150_ppi_dataread,
+
+ &fc8150_ppi_deinit
+};
+
+static struct IF_PORT i2cif = {
+ &fc8150_i2c_init,
+
+ &fc8150_i2c_byteread,
+ &fc8150_i2c_wordread,
+ &fc8150_i2c_longread,
+ &fc8150_i2c_bulkread,
+
+ &fc8150_i2c_bytewrite,
+ &fc8150_i2c_wordwrite,
+ &fc8150_i2c_longwrite,
+ &fc8150_i2c_bulkwrite,
+
+ &fc8150_i2c_dataread,
+
+ &fc8150_i2c_deinit
+};
+
+static struct IF_PORT *ifport = &spiif;
+u8 hostif_type = BBM_SPI;
+
+int bbm_hostif_select(HANDLE hDevice, u8 hostif)
+{
+ hostif_type = hostif;
+
+ switch (hostif) {
+ case BBM_HPI:
+ ifport = &hpiif;
+ break;
+ case BBM_SPI:
+ ifport = &spiif;
+ break;
+ case BBM_I2C:
+ ifport = &i2cif;
+ break;
+ case BBM_PPI:
+ ifport = &ppiif;
+ break;
+ case BBM_SPIB:
+ ifport = &spibif;
+ break;
+ default:
+ return BBM_E_HOSTIF_SELECT;
+ }
+
+ if (ifport->init(hDevice, 0, 0))
+ return BBM_E_HOSTIF_INIT;
+
+ return BBM_OK;
+}
+
+int bbm_hostif_deselect(HANDLE hDevice)
+{
+ if (ifport->deinit(hDevice))
+ return BBM_NOK;
+
+ ifport = NULL;
+ hostif_type = BBM_SPI;
+
+ return BBM_OK;
+}
+
+int bbm_read(HANDLE hDevice, u16 addr, u8 *data)
+{
+ if (ifport->byteread(hDevice, addr, data))
+ return BBM_E_BB_READ;
+ return BBM_OK;
+}
+
+int bbm_byte_read(HANDLE hDevice, u16 addr, u8 *data)
+{
+ if (ifport->byteread(hDevice, addr, data))
+ return BBM_E_BB_READ;
+ return BBM_OK;
+}
+
+int bbm_word_read(HANDLE hDevice, u16 addr, u16 *data)
+{
+ if (ifport->wordread(hDevice, addr, data))
+ return BBM_E_BB_READ;
+ return BBM_OK;
+}
+
+int bbm_long_read(HANDLE hDevice, u16 addr, u32 *data)
+{
+ if (ifport->longread(hDevice, addr, data))
+ return BBM_E_BB_READ;
+ return BBM_OK;
+}
+
+int bbm_bulk_read(HANDLE hDevice, u16 addr, u8 *data, u16 length)
+{
+ if (ifport->bulkread(hDevice, addr, data, length))
+ return BBM_E_BB_READ;
+ return BBM_OK;
+}
+
+int bbm_write(HANDLE hDevice, u16 addr, u8 data)
+{
+ if (ifport->bytewrite(hDevice, addr, data))
+ return BBM_E_BB_WRITE;
+ return BBM_OK;
+}
+
+int bbm_byte_write(HANDLE hDevice, u16 addr, u8 data)
+{
+ if (ifport->bytewrite(hDevice, addr, data))
+ return BBM_E_BB_WRITE;
+ return BBM_OK;
+}
+
+int bbm_word_write(HANDLE hDevice, u16 addr, u16 data)
+{
+ if (ifport->wordwrite(hDevice, addr, data))
+ return BBM_E_BB_WRITE;
+ return BBM_OK;
+}
+
+int bbm_long_write(HANDLE hDevice, u16 addr, u32 data)
+{
+ if (ifport->longwrite(hDevice, addr, data))
+ return BBM_E_BB_WRITE;
+ return BBM_OK;
+}
+
+int bbm_bulk_write(HANDLE hDevice, u16 addr, u8 *data, u16 length)
+{
+ if (ifport->bulkwrite(hDevice, addr, data, length))
+ return BBM_E_BB_WRITE;
+ return BBM_OK;
+}
+
+int bbm_data(HANDLE hDevice, u16 addr, u8 *data, u32 length)
+{
+ if (ifport->dataread(hDevice, addr, data, length))
+ return BBM_E_BB_WRITE;
+ return BBM_OK;
+}
diff --git a/drivers/media/isdbt/fc8150/fci_hal.h b/drivers/media/isdbt/fc8150/fci_hal.h
new file mode 100644
index 0000000..e9d44c4
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fci_hal.h
@@ -0,0 +1,37 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : fc8150_hal.h
+
+ Description : fc8150 host interface
+*******************************************************************************/
+
+#ifndef __FCI_HAL_H__
+#define __FCI_HAL_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int bbm_hostif_select(HANDLE hDevice, u8 hostif);
+extern int bbm_hostif_deselect(HANDLE hDevice);
+
+extern int bbm_read(HANDLE hDevice, u16 addr, u8 *data);
+extern int bbm_byte_read(HANDLE hDevice, u16 addr, u8 *data);
+extern int bbm_word_read(HANDLE hDevice, u16 addr, u16 *data);
+extern int bbm_long_read(HANDLE hDevice, u16 addr, u32 *data);
+extern int bbm_bulk_read(HANDLE hDevice, u16 addr, u8 *data, u16 length);
+
+extern int bbm_write(HANDLE hDevice, u16 addr, u8 data);
+extern int bbm_byte_write(HANDLE hDevice, u16 addr, u8 data);
+extern int bbm_word_write(HANDLE hDevice, u16 addr, u16 data);
+extern int bbm_long_write(HANDLE hDevice, u16 addr, u32 data);
+extern int bbm_bulk_write(HANDLE hDevice, u16 addr, u8 *data, u16 length);
+
+extern int bbm_data(HANDLE hDevice, u16 addr, u8 *data, u32 length);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/drivers/media/isdbt/fc8150/fci_i2c.c b/drivers/media/isdbt/fc8150/fci_i2c.c
new file mode 100644
index 0000000..1f011ca
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fci_i2c.c
@@ -0,0 +1,226 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : fci_i2c.c
+
+ Description : fci i2c driver
+*******************************************************************************/
+
+#include "fci_types.h"
+#include "fci_oal.h"
+#include "fc8150_regs.h"
+#include "fci_hal.h"
+
+#define I2CSTAT_TIP 0x02 /* Tip bit */
+#define I2CSTAT_NACK 0x80 /* Nack bit */
+
+#define I2C_TIMEOUT 100
+
+#define I2C_CR_STA 0x80
+#define I2C_CR_STO 0x40
+#define I2C_CR_RD 0x20
+#define I2C_CR_WR 0x10
+#define I2C_CR_NACK 0x08
+#define I2C_CR_IACK 0x01
+
+#define I2C_WRITE 0
+#define I2C_READ 1
+
+#define I2C_OK 0
+#define I2C_NOK 1
+#define I2C_NACK 2
+#define I2C_NOK_LA 3 /* Lost arbitration */
+#define I2C_NOK_TOUT 4 /* time out */
+
+#define FC8150_FREQ_XTAL BBM_XTAL_FREQ
+
+/* static OAL_SEMAPHORE hBbmMutex; */
+
+static int WaitForXfer(HANDLE hDevice)
+{
+ int i;
+ int res = I2C_OK;
+ u8 status;
+
+ i = I2C_TIMEOUT * 20000;
+ /* wait for transfer complete */
+ do {
+ bbm_read(hDevice, BBM_I2C_SR, &status);
+ i--;
+ } while ((i > 0) && (status & I2CSTAT_TIP));
+
+ /* check time out or nack */
+ if (status & I2CSTAT_TIP) {
+ res = I2C_NOK_TOUT;
+ } else {
+ bbm_read(hDevice, BBM_I2C_SR, &status);
+ if (status & I2CSTAT_NACK)
+ res = I2C_NACK;
+ else
+ res = I2C_OK;
+ }
+
+ return res;
+}
+
+static int fci_i2c_transfer(HANDLE hDevice, u8 cmd_type, u8 chip
+ , u8 addr[], u8 addr_len, u8 data[], u8 data_len)
+{
+ int i;
+ int result = I2C_OK;
+
+ switch (cmd_type) {
+ case I2C_WRITE:
+ bbm_write(hDevice, BBM_I2C_TXR, chip | cmd_type);
+ bbm_write(hDevice, BBM_I2C_CR, I2C_CR_STA | I2C_CR_WR /*0x90*/);
+ result = WaitForXfer(hDevice);
+ if (result != I2C_OK)
+ return result;
+
+ if (addr && addr_len) {
+ i = 0;
+ while ((i < addr_len) && (result == I2C_OK)) {
+ bbm_write(hDevice, BBM_I2C_TXR, addr[i]);
+ bbm_write(hDevice, BBM_I2C_CR
+ , I2C_CR_WR /*0x10*/);
+ result = WaitForXfer(hDevice);
+ if (result != I2C_OK)
+ return result;
+ i++;
+ }
+ }
+
+ i = 0;
+ while ((i < data_len) && (result == I2C_OK)) {
+ bbm_write(hDevice, BBM_I2C_TXR, data[i]);
+ bbm_write(hDevice, BBM_I2C_CR, I2C_CR_WR /*0x10*/);
+ result = WaitForXfer(hDevice);
+ if (result != I2C_OK)
+ return result;
+ i++;
+ }
+
+ bbm_write(hDevice, BBM_I2C_CR, I2C_CR_STO /*0x40*/);
+ result = WaitForXfer(hDevice);
+ if (result != I2C_OK)
+ return result;
+ break;
+ case I2C_READ:
+ if (addr && addr_len) {
+ bbm_write(hDevice, BBM_I2C_TXR, chip | I2C_WRITE);
+ bbm_write(hDevice, BBM_I2C_CR
+ , I2C_CR_STA | I2C_CR_WR /*0x90*/);
+ result = WaitForXfer(hDevice);
+ if (result != I2C_OK)
+ return result;
+
+ i = 0;
+ while ((i < addr_len) && (result == I2C_OK)) {
+ bbm_write(hDevice, BBM_I2C_TXR, addr[i]);
+ bbm_write(hDevice, BBM_I2C_CR
+ , I2C_CR_WR /*0x10*/);
+ result = WaitForXfer(hDevice);
+ if (result != I2C_OK)
+ return result;
+ i++;
+ }
+ }
+
+ bbm_write(hDevice, BBM_I2C_TXR, chip | I2C_READ);
+ bbm_write(hDevice, BBM_I2C_CR, I2C_CR_STA | I2C_CR_WR /*0x90*/);
+ result = WaitForXfer(hDevice);
+ if (result != I2C_OK)
+ return result;
+
+ i = 0;
+ while ((i < data_len) && (result == I2C_OK)) {
+ if (i == data_len - 1) {
+ bbm_write(hDevice, BBM_I2C_CR
+ , I2C_CR_RD|I2C_CR_NACK/*0x28*/);
+ result = WaitForXfer(hDevice);
+ if ((result != I2C_NACK)
+ && (result != I2C_OK)) {
+ PRINTF(hDevice, "NACK4-0[%02x]\n"
+ , result);
+ return result;
+ }
+ } else {
+ bbm_write(hDevice, BBM_I2C_CR
+ , I2C_CR_RD /*0x20*/);
+ result = WaitForXfer(hDevice);
+ if (result != I2C_OK) {
+ PRINTF(hDevice, "NACK4-1[%02x]\n"
+ , result);
+ return result;
+ }
+ }
+ bbm_read(hDevice, BBM_I2C_RXR, &data[i]);
+ i++;
+ }
+
+ bbm_write(hDevice, BBM_I2C_CR, I2C_CR_STO /*0x40*/);
+ result = WaitForXfer(hDevice);
+ if ((result != I2C_NACK) && (result != I2C_OK)) {
+ PRINTF(hDevice, "NACK5[%02X]\n", result);
+ return result;
+ }
+ break;
+ default:
+ return I2C_NOK;
+ }
+
+ return I2C_OK;
+}
+
+int fci_i2c_init(HANDLE hDevice, int speed, int slaveaddr)
+{
+ u16 r = FC8150_FREQ_XTAL % (5 * speed);
+ u16 pr = (FC8150_FREQ_XTAL - r) / (5 * speed) - 1;
+
+ if (((5 * speed) >> 1) <= r)
+ pr++;
+
+ bbm_word_write(hDevice, BBM_I2C_PR_L, pr);
+ bbm_write(hDevice, BBM_I2C_CTR, 0xc0);
+
+ PRINTF(hDevice, "Internal I2C Pre-scale: 0x%02x\n", pr);
+
+ return BBM_OK;
+}
+
+int fci_i2c_read(HANDLE hDevice, u8 chip, u8 addr, u8 alen, u8 *data, u8 len)
+{
+ int ret;
+
+ ret = fci_i2c_transfer(hDevice, I2C_READ, chip << 1, &addr
+ , alen, data, len);
+
+ if (ret != I2C_OK) {
+ PRINTF(hDevice, "fci_i2c_read() result=%d, addr = %x, data=%x\n"
+ , ret, addr, *data);
+ return ret;
+ }
+
+ return ret;
+}
+
+int fci_i2c_write(HANDLE hDevice, u8 chip, u8 addr, u8 alen, u8 *data, u8 len)
+{
+ int ret;
+ u8 *paddr = &addr;
+
+ ret = fci_i2c_transfer(hDevice, I2C_WRITE, chip << 1
+ , paddr, alen, data, len);
+
+ if (ret != I2C_OK)
+ PRINTF(hDevice, "fci_i2c_write() result=%d, addr= %x, data=%x\n"
+ , ret, addr, *data);
+
+ return ret;
+}
+
+int fci_i2c_deinit(HANDLE hDevice)
+{
+ bbm_write(hDevice, BBM_I2C_CTR, 0x00);
+ return BBM_OK;
+}
diff --git a/drivers/media/isdbt/fc8150/fci_i2c.h b/drivers/media/isdbt/fc8150/fci_i2c.h
new file mode 100644
index 0000000..8c4ce07
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fci_i2c.h
@@ -0,0 +1,29 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : fci_i2c.h
+
+ Description : fci i2c driver header
+*******************************************************************************/
+
+#ifndef __FCI_I2C_H__
+#define __FCI_I2C_H__
+
+#include "fci_types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int fci_i2c_init(HANDLE hDevice, int speed, int slaveaddr);
+extern int fci_i2c_read(HANDLE hDevice, u8 chip, u8 addr
+ , u8 alen, u8 *data, u8 len);
+extern int fci_i2c_write(HANDLE hDevice, u8 chip, u8 addr
+ , u8 alen, u8 *data, u8 len);
+extern int fci_i2c_deinit(HANDLE hDevice);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/drivers/media/isdbt/fc8150/fci_oal.c b/drivers/media/isdbt/fc8150/fci_oal.c
new file mode 100644
index 0000000..a7d7f77
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fci_oal.c
@@ -0,0 +1,50 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : fci_oal.c
+
+ Description : OS adaptation layer
+*******************************************************************************/
+#include <linux/kernel.h>
+#include <linux/delay.h>
+
+#include "fc8150_regs.h"
+#include "fci_types.h"
+
+void PRINTF(HANDLE hDevice, char *fmt, ...)
+{
+ va_list ap;
+ char str[256];
+
+ va_start(ap, fmt);
+ vsprintf(str, fmt, ap);
+
+ printk(KERN_DEBUG"%s", str);
+
+ va_end(ap);
+}
+
+void msWait(int ms)
+{
+ msleep(ms);
+}
+
+void OAL_CREATE_SEMAPHORE(void)
+{
+
+}
+
+void OAL_DELETE_SEMAPHORE(void)
+{
+
+}
+
+void OAL_OBTAIN_SEMAPHORE(void)
+{
+
+}
+
+void OAL_RELEASE_SEMAPHORE(void)
+{
+
+}
diff --git a/drivers/media/isdbt/fc8150/fci_oal.h b/drivers/media/isdbt/fc8150/fci_oal.h
new file mode 100644
index 0000000..88b3c35
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fci_oal.h
@@ -0,0 +1,28 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : fci_oal.h
+
+ Description : OS adatation layer
+*******************************************************************************/
+
+#ifndef __FCI_OAL_H__
+#define __FCI_OAL_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern void PRINTF(HANDLE hDevice, char *fmt, ...);
+extern void msWait(int ms);
+
+extern void OAL_CREATE_SEMAPHORE(void);
+extern void OAL_DELETE_SEMAPHORE(void);
+extern void OAL_OBTAIN_SEMAPHORE(void);
+extern void OAL_RELEASE_SEMAPHORE(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/drivers/media/isdbt/fc8150/fci_ringbuffer.c b/drivers/media/isdbt/fc8150/fci_ringbuffer.c
new file mode 100644
index 0000000..25fad51
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fci_ringbuffer.c
@@ -0,0 +1,271 @@
+/*****************************************************************************
+ Copyright(c) 2010 FCI Inc. All Rights Reserved
+
+ File name : fci_ringbuffer.c
+
+ Description : fci ringbuffer
+
+ History :
+ ----------------------------------------------------------------------
+ 2010/11/25 aslan.cho initial
+*******************************************************************************/
+
+#include <linux/errno.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/string.h>
+#include <linux/uaccess.h>
+
+#include "fci_ringbuffer.h"
+
+#define PKT_READY 0
+#define PKT_DISPOSED 1
+
+void fci_ringbuffer_init(struct fci_ringbuffer *rbuf, void *data, size_t len)
+{
+ rbuf->pread = rbuf->pwrite = 0;
+ rbuf->data = data;
+ rbuf->size = len;
+ rbuf->error = 0;
+
+ init_waitqueue_head(&rbuf->queue);
+
+ spin_lock_init(&(rbuf->lock));
+}
+
+int fci_ringbuffer_empty(struct fci_ringbuffer *rbuf)
+{
+ return (rbuf->pread == rbuf->pwrite);
+}
+
+ssize_t fci_ringbuffer_free(struct fci_ringbuffer *rbuf)
+{
+ ssize_t free;
+
+ free = rbuf->pread - rbuf->pwrite;
+ if (free <= 0)
+ free += rbuf->size;
+ return free-1;
+}
+
+ssize_t fci_ringbuffer_avail(struct fci_ringbuffer *rbuf)
+{
+ ssize_t avail;
+
+ avail = rbuf->pwrite - rbuf->pread;
+ if (avail < 0)
+ avail += rbuf->size;
+ return avail;
+}
+
+void fci_ringbuffer_flush(struct fci_ringbuffer *rbuf)
+{
+ rbuf->pread = rbuf->pwrite;
+ rbuf->error = 0;
+}
+
+void fci_ringbuffer_reset(struct fci_ringbuffer *rbuf)
+{
+ rbuf->pread = rbuf->pwrite = 0;
+ rbuf->error = 0;
+}
+
+void fci_ringbuffer_flush_spinlock_wakeup(struct fci_ringbuffer *rbuf)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&rbuf->lock, flags);
+ fci_ringbuffer_flush(rbuf);
+ spin_unlock_irqrestore(&rbuf->lock, flags);
+
+ wake_up(&rbuf->queue);
+}
+
+ssize_t fci_ringbuffer_read_user(struct fci_ringbuffer *rbuf
+ , u8 __user *buf, size_t len)
+{
+ size_t todo = len;
+ size_t split;
+
+ split = (rbuf->pread + len > rbuf->size) ? rbuf->size - rbuf->pread : 0;
+ if (split > 0) {
+ if (copy_to_user(buf, rbuf->data+rbuf->pread, split))
+ return -EFAULT;
+ buf += split;
+ todo -= split;
+ rbuf->pread = 0;
+ }
+ if (copy_to_user(buf, rbuf->data+rbuf->pread, todo))
+ return -EFAULT;
+
+ rbuf->pread = (rbuf->pread + todo) % rbuf->size;
+
+ return len;
+}
+
+void fci_ringbuffer_read(struct fci_ringbuffer *rbuf, u8 *buf, size_t len)
+{
+ size_t todo = len;
+ size_t split;
+
+ split = (rbuf->pread + len > rbuf->size) ? rbuf->size - rbuf->pread : 0;
+ if (split > 0) {
+ memcpy(buf, rbuf->data+rbuf->pread, split);
+ buf += split;
+ todo -= split;
+ rbuf->pread = 0;
+ }
+ memcpy(buf, rbuf->data+rbuf->pread, todo);
+
+ rbuf->pread = (rbuf->pread + todo) % rbuf->size;
+}
+
+ssize_t fci_ringbuffer_write(struct fci_ringbuffer *rbuf
+ , const u8 *buf, size_t len)
+{
+ size_t todo = len;
+ size_t split;
+
+ split = (rbuf->pwrite + len > rbuf->size)
+ ? rbuf->size - rbuf->pwrite : 0;
+
+ if (split > 0) {
+ memcpy(rbuf->data+rbuf->pwrite, buf, split);
+ buf += split;
+ todo -= split;
+ rbuf->pwrite = 0;
+ }
+ memcpy(rbuf->data+rbuf->pwrite, buf, todo);
+ rbuf->pwrite = (rbuf->pwrite + todo) % rbuf->size;
+
+ return len;
+}
+
+ssize_t fci_ringbuffer_pkt_write(struct fci_ringbuffer *rbuf
+ , u8 *buf, size_t len)
+{
+ int status;
+ ssize_t oldpwrite = rbuf->pwrite;
+
+ FCI_RINGBUFFER_WRITE_BYTE(rbuf, len >> 8);
+ FCI_RINGBUFFER_WRITE_BYTE(rbuf, len & 0xff);
+ FCI_RINGBUFFER_WRITE_BYTE(rbuf, PKT_READY);
+ status = fci_ringbuffer_write(rbuf, buf, len);
+
+ if (status < 0)
+ rbuf->pwrite = oldpwrite;
+ return status;
+}
+
+ssize_t fci_ringbuffer_pkt_read_user(struct fci_ringbuffer *rbuf, size_t idx,
+ int offset, u8 __user *buf, size_t len)
+{
+ size_t todo;
+ size_t split;
+ size_t pktlen;
+
+ pktlen = rbuf->data[idx] << 8;
+ pktlen |= rbuf->data[(idx + 1) % rbuf->size];
+ if (offset > pktlen)
+ return -EINVAL;
+ if ((offset + len) > pktlen)
+ len = pktlen - offset;
+
+ idx = (idx + FCI_RINGBUFFER_PKTHDRSIZE + offset) % rbuf->size;
+ todo = len;
+ split = ((idx + len) > rbuf->size) ? rbuf->size - idx : 0;
+ if (split > 0) {
+ if (copy_to_user(buf, rbuf->data+idx, split))
+ return -EFAULT;
+ buf += split;
+ todo -= split;
+ idx = 0;
+ }
+ if (copy_to_user(buf, rbuf->data+idx, todo))
+ return -EFAULT;
+
+ return len;
+}
+
+ssize_t fci_ringbuffer_pkt_read(struct fci_ringbuffer *rbuf, size_t idx,
+ int offset, u8 *buf, size_t len)
+{
+ size_t todo;
+ size_t split;
+ size_t pktlen;
+
+ pktlen = rbuf->data[idx] << 8;
+ pktlen |= rbuf->data[(idx + 1) % rbuf->size];
+ if (offset > pktlen)
+ return -EINVAL;
+ if ((offset + len) > pktlen)
+ len = pktlen - offset;
+
+ idx = (idx + FCI_RINGBUFFER_PKTHDRSIZE + offset) % rbuf->size;
+ todo = len;
+ split = ((idx + len) > rbuf->size) ? rbuf->size - idx : 0;
+ if (split > 0) {
+ memcpy(buf, rbuf->data+idx, split);
+ buf += split;
+ todo -= split;
+ idx = 0;
+ }
+ memcpy(buf, rbuf->data+idx, todo);
+ return len;
+}
+
+void fci_ringbuffer_pkt_dispose(struct fci_ringbuffer *rbuf, size_t idx)
+{
+ size_t pktlen;
+
+ rbuf->data[(idx + 2) % rbuf->size] = PKT_DISPOSED;
+
+ while (fci_ringbuffer_avail(rbuf) > FCI_RINGBUFFER_PKTHDRSIZE) {
+ if (FCI_RINGBUFFER_PEEK(rbuf, 2) == PKT_DISPOSED) {
+ pktlen = FCI_RINGBUFFER_PEEK(rbuf, 0) << 8;
+ pktlen |= FCI_RINGBUFFER_PEEK(rbuf, 1);
+ FCI_RINGBUFFER_SKIP(rbuf
+ , pktlen + FCI_RINGBUFFER_PKTHDRSIZE);
+ } else
+ break;
+ }
+}
+
+ssize_t fci_ringbuffer_pkt_next(struct fci_ringbuffer *rbuf
+ , size_t idx, size_t *pktlen)
+{
+ int consumed;
+ int curpktlen;
+ int curpktstatus;
+
+ if (idx == -1)
+ idx = rbuf->pread;
+ else {
+ curpktlen = rbuf->data[idx] << 8;
+ curpktlen |= rbuf->data[(idx + 1) % rbuf->size];
+ idx = (idx + curpktlen + FCI_RINGBUFFER_PKTHDRSIZE)
+ % rbuf->size;
+ }
+
+ consumed = (idx - rbuf->pread) % rbuf->size;
+
+ while ((fci_ringbuffer_avail(rbuf) - consumed)
+ > FCI_RINGBUFFER_PKTHDRSIZE) {
+
+ curpktlen = rbuf->data[idx] << 8;
+ curpktlen |= rbuf->data[(idx + 1) % rbuf->size];
+ curpktstatus = rbuf->data[(idx + 2) % rbuf->size];
+
+ if (curpktstatus == PKT_READY) {
+ *pktlen = curpktlen;
+ return idx;
+ }
+
+ consumed += curpktlen + FCI_RINGBUFFER_PKTHDRSIZE;
+ idx = (idx + curpktlen + FCI_RINGBUFFER_PKTHDRSIZE)
+ % rbuf->size;
+ }
+
+ return -1;
+}
diff --git a/drivers/media/isdbt/fc8150/fci_ringbuffer.h b/drivers/media/isdbt/fc8150/fci_ringbuffer.h
new file mode 100644
index 0000000..0d1a2cc
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fci_ringbuffer.h
@@ -0,0 +1,89 @@
+/*****************************************************************************
+ Copyright(c) 2010 FCI Inc. All Rights Reserved
+
+ File name : fci_ringbuffer.h
+
+ Description :
+
+ History :
+ ----------------------------------------------------------------------
+ 2010/11/25 aslan.cho initial
+*******************************************************************************/
+
+#ifndef __FCI_RINGBUFFER_H__
+#define __FCI_RINGBUFFER_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <linux/spinlock.h>
+#include <linux/wait.h>
+
+struct fci_ringbuffer {
+ u8 *data;
+ ssize_t size;
+ ssize_t pread;
+ ssize_t pwrite;
+ int error;
+
+ wait_queue_head_t queue;
+ spinlock_t lock;
+};
+
+#define FCI_RINGBUFFER_PKTHDRSIZE 3
+
+extern void fci_ringbuffer_init(struct fci_ringbuffer *rbuf
+ , void *data, size_t len);
+
+extern int fci_ringbuffer_empty(struct fci_ringbuffer *rbuf);
+
+extern ssize_t fci_ringbuffer_free(struct fci_ringbuffer *rbuf);
+
+extern ssize_t fci_ringbuffer_avail(struct fci_ringbuffer *rbuf);
+
+extern void fci_ringbuffer_reset(struct fci_ringbuffer *rbuf);
+
+extern void fci_ringbuffer_flush(struct fci_ringbuffer *rbuf);
+
+extern void fci_ringbuffer_flush_spinlock_wakeup(struct fci_ringbuffer *rbuf);
+
+#define FCI_RINGBUFFER_PEEK(rbuf, offs) \
+ ((rbuf)->data[((rbuf)->pread+(offs)) % (rbuf)->size])
+
+#define FCI_RINGBUFFER_SKIP(rbuf, num) \
+ ((rbuf)->pread = ((rbuf)->pread+(num)) % (rbuf)->size)
+
+extern ssize_t fci_ringbuffer_read_user(struct fci_ringbuffer *rbuf
+, u8 __user *buf, size_t len);
+
+extern void fci_ringbuffer_read(struct fci_ringbuffer *rbuf
+ , u8 *buf, size_t len);
+
+
+#define FCI_RINGBUFFER_WRITE_BYTE(rbuf, byte) \
+ { (rbuf)->data[(rbuf)->pwrite] = (byte); \
+ (rbuf)->pwrite = ((rbuf)->pwrite + 1) % (rbuf)->size; }
+
+extern ssize_t fci_ringbuffer_write(struct fci_ringbuffer *rbuf
+ , const u8 *buf, size_t len);
+
+extern ssize_t fci_ringbuffer_pkt_write(struct fci_ringbuffer *rbuf
+ , u8 *buf, size_t len);
+
+extern ssize_t fci_ringbuffer_pkt_read_user(struct fci_ringbuffer *rbuf
+ , size_t idx, int offset, u8 __user *buf, size_t len);
+
+extern ssize_t fci_ringbuffer_pkt_read(struct fci_ringbuffer *rbuf
+ , size_t idx, int offset, u8 *buf, size_t len);
+
+extern void fci_ringbuffer_pkt_dispose(struct fci_ringbuffer *rbuf, size_t idx);
+
+extern ssize_t fci_ringbuffer_pkt_next(struct fci_ringbuffer *rbuf
+ , size_t idx, size_t *pktlen);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/drivers/media/isdbt/fc8150/fci_tun.c b/drivers/media/isdbt/fc8150/fci_tun.c
new file mode 100644
index 0000000..a369487
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fci_tun.c
@@ -0,0 +1,204 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : fci_tun.c
+
+ Description : tuner control driver
+*******************************************************************************/
+
+#include "fci_types.h"
+#include "fci_oal.h"
+#include "fci_hal.h"
+#include "fci_tun.h"
+#include "fci_i2c.h"
+#include "fci_bypass.h"
+#include "fc8150_regs.h"
+#include "fc8150_bb.h"
+#include "fc8150_tun.h"
+
+
+#define FC8150_TUNER_ADDR 0x5b
+
+static u8 tuner_addr = FC8150_TUNER_ADDR;
+static enum band_type tuner_band = ISDBT_1_SEG_TYPE;
+static enum i2c_type tuner_i2c = FCI_I2C_TYPE;
+
+struct I2C_DRV {
+ int (*init)(HANDLE hDevice, int speed, int slaveaddr);
+ int (*read)(HANDLE hDevice, u8 chip, u8 addr
+ , u8 alen, u8 *data, u8 len);
+ int (*write)(HANDLE hDevice, u8 chip, u8 addr
+ , u8 alen, u8 *data, u8 len);
+ int (*deinit)(HANDLE hDevice);
+};
+
+static struct I2C_DRV fcii2c = {
+ &fci_i2c_init,
+ &fci_i2c_read,
+ &fci_i2c_write,
+ &fci_i2c_deinit
+};
+
+static struct I2C_DRV fcibypass = {
+ &fci_bypass_init,
+ &fci_bypass_read,
+ &fci_bypass_write,
+ &fci_bypass_deinit
+};
+
+struct TUNER_DRV {
+ int (*init)(HANDLE hDevice, enum band_type band);
+ int (*set_freq)(HANDLE hDevice
+ , enum band_type band, u32 rf_Khz);
+ int (*get_rssi)(HANDLE hDevice, int *rssi);
+ int (*deinit)(HANDLE hDevice);
+};
+
+static struct TUNER_DRV fc8150_tuner = {
+ &fc8150_tuner_init,
+ &fc8150_set_freq,
+ &fc8150_get_rssi,
+ &fc8150_tuner_deinit
+};
+
+#if 0
+static TUNER_DRV fc8151_tuner = {
+ &fc8151_tuner_init,
+ &fc8151_set_freq,
+ &fc8151_get_rssi,
+ &fc8151_tuner_deinit
+};
+#endif
+
+static struct I2C_DRV *tuner_ctrl = &fcii2c;
+static struct TUNER_DRV *tuner = &fc8150_tuner;
+
+int tuner_ctrl_select(HANDLE hDevice, enum i2c_type type)
+{
+ switch (type) {
+ case FCI_I2C_TYPE:
+ tuner_ctrl = &fcii2c;
+ break;
+ case FCI_BYPASS_TYPE:
+ tuner_ctrl = &fcibypass;
+ break;
+ default:
+ return BBM_E_TN_CTRL_SELECT;
+ }
+
+ if (tuner_ctrl->init(hDevice, 600, 0))
+ return BBM_E_TN_CTRL_INIT;
+
+ tuner_i2c = type;
+
+ return BBM_OK;
+}
+
+int tuner_ctrl_deselect(HANDLE hDevice)
+{
+ if (tuner_ctrl == NULL)
+ return BBM_E_TN_CTRL_SELECT;
+
+ tuner_ctrl->deinit(hDevice);
+
+ tuner_i2c = FCI_I2C_TYPE;
+ tuner_ctrl = &fcii2c;
+
+ return BBM_OK;
+}
+
+int tuner_i2c_read(HANDLE hDevice, u8 addr, u8 alen, u8 *data, u8 len)
+{
+ if (tuner_ctrl == NULL)
+ return BBM_E_TN_CTRL_SELECT;
+
+ if (tuner_ctrl->read(hDevice, tuner_addr, addr, alen, data, len))
+ return BBM_E_TN_READ;
+
+ return BBM_OK;
+}
+
+int tuner_i2c_write(HANDLE hDevice, u8 addr, u8 alen, u8 *data, u8 len)
+{
+ if (tuner_ctrl == NULL)
+ return BBM_E_TN_CTRL_SELECT;
+
+ if (tuner_ctrl->write(hDevice, tuner_addr, addr, alen, data, len))
+ return BBM_E_TN_WRITE;
+
+ return BBM_OK;
+}
+
+int tuner_set_freq(HANDLE hDevice, u32 freq)
+{
+ if (tuner == NULL)
+ return BBM_E_TN_SELECT;
+
+#if (BBM_BAND_WIDTH == 8)
+ freq -= 460;
+#else
+ freq -= 380;
+#endif
+
+ if (tuner->set_freq(hDevice, tuner_band, freq))
+ return BBM_E_TN_SET_FREQ;
+
+ fc8150_reset(hDevice);
+
+ return BBM_OK;
+}
+
+int tuner_select(HANDLE hDevice, u32 product, u32 band)
+{
+ switch (product) {
+ case FC8150_TUNER:
+ tuner = &fc8150_tuner;
+ tuner_addr = FC8150_TUNER_ADDR;
+ tuner_band = band;
+ break;
+#if 0
+ case FC8151_TUNER:
+ tuner = &fc8151_tuner;
+ tuner_addr = FC8150_TUNER_ADDR;
+ tuner_band = band;
+ break;
+#endif
+ default:
+ return BBM_E_TN_SELECT;
+ }
+
+ if (tuner == NULL)
+ return BBM_E_TN_SELECT;
+
+ if (tuner_i2c == FCI_BYPASS_TYPE)
+ bbm_write(hDevice, BBM_RF_DEVID, tuner_addr);
+
+ if (tuner->init(hDevice, tuner_band))
+ return BBM_E_TN_INIT;
+
+ return BBM_OK;
+}
+
+int tuner_deselect(HANDLE hDevice)
+{
+ if (tuner == NULL)
+ return BBM_E_TN_SELECT;
+
+ if (tuner->deinit(hDevice))
+ return BBM_NOK;
+
+ tuner = NULL;
+
+ return BBM_OK;
+}
+
+int tuner_get_rssi(HANDLE hDevice, s32 *rssi)
+{
+ if (tuner == NULL)
+ return BBM_E_TN_SELECT;
+
+ if (tuner->get_rssi(hDevice, rssi))
+ return BBM_E_TN_RSSI;
+
+ return BBM_OK;
+}
diff --git a/drivers/media/isdbt/fc8150/fci_tun.h b/drivers/media/isdbt/fc8150/fci_tun.h
new file mode 100644
index 0000000..f81c522
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fci_tun.h
@@ -0,0 +1,46 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : fci_tun.h
+
+ Description : tuner control driver
+*******************************************************************************/
+
+#ifndef __FCI_TUN_H__
+#define __FCI_TUN_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "fci_types.h"
+
+enum i2c_type {
+ FCI_I2C_TYPE = 0,
+ FCI_BYPASS_TYPE = 1
+};
+
+enum band_type {
+ ISDBT_1_SEG_TYPE = 2
+};
+
+enum product_type {
+ FC8150_TUNER = 8150,
+ FC8151_TUNER = 8151
+};
+
+extern int tuner_ctrl_select(HANDLE hDevice, enum i2c_type type);
+extern int tuner_ctrl_deselect(HANDLE hDevice);
+extern int tuner_select(HANDLE hDevice, u32 product, u32 band);
+extern int tuner_deselect(HANDLE hDevice);
+
+extern int tuner_i2c_read(HANDLE hDevice, u8 addr, u8 alen, u8 *data, u8 len);
+extern int tuner_i2c_write(HANDLE hDevice, u8 addr, u8 alen, u8 *data, u8 len);
+extern int tuner_set_freq(HANDLE hDevice, u32 freq);
+extern int tuner_get_rssi(HANDLE hDevice, s32 *rssi);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/drivers/media/isdbt/fc8150/fci_types.h b/drivers/media/isdbt/fc8150/fci_types.h
new file mode 100644
index 0000000..95b5ca8
--- /dev/null
+++ b/drivers/media/isdbt/fc8150/fci_types.h
@@ -0,0 +1,61 @@
+/*****************************************************************************
+ Copyright(c) 2012 FCI Inc. All Rights Reserved
+
+ File name : fci_types.h
+
+ Description :
+*******************************************************************************/
+
+#ifndef __FCI_TYPES_H__
+#define __FCI_TYPES_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef HANDLE
+#define HANDLE void *
+#endif
+
+#define BBM_HPI 0
+#define BBM_SPI 1
+#define BBM_USB 2
+#define BBM_I2C 3
+#define BBM_PPI 4
+#define BBM_SPIB 5
+
+#define s8 signed char
+#define s16 signed short int
+#define s32 signed int
+#define u8 unsigned char
+#define u16 unsigned short
+#define u32 unsigned int
+#define TRUE 1
+#define FALSE 0
+
+#ifndef NULL
+#define NULL 0
+#endif
+
+#define BBM_OK 0
+#define BBM_NOK 1
+
+#define BBM_E_FAIL 0x00000001
+#define BBM_E_HOSTIF_SELECT 0x00000002
+#define BBM_E_HOSTIF_INIT 0x00000003
+#define BBM_E_BB_WRITE 0x00000100
+#define BBM_E_BB_READ 0x00000101
+#define BBM_E_TN_WRITE 0x00000200
+#define BBM_E_TN_READ 0x00000201
+#define BBM_E_TN_CTRL_SELECT 0x00000202
+#define BBM_E_TN_CTRL_INIT 0x00000203
+#define BBM_E_TN_SELECT 0x00000204
+#define BBM_E_TN_INIT 0x00000205
+#define BBM_E_TN_RSSI 0x00000206
+#define BBM_E_TN_SET_FREQ 0x00000207
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif