Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 3aa41146 authored by derfelot's avatar derfelot
Browse files

misc: Add Socionext mm_tuner driver support from Sony kernel

Taken from Sony 47.2.A.10.107 stock kernel
parent a3993fee
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -618,4 +618,5 @@ source "drivers/misc/mic/Kconfig"
source "drivers/misc/genwqe/Kconfig"
source "drivers/misc/echo/Kconfig"
source "drivers/misc/cxl/Kconfig"
source "drivers/misc/mm_tuner/Kconfig"
endmenu
+1 −0
Original line number Diff line number Diff line
@@ -69,3 +69,4 @@ obj-y += qcom/
obj-$(CONFIG_QPNP_MISC) 	+= qpnp-misc.o
obj-$(CONFIG_MEMORY_STATE_TIME) += memory_state_time.o
obj-$(CONFIG_LDO_VIBRATOR) += ldo_vibrator.o
obj-$(CONFIG_MMTUNER_MN8855x) += mm_tuner/
+16 −0
Original line number Diff line number Diff line
config MMTUNER_MN8855x
	tristate "Socionext mm_tuner driver support"
	---help---
	  This module adds support for wireless adapters based on
	  Socionext MN8855x chipset.

	  If you choose to build a module, it'll be called mm_tuner. Say Y if
	  unsure.

config MMTUNER_DEBUG
        bool "Socionext MN8855x Debug message mode"
	depends on MMTUNER_MN8855x
	default n
	---help---
	  MN8855x driver debug message mode. Say Y when you want to debug.
+162 −0
Original line number Diff line number Diff line
##############################################################################
# Makefile for TUNER Driver
##############################################################################

#driver name
ifndef DRV_NAME
DRV_NAME = mm_tuner
endif

LOCAL_INC    += $(src)/include
LOCAL_COMMON += $(src)/include_share

subdir-ccflags-y += -I$(LOCAL_INC)
subdir-ccflags-y += -I$(LOCAL_COMMON)

OBJS := src/tuner_drv.o
OBJS += src/tuner_drv_hw.o

#PATH compile options
CONFIG_MMTUNER_DPATH=SPI
CONFIG_MMTUNER_CPATH=SPI

ifeq ($(CONFIG_MMTUNER_DEBUG), y)
  subdir-ccflags-y += -DDEBUG
endif
ifeq ($(CONFIG_MMTUNER_MN8855x), m)
  subdir-ccflags-y += -fno-pic
endif
ifdef $(CONFIG_MMTUNER_I2CPARPORTX)
  subdir-ccflags-y += -DTUNER_CONFIG_IRQ_PC_LINUX
endif
ifeq ($(CONFIG_MMTUNER_HOSTCPU), pandaboard)
  subdir-ccflags-y += -DPANDABOARD
endif
ifeq ($(CONFIG_MMTUNER_HOSTCPU), dragon410c)
  subdir-ccflags-y += -DDRAGON410C
endif
ifeq ($(CONFIG_NO_DEVICE_TREE), y)
  subdir-ccflags-y += -DTUNER_CONFIG_NO_DEVICE_TREE
endif

#
# SPI compile options
#  CONFIG_MMTUNER_TSIF_SPI_EDGE : Use edge mode for SPI
#  CONFIG_MMTUNER_TSIF_SI_EXT   : Use Extend Read command for packet read
#  CONFIG_MMTUNER_DIV_SPI_MSG   : Use message separetion mode for SPI
#
ifeq ($(CONFIG_MMTUNER_TSIF_SPI_EDGE), y)
  subdir-ccflags-y += -DTUNER_CONFIG_SPI_EDGE
endif
ifeq ($(CONFIG_MMTUNER_TSIF_SPI_EXT), y)
  subdir-ccflags-y += -DTUNER_CONFIG_SPI_EXTREAD
endif
ifeq ($(CONFIG_MMTUNER_DIV_SPI_MSG), y)
  OBJS += src/tuner_drv_hw_spi.o
  subdir-ccflags-y += -DTUNER_CONFIG_SPI_DIVMSG
endif
ifeq ($(CONFIG_MMTUNER_SPI_BREAKCODE), y)
  subdir-ccflags-y += -DTUNER_CONFIG_SPI_BREAKCODE
endif


ifeq ($(CONFIG_MMTUNER_DPATH), SDIO)
  OBJS += src/tuner_drv_hw_sdio.o
  subdir-ccflags-y += -DDPATH_SDIO
endif
ifeq ($(CONFIG_MMTUNER_DPATH), SPI)
  OBJS += src/tuner_drv_hw_spi.o
  subdir-ccflags-y += -DDPATH_SPI
endif
ifeq ($(CONFIG_MMTUNER_CPATH), I2C)
  OBJS += src/tuner_drv_hw_i2c.o
  subdir-ccflags-y += -DCPATH_I2C
endif
ifeq ($(CONFIG_MMTUNER_CPATH), SPI)
  subdir-ccflags-y += -DCPATH_SPI
endif
ifeq ($(CONFIG_MMTUNER_CPATH), SDIO)
  subdir-ccflags-y += -DCPATH_SDIO
endif

#SPI performance measurement debug
#GP Get Packet
#DR Get DATAREADY
#subdir-ccflags-y += -DSPI_GP_MESURE_DEBUG
#subdir-ccflags-y += -DSPI_DR_MESURE_DEBUG

#
# PID NULL FILTER
#
ifeq ($(CONFIG_MMTUNER_NULLFILTER), y)
  subdir-ccflags-y += -DTUNER_CONFIG_PF_NULLFILTER
endif

#
# BYTE ORDER CONFIGURATION.
#
ifeq ($(CONFIG_MMTUNER_MSBFIRST), y)
  subdir-ccflags-y += -DTUNER_CONFIG_SLV_MSBFIRST
endif

#
# DMA ALIGNMENT
#
ifdef CONFIG_MMTUNER_ALIGN
  subdir-ccflags-y += -DTUNER_CONFIG_SPI_ALIGN=${CONFIG_MMTUNER_ALIGN}
endif


#
# AES compile options
#
#   CONFIG_MMTUNER_AES = y : Use AES but does not check TS header of 1st packet
#   CONFIG_MMTUNER_AES = c : Use AES and check TS header of 1st packet
#
ifeq ($(CONFIG_MMTUNER_AES), y)
  OBJS += src/tuner_drv_hw_aes.o
  subdir-ccflags-y += -DTUNER_CONFIG_AES_ENABLE
endif

ifeq ($(CONFIG_MMTUNER_AES), c)
  OBJS += src/tuner_drv_hw_aes.o
  OBJS += src/aes_sample.o
  subdir-ccflags-y += -DTUNER_CONFIG_AES_ENABLE
  subdir-ccflags-y += -DTUNER_CONFIG_AES_TSCHK
endif


#
# GPIF compile options
#
# CONFIG_MMTUNER_DPATH = GPIF  : Use GPIF for DPATH
# CONFIG_MMTUNER_CPATH = GPIF  : Use GPIF for CPATH
# CONFIG_MMTUNER_TSIF_GPIF_DMA : Use DMA transfer for DPATH
#
ifeq ($(CONFIG_MMTUNER_DPATH), GPIF)
  OBJS += src/gpif.o
  OBJS += src/gpmc.o
  OBJS += src/tuner_drv_hw_gpif.o
  subdir-ccflags-y += -DDPATH_GPIF
endif
ifeq ($(CONFIG_MMTUNER_CPATH), GPIF)
  subdir-ccflags-y += -DCPATH_GPIF
endif
ifeq ($(CONFIG_MMTUNER_TSIF_GPIF_DMA), y)
  subdir-ccflags-y += -DTUNER_CONFIG_GPIF_DMA
endif

#
# Addtional libaray path is here
#
ifdef CONFIG_MMTUNER_LIBS
  subdir-ccflags-y += -I${CONFIG_MMTUNER_LIBS}
endif



$(DRV_NAME)-objs += $(OBJS)

obj-$(CONFIG_MMTUNER_MN8855x) = $(DRV_NAME).o

clean-files := *.o .*.cmd modules.builtin modules.order
+170 −0
Original line number Diff line number Diff line
/***************************************************************************//**
 *
 *  @file		tuner_drv.h
 *
 *  @brief		common header file for mm_tuner55x driver
 *
 ****************************************************************************//*
 * Copyright (c) 2015 Socionext Inc.
 *******************************************************************************
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 ******************************************************************************/
/*
 * Copyright (C) 2016 Sony Mobile Communications Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2, as
 * published by the Free Software Foundation.
 */
/*..+....1....+....2....+....3....+....4....+....5....+....6....+....7....+...*/
#ifndef _TUNER_DRV_H
#define _TUNER_DRV_H

#ifdef DEBUG
#include <linux/string.h>
#define __file__		(strrchr(__FILE__, '/') + 1)
#else
#endif

#include <linux/interrupt.h>
#include <linux/slab.h>
#include <linux/mutex.h>

#include "tuner_drv_sys.h"

/**
 * Structure providing the version of the tuner driver runtime
 */
struct _mmtuner_version {
	/** target device identifier
	 *
	 * Device id means two digits of bottom of type name.
	 */
	const uint8_t device;

	/** driver major version */
	const uint8_t major;

	/** driver minor version */
	const uint8_t minor;

	/** driver tinny version */
	const uint8_t hotfix;

	/** driver release candidate suffix string, e.g. "-rc4". */
	const char *rc;

	/** driver description */
	const char *describe;
};

/**
 * MMTUNER context structure that contain some parameters and
 * handle of the kernel threads.
 */
struct _mmtuner_cntxt {
	/* wait queue for the poll/select system call */
	wait_queue_head_t poll_waitq;
	/* exclusive control to access poll_flag */
	spinlock_t poll_lock;
	/* status flag for poll/select */
	uint32_t poll_flag;

	/* ID of kernel thread that handle interrupts (IRQ) from tuner device */
	struct task_struct *irqth_id;
	/* IRQ kernel thread wake up flag */
	uint32_t irqth_flag;
	/* IRQ kernel thread wait queue */
	wait_queue_head_t irqth_waitq;

	/* to record the IRQ (event) factor */
	union _tuner_data_event ev;

	/* multiple open count */
	uint32_t opcnt;
};

struct _tsif_cntxt {
	/* TS I/F Thread */
	struct task_struct *tsifth_id;	/* Kernel thread ID */
	bool tsifth_wait;				/* Wait indicator */
	uint32_t tsifth_flag;			/* wake up flag */
	wait_queue_head_t tsifth_waitq;	/* wait queue */

	/* TS packet buffer */
	uint8_t *pktbuf;		/* pointer to TS packet buffer */
	uint8_t *spibuf;		/* pointer to SPI transfer*/
	uint32_t pwr;			/* write position of TS packet buffer */
	uint32_t prd;			/* read position of TS packet buffer */
	uint32_t ovf;			/* packet buffer overflow counter */

	enum _bw_seg bw;		/* reception SEGment system */
	size_t ts_rxpkt_num;	/* num of packets a RX transaction */
	size_t ts_rx_size;		/* RX transaction byte size */
	size_t ts_pktbuf_size;	/* TS receive buffer size */

	/* read (TS data read) */
	uint32_t tsread_flag;			/* wake up flag */
	wait_queue_head_t tsread_waitq;	/* wait queue */

	struct _tuner_data_tsif *tsif;
};

/* flag bit position of IRQ kernel thread */
#define TUNER_IRQTH_NONE		0x00000000	/* initial flag */
#define TUNER_IRQKTH_CATCHIRQ	0x00000001	/* interrupt flag position */
#define TUNER_KTH_END			0x80000000	/* end flag position */

/* flag bit position of TS buffering thread */
#define TUNER_TSIFTH_NONE		0x00000000	/* initial flag */
#define TUNER_TSIFTH_ACTIVE		0x00000001	/* thread is working */
#define TUNER_TSIFTH_END		0x80000000	/* end flag position */

#define TUNER_TSIFTH_FIFOERROR_MAX	(10)

/* TS I/F thread retry & wait time */
#define TUNER_TSIFTH_SLEEP_RETRY	(500)
#define TUNER_TSIFTH_SLEEP_MIN		(1000)
#define TUNER_TSIFTH_SLEEP_MAX		(2000)

/* flag bit position of TS reading */
#define TUNER_TSREAD_WAIT		0x00000000	/* wait */
#define TUNER_TSREAD_IDLE		0x00000001	/* idle (initial) */
#define TUNER_TSREAD_ACTIVE		0x00000002	/* active (reading) */
#define TUNER_TSREAD_TIMEOUT	0x00000004	/* Timeout */
#define TUNER_TSREAD_END		0x80000000	/* end */


/* 4 : Use both IL=2 and IL=4 , then packet buffer is 1.0Mb (default)*/
/* 2 : USE ONLY IL=2 , then expand packet buffer to 2.7Mb */
/* Please set TUNER_TSPKTBUF_MODE to 2
*  when you don't need to Interleave mode 4
*/
#define TUNER_TSPKTBUF_MODE     4

/* Maximum packet buffer size is defined by MAX_TSPKTBUF_SIZE.
*  Also it will be limited by MAX_TSPKTBUF_BANK. The size of
*  packet buffer will be calculated by the below,
*  maxbank = TUNER_MAX_TSPKTBUF_SIZE/lowerlimit;
*  if ( maxbank > TUNER_MAX_TSPKTBUF_BANK ) maxbank = TUNER_MAX_TSPKTBUF_BANK;
*  packet buffer size =  tc->ts_rx_size) * maxbank;
*/
#define TUNER_MAX_TSPKTBUF_SIZE 2097152
#define TUNER_MAX_TSPKTBUF_BANK 12

extern irqreturn_t tuner_interrupt(int irq, void *dev_id);

#endif /* _TUNER_DRV_H */
/*******************************************************************************
 * Copyright (c) 2015 Socionext Inc.
 ******************************************************************************/
Loading