add and update

This commit is contained in:
pvvx 2016-11-22 07:48:09 +03:00
parent 03ed2886cb
commit bda4d33012
109 changed files with 73065 additions and 85 deletions

View file

@ -581,12 +581,11 @@ void fATSM(void *arg)
}
#endif
extern u8 __HeapLimit, __StackTop;
void fATSt(void *arg)
{
AT_PRINTK("[ATS#]: _AT_SYSTEM_TEST_");
DBG_8195A("\nCLK CPU\t\t%d Hz\nRAM heap\t%d bytes\nRAM stack\t%d bytes\nTCM heap\t%d bytes\n",
HalGetCpuClk(), xPortGetFreeHeapSize(), (int)&__StackTop - (int)&__HeapLimit, tcm_heap_freeSpace());
DBG_8195A("\nCLK CPU\t\t%d Hz\nRAM heap\t%d bytes\nTCM heap\t%d bytes\n",
HalGetCpuClk(), xPortGetFreeHeapSize(), tcm_heap_freeSpace());
dump_mem_block_list();
tcm_heap_dump();
DBG_8195A("\n");
@ -1159,16 +1158,13 @@ void fATSX(void *arg)
void fATST(void *arg){
extern void dump_mem_block_list(void); // heap_5.c
extern u8 __HeapLimit, __StackTop;
extern struct Heap g_tcm_heap;
//DBG_INFO_MSG_ON(_DBG_TCM_HEAP_); // On Debug TCM MEM
#if DEBUG_AT_USER_LEVEL > 1
printf("ATST: Mem info:\n");
#endif
// vPortFree(pvPortMalloc(4)); // Init RAM heap
printf("\nCLK CPU\t\t%d Hz\nRAM heap\t%d bytes\nRAM free\t%d bytes\nTCM heap\t%d bytes\n",
HalGetCpuClk(), xPortGetFreeHeapSize(), (int)&__StackTop - (int)&__HeapLimit, tcm_heap_freeSpace());
printf("TCM ps_monitor\t%d bytes\n", 0x20000000 - (u32)&tcm_heap - tcm_heap_size);
printf("\nCLK CPU\t\t%d Hz\nRAM heap\t%d bytes\nTCM heap\t%d bytes\n",
HalGetCpuClk(), xPortGetFreeHeapSize(), tcm_heap_freeSpace());
dump_mem_block_list();
u32 saved = ConfigDebugInfo;
DBG_INFO_MSG_ON(_DBG_TCM_HEAP_); // On Debug TCM MEM

View file

@ -0,0 +1,149 @@
#include <PinNames.h>
#include <pinmap.h>
#include <gpio_api.h>
#include <wifi_wowlan.h>
#include <freertos_pmu.h>
#include <wifi_conf.h>
#define CONFIG_WOWLAN_DEV_NT96658 //build for Nova NT96658
//#define CONFIG_WOWLAN_DEV_OV788 //build for OmniVision OV788
#if defined(CONFIG_WOWLAN_DEV_NT96658) && defined(CONFIG_WOWLAN_DEV_OV788)
#error "CONFIG_WOWLAN_DEV_NT96658 and CONFIG_WOWLAN_DEV_OV788 are mutually exclusive. "
#endif
#ifdef CONFIG_WOWLAN_DEV_NT96658
#define WOW_WIFI_IN_PIN PE_4 //JTAG pin, so JTAG must be disable before using this pin as wakeup pin
#define WOW_TRIGGER_INTERVAL 500
#elif defined(CONFIG_WOWLAN_DEV_OV788)
#define WOW_WIFI_IN_PIN PD_5
#define WOW_WLAN_ON_PIN PB_3
#define WOW_TRIGGER_INTERVAL 200
#else
#error "Either CONFIG_WOWLAN_DEV_NT96658 or CONFIG_WOWLAN_DEV_OV788 should be defined, but not both. "
#endif
//pin assignment for SDIO, default pull high
#define SD_D2 PA_0
#define SD_D3 PA_1
#define SD_CMD PA_2
#define SD_CLK PA_3
#define SD_D0 PA_4
#define SD_D1 PA_5
#define SD_CD PA_6
gpio_t wow_gpio_wifi_in; //WOWLAN WAKEUP TRIGGER PORT
gpio_t wow_gpio_wlan_on; //RECORD WOWLAN STATUS: 1:OFF, 0:ON
int dev_wowlan_init(void){
WOWLAN_PRINTK("WOWLAN: device init!");
#ifdef CONFIG_WOWLAN_DEV_OV788
// Initial WLAN_ON pin
gpio_init(&wow_gpio_wlan_on, WOW_WLAN_ON_PIN);
gpio_dir(&wow_gpio_wlan_on, PIN_OUTPUT);
gpio_mode(&wow_gpio_wlan_on, PullNone);
gpio_write(&wow_gpio_wlan_on, 1);
#endif
return 0;
}
int dev_wowlan_enable(void){
WOWLAN_PRINTK("WOWLAN: device enable!");
// Init WIFI_IN pin (wakeup pin)
gpio_init(&wow_gpio_wifi_in, WOW_WIFI_IN_PIN);
gpio_dir(&wow_gpio_wifi_in, PIN_OUTPUT);
gpio_mode(&wow_gpio_wifi_in, PullNone);
gpio_write(&wow_gpio_wifi_in, 0);
#ifdef CONFIG_WOWLAN_DEV_OV788
gpio_write(&wow_gpio_wlan_on, 0);
#endif
#if CONFIG_WLAN
wifi_set_power_mode(0xff, 1);
#endif
return 0;
}
int dev_wowlan_wakeup_process(void){
WOWLAN_PRINTK("WOWLAN: device wake up!");
#if defined(CONFIG_WOWLAN_DEV_NT96658) || defined(CONFIG_WOWLAN_DEV_OV788)
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
//acquire wakelock to keep system awake
acquire_wakelock(WAKELOCK_SDIO_DEVICE);
#endif
#endif
#ifdef CONFIG_WOWLAN_DEV_OV788
//record wowlan status
gpio_write(&wow_gpio_wlan_on, 1);
#endif
#if defined(CONFIG_WOWLAN_DEV_NT96658)
//restore SDIO pin status for bus communication
pin_mode(SD_D0, PullUp);
pin_mode(SD_D1, PullUp);
pin_mode(SD_D2, PullUp);
pin_mode(SD_D3, PullUp);
pin_mode(SD_CMD, PullUp);
pin_mode(SD_CLK, PullDown);
#endif
//send signal to awake host
gpio_write(&wow_gpio_wifi_in, 0);
wowlan_mdelay_os(WOW_TRIGGER_INTERVAL);
gpio_write(&wow_gpio_wifi_in, 1);
wowlan_mdelay_os(WOW_TRIGGER_INTERVAL);
gpio_write(&wow_gpio_wifi_in, 0);
wowlan_mdelay_os(WOW_TRIGGER_INTERVAL);
return 0;
}
int dev_wowlan_sleep_process(void){
#if defined(CONFIG_WOWLAN_DEV_NT96658)
//pull control for SDIO pin only when host is already power off
if(rtw_wowlan_is_enabled() && (rtw_wowlan_get_wk_reason() == 0)){
WOWLAN_PRINTK("pull control");
//configure SDIO pin status for avoiding current leakage
pin_mode(SD_D0, PullNone);
pin_mode(SD_D1, PullNone);
pin_mode(SD_D2, PullNone);
pin_mode(SD_D3, PullNone);
pin_mode(SD_CMD, PullNone);
pin_mode(SD_CLK, PullNone);
}
#endif
return 0;
}
int dev_wowlan_disable(void){
WOWLAN_PRINTK("WOWLAN: device disable!");
#if CONFIG_WLAN
wifi_set_power_mode(0xff, 0);
#endif
#ifdef CONFIG_WOWLAN_DEV_OV788
gpio_write(&wow_gpio_wlan_on, 1);
#endif
return 0;
}
void dev_wowlan_ops_init(void *dev_ops){
struct rtw_wowlan_ops *ops = (struct rtw_wowlan_ops *)dev_ops;
WOWLAN_PRINTK("WOWLAN: device ops init!");
ops->DevWowlanInit = dev_wowlan_init;
ops->DevWowlanEnable = dev_wowlan_enable;
ops->DevWowlanDisable = dev_wowlan_disable;
ops->DevWowlanWakeUp = dev_wowlan_wakeup_process;
ops->DevWowlanSleep = dev_wowlan_sleep_process;
}

View file

@ -0,0 +1,381 @@
#ifndef _WIFI_WOWLAN_H_
#define _WIFI_WOWLAN_H_
#include <platform_stdlib.h>
#include <osdep_service.h>
#include <FreeRTOS.h>
#include <timers.h>
#define WOWLAN_DBG 1
enum{
WOWLAN_DBG_OFF = 0,
WOWLAN_DBG_ALWAYS,
WOWLAN_DBG_ERROR,
WOWLAN_DBG_WARNING,
WOWLAN_DBG_INFO
};
#if WOWLAN_DBG
//#define WOWLAN_DUMP_MSG
#define WOWLAN_DUMP_MSG_1 //dump packet when setting
static unsigned char gWowlanDbgLevel = WOWLAN_DBG_ERROR;
#define WOWLAN_PRINTK(fmt, args...) printf(fmt"\r\n",## args)
#define _WOWLAN_PRINTK(fmt, args...) printf(fmt,## args)
#define WOWLAN_DBG_MSG(level, fmt, args...) \
do{ \
if(level <= gWowlanDbgLevel){ \
WOWLAN_PRINTK(fmt,## args); \
} \
}while(0)
#else
#define WOWLAN_PRINTK(fmt, args...)
#define WOWLAN_DBG_MSG(level, fmt, args...)
#endif
#ifndef u8
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
#endif
#ifndef BIT
#define BIT(x) ((u32)1 << (x))
#endif
#ifndef le16_to_cpu //need a general definition for the whole system
#define cpu_to_le32(x) ((u32)(x))
#define le32_to_cpu(x) ((u32)(x))
#define cpu_to_le16(x) ((u16)(x))
#define le16_to_cpu(x) ((u16)(x))
#endif
#ifndef IP_FMT
#define IP_FMT "%d.%d.%d.%d"
#endif
#ifndef IP_ARG
#define IP_ARG(x) ((u8*)(x))[0],((u8*)(x))[1],((u8*)(x))[2],((u8*)(x))[3]
#endif
#ifndef MAC_FMT
#define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
#endif
#ifndef MAC_ARG
#define MAC_ARG(x) ((u8*)(x))[0],((u8*)(x))[1],((u8*)(x))[2],((u8*)(x))[3],((u8*)(x))[4],((u8*)(x))[5]
#endif
#ifndef ETH_ALEN
#define ETH_ALEN 6
#endif
#ifndef ethhdr
struct ethhdr
{
unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
unsigned char h_source[ETH_ALEN]; /* source ether addr */
unsigned short h_proto; /* packet type ID field */
};
#endif
#ifndef wowlan_memcpy
#define wowlan_memcpy(d, s, n) rtw_memcpy((void*)(d), ((void*)(s)), (n))
#endif
#ifndef wowlan_malloc
#define wowlan_malloc(sz) rtw_malloc(sz)
#endif
#ifndef wowlan_zmalloc
#define wowlan_zmalloc(sz) rtw_zmalloc(sz)
#endif
#ifndef wowlan_memset
#define wowlan_memset(pbuf, c, sz) rtw_memset(pbuf, c, sz)
#endif
#ifndef wowlan_mfree
#define wowlan_mfree(p, sz) rtw_mfree(((u8*)(p)), (sz))
#endif
#ifndef wowlan_memcmp
#define wowlan_memcmp(s1, s2, n) rtw_memcmp(((void*)(s1)), ((void*)(s2)), (n))
#endif
#ifndef wowlan_mdelay_os
#define wowlan_mdelay_os(ms) rtw_mdelay_os(ms)
#endif
/*Mutex services*/
typedef _mutex _wowlock;
__inline static void _init_wowlock(_wowlock *plock)
{
rtw_mutex_init(plock);
}
__inline static void _free_wowlock(_wowlock *plock)
{
rtw_mutex_free(plock);
}
__inline static void _enter_wowlock(_wowlock *plock)
{
rtw_mutex_get(plock);
}
__inline static void _exit_wowlock(_wowlock *plock)
{
rtw_mutex_put(plock);
}
/*Timer services*/
typedef TimerHandle_t _wowTimer;
#define TMR_AUTO_RELOAD_EN _TRUE
#define TMR_AUTO_RELOAD_DIS _FALSE
__inline static void
_wowlan_init_timer(_wowTimer *ptimer, void *adapter, TIMER_FUN pfunc,void* cntx, const char *name, u32 auto_reload)
{
*ptimer = rtw_timerCreate(
(signed const char *)name, // Just a text name, not used by the RTOS kernel.
TIMER_MAX_DELAY, // Timer Period, not 0
auto_reload, // Whether timer will auto-load themselves when expires
cntx, // Uniq id used to identify which timer expire..
pfunc // Timer callback
);
}
__inline static void
_wowlan_set_timer(_wowTimer *ptimer, u32 delay_time_ms)
{
if(rtw_timerChangePeriod(*ptimer, rtw_ms_to_systime(delay_time_ms), TIMER_MAX_DELAY) == _FAIL)
WOWLAN_PRINTK("Fail to set timer period");
}
__inline static void
_wowlan_cancel_timer(_wowTimer *ptimer)
{
rtw_timerStop(*ptimer, TIMER_MAX_DELAY);
}
__inline static void
_wowlan_del_timer(_wowTimer *ptimer)
{
rtw_timerDelete(*ptimer, TIMER_MAX_DELAY);
}
__inline static void *
_wowlan_get_timer_cntx(_wowTimer timer)
{
return pvTimerGetTimerID(timer);
}
enum rtw_wowlan_wakeup_reason {
RTW_WOWLAN_WAKEUP_BY_PATTERN = BIT(0),
RTW_WOWLAN_WAKEUP_BY_DISCONNECTION = BIT(1),
RTW_WOWLAN_WAKEUP_MAX = 0x7FFFFFFF
};
enum rtw_wowlan_cmd_id{
RTW_WOWLAN_CMD_ENABLE = 0x01, // enable wowlan service
RTW_WOWLAN_CMD_PATTERNS = 0x02, // wowlan pattern setting
RTW_WOWLAN_CMD_PROT_OFFLOAD_CONFIG = 0x03, //ARP offload setting
RTW_WOWLAN_CMD_GET_STATUS = 0x04, // get rtw_wowlan_status
RTW_WOWLAN_CMD_CLEAR_ALL = 0x05, //clear wowlan content
RTW_WOWLAN_CMD_KEEPALIVE = 0x06, //for keep alive packet setting
RTW_WOWLAN_CMD_MAX = 0xff
};
#define RTW_WOWLAN_MAX_RX_FILTERS (5)
#define RTW_WOWLAN_RX_FILTER_MAX_FIELDS (8)
#define RTW_WOWLAN_ID_OFFSET (100) //to match some application, ID starts from 100
#define RTW_WOWLAN_MIN_FILTERS_ID (RTW_WOWLAN_ID_OFFSET)
#define RTW_WOWLAN_MAX_FILTERS_ID (RTW_WOWLAN_ID_OFFSET+RTW_WOWLAN_MAX_RX_FILTERS-1)
struct rtw_wowlan_rx_filter_field {
u16 offset;
u8 len;
u8 flags;
u8 *mask;
u8 *pattern;
};
struct rtw_wowlan_rx_filter {
u8 action;
u8 offset;
u8 num_fields;
struct rtw_wowlan_rx_filter_field fields[RTW_WOWLAN_RX_FILTER_MAX_FIELDS];
};
#if defined(__IAR_SYSTEMS_ICC__)
#pragma pack(1)
#else
#error "this structure needs to be packed!"
#endif
struct rtw_wowlan_status {
u32 wakeup_reasons; //record wake up reason
u32 filter_id; //record which pattern is matched
};
#if defined(__IAR_SYSTEMS_ICC__)
#pragma pack()
#else
#error "this structure needs to be packed!"
#endif
/**
* struct rtw_wowlan_keepalive_packet
*
* @payload_len: data payload length
* @payload: data payload buffer
* @data_interval: interval at which to send data packets
**/
#define RTW_WOWLAN_MAX_KPALIVE_PKT 3
#define RTW_WOWLAN_MAX_KPALIVE_PKT_SZ 512
struct rtw_wowlan_keepalive_packet{
u8 packet_id;
int payload_len;
u8 *payload;
u32 data_interval;
_wowTimer keepalive_tmr;
};
struct rtw_wowlan_ops {
int (*DevWowlanInit)(void);
int (*DevWowlanEnable)(void);
int (*DevWowlanDisable)(void);
int (*DevWowlanWakeUp)(void);
int (*DevWowlanSleep)(void);
};
/**
* enum rtw_wowlan_proto_offloads - enabled protocol offloads
* @RTW_WOWLAN_PROTO_OFFLOAD_ARP: ARP data is enabled
*/
enum rtw_wowlan_proto_offloads {
RTW_WOWLAN_PROTO_OFFLOAD_ARP = BIT(0),
RTW_WOWLAN_PROTO_OFFLOAD_MAX = 0x7FFFFFFF
};
/**
* struct rtw_wowlan_proto_offload_common - ARP/NS offload common part
* @enabled: enable flags
* @remote_ipv4_addr: remote address to answer to (or zero if all)
* @host_ipv4_addr: our IPv4 address to respond to queries for
* @arp_mac_addr: our MAC address for ARP responses
* @reserved: unused
*/
struct rtw_wowlan_proto_offload_common{
int proto_enabled;
u32 remote_ipv4_addr;
u32 host_ipv4_addr;
u8 host_mac_addr[ETH_ALEN];
u16 reserved;
};
struct rtw_wowlan {
_wowlock wow_mutex;
bool enabled;
struct rtw_wowlan_status status;
struct rtw_wowlan_ops ops;
struct rtw_wowlan_proto_offload_common proto;
bool proto_offload_enabled;
struct rtw_wowlan_rx_filter *rx_filter[RTW_WOWLAN_MAX_RX_FILTERS];
bool rx_filter_enabled[RTW_WOWLAN_MAX_RX_FILTERS];/* RX Data filter rule state - enabled/disabled */
struct rtw_wowlan_keepalive_packet *tx_keepalive[RTW_WOWLAN_MAX_KPALIVE_PKT];
bool tx_keepalive_enabled[RTW_WOWLAN_MAX_KPALIVE_PKT];/* TX keep avlive rule state - enabled/disabled */
};
#define eqMacAddr(a,b) ( ((a)[0]==(b)[0] && (a)[1]==(b)[1] && (a)[2]==(b)[2] && (a)[3]==(b)[3] && (a)[4]==(b)[4] && (a)[5]==(b)[5]) ? 1:0 )
#define cpMacAddr(des,src) ((des)[0]=(src)[0],(des)[1]=(src)[1],(des)[2]=(src)[2],(des)[3]=(src)[3],(des)[4]=(src)[4],(des)[5]=(src)[5])
#define cpIpAddr(des,src) ((des)[0]=(src)[0],(des)[1]=(src)[1],(des)[2]=(src)[2],(des)[3]=(src)[3])
#define RTW_WOWLAN_GET_ARP_PKT_OPERATION(__pHeader) ReadEF2Byte( ((u8*)(__pHeader)) + 6)
#define RTW_WOWLAN_GET_ARP_PKT_SENDER_MAC_ADDR(__pHeader, _val) cpMacAddr((u8*)(_val), ((u8*)(__pHeader))+8)
#define RTW_WOWLAN_GET_ARP_PKT_SENDER_IP_ADDR(__pHeader, _val) cpIpAddr((u8*)(_val), ((u8*)(__pHeader))+14)
#define RTW_WOWLAN_GET_ARP_PKT_TARGET_MAC_ADDR(__pHeader, _val) cpMacAddr((u8*)(_val), ((u8*)(__pHeader))+18)
#define RTW_WOWLAN_GET_ARP_PKT_TARGET_IP_ADDR(__pHeader, _val) cpIpAddr((u8*)(_val), ((u8*)(__pHeader))+24)
#define RTW_WOWLAN_SET_ARP_PKT_HW(__pHeader, __Value) WriteEF2Byte( ((u8*)(__pHeader)) + 0, __Value)
#define RTW_WOWLAN_SET_ARP_PKT_PROTOCOL(__pHeader, __Value) WriteEF2Byte( ((u8*)(__pHeader)) + 2, __Value)
#define RTW_WOWLAN_SET_ARP_PKT_HW_ADDR_LEN(__pHeader, __Value) WriteEF1Byte( ((u8*)(__pHeader)) + 4, __Value)
#define RTW_WOWLAN_SET_ARP_PKT_PROTOCOL_ADDR_LEN(__pHeader, __Value) WriteEF1Byte( ((u8*)(__pHeader)) + 5, __Value)
#define RTW_WOWLAN_SET_ARP_PKT_OPERATION(__pHeader, __Value) WriteEF2Byte( ((u8*)(__pHeader)) + 6, __Value)
#define RTW_WOWLAN_SET_ARP_PKT_SENDER_MAC_ADDR(__pHeader, _val) cpMacAddr(((u8*)(__pHeader))+8, (u8*)(_val))
#define RTW_WOWLAN_SET_ARP_PKT_SENDER_IP_ADDR(__pHeader, _val) cpIpAddr(((u8*)(__pHeader))+14, (u8*)(_val))
#define RTW_WOWLAN_SET_ARP_PKT_TARGET_MAC_ADDR(__pHeader, _val) cpMacAddr(((u8*)(__pHeader))+18, (u8*)(_val))
#define RTW_WOWLAN_SET_ARP_PKT_TARGET_IP_ADDR(__pHeader, _val) cpIpAddr(((u8*)(__pHeader))+24, (u8*)(_val))
#define RTW_WOWLAN_ARP_PKT_LEN 0x2A
#define RTW_WOWLAN_ARP_PKT_OPERATION_REQ 0x0100 //arp request
#define RTW_WOWLAN_ARP_PKT_OPERATION_RSP 0x0200 //arp response
extern u8 key_2char2num(u8 hch, u8 lch);
extern _LONG_CALL_ void __rtl_memDump_v1_00(const u8 *start, u32 size, char * strHeader);
#define rtw_wowlan_DumpForBytes(pData, Len) __rtl_memDump_v1_00(pData, Len, NULL)
#define PWOWLAN_TO_STATUS(pwowlan) (&pwowlan->status)
#define PWOWLAN_TO_OPS(pwowlan) (&pwowlan->ops)
#define PWOWLAN_TO_PROTO(pwowlan) (&pwowlan->proto)
#define PWOWLAN_TO_RX_FILTER(pwowlan) (pwowlan->rx_filter)
#define PWOWLAN_TO_TX_KEEPALIVE(pwowlan) (pwowlan->tx_keepalive)
/**
* rtw_wowlan_init: initialize wowlan service
* arg: None
* return: _SUCCESS or _FAIL
*/
extern int rtw_wowlan_init(void);
/**
* cmd_wowlan_service: input commands to configure wowlan service
* arg:
* @argc: number of input parameter
* @argv: content of input string
* return: None
*/
extern void cmd_wowlan_service(int argc, char **argv);
/**
* rtw_wowlan_process_rx_packet: entry for packet process in wowlan service once it starts
* arg:
* @rx_pkt: receive packet from wlan/ethernet
* @pkt_len: receive packet length
* return: _SUCCESS or _FAIL
*/
extern int rtw_wowlan_process_rx_packet(char *rx_pkt, u16 pkt_len);
/**
* rtw_wowlan_wakeup_process: wake up process once the reasons are matched,
* refer to enum rtw_wowlan_wakeup_reason
* arg:
* @reason: wake up reason, refer to enum rtw_wowlan_wakeup_reason
* return: None
*/
extern void rtw_wowlan_wakeup_process(int reason);
/**
* rtw_wowlan_is_enabled: if wowlan service is already enabled
* this function is called in rx path and wifi_inidication when wowlan service is running
* arg: None
* return: _True if enable or _False if disable
*/
extern int rtw_wowlan_is_enabled(void);
/**
* rtw_wowlan_get_wk_reason: query wake up reason, refer to enum rtw_wowlan_wakeup_reason
* arg: None
* return: wakeup_reason
*/
extern int rtw_wowlan_get_wk_reason(void);
/**
* rtw_wowlan_dev_sleep: sleep process on Ameba side, pull control for example
* this function is linked to dev_wowlan_sleep_process() in dev_wowlan.c
* arg: None
* return: None
*/
extern void rtw_wowlan_dev_sleep(void);
#endif

View file

@ -178,9 +178,9 @@ typedef struct net_device
extern struct net_device *rltk_wlan_info;
void patch_rltk_wlan_deinit(void)
{
struct net_device *v0; // r6@1
int v1; // r5@2
char *v4; // r7@3
struct net_device *v0;
int v1;
char *v4;
v0 = rltk_wlan_info;
@ -998,7 +998,7 @@ int wifi_rf_off(void)
//----------------------------------------------------------------------------//
int wifi_on(rtw_mode_t mode)
{
int ret = 1;
int ret = 0;
//pvvx int timeout = 20; // 20 sec ??!!
int timeout = wifi_test_timeout_ms/wifi_test_timeout_step_ms;
int idx;
@ -1007,7 +1007,7 @@ int wifi_on(rtw_mode_t mode)
if(rltk_wlan_running(WLAN0_IDX)) {
printf("WIFI is already running\n");
return 1;
return 0;
}
if(event_init == 0){
@ -1061,7 +1061,7 @@ int wifi_on(rtw_mode_t mode)
int wifi_off(void)
{
int ret = 0;
// int ret = 0;
//pvvx int timeout = 20; // 20 sec ??!!
int timeout = wifi_test_timeout_ms/10;
@ -1105,7 +1105,7 @@ int wifi_off(void)
inic_stop();
#endif
return ret;
return 1;
}
int wifi_set_power_mode(unsigned char ips_mode, unsigned char lps_mode)

View file

@ -0,0 +1,675 @@
/*******************************example_joinlink **************************/
#include "autoconf.h"
#include "platform_stdlib.h"
#include "wifi_conf.h"
#include "wifi_structures.h"
#include "osdep_service.h"
#include "lwip_netconf.h"
#include "task.h"
#include "joinlink.h"
#include "cJSON.h"
#include <lwip/sockets.h>
#include <lwip/raw.h>
#include <lwip/icmp.h>
#include <lwip/inet_chksum.h>
#include <platform/platform_stdlib.h>
#define MASK_SIZE_JOINLINK 3
#define SOURCE_PORT 101
//gloable
static unsigned char cur_channel = 1;
static unsigned char lock_channel = 1;
static _timer timer_handler_phase2;
static _timer timer_handler_phase1;
static u8 joinlink_finished = 0;
static u8 security_type = 0xff;
static u8 jl_rx_flag = 0;
static rtw_scan_result_t *all_channel_scan_result = NULL;
static rtw_scan_result_t *p_result = NULL;
static int all_channel_ret = 0;
static int phase1_finished = 0;
static int phase2_started = 0;
static u32 start_time = 0;
static u32 current_time = 0;
static int idx = 1;
static int phase1_scanned_channel[14];
static char ap_bssid[6];
static char aes_key[] = "123456789";
static void* pre_scan_sema;
static int ack_socket;
static struct sockaddr_in to_addr;
static struct sockaddr_in from_addr;
static char header_cmd[] = "cmd";
static cJSON *ack_content = NULL;
extern struct netif xnetif[];
void example_joinlink(void);
static rtw_result_t joinlink_scan_result_handler(rtw_scan_handler_result_t* malloced_scan_result )
{
static int ApNum = 0;
//TODO: add timer of 2s, wf, 1021
if (malloced_scan_result->scan_complete != RTW_TRUE) {
rtw_scan_result_t* record = &malloced_scan_result->ap_details;
record->SSID.val[record->SSID.len] = 0; /* Ensure the SSID is null terminated */
++ApNum;
if(malloced_scan_result->user_data)
memcpy((void *)((char *)malloced_scan_result->user_data+(ApNum-1)*sizeof(rtw_scan_result_t)), (char *)record, sizeof(rtw_scan_result_t));
}
// scan finished, wf, 1022
else
{
rtw_up_sema(&pre_scan_sema);
ApNum = 0;
}
return RTW_SUCCESS;
}
void* joinlink_all_scan()
{
int ret = 0;
rtw_scan_result_t *joinlink_scan_buf = NULL;
if(joinlink_scan_buf != NULL)
free(joinlink_scan_buf);
joinlink_scan_buf = (rtw_scan_result_t *)malloc(65*sizeof(rtw_scan_result_t));
if(joinlink_scan_buf == NULL){
return 0;
}
memset(joinlink_scan_buf, 0, 65*sizeof(rtw_scan_result_t));
if((ret = wifi_scan_networks(joinlink_scan_result_handler, joinlink_scan_buf)) != RTW_SUCCESS){
printf("[ATWS]ERROR: wifi scan failed\n\r");
free(joinlink_scan_buf);
return 0;
}
return joinlink_scan_buf;
}
void joinlink_deinit_content()
{
rtw_del_timer(&timer_handler_phase2);
rtw_del_timer(&timer_handler_phase1);
if(all_channel_scan_result)
{
free(all_channel_scan_result);
all_channel_scan_result = NULL;
}
rtw_free_sema(&pre_scan_sema);
joinlink_deinit();
return;
}
static char *jl_itoa(int value)
{
char *val_str;
int tmp = value, len = 1;
while((tmp /= 10) > 0)
len ++;
val_str = (char *) malloc(len + 1);
sprintf(val_str, "%d", value);
return val_str;
}
static void get_ip_str(int *ip_int, char *ip_ch)
{
char *ip_single = NULL;
u8 pos = 0, len = 0;
for(int i = 0; i < 4; i++)
{
ip_single = jl_itoa(ip_int[i]);
len = strlen(ip_single);
memcpy(ip_ch + pos, ip_single,len);
free(ip_single);
ip_single = NULL;
pos += len;
if(i == 3)
{
*(ip_ch + pos) = 0;
break;
}
*(ip_ch + pos) = '.';
pos++;
}
}
static int joinlink_set_ack_content(u8 check_sum)
{
cJSON_Hooks memoryHook;
memoryHook.malloc_fn = malloc;
memoryHook.free_fn = free;
cJSON_InitHooks(&memoryHook);
if(ack_content != NULL)
{
cJSON_Delete(ack_content);
ack_content = NULL;
}
if((ack_content = cJSON_CreateObject()) != NULL)
{
char mac_str[18];
u8 pos = 0;
memset(mac_str, 0, sizeof(mac_str));
for(int i = 0; i < 6; i++)
{
sprintf(mac_str + pos, "%02x", xnetif[0].hwaddr[i]);
pos += 2;
if(i != 5)
mac_str[pos++] = ':';
}
cJSON_AddItemToObject(ack_content, "deviceid", cJSON_CreateString(mac_str));
cJSON_AddItemToObject(ack_content, "code", cJSON_CreateNumber(check_sum));
}
else
{
printf("create jSON object failure\n");
return -1;
}
return 0;
}
#if 1
static void recv_cmd(void *para)
{
int rev_len = 0;
char pkt_buf[16];
while(1)
{
vTaskDelay(500);
if((rev_len = recvfrom(ack_socket, pkt_buf, sizeof(pkt_buf), 0, NULL, NULL)) >= 0)
{
if(memcmp(pkt_buf, header_cmd, sizeof(header_cmd)) == 0)
{
printf("received reboot command, restart join_link process\n");
// do we need to reboot?
example_joinlink();
close(ack_socket);
break;
}
}
}
vTaskDelete(NULL);
return;
}
static int send_ack(int *dest_ip, int dest_port, u8 sum)
{
#if CONFIG_LWIP_LAYER
int ack_transmit_round;
char ip[16];
char *jsonString = NULL;
int sended_data = 0;
if(joinlink_set_ack_content(sum) == -1)
return -1;
jsonString = cJSON_Print(ack_content);
if(jsonString == NULL)
{
printf("json string convert failure\n");
cJSON_Delete(ack_content);
return -1;
}
get_ip_str(dest_ip, ip);
ack_socket = socket(PF_INET, SOCK_DGRAM, IP_PROTO_UDP);
if (ack_socket == -1) {
printf("create socket failure\n");
return -1;
}
FD_ZERO(&to_addr);
to_addr.sin_family = AF_INET;
to_addr.sin_port = htons(dest_port);
to_addr.sin_addr.s_addr = htonl(INADDR_ANY);
FD_ZERO(&from_addr);
from_addr.sin_family = AF_INET;
from_addr.sin_port = htons(SOURCE_PORT);
to_addr.sin_addr.s_addr = inet_addr(ip);
if(bind(ack_socket, (struct sockaddr *)&from_addr, sizeof(from_addr)) < 0)
{
printf("bind to source port error\n");
return -1;
}
for (ack_transmit_round = 0; ack_transmit_round < 5; ack_transmit_round++) {
sended_data = sendto(ack_socket, (unsigned char *)jsonString, strlen(jsonString), 0, (struct sockaddr *) &to_addr, sizeof(struct sockaddr));
//printf("\r\nAlready send %d bytes data\n", sended_data);
vTaskDelay(100); /* delay 100 ms */
}
if(xTaskCreate(recv_cmd, (char const *)"recv_cmd", 1512, NULL, tskIDLE_PRIORITY + 2, NULL) != pdPASS)
printf("%s xTaskCreate failed\n", __FUNCTION__);
close(ack_socket);
if(jsonString)
{
free(jsonString);
jsonString = NULL;
}
cJSON_Delete(ack_content);
#endif
return 0;
}
#endif
static void remove_filter()
{
wifi_disable_packet_filter(1);
wifi_disable_packet_filter(2);
wifi_remove_packet_filter(1);
wifi_remove_packet_filter(2);
}
int joinlink_finish(unsigned char security_type)
{
int ret = 0;
int retry = 3;
unsigned char pscan_config = 1;
joinlink_result_t result;
rtw_security_t security_mode;
wifi_set_promisc(RTW_PROMISC_DISABLE,NULL,0);
remove_filter();
pscan_config = PSCAN_ENABLE | PSCAN_SIMPLE_CONFIG;
ret = joinlink_get_result(&result);
if (ret == 0) {
printf("get result OK\n");
//printf("\r\n joinlink get result ok,ssid = %s, pwd = %s,ssid length = %d,pwd length = %d",
// result.ssid, result.pwd, result.ssid_length,result.pwd_length);
}
else{
printf("joinlink result not get!\n");
joinlink_deinit_content();
return -1;
}
//ap security type
switch(security_type){
case RTW_ENCRYPTION_OPEN:
security_mode = RTW_SECURITY_OPEN;
break;
case RTW_ENCRYPTION_WEP40:
case RTW_ENCRYPTION_WEP104:
security_mode = RTW_SECURITY_WEP_PSK;
break;
case RTW_ENCRYPTION_WPA_TKIP:
case RTW_ENCRYPTION_WPA_AES:
case RTW_ENCRYPTION_WPA2_TKIP:
case RTW_ENCRYPTION_WPA2_AES:
case RTW_ENCRYPTION_WPA2_MIXED:
security_mode = RTW_SECURITY_WPA2_AES_PSK;
break;
case RTW_ENCRYPTION_UNKNOWN:
case RTW_ENCRYPTION_UNDEF:
default:
printf("unknow security mode,connect fail!\n");
}
#if 1
while(1){
if(wifi_set_pscan_chan(&lock_channel, &pscan_config, 1) < 0){
printf("ERROR: wifi set partial scan channel fail\n");
break;
}
printf("wifi_connect\n");
//printf("ap_bssid: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n", ap_bssid[0],ap_bssid[1],ap_bssid[2],ap_bssid[3],ap_bssid[4],ap_bssid[5]);
ret = wifi_connect((unsigned char *)result.ssid, security_mode,
(unsigned char *)result.pwd, result.ssid_length,
result.pwd_length,
0,NULL);
if(ret == RTW_SUCCESS){
printf("Connect ok!\n");
#if CONFIG_LWIP_LAYER
/* If not rise priority, LwIP DHCP may timeout */
vTaskPrioritySet(NULL, tskIDLE_PRIORITY + 3);
/* Start DHCP Client */
ret = LwIP_DHCP(0, DHCP_START);
vTaskPrioritySet(NULL, tskIDLE_PRIORITY + 1);
#endif
break;
}
if (retry == 0) {
break;
}
retry--;
}
if(send_ack(result.source_ip, result.source_port, result.sum) != 0)
printf("send ack failure\n");
#endif
joinlink_deinit_content();
return 0;
}
// handler for phase2
void timer_handler_phase2_func(void *FunctionContext)
{
// do not switch channel while handle frames, wf, 1021
if(jl_rx_flag){
rtw_set_timer(&timer_handler_phase2, CHANNEL_SWITCH_TIME - 25);
} else {
if(cur_channel >= 13)
{cur_channel = 1;}
else
cur_channel ++;
wifi_set_channel(cur_channel);
rtw_set_timer(&timer_handler_phase2, CHANNEL_SWITCH_TIME);
}
//printf("phase2:wifi switch channel to %d\n",cur_channel);
return;
}
// timer handler for the 1st phase, wf, 1022
void timer_handler_phase1_func(void *FunctionContext)
{
// do not switch channel while handle frames, wf, 1021
if(jl_rx_flag){
rtw_set_timer(&timer_handler_phase1, SSID_SWITCH_TIME - 25);
}
// switch ssid, wf, 1022
else
{
if(idx >= 14)
{
phase1_finished = 1;
printf("wifi: phase1 scan finished\n");
printf("wifi: start phase2 scan\n");
// move from pkt handler to here in case no pkt to trigue phase2
#if 1
if(phase1_finished)
{
phase1_finished = 0;
phase2_started = 1;
rtw_cancel_timer(&timer_handler_phase1);
//start phase2 for ch1~ch13
cur_channel = 1;
wifi_set_channel(cur_channel);
rtw_init_timer(&timer_handler_phase2, NULL, &timer_handler_phase2_func, NULL, "phase_2");
rtw_set_timer(&timer_handler_phase2, CHANNEL_SWITCH_TIME);
}
#endif
return;
}
while(idx < 14)
{
if(phase1_scanned_channel[idx])
{
wifi_set_channel(idx);
rtw_set_timer(&timer_handler_phase1, SSID_SWITCH_TIME);
//printf("phase1: wifi switch channel to %d\n",idx);
idx++;
break;
}
else
{
if(idx == 13)
rtw_set_timer(&timer_handler_phase1, SSID_SWITCH_TIME);
idx++;
}
}
}
return;
}
static void rtl_frame_recv_handle(unsigned char *buf, int len, unsigned char *da, unsigned char *sa, void *user_data) {
int ret = 0;
int fixed_channel;
char scanned_ssid[50] = {0};
unsigned char *current_bssid = NULL;
int scanned_ssid_len = 0;
//set this flag prevent joinlink_recv interruptted by timer,since timer has higher priority
jl_rx_flag = 1;
if (joinlink_finished) {
jl_rx_flag = 0;
return;
}
ret = joinlink_recv(da, sa, len, user_data);
if(ret == JOINLINK_STATUS_CHANNEL_LOCKED)
{
if(phase2_started)
{
phase2_started = 0;
rtw_cancel_timer(&timer_handler_phase2);
}
else
rtw_cancel_timer(&timer_handler_phase1);
lock_channel = cur_channel;
security_type = ((ieee80211_frame_info_t *)user_data)->encrypt;
printf("JoinLink locked to channel[%d]\n",lock_channel);
current_bssid = buf + 4 + ETH_ALEN;
memcpy(ap_bssid, current_bssid, 6);
fixed_channel = promisc_get_fixed_channel(current_bssid, scanned_ssid, &scanned_ssid_len);
if (fixed_channel != 0) {
printf("JoinLink force fixed to channel[%d]\r\n",fixed_channel);
printf("JoinLink ssid scanned[%s]\r\n",scanned_ssid);
wifi_set_channel(fixed_channel);
}
}
else if(ret == JOINLINK_STATUS_COMPLETE){
//wifi_set_promisc(RTW_PROMISC_DISABLE,NULL,0);
joinlink_finished = 1;
printf("quit promisc mode!\r\n");
}
//release flag
jl_rx_flag = 0;
return;
}
// callback for promisc packets, like rtk_start_parse_packet in SC, wf, 1021
void wifi_promisc_rx(unsigned char* buf, unsigned int len, void* user_data)
{
unsigned char * da = buf;
unsigned char * sa = buf + ETH_ALEN;
if (joinlink_finished)
return;
rtl_frame_recv_handle(buf, len, da, sa, user_data);
return;
}
// the entry point for joinlink
void joinlink_process(void *param)
{
while(1)
{
current_time = xTaskGetTickCount();
if(joinlink_finished)
{
printf("joinlink finished\n");
break;
}
if((current_time - start_time) > JOINLINK_TIME * configTICK_RATE_HZ)
{
printf("joinlink timeout\n");
break;
}
vTaskDelay(500);
}
joinlink_finish(security_type);
vTaskDelete(NULL);
return;
}
int joinlink_init_content()
{
int ret = 0;
ret = joinlink_init();
if(ret < 0){
printf("JoinLink init failed!\n");
return ret;
}
memset(phase1_scanned_channel, 0, sizeof(phase1_scanned_channel));
security_type = 0xff;
cur_channel = 1;
lock_channel = 1;
joinlink_finished = 0;
jl_rx_flag = 0;
p_result = NULL;
all_channel_ret = 0;
phase1_finished = 0;
phase2_started = 0;
idx = 1;
rtw_init_sema(&pre_scan_sema, 0);
memset(ap_bssid, 0, sizeof(ap_bssid));
set_aes_key(aes_key, sizeof(aes_key) - 1);
return 0;
}
// ret:1 indicate suc, else fail
int scan_all_channel()
{
all_channel_scan_result = (rtw_scan_result_t *)joinlink_all_scan();
if(all_channel_scan_result == NULL)
return 0;
else
return 1;
}
void get_phase1_channel()
{
p_result = all_channel_scan_result;
while(p_result->channel)
{
if((p_result->channel >= 1) && (p_result->channel <= 13))
phase1_scanned_channel[p_result->channel] = 1;
p_result++;
}
return;
}
// now only accept mcast and bcast pkt
static void filter_add_enable()
{
u8 mask[MASK_SIZE_JOINLINK]={0xFF,0xFF,0xFF};
u8 pattern[MASK_SIZE_JOINLINK]={0x01,0x00,0x5e};
u8 pattern_bcast[MASK_SIZE_JOINLINK]={0xff,0xff,0xff};
rtw_packet_filter_pattern_t packet_filter;
rtw_packet_filter_pattern_t packet_filter_bcast;
rtw_packet_filter_rule_e rule;
packet_filter.offset = 0;
packet_filter.mask_size = 3;
packet_filter.mask = mask;
packet_filter.pattern = pattern;
packet_filter_bcast.offset = 0;
packet_filter_bcast.mask_size = 3;
packet_filter_bcast.mask = mask;
packet_filter_bcast.pattern = pattern_bcast;
rule = RTW_POSITIVE_MATCHING;
wifi_init_packet_filter();
wifi_add_packet_filter(1, &packet_filter,rule);
wifi_add_packet_filter(2, &packet_filter_bcast,rule);
wifi_enable_packet_filter(1);
wifi_enable_packet_filter(2);
}
void joinlink_start(void *param)
{
joinlink_finished = 0;
start_time = xTaskGetTickCount();
if(xTaskCreate(joinlink_process, (char const *)"JoinLink", 1512, NULL, tskIDLE_PRIORITY + 2, NULL) != pdPASS)
printf("%s xTaskCreate failed\n", __FUNCTION__);
if (joinlink_init_content() < 0)
printf("joinlink init fail!\n");
while(1)
{
if(wifi_is_ready_to_transceive(RTW_STA_INTERFACE) == RTW_SUCCESS)
break;
else
vTaskDelay(3000);
}
all_channel_ret = scan_all_channel();
if (rtw_down_sema(&pre_scan_sema) == _FAIL)
printf("%s, Take Semaphore Fail\n", __FUNCTION__);
//printf("\npre scan finished\n");
//set wifi to station mode,enable promisc mode and timer to change channel
wifi_enter_promisc_mode();
filter_add_enable();
/* enable all 802.11 packets*/
wifi_set_promisc(RTW_PROMISC_ENABLE, wifi_promisc_rx, 1);
//init timer handler,and set timer hanler funcion
if(all_channel_ret)
{
printf("\nstart the phase1 scan\n");
get_phase1_channel();
rtw_init_timer(&timer_handler_phase1, NULL, &timer_handler_phase1_func, NULL, "phase1_timer");
rtw_set_timer(&timer_handler_phase1, SSID_SWITCH_TIME);
}
else
{
printf("phase1 scan fail, start phase2 scan\n");
rtw_init_timer(&timer_handler_phase2, NULL, &timer_handler_phase2_func, NULL, "phase2_timer");
wifi_set_channel(cur_channel);
rtw_set_timer(&timer_handler_phase2, CHANNEL_SWITCH_TIME);
}
vTaskDelete(NULL);
return;
}
void example_joinlink(void)
{
if(xTaskCreate(joinlink_start, (char const *)"JoinLink_entry", 1512, NULL, tskIDLE_PRIORITY + 2, NULL) != pdPASS)
printf("%s xTaskCreate failed\n", __FUNCTION__);
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,64 @@
/******************************* joinlink **************************/
#ifndef __JOINLINK_H
#define __JOINLINK_H
#include "autoconf.h"
#include "platform_stdlib.h"
#include "wifi_conf.h"
#include "wifi_structures.h"
#include "osdep_service.h"
#include "lwip_netconf.h"
#include "task.h"
#include "hal_crypto.h"
#define SSID_SWITCH_TIME 500 //ssid switch time in phase1,units:ms, 50
#define CHANNEL_SWITCH_TIME 500 //channel switch time in phase2,units:ms, 50
#define JOINLINK_TIME 120 //timeout for joinlink process, units: s
/*
* store AP profile after successfully decode
* SUM +£¨length£¬pass£©+£¨IP+Port£©+£¨length£¬SSID)
*/
typedef struct
{
unsigned char sum;
unsigned char pwd_length;
char pwd[65];
int source_ip[4];
unsigned int source_port;
unsigned char ssid_length;
char ssid[65];
} joinlink_result_t;
/*
* return value of joinlink_recv()
*/
typedef enum
{
JOINLINK_STATUS_CONTINUE = 0,
JOINLINK_STATUS_CHANNEL_LOCKED = 1,
JOINLINK_STATUS_COMPLETE = 2
} joinlink_status_t;
//initialize the related data structure
int joinlink_init();
/*
handler to decode pkt
*/
joinlink_status_t joinlink_recv(unsigned char *da, unsigned char *sa, int len, void *user_data);
/*
* get the AP profile after decode
*/
int joinlink_get_result(joinlink_result_t *result);
/*
* set the aes_key, the max len should be 16
* ret 1: success; ret 0: the len is invalid;
*/
int set_aes_key(char *key, int len);
// call this after finish join_link process
void joinlink_deinit();
#endif //__JOINLINK_H

View file

@ -0,0 +1,24 @@
#ifndef _G711_CODEC_H
#define _G711_CODEC_H
#include "basic_types.h"
typedef enum {
I2S_MODE_UNKNOWN = -1,
I2S_MODE_G711A = 1,
I2S_MODE_G711U = 2
}I2S_mode;
typedef struct {
I2S_mode mode; //intend to encode as G711A or G711U
int len; //data length
// _sema RWSema;
unsigned char *raw_data; //address of buffered data (not encoded
int data_start; // a shift value to show where the data starts
int data_end; // a shift value shows data ending
}i2s_buf_context;
//void encoder_init(int mode);
int G711_encoder(short *source, unsigned char *des, int mode, int size);
int G711_decoder(unsigned char *source, short *des, int mode, int size);
int mono2stereo(unsigned char *src, unsigned char *dst, int size, int wl);
#endif

View file

@ -0,0 +1,196 @@
#include <stdio.h>
#include "PinNames.h"
#include "basic_types.h"
#include "diag.h"
#include <osdep_api.h>
#include "i2c_api.h"
#include "pinmap.h"
//#define I2C_MTR_SDA PC_4//PB_3
//#define I2C_MTR_SCL PC_5//PB_2
#define I2C_MTR_SDA PB_3
#define I2C_MTR_SCL PB_2
#define I2C_BUS_CLK 100000 //hz
#define I2C_ALC5651_ADDR (0x34/2)
#define RT5651_PRIV_INDEX 0x6a
#define RT5651_PRIV_DATA 0x6c
#if defined (__ICCARM__)
i2c_t alc5651_i2c;
#else
volatile i2c_t alc5651_i2c;
#define printf DBG_8195A
#endif
static void alc5651_delay(void)
{
int i;
i=10000;
while (i) {
i--;
asm volatile ("nop\n\t");
}
}
void alc5651_reg_write(unsigned int reg, unsigned int value)
{
char buf[4];
buf[0] = (char)reg;
buf[1] = (char)(value>>8);
buf[2] = (char)(value&0xff);
i2c_write(&alc5651_i2c, I2C_ALC5651_ADDR, &buf[0], 3, 1);
alc5651_delay();
}
void alc5651_reg_read(unsigned int reg, unsigned int *value)
{
int tmp;
char *buf = (char*)&tmp;
buf[0] = (char)reg;
i2c_write(&alc5651_i2c, I2C_ALC5651_ADDR, &buf[0], 1, 1);
alc5651_delay();
buf[0] = 0xaa;
buf[1] = 0xaa;
i2c_read(&alc5651_i2c, I2C_ALC5651_ADDR, &buf[0], 2, 1);
alc5651_delay();
*value= ((buf[0]&0xFF)<<8)|(buf[1]&0xFF);
}
void alc5651_index_write(unsigned int reg, unsigned int value)
{
alc5651_reg_write(RT5651_PRIV_INDEX, reg);
alc5651_reg_write(RT5651_PRIV_DATA, value);
}
void alc5651_index_read(unsigned int reg, unsigned int *value)
{
alc5651_reg_write(RT5651_PRIV_INDEX, reg);
alc5651_reg_read(RT5651_PRIV_DATA, value);
}
void alc5651_reg_dump(void)
{
int i;
unsigned int value;
printf("alc5651 codec reg dump\n\r");
printf("------------------------\n\r");
for(i=0;i<=0xff;i++){
alc5651_reg_read(i, &value);
printf("%02x : %04x\n\r", i, (unsigned short)value);
}
printf("------------------------\n\r");
}
void alc5651_index_dump(void)
{
int i;
unsigned int value;
printf("alc5651 codec index dump\n\r");
printf("------------------------\n\r");
for(i=0;i<=0xff;i++){
alc5651_index_read(i, &value);
printf("%02x : %04x\n\r", i, (unsigned short)value);
}
printf("------------------------\n\r");
}
void alc5651_init(void)
{
i2c_init(&alc5651_i2c, I2C_MTR_SDA, I2C_MTR_SCL);
i2c_frequency(&alc5651_i2c, I2C_BUS_CLK);
}
void alc5651_set_word_len(int len_idx) // interface2
{
// 0: 16 1: 20 2: 24 3: 8
unsigned int val;
alc5651_reg_read(0x71,&val);
val &= (~(0x3<<2));
val |= (len_idx<<2);
alc5651_reg_write(0x71,val);
alc5651_reg_read(0x70,&val);
val &= (~(0x3<<2));
val |= (len_idx<<2);
alc5651_reg_write(0x70,val);
}
void alc5651_init_interface1(void)
{
alc5651_reg_write(0x00,0x0021);
alc5651_reg_write(0x63,0xE8FE);
alc5651_reg_write(0x61,0x5800);
alc5651_reg_write(0x62,0x0C00);
alc5651_reg_write(0x73,0x0000);
alc5651_reg_write(0x2A,0x4242);
alc5651_reg_write(0x45,0x2000);
alc5651_reg_write(0x02,0x4848);
alc5651_reg_write(0x8E,0x0019);
alc5651_reg_write(0x8F,0x3100);
alc5651_reg_write(0x91,0x0E00);
alc5651_index_write(0x3D,0x3E00);
alc5651_reg_write(0xFA,0x0011);
alc5651_reg_write(0x83,0x0800);
alc5651_reg_write(0x84,0xA000);
alc5651_reg_write(0xFA,0x0C11);
alc5651_reg_write(0x64,0x4010);
alc5651_reg_write(0x65,0x0C00);
alc5651_reg_write(0x61,0x5806);
alc5651_reg_write(0x62,0xCC00);
alc5651_reg_write(0x3C,0x004F);
alc5651_reg_write(0x3E,0x004F);
alc5651_reg_write(0x27,0x3820);
alc5651_reg_write(0x77,0x0000);
}
void alc5651_init_interface2(void)
{
int reg_value=0;
alc5651_reg_write(0x00,0x0021);//reset all, device id 1
alc5651_reg_write(0x63,0xE8FE);//Power managerment control 3:
//VREF1&2 on, both slow VREF, MBIAS on, MBIAS bandcap power on, L & R HP Amp on, improve HP Amp driving enabled
alc5651_reg_write(0x61,0x5800);//power managerment control 1:
//I2S2 digital interface on, Analog DACL1 & DACR1 on.
alc5651_reg_write(0x62,0x0C00);//stereo1 & 2 DAC filter power on
alc5651_reg_write(0x73,0x0000);//ADC/DAC Clock control 1:
//I2S Clock Pre-Divider 1 & 2: /1. Stereo DAC Over Sample Rate : 128Fs
alc5651_reg_write(0x2A,0x4242);//Stereo DAC digital mixer control
//Un-mute DACL2 to Stereo DAC Left & Right Mixer
alc5651_reg_write(0x45,0x2000);//HPOMIX: Un-mute DAC1 to HPOMIX
alc5651_reg_write(0x02,0x4848);//HP Output Control:
//Unmute HPOL, HPOR
// alc5651_reg_write(0x0F,0x1F1F);//INL & INR Volume Control
// alc5651_reg_write(0x0D,0x0800);//IN1/2 Input Control
// alc5651_reg_write(0x1C,0x7F7F);//Stereo1 ADC Digital Volume Control
// alc5651_reg_write(0x1E,0xF000);// ADC Digital Boost Gain Control
alc5651_reg_write(0x8E,0x0019);//HP Amp Control 1
// Enable HP Output, Charge Pump Power On, HP Amp All Power On
alc5651_reg_write(0x8F,0x3100);//HP Amp Control 2, HP Depop Mode 2
alc5651_reg_write(0x91,0x0E00);//HP Amp Control 3, select HP capless power mode
alc5651_index_write(0x3D,0x3E00);//unknown
alc5651_reg_write(0xFA,0x0011);//enable input clock
alc5651_reg_write(0x83,0x0800);//default ASRC control 1
alc5651_reg_write(0x84,0xA000);//ASRC control 2: I2S1 enable ASRC mode, Sterol1 DAC filter ASRC mode.
// alc5651_reg_write(0xFA,0x0C11);//? ? ? MX-FAh[15:4]reserved
alc5651_reg_write(0x64,0x4010);//power managerment control 4:
//MIC BST2 Power On; MIC2 SE Mode single-end mode or line-input mode
alc5651_reg_write(0x65,0x0C00);//power managerment control 5: RECMIX L & R power on
alc5651_reg_write(0x61,0x5806);//power managerment control 1:
// I2S2 Digital Interface On, Analog DACL1, DACR1 power on; Analog ADCL, ADCR power on
alc5651_reg_write(0x62,0xCC00);//power managerment control 2: Stereo1&2 ADC/DAC digital filter power on
alc5651_reg_write(0x3C,0x004F);//RECMIXL
alc5651_reg_write(0x3E,0x004F);//RECMIXR
alc5651_reg_write(0x28,0x3030);//stereo2 ADC digital mixer control : Mute Stereo2 ADC L&R channel, ADCR
alc5651_reg_write(0x2F,0x0080); //Interface DAC/ADC Data control: Select IF2 ADCDAT Data Source IF1_ADC2
}

View file

@ -0,0 +1,22 @@
#ifndef _ETH_DEBUG_H_
#define _ETH_DEBUG_H_
#define ETH_DEBUG 0
#if ETH_DEBUG
#define ETH_PRINT(fmt, args...) printf("\n\r[%s]%s: " fmt, __FUNCTION__, ## args)
#define ETH_ERROR(fmt, args...) printf("\n\r[%s]%s: " fmt, __FUNCTION__, ## args)
#define ETH_WARM(fmt, args...) printf("\n\r[%s]%s: " fmt, __FUNCTION__, ## args)
#define FUN_ENTER printf("\n\r[%s ==>]\n", __func__)
#define FUN_EXIT printf("\n\r[%s <==]\n", __func__)
#define FUN_TRACE printf("\n\r[%s]:%d \n", __func__, __LINE__)
#else
#define ETH_PRINT(fmt, args...)
#define ETH_ERROR(fmt, args...) printf("\n\r%s: " fmt,__FUNCTION__, ## args)
#define ETH_WARM(fmt, args...)
#define FUN_ENTER
#define FUN_EXIT
#define FUN_TRACE
#endif
#endif

View file

@ -0,0 +1,358 @@
/*
* Ethernet gadget driver -- with CDC and non-CDC options
* Builds on hardware support for a full duplex link.
*
* CDC Ethernet is the standard USB solution for sending Ethernet frames
* using USB. Real hardware tends to use the same framing protocol but look
* different for control features. This driver strongly prefers to use
* this USB-IF standard as its open-systems interoperability solution;
* most host side USB stacks (except from Microsoft) support it.
*
* There's some hardware that can't talk CDC. We make that hardware
* implement a "minimalist" vendor-agnostic CDC core: same framing, but
* link-level setup only requires activating the configuration.
* Linux supports it, but other host operating systems may not.
* (This is a subset of CDC Ethernet.)
*
* A third option is also in use. Rather than CDC Ethernet, or something
* simpler, Microsoft pushes their own approach: RNDIS. The published
* RNDIS specs are ambiguous and appear to be incomplete, and are also
* needlessly complex.
*/
#ifndef __USB_ETHERNET_H
#define __USB_ETHERNET_H
#include "usb.h"
#include "usb_gadget.h"
#include "core/inc/usb_composite.h"
//#define DRIVER_DESC "Ethernet Gadget"
#define DRIVER_DESC "USB Network Interface"
#define DRIVER_VERSION "May Day 2015"
#define ETH_ADDR "00E04C8196C8"
static const char shortname [] = "ether";
static const char driver_desc [] = DRIVER_DESC;
#define CONFIG_USB_ETH_RNDIS 1
#define RNDIS_VENDOR_NUM ULINKER_ETHER_VID
#define RNDIS_PRODUCT_NUM ULINKER_ETHER_PID
/* Thanks to NetChip Technologies for donating this product ID.
* It's for devices with only CDC Ethernet configurations.
*/
#define CDC_VENDOR_NUM 0x0525 /* NetChip */
#define CDC_PRODUCT_NUM 0xa4a1 /* Linux-USB Ethernet Gadget */
/* USB DRIVER HOOKUP (to the hardware driver, below us), mostly
* ep0 implementation: descriptors, config management, setup().
* also optional class-specific notification interrupt transfer.
*/
/*
* DESCRIPTORS ... most are static, but strings and (full) configuration
* descriptors are built on demand. For now we do either full CDC, or
* our simple subset, with RNDIS as an optional second configuration.
*
* RNDIS includes some CDC ACM descriptors ... like CDC Ethernet. But
* the class descriptors match a modem (they're ignored; it's really just
* Ethernet functionality), they don't need the NOP altsetting, and the
* status transfer endpoint isn't optional.
*/
#define STRING_MANUFACTURER 1
#define STRING_PRODUCT 2
#define STRING_ETHADDR 3
#define STRING_DATA 4
#define STRING_CONTROL 5
#define STRING_RNDIS_CONTROL 6
#define STRING_CDC 7
#define STRING_SUBSET 8
#define STRING_RNDIS 9
#define STRING_SERIALNUMBER 10
/* holds our biggest descriptor (or RNDIS response) */
#define USB_BUFSIZ 256
#define BUFSIZ_IN 512
#define BUFSIZ_OUT 512
/*
* This device advertises one configuration, eth_config, unless RNDIS
* is enabled (rndis_config) on hardware supporting at least two configs.
*
* NOTE: Controllers like superh_udc should probably be able to use
* an RNDIS-only configuration.
*
* FIXME define some higher-powered configurations to make it easier
* to recharge batteries ...
*/
//#define DEV_CONFIG_VALUE 1 /* cdc or subset */
//#define DEV_RNDIS_CONFIG_VALUE 2 /* rndis; optional */
#define DEV_CONFIG_VALUE 2 /* cdc or subset */
#define DEV_RNDIS_CONFIG_VALUE 1 /* rndis; optional */
#define DEVSPEED USB_SPEED_HIGH
/* descriptors that are built on-demand */
static char manufacturer [50];
static char product_desc [40] = DRIVER_DESC;
static char serial_number [20];
/* address that the host will use ... usually assigned at random */
//ModifiedByJD static char ethaddr [2 * ETH_ALEN + 1];
static char ethaddr [2 * 6 + 1] = ETH_ADDR;
/* static strings, in UTF-8 */
static struct usb_string strings [] = {
{ STRING_MANUFACTURER, manufacturer, },
{ STRING_PRODUCT, product_desc, },
{ STRING_SERIALNUMBER, serial_number, },
{ STRING_DATA, "Ethernet Data", },
#if 1//def DEV_CONFIG_CDC//ModifiedByJD
{ STRING_CDC, "CDC Ethernet", },
{ STRING_ETHADDR, ethaddr, },
{ STRING_CONTROL, "CDC Communications Control", },
#endif
#if 1//def DEV_CONFIG_SUBSET//ModifiedByJD
{ STRING_SUBSET, "CDC Ethernet Subset", },
#endif
#if 1//def CONFIG_USB_ETH_RNDIS//ModifiedByJD
{ STRING_RNDIS, "RNDIS", },
{ STRING_RNDIS_CONTROL, "RNDIS Communications Control", },
#endif /* end of list */
};
static struct usb_gadget_strings stringtab = {
.language = 0x0409, /* en-us */
.strings = strings,
};
static struct usb_gadget_strings *dev_strings[] = {
&stringtab,
NULL,
};
static struct usb_device_descriptor
device_desc = {
.bLength = sizeof device_desc,
.bDescriptorType = USB_DT_DEVICE,
.bcdUSB = (0x0200),
.bDeviceClass = USB_CLASS_COMM,
.bDeviceSubClass = 0,
.bDeviceProtocol = 0,
.idVendor = (CDC_VENDOR_NUM),
.idProduct = (CDC_PRODUCT_NUM),
.iManufacturer = STRING_MANUFACTURER,
.iProduct = STRING_PRODUCT,
.bNumConfigurations = 1,
};
static struct usb_config_descriptor
eth_config = {
.bLength = sizeof eth_config,
.bDescriptorType = USB_DT_CONFIG,
/* compute wTotalLength on the fly */
.bNumInterfaces = 1,
.bConfigurationValue = DEV_CONFIG_VALUE,
.iConfiguration = STRING_CDC,
.bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
.bMaxPower = 50,
};
static struct usb_otg_descriptor
otg_descriptor = {
.bLength = sizeof otg_descriptor,
.bDescriptorType = USB_DT_OTG,
.bmAttributes = USB_OTG_SRP,
};
#ifdef CONFIG_USB_ETH_RNDIS
/* RNDIS doesn't activate by changing to the "real" altsetting */
static struct usb_interface_descriptor
rndis_data_intf = {
.bLength = sizeof rndis_data_intf,
.bDescriptorType = USB_DT_INTERFACE,
.bInterfaceNumber = 0,
.bAlternateSetting = 0,
.bNumEndpoints = 2,
.bInterfaceClass = USB_CLASS_CDC_DATA,
.bInterfaceSubClass = 0,
.bInterfaceProtocol = 0,
.iInterface = STRING_DATA,
};
#endif
static struct usb_endpoint_descriptor
hs_source_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
.wMaxPacketSize = (512),//ModifiedByJD
};
static struct usb_endpoint_descriptor
hs_sink_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
.wMaxPacketSize = (512),//ModifiedByJD
};
static struct usb_endpoint_descriptor
fs_source_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
};
static struct usb_endpoint_descriptor
fs_sink_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_OUT,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
};
static const struct usb_descriptor_header *fs_rndis_function [] = {
(struct usb_descriptor_header *) &otg_descriptor,
/* control interface matches ACM, not Ethernet */
#if 0//ModifiedByJD
(struct usb_descriptor_header *) &rndis_control_intf,
(struct usb_descriptor_header *) &header_desc,
(struct usb_descriptor_header *) &call_mgmt_descriptor,
(struct usb_descriptor_header *) &acm_descriptor,
(struct usb_descriptor_header *) &union_desc,
(struct usb_descriptor_header *) &fs_status_desc,
#endif
/* data interface has no altsetting */
(struct usb_descriptor_header *) &rndis_data_intf,
(struct usb_descriptor_header *) &fs_source_desc,
(struct usb_descriptor_header *) &fs_sink_desc,
NULL,
};
static const struct usb_descriptor_header *fs_eth_function [11] = {
(struct usb_descriptor_header *) &otg_descriptor,
#ifdef DEV_CONFIG_CDC
/* "cdc" mode descriptors */
(struct usb_descriptor_header *) &control_intf,
(struct usb_descriptor_header *) &header_desc,
(struct usb_descriptor_header *) &union_desc,
(struct usb_descriptor_header *) &ether_desc,
/* NOTE: status endpoint may need to be removed */
(struct usb_descriptor_header *) &fs_status_desc,
/* data interface, with altsetting */
(struct usb_descriptor_header *) &data_nop_intf,
(struct usb_descriptor_header *) &data_intf,
(struct usb_descriptor_header *) &fs_source_desc,
(struct usb_descriptor_header *) &fs_sink_desc,
NULL,
#endif /* DEV_CONFIG_CDC */
};
#ifdef CONFIG_USB_ETH_RNDIS
static const struct usb_descriptor_header *hs_rndis_function [] = {
(struct usb_descriptor_header *) &otg_descriptor,
/* control interface matches ACM, not Ethernet */
#if 0//ModifiedByJD
(struct usb_descriptor_header *) &rndis_control_intf,
(struct usb_descriptor_header *) &header_desc,
(struct usb_descriptor_header *) &call_mgmt_descriptor,
(struct usb_descriptor_header *) &acm_descriptor,
(struct usb_descriptor_header *) &union_desc,
(struct usb_descriptor_header *) &hs_status_desc,
#endif
/* data interface has no altsetting */
(struct usb_descriptor_header *) &rndis_data_intf,
(struct usb_descriptor_header *) &hs_source_desc,
(struct usb_descriptor_header *) &hs_sink_desc,
NULL,
};
#endif
static struct usb_config_descriptor
rndis_config = {
.bLength = sizeof rndis_config,
.bDescriptorType = USB_DT_CONFIG,
/* compute wTotalLength on the fly */
.bNumInterfaces = 1,
.bConfigurationValue = DEV_RNDIS_CONFIG_VALUE,
.iConfiguration = STRING_RNDIS,
.bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
.bMaxPower = 50,
};
static struct usb_configuration eth_configuration = {
.label = "eth_configuration",
.bConfigurationValue = DEV_CONFIG_VALUE,
// .bConfigurationValue = 1,
/* .iConfiguration = DYNAMIC */
.bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
};
static struct eth_dev{
struct usb_gadget *gadget;
struct usb_request *req; /* for control responses */
/* when configured, we have one of two configs:
* - source data (in to host) and sink it (out from host)
* - or loop it back (out from host back in to host)
*/
u8 config;
struct usb_ep *in_ep;
struct usb_ep *out_ep;
const struct usb_endpoint_descriptor
*in, *out, *status;
// lock is held when accessing usb
_Lock lock;
struct usb_function func;
/*send (depends on host)*/
_Sema xmit_sema;
xTaskHandle xmit_task;
unsigned int qlen;
_Mutex xmit_mutex;
_LIST eth2wlan_list;
/*receive (debuf_poolpends on host)*/
_Sema recv_sema;
xTaskHandle recv_task;
_Mutex recv_mutex;
_LIST wlan2eth_list;
};
extern int usb_eth_init(void);
#endif

View file

@ -0,0 +1,183 @@
#ifndef USBD_MSC_H
#define USBD_MSC_H
#include "usb.h"
#include "usb_gadget.h"
#include "core/inc/usb_composite.h"
#include "msc/inc/usbd_msc_config.h"
/* config usb msc device debug inforation */
#define USBD_MSC_DEBUG 0
#if USBD_MSC_DEBUG
#define USBD_PRINTF(fmt, args...) DBG_8195A("\n\r%s: " fmt, __FUNCTION__, ## args)
#define USBD_ERROR(fmt, args...) DBG_8195A("\n\r%s: " fmt, __FUNCTION__, ## args)
#define USBD_WARN(fmt, args...) DBG_8195A("\n\r%s: " fmt, __FUNCTION__, ## args)
#define FUN_ENTER DBG_8195A("\n\r%s ==>\n", __func__)
#define FUN_EXIT DBG_8195A("\n\r%s <==\n", __func__)
#define FUN_TRACE DBG_8195A("\n\r%s:%d \n", __func__, __LINE__)
#else
#define USBD_PRINTF(fmt, args...)
#define USBD_ERROR(fmt, args...) DBG_8195A("\n\r%s: " fmt, __FUNCTION__, ## args)
#define USBD_WARN(fmt, args...)
#define FUN_ENTER
#define FUN_EXIT
#define FUN_TRACE
#endif
/* MSC Request Codes */
#define MSC_REQUEST_RESET 0xFF
#define MSC_REQUEST_GET_MAX_LUN 0xFE
/* MSC LUN */
#define MSC_MAX_LOGIC_UNIT_NUMBER 1
enum data_direction{
DATA_DIR_UNKNOWN = 0,
DATA_DIR_FROM_HOST,
DATA_DIR_TO_HOST,
DATA_DIR_NONE
};
typedef enum _disk_type{
DISK_SDCARD,
DISK_FLASH
}disk_type;
//structure predefine
struct msc_dev;
struct msc_bufhd;
struct msc_opts{
int (*disk_init)(void);
int (*disk_deinit)(void);
int (*disk_getcapacity)(u32* sectors);
int (*disk_read)(u32 sector,u8 *buffer,u32 count);
int (*disk_write)(u32 sector,const u8 *buffer,u32 count);
};
struct msc_lun {
unsigned int initially_ro:1;
unsigned int ro:1;
unsigned int removable:1;
unsigned int cdrom:1;
unsigned int prevent_medium_removal:1;
unsigned int registered:1;
unsigned int info_valid:1;
unsigned int nofua:1;
u32 sense_data;
u32 sense_data_info;
u32 unit_attention_data;
u64 file_length;
unsigned int num_sectors; /* */
unsigned int blkbits; /* Bits of logical block size
of bound block device */
unsigned int blksize; /* logical block size of bound block device */
const char *name; /* "lun.name" */
unsigned int lba; // the current read and write logical block address
u8 is_open;
_mutex lun_mutex;
struct msc_opts *lun_opts;
};
struct msc_common{
struct msc_dev *mscdev;
struct msc_lun **luns;
struct msc_lun *curlun;
struct usb_gadget *gadget;
struct usb_ep *ep0;
struct usb_request *req0; /* for control responses */
/* scsi cbw relevant */
enum data_direction data_dir;
u32 data_size;
u32 data_size_from_cmnd;
u32 tag;
u32 residue;
u32 usb_amount_left;
u8 scsi_cmnd[16]; // max command
u8 cmnd_size;
u8 lun; /* current lun*/
u8 nluns;
u8 nbufhd;
u8 nbufhd_a;
_list bufhd_pool;
_mutex bufhd_mutex;
/* bulk out cmd*/
_list boc_list;
_mutex boc_mutex;
/* bolk out data*/
_mutex bod_mutex;
_list bod_list;
/**/
struct msc_bufhd* curbh; // current buffer header
struct msc_bufhd* cbw_bh; // buffer header for CBW
struct msc_bufhd* csw_bh; // buffer header for CSW
unsigned int can_stall:1;
unsigned int phase_error:1;
unsigned int short_packet_received:1;
unsigned int bad_lun_okay:1;
unsigned int running:1;
};
typedef enum _bufhd_type{
BUFHD_CBW = 0,
BUFHD_CSW,
BUFHD_DATA,
}bufhd_type;
struct msc_bufhd{
u8* buf;
int buf_size;
bufhd_type type;
_list list;
struct usb_request *reqin; /* for bulkin responses */
struct usb_request *reqout;
};
struct msc_dev{
struct msc_common *common;
u16 interface_number;
u8 config;
struct usb_ep *in_ep;
struct usb_ep *out_ep;
unsigned int bulk_in_enabled:1;
unsigned int bulk_out_enabled:1;
const struct usb_endpoint_descriptor
*in, *out, *status;
// lock is held when accessing usb
struct task_struct msc_outCmdTask;
struct task_struct msc_outDataTask;
struct usb_function func;
};
u32 min(u32 value1,u32 value2);
int usbd_msc_halt_bulk_in_endpoint(struct msc_dev *mscdev);
void usbd_msc_put_bufhd(struct msc_common *common, struct msc_bufhd* bufhd);
struct msc_bufhd* usbd_msc_get_bufhd(struct msc_common *common);
int usbd_msc_bulk_in_transfer(struct msc_dev *mscdev, struct usb_request *req);
int usbd_msc_bulk_out_transfer(struct msc_dev *mscdev, struct usb_request *req);
/*
* N_bh : number of buffer header
* Size_bh: buffer size per buffer
* type:msc physical disk type
*/
int usbd_msc_init(int N_bh, int Size_bh, disk_type type);
void usbd_msc_deinit(void);
#endif

View file

@ -0,0 +1,8 @@
#ifndef _USBD_MSC_CONFIG_H
#define _USBD_MSC_CONFIG_H
/* config usb MSC device buffer resource */
#define MSC_NBR_BUFHD 2 /* number of buffer header for bulk in/out data*/
#define MSC_BUFLEN (20*512)/* Default size of buffer length. Minmun of 512 byte*/
#endif

View file

@ -0,0 +1,196 @@
#include "usb_ch9.h"
#include "usb_defs.h"
#include "usb_gadget.h"
// <i> Enable high-speed functionality (if device supports it)
#define USBD_HS_ENABLE 1
// define string index
#define STRING_MANUFACTURER 1
#define STRING_PRODUCT 2
#define STRING_SERIALNUMBER 3
#define STRING_INTERFACE 4
#define STRING_MSC 5
#define DEV_CONFIG_VALUE 1
#define DRIVER_DESC "USB Mass Storage"
#define DRIVER_VERSION "Feb 2016"
#define MANUFACTURER "Realtek Singapore Semiconductor"
static char string_manufacturer [50] = MANUFACTURER;
static char string_product [40] = DRIVER_DESC;
static char string_serial [20] = "0123456789";
struct usb_string
usbd_msc_strings [] = {
{ STRING_MANUFACTURER, string_manufacturer, },
{ STRING_PRODUCT, string_product, },
{ STRING_SERIALNUMBER, string_serial, },
{ STRING_INTERFACE, "USB MSC Interface", },
{ STRING_MSC, "USB MSC", },
};
struct usb_gadget_strings msc_stringtab = {
.language = 0x0409, /* en-us */
.strings = usbd_msc_strings,
};
struct usb_gadget_strings *dev_msc_strings[] = {
&msc_stringtab,
NULL,
};
static struct usb_device_descriptor
usbd_msc_device_desc = {
.bLength = sizeof usbd_msc_device_desc,
.bDescriptorType = USB_DT_DEVICE,
.bcdUSB = (0x0200),
.bDeviceClass = 0x00,// define in interface descriptor
.bDeviceSubClass = 0x00,
.bDeviceProtocol = 0x00,
.bMaxPacketSize0 = 64, // this will be set automatically depends on ep0 setting
.idVendor = 0x0BDA,
.idProduct = 0x8195,
// .bcdDevice = ,
.iManufacturer = STRING_MANUFACTURER,
.iProduct = STRING_PRODUCT,
.iSerialNumber = STRING_SERIALNUMBER,
.bNumConfigurations=0x01,
};
#if 0
struct usb_config_descriptor
usbd_msc_config_desc = {
.bLength = sizeof usbd_msc_config_desc,
.bDescriptorType = USB_DT_CONFIG,
/* compute wTotalLength on the fly */
.bNumInterfaces = 1,
.bConfigurationValue = DEV_CONFIG_VALUE,
.iConfiguration = STRING_MSC,
.bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
.bMaxPower = 0x32,
};
#endif
#if USBD_HS_ENABLE
/* USB Device Qualifier Descriptor (for Full Speed) */
static struct usb_qualifier_descriptor
usbd_msc_qualifier_desc_FS = {
.bLength = sizeof usbd_msc_qualifier_desc_FS,
.bDescriptorType = USB_DT_DEVICE_QUALIFIER,
.bcdUSB = 0x0200,
.bDeviceClass = 0x00,
.bDeviceSubClass = 0x00,
.bDeviceProtocol = 0x00,
.bMaxPacketSize0 = 64,
.bNumConfigurations = 0x01,
.bRESERVED = 0x00,
};
/* USB Device Qualifier Descriptor for High Speed */
static struct usb_qualifier_descriptor
usbd_msc_qualifier_desc_HS = {
.bLength = sizeof usbd_msc_qualifier_desc_HS,
.bDescriptorType = USB_DT_DEVICE_QUALIFIER,
.bcdUSB = 0x0200,
.bDeviceClass = 0x00,
.bDeviceSubClass = 0x00,
.bDeviceProtocol = 0x00,
.bMaxPacketSize0 = 64,
.bNumConfigurations = 0x01,
.bRESERVED = 0x00,
};
#else
/* USB Device Qualifier Descriptor (for Full Speed) */
static struct usb_qualifier_descriptor
usbd_msc_qualifier_desc_FS = { 0 };
/* USB Device Qualifier Descriptor for High Speed */
static struct usb_qualifier_descriptor
usbd_msc_qualifier_desc_HS = { 0 };
#endif
/* MSC Interface, Alternate Setting 0*/
struct usb_interface_descriptor
usbd_msc_intf_desc = {
.bLength = sizeof usbd_msc_intf_desc,
.bDescriptorType = USB_DT_INTERFACE,
.bInterfaceNumber = 0x00, // this will be assign automatically
.bAlternateSetting =0x00,
.bNumEndpoints = 0x02,
.bInterfaceClass = USB_CLASS_MASS_STORAGE,
.bInterfaceSubClass = US_SC_SCSI,
.bInterfaceProtocol = US_PR_BULK,
.iInterface = STRING_INTERFACE,
};
/* MSC Endpoints for Low-speed/Full-speed */
/* Endpoint, EP Bulk IN */
struct usb_endpoint_descriptor
usbd_msc_source_desc_FS = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
.wMaxPacketSize = (64),
.bInterval = 0x00,
};
/* Endpoint, EP Bulk OUT */
struct usb_endpoint_descriptor
usbd_msc_sink_desc_FS = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_OUT,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
.wMaxPacketSize = (64),
.bInterval = 0x00,
};
/* MSC Endpoints for High-speed */
/* Endpoint, EP Bulk IN */
struct usb_endpoint_descriptor
usbd_msc_source_desc_HS = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_IN,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
.wMaxPacketSize = (512),
.bInterval = 0x00,
};
/* Endpoint, EP Bulk OUT */
struct usb_endpoint_descriptor
usbd_msc_sink_desc_HS = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_DIR_OUT,
.bmAttributes = USB_ENDPOINT_XFER_BULK,
.wMaxPacketSize = (512),
.bInterval = 0x00,
};
struct usb_descriptor_header *usbd_msc_descriptors_FS [] = {
/* data interface has no altsetting */
(struct usb_descriptor_header *) &usbd_msc_intf_desc,
(struct usb_descriptor_header *) &usbd_msc_source_desc_FS,
(struct usb_descriptor_header *) &usbd_msc_sink_desc_FS,
NULL,
};
struct usb_descriptor_header *usbd_msc_descriptors_HS [] = {
/* data interface has no altsetting */
(struct usb_descriptor_header *) &usbd_msc_intf_desc,
(struct usb_descriptor_header *) &usbd_msc_source_desc_HS,
(struct usb_descriptor_header *) &usbd_msc_sink_desc_HS,
NULL,
};

View file

@ -0,0 +1,110 @@
#ifndef USBD_SCSI_H
#define USBD_SCSI_H
#include "basic_types.h"
#include "msc/inc/usbd_msc.h"
#define MAX_COMMAND_SIZE 16
#define MSC_MAX_LUNS 8
/* SCSI Commands */
#define SCSI_FORMAT_UNIT 0x04
#define SCSI_INQUIRY 0x12
#define SCSI_MODE_SELECT6 0x15
#define SCSI_MODE_SELECT10 0x55
#define SCSI_MODE_SENSE6 0x1A
#define SCSI_MODE_SENSE10 0x5A
#define SCSI_ALLOW_MEDIUM_REMOVAL 0x1E
#define SCSI_READ6 0x08
#define SCSI_READ10 0x28
#define SCSI_READ12 0xA8
#define SCSI_READ16 0x88
#define SCSI_READ_CAPACITY10 0x25
#define SCSI_READ_CAPACITY16 0x9E
#define SCSI_SYNCHRONIZE_CACHE 0x35
#define SCSI_REQUEST_SENSE 0x03
#define SCSI_START_STOP_UNIT 0x1B
#define SCSI_TEST_UNIT_READY 0x00
#define SCSI_WRITE6 0x0A
#define SCSI_WRITE10 0x2A
#define SCSI_WRITE12 0xAA
#define SCSI_WRITE16 0x8A
#define SCSI_VERIFY10 0x2F
#define SCSI_VERIFY12 0xAF
#define SCSI_VERIFY16 0x8F
#define SCSI_SEND_DIAGNOSTIC 0x1D
#define SCSI_READ_FORMAT_CAPACITIES 0x23
#define READ_FORMAT_CAPACITY_DATA_LEN 0x0C
#define READ_CAPACITY10_DATA_LEN 0x08
#define MODE_SENSE10_DATA_LEN 0x08
#define MODE_SENSE6_DATA_LEN 0x04
#define REQUEST_SENSE_DATA_LEN 0x12
#define STANDARD_INQUIRY_DATA_LEN 0x24
/* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */
#define SS_NO_SENSE 0
#define SS_COMMUNICATION_FAILURE 0x040800
#define SS_INVALID_COMMAND 0x052000
#define SS_INVALID_FIELD_IN_CDB 0x052400
#define SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x052100
#define SS_LOGICAL_UNIT_NOT_SUPPORTED 0x052500
#define SS_MEDIUM_NOT_PRESENT 0x023a00
#define SS_MEDIUM_REMOVAL_PREVENTED 0x055302
#define SS_NOT_READY_TO_READY_TRANSITION 0x062800
#define SS_RESET_OCCURRED 0x062900
#define SS_SAVING_PARAMETERS_NOT_SUPPORTED 0x053900
#define SS_UNRECOVERED_READ_ERROR 0x031100
#define SS_WRITE_ERROR 0x030c02
#define SS_WRITE_PROTECTED 0x072700
#define SK(x) ((u8) ((x) >> 16)) /* Sense Key byte, etc. */
#define ASC(x) ((u8) ((x) >> 8))
#define ASCQ(x) ((u8) (x))
/*
* Bulk only data structures
*/
/* command block wrapper */
struct bulk_cb_wrap {
unsigned int Signature; /* contains 'USBC', denote bulk_cb_wrap */
unsigned int Tag; /* unique per command id */
unsigned int DataTransferLength; /* size of data for transfer */
unsigned char Flags; /* data transfer direction */
unsigned char Lun; /* LUN normally 0, (which command block is sent) */
unsigned char Length; /* length of the CDB */
unsigned char CDB[16]; /* max command */
};
#define US_BULK_CB_WRAP_LEN 31
#define US_BULK_CB_SIGN 0x43425355 /*spells out USBC */
#define US_BULK_FLAG_IN (1 << 7)
#define US_BULK_FLAG_OUT 0
/* command status wrapper */
struct bulk_cs_wrap {
unsigned int Signature; /* should = 'USBS' */
unsigned int Tag; /* same as original command, echoed by the device as received */
unsigned int Residue; /* amount not transferred */
unsigned char Status; /* execute command status */
};
#define US_BULK_CS_WRAP_LEN 13
#define US_BULK_CS_SIGN 0x53425355 /* spells out 'USBS' */
// execute command status
#define US_BULK_STAT_OK 0
#define US_BULK_STAT_FAIL 1
#define US_BULK_STAT_PHASE 2
/* bulk-only class specific requests */
#define US_BULK_RESET_REQUEST 0xff
#define US_BULK_GET_MAX_LUN 0xfe
extern int usbd_msc_receive_cbw(struct msc_dev *mscdev, struct usb_request *req);
#endif

View file

@ -0,0 +1,24 @@
#ifndef _GADEGT_DEBUG_H_
#define _GADGET_DEBUG_H_
#include "diag.h"
#define GADGET_DEBUG 0
#if GADGET_DEBUG
#define GADGET_PRINT(fmt, args...) DBG_8195A("\n\r[%s]: " fmt, __FUNCTION__, ## args)
#define GADGET_ERROR(fmt, args...) DBG_8195A("\n\r[%s]: " fmt, __FUNCTION__, ## args)
#define GADGET_WARN(fmt, args...) DBG_8195A("\n\r[%s]: " fmt, __FUNCTION__, ## args)
#define FUN_ENTER DBG_8195A("\n\r[%s ==>]\n", __func__)
#define FUN_EXIT DBG_8195A("\n\r[%s <==]\n", __func__)
#define FUN_TRACE DBG_8195A("\n\r[%s]:%d \n", __func__, __LINE__)
#else
#define GADGET_PRINT(fmt, args...)
#define GADGET_ERROR(fmt, args...) DBG_8195A("\n\r[%s]: " fmt, __FUNCTION__, ## args)
#define GADGET_WARN(fmt, args...)
#define FUN_ENTER
#define FUN_EXIT
#define FUN_TRACE
#endif
#endif

View file

@ -0,0 +1,30 @@
#ifndef _OS_WRAPPER_H_
#define _OS_WRAPPER_H_
#include "osdep_api.h"
#ifndef spinlock_t
#define spinlock_t _Lock
#endif
#ifndef _atomic_spin_lock_irqsave
#define _atomic_spin_lock_irqsave(p, flags) SaveAndCli()
#endif
#ifndef _atomic_spin_unlock_irqrestore
#define _atomic_spin_unlock_irqrestore(p, flags) RestoreFlags()
#endif
/* spin lock */
#ifndef spin_lock_init
#define spin_lock_init(plock) RtlSpinlockInit((plock))
#endif
#ifndef spin_lock_free
#define spin_lock_free(plock) RtlSpinlockFree((plock))
#endif
#ifndef spin_lock
#define spin_lock(plock) RtlSpinlock((plock))
#endif
#ifndef spin_unlock
#define spin_unlock(plock) RtlSpinunlock((plock))
#endif
#endif

View file

@ -0,0 +1,398 @@
#ifndef _USB_COMPOSITE_H_
#define _USB_COMPOSITE_H_
#include "usb_gadget.h"
#include "usb.h"
/*
* USB function drivers should return USB_GADGET_DELAYED_STATUS if they
* wish to delay the data/status stages of the control transfer till they
* are ready. The control transfer will then be kept from completing till
* all the function drivers that requested for USB_GADGET_DELAYED_STAUS
* invoke usb_composite_setup_continue().
*/
#define USB_GADGET_DELAYED_STATUS 0x7fff /* Impossibly large value */
/* big enough to hold our biggest descriptor */
#define USB_COMP_EP0_BUFSIZ 1024+24
#define MAX_CONFIG_INTERFACES 16 /* arbitrary; max 255 */
// predefine structure
struct usb_composite_dev;
struct usb_composite_driver;
enum control_request_return_codes {
USBD_REQ_NOTSUPP = 0,
USBD_REQ_HANDLED = 1,
USBD_REQ_NEXT_CALLBACK = 2,
};
/**
* struct usb_composite_driver - groups configurations into a gadget
* @name: For diagnostics, identifies the driver.
* @dev: Template descriptor for the device, including default device
* identifiers.
* @strings: tables of strings, keyed by identifiers assigned during @bind
* and language IDs provided in control requests. Note: The first entries
* are predefined. The first entry that may be used is
* USB_GADGET_FIRST_AVAIL_IDX
* @max_speed: Highest speed the driver supports.
* @needs_serial: set to 1 if the gadget needs userspace to provide
* a serial number. If one is not provided, warning will be printed.
* @bind: (REQUIRED) Used to allocate resources that are shared across the
* whole device, such as string IDs, and add its configurations using
* @usb_add_config(). This may fail by returning a negative errno
* value; it should return zero on successful initialization.
* @unbind: Reverses @bind; called as a side effect of unregistering
* this driver.
* @disconnect: optional driver disconnect method
* @suspend: Notifies when the host stops sending USB traffic,
* after function notifications
* @resume: Notifies configuration when the host restarts USB traffic,
* before function notifications
* @gadget_driver: Gadget driver controlling this driver
*
* Devices default to reporting self powered operation. Devices which rely
* on bus powered operation should report this in their @bind method.
*
* Before returning from @bind, various fields in the template descriptor
* may be overridden. These include the idVendor/idProduct/bcdDevice values
* normally to bind the appropriate host side driver, and the three strings
* (iManufacturer, iProduct, iSerialNumber) normally used to provide user
* meaningful device identifiers. (The strings will not be defined unless
* they are defined in @dev and @strings.) The correct ep0 maxpacket size
* is also reported, as defined by the underlying controller driver.
*/
struct usb_composite_driver {
const char *name;
const struct usb_device_descriptor *dev;
struct usb_gadget_strings **strings;
enum usb_device_speed max_speed;
unsigned needs_serial:1;
int (*bind)(struct usb_composite_dev *cdev);
int (*unbind)(struct usb_composite_dev *);
void (*disconnect)(struct usb_composite_dev *);
/* global suspend hooks */
void (*suspend)(struct usb_composite_dev *);
void (*resume)(struct usb_composite_dev *);
struct usb_gadget_driver gadget_driver;
};
/**
* struct usb_composite_device - represents one composite usb gadget
* @gadget: read-only, abstracts the gadget's usb peripheral controller
* @req: used for control responses; buffer is pre-allocated
* @os_desc_req: used for OS descriptors responses; buffer is pre-allocated
* @config: the currently active configuration
* @qw_sign: qwSignature part of the OS string
* @b_vendor_code: bMS_VendorCode part of the OS string
* @use_os_string: false by default, interested gadgets set it
* @os_desc_config: the configuration to be used with OS descriptors
*
* One of these devices is allocated and initialized before the
* associated device driver's bind() is called.
*
* OPEN ISSUE: it appears that some WUSB devices will need to be
* built by combining a normal (wired) gadget with a wireless one.
* This revision of the gadget framework should probably try to make
* sure doing that won't hurt too much.
*
* One notion for how to handle Wireless USB devices involves:
* (a) a second gadget here, discovery mechanism TBD, but likely
* needing separate "register/unregister WUSB gadget" calls;
* (b) updates to usb_gadget to include flags "is it wireless",
* "is it wired", plus (presumably in a wrapper structure)
* bandgroup and PHY info;
* (c) presumably a wireless_ep wrapping a usb_ep, and reporting
* wireless-specific parameters like maxburst and maxsequence;
* (d) configurations that are specific to wireless links;
* (e) function drivers that understand wireless configs and will
* support wireless for (additional) function instances;
* (f) a function to support association setup (like CBAF), not
* necessarily requiring a wireless adapter;
* (g) composite device setup that can create one or more wireless
* configs, including appropriate association setup support;
* (h) more, TBD.
*/
#define MAX_USER_CONTROL_CALLBACK 2
typedef int (*user_control_callback)(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl);
struct usb_composite_dev {
struct usb_gadget *gadget;
struct usb_request *req;
struct usb_request *os_desc_req;
struct usb_configuration *config;
//
// /* OS String is a custom (yet popular) extension to the USB standard. */
// u8 qw_sign[OS_STRING_QW_SIGN_LEN];
// u8 b_vendor_code;
// struct usb_configuration *os_desc_config;
// unsigned int use_os_string:1;
//
// /* private: */
// /* internals */
unsigned int suspended:1;
struct usb_device_descriptor desc;
//_LIST config_list;
dwc_list_link_t config_list; // by jimmy
//_LIST gstring_list;
dwc_list_link_t gstring_list;// by jimmy
struct usb_composite_driver *driver;
// u8 next_string_id;
// char *def_manufacturer;
//
// /* the gadget driver won't enable the data pullup
// * while the deactivation count is nonzero.
// */
// unsigned deactivations;
//
// /* the composite driver won't complete the control transfer's
// * data/status stages till delayed_status is zero.
// */
// int delayed_status;
//
// /* protects deactivations and delayed_status counts*/
_Lock lock;
/* for unstandard control request handler */
user_control_callback control_cb[MAX_USER_CONTROL_CALLBACK];
};
#if 0
#define container_of(p,t,n) (t*)((p)-&(((t*)0)->n))
static inline struct usb_composite_driver *to_cdriver(
struct usb_gadget_driver *gdrv)
{
return container_of(gdrv, struct usb_composite_driver, gadget_driver);
}
#endif
#if 1
/**
* struct usb_configuration - represents one gadget configuration
* @label: For diagnostics, describes the configuration.
* @strings: Tables of strings, keyed by identifiers assigned during @bind()
* and by language IDs provided in control requests.
* @descriptors: Table of descriptors preceding all function descriptors.
* Examples include OTG and vendor-specific descriptors.
* @unbind: Reverses @bind; called as a side effect of unregistering the
* driver which added this configuration.
* @setup: Used to delegate control requests that aren't handled by standard
* device infrastructure or directed at a specific interface.
* @bConfigurationValue: Copied into configuration descriptor.
* @iConfiguration: Copied into configuration descriptor.
* @bmAttributes: Copied into configuration descriptor.
* @MaxPower: Power consumtion in mA. Used to compute bMaxPower in the
* configuration descriptor after considering the bus speed.
* @cdev: assigned by @usb_add_config() before calling @bind(); this is
* the device associated with this configuration.
*
* Configurations are building blocks for gadget drivers structured around
* function drivers. Simple USB gadgets require only one function and one
* configuration, and handle dual-speed hardware by always providing the same
* functionality. Slightly more complex gadgets may have more than one
* single-function configuration at a given speed; or have configurations
* that only work at one speed.
*
* Composite devices are, by definition, ones with configurations which
* include more than one function.
*
* The lifecycle of a usb_configuration includes allocation, initialization
* of the fields described above, and calling @usb_add_config() to set up
* internal data and bind it to a specific device. The configuration's
* @bind() method is then used to initialize all the functions and then
* call @usb_add_function() for them.
*
* Those functions would normally be independent of each other, but that's
* not mandatory. CDC WMC devices are an example where functions often
* depend on other functions, with some functions subsidiary to others.
* Such interdependency may be managed in any way, so long as all of the
* descriptors complete by the time the composite driver returns from
* its bind() routine.
*/
struct usb_configuration {
const char *label;
struct usb_gadget_strings **strings;
const struct usb_descriptor_header **descriptors;
/* REVISIT: bind() functions can be marked __init, which
* makes trouble for section mismatch analysis. See if
* we can't restructure things to avoid mismatching...
*/
/* configuration management: unbind/setup */
void (*unbind)(struct usb_configuration *);
int (*setup)(struct usb_configuration *,
const struct usb_ctrlrequest *);
/* fields in the config descriptor */
u8 bConfigurationValue;
u8 iConfiguration;
u8 bmAttributes;
u16 MaxPower;
struct usb_composite_dev *cdev;
/* private: */
/* internals */
//_LIST list;
//_LIST function_lists;
dwc_list_link_t list;
dwc_list_link_t function_lists; // by jimmy
u8 next_interface_id;
unsigned superspeed:1;
unsigned highspeed:1;
unsigned fullspeed:1;
struct usb_function *interface[MAX_CONFIG_INTERFACES];
};
_LONG_CALL_ int usb_interface_id(struct usb_configuration *config,
struct usb_function *function);
_LONG_CALL_ int usb_add_config(struct usb_composite_dev *,
struct usb_configuration *,
int (*)(struct usb_configuration *));
_LONG_CALL_ void usb_remove_config(struct usb_composite_dev *,
struct usb_configuration *);
/**
* struct usb_function - describes one function of a configuration
* @name: For diagnostics, identifies the function.
* @strings: tables of strings, keyed by identifiers assigned during bind()
* and by language IDs provided in control requests
* @fs_descriptors: Table of full (or low) speed descriptors, using interface and
* string identifiers assigned during @bind(). If this pointer is null,
* the function will not be available at full speed (or at low speed).
* @hs_descriptors: Table of high speed descriptors, using interface and
* string identifiers assigned during @bind(). If this pointer is null,
* the function will not be available at high speed.
* @ss_descriptors: Table of super speed descriptors, using interface and
* string identifiers assigned during @bind(). If this
* pointer is null after initiation, the function will not
* be available at super speed.
* @config: assigned when @usb_add_function() is called; this is the
* configuration with which this function is associated.
* @os_desc_table: Table of (interface id, os descriptors) pairs. The function
* can expose more than one interface. If an interface is a member of
* an IAD, only the first interface of IAD has its entry in the table.
* @os_desc_n: Number of entries in os_desc_table
* @bind: Before the gadget can register, all of its functions bind() to the
* available resources including string and interface identifiers used
* in interface or class descriptors; endpoints; I/O buffers; and so on.
* @unbind: Reverses @bind; called as a side effect of unregistering the
* driver which added this function.
* @free_func: free the struct usb_function.
* @mod: (internal) points to the module that created this structure.
* @set_alt: (REQUIRED) Reconfigures altsettings; function drivers may
* initialize usb_ep.driver data at this time (when it is used).
* Note that setting an interface to its current altsetting resets
* interface state, and that all interfaces have a disabled state.
* @get_alt: Returns the active altsetting. If this is not provided,
* then only altsetting zero is supported.
* @disable: (REQUIRED) Indicates the function should be disabled. Reasons
* include host resetting or reconfiguring the gadget, and disconnection.
* @setup: Used for interface-specific control requests.
* @suspend: Notifies functions when the host stops sending USB traffic.
* @resume: Notifies functions when the host restarts USB traffic.
* @get_status: Returns function status as a reply to
* GetStatus() request when the recipient is Interface.
* @func_suspend: callback to be called when
* SetFeature(FUNCTION_SUSPEND) is reseived
*
* A single USB function uses one or more interfaces, and should in most
* cases support operation at both full and high speeds. Each function is
* associated by @usb_add_function() with a one configuration; that function
* causes @bind() to be called so resources can be allocated as part of
* setting up a gadget driver. Those resources include endpoints, which
* should be allocated using @usb_ep_autoconfig().
*
* To support dual speed operation, a function driver provides descriptors
* for both high and full speed operation. Except in rare cases that don't
* involve bulk endpoints, each speed needs different endpoint descriptors.
*
* Function drivers choose their own strategies for managing instance data.
* The simplest strategy just declares it "static', which means the function
* can only be activated once. If the function needs to be exposed in more
* than one configuration at a given speed, it needs to support multiple
* usb_function structures (one for each configuration).
*
* A more complex strategy might encapsulate a @usb_function structure inside
* a driver-specific instance structure to allows multiple activations. An
* example of multiple activations might be a CDC ACM function that supports
* two or more distinct instances within the same configuration, providing
* several independent logical data links to a USB host.
*/
struct usb_function {
const char *name;
struct usb_gadget_strings **strings;
struct usb_descriptor_header **fs_descriptors;
struct usb_descriptor_header **hs_descriptors;
// struct usb_descriptor_header **ss_descriptors;
struct usb_configuration *config;
// struct usb_os_desc_table *os_desc_table;
// unsigned os_desc_n;
/* REVISIT: bind() functions can be marked __init, which
* makes trouble for section mismatch analysis. See if
* we can't restructure things to avoid mismatching.
* Related: unbind() may kfree() but bind() won't...
*/
/* configuration management: bind/unbind */
int (*bind)(struct usb_configuration *,
struct usb_function *);
void (*unbind)(struct usb_configuration *,
struct usb_function *);
void (*free_func)(struct usb_function *f);
struct module *mod;
/* runtime state management */
int (*set_alt)(struct usb_function *,
unsigned interface, unsigned alt);
int (*get_alt)(struct usb_function *,
unsigned interface);
void (*disable)(struct usb_function *);
int (*setup)(struct usb_function *,
const struct usb_ctrlrequest *);
void (*suspend)(struct usb_function *);
void (*resume)(struct usb_function *);
/* USB 3.0 additions */
int (*get_status)(struct usb_function *);
int (*func_suspend)(struct usb_function *,
u8 suspend_opt);
/* private: */
/* internals */
//_LIST list;
dwc_list_link_t list; // by jimmy
// DECLARE_BITMAP(endpoints, 32);
// const struct usb_function_instance *fi;
};
#endif
extern _LONG_CALL_ int usb_add_function(struct usb_configuration *, struct usb_function *);
extern _LONG_CALL_ void usb_remove_function(struct usb_configuration *, struct usb_function *);
extern _LONG_CALL_ void usb_put_function(struct usb_function *);
extern _LONG_CALL_ int usb_function_deactivate(struct usb_function *);
extern _LONG_CALL_ int usb_function_activate(struct usb_function *);
extern _LONG_CALL_ int usb_interface_id(struct usb_configuration *, struct usb_function *);
extern _LONG_CALL_ int usb_composite_probe(struct usb_composite_driver *driver);
extern _LONG_CALL_ int register_class_vendor_control_request_cb(struct usb_composite_dev *cdev, user_control_callback cb);
extern _LONG_CALL_ void usb_composite_unregister(struct usb_composite_driver *driver);
#endif

View file

@ -0,0 +1,12 @@
#ifndef _USB_CONFIG_H_
#define _USB_CONFIG_H_
#include "core/inc/usb_composite.h"
extern _LONG_CALL_ int usb_assign_descriptors(struct usb_function *f,
struct usb_descriptor_header **fs,
struct usb_descriptor_header **hs,
struct usb_descriptor_header **ss);
extern _LONG_CALL_ void usb_free_all_descriptors(struct usb_function *f);
#endif

View file

@ -0,0 +1,5 @@
#ifndef _USB_BOT_H
#define _USB_BOT_H
#include "basic_types.h"
#endif

View file

@ -0,0 +1,34 @@
/*
* This file holds the definitions of quirks found in USB devices.
* Only quirks that affect the whole device, not an interface,
* belong here.
*/
#ifndef __QUIRKS_H
#define __QUIRKS_H
/* string descriptors must not be fetched using a 255-byte read */
#define USB_QUIRK_STRING_FETCH_255 0x00000001
/* device can't resume correctly so reset it instead */
#define USB_QUIRK_RESET_RESUME 0x00000002
/* device can't handle Set-Interface requests */
#define USB_QUIRK_NO_SET_INTF 0x00000004
/* device can't handle its Configuration or Interface strings */
#define USB_QUIRK_CONFIG_INTF_STRINGS 0x00000008
/* device can't be reset(e.g morph devices), don't use reset */
#define USB_QUIRK_RESET 0x00000010
/* device has more interface descriptions than the bNumInterfaces count,
and can't handle talking to these interfaces */
#define USB_QUIRK_HONOR_BNUMINTERFACES 0x00000020
/* device needs a pause during initialization, after we read the device
descriptor */
#define USB_QUIRK_DELAY_INIT 0x00000040
#endif /* __QUIRKS_H */

View file

@ -0,0 +1,20 @@
#ifndef _SCATTERLIST_H
#define _SCATTERLIST_H
struct scatterlist {
unsigned long sg_magic;
unsigned long page_link;
unsigned int offset;
unsigned int length;
dma_addr_t dma_address;
__u32 dma_length;
};
struct sg_table {
struct scatterlist *sgl; /* the list */
unsigned int nents; /* number of mapped entries */
unsigned int orig_nents; /* original size of list */
};
#endif

View file

@ -0,0 +1,12 @@
#ifndef _DMA_DIRECTION_H
#define _DMA_DIRECTION_H
enum dma_data_direction {
DMA_BIDIRECTIONAL = 0,
DMA_TO_DEVICE = 1,
DMA_FROM_DEVICE = 2,
DMA_NONE = 3,
};
#endif

View file

@ -0,0 +1,585 @@
/*
* This header file contains public constants and structures used by
* the scsi code for linux.
*
* For documentation on the OPCODES, MESSAGES, and SENSE values,
* please consult the SCSI standard.
*/
#ifndef _SCSI_SCSI_H
#define _SCSI_SCSI_H
#include "us_os_wrap_via_osdep_api.h"
#define HZ 1024
struct scsi_cmnd;
enum scsi_timeouts {
SCSI_DEFAULT_EH_TIMEOUT = 10 * HZ,
};
/*
* The maximum number of SG segments that we will put inside a
* scatterlist (unless chaining is used). Should ideally fit inside a
* single page, to avoid a higher order allocation. We could define this
* to SG_MAX_SINGLE_ALLOC to pack correctly at the highest order. The
* minimum value is 32
*/
#define SCSI_MAX_SG_SEGMENTS 128
/*
* Like SCSI_MAX_SG_SEGMENTS, but for archs that have sg chaining. This limit
* is totally arbitrary, a setting of 2048 will get you at least 8mb ios.
*/
#ifdef ARCH_HAS_SG_CHAIN
#define SCSI_MAX_SG_CHAIN_SEGMENTS 2048
#else
#define SCSI_MAX_SG_CHAIN_SEGMENTS SCSI_MAX_SG_SEGMENTS
#endif
/*
* DIX-capable adapters effectively support infinite chaining for the
* protection information scatterlist
*/
#define SCSI_MAX_PROT_SG_SEGMENTS 0xFFFF
/*
* Special value for scanning to specify scanning or rescanning of all
* possible channels, (target) ids, or luns on a given shost.
*/
#define SCAN_WILD_CARD ~0
/*
* SCSI opcodes
*/
#define TEST_UNIT_READY 0x00
#define REZERO_UNIT 0x01
#define REQUEST_SENSE 0x03
#define FORMAT_UNIT 0x04
#define READ_BLOCK_LIMITS 0x05
#define REASSIGN_BLOCKS 0x07
#define INITIALIZE_ELEMENT_STATUS 0x07
#define READ_6 0x08
#define WRITE_6 0x0a
#define SEEK_6 0x0b
#define READ_REVERSE 0x0f
#define WRITE_FILEMARKS 0x10
#define SPACE 0x11
#define INQUIRY 0x12
#define RECOVER_BUFFERED_DATA 0x14
#define MODE_SELECT 0x15
#define RESERVE 0x16
#define RELEASE 0x17
#define COPY 0x18
#define ERASE 0x19
#define MODE_SENSE 0x1a
#define START_STOP 0x1b
#define RECEIVE_DIAGNOSTIC 0x1c
#define SEND_DIAGNOSTIC 0x1d
#define ALLOW_MEDIUM_REMOVAL 0x1e
#define READ_FORMAT_CAPACITIES 0x23
#define SET_WINDOW 0x24
#define READ_CAPACITY 0x25
#define READ_10 0x28
#define WRITE_10 0x2a
#define SEEK_10 0x2b
#define POSITION_TO_ELEMENT 0x2b
#define WRITE_VERIFY 0x2e
#define VERIFY 0x2f
#define SEARCH_HIGH 0x30
#define SEARCH_EQUAL 0x31
#define SEARCH_LOW 0x32
#define SET_LIMITS 0x33
#define PRE_FETCH 0x34
#define READ_POSITION 0x34
#define SYNCHRONIZE_CACHE 0x35
#define LOCK_UNLOCK_CACHE 0x36
#define READ_DEFECT_DATA 0x37
#define MEDIUM_SCAN 0x38
#define COMPARE 0x39
#define COPY_VERIFY 0x3a
#define WRITE_BUFFER 0x3b
#define READ_BUFFER 0x3c
#define UPDATE_BLOCK 0x3d
#define READ_LONG 0x3e
#define WRITE_LONG 0x3f
#define CHANGE_DEFINITION 0x40
#define WRITE_SAME 0x41
#define UNMAP 0x42
#define READ_TOC 0x43
#define READ_HEADER 0x44
#define GET_EVENT_STATUS_NOTIFICATION 0x4a
#define LOG_SELECT 0x4c
#define LOG_SENSE 0x4d
#define XDWRITEREAD_10 0x53
#define MODE_SELECT_10 0x55
#define RESERVE_10 0x56
#define RELEASE_10 0x57
#define MODE_SENSE_10 0x5a
#define PERSISTENT_RESERVE_IN 0x5e
#define PERSISTENT_RESERVE_OUT 0x5f
#define VARIABLE_LENGTH_CMD 0x7f
#define REPORT_LUNS 0xa0
#define SECURITY_PROTOCOL_IN 0xa2
#define MAINTENANCE_IN 0xa3
#define MAINTENANCE_OUT 0xa4
#define MOVE_MEDIUM 0xa5
#define EXCHANGE_MEDIUM 0xa6
#define READ_12 0xa8
#define WRITE_12 0xaa
#define READ_MEDIA_SERIAL_NUMBER 0xab
#define WRITE_VERIFY_12 0xae
#define VERIFY_12 0xaf
#define SEARCH_HIGH_12 0xb0
#define SEARCH_EQUAL_12 0xb1
#define SEARCH_LOW_12 0xb2
#define SECURITY_PROTOCOL_OUT 0xb5
#define READ_ELEMENT_STATUS 0xb8
#define SEND_VOLUME_TAG 0xb6
#define WRITE_LONG_2 0xea
#define EXTENDED_COPY 0x83
#define RECEIVE_COPY_RESULTS 0x84
#define ACCESS_CONTROL_IN 0x86
#define ACCESS_CONTROL_OUT 0x87
#define READ_16 0x88
#define COMPARE_AND_WRITE 0x89
#define WRITE_16 0x8a
#define READ_ATTRIBUTE 0x8c
#define WRITE_ATTRIBUTE 0x8d
#define VERIFY_16 0x8f
#define SYNCHRONIZE_CACHE_16 0x91
#define WRITE_SAME_16 0x93
#define SERVICE_ACTION_IN 0x9e
/* values for service action in */
#define SAI_READ_CAPACITY_16 0x10
#define SAI_GET_LBA_STATUS 0x12
#define SAI_REPORT_REFERRALS 0x13
/* values for VARIABLE_LENGTH_CMD service action codes
* see spc4r17 Section D.3.5, table D.7 and D.8 */
#define VLC_SA_RECEIVE_CREDENTIAL 0x1800
/* values for maintenance in */
#define MI_REPORT_IDENTIFYING_INFORMATION 0x05
#define MI_REPORT_TARGET_PGS 0x0a
#define MI_REPORT_ALIASES 0x0b
#define MI_REPORT_SUPPORTED_OPERATION_CODES 0x0c
#define MI_REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS 0x0d
#define MI_REPORT_PRIORITY 0x0e
#define MI_REPORT_TIMESTAMP 0x0f
#define MI_MANAGEMENT_PROTOCOL_IN 0x10
/* value for MI_REPORT_TARGET_PGS ext header */
#define MI_EXT_HDR_PARAM_FMT 0x20
/* values for maintenance out */
#define MO_SET_IDENTIFYING_INFORMATION 0x06
#define MO_SET_TARGET_PGS 0x0a
#define MO_CHANGE_ALIASES 0x0b
#define MO_SET_PRIORITY 0x0e
#define MO_SET_TIMESTAMP 0x0f
#define MO_MANAGEMENT_PROTOCOL_OUT 0x10
/* values for variable length command */
#define XDREAD_32 0x03
#define XDWRITE_32 0x04
#define XPWRITE_32 0x06
#define XDWRITEREAD_32 0x07
#define READ_32 0x09
#define VERIFY_32 0x0a
#define WRITE_32 0x0b
#define WRITE_SAME_32 0x0d
/* Values for T10/04-262r7 */
#define ATA_16 0x85 /* 16-byte pass-thru */
#define ATA_12 0xa1 /* 12-byte pass-thru */
/*
* SCSI command lengths
*/
#define SCSI_MAX_VARLEN_CDB_SIZE 260
/* defined in T10 SCSI Primary Commands-2 (SPC2) */
struct scsi_varlen_cdb_hdr {
__u8 opcode; /* opcode always == VARIABLE_LENGTH_CMD */
__u8 control;
__u8 misc[5];
__u8 additional_cdb_length; /* total cdb length - 8 */
__be16 service_action;
/* service specific data follows */
};
static inline unsigned
scsi_varlen_cdb_length(const void *hdr)
{
return ((struct scsi_varlen_cdb_hdr *)hdr)->additional_cdb_length + 8;
}
extern const unsigned char scsi_command_size_tbl[8];
#define COMMAND_SIZE(opcode) scsi_command_size_tbl[((opcode) >> 5) & 7]
static inline unsigned
scsi_command_size(const unsigned char *cmnd)
{
return (cmnd[0] == VARIABLE_LENGTH_CMD) ?
scsi_varlen_cdb_length(cmnd) : COMMAND_SIZE(cmnd[0]);
}
#ifdef CONFIG_ACPI
struct acpi_bus_type;
extern int
scsi_register_acpi_bus_type(struct acpi_bus_type *bus);
extern void
scsi_unregister_acpi_bus_type(struct acpi_bus_type *bus);
#endif
/*
* SCSI Architecture Model (SAM) Status codes. Taken from SAM-3 draft
* T10/1561-D Revision 4 Draft dated 7th November 2002.
*/
#define SAM_STAT_GOOD 0x00
#define SAM_STAT_CHECK_CONDITION 0x02
#define SAM_STAT_CONDITION_MET 0x04
#define SAM_STAT_BUSY 0x08
#define SAM_STAT_INTERMEDIATE 0x10
#define SAM_STAT_INTERMEDIATE_CONDITION_MET 0x14
#define SAM_STAT_RESERVATION_CONFLICT 0x18
#define SAM_STAT_COMMAND_TERMINATED 0x22 /* obsolete in SAM-3 */
#define SAM_STAT_TASK_SET_FULL 0x28
#define SAM_STAT_ACA_ACTIVE 0x30
#define SAM_STAT_TASK_ABORTED 0x40
/** scsi_status_is_good - check the status return.
*
* @status: the status passed up from the driver (including host and
* driver components)
*
* This returns true for known good conditions that may be treated as
* command completed normally
*/
static inline int scsi_status_is_good(int status)
{
/*
* FIXME: bit0 is listed as reserved in SCSI-2, but is
* significant in SCSI-3. For now, we follow the SCSI-2
* behaviour and ignore reserved bits.
*/
status &= 0xfe;
return ((status == SAM_STAT_GOOD) ||
(status == SAM_STAT_INTERMEDIATE) ||
(status == SAM_STAT_INTERMEDIATE_CONDITION_MET) ||
/* FIXME: this is obsolete in SAM-3 */
(status == SAM_STAT_COMMAND_TERMINATED));
}
/*
* Status codes. These are deprecated as they are shifted 1 bit right
* from those found in the SCSI standards. This causes confusion for
* applications that are ported to several OSes. Prefer SAM Status codes
* above.
*/
#define GOOD 0x00
#define CHECK_CONDITION 0x01
#define CONDITION_GOOD 0x02
#define BUSY 0x04
#define INTERMEDIATE_GOOD 0x08
#define INTERMEDIATE_C_GOOD 0x0a
#define RESERVATION_CONFLICT 0x0c
#define COMMAND_TERMINATED 0x11
#define QUEUE_FULL 0x14
#define ACA_ACTIVE 0x18
#define TASK_ABORTED 0x20
#define STATUS_MASK 0xfe
/*
* SENSE KEYS
*/
#define NO_SENSE 0x00
#define RECOVERED_ERROR 0x01
#define NOT_READY 0x02
#define MEDIUM_ERROR 0x03
#define HARDWARE_ERROR 0x04
#define ILLEGAL_REQUEST 0x05
#define UNIT_ATTENTION 0x06
#define DATA_PROTECT 0x07
#define BLANK_CHECK 0x08
#define COPY_ABORTED 0x0a
#define ABORTED_COMMAND 0x0b
#define VOLUME_OVERFLOW 0x0d
#define MISCOMPARE 0x0e
/*
* DEVICE TYPES
* Please keep them in 0x%02x format for $MODALIAS to work
*/
#define TYPE_DISK 0x00
#define TYPE_TAPE 0x01
#define TYPE_PRINTER 0x02
#define TYPE_PROCESSOR 0x03 /* HP scanners use this */
#define TYPE_WORM 0x04 /* Treated as ROM by our system */
#define TYPE_ROM 0x05
#define TYPE_SCANNER 0x06
#define TYPE_MOD 0x07 /* Magneto-optical disk -
* - treated as TYPE_DISK */
#define TYPE_MEDIUM_CHANGER 0x08
#define TYPE_COMM 0x09 /* Communications device */
#define TYPE_RAID 0x0c
#define TYPE_ENCLOSURE 0x0d /* Enclosure Services Device */
#define TYPE_RBC 0x0e
#define TYPE_OSD 0x11
#define TYPE_NO_LUN 0x7f
/* SCSI protocols; these are taken from SPC-3 section 7.5 */
enum scsi_protocol {
SCSI_PROTOCOL_FCP = 0, /* Fibre Channel */
SCSI_PROTOCOL_SPI = 1, /* parallel SCSI */
SCSI_PROTOCOL_SSA = 2, /* Serial Storage Architecture - Obsolete */
SCSI_PROTOCOL_SBP = 3, /* firewire */
SCSI_PROTOCOL_SRP = 4, /* Infiniband RDMA */
SCSI_PROTOCOL_ISCSI = 5,
SCSI_PROTOCOL_SAS = 6,
SCSI_PROTOCOL_ADT = 7, /* Media Changers */
SCSI_PROTOCOL_ATA = 8,
SCSI_PROTOCOL_UNSPEC = 0xf, /* No specific protocol */
};
/* Returns a human-readable name for the device */
extern const char * scsi_device_type(unsigned type);
/*
* standard mode-select header prepended to all mode-select commands
*/
struct ccs_modesel_head {
__u8 _r1; /* reserved */
__u8 medium; /* device-specific medium type */
__u8 _r2; /* reserved */
__u8 block_desc_length; /* block descriptor length */
__u8 density; /* device-specific density code */
__u8 number_blocks_hi; /* number of blocks in this block desc */
__u8 number_blocks_med;
__u8 number_blocks_lo;
__u8 _r3;
__u8 block_length_hi; /* block length for blocks in this desc */
__u8 block_length_med;
__u8 block_length_lo;
};
/*
* ScsiLun: 8 byte LUN.
*/
struct scsi_lun {
__u8 scsi_lun[8];
};
/*
* The Well Known LUNS (SAM-3) in our int representation of a LUN
*/
#define SCSI_W_LUN_BASE 0xc100
#define SCSI_W_LUN_REPORT_LUNS (SCSI_W_LUN_BASE + 1)
#define SCSI_W_LUN_ACCESS_CONTROL (SCSI_W_LUN_BASE + 2)
#define SCSI_W_LUN_TARGET_LOG_PAGE (SCSI_W_LUN_BASE + 3)
static inline int scsi_is_wlun(unsigned int lun)
{
return (lun & 0xff00) == SCSI_W_LUN_BASE;
}
/*
* MESSAGE CODES
*/
#define COMMAND_COMPLETE 0x00
#define EXTENDED_MESSAGE 0x01
#define EXTENDED_MODIFY_DATA_POINTER 0x00
#define EXTENDED_SDTR 0x01
#define EXTENDED_EXTENDED_IDENTIFY 0x02 /* SCSI-I only */
#define EXTENDED_WDTR 0x03
#define EXTENDED_PPR 0x04
#define EXTENDED_MODIFY_BIDI_DATA_PTR 0x05
#define SAVE_POINTERS 0x02
#define RESTORE_POINTERS 0x03
#define DISCONNECT 0x04
#define INITIATOR_ERROR 0x05
#define ABORT_TASK_SET 0x06
#define MESSAGE_REJECT 0x07
#define NOP 0x08
#define MSG_PARITY_ERROR 0x09
#define LINKED_CMD_COMPLETE 0x0a
#define LINKED_FLG_CMD_COMPLETE 0x0b
#define TARGET_RESET 0x0c
#define ABORT_TASK 0x0d
#define CLEAR_TASK_SET 0x0e
#define INITIATE_RECOVERY 0x0f /* SCSI-II only */
#define RELEASE_RECOVERY 0x10 /* SCSI-II only */
#define CLEAR_ACA 0x16
#define LOGICAL_UNIT_RESET 0x17
#define SIMPLE_QUEUE_TAG 0x20
#define HEAD_OF_QUEUE_TAG 0x21
#define ORDERED_QUEUE_TAG 0x22
#define IGNORE_WIDE_RESIDUE 0x23
#define ACA 0x24
#define QAS_REQUEST 0x55
/* Old SCSI2 names, don't use in new code */
#define BUS_DEVICE_RESET TARGET_RESET
#define ABORT ABORT_TASK_SET
/*
* Host byte codes
*/
#define DID_OK 0x00 /* NO error */
#define DID_NO_CONNECT 0x01 /* Couldn't connect before timeout period */
#define DID_BUS_BUSY 0x02 /* BUS stayed busy through time out period */
#define DID_TIME_OUT 0x03 /* TIMED OUT for other reason */
#define DID_BAD_TARGET 0x04 /* BAD target. */
#define DID_ABORT 0x05 /* Told to abort for some other reason */
#define DID_PARITY 0x06 /* Parity error */
#define DID_ERROR 0x07 /* Internal error */
#define DID_RESET 0x08 /* Reset by somebody. */
#define DID_BAD_INTR 0x09 /* Got an interrupt we weren't expecting. */
#define DID_PASSTHROUGH 0x0a /* Force command past mid-layer */
#define DID_SOFT_ERROR 0x0b /* The low level driver just wish a retry */
#define DID_IMM_RETRY 0x0c /* Retry without decrementing retry count */
#define DID_REQUEUE 0x0d /* Requeue command (no immediate retry) also
* without decrementing the retry count */
#define DID_TRANSPORT_DISRUPTED 0x0e /* Transport error disrupted execution
* and the driver blocked the port to
* recover the link. Transport class will
* retry or fail IO */
#define DID_TRANSPORT_FAILFAST 0x0f /* Transport class fastfailed the io */
#define DID_TARGET_FAILURE 0x10 /* Permanent target failure, do not retry on
* other paths */
#define DID_NEXUS_FAILURE 0x11 /* Permanent nexus failure, retry on other
* paths might yield different results */
#define DID_ALLOC_FAILURE 0x12 /* Space allocation on the device failed */
#define DID_MEDIUM_ERROR 0x13 /* Medium error */
#define DRIVER_OK 0x00 /* Driver status */
/*
* These indicate the error that occurred, and what is available.
*/
#define DRIVER_BUSY 0x01
#define DRIVER_SOFT 0x02
#define DRIVER_MEDIA 0x03
#define DRIVER_ERROR 0x04
#define DRIVER_INVALID 0x05
#define DRIVER_TIMEOUT 0x06
#define DRIVER_HARD 0x07
#define DRIVER_SENSE 0x08
/*
* Internal return values.
*/
#define NEEDS_RETRY 0x2001
#define SUCCESS 0x2002
#define FAILED 0x2003
#define QUEUED 0x2004
#define SOFT_ERROR 0x2005
#define ADD_TO_MLQUEUE 0x2006
#define TIMEOUT_ERROR 0x2007
#define SCSI_RETURN_NOT_HANDLED 0x2008
#define FAST_IO_FAIL 0x2009
/*
* Midlevel queue return values.
*/
#define SCSI_MLQUEUE_HOST_BUSY 0x1055
#define SCSI_MLQUEUE_DEVICE_BUSY 0x1056
#define SCSI_MLQUEUE_EH_RETRY 0x1057
#define SCSI_MLQUEUE_TARGET_BUSY 0x1058
/*
* Use these to separate status msg and our bytes
*
* These are set by:
*
* status byte = set from target device
* msg_byte = return status from host adapter itself.
* host_byte = set by low-level driver to indicate status.
* driver_byte = set by mid-level.
*/
#define status_byte(result) (((result) >> 1) & 0x7f)
#define msg_byte(result) (((result) >> 8) & 0xff)
#define host_byte(result) (((result) >> 16) & 0xff)
#define driver_byte(result) (((result) >> 24) & 0xff)
#define sense_class(sense) (((sense) >> 4) & 0x7)
#define sense_error(sense) ((sense) & 0xf)
#define sense_valid(sense) ((sense) & 0x80)
/*
* default timeouts
*/
#define FORMAT_UNIT_TIMEOUT (2 * 60 * 60 * HZ)
#define START_STOP_TIMEOUT (60 * HZ)
#define MOVE_MEDIUM_TIMEOUT (5 * 60 * HZ)
#define READ_ELEMENT_STATUS_TIMEOUT (5 * 60 * HZ)
#define READ_DEFECT_DATA_TIMEOUT (60 * HZ )
#define IDENTIFY_BASE 0x80
#define IDENTIFY(can_disconnect, lun) (IDENTIFY_BASE |\
((can_disconnect) ? 0x40 : 0) |\
((lun) & 0x07))
/*
* struct scsi_device::scsi_level values. For SCSI devices other than those
* prior to SCSI-2 (i.e. over 12 years old) this value is (resp[2] + 1)
* where "resp" is a byte array of the response to an INQUIRY. The scsi_level
* variable is visible to the user via sysfs.
*/
#define SCSI_UNKNOWN 0
#define SCSI_1 1
#define SCSI_1_CCS 2
#define SCSI_2 3
#define SCSI_3 4 /* SPC */
#define SCSI_SPC_2 5
#define SCSI_SPC_3 6
/*
* INQ PERIPHERAL QUALIFIERS
*/
#define SCSI_INQ_PQ_CON 0x00
#define SCSI_INQ_PQ_NOT_CON 0x01
#define SCSI_INQ_PQ_NOT_CAP 0x03
/*
* Here are some scsi specific ioctl commands which are sometimes useful.
*
* Note that include/linux/cdrom.h also defines IOCTL 0x5300 - 0x5395
*/
/* Used to obtain PUN and LUN info. Conflicts with CDROMAUDIOBUFSIZ */
#define SCSI_IOCTL_GET_IDLUN 0x5382
/* 0x5383 and 0x5384 were used for SCSI_IOCTL_TAGGED_{ENABLE,DISABLE} */
/* Used to obtain the host number of a device. */
#define SCSI_IOCTL_PROBE_HOST 0x5385
/* Used to obtain the bus number for a device */
#define SCSI_IOCTL_GET_BUS_NUMBER 0x5386
/* Used to obtain the PCI location of a device */
#define SCSI_IOCTL_GET_PCI 0x5387
/* Pull a u32 out of a SCSI message (using BE SCSI conventions) */
static inline __u32 scsi_to_u32(__u8 *ptr)
{
return (ptr[0]<<24) + (ptr[1]<<16) + (ptr[2]<<8) + ptr[3];
}
#endif /* _SCSI_SCSI_H */

View file

@ -0,0 +1,84 @@
#ifndef __SCSI_CMND_H_
#define __SCSI_CMND_H_
#include "us_usb.h"
#include "us_os_wrap_via_osdep_api.h"
#include <scsi/scsi.h>
#include <scsi/dma_direction.h>
#include <scatterlist/scatterlist.h>
/**
* define flash block size
*/
#define BLOCK_SIZE 512
struct scsi_data_buffer {
struct sg_table table;
unsigned char *data_buffer; /* Data buffer to store read data */
unsigned length;
int resid;
};
struct scsi_cmnd{
int result; /* Status code from lower level driver */
unsigned int channel,id,lun;
enum dma_data_direction sc_data_direction;
unsigned short cmd_len;
unsigned length;
_Sema cmnd_done;
int eh_eflags; /* Used by error handlr */
struct scsi_data_buffer sdb;
unsigned long sector;/* Sector address in LBA */
unsigned int count;/* Number of sectors to read */
void *request_buffer;
/* These elements define the operation we are about to perform */
#define MAX_COMMAND_SIZE 16
unsigned char cmnd[MAX_COMMAND_SIZE];
#define SCSI_SENSE_BUFFERSIZE 96
unsigned char *sense_buffer; /* obtained by REQUEST SENSE
* when CHECK CONDITION is
* received on original command
* (auto-sense) */
/* Low-level done function - can be used by low-level driver to point
* to completion function. Not used by mid/upper level code. */
void (*scsi_done) (struct scsi_cmnd *);
unsigned underflow; /* Return error if less than
this amount is transferred */
};
static inline unsigned scsi_sg_count(struct scsi_cmnd *cmd)
{
return cmd->sdb.table.nents;
}
static inline struct scatterlist *scsi_sglist(struct scsi_cmnd *cmd)
{
return cmd->sdb.table.sgl;
}
static inline void scsi_set_resid(struct scsi_cmnd *cmd, int resid)
{
cmd->sdb.resid = resid;
}
//
static inline int scsi_get_resid(struct scsi_cmnd *cmd)
{
return cmd->sdb.resid;
}
static inline unsigned scsi_bufflen(struct scsi_cmnd *cmd)
{
return cmd->sdb.length;
}
extern int scsi_cmnd_execute(char cmnd, unsigned char * _buff,
unsigned long _sector, unsigned int _count);
#endif

View file

@ -0,0 +1,52 @@
#ifndef _SCSI_EH_H_
#define _SCSI_EH_H_
#include "scsi/scsi_cmnd.h"
#include "dma_direction.h"
#define BLK_MAX_CDB 16
/*
* This is a slightly modified SCSI sense "descriptor" format header.
* The addition is to allow the 0x70 and 0x71 response codes. The idea
* is to place the salient data from either "fixed" or "descriptor" sense
* format into one structure to ease application processing.
*
* The original sense buffer should be kept around for those cases
* in which more information is required (e.g. the LBA of a MEDIUM ERROR).
*/
struct scsi_sense_hdr { /* See SPC-3 section 4.5 */
u8 response_code; /* permit: 0x0, 0x70, 0x71, 0x72, 0x73 */
u8 sense_key;
u8 asc;
u8 ascq;
u8 byte4;
u8 byte5;
u8 byte6;
u8 additional_length; /* always 0 for fixed sense format */
};
static inline int scsi_sense_valid(struct scsi_sense_hdr *sshdr)
{
if (!sshdr)
return 0;
return (sshdr->response_code & 0x70) == 0x70;
}
struct scsi_eh_save {
/* saved state */
int result;
enum dma_data_direction data_direction;
unsigned underflow;
unsigned char cmd_len;
// unsigned char prot_op;
unsigned char cmnd[BLK_MAX_CDB];
struct scsi_data_buffer sdb;
// struct request *next_rq;
/* new command support */
unsigned char eh_cmnd[BLK_MAX_CDB];
// struct scatterlist sense_sgl;
};
const u8 * scsi_sense_desc_find(const u8 * sense_buffer, int sb_len,
int desc_type);
#endif

View file

@ -0,0 +1,78 @@
#ifndef __STORAGE_H
#define __STORAGE_H
#include "us_os_wrap_via_osdep_api.h"
/* Storage subclass codes */
#define USB_SC_RBC 0x01 /* Typically, flash devices */
#define USB_SC_8020 0x02 /* CD-ROM */
#define USB_SC_QIC 0x03 /* QIC-157 Tapes */
#define USB_SC_UFI 0x04 /* Floppy */
#define USB_SC_8070 0x05 /* Removable media */
#define USB_SC_SCSI 0x06 /* Transparent */
#define USB_SC_LOCKABLE 0x07 /* Password-protected */
#define USB_SC_ISD200 0xf0 /* ISD200 ATA */
#define USB_SC_CYP_ATACB 0xf1 /* Cypress ATACB */
#define USB_SC_DEVICE 0xff /* Use device's value */
/* Storage protocol codes */
#define USB_PR_CBI 0x00 /* Control/Bulk/Interrupt */
#define USB_PR_CB 0x01 /* Control/Bulk w/o interrupt */
#define USB_PR_BULK 0x50 /* bulk only */
#define USB_PR_UAS 0x62 /* USB Attached SCSI */
#define USB_PR_USBAT 0x80 /* SCM-ATAPI bridge */
#define USB_PR_EUSB_SDDR09 0x81 /* SCM-SCSI bridge for SDDR-09 */
#define USB_PR_SDDR55 0x82 /* SDDR-55 (made up) */
#define USB_PR_DPCM_USB 0xf0 /* Combination CB/SDDR09 */
#define USB_PR_FREECOM 0xf1 /* Freecom */
#define USB_PR_DATAFAB 0xf2 /* Datafab chipsets */
#define USB_PR_JUMPSHOT 0xf3 /* Lexar Jumpshot */
#define USB_PR_ALAUDA 0xf4 /* Alauda chipsets */
#define USB_PR_KARMA 0xf5 /* Rio Karma */
#define USB_PR_DEVICE 0xff /* Use device's value */
/*
* Bulk only data structures
*/
/* command block wrapper */
struct bulk_cb_wrap {
__le32 Signature; /* contains 'USBC', denote bulk_cb_wrap */
__u32 Tag; /* unique per command id */
__le32 DataTransferLength; /* size of data for transfer */
__u8 Flags; /* data transfer direction */
__u8 Lun; /* LUN normally 0, (which command block is sent) */
__u8 Length; /* length of the CDB */
__u8 CDB[16]; /* max command */
};
#define US_BULK_CB_WRAP_LEN 31
#define US_BULK_CB_SIGN 0x43425355 /*spells out USBC */
#define US_BULK_FLAG_IN (1 << 7)
#define US_BULK_FLAG_OUT 0
/* command status wrapper */
struct bulk_cs_wrap {
__le32 Signature; /* should = 'USBS' */
__u32 Tag; /* same as original command, echoed by the device as received */
__le32 Residue; /* amount not transferred */
__u8 Status; /* execute command status */
};
#define US_BULK_CS_WRAP_LEN 13
#define US_BULK_CS_SIGN 0x53425355 /* spells out 'USBS' */
// execute command status
#define US_BULK_STAT_OK 0
#define US_BULK_STAT_FAIL 1
#define US_BULK_STAT_PHASE 2
/* bulk-only class specific requests */
#define US_BULK_RESET_REQUEST 0xff
#define US_BULK_GET_MAX_LUN 0xfe
#endif

View file

@ -0,0 +1,102 @@
/* Driver for USB Mass Storage compliant devices
* Transport Functions Header File
*
* Current development and maintenance by:
* (c) 1999, 2000 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
*
* This driver is based on the 'USB Mass Storage Class' document. This
* describes in detail the protocol used to communicate with such
* devices. Clearly, the designers had SCSI and ATAPI commands in
* mind when they created this document. The commands are all very
* similar to commands in the SCSI-II and ATAPI specifications.
*
* It is important to note that in a number of cases this class
* exhibits class-specific exemptions from the USB specification.
* Notably the usage of NAK, STALL and ACK differs from the norm, in
* that they are used to communicate wait, failed and OK on commands.
*
* Also, for certain devices, the interrupt endpoint is used to convey
* status of a command.
*
* Please see http://www.one-eyed-alien.net/~mdharm/linux-usb for more
* information about this driver.
*
* 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, 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.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _US_TRANSPORT_H_
#define _US_TRANSPORT_H_
#if 0
#include <linux/blkdev.h>
#endif
/*
* usb_stor_bulk_transfer_xxx() return codes, in order of severity
*/
#define USB_STOR_XFER_GOOD 0 /* good transfer */
#define USB_STOR_XFER_SHORT 1 /* transferred less than expected */
#define USB_STOR_XFER_STALLED 2 /* endpoint stalled */
#define USB_STOR_XFER_LONG 3 /* device tried to send too much */
#define USB_STOR_XFER_ERROR 4 /* transfer died in the middle */
/*
* Transport return codes
*/
#define USB_STOR_TRANSPORT_GOOD 0 /* Transport good, command good */
#define USB_STOR_TRANSPORT_FAILED 1 /* Transport good, command failed */
#define USB_STOR_TRANSPORT_NO_SENSE 2 /* Command failed, no auto-sense */
#define USB_STOR_TRANSPORT_ERROR 3 /* Transport bad (i.e. device dead) */
/*
* We used to have USB_STOR_XFER_ABORTED and USB_STOR_TRANSPORT_ABORTED
* return codes. But now the transport and low-level transfer routines
* treat an abort as just another error (-ENOENT for a cancelled URB).
* It is up to the invoke_transport() function to test for aborts and
* distinguish them from genuine communication errors.
*/
/*
* CBI accept device specific command
*/
#define US_CBI_ADSC 0
//extern int usb_stor_CB_transport(struct scsi_cmnd *, struct us_data*);
//extern int usb_stor_CB_reset(struct us_data*);
//
//extern int usb_stor_Bulk_transport(struct scsi_cmnd *, struct us_data*);
//extern int usb_stor_Bulk_max_lun(struct us_data*);
//extern int usb_stor_Bulk_reset(struct us_data*);
//
//extern void usb_stor_invoke_transport(struct scsi_cmnd *, struct us_data*);
//extern void usb_stor_stop_transport(struct us_data*);
//extern int usb_stor_control_msg(struct us_data *us, unsigned int pipe,
// u8 request, u8 requesttype, u16 value, u16 index,
// void *data, u16 size, int timeout);
//extern int usb_stor_clear_halt(struct us_data *us, unsigned int pipe);
//
//extern int usb_stor_ctrl_transfer(struct us_data *us, unsigned int pipe,
// u8 request, u8 requesttype, u16 value, u16 index,
// void *data, u16 size);
//extern int usb_stor_bulk_transfer_buf(struct us_data *us, unsigned int pipe,
// void *buf, unsigned int length, unsigned int *act_len);
//extern int usb_stor_bulk_transfer_sg(struct us_data *us, unsigned int pipe,
// void *buf, unsigned int length, int use_sg, int *residual);
//extern int usb_stor_bulk_srb(struct us_data* us, unsigned int pipe,
// struct scsi_cmnd* srb);
//
//extern int usb_stor_port_reset(struct us_data *us);
#endif

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,32 @@
#ifndef __UNUSUAL_USBAT_H
#define __UNUSUAL_USBAT_H
#if defined(CONFIG_USB_STORAGE_USBAT) || \
defined(CONFIG_USB_STORAGE_USBAT_MODULE)
UNUSUAL_DEV( 0x03f0, 0x0207, 0x0001, 0x0001,
"HP",
"CD-Writer+ 8200e",
USB_SC_8070, USB_PR_USBAT, init_usbat_cd, 0),
UNUSUAL_DEV( 0x03f0, 0x0307, 0x0001, 0x0001,
"HP",
"CD-Writer+ CD-4e",
USB_SC_8070, USB_PR_USBAT, init_usbat_cd, 0),
UNUSUAL_DEV( 0x04e6, 0x1010, 0x0000, 0x9999,
"Shuttle/SCM",
"USBAT-02",
USB_SC_SCSI, USB_PR_USBAT, init_usbat_flash,
US_FL_SINGLE_LUN),
UNUSUAL_DEV( 0x0781, 0x0005, 0x0005, 0x0005,
"Sandisk",
"ImageMate SDDR-05b",
USB_SC_SCSI, USB_PR_USBAT, init_usbat_flash,
US_FL_SINGLE_LUN),
#endif /* defined(CONFIG_USB_STORAGE_USBAT) || ... */
#endif

View file

@ -0,0 +1,26 @@
#ifndef _US_DEBUG_H_
#define _US_DEBUG_H_
#include "diag.h"
#define US_DEBUG 0
#define US_DRIVER "US_DRIVER"
#if US_DEBUG
#define US_INFO(fmt, args...) DBG_8195A("\n\r[%s]%s: " fmt, US_DRIVER, __FUNCTION__, ## args)
#define US_ERR(fmt, args...) DBG_8195A("\n\r[%s]%s: " fmt, US_DRIVER,__FUNCTION__, ## args)
#define US_WARN(fmt, args...) DBG_8195A("\n\r[%s]%s: " fmt, US_DRIVER,__FUNCTION__, ## args)
#define FUN_ENTER DBG_8195A("\n\r[%s]%s ==>\n", US_DRIVER,__FUNCTION__)
#define FUN_EXIT DBG_8195A("\n\r[%s]%s <==\n", US_DRIVER,__FUNCTION__)
#define FUN_TRACE DBG_8195A("\n\r[%s]%s:%d \n", US_DRIVER,__FUNCTION__, __LINE__)
#else
#define US_INFO(fmt, args...)
#define US_ERR(fmt, args...) DBG_8195A("\n\r[%s]%s: " fmt, US_DRIVER,__FUNCTION__, ## args)
#define US_WARN(fmt, args...)
#define FUN_ENTER
#define FUN_EXIT
#define FUN_TRACE
#endif
#endif /* _US_DEBUG_H_ */

View file

@ -0,0 +1,14 @@
#include "usb.h"
#include "transport.h"
/* This places the Shuttle/SCM USB<->SCSI bridge devices in multi-target
* mode */
int usb_stor_euscsi_init(struct us_data *us);
/* This function is required to activate all four slots on the UCR-61S2B
* flash reader */
int usb_stor_ucr61s2b_init(struct us_data *us);
/* This places the HUAWEI E220 devices in multi-port mode */
int usb_stor_huawei_e220_init(struct us_data *us);

View file

@ -0,0 +1,34 @@
#ifndef __US_INTF_H_
#define __US_INTF_H_
#include "basic_types.h"
typedef enum
{
MSC_OK = 0,
MSC_NOT_READY,
MSC_W_PROTECT,
MSC_ERROR,
}MSC_RESULT;
extern MSC_RESULT us_init(void);
extern MSC_RESULT us_isready (void);
extern MSC_RESULT us_getStatus(void);
extern MSC_RESULT us_getmaxlun (u8* lun_num);
extern MSC_RESULT us_unitisready (u8 lun);
extern MSC_RESULT us_inquiry (u8 *pbuf);
extern MSC_RESULT us_getcap(u32 *last_blk_addr, u32 *block_size);
extern MSC_RESULT us_read_blocks( u8 *pbuf, u32 sector, u32 count);
extern MSC_RESULT us_write_blocks( const u8 *pbuf, u32 sector, u32 count);
// indicate usb storage driver status
extern bool USB_STORAGE_READY;
#endif

View file

@ -0,0 +1,313 @@
/*
* umsc_os_wrap_via_osdep_api.h
*
* Created on: Sep 5, 2014
* Author: jimmysqf
*/
#ifndef US_OS_WRAP_VIA_OSDEP_API_H_
#define US_OS_WRAP_VIA_OSDEP_API_H_
#include "basic_types.h"
#include "osdep_api.h"
#define GFP_KERNEL 1
#define GFP_ATOMIC 1
typedef unsigned int gfp_t;
/* misc items */
#ifndef ssize_t
#define ssize_t SSIZE_T
#endif
#ifndef size_t
#define size_t SIZE_T
#endif
#ifndef __user
#define __user
#endif
#ifndef loff_t
#define loff_t long
#endif
#ifndef __u8
#define __u8 u8
#endif
#ifndef __u16
#define __u16 u16
#endif
#ifndef __u32
#define __u32 u32
#endif
#ifndef __u64
#define __u64 u64
#endif
#ifndef __s8
#define __s8 s8
#endif
#ifndef __s16
#define __s16 s16
#endif
#ifndef __s32
#define __s32 s32
#endif
#ifndef __s64
#define __s64 s64
#endif
typedef __u16 __le16;
typedef __u16 __be16;
typedef __u32 __le32;
typedef __u32 __be32;
typedef __u64 __le64;
typedef __u64 __be64;
typedef __u16 __sum16;
typedef __u32 __wsum;
#ifndef cpu_to_le32
#define cpu_to_le32(x) rtk_cpu_to_le32(x)
#endif
#ifndef le32_to_cpu
#define le32_to_cpu(x) rtk_le32_to_cpu(x)
#endif
#ifndef cpu_to_le16
#define cpu_to_le16(x) rtk_cpu_to_le16(x)
#endif
#ifndef le16_to_cpu
#define le16_to_cpu(x) rtk_le16_to_cpu(x)
#endif
#ifndef cpu_to_be32
#define cpu_to_be32(x) rtk_cpu_to_be32(x)
#endif
#ifndef be32_to_cpu
#define be32_to_cpu(x) rtk_be32_to_cpu(x)
#endif
#ifndef cpu_to_be16
#define cpu_to_be16(x) rtk_cpu_to_be16(x)
#endif
#ifndef be16_to_cpu
#define be16_to_cpu(x) rtk_be16_to_cpu(x)
#endif
#ifndef DIV_ROUND_UP
#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
#endif
#ifndef BITS_PER_LONG
#define BITS_PER_LONG (32)
#endif
#ifndef BITS_PER_LONG_LONG
#define BITS_PER_LONG_LONG (32)
#endif
#ifndef BIT
#define BIT(nr) (1UL << (nr))
#endif
#ifndef BIT_ULL
#define BIT_ULL(nr) (1ULL << (nr))
#endif
#ifndef BIT_MASK
#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
#endif
#ifndef BIT_WORD
#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
#endif
#ifndef BIT_ULL_MASK
#define BIT_ULL_MASK(nr) (1ULL << ((nr) % BITS_PER_LONG_LONG))
#endif
#ifndef BIT_ULL_WORD
#define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG)
#endif
#ifndef BITS_PER_BYTE
#define BITS_PER_BYTE (8)
#endif
#ifndef BITS_TO_LONGS
#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
#endif
#ifndef min
#define min(x, y) ((x) < (y) ? (x) : (y))
#endif
#ifndef max
#define max(x, y) ((x) > (y) ? (x) : (y))
#endif
#ifndef min_t
#define min_t(type, x, y) ({ \
type __min1 = (x); \
type __min2 = (y); \
__min1 < __min2 ? __min1 : __min2; })
#endif
#ifndef max_t
#define max_t(type, x, y) ({ \
type __max1 = (x); \
type __max2 = (y); \
__max1 > __max2 ? __max1 : __max2; })
#endif
/**
* container_of - cast a member of a structure out to the containing structure
* @p(ptr): the pointer to the member.
* @t(type): the type of the container struct this is embedded in.
* @m(member): the name of the member within the struct.
*
*/
#ifndef container_of
#define container_of(ptr, type, member) \
((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member)))
#endif
/**
* test_bit - Determine whether a bit is set
* @nr: bit number to test
* @addr: Address to start counting from
*/
static inline int test_bit(int nr, const volatile unsigned long *addr)
{
return ((1UL << (nr & 31)) & (addr[nr >> 5])) != 0;
}
/**
* set_bit - Atomically set a bit in memory
* @nr: the bit to set
* @addr: the address to start counting from
*
* This function is atomic and may not be reordered. See __set_bit()
* if you do not require the atomic guarantees.
*
* Note: there are no guarantees that this function will not be reordered
* on non x86 architectures, so if you are writing portable code,
* make sure not to rely on its reordering guarantees.
*
* Note that @nr may be almost arbitrarily large; this function is not
* restricted to acting on a single-word quantity.
*/
static inline void set_bit(int nr, volatile unsigned long *addr)
{
unsigned long mask = BIT_MASK(nr);
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
SaveAndCli();
*p |= mask;
RestoreFlags();
}
/**
* clear_bit - Clears a bit in memory
* @nr: Bit to clear
* @addr: Address to start counting from
*
* clear_bit() is atomic and may not be reordered. However, it does
* not contain a memory barrier, so if it is used for locking purposes,
* you should call smp_mb__before_clear_bit() and/or smp_mb__after_clear_bit()
* in order to ensure changes are visible on other processors.
*/
static inline void clear_bit(int nr, volatile unsigned long *addr)
{
unsigned long mask = BIT_MASK(nr);
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
SaveAndCli();
*p &= ~mask;
RestoreFlags();
}
/**
* change_bit - Toggle a bit in memory
* @nr: Bit to change
* @addr: Address to start counting from
*
* change_bit() is atomic and may not be reordered. It may be
* reordered on other architectures than x86.
* Note that @nr may be almost arbitrarily large; this function is not
* restricted to acting on a single-word quantity.
*/
static inline void change_bit(int nr, volatile unsigned long *addr)
{
unsigned long mask = BIT_MASK(nr);
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
SaveAndCli();
*p ^= mask;
RestoreFlags();
}
/**
* test_and_set_bit - Set a bit and return its old value
* @nr: Bit to set
* @addr: Address to count from
*
* This operation is atomic and cannot be reordered.
* It may be reordered on other architectures than x86.
* It also implies a memory barrier.
*/
static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
{
unsigned long mask = BIT_MASK(nr);
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
unsigned long old;
SaveAndCli();
old = *p;
*p = old | mask;
RestoreFlags();
return (old & mask) != 0;
}
/**
* test_and_clear_bit - Clear a bit and return its old value
* @nr: Bit to clear
* @addr: Address to count from
*
* This operation is atomic and cannot be reordered.
* It can be reorderdered on other architectures other than x86.
* It also implies a memory barrier.
*/
static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
{
unsigned long mask = BIT_MASK(nr);
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
unsigned long old;
SaveAndCli();
old = *p;
*p = old & ~mask;
RestoreFlags();
return (old & mask) != 0;
}
/**
* test_and_change_bit - Change a bit and return its old value
* @nr: Bit to change
* @addr: Address to count from
*
* This operation is atomic and cannot be reordered.
* It also implies a memory barrier.
*/
static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
{
unsigned long mask = BIT_MASK(nr);
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
unsigned long old;
SaveAndCli();
old = *p;
*p = old ^ mask;
RestoreFlags();
return (old & mask) != 0;
}
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#endif
#endif /* US_OS_WRAP_VIA_OSDEP_API_H_ */

View file

@ -0,0 +1,19 @@
#ifndef _US_SCSI_H
#define _US_SCSI_H
/**
* define transfer length
*/
#define TRANS_LEN_READ_10 512
#define TRANS_LEN_WRITE_10 512
#define TRANS_LEN_INQUIRY 36
#define TRANS_LEN_TEST_UNIT_READY 0
#define TRANS_LEN_READ_CAPACITY_10 8
#define TRANS_LEN_READ_CAPACITY_16 12
#define TRANS_LEN_REQUEST_SENSE 18
#define TRANS_LEN_MODE_SENSE 192
extern int scsi_cmnd_execute(char cmnd, unsigned char * _buff,
unsigned long _sector, unsigned int _count);
#endif

View file

@ -0,0 +1,28 @@
#ifndef _US_STRINGS_H
#define _US_STRINGS_H
/* description of the sense key values */
static const char * const snstext[] = {
"No Sense", /* 0: There is no sense information */
"Recovered Error", /* 1: The last command completed successfully
but used error correction */
"Not Ready", /* 2: The addressed target is not ready */
"Medium Error", /* 3: Data error detected on the medium */
"Hardware Error", /* 4: Controller or device failure */
"Illegal Request", /* 5: Error in request */
"Unit Attention", /* 6: Removable medium was changed, or
the target has been reset, or ... */
"Data Protect", /* 7: Access to the data is blocked */
"Blank Check", /* 8: Reached unexpected written or unwritten
region of the medium */
"Vendor Specific(9)",
"Copy Aborted", /* A: COPY or COMPARE was aborted */
"Aborted Command", /* B: The target aborted the command */
"Equal", /* C: A SEARCH DATA command found data equal,
reserved in SPC-4 rev 36 */
"Volume Overflow", /* D: Medium full with still data to be written */
"Miscompare", /* E: Source data and data on the medium
do not agree */
"Completed", /* F: command completed sense data reported,
may occur for successful command */
};
#endif

View file

@ -0,0 +1,67 @@
/* Driver for USB Mass Storage compliant devices
* Transport Functions Header File
*/
#ifndef _US_TRANSPORT_H_
#define _US_TRANSPORT_H_
/*
* usb_stor_bulk_transfer_xxx() return codes, in order of severity
*/
#define USB_STOR_XFER_GOOD 0 /* good transfer */
#define USB_STOR_XFER_SHORT 1 /* transferred less than expected */
#define USB_STOR_XFER_STALLED 2 /* endpoint stalled */
#define USB_STOR_XFER_LONG 3 /* device tried to send too much */
#define USB_STOR_XFER_ERROR 4 /* transfer died in the middle */
/*
* Transport return codes
*/
#define USB_STOR_TRANSPORT_GOOD 0 /* Transport good, command good */
#define USB_STOR_TRANSPORT_FAILED 1 /* Transport good, command failed */
#define USB_STOR_TRANSPORT_NO_SENSE 2 /* Command failed, no auto-sense */
#define USB_STOR_TRANSPORT_ERROR 3 /* Transport bad (i.e. device dead) */
/*
* We used to have USB_STOR_XFER_ABORTED and USB_STOR_TRANSPORT_ABORTED
* return codes. But now the transport and low-level transfer routines
* treat an abort as just another error (-ENOENT for a cancelled URB).
* It is up to the invoke_transport() function to test for aborts and
* distinguish them from genuine communication errors.
*/
/*
* CBI accept device specific command
*/
#define US_CBI_ADSC 0
//extern int usb_stor_CB_transport(struct scsi_cmnd *, struct us_data*);
//extern int usb_stor_CB_reset(struct us_data*);
//
//extern int usb_stor_Bulk_transport(struct scsi_cmnd *, struct us_data*);
//extern int usb_stor_Bulk_max_lun(struct us_data*);
//extern int usb_stor_Bulk_reset(struct us_data*);
//
//extern void usb_stor_invoke_transport(struct scsi_cmnd *, struct us_data*);
//extern void usb_stor_stop_transport(struct us_data*);
//extern int usb_stor_control_msg(struct us_data *us, unsigned int pipe,
// u8 request, u8 requesttype, u16 value, u16 index,
// void *data, u16 size, int timeout);
//extern int usb_stor_clear_halt(struct us_data *us, unsigned int pipe);
//
//extern int usb_stor_ctrl_transfer(struct us_data *us, unsigned int pipe,
// u8 request, u8 requesttype, u16 value, u16 index,
// void *data, u16 size);
//extern int usb_stor_bulk_transfer_buf(struct us_data *us, unsigned int pipe,
// void *buf, unsigned int length, unsigned int *act_len);
//extern int usb_stor_bulk_transfer_sg(struct us_data *us, unsigned int pipe,
// void *buf, unsigned int length, int use_sg, int *residual);
//extern int usb_stor_bulk_srb(struct us_data* us, unsigned int pipe,
// struct scsi_cmnd* srb);
//
//extern int usb_stor_port_reset(struct us_data *us);
#endif

View file

@ -0,0 +1,245 @@
#ifndef _US_USB_H_
#define _US_USB_H_
#include "usb.h"
#include "us_os_wrap_via_osdep_api.h"
#include "us_debug.h"
//#include "sg.h"
struct us_data;
struct scsi_cmnd;
#define CONFIG_SG 0
#define CONFIG_DMA 0
/*
* Unusual device list definitions
*/
struct us_unusual_dev {
const char* vendorName;
const char* productName;
__u8 useProtocol;
__u8 useTransport;
int (*initFunction)(struct us_data *);
};
/* Flag definitions: these entries are static */
#define US_FL_SINGLE_LUN 0x00000001 /* allow access to only LUN 0 */
//#define US_FL_MODE_XLATE 0 /* [no longer used] */
#define US_FL_NEED_OVERRIDE 0x00000004 /* unusual_devs entry is necessary */
//#define US_FL_IGNORE_SER 0 /* [no longer used] */
#define US_FL_SCM_MULT_TARG 0x00000020 /* supports multiple targets */
#define US_FL_FIX_INQUIRY 0x00000040 /* INQUIRY response needs faking */
#define US_FL_FIX_CAPACITY 0x00000080 /* READ CAPACITY response too big */
#define US_FL_IGNORE_RESIDUE 0x00000100 /* reported residue is wrong */
#define US_FL_BULK32 0x00000200 /* Uses 32-byte CBW length */
/* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
#define US_FLIDX_URB_ACTIVE 0 /* current_urb is in use */
#define US_FLIDX_SG_ACTIVE 1 /* current_sg is in use */
#define US_FLIDX_ABORTING 2 /* abort is in progress */
#define US_FLIDX_DISCONNECTING 3 /* disconnect in progress */
#define US_FLIDX_RESETTING 4 /* device reset in progress */
#define US_FLIDX_TIMED_OUT 5 /* SCSI midlayer timed out */
#define US_FLIDX_SCAN_PENDING 6 /* scanning not yet done */
#define US_FLIDX_REDO_READ10 7 /* redo READ(10) command */
#define US_FLIDX_READ10_WORKED 8 /* previous READ(10) succeeded */
#define USB_STOR_STRING_LEN 32
/*
* We provide a DMA-mapped I/O buffer for use with small USB transfers.
* It turns out that CB[I] needs a 12-byte buffer and Bulk-only needs a
* 31-byte buffer. But Freecom needs a 64-byte buffer, so that's the
* size we'll allocate.
*/
#define US_IOBUF_SIZE 64 /* Size of the DMA-mapped I/O buffer */
#define US_SENSE_SIZE 18 /* Size of the autosense data buffer */
typedef int (*trans_cmnd)(struct scsi_cmnd *, struct us_data*);
typedef int (*trans_reset)(struct us_data*);
typedef void (*proto_cmnd)(struct scsi_cmnd*, struct us_data*);
typedef void (*extra_data_destructor)(void *); /* extra data destructor */
typedef void (*pm_hook)(struct us_data *, int); /* power management hook */
#define US_SUSPEND 0
#define US_RESUME 1
/* we allocate one of these for every device that we remember */
struct us_data {
/* The device we're working with
* It's important to note:
* (o) you must hold dev_mutex to change pusb_dev
*/
_Mutex dev_mutex;
struct usb_device *pusb_dev; /* this usb_device */
struct usb_interface *pusb_intf; /* this interface */
struct us_unusual_dev *unusual_dev; /* device-filter entry */
unsigned long fflags; /* fixed flags from filter */
unsigned long dflags; /* dynamic atomic bitflags */
unsigned int send_bulk_pipe; /* cached pipe values */
unsigned int recv_bulk_pipe;
unsigned int send_ctrl_pipe;
unsigned int recv_ctrl_pipe;
unsigned int recv_intr_pipe;
/* information about the device */
char *transport_name;
char *protocol_name;
__le32 bcs_signature;
u8 subclass;
u8 protocol;
u8 max_lun; // max number of logical unit (0,1,2,3...)
u8 ifnum; /* interface number */
u8 ep_bInterval; /* interrupt interval */
/* function pointers for this device */
trans_cmnd transport; /* transport function */
trans_reset transport_reset; /* transport device reset */
proto_cmnd proto_handler; /* protocol handler */
/* SCSI interfaces */
struct scsi_cmnd *srb; /* current srb */
unsigned int tag; /* current dCBWTag */
/* control and bulk communications data */
struct urb *current_urb; /* USB requests */
struct usb_ctrlrequest *cr; /* control requests */
// struct usb_sg_request current_sg; /* scatter-gather req. */
unsigned char *iobuf; /* I/O buffer */
dma_addr_t iobuf_dma; /* buffer DMA addresses */
xTaskHandle ctl_task; /*the control task handle*/
/* mutual exclusion and synchronization structures */
_Sema cmnd_ready; /* to sleep thread on */
_Mutex notify; /* thread begin/end */
unsigned no_sg_constraint:1; /* no sg constraint */
unsigned sg_tablesize; /* 0 or largest number of sg list entries */
/* subdriver information */
void *extra; /* Any extra data */
};
/* Convert between us_data and the corresponding Scsi_Host */
//static inline struct Scsi_Host *us_to_host(struct us_data *us) {
// return container_of((void *) us, struct Scsi_Host, hostdata);
//}
//static inline struct us_data *host_to_us(struct Scsi_Host *host) {
// return (struct us_data *) host->hostdata;
//}
/* Function to fill an inquiry response. See usb.c for details */
extern void fill_inquiry_response(struct us_data *us,
unsigned char *data, unsigned int data_len);
/* The scsi_lock() and scsi_unlock() macros protect the sm_state and the
* single queue element srb for write access */
//#define scsi_unlock(host) spin_unlock_irq(host->host_lock)
//#define scsi_lock(host) spin_lock_irq(host->host_lock)
#define scsi_unlock(host) spin_unlock(host->host_lock)
#define scsi_lock(host) spin_lock(host->host_lock)
/* General routines provided by the usb-storage standard core */
#ifdef CONFIG_PM
extern int usb_stor_suspend(struct usb_interface *iface, pm_message_t message);
extern int usb_stor_resume(struct usb_interface *iface);
extern int usb_stor_reset_resume(struct usb_interface *iface);
#else
#define usb_stor_suspend NULL
#define usb_stor_resume NULL
#define usb_stor_reset_resume NULL
#endif
extern int usb_stor_pre_reset(struct usb_interface *iface);
extern int usb_stor_post_reset(struct usb_interface *iface);
extern int usb_stor_probe1(struct us_data *us,
struct usb_interface *intf,
const struct usb_device_id *id,
struct us_unusual_dev *unusual_dev);
extern int usb_stor_probe2(struct us_data *us);
extern void usb_stor_disconnect(struct usb_interface *intf);
extern void usb_stor_adjust_quirks(struct usb_device *dev,
unsigned long *fflags);
// the follow definition should be prot to usb.h for other usb device
/* USB autosuspend and autoresume */
#ifdef CONFIG_PM_RUNTIME
extern void usb_enable_autosuspend(struct usb_device *udev);
extern void usb_disable_autosuspend(struct usb_device *udev);
extern int usb_autopm_get_interface(struct usb_interface *intf);
extern void usb_autopm_put_interface(struct usb_interface *intf);
extern int usb_autopm_get_interface_async(struct usb_interface *intf);
extern void usb_autopm_put_interface_async(struct usb_interface *intf);
extern void usb_autopm_get_interface_no_resume(struct usb_interface *intf);
extern void usb_autopm_put_interface_no_suspend(struct usb_interface *intf);
static inline void usb_mark_last_busy(struct usb_device *udev)
{
pm_runtime_mark_last_busy(&udev->dev);
}
#else
static inline int usb_enable_autosuspend(struct usb_device *udev)
{ return 0; }
static inline int usb_disable_autosuspend(struct usb_device *udev)
{ return 0; }
static inline int usb_autopm_get_interface(struct usb_interface *intf)
{ return 0; }
static inline int usb_autopm_get_interface_async(struct usb_interface *intf)
{ return 0; }
static inline void usb_autopm_put_interface(struct usb_interface *intf)
{ }
static inline void usb_autopm_put_interface_async(struct usb_interface *intf)
{ }
static inline void usb_autopm_get_interface_no_resume(
struct usb_interface *intf)
{ }
static inline void usb_autopm_put_interface_no_suspend(
struct usb_interface *intf)
{ }
static inline void usb_mark_last_busy(struct usb_device *udev)
{ }
#endif
/* USB port reset for device reinitialization */
extern int usb_reset_device(struct usb_device *dev);
extern void usb_queue_reset_device(struct usb_interface *dev);
extern void *usb_alloc_coherent(struct usb_device *dev, size_t size,
gfp_t mem_flags, dma_addr_t *dma);
extern void usb_free_coherent(struct usb_device *dev, size_t size,
void *addr, dma_addr_t dma);
// copy from transport.h
extern int usb_stor_CB_transport(struct scsi_cmnd *, struct us_data*);
extern int usb_stor_CB_reset(struct us_data*);
extern int usb_stor_Bulk_transport(struct scsi_cmnd *, struct us_data*);
extern int usb_stor_Bulk_max_lun(struct us_data*);
extern int usb_stor_Bulk_reset(struct us_data*);
extern void usb_stor_invoke_transport(struct scsi_cmnd *, struct us_data*);
extern void usb_stor_stop_transport(struct us_data*);
// copy form protocol.h
extern void usb_stor_transparent_scsi_command(struct scsi_cmnd* srb, struct us_data* );
extern unsigned char usb_stor_sense_invalidCDB[18];
#endif

View file

@ -0,0 +1,37 @@
#ifndef __US_USUAL_H
#define __US_USUAL_H
#include "usb.h"
#include "storage.h"
#define US_FL_SINGLE_LUN 0x00000001/* allow access to only LUN 0 */
//#define US_FL_NEED_OVERRIDE 0x00000002/* unusual_devs entry is necessary */
//#define US_FL_SCM_MULT_TARG 0x00000004/* supports multiple targets */
//#define US_FL_FIX_INQUIRY 0x00000008/* INQUIRY response needs faking */
//#define US_FL_FIX_CAPACITY 0x00000010/* READ CAPACITY response too big */
//#define US_FL_IGNORE_RESIDUE 0x00000020/* reported residue is wrong */
//#define US_FL_BULK32 0x00000040/* Uses 32-byte CBW length */
#define US_FL_NOT_LOCKABLE 0x00000080/* PREVENT/ALLOW not supported */
#define US_FL_GO_SLOW 0x00000100/* Need delay after Command phase */
#define US_FL_NO_WP_DETECT 0x00000200/* Don't check for write-protect */
#define US_FL_MAX_SECTORS_64 0x00000400/* Sets max_sectors to 64 */
#define US_FL_IGNORE_DEVICE 0x00000800/* Don't claim device */
#define US_FL_CAPACITY_HEURISTICS 0x00001000/* sometimes sizes is too big */
#define US_FL_MAX_SECTORS_MIN 0x00002000/* Sets max_sectors to arch min */
#define US_FL_BULK_IGNORE_TAG 0x00004000/* Ignore tag mismatch in bulk operations */
#define US_FL_SANE_SENSE 0x00008000/* Sane Sense (> 18 bytes) */
#define US_FL_CAPACITY_OK 0x00010000/* READ CAPACITY response is correct */
#define US_FL_BAD_SENSE 0x00020000/* Bad Sense (never more than 18 bytes) */
#define US_FL_NO_READ_DISC_INFO 0x00040000/* cannot handle READ_DISC_INFO */
#define US_FL_NO_READ_CAPACITY_16 0x00080000/* cannot handle READ_CAPACITY_16*/
#define US_FL_INITIAL_READ10 0x00100000/* Initial READ(10) (and others) must be retried */
#define US_FL_WRITE_CACHE 0x00200000/* Write Cache status is not available */
#define US_FL_NEEDS_CAP16 0x00400000/* cannot handle READ_CAPACITY_10 */
#define US_FL_IGNORE_UAS 0x00800000/* Device advertises UAS but it is broken */
#define US_FL_BROKEN_FUA 0x01000000/* Cannot handle FUA in WRITE or READ CDBs */
extern int usb_usual_ignore_device(struct usb_interface *intf);
extern struct usb_device_id usb_storage_usb_ids[];
#endif /* __US_USUAL_H */

View file

@ -0,0 +1,41 @@
#ifndef _MJPEG_API_H
#define _MJPEG_API_H
/* memory disk type */
typedef enum _medium_type{
medium_SD,
medium_USB,
medium_FLASH,
medium_CACHE
}medium_type;
/* time unit*/
typedef enum _time_unit{
unit_HR, // hour
unit_MIN, // minute
unit_SEC, //second
}time_unit;
typedef struct _mjpeg_cache{
unsigned char* addr;
int size;
}mjpeg_cache;
struct mjpeg_context{
/* mjpeg size*/
int width;//frame width
int height;//frame height
/* */
medium_type disktype;
time_unit timeunit;
int interval;
unsigned char* name;
unsigned char is_periodic;
/* store mjpeg in a RAM cache */
mjpeg_cache cache;
};
int mjpeg_get(struct mjpeg_context *context);
#endif

View file

@ -38,6 +38,7 @@ int uvc_stream_init(void); //entry function to start uvc
void uvc_stream_free(void); // free streaming resources
int uvc_is_stream_ready(void); // return true if uvc device is initialized successfully
int uvc_is_stream_on(void); //return true if uvc device is streaming now
int uvc_is_stream_off(void); //return true if uvc device is free already
int uvc_stream_on(void); //enable camera streaming
void uvc_stream_off(void); //disable camera streaming
int uvc_set_param(uvc_fmt_t fmt_type, int *width, int *height, int *frame_rate, int *compression_ratio);//set camera streaming video parameters:video format, resolution and frame rate.

View file

@ -335,10 +335,10 @@ static inline __u16 le16_to_cpup(const __le16 *p)
#endif
#ifndef copy_from_user
#define copy_from_user(to, from, sz) RtlMemcpy((to), (from), (sz))
#define copy_from_user(to, from, sz) _memcpy((to), (from), (sz))
#endif
#ifndef copy_to_user
#define copy_to_user(to, from, sz) RtlMemcpy((to), (from), (sz))
#define copy_to_user(to, from, sz) _memcpy((to), (from), (sz))
#endif
typedef u32 compat_caddr_t; //used for compatibility in uvc_v4l2.c
@ -354,6 +354,7 @@ typedef u32 compat_caddr_t; //used for compatibility in uvc_v4l2.c
* of course, the buffer size is zero). It does not pad
* out the result like strncpy() does.
*/
#ifndef __GNUC__
static inline size_t strlcpy(char *dest, const char *src, size_t size)
{
size_t ret = _strlen(src);
@ -365,6 +366,7 @@ static inline size_t strlcpy(char *dest, const char *src, size_t size)
}
return ret;
}
#endif
/**
* clamp - return a value clamped to a given range with strict typechecking
@ -505,6 +507,7 @@ static inline size_t memweight(const void *ptr, size_t bytes)
* @src: The string to append to it
* @count: The size of the destination buffer.
*/
#ifndef __GNUC__
static inline size_t strlcat(char *dest, const char *src, size_t count)
{
size_t dsize = _strlen(dest);
@ -522,7 +525,7 @@ static inline size_t strlcat(char *dest, const char *src, size_t count)
dest[len] = 0;
return res;
}
#endif
/**
* atomic_dec_and_test - decrement and test

View file

@ -0,0 +1,7 @@
#ifndef _ATADRIVE_H_
#define _ATADRIVE_H_
#include "fatfs_ext/inc/ff_driver.h"
extern ll_diskio_drv ATA_disk_Driver;
#endif

View file

@ -0,0 +1,14 @@
/* mbed Microcontroller Library - CMSIS
* Copyright (C) 2009-2011 ARM Limited. All rights reserved.
*
* A generic CMSIS include header, pulling in RTL8195A specifics
*/
#ifndef MBED_CMSIS_H
#define MBED_CMSIS_H
#include <platform/platform_stdlib.h>
#include <hal_platform.h>
#endif

View file

@ -0,0 +1,42 @@
#ifndef _AAC_H
#define _AAC_H
#include "dlist.h" //list management
#include "basic_types.h"
#include "osdep_service.h"
//#include "osdep_api.h"
#define AAC_DEBUG 1
#if AAC_DEBUG
#define AAC_PRINTF(fmt, args...) printf("\n\r%s: " fmt, __FUNCTION__, ## args)
#define AAC_ERROR(fmt, args...) printf("\n\r%s: " fmt, __FUNCTION__, ## args)
#else
#define AAC_PRINTF(fmt, args...)
#define AAC_ERROR(fmt, args...)
#endif
struct rtp_au_hdr
{
u32 au_size; //contain AU size in octets(header length included)
#if 0
u16 au_index;
u16 au_index_delta;
u16 cts_flag;
u16 cts_delta;
u16 dts_flag;
u16 dts_delta;
u16 rap_flag;
u16 stream_state;
#endif
u32 au_header_len; //record AU header size in octets
};
struct rtp_aac_obj
{
u16 au_headers_len; //contain AU header size in octet (we will translate it into bit-wise count before sending)
u8 au_header_num; //contain AU header number
// struct rtp_au_hdr *au_hdr;
};
#endif /*_AAC_H*/

View file

@ -0,0 +1,139 @@
#ifndef _AV_CODEC_H_
#define _AV_CODEC_H_
/* Is this the place to include different codec header for rtp usage?*/
struct codec_info
{
int codec_id;
const char codec_name[8];
u8 pt;
u32 clock_rate;
u8 audio_channels;
void *priv;
};
/* media type list -- range from 0-255 stored in 1 BYTE*/
#define AVMEDIA_TYPE_VIDEO 0
#define AVMEDIA_TYPE_AUDIO 1
#define AVMEDIA_TYPE_SUBTITLE 2
#define AVMEDIA_TYPE_UNKNOWN 255
/*codec id list -- id must match its placing order (starting from 0) in av_codec_tables*/
#define AV_CODEC_ID_MJPEG 0
#define AV_CODEC_ID_H264 1
#define AV_CODEC_ID_PCMU 2
#define AV_CODEC_ID_PCMA 3
#define AV_CODEC_ID_MP4A_LATM 4
#define AV_CODEC_ID_MP4V_ES 5
#define AV_CODEC_ID_UNKNOWN -1
/*rtp payload type mapping and standard rtp payload type table -- range from 0-255 in 1 BYTE*/
#define RTP_PT_PCMU 0
#define RTP_PT_GSM 3
#define RTP_PT_G723 4
#define RTP_PT_DVI4_R8000 5
#define RTP_PT_DVI4_R16000 6
#define RTP_PT_LPC 7
#define RTP_PT_PCMA 8
#define RTP_PT_G722 9
#define RTP_PT_L16_C2 10
#define RTP_PT_L16_C1 11
#define RTP_PT_QCELP 12
#define RTP_PT_CN 13
#define RTP_PT_MPA 14
#define RTP_PT_G728 15
#define RTP_PT_DVI4_R11025 16
#define RTP_PT_DVI4_R22050 17
#define RTP_PT_G719 18
#define RTP_PT_CELB 25
#define RTP_PT_JPEG 26
#define RTP_PT_NV 28
#define RTP_PT_H261 31
#define RTP_PT_MPV 32
#define RTP_PT_MP2T 33
#define RTP_PT_H263 34
#define RTP_PT_RTCP_BASE 72
#define RTP_PT_DYN_BASE 96
#define RTP_PT_UNKNOWN 255
/* AAC PROFILE */
#define AV_PROFILE_AAC_MAIN 0
#define AV_PROFILE_AAC_LOW 1
#define AV_PROFILE_AAC_SSR 2
#define AV_PROFILE_AAC_LTP 3
#define AV_PROFILE_AAC_HE 4
#define AV_PROFILE_AAC_HE_V2 28
#define AV_PROFILE_AAC_LD 22
#define AV_PROFILE_AAC_ELD 38
#define AV_PROFILE_MPEG2_AAC_LOW 128
#define AV_PROFILE_MPEG2_AAC_HE 131
#if 0
/* MPEG4 VIDEO PROFILE */
#define AV_PROFILE_MPEG4_SIMPLE 0
#define AV_PROFILE_MPEG4_SIMPLE_SCALABLE 1
#define AV_PROFILE_MPEG4_CORE 2
#define AV_PROFILE_MPEG4_MAIN 3
#define AV_PROFILE_MPEG4_N_BIT 4
#define AV_PROFILE_MPEG4_SCALABLE_TEXTURE 5
#define AV_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION 6
#define AV_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE 7
#define AV_PROFILE_MPEG4_HYBRID 8
#define AV_PROFILE_MPEG4_ADVANCED_REAL_TIME 9
#define AV_PROFILE_MPEG4_CORE_SCALABLE 10
#define AV_PROFILE_MPEG4_ADVANCED_CODING 11
#define AV_PROFILE_MPEG4_ADVANCED_CORE 12
#define AV_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE 13
#define AV_PROFILE_MPEG4_SIMPLE_STUDIO 14
#define AV_PROFILE_MPEG4_ADVANCED_SIMPLE 15
/* DTS */
#define AV_PROFILE_DTS 20
#define AV_PROFILE_DTS_ES 30
#define AV_PROFILE_DTS_96_24 40
#define AV_PROFILE_DTS_HD_HRA 50
#define AV_PROFILE_DTS_HD_MA 60
#define AV_PROFILE_DTS_EXPRESS 70
/* MPEG2 */
#define AV_PROFILE_MPEG2_422 0
#define AV_PROFILE_MPEG2_HIGH 1
#define AV_PROFILE_MPEG2_SS 2
#define AV_PROFILE_MPEG2_SNR_SCALABLE 3
#define AV_PROFILE_MPEG2_MAIN 4
#define AV_PROFILE_MPEG2_SIMPLE 5
/* H264 */
#define AV_PROFILE_H264_CONSTRAINED (1<<9) // 8+1; constraint_set1_flag
#define AV_PROFILE_H264_INTRA (1<<11) // 8+3; constraint_set3_flag
#define AV_PROFILE_H264_BASELINE 66
#define AV_PROFILE_H264_CONSTRAINED_BASELINE (66|FF_PROFILE_H264_CONSTRAINED)
#define AV_PROFILE_H264_MAIN 77
#define AV_PROFILE_H264_EXTENDED 88
#define AV_PROFILE_H264_HIGH 100
#define AV_PROFILE_H264_HIGH_10 110
#define AV_PROFILE_H264_HIGH_10_INTRA (110|FF_PROFILE_H264_INTRA)
#define AV_PROFILE_H264_HIGH_422 122
#define AV_PROFILE_H264_HIGH_422_INTRA (122|FF_PROFILE_H264_INTRA)
#define AV_PROFILE_H264_HIGH_444 144
#define AV_PROFILE_H264_HIGH_444_PREDICTIVE 244
#define AV_PROFILE_H264_HIGH_444_INTRA (244|FF_PROFILE_H264_INTRA)
#define AV_PROFILE_H264_CAVLC_444 44
#endif
/*av codec tables*/
//#include "section_config.h"
//SDRAM_DATA_SECTION
static const struct codec_info av_codec_tables[] = {
{AV_CODEC_ID_MJPEG, "MJPEG", RTP_PT_JPEG, 90000, 0, 0},
{AV_CODEC_ID_H264, "H264", RTP_PT_DYN_BASE, 90000, 0, 0},
{AV_CODEC_ID_PCMU, "PCMU", RTP_PT_PCMU, 8000, 1, 0},
{AV_CODEC_ID_PCMA, "PCMA", RTP_PT_PCMA, 8000, 1, 0},
{AV_CODEC_ID_MP4A_LATM, "MP4A", RTP_PT_DYN_BASE, 16000, 2, 0},
{AV_CODEC_ID_MP4V_ES, "MP4V", RTP_PT_DYN_BASE, 90000, 0, 0},
};
#define AVCODEC_SIZE 6
void get_codec_by_id(struct codec_info *c, int id);
#endif //_AV_CODEC_H_

View file

@ -0,0 +1,27 @@
#ifndef _G711_H
#define _G711_H
#include "dlist.h" //list management
#include "basic_types.h"
#include "osdep_service.h"
//#include "osdep_api.h"
#define G711_DEBUG 1
#if G711_DEBUG
#define G711_PRINTF(fmt, args...) printf("\n\r%s: " fmt, __FUNCTION__, ## args)
#define G711_ERROR(fmt, args...) printf("\n\r%s: " fmt, __FUNCTION__, ## args)
#else
#define G711_PRINTF(fmt, args...)
#define G711_ERROR(fmt, args...)
#endif
//struct rtp_g711_obj {
//};
/*for debug purpose*/
#endif /*_G711_H*/

View file

@ -0,0 +1,75 @@
#ifndef _H264_H
#define _H264_H
#include "dlist.h" //list management
#include "basic_types.h"
#include "osdep_service.h"
//#include "osdep_api.h"
#define H264_DEBUG 0
#if H264_DEBUG
#define H264_PRINTF(fmt, args...) printf("\n\r%s: " fmt, __FUNCTION__, ## args)
#define H264_ERROR(fmt, args...) printf("\n\r%s: " fmt, __FUNCTION__, ## args)
#else
#define H264_PRINTF(fmt, args...)
#define H264_ERROR(fmt, args...)
#endif
#define MAX_NUM_NAL_PER_FRM 4
struct rtp_nal_obj
{
u8 start_code_len;
unsigned char nal_header;
u8 is_fu_start;
u8 is_fu_end;
u8 must_not_drop;
u8 do_not_send;
int offset;
};
struct rtp_h264_obj
{
int num_nal;
struct rtp_nal_obj nal_obj[MAX_NUM_NAL_PER_FRM];
};
#endif /*_H264_H*/
#if 0
#ifndef _H264_H
#define _H264_H
#include "dlist.h" //list management
#include "basic_types.h"
#include "osdep_service.h"
//#include "osdep_api.h"
#define H264_DEBUG 0
#if H264_DEBUG
#define H264_PRINTF(fmt, args...) printf("\n\r%s: " fmt, __FUNCTION__, ## args)
#define H264_ERROR(fmt, args...) printf("\n\r%s: " fmt, __FUNCTION__, ## args)
#else
#define H264_PRINTF(fmt, args...)
#define H264_ERROR(fmt, args...)
#endif
/* in favor of rtp fragmentation */
struct rtp_h264_obj
{
u8 start_code_len;
unsigned char nal_header;
u8 is_fu_start;
u8 is_fu_end;
u8 must_not_drop;
};
/********************************h264 over rtp******************************/
#endif /*_H264_H*/
#endif

View file

@ -0,0 +1,62 @@
#ifndef _MJPEG_H
#define _MJPEG_H
#include "dlist.h" //list management
#include "basic_types.h"
#include "osdep_service.h"
//#include "osdep_api.h"
#define MJPEG_DEBUG 0
#if MJPEG_DEBUG
#define MJPEG_PRINTF(fmt, args...) printf("\n\r%s: " fmt, __FUNCTION__, ## args)
#define MJPEG_ERROR(fmt, args...) printf("\n\r%s: " fmt, __FUNCTION__, ## args)
#else
#define MJPEG_PRINTF(fmt, args...)
#define MJPEG_ERROR(fmt, args...)
#endif
struct jpeghdr {
unsigned int tspec:8; /* type-specific field */
unsigned int off:24; /* fragment byte offset */
u8 type; /* id of jpeg decoder params */
u8 q; /* quantization factor (or table id) */
u8 width; /* frame width in 8 pixel blocks */
u8 height; /* frame height in 8 pixel blocks */
};
struct jpeghdr_rst {
u16 dri; /*restart interval*/
unsigned int f:1; /*restart first bit flag*/
unsigned int l:1; /*restart last bit flag*/
unsigned int count:14; /*restart count*/
};
struct jpeghdr_qtable {
u8 mbz;
u8 precision;
u16 length;
};
#define RTP_JPEG_RESTART 0x40
#define USE_EXPLICIT_DQT 128
#define USE_IMPLICIT_DQT 0
struct rtp_jpeg_obj
{
struct jpeghdr jpghdr;
struct jpeghdr_rst rsthdr;
struct jpeghdr_qtable qtable;
u8 lqt[64*2]; /* Luma Quantizer table */
u8 cqt[64*2]; /* Croma Quantizer table */
int hdr_len;
int frame_offset;
};
/*for debug purpose*/
void dumpJpegHeader(struct jpeghdr *jpghdr);
void dumpRstDeader(struct jpeghdr_rst *rsthdr);
#endif /*_MJPEG_H*/

View file

@ -0,0 +1,89 @@
#ifndef _EXCHBUF_H
#define _EXCHBUF_H
#include "cmsis_os.h"
#include "errno.h"
/*service task state*/
#define S_STOP 0x00
#define S_RUN 0x01
#define S_FROZEN 0X02
#define CMD_SET_HEIGHT 0x00
#define CMD_SET_WIDTH 0x01
#define CMD_SET_BITRATE 0x02
#define CMD_SET_FRAMERATE 0x03
#define CMD_SET_CPZRATIO 0x04
#define CMD_SET_FRAMETYPE 0x05
#define CMD_SET_SAMPLERATE 0x06
#define CMD_SET_CHANNEL 0x07
#define CMD_SET_CODEC 0x08
#define CMD_SET_STREAMNUM 0x09
#define CMD_SET_SPS 0x0a
#define CMD_SET_PPS 0x0b
#define CMD_SET_LEVEL 0x0c
#define CMD_SET_APPLY 0x1f
#define CMD_SET_STREAMMING 0x20
#define CMD_SET_INPUT_QUEUE 0x21
#define CMD_SET_OUTPUT_QUEUE 0x22
#define CMD_SET_PRIV_BUF 0x23
#define CMD_SET_TASK_ON 0x24
#define CMD_SET_TASK_FROZEN 0x25
#define CMD_SET_TASK_OFF 0x26
#define CMD_SELECT_CHANNEL 0x30
#define CMD_SET_CB_START 0x40
#define CMD_SET_CB_STOP 0x41
#define CMD_SET_CB_PAUSE 0x42
#define CMD_SET_CB_CUSTOMCMD 0x43
#define CMD_FLUSH 0x50
#define CMD_SET_FLAG 0X51
#define CMD_GET_STREAM_READY 0x52
#define CMD_GET_STREAM_STATUS 0x53
/*mp4 storage*/
#define CMD_SET_ST_PERIOD 0X60
#define CMD_SET_ST_TOTAL 0X61
#define CMD_SET_ST_TYPE 0X62
#define CMD_SET_ST_FILENAME 0x63
#define CMD_SET_ST_START 0x64
/*mp4 storage*/
#define STORAGE_ALL 0
#define STORAGE_VIDEO 1
#define STORAGE_AUDIO 2
/*exchange buffer state*/
#define STAT_INIT 0
#define STAT_USED 1
#define STAT_READY 2
#define STAT_RESERVED 3
#define TIME_SYNC_EN 0
#define TIME_SYNC_DIS 1
#define FMT_V_MJPG 0x00
#define FMT_V_H264 0x01
#define FMT_V_MP4V_ES 0x02
#define FMT_A_PCMU 0x10
#define FMT_A_PCMA 0x11
#define FMT_A_MP4A_LATM 0x12
#define FMT_AV_UNKNOWN 0xFF
#define MFT_CMD 0
#define MFT_DATA 1
typedef struct _exch_buf{
//_list node; // linking node
uint32_t type; // CMD, or DATA
uint32_t cmd; // command
uint32_t arg; // command arg
uint8_t* data; //
uint32_t index;
uint32_t len;
uint32_t timestamp; // 0: not set
uint32_t codec_fmt; // FMT_V_xx or FMT_A_xx
uint32_t state;
void* priv; // private use
}exch_buf_t;
typedef int (*mmf_cb_t)(void*);
#endif

View file

@ -0,0 +1,30 @@
#ifndef _STREAM_H
#define _STREAM_H
#include "cmsis_os.h"
#include "mmf_common.h"
typedef struct _media_sink_module{
void* (*create)(void);
void (*destroy)(void*);
int (*set_param)(void*, int, int);
int (*handle)(void*, void*);
}msink_module_t;
typedef struct _media_sink_context{
xQueueHandle input_qid;
xQueueHandle output_qid;
int state;
xTaskHandle hdl_task;
void* drv_priv; // private data for module
msink_module_t *sink;
}msink_context;
void mmf_sink_close(msink_context* ctx);
msink_context* mmf_sink_open(msink_module_t *sink);
int mmf_sink_ctrl(msink_context* ctx, int cmd, int arg);
int mmf_sink_put_frame(msink_context* ctx, exch_buf_t* exbuf);
// must be here
#include "mmf_sink_modules/mmf_sink_list.h"
#endif

View file

@ -0,0 +1,10 @@
#ifndef _STREAM_MODULES_H
#define _STREAM_MODULES_H
#include "../mmf_sink.h"
//list all avaliable modules here
extern msink_module_t rtsp_module;
extern msink_module_t rtsp2_module;
extern msink_module_t i2s_sink_module;
extern msink_module_t mp4_module;
#endif

View file

@ -0,0 +1,32 @@
#ifndef _MEDIA_H
#define _MEDIA_H
#include "cmsis_os.h"
#include "mmf_common.h"
typedef struct _media_source_module{
void* (*create)(void);
void (*destroy)(void*);
int (*set_param)(void*, int, int);
int (*handle)(void*, void*); // input output will cast to exch_buf_t
}msrc_module_t;
typedef struct _media_source_context{
xQueueHandle input_qid;
xQueueHandle output_qid;
int state;
xTaskHandle hdl_task;
void* drv_priv;
msrc_module_t* source;
}msrc_context;
void mmf_source_close(msrc_context* ctx);
msrc_context* mmf_source_open(msrc_module_t* source);
int mmf_source_ctrl(msrc_context* ctx, int cmd, int arg);
int mmf_source_get_frame(msrc_context* ctx, exch_buf_t *exbuf);
// must be here
#include "mmf_source_modules/mmf_source_list.h"
#endif

View file

@ -0,0 +1,35 @@
#ifndef MMF_SOURCE_I2S_FILE_H
#define MMF_SOURCE_I2S_FILE_H
#include "mmf_source.h"
#include "FreeRTOS.h"
#include "task.h"
//#include "example_rtsp_server_i2s.h"
#include "rtsp/rtsp_api.h"
#include "sockets.h"
#include "lwip/netif.h"
#include "i2s_api.h"
#include "alc5651.c"
#include "g711_codec.h"
#include "gpio_api.h" // mbed
#include "gpio_irq_api.h"
#include <platform/platform_stdlib.h>
#include "platform_opts.h"
#include "dlist.h"
#include "basic_types.h"
#include "osdep_service.h"
#define I2S_DMA_PAGE_SIZE 320 // 2 ~ 4096
#define I2S_DMA_PAGE_NUM 4 // Vaild number is 2~4
#define RECV_PAGE_NUM I2S_DMA_PAGE_NUM
#define G711_FSIZE 160
#define I2S_MODE_SWITCH PE_5
#define I2S_SCLK_PIN PC_1
#define I2S_WS_PIN PC_0
#define I2S_SD_PIN PC_2
#endif /* MMF_SOURCE_I2S_FILE_H */

View file

@ -0,0 +1,14 @@
#ifndef _MEDIA_MODULES_H
#define _MEDIA_MODULES_H
#include "../mmf_source.h"
//list all avaliable modules here
extern msrc_module_t uvc_module;
extern msrc_module_t geo_module;
extern msrc_module_t mjpgf_module;
extern msrc_module_t h264f_module;
extern msrc_module_t aacf_module;
extern msrc_module_t pcmuf_module;
extern msrc_module_t i2s_module;
extern msrc_module_t rtp_src_module;
#endif

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,110 @@
#ifndef _MP4_ENCAP_H_
#define _MP4_ENCAP_H_
#include "basic_types.h"
#include "osdep_service.h"
#define MAX_BOX_CHILD 8
#define RBUF_SIZE 1024
typedef struct _mp4root{
unsigned int video_len;
unsigned int audio_len;
unsigned int total;
unsigned int keyindex;
}MP4root,*PMP4root;
#define STORAGE_IDLE 0
#define STORAGE_START 1
#define STORAGE_WRITE_ALL 2
#define STORAGE_WRITE_VIDEO 3
#define STORAGE_WRITE_AUDIO 4
#define STORAGE_STOP 5
#define STORAGE_END 6
#define STORAGE_ALL 0
#define STORAGE_VIDEO 1
#define STORAGE_AUDIO 2
typedef struct _mp4_payload{
unsigned char *addr;
unsigned int len;
}mp4_payload,pmp4_payload;
typedef struct _mp4_write_info{
int mp4_start_position;
int mp4_end_position;
int mp4_occupy_size;
int mp4_empty_size;
int mp4_write_start_position;
int mp4_write_end_position;
int mp4_write_occupy_size;
int mp4_write_empty_size;
int mp4_write_length;
}mp4_winfo,*pmp4_winfo;
typedef struct _mp4_context{
FATFS m_fs;
int drv_num;
char _drv[4];
FIL m_file;
char filename[32];
int Fatfs_ok;
int filecount;
int width;
int height;
int sample_rate;
int channel_count;
int frame_rate;
u32 start_time;//rtw_get_current_time()
u32 file_name_index;
u32 storage_state;
MP4root root;
MP4root root_reserve;
int period_time;
int file_total;
int sps_start;
int type;
int sps_len;
int pps_len;
int sps_pps_mark;
unsigned int *video_buffer_index;
unsigned int *video_buffer_size;
int video_size;
unsigned int *audio_buffer_index;
unsigned int *audio_buffer_size;
int audio_size;
unsigned char *moov_box;
int moov_box_size;
unsigned char *h264_buf;
int H264_LENGTH;
mp4_payload payload;
mp4_payload reserved_payload;
int reserved_start_index;
int iframe;
int reserved_type;
_sema start_fatfs_write;
int write_status;
int audio_write_status;
int video_write_status;
int buffer_write_status;//0: real write 1: virtual write
mp4_winfo winfo;
int nal_len;
int h264_extra_len;
int mp4_muxer_enable;
}mp4_context,*pmp4_context;
#define IDLE 0
#define FATFS_WRITING 1
#define FATFS_DONE 2
void mp4_handle(pmp4_context mp4_ctx,unsigned char *buf,unsigned int size,int type);
void set_mp4_audio_buffer(pmp4_context mp4_ctx,unsigned int *audio_index,unsigned int *audio_size,int size);
void set_mp4_video_buffer(pmp4_context mp4_ctx,unsigned int *video_index,unsigned int *video_size,int size);
void set_mp4_moov_buffer(pmp4_context mp4_ctx,unsigned char *moov,int size);
int mp4_set_record(pmp4_context mp4_ctx,int num);
void mp4_muxer_init(pmp4_context mp4_ctx);
void mp4_muxer_close(pmp4_context mp4_ctx);
int mp4_set_start_status(pmp4_context mp4_ctx);
#endif

View file

@ -71,10 +71,10 @@
#include "freertos/inic_intf.h"
#endif
#define netifMTU (1500)
#define netifMTU (1500)
#define netifINTERFACE_TASK_STACK_SIZE ( 350 )
#define netifINTERFACE_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
#define netifGUARD_BLOCK_TIME ( 250 )
#define netifGUARD_BLOCK_TIME ( 250 )
/* The time to block waiting for input. */
#define emacBLOCK_TIME_WAITING_FOR_INPUT ( ( portTickType ) 100 )

View file

@ -0,0 +1,134 @@
#ifndef _RTP_API_H_
#define _RTP_API_H_
#include "dlist.h"
#include "basic_types.h"
#include "osdep_service.h"
//#include "osdep_api.h"
#include "avcodec.h"
#include <lwip/def.h> //for host network byte order convertion
/* from error_base.h */
#define EIO 5 /* I/O error */
#define EAGAIN 11 /* Try again */
#define ENOMEM 12 /* Out of memory */
#define EINVAL 22 /* Invalid argument */
#define RTP_BIG_ENDIAN 0
#define RTP_HDR_SZ 12
#define RTP_SERVER_PORT_BASE 55608
#define RTP_PORT_BASE 50020
#define RTP_CLIENT_PORT_BASE 51020
/*
* RTP data header from RFC1889
*/
/*
*
*
* The RTP header has the following format:
*
* 0 1 2 3
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* |V=2|P|X| CC |M| PT | sequence number |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | timestamp |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | synchronization source (SSRC) identifier |
* +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
* | contributing source (CSRC) identifiers |
* | .... |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
* RTP data header
*/
typedef struct {
#if RTP_BIG_ENDIAN
u16 version:2; /* protocol version */
u16 p:1; /* padding flag */
u16 x:1; /* header extension flag */
u16 cc:4; /* CSRC count */
u16 m:1; /* marker bit */
u16 pt:7; /* payload type */
#else /*RTP_LITTLE_ENDIAN*/
u16 cc:4; /* CSRC count */
u16 x:1; /* header extension flag */
u16 p:1; /* padding flag */
u16 version:2; /* protocol version */
u16 pt:7; /* payload type */
u16 m:1; /* marker bit */
#endif
u16 seq; /* sequence number */
u32 ts; /* timestamp */
u32 ssrc; /* synchronization source */
u32 *csrc; /* optional CSRC list, skip if cc is set to 0 here*/
} rtp_hdr_t;
/*sturcture to hold connect info*/
struct connect_context
{
int socket_id;
u8 *server_ip;
u16 server_port;
u8 *remote_ip;
u16 remote_port;
};
struct rtp_statistics
{
u32 rtp_tick;
u32 rtp_tick_inc;
u32 base_timestamp;
/*for flow control*/
u32 delay_threshold; //in ms
u32 timer1; //time before send
u32 timer2; //time after sent
u32 delta_timer;
u8 do_start_check; //indicate if start check need to be done
u32 sent_packet;
u32 drop_packet;
};
enum rtp_object_state
{
RTP_OBJECT_IDLE = 0,
RTP_OBJECT_READY,
RTP_OBJECT_INUSE,
RTP_OBJECT_USED,
};
struct stream_context;
struct rtp_object;
struct rtp_object
{
struct list_head rtp_list;
_mutex list_lock;
rtp_hdr_t *rtphdr;
void *extra; //pointer to type specific structure
int index; //respective internal buffer index
u8 *data; // respective internal buffer data addr
int len; //one complete frame data length
u32 timestamp; //timestamp
u32 fs:1; //fragment start
u32 fe:1; //fragment end
u32 fk:1; //fragment keep indicator so that cannot avoid sending by flow control
u32 fd:29; //fragment data size (max size of 2^29-1)
enum rtp_object_state state;
struct connect_context connect_ctx;
int (*rtp_object_handler)(struct stream_context *stream_ctx, struct rtp_object *payload);
};
void rtp_object_init(struct rtp_object *payload);
void rtp_object_deinit(struct rtp_object *payload);
void rtp_object_set_fs(struct rtp_object *payload, int flag);
void rtp_object_set_fe(struct rtp_object *payload, int flag);
void rtp_object_set_fk(struct rtp_object *payload, int flag);
void rtp_object_set_fd(struct rtp_object *payload, int size);
void rtp_load_o_handler_by_codec_id(struct rtp_object *payload, int id);
void rtp_fill_header(rtp_hdr_t *rtphdr, int version, int padding, int extension, int cc, int marker, int pt, u16 seq, u32 ts, u32 ssrc);
int rtp_parse_header(u8 *src, rtp_hdr_t *rtphdr, int is_nbo);
void rtp_dump_header(rtp_hdr_t *rtphdr, int is_nbo);
#endif

View file

@ -0,0 +1,100 @@
#ifndef _SRC2RTSP_H_
#define _SRC2RTSP_H_
/* Add by Ian -- This file contains parts used for rtsp to access lower layer stream src information*/
#include "dlist.h"
#include "basic_types.h"
#include "osdep_service.h"
//#include "osdep_api.h"
#include "rtsp/rtp_api.h"
#include "avcodec.h"
#define SRC_FROM_UVC
//#define SRC_FROM_UAC
//#define SRC_FROM_SPI
#define SRC_FROM_I2S
#define SRC_FROM_STA
#define SRC_TYPE_NUL 0
#define SRC_TYPE_UVC 1
#define SRC_TYPE_SPI 2
#define SRC_TYPE_UAC 3
#define SRC_TYPE_I2S 4
#define SRC_TYPE_STA 7
struct FormatInfo
{
struct codec_info codec;
u8 framerate;
u32 bitrate;
u32 height;
u32 width;
};
struct stream_flow
{
int id;
void *prot_hook; //transport protocol hook
void *src;
int src_type;
struct FormatInfo currentFormatInfo;
int (*src_handler) (void *src, struct rtp_object *payload);
struct list_head input_queue;
_mutex input_lock;
struct list_head output_queue;
_mutex output_lock;
u8 is_src2rtsp_init;
u8 is_src2rtsp_start;
_sema start_src2rtsp_sema;
struct stream_flow *next;
};
#ifdef SRC_FROM_UVC
#include "v4l2_intf.h"
struct uvc_streaming;
struct uvcManager
{
struct uvc_streaming *stream;
streaming_state state;
struct FormatInfo currentFormatInfo;
};
#endif
#ifdef SRC_FROM_SPI
#endif
#ifdef SRC_FROM_UAC
#endif
#ifdef SRC_FROM_I2S
struct i2sManager{
struct FormatInfo currentFormatInfo;
};
#endif
#ifdef SRC_FROM_STA
struct rtsp_static_source_manager
{
struct FormatInfo currentFormatInfo;
};
#endif
struct stream_flow* rtsp_stream_flow_create(void);
void rtsp_stream_flow_free(struct stream_flow *stream);
void rtsp_register_src_handler(struct stream_flow *stream, int (*src_handler) (void *stream_src, struct rtp_object *payload));
int rtsp_get_src_currentFormatInfo(struct stream_flow *stream);
int rtsp_set_src_FormatInfo(struct stream_flow *stream, int codec_id, u8 framerate, u32 height, u32 width, u32 bitrate);
extern int rtsp_set_src_extra(struct stream_flow, void *param);
int rtsp_stream_flow_set(struct stream_flow *stream, void *source, int src_type);
int rtsp_stream_flow_update(struct stream_flow *stream);
int rtsp_stream_flow_concat(struct stream_flow *stream, struct stream_flow *stream_next);
void rtp_object_in_src_queue(struct rtp_object *payload, struct stream_flow *stream);
struct rtp_object *rtp_object_out_src_queue(struct stream_flow *stream);
#endif

View file

@ -0,0 +1,120 @@
#ifndef EASYWSCLIENT_H
#define EASYWSCLIENT_H
#include <platform/platform_stdlib.h>
/****************Define the debug message level*********************/
#define DEBUG_WSCLIENT 1
#define WSCLIENT_LOG(level, fmt, ...) printf("\n\r[WSCLIENT %s] %s: " fmt "\n", level, __FUNCTION__, ##__VA_ARGS__)
#if DEBUG_WSCLIENT == 2
#define WSCLIENT_DEBUG(fmt, ...) WSCLIENT_LOG("DEBUG", fmt, ##__VA_ARGS__)
#else
#define WSCLIENT_DEBUG(fmt, ...)
#endif
#if DEBUG_WSCLIENT
#define WSCLIENT_ERROR(fmt, ...) WSCLIENT_LOG("ERROR", fmt, ##__VA_ARGS__)
#else
#define WSCLIENT_ERROR(fmt, ...)
#endif
/*******************************************************************/
/****************Define the structures used*************************/
typedef enum{
CLOSING,
CLOSED,
CONNECTING,
OPEN
} readyStateValues;
struct wsheader_type{
unsigned header_size;
int fin;
int mask;
enum opcode_type {
CONTINUATION = 0x0,
TEXT_FRAME = 0x1,
BINARY_FRAME = 0x2,
CLOSE = 8,
PING = 9,
PONG = 0xa,
} opcode;
int N0;
uint64_t N;
uint8_t masking_key[4];
};
struct _wsclient_context;
struct _ssl_context;
struct ssl_fun_ops{
int (*memory_set_own)( void * (*malloc_func)( size_t ),void (*free_func)( void * ) );
int (*net_connect)( int *fd, const char *host, int port );
int (*ssl_init)( struct _ssl_context *ssl );
void (*ssl_set_endpoint)( struct _ssl_context *ssl, int endpoint );
void (*ssl_set_authmode)( struct _ssl_context *ssl, int authmode );
void (*ssl_set_rng)( struct _ssl_context *ssl,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng );
void (*ssl_set_bio)( struct _ssl_context *ssl,
int (*f_recv)(void *, unsigned char *, size_t), void *p_recv,
int (*f_send)(void *, const unsigned char *, size_t), void *p_send );
int (*ssl_handshake)( struct _ssl_context *ssl );
void (*net_close)( int fd );
void (*ssl_free)( struct _ssl_context *ssl );
int (*ssl_read)( struct _ssl_context *ssl, unsigned char *buf, size_t len );
int (*ssl_write)( struct _ssl_context *ssl, const unsigned char *buf, size_t len );
const char *(*ssl_get_ciphersuite)( const struct _ssl_context *ssl );
int (*net_recv)( void *ctx, unsigned char *buf, size_t len );
int (*net_send)( void *ctx, const unsigned char *buf, size_t len );
};
struct ws_fun_ops{
int (*hostname_connect)(struct _wsclient_context *wsclient);
void (*client_close)(struct _wsclient_context *wsclient);
int (*client_send)(struct _wsclient_context *wsclient, unsigned char *data, size_t data_len);
int (*client_read)(struct _wsclient_context *wsclient, unsigned char *data, size_t data_len);
struct ssl_fun_ops ssl_fun_ops;
};
typedef struct _wsclient_context{
char host[128];
char path[128];
char origin[200];
int port;
uint8_t use_ssl;
int sockfd;
readyStateValues readyState;
int tx_len;
void *ssl;
uint8_t *txbuf;
uint8_t *rxbuf;
uint8_t *receivedData;
struct ws_fun_ops fun_ops;
}wsclient_context;
/*******************************************************************/
/****************General functions used by wsclient*****************/
void ws_get_random_bytes(void *buf, size_t len);
void* ws_malloc(unsigned int size);
void ws_free(void *buf);
int ws_client_handshake(wsclient_context *wsclient);
int ws_check_handshake(wsclient_context *wsclient);
void ws_sendData(uint8_t type, size_t message_size, uint8_t* message, int useMask, wsclient_context *wsclient);
/*******************************************************************/
/*************Functions used by wsclient without SSL****************/
int ws_hostname_connect(wsclient_context *wsclient);
int ws_client_read(wsclient_context *wsclient, unsigned char *data, size_t data_len);
int ws_client_send(wsclient_context *wsclient, unsigned char *data, size_t data_len);
void ws_client_close(wsclient_context *wsclient);
/*******************************************************************/
/***************Functions used by wsclient with SSL*****************/
int wss_hostname_connect(wsclient_context *wsclient);
int wss_client_read(wsclient_context *wsclient, unsigned char *data, size_t data_len);
int wss_client_send(wsclient_context *wsclient, unsigned char *data, size_t data_len);
void wss_client_close(wsclient_context *wsclient);
/*******************************************************************/
#endif

View file

@ -0,0 +1,108 @@
#ifndef WSCLIENT_H
#define WSCLIENT_H
#include <websocket/libwsclient.h>
/******Define the maximum bytes of data send and receive********/
#define MAX_DATA_LEN 1500
/****************Define if using the polarssl*******************/
#define USING_SSL
/******************Define the function used*********************/
#ifdef USING_SSL
int wss_set_fun_ops(wsclient_context *wsclient);
#define wsclient_set_fun_ops(wsclient) wss_set_fun_ops(wsclient)
#else
int ws_set_fun_ops(wsclient_context *wsclient);
#define wsclient_set_fun_ops(wsclient) ws_set_fun_ops(wsclient)
#endif
/***************************************************************/
/*************************************************************************************************
** Function Name : create_wsclient
** Description : Creating the websocket client context structure
** Input : url:websocket server's url
** port:websocket server's port, if not given, default 80 for "ws", 443 for "wss"
** origin: the address or url of your self
** Return : Created: websocket client context structure
** Failed: NULL
**************************************************************************************************/
wsclient_context *create_wsclient(char *url, int port,char *path, char* origin);
/*************************************************************************************************
** Function Name : ws_connect_url
** Description : Connecting to the websocket server
** Input : wsclient: the websocket client context created by create_wsclientfunction
** Return : Connected: the socket value
** Failed: -1
**************************************************************************************************/
int ws_connect_url(wsclient_context *wsclient);
/*************************************************************************************************
** Function Name : ws_send
** Description : Create the sending string data and copy to tx_buf
** Input : message: the string that send to server(cannot exceeding the MAX_DATA_LEN
** message_len: the length of the string
** use_mask: 0/1; 1 means using mask for bynary
** wsclient: the websocket client context
** Return : None
**************************************************************************************************/
void ws_send(char* message, int message_len, int use_mask, wsclient_context *wsclient);
/*************************************************************************************************
** Function Name : ws_sendBinary
** Description : Create the sending binary data and copy to tx_buf
** Input : message: the binary that send to server(cannot exceeding the MAX_DATA_LEN
** message_len: the length of the binary
** use_mask: 0/1; 1 means using mask for bynary
** wsclient: the websocket client context
** Return : None
**************************************************************************************************/
void ws_sendBinary(uint8_t* message, int message_len, int use_mask, wsclient_context *wsclient);
/*************************************************************************************************
** Function Name : ws_sendPing
** Description : Sending Ping to websocket server
** Input : wsclient: the websocket client context
** Return : None
**************************************************************************************************/
void ws_sendPing(wsclient_context *wsclient);
/*************************************************************************************************
** Function Name : ws_poll
** Description : Receicing data from server and send the data in tx_buf
** Input : timeout(in milliseconds)
wsclient: the websocket client context
** Return : None
**************************************************************************************************/
void ws_poll(int timeout, wsclient_context *wsclient);
/*************************************************************************************************
** Function Name : ws_dispatch
** Description : callback function when getting message from server
** Input : function that resolve the message received and the message length
** Return : None
**************************************************************************************************/
void ws_dispatch(void (*callback)(wsclient_context *, int)) ;
/*************************************************************************************************
** Function Name : ws_getReadyState
** Description : Getting the connection status
** Input : wsclient: the websocket client context
** Return : readyStateValues(4 types:CLOSING, CLOSED, CONNECTING, OPEN)
**************************************************************************************************/
readyStateValues ws_getReadyState(wsclient_context *wsclient);
/*************************************************************************************************
** Function Name : ws_close
** Description : Closing the connection with websocket server
** Input : wsclient: the websocket client context
** Return : None
**************************************************************************************************/
void ws_close(wsclient_context *wsclient);
#endif

View file

@ -0,0 +1,121 @@
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#include "lwip/opt.h"
#if LWIP_NETCONN
#include "lwip/sys.h"
#include "lwip/api.h"
#define TCPECHO_THREAD_PRIO ( tskIDLE_PRIORITY + 3 )
/*-----------------------------------------------------------------------------------*/
static void tcpecho_thread(void *arg)
{
struct netconn *conn, *newconn;
err_t err;
LWIP_UNUSED_ARG(arg);
/* Create a new connection identifier. */
conn = netconn_new(NETCONN_TCP);
if (conn!=NULL)
{
/* Bind connection to well known port number 7. */
err = netconn_bind(conn, NULL, 7);
if (err == ERR_OK)
{
/* Tell connection to go into listening mode. */
netconn_listen(conn);
while (1)
{
/* Grab new connection. */
newconn = netconn_accept(conn);
/* Process the new connection. */
if (newconn)
{
struct netbuf *buf;
void *data;
u16_t len;
while ((buf = netconn_recv(newconn)) != NULL)
{
do
{
netbuf_data(buf, &data, &len);
netconn_write(newconn, data, len, NETCONN_COPY);
}
while (netbuf_next(buf) >= 0);
netbuf_delete(buf);
}
/* Close connection and discard connection identifier. */
netconn_close(newconn);
netconn_delete(newconn);
}
}
}
else
{
printf(" can not bind TCP netconn");
}
}
else
{
printf("can not create TCP netconn");
}
}
/*-----------------------------------------------------------------------------------*/
void tcpecho_init(void)
{
sys_thread_new("tcpecho_thread", tcpecho_thread, NULL, DEFAULT_THREAD_STACKSIZE, TCPECHO_THREAD_PRIO);
}
/*-----------------------------------------------------------------------------------*/
void cmd_tcpecho(int argc, char **argv)
{
printf("\n\rInit TCP ECHO Server ...");
tcpecho_init();
printf("\n\r\nPlease use echotool to connect to this echo server. ex. echotool 192.168.0.1 /p tcp /r 7 /n 0");
}
#endif /* LWIP_NETCONN */

View file

@ -0,0 +1,92 @@
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#include "lwip/opt.h"
#if LWIP_NETCONN
#include "lwip/api.h"
#include "lwip/sys.h"
#define UDPECHO_THREAD_PRIO ( tskIDLE_PRIORITY + 3 )
static struct netconn *conn;
static struct netbuf *buf;
static struct ip_addr *addr;
static unsigned short port;
/*-----------------------------------------------------------------------------------*/
static void udpecho_thread(void *arg)
{
err_t err;
LWIP_UNUSED_ARG(arg);
conn = netconn_new(NETCONN_UDP);
if (conn!= NULL)
{
err = netconn_bind(conn, IP_ADDR_ANY, 7);
if (err == ERR_OK)
{
while (1)
{
buf = netconn_recv(conn);
if (buf!= NULL)
{
addr = netbuf_fromaddr(buf);
port = netbuf_fromport(buf);
netconn_connect(conn, addr, port);
buf->addr = NULL;
netconn_send(conn,buf);
netbuf_delete(buf);
}
}
}
else
{
printf("can not bind netconn");
}
}
else
{
printf("can create new UDP netconn");
}
}
/*-----------------------------------------------------------------------------------*/
void udpecho_init(void)
{
sys_thread_new("udpecho_thread", udpecho_thread, NULL, DEFAULT_THREAD_STACKSIZE,UDPECHO_THREAD_PRIO );
}
#endif /* LWIP_NETCONN */

View file

@ -0,0 +1,105 @@
/*
* Media device
*
* Copyright (C) 2010 Nokia Corporation
*
* Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
* Sakari Ailus <sakari.ailus@iki.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _MEDIA_DEVICE_H
#define _MEDIA_DEVICE_H
#if 0
#include <linux/list.h>
#include <linux/mutex.h>
#include <linux/spinlock.h>
#endif
#include "v4l2-osdep.h"
#include "media-devnode.h"
#include "media-entity.h"
//struct device;
/**
* struct media_device - Media device
* @dev: Parent device
* @devnode: Media device node
* @model: Device model name
* @serial: Device serial number (optional)
* @bus_info: Unique and stable device location identifier
* @hw_revision: Hardware device revision
* @driver_version: Device driver version
* @entity_id: ID of the next entity to be registered
* @entities: List of registered entities
* @lock: Entities list lock
* @graph_mutex: Entities graph operation lock
* @link_notify: Link state change notification callback
*
* This structure represents an abstract high-level media device. It allows easy
* access to entities and provides basic media device-level support. The
* structure can be allocated directly or embedded in a larger structure.
*
* The parent @dev is a physical device. It must be set before registering the
* media device.
*
* @model is a descriptive model name exported through sysfs. It doesn't have to
* be unique.
*/
struct media_device {
/* dev->driver_data points to this struct. */
//struct device *dev;
struct media_devnode devnode;
char model[32];
char serial[40];
char bus_info[32];
u32 hw_revision;
u32 driver_version;
u32 entity_id;
struct list_head entities;
/* Protects the entities list */
spinlock_t lock;
/* Serializes graph operations. */
//struct mutex graph_mutex;
_Mutex graph_mutex;
int (*link_notify)(struct media_link *link, u32 flags, unsigned int notification);
};
/* Supported link_notify @notification values. */
#define MEDIA_DEV_NOTIFY_PRE_LINK_CH 0
#define MEDIA_DEV_NOTIFY_POST_LINK_CH 1
/* media_devnode to media_device */
#define to_media_device(node) container_of(node, struct media_device, devnode)
int media_device_register(struct media_device *mdev);
void media_device_unregister(struct media_device *mdev);
int media_device_register_entity(struct media_device *mdev,
struct media_entity *entity);
void media_device_unregister_entity(struct media_entity *entity);
/* Iterate over all entities. */
#define media_device_for_each_entity(entity, mdev, type) \
list_for_each_entry(entity, &(mdev)->entities, list, type)
#endif

View file

@ -0,0 +1,104 @@
/*
* Media device node
*
* Copyright (C) 2010 Nokia Corporation
*
* Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
* Sakari Ailus <sakari.ailus@iki.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* --
*
* Common functions for media-related drivers to register and unregister media
* device nodes.
*/
#ifndef _MEDIA_DEVNODE_H
#define _MEDIA_DEVNODE_H
#if 0
#include <linux/poll.h>
#include <linux/fs.h>
#include <linux/device.h>
#include <linux/cdev.h>
#endif
/*
* Flag to mark the media_devnode struct as registered. Drivers must not touch
* this flag directly, it will be set and cleared by media_devnode_register and
* media_devnode_unregister.
*/
#define MEDIA_FLAG_REGISTERED 0
struct media_file_operations {
//struct module *owner;
#if 0
ssize_t (*read) (char __user *, size_t, loff_t *);
ssize_t (*write) (const char __user *, size_t, loff_t *);
unsigned int (*poll) (struct poll_table_struct *);
#endif
long (*ioctl) (unsigned int, unsigned long);
long (*compat_ioctl) (unsigned int, unsigned long);
int (*open) ();
int (*release) ();
};
/**
* struct media_devnode - Media device node
* @parent: parent device
* @minor: device node minor number
* @flags: flags, combination of the MEDIA_FLAG_* constants
*
* This structure represents a media-related device node.
*
* The @parent is a physical device. It must be set by core or device drivers
* before registering the node.
*/
struct media_devnode {
/* device ops */
const struct media_file_operations *fops;
/* sysfs */
#if 0
struct device dev; /* media device */
struct cdev cdev; /* character device */
struct device *parent; /* device parent */
#endif
/* device info */
int minor;
unsigned long flags; /* Use bitops to access flags */
/* callbacks */
void (*release)(struct media_devnode *mdev);
};
/* dev to media_devnode */
#define to_media_devnode(minor) container_of(minor, struct media_devnode, dev)
int media_devnode_register(struct media_devnode *mdev);
void media_devnode_unregister(struct media_devnode *mdev);
#if 0
static inline struct media_devnode *media_devnode_data()
{
return private_data;
}
#endif
static inline int media_devnode_is_registered(struct media_devnode *mdev)
{
return test_bit(MEDIA_FLAG_REGISTERED, &mdev->flags);
}
#endif /* _MEDIA_DEVNODE_H */

View file

@ -0,0 +1,164 @@
/*
* Media entity
*
* Copyright (C) 2010 Nokia Corporation
*
* Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
* Sakari Ailus <sakari.ailus@iki.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _MEDIA_ENTITY_H
#define _MEDIA_ENTITY_H
#if 0
#include <linux/bitops.h>
#include <linux/list.h>
#include <linux/media.h>
#endif
#include "v4l2-osdep.h"
struct media_pipeline {
int media_test;
};
struct media_link {
struct media_pad *source; /* Source pad */
struct media_pad *sink; /* Sink pad */
struct media_link *reverse; /* Link in the reverse direction */
unsigned long flags; /* Link flags (MEDIA_LNK_FL_*) */
};
struct media_pad {
struct media_entity *entity; /* Entity this pad belongs to */
u16 index; /* Pad index in the entity pads array */
unsigned long flags; /* Pad flags (MEDIA_PAD_FL_*) */
};
struct media_entity_operations {
int (*link_setup)(struct media_entity *entity,
const struct media_pad *local,
const struct media_pad *remote, u32 flags);
int (*link_validate)(struct media_link *link);
};
struct media_entity {
//struct LISlist;
struct media_device *parent; /* Media device this entity belongs to*/
u32 id; /* Entity ID, unique in the parent media
* device context */
const char *name; /* Entity name */
u32 type; /* Entity type (MEDIA_ENT_T_*) */
u32 revision; /* Entity revision, driver specific */
unsigned long flags; /* Entity flags (MEDIA_ENT_FL_*) */
u32 group_id; /* Entity group ID */
u16 num_pads; /* Number of sink and source pads */
u16 num_links; /* Number of existing links, both
* enabled and disabled */
u16 num_backlinks; /* Number of backlinks */
u16 max_links; /* Maximum number of links */
struct media_pad *pads; /* Pads array (num_pads elements) */
struct media_link *links; /* Links array (max_links elements)*/
const struct media_entity_operations *ops; /* Entity operations */
/* Reference counts must never be negative, but are signed integers on
* purpose: a simple WARN_ON(<0) check can be used to detect reference
* count bugs that would make them negative.
*/
int stream_count; /* Stream count for the entity. */
int use_count; /* Use count for the entity. */
struct media_pipeline *pipe; /* Pipeline this entity belongs to. */
union {
/* Node specifications */
struct {
u32 major;
u32 minor;
} v4l;
struct {
u32 major;
u32 minor;
} fb;
struct {
u32 card;
u32 device;
u32 subdevice;
} alsa;
int dvb;
/* Sub-device specifications */
/* Nothing needed yet */
} info;
};
#if 0
static inline u32 media_entity_type(struct media_entity *entity)
{
return entity->type & MEDIA_ENT_TYPE_MASK;
}
static inline u32 media_entity_subtype(struct media_entity *entity)
{
return entity->type & MEDIA_ENT_SUBTYPE_MASK;
}
#define MEDIA_ENTITY_ENUM_MAX_DEPTH 16
#define MEDIA_ENTITY_ENUM_MAX_ID 64
struct media_entity_graph {
struct {
struct media_entity *entity;
int link;
} stack[MEDIA_ENTITY_ENUM_MAX_DEPTH];
DECLARE_BITMAP(entities, MEDIA_ENTITY_ENUM_MAX_ID);
int top;
};
int media_entity_init(struct media_entity *entity, u16 num_pads,
struct media_pad *pads, u16 extra_links);
void media_entity_cleanup(struct media_entity *entity);
int media_entity_create_link(struct media_entity *source, u16 source_pad,
struct media_entity *sink, u16 sink_pad, u32 flags);
void __media_entity_remove_links(struct media_entity *entity);
void media_entity_remove_links(struct media_entity *entity);
int __media_entity_setup_link(struct media_link *link, u32 flags);
int media_entity_setup_link(struct media_link *link, u32 flags);
struct media_link *media_entity_find_link(struct media_pad *source,
struct media_pad *sink);
struct media_pad *media_entity_remote_pad(struct media_pad *pad);
struct media_entity *media_entity_get(struct media_entity *entity);
void media_entity_put(struct media_entity *entity);
void media_entity_graph_walk_start(struct media_entity_graph *graph,
struct media_entity *entity);
struct media_entity *
media_entity_graph_walk_next(struct media_entity_graph *graph);
int media_entity_pipeline_start(struct media_entity *entity,
struct media_pipeline *pipe);
void media_entity_pipeline_stop(struct media_entity *entity);
#define media_entity_call(entity, operation, args...) \
(((entity)->ops && (entity)->ops->operation) ? \
(entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD)
#endif
#endif

View file

@ -0,0 +1,71 @@
/*
* include/linux/v4l2-common.h
*
* Common V4L2 and V4L2 subdev definitions.
*
* Users are advised to #include this file either through videodev2.h
* (V4L2) or through v4l2-subdev.h (V4L2 subdev) rather than to refer
* to this file directly.
*
* Copyright (C) 2012 Nokia Corporation
* Contact: Sakari Ailus <sakari.ailus@iki.fi>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#ifndef __V4L2_COMMON__
#define __V4L2_COMMON__
/*
*
* Selection interface definitions
*
*/
/* Current cropping area */
#define V4L2_SEL_TGT_CROP 0x0000
/* Default cropping area */
#define V4L2_SEL_TGT_CROP_DEFAULT 0x0001
/* Cropping bounds */
#define V4L2_SEL_TGT_CROP_BOUNDS 0x0002
/* Current composing area */
#define V4L2_SEL_TGT_COMPOSE 0x0100
/* Default composing area */
#define V4L2_SEL_TGT_COMPOSE_DEFAULT 0x0101
/* Composing bounds */
#define V4L2_SEL_TGT_COMPOSE_BOUNDS 0x0102
/* Current composing area plus all padding pixels */
#define V4L2_SEL_TGT_COMPOSE_PADDED 0x0103
/* Backward compatibility target definitions --- to be removed. */
#define V4L2_SEL_TGT_CROP_ACTIVE V4L2_SEL_TGT_CROP
#define V4L2_SEL_TGT_COMPOSE_ACTIVE V4L2_SEL_TGT_COMPOSE
#define V4L2_SUBDEV_SEL_TGT_CROP_ACTUAL V4L2_SEL_TGT_CROP
#define V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTUAL V4L2_SEL_TGT_COMPOSE
#define V4L2_SUBDEV_SEL_TGT_CROP_BOUNDS V4L2_SEL_TGT_CROP_BOUNDS
#define V4L2_SUBDEV_SEL_TGT_COMPOSE_BOUNDS V4L2_SEL_TGT_COMPOSE_BOUNDS
/* Selection flags */
#define V4L2_SEL_FLAG_GE (1 << 0)
#define V4L2_SEL_FLAG_LE (1 << 1)
#define V4L2_SEL_FLAG_KEEP_CONFIG (1 << 2)
/* Backward compatibility flag definitions --- to be removed. */
#define V4L2_SUBDEV_SEL_FLAG_SIZE_GE V4L2_SEL_FLAG_GE
#define V4L2_SUBDEV_SEL_FLAG_SIZE_LE V4L2_SEL_FLAG_LE
#define V4L2_SUBDEV_SEL_FLAG_KEEP_CONFIG V4L2_SEL_FLAG_KEEP_CONFIG
#endif /* __V4L2_COMMON__ */

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,99 @@
/*
* V4L2 asynchronous subdevice registration API
*
* Copyright (C) 2012-2013, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
*
* 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.
*/
#ifndef V4L2_ASYNC_H
#define V4L2_ASYNC_H
#if 0
#include <linux/list.h>
#include <linux/mutex.h>
#endif
#include "v4l2-osdep.h"
//struct device;
//struct device_node;
struct v4l2_device;
struct v4l2_subdev;
struct v4l2_async_notifier;
/* A random max subdevice number, used to allocate an array on stack */
#define V4L2_MAX_SUBDEVS 128U
enum v4l2_async_match_type {
V4L2_ASYNC_MATCH_CUSTOM,
V4L2_ASYNC_MATCH_DEVNAME,
V4L2_ASYNC_MATCH_I2C,
V4L2_ASYNC_MATCH_OF,
};
/**
* struct v4l2_async_subdev - sub-device descriptor, as known to a bridge
* @bus_type: subdevice bus type to select the appropriate matching method
* @match: union of per-bus type matching data sets
* @list: used to link struct v4l2_async_subdev objects, waiting to be
* probed, to a notifier->waiting list
*/
struct v4l2_async_subdev {
enum v4l2_async_match_type match_type;
union {
struct {
const struct device_node *node;
} of;
struct {
const char *name;
} device_name;
struct {
int adapter_id;
unsigned short address;
} i2c;
struct {
bool (*match)(const char *dev_init_name, struct v4l2_async_subdev *);
void *priv;
} custom;
} match;
/* v4l2-async core private: not to be used by drivers */
struct list_head list;
};
/**
* v4l2_async_notifier - v4l2_device notifier data
* @num_subdevs:number of subdevices
* @subdevs: array of pointers to subdevice descriptors
* @v4l2_dev: pointer to struct v4l2_device
* @waiting: list of struct v4l2_async_subdev, waiting for their drivers
* @done: list of struct v4l2_subdev, already probed
* @list: member in a global list of notifiers
* @bound: a subdevice driver has successfully probed one of subdevices
* @complete: all subdevices have been probed successfully
* @unbind: a subdevice is leaving
*/
struct v4l2_async_notifier {
unsigned int num_subdevs;
struct v4l2_async_subdev **subdevs;
struct v4l2_device *v4l2_dev;
struct list_head waiting;
struct list_head done;
struct list_head list;
int (*bound)(struct v4l2_async_notifier *notifier,
struct v4l2_subdev *subdev,
struct v4l2_async_subdev *asd);
int (*complete)(struct v4l2_async_notifier *notifier);
void (*unbind)(struct v4l2_async_notifier *notifier,
struct v4l2_subdev *subdev,
struct v4l2_async_subdev *asd);
};
int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev,
struct v4l2_async_notifier *notifier);
void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier);
int v4l2_async_register_subdev(struct v4l2_subdev *sd);
void v4l2_async_unregister_subdev(struct v4l2_subdev *sd);
#endif

View file

@ -0,0 +1,59 @@
/*
* V4L2 clock service
*
* Copyright (C) 2012-2013, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
*
* 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.
*
* ATTENTION: This is a temporary API and it shall be replaced by the generic
* clock API, when the latter becomes widely available.
*/
#ifndef MEDIA_V4L2_CLK_H
#define MEDIA_V4L2_CLK_H
#if 0
#include <linux/atomic.h>
#include <linux/list.h>
#include <linux/mutex.h>
#endif
#include "v4l2-osdep.h"
//struct module;
//struct device;
struct v4l2_clk {
struct LIST_HEADER list;
const struct v4l2_clk_ops *ops;
const char *dev_id;
const char *id;
int enable;
//struct mutex lock; /* Protect the enable count */
_Mutex lock;
atomic_t use_count;
void *priv;
};
struct v4l2_clk_ops {
//struct module *owner;
int (*enable)(struct v4l2_clk *clk);
void (*disable)(struct v4l2_clk *clk);
unsigned long (*get_rate)(struct v4l2_clk *clk);
int (*set_rate)(struct v4l2_clk *clk, unsigned long);
};
struct v4l2_clk *v4l2_clk_register(const struct v4l2_clk_ops *ops,
const char *dev_name,
const char *name, void *priv);
void v4l2_clk_unregister(struct v4l2_clk *clk);
struct v4l2_clk *v4l2_clk_get(const char *id);
void v4l2_clk_put(struct v4l2_clk *clk);
int v4l2_clk_enable(struct v4l2_clk *clk);
void v4l2_clk_disable(struct v4l2_clk *clk);
unsigned long v4l2_clk_get_rate(struct v4l2_clk *clk);
int v4l2_clk_set_rate(struct v4l2_clk *clk, unsigned long rate);
#endif

View file

@ -0,0 +1,210 @@
/*
v4l2 common internal API header
This header contains internal shared ioctl definitions for use by the
internal low-level v4l2 drivers.
Each ioctl begins with VIDIOC_INT_ to clearly mark that it is an internal
define,
Copyright (C) 2005 Hans Verkuil <hverkuil@xs4all.nl>
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef V4L2_COMMON_H_
#define V4L2_COMMON_H_
#include "v4l2-dev.h"
/* Common printk constucts for v4l-i2c drivers. These macros create a unique
prefix consisting of the driver name, the adapter number and the i2c
address. */
#if 0
#define v4l_printk(level, name, adapter, addr, fmt, arg...) \
printk(level "%s %d-%04x: " fmt, name, i2c_adapter_id(adapter), addr , ## arg)
#define v4l_client_printk(level, client, fmt, arg...) \
v4l_printk(level, (client)->driver->driver.name, (client)->adapter, \
(client)->addr, fmt , ## arg)
#define v4l_err(client, fmt, arg...) \
v4l_client_printk(KERN_ERR, client, fmt , ## arg)
#define v4l_warn(client, fmt, arg...) \
v4l_client_printk(KERN_WARNING, client, fmt , ## arg)
#define v4l_info(client, fmt, arg...) \
v4l_client_printk(KERN_INFO, client, fmt , ## arg)
/* These three macros assume that the debug level is set with a module
parameter called 'debug'. */
#define v4l_dbg(level, debug, client, fmt, arg...) \
do { \
if (debug >= (level)) \
v4l_client_printk(KERN_DEBUG, client, fmt , ## arg); \
} while (0)
#endif
/* ------------------------------------------------------------------------- */
#if 0
/* These printk constructs can be used with v4l2_device and v4l2_subdev */
#define v4l2_printk(level, dev, fmt, arg...) \
printk(level "%s: " fmt, (dev)->name , ## arg)
#define v4l2_err(dev, fmt, arg...) \
v4l2_printk(KERN_ERR, dev, fmt , ## arg)
#define v4l2_warn(dev, fmt, arg...) \
v4l2_printk(KERN_WARNING, dev, fmt , ## arg)
#define v4l2_info(dev, fmt, arg...) \
v4l2_printk(KERN_INFO, dev, fmt , ## arg)
/* These three macros assume that the debug level is set with a module
parameter called 'debug'. */
#define v4l2_dbg(level, debug, dev, fmt, arg...) \
do { \
if (debug >= (level)) \
v4l2_printk(KERN_DEBUG, dev, fmt , ## arg); \
} while (0)
#endif
/* ------------------------------------------------------------------------- */
//edit by Ian -- remove control helper functions
#if 0
/* Control helper functions */
int v4l2_ctrl_check(struct v4l2_ext_control *ctrl, struct v4l2_queryctrl *qctrl,
const char * const *menu_items);
const char *v4l2_ctrl_get_name(u32 id);
const char * const *v4l2_ctrl_get_menu(u32 id);
const s64 *v4l2_ctrl_get_int_menu(u32 id, u32 *len);
int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def);
int v4l2_ctrl_query_menu(struct v4l2_querymenu *qmenu,
struct v4l2_queryctrl *qctrl, const char * const *menu_items);
#define V4L2_CTRL_MENU_IDS_END (0xffffffff)
int v4l2_ctrl_query_menu_valid_items(struct v4l2_querymenu *qmenu, const u32 *ids);
#endif
/* Note: ctrl_classes points to an array of u32 pointers. Each u32 array is a
0-terminated array of control IDs. Each array must be sorted low to high
and belong to the same control class. The array of u32 pointers must also
be sorted, from low class IDs to high class IDs. */
//u32 v4l2_ctrl_next(const u32 * const *ctrl_classes, u32 id);
/* ------------------------------------------------------------------------- */
/* I2C Helper functions */
#if 0
struct i2c_driver;
struct i2c_adapter;
struct i2c_client;
struct i2c_device_id;
struct v4l2_device;
struct v4l2_subdev;
struct v4l2_subdev_ops;
/* Load an i2c module and return an initialized v4l2_subdev struct.
The client_type argument is the name of the chip that's on the adapter. */
struct v4l2_subdev *v4l2_i2c_new_subdev(struct v4l2_device *v4l2_dev,
struct i2c_adapter *adapter, const char *client_type,
u8 addr, const unsigned short *probe_addrs);
struct i2c_board_info;
struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
struct i2c_adapter *adapter, struct i2c_board_info *info,
const unsigned short *probe_addrs);
/* Initialize a v4l2_subdev with data from an i2c_client struct */
void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client,
const struct v4l2_subdev_ops *ops);
/* Return i2c client address of v4l2_subdev. */
unsigned short v4l2_i2c_subdev_addr(struct v4l2_subdev *sd);
enum v4l2_i2c_tuner_type {
ADDRS_RADIO, /* Radio tuner addresses */
ADDRS_DEMOD, /* Demod tuner addresses */
ADDRS_TV, /* TV tuner addresses */
/* TV tuner addresses if demod is present, this excludes
addresses used by the demodulator from the list of
candidates. */
ADDRS_TV_WITH_DEMOD,
};
/* Return a list of I2C tuner addresses to probe. Use only if the tuner
addresses are unknown. */
const unsigned short *v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type);
/* ------------------------------------------------------------------------- */
/* SPI Helper functions */
#if defined(CONFIG_SPI)
#include <linux/spi/spi.h>
struct spi_device;
/* Load an spi module and return an initialized v4l2_subdev struct.
The client_type argument is the name of the chip that's on the adapter. */
struct v4l2_subdev *v4l2_spi_new_subdev(struct v4l2_device *v4l2_dev,
struct spi_master *master, struct spi_board_info *info);
/* Initialize a v4l2_subdev with data from an spi_device struct */
void v4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi,
const struct v4l2_subdev_ops *ops);
#endif
#endif
/* ------------------------------------------------------------------------- */
#if 0
/* Note: these remaining ioctls/structs should be removed as well, but they are
still used in tuner-simple.c (TUNER_SET_CONFIG), cx18/ivtv (RESET) and
v4l2-int-device.h (v4l2_routing). To remove these ioctls some more cleanup
is needed in those modules. */
/* s_config */
struct v4l2_priv_tun_config {
int tuner;
void *priv;
};
#define TUNER_SET_CONFIG _IOW('d', 92, struct v4l2_priv_tun_config)
#define VIDIOC_INT_RESET _IOW ('d', 102, u32)
struct v4l2_routing {
u32 input;
u32 output;
};
#endif
/* ------------------------------------------------------------------------- */
/* Miscellaneous helper functions */
#if 0
void v4l_bound_align_image(u32*w, unsigned int wmin,
unsigned int wmax, unsigned int walign,
u32 *h, unsigned int hmin,
unsigned int hmax, unsigned int halign,
unsigned int salign);
struct v4l2_discrete_probe {
const struct v4l2_frmsize_discrete *sizes;
int num_sizes;
};
const struct v4l2_frmsize_discrete *v4l2_find_nearest_format(
const struct v4l2_discrete_probe *probe,
s32 width, s32 height);
#endif
//void v4l2_get_timestamp(struct timeval *tv);
#endif /* V4L2_COMMON_H_ */

View file

@ -0,0 +1,885 @@
/*
* Video for Linux Two controls header file
*
* Copyright (C) 1999-2012 the contributors
*
* 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.
*
* Alternatively you can redistribute this file under the terms of the
* BSD license as stated below:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. The names of its contributors may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The contents of this header was split off from videodev2.h. All control
* definitions should be added to this header, which is included by
* videodev2.h.
*/
#ifndef __LINUX_V4L2_CONTROLS_H
#define __LINUX_V4L2_CONTROLS_H
/* Control classes */
#define V4L2_CTRL_CLASS_USER 0x00980000 /* Old-style 'user' controls */
#define V4L2_CTRL_CLASS_MPEG 0x00990000 /* MPEG-compression controls */
#define V4L2_CTRL_CLASS_CAMERA 0x009a0000 /* Camera class controls */
#define V4L2_CTRL_CLASS_FM_TX 0x009b0000 /* FM Modulator controls */
#define V4L2_CTRL_CLASS_FLASH 0x009c0000 /* Camera flash controls */
#define V4L2_CTRL_CLASS_JPEG 0x009d0000 /* JPEG-compression controls */
#define V4L2_CTRL_CLASS_IMAGE_SOURCE 0x009e0000 /* Image source controls */
#define V4L2_CTRL_CLASS_IMAGE_PROC 0x009f0000 /* Image processing controls */
#define V4L2_CTRL_CLASS_DV 0x00a00000 /* Digital Video controls */
#define V4L2_CTRL_CLASS_FM_RX 0x00a10000 /* FM Receiver controls */
/* User-class control IDs */
#define V4L2_CID_BASE (V4L2_CTRL_CLASS_USER | 0x900)
#define V4L2_CID_USER_BASE V4L2_CID_BASE
#define V4L2_CID_USER_CLASS (V4L2_CTRL_CLASS_USER | 1)
#define V4L2_CID_BRIGHTNESS (V4L2_CID_BASE+0)
#define V4L2_CID_CONTRAST (V4L2_CID_BASE+1)
#define V4L2_CID_SATURATION (V4L2_CID_BASE+2)
#define V4L2_CID_HUE (V4L2_CID_BASE+3)
#define V4L2_CID_AUDIO_VOLUME (V4L2_CID_BASE+5)
#define V4L2_CID_AUDIO_BALANCE (V4L2_CID_BASE+6)
#define V4L2_CID_AUDIO_BASS (V4L2_CID_BASE+7)
#define V4L2_CID_AUDIO_TREBLE (V4L2_CID_BASE+8)
#define V4L2_CID_AUDIO_MUTE (V4L2_CID_BASE+9)
#define V4L2_CID_AUDIO_LOUDNESS (V4L2_CID_BASE+10)
#define V4L2_CID_BLACK_LEVEL (V4L2_CID_BASE+11) /* Deprecated */
#define V4L2_CID_AUTO_WHITE_BALANCE (V4L2_CID_BASE+12)
#define V4L2_CID_DO_WHITE_BALANCE (V4L2_CID_BASE+13)
#define V4L2_CID_RED_BALANCE (V4L2_CID_BASE+14)
#define V4L2_CID_BLUE_BALANCE (V4L2_CID_BASE+15)
#define V4L2_CID_GAMMA (V4L2_CID_BASE+16)
#define V4L2_CID_WHITENESS (V4L2_CID_GAMMA) /* Deprecated */
#define V4L2_CID_EXPOSURE (V4L2_CID_BASE+17)
#define V4L2_CID_AUTOGAIN (V4L2_CID_BASE+18)
#define V4L2_CID_GAIN (V4L2_CID_BASE+19)
#define V4L2_CID_HFLIP (V4L2_CID_BASE+20)
#define V4L2_CID_VFLIP (V4L2_CID_BASE+21)
#define V4L2_CID_POWER_LINE_FREQUENCY (V4L2_CID_BASE+24)
enum v4l2_power_line_frequency {
V4L2_CID_POWER_LINE_FREQUENCY_DISABLED = 0,
V4L2_CID_POWER_LINE_FREQUENCY_50HZ = 1,
V4L2_CID_POWER_LINE_FREQUENCY_60HZ = 2,
V4L2_CID_POWER_LINE_FREQUENCY_AUTO = 3,
};
#define V4L2_CID_HUE_AUTO (V4L2_CID_BASE+25)
#define V4L2_CID_WHITE_BALANCE_TEMPERATURE (V4L2_CID_BASE+26)
#define V4L2_CID_SHARPNESS (V4L2_CID_BASE+27)
#define V4L2_CID_BACKLIGHT_COMPENSATION (V4L2_CID_BASE+28)
#define V4L2_CID_CHROMA_AGC (V4L2_CID_BASE+29)
#define V4L2_CID_COLOR_KILLER (V4L2_CID_BASE+30)
#define V4L2_CID_COLORFX (V4L2_CID_BASE+31)
enum v4l2_colorfx {
V4L2_COLORFX_NONE = 0,
V4L2_COLORFX_BW = 1,
V4L2_COLORFX_SEPIA = 2,
V4L2_COLORFX_NEGATIVE = 3,
V4L2_COLORFX_EMBOSS = 4,
V4L2_COLORFX_SKETCH = 5,
V4L2_COLORFX_SKY_BLUE = 6,
V4L2_COLORFX_GRASS_GREEN = 7,
V4L2_COLORFX_SKIN_WHITEN = 8,
V4L2_COLORFX_VIVID = 9,
V4L2_COLORFX_AQUA = 10,
V4L2_COLORFX_ART_FREEZE = 11,
V4L2_COLORFX_SILHOUETTE = 12,
V4L2_COLORFX_SOLARIZATION = 13,
V4L2_COLORFX_ANTIQUE = 14,
V4L2_COLORFX_SET_CBCR = 15,
};
#define V4L2_CID_AUTOBRIGHTNESS (V4L2_CID_BASE+32)
#define V4L2_CID_BAND_STOP_FILTER (V4L2_CID_BASE+33)
#define V4L2_CID_ROTATE (V4L2_CID_BASE+34)
#define V4L2_CID_BG_COLOR (V4L2_CID_BASE+35)
#define V4L2_CID_CHROMA_GAIN (V4L2_CID_BASE+36)
#define V4L2_CID_ILLUMINATORS_1 (V4L2_CID_BASE+37)
#define V4L2_CID_ILLUMINATORS_2 (V4L2_CID_BASE+38)
#define V4L2_CID_MIN_BUFFERS_FOR_CAPTURE (V4L2_CID_BASE+39)
#define V4L2_CID_MIN_BUFFERS_FOR_OUTPUT (V4L2_CID_BASE+40)
#define V4L2_CID_ALPHA_COMPONENT (V4L2_CID_BASE+41)
#define V4L2_CID_COLORFX_CBCR (V4L2_CID_BASE+42)
/* last CID + 1 */
#define V4L2_CID_LASTP1 (V4L2_CID_BASE+43)
/* USER-class private control IDs */
/* The base for the meye driver controls. See linux/meye.h for the list
* of controls. We reserve 16 controls for this driver. */
#define V4L2_CID_USER_MEYE_BASE (V4L2_CID_USER_BASE + 0x1000)
/* The base for the bttv driver controls.
* We reserve 32 controls for this driver. */
#define V4L2_CID_USER_BTTV_BASE (V4L2_CID_USER_BASE + 0x1010)
/* The base for the s2255 driver controls.
* We reserve 16 controls for this driver. */
#define V4L2_CID_USER_S2255_BASE (V4L2_CID_USER_BASE + 0x1030)
/* The base for the si476x driver controls. See include/media/si476x.h for the list
* of controls. Total of 16 controls is reserved for this driver */
#define V4L2_CID_USER_SI476X_BASE (V4L2_CID_USER_BASE + 0x1040)
/* MPEG-class control IDs */
/* The MPEG controls are applicable to all codec controls
* and the 'MPEG' part of the define is historical */
#define V4L2_CID_MPEG_BASE (V4L2_CTRL_CLASS_MPEG | 0x900)
#define V4L2_CID_MPEG_CLASS (V4L2_CTRL_CLASS_MPEG | 1)
/* MPEG streams, specific to multiplexed streams */
#define V4L2_CID_MPEG_STREAM_TYPE (V4L2_CID_MPEG_BASE+0)
enum v4l2_mpeg_stream_type {
V4L2_MPEG_STREAM_TYPE_MPEG2_PS = 0, /* MPEG-2 program stream */
V4L2_MPEG_STREAM_TYPE_MPEG2_TS = 1, /* MPEG-2 transport stream */
V4L2_MPEG_STREAM_TYPE_MPEG1_SS = 2, /* MPEG-1 system stream */
V4L2_MPEG_STREAM_TYPE_MPEG2_DVD = 3, /* MPEG-2 DVD-compatible stream */
V4L2_MPEG_STREAM_TYPE_MPEG1_VCD = 4, /* MPEG-1 VCD-compatible stream */
V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD = 5, /* MPEG-2 SVCD-compatible stream */
};
#define V4L2_CID_MPEG_STREAM_PID_PMT (V4L2_CID_MPEG_BASE+1)
#define V4L2_CID_MPEG_STREAM_PID_AUDIO (V4L2_CID_MPEG_BASE+2)
#define V4L2_CID_MPEG_STREAM_PID_VIDEO (V4L2_CID_MPEG_BASE+3)
#define V4L2_CID_MPEG_STREAM_PID_PCR (V4L2_CID_MPEG_BASE+4)
#define V4L2_CID_MPEG_STREAM_PES_ID_AUDIO (V4L2_CID_MPEG_BASE+5)
#define V4L2_CID_MPEG_STREAM_PES_ID_VIDEO (V4L2_CID_MPEG_BASE+6)
#define V4L2_CID_MPEG_STREAM_VBI_FMT (V4L2_CID_MPEG_BASE+7)
enum v4l2_mpeg_stream_vbi_fmt {
V4L2_MPEG_STREAM_VBI_FMT_NONE = 0, /* No VBI in the MPEG stream */
V4L2_MPEG_STREAM_VBI_FMT_IVTV = 1, /* VBI in private packets, IVTV format */
};
/* MPEG audio controls specific to multiplexed streams */
#define V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ (V4L2_CID_MPEG_BASE+100)
enum v4l2_mpeg_audio_sampling_freq {
V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100 = 0,
V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000 = 1,
V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000 = 2,
};
#define V4L2_CID_MPEG_AUDIO_ENCODING (V4L2_CID_MPEG_BASE+101)
enum v4l2_mpeg_audio_encoding {
V4L2_MPEG_AUDIO_ENCODING_LAYER_1 = 0,
V4L2_MPEG_AUDIO_ENCODING_LAYER_2 = 1,
V4L2_MPEG_AUDIO_ENCODING_LAYER_3 = 2,
V4L2_MPEG_AUDIO_ENCODING_AAC = 3,
V4L2_MPEG_AUDIO_ENCODING_AC3 = 4,
};
#define V4L2_CID_MPEG_AUDIO_L1_BITRATE (V4L2_CID_MPEG_BASE+102)
enum v4l2_mpeg_audio_l1_bitrate {
V4L2_MPEG_AUDIO_L1_BITRATE_32K = 0,
V4L2_MPEG_AUDIO_L1_BITRATE_64K = 1,
V4L2_MPEG_AUDIO_L1_BITRATE_96K = 2,
V4L2_MPEG_AUDIO_L1_BITRATE_128K = 3,
V4L2_MPEG_AUDIO_L1_BITRATE_160K = 4,
V4L2_MPEG_AUDIO_L1_BITRATE_192K = 5,
V4L2_MPEG_AUDIO_L1_BITRATE_224K = 6,
V4L2_MPEG_AUDIO_L1_BITRATE_256K = 7,
V4L2_MPEG_AUDIO_L1_BITRATE_288K = 8,
V4L2_MPEG_AUDIO_L1_BITRATE_320K = 9,
V4L2_MPEG_AUDIO_L1_BITRATE_352K = 10,
V4L2_MPEG_AUDIO_L1_BITRATE_384K = 11,
V4L2_MPEG_AUDIO_L1_BITRATE_416K = 12,
V4L2_MPEG_AUDIO_L1_BITRATE_448K = 13,
};
#define V4L2_CID_MPEG_AUDIO_L2_BITRATE (V4L2_CID_MPEG_BASE+103)
enum v4l2_mpeg_audio_l2_bitrate {
V4L2_MPEG_AUDIO_L2_BITRATE_32K = 0,
V4L2_MPEG_AUDIO_L2_BITRATE_48K = 1,
V4L2_MPEG_AUDIO_L2_BITRATE_56K = 2,
V4L2_MPEG_AUDIO_L2_BITRATE_64K = 3,
V4L2_MPEG_AUDIO_L2_BITRATE_80K = 4,
V4L2_MPEG_AUDIO_L2_BITRATE_96K = 5,
V4L2_MPEG_AUDIO_L2_BITRATE_112K = 6,
V4L2_MPEG_AUDIO_L2_BITRATE_128K = 7,
V4L2_MPEG_AUDIO_L2_BITRATE_160K = 8,
V4L2_MPEG_AUDIO_L2_BITRATE_192K = 9,
V4L2_MPEG_AUDIO_L2_BITRATE_224K = 10,
V4L2_MPEG_AUDIO_L2_BITRATE_256K = 11,
V4L2_MPEG_AUDIO_L2_BITRATE_320K = 12,
V4L2_MPEG_AUDIO_L2_BITRATE_384K = 13,
};
#define V4L2_CID_MPEG_AUDIO_L3_BITRATE (V4L2_CID_MPEG_BASE+104)
enum v4l2_mpeg_audio_l3_bitrate {
V4L2_MPEG_AUDIO_L3_BITRATE_32K = 0,
V4L2_MPEG_AUDIO_L3_BITRATE_40K = 1,
V4L2_MPEG_AUDIO_L3_BITRATE_48K = 2,
V4L2_MPEG_AUDIO_L3_BITRATE_56K = 3,
V4L2_MPEG_AUDIO_L3_BITRATE_64K = 4,
V4L2_MPEG_AUDIO_L3_BITRATE_80K = 5,
V4L2_MPEG_AUDIO_L3_BITRATE_96K = 6,
V4L2_MPEG_AUDIO_L3_BITRATE_112K = 7,
V4L2_MPEG_AUDIO_L3_BITRATE_128K = 8,
V4L2_MPEG_AUDIO_L3_BITRATE_160K = 9,
V4L2_MPEG_AUDIO_L3_BITRATE_192K = 10,
V4L2_MPEG_AUDIO_L3_BITRATE_224K = 11,
V4L2_MPEG_AUDIO_L3_BITRATE_256K = 12,
V4L2_MPEG_AUDIO_L3_BITRATE_320K = 13,
};
#define V4L2_CID_MPEG_AUDIO_MODE (V4L2_CID_MPEG_BASE+105)
enum v4l2_mpeg_audio_mode {
V4L2_MPEG_AUDIO_MODE_STEREO = 0,
V4L2_MPEG_AUDIO_MODE_JOINT_STEREO = 1,
V4L2_MPEG_AUDIO_MODE_DUAL = 2,
V4L2_MPEG_AUDIO_MODE_MONO = 3,
};
#define V4L2_CID_MPEG_AUDIO_MODE_EXTENSION (V4L2_CID_MPEG_BASE+106)
enum v4l2_mpeg_audio_mode_extension {
V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4 = 0,
V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_8 = 1,
V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_12 = 2,
V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_16 = 3,
};
#define V4L2_CID_MPEG_AUDIO_EMPHASIS (V4L2_CID_MPEG_BASE+107)
enum v4l2_mpeg_audio_emphasis {
V4L2_MPEG_AUDIO_EMPHASIS_NONE = 0,
V4L2_MPEG_AUDIO_EMPHASIS_50_DIV_15_uS = 1,
V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17 = 2,
};
#define V4L2_CID_MPEG_AUDIO_CRC (V4L2_CID_MPEG_BASE+108)
enum v4l2_mpeg_audio_crc {
V4L2_MPEG_AUDIO_CRC_NONE = 0,
V4L2_MPEG_AUDIO_CRC_CRC16 = 1,
};
#define V4L2_CID_MPEG_AUDIO_MUTE (V4L2_CID_MPEG_BASE+109)
#define V4L2_CID_MPEG_AUDIO_AAC_BITRATE (V4L2_CID_MPEG_BASE+110)
#define V4L2_CID_MPEG_AUDIO_AC3_BITRATE (V4L2_CID_MPEG_BASE+111)
enum v4l2_mpeg_audio_ac3_bitrate {
V4L2_MPEG_AUDIO_AC3_BITRATE_32K = 0,
V4L2_MPEG_AUDIO_AC3_BITRATE_40K = 1,
V4L2_MPEG_AUDIO_AC3_BITRATE_48K = 2,
V4L2_MPEG_AUDIO_AC3_BITRATE_56K = 3,
V4L2_MPEG_AUDIO_AC3_BITRATE_64K = 4,
V4L2_MPEG_AUDIO_AC3_BITRATE_80K = 5,
V4L2_MPEG_AUDIO_AC3_BITRATE_96K = 6,
V4L2_MPEG_AUDIO_AC3_BITRATE_112K = 7,
V4L2_MPEG_AUDIO_AC3_BITRATE_128K = 8,
V4L2_MPEG_AUDIO_AC3_BITRATE_160K = 9,
V4L2_MPEG_AUDIO_AC3_BITRATE_192K = 10,
V4L2_MPEG_AUDIO_AC3_BITRATE_224K = 11,
V4L2_MPEG_AUDIO_AC3_BITRATE_256K = 12,
V4L2_MPEG_AUDIO_AC3_BITRATE_320K = 13,
V4L2_MPEG_AUDIO_AC3_BITRATE_384K = 14,
V4L2_MPEG_AUDIO_AC3_BITRATE_448K = 15,
V4L2_MPEG_AUDIO_AC3_BITRATE_512K = 16,
V4L2_MPEG_AUDIO_AC3_BITRATE_576K = 17,
V4L2_MPEG_AUDIO_AC3_BITRATE_640K = 18,
};
#define V4L2_CID_MPEG_AUDIO_DEC_PLAYBACK (V4L2_CID_MPEG_BASE+112)
enum v4l2_mpeg_audio_dec_playback {
V4L2_MPEG_AUDIO_DEC_PLAYBACK_AUTO = 0,
V4L2_MPEG_AUDIO_DEC_PLAYBACK_STEREO = 1,
V4L2_MPEG_AUDIO_DEC_PLAYBACK_LEFT = 2,
V4L2_MPEG_AUDIO_DEC_PLAYBACK_RIGHT = 3,
V4L2_MPEG_AUDIO_DEC_PLAYBACK_MONO = 4,
V4L2_MPEG_AUDIO_DEC_PLAYBACK_SWAPPED_STEREO = 5,
};
#define V4L2_CID_MPEG_AUDIO_DEC_MULTILINGUAL_PLAYBACK (V4L2_CID_MPEG_BASE+113)
/* MPEG video controls specific to multiplexed streams */
#define V4L2_CID_MPEG_VIDEO_ENCODING (V4L2_CID_MPEG_BASE+200)
enum v4l2_mpeg_video_encoding {
V4L2_MPEG_VIDEO_ENCODING_MPEG_1 = 0,
V4L2_MPEG_VIDEO_ENCODING_MPEG_2 = 1,
V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC = 2,
};
#define V4L2_CID_MPEG_VIDEO_ASPECT (V4L2_CID_MPEG_BASE+201)
enum v4l2_mpeg_video_aspect {
V4L2_MPEG_VIDEO_ASPECT_1x1 = 0,
V4L2_MPEG_VIDEO_ASPECT_4x3 = 1,
V4L2_MPEG_VIDEO_ASPECT_16x9 = 2,
V4L2_MPEG_VIDEO_ASPECT_221x100 = 3,
};
#define V4L2_CID_MPEG_VIDEO_B_FRAMES (V4L2_CID_MPEG_BASE+202)
#define V4L2_CID_MPEG_VIDEO_GOP_SIZE (V4L2_CID_MPEG_BASE+203)
#define V4L2_CID_MPEG_VIDEO_GOP_CLOSURE (V4L2_CID_MPEG_BASE+204)
#define V4L2_CID_MPEG_VIDEO_PULLDOWN (V4L2_CID_MPEG_BASE+205)
#define V4L2_CID_MPEG_VIDEO_BITRATE_MODE (V4L2_CID_MPEG_BASE+206)
enum v4l2_mpeg_video_bitrate_mode {
V4L2_MPEG_VIDEO_BITRATE_MODE_VBR = 0,
V4L2_MPEG_VIDEO_BITRATE_MODE_CBR = 1,
};
#define V4L2_CID_MPEG_VIDEO_BITRATE (V4L2_CID_MPEG_BASE+207)
#define V4L2_CID_MPEG_VIDEO_BITRATE_PEAK (V4L2_CID_MPEG_BASE+208)
#define V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION (V4L2_CID_MPEG_BASE+209)
#define V4L2_CID_MPEG_VIDEO_MUTE (V4L2_CID_MPEG_BASE+210)
#define V4L2_CID_MPEG_VIDEO_MUTE_YUV (V4L2_CID_MPEG_BASE+211)
#define V4L2_CID_MPEG_VIDEO_DECODER_SLICE_INTERFACE (V4L2_CID_MPEG_BASE+212)
#define V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER (V4L2_CID_MPEG_BASE+213)
#define V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB (V4L2_CID_MPEG_BASE+214)
#define V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE (V4L2_CID_MPEG_BASE+215)
#define V4L2_CID_MPEG_VIDEO_HEADER_MODE (V4L2_CID_MPEG_BASE+216)
enum v4l2_mpeg_video_header_mode {
V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE = 0,
V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME = 1,
};
#define V4L2_CID_MPEG_VIDEO_MAX_REF_PIC (V4L2_CID_MPEG_BASE+217)
#define V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE (V4L2_CID_MPEG_BASE+218)
#define V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES (V4L2_CID_MPEG_BASE+219)
#define V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB (V4L2_CID_MPEG_BASE+220)
#define V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE (V4L2_CID_MPEG_BASE+221)
enum v4l2_mpeg_video_multi_slice_mode {
V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE = 0,
V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_MB = 1,
V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES = 2,
};
#define V4L2_CID_MPEG_VIDEO_VBV_SIZE (V4L2_CID_MPEG_BASE+222)
#define V4L2_CID_MPEG_VIDEO_DEC_PTS (V4L2_CID_MPEG_BASE+223)
#define V4L2_CID_MPEG_VIDEO_DEC_FRAME (V4L2_CID_MPEG_BASE+224)
#define V4L2_CID_MPEG_VIDEO_VBV_DELAY (V4L2_CID_MPEG_BASE+225)
#define V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER (V4L2_CID_MPEG_BASE+226)
#define V4L2_CID_MPEG_VIDEO_H263_I_FRAME_QP (V4L2_CID_MPEG_BASE+300)
#define V4L2_CID_MPEG_VIDEO_H263_P_FRAME_QP (V4L2_CID_MPEG_BASE+301)
#define V4L2_CID_MPEG_VIDEO_H263_B_FRAME_QP (V4L2_CID_MPEG_BASE+302)
#define V4L2_CID_MPEG_VIDEO_H263_MIN_QP (V4L2_CID_MPEG_BASE+303)
#define V4L2_CID_MPEG_VIDEO_H263_MAX_QP (V4L2_CID_MPEG_BASE+304)
#define V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP (V4L2_CID_MPEG_BASE+350)
#define V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP (V4L2_CID_MPEG_BASE+351)
#define V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP (V4L2_CID_MPEG_BASE+352)
#define V4L2_CID_MPEG_VIDEO_H264_MIN_QP (V4L2_CID_MPEG_BASE+353)
#define V4L2_CID_MPEG_VIDEO_H264_MAX_QP (V4L2_CID_MPEG_BASE+354)
#define V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM (V4L2_CID_MPEG_BASE+355)
#define V4L2_CID_MPEG_VIDEO_H264_CPB_SIZE (V4L2_CID_MPEG_BASE+356)
#define V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE (V4L2_CID_MPEG_BASE+357)
enum v4l2_mpeg_video_h264_entropy_mode {
V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CAVLC = 0,
V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CABAC = 1,
};
#define V4L2_CID_MPEG_VIDEO_H264_I_PERIOD (V4L2_CID_MPEG_BASE+358)
#define V4L2_CID_MPEG_VIDEO_H264_LEVEL (V4L2_CID_MPEG_BASE+359)
enum v4l2_mpeg_video_h264_level {
V4L2_MPEG_VIDEO_H264_LEVEL_1_0 = 0,
V4L2_MPEG_VIDEO_H264_LEVEL_1B = 1,
V4L2_MPEG_VIDEO_H264_LEVEL_1_1 = 2,
V4L2_MPEG_VIDEO_H264_LEVEL_1_2 = 3,
V4L2_MPEG_VIDEO_H264_LEVEL_1_3 = 4,
V4L2_MPEG_VIDEO_H264_LEVEL_2_0 = 5,
V4L2_MPEG_VIDEO_H264_LEVEL_2_1 = 6,
V4L2_MPEG_VIDEO_H264_LEVEL_2_2 = 7,
V4L2_MPEG_VIDEO_H264_LEVEL_3_0 = 8,
V4L2_MPEG_VIDEO_H264_LEVEL_3_1 = 9,
V4L2_MPEG_VIDEO_H264_LEVEL_3_2 = 10,
V4L2_MPEG_VIDEO_H264_LEVEL_4_0 = 11,
V4L2_MPEG_VIDEO_H264_LEVEL_4_1 = 12,
V4L2_MPEG_VIDEO_H264_LEVEL_4_2 = 13,
V4L2_MPEG_VIDEO_H264_LEVEL_5_0 = 14,
V4L2_MPEG_VIDEO_H264_LEVEL_5_1 = 15,
};
#define V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA (V4L2_CID_MPEG_BASE+360)
#define V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA (V4L2_CID_MPEG_BASE+361)
#define V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE (V4L2_CID_MPEG_BASE+362)
enum v4l2_mpeg_video_h264_loop_filter_mode {
V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_ENABLED = 0,
V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED = 1,
V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED_AT_SLICE_BOUNDARY = 2,
};
#define V4L2_CID_MPEG_VIDEO_H264_PROFILE (V4L2_CID_MPEG_BASE+363)
enum v4l2_mpeg_video_h264_profile {
V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE = 0,
V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE = 1,
V4L2_MPEG_VIDEO_H264_PROFILE_MAIN = 2,
V4L2_MPEG_VIDEO_H264_PROFILE_EXTENDED = 3,
V4L2_MPEG_VIDEO_H264_PROFILE_HIGH = 4,
V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_10 = 5,
V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_422 = 6,
V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_444_PREDICTIVE = 7,
V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_10_INTRA = 8,
V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_422_INTRA = 9,
V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_444_INTRA = 10,
V4L2_MPEG_VIDEO_H264_PROFILE_CAVLC_444_INTRA = 11,
V4L2_MPEG_VIDEO_H264_PROFILE_SCALABLE_BASELINE = 12,
V4L2_MPEG_VIDEO_H264_PROFILE_SCALABLE_HIGH = 13,
V4L2_MPEG_VIDEO_H264_PROFILE_SCALABLE_HIGH_INTRA = 14,
V4L2_MPEG_VIDEO_H264_PROFILE_STEREO_HIGH = 15,
V4L2_MPEG_VIDEO_H264_PROFILE_MULTIVIEW_HIGH = 16,
};
#define V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_HEIGHT (V4L2_CID_MPEG_BASE+364)
#define V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_WIDTH (V4L2_CID_MPEG_BASE+365)
#define V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_ENABLE (V4L2_CID_MPEG_BASE+366)
#define V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_IDC (V4L2_CID_MPEG_BASE+367)
enum v4l2_mpeg_video_h264_vui_sar_idc {
V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_UNSPECIFIED = 0,
V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_1x1 = 1,
V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_12x11 = 2,
V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_10x11 = 3,
V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_16x11 = 4,
V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_40x33 = 5,
V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_24x11 = 6,
V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_20x11 = 7,
V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_32x11 = 8,
V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_80x33 = 9,
V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_18x11 = 10,
V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_15x11 = 11,
V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_64x33 = 12,
V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_160x99 = 13,
V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_4x3 = 14,
V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_3x2 = 15,
V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_2x1 = 16,
V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_EXTENDED = 17,
};
#define V4L2_CID_MPEG_VIDEO_H264_SEI_FRAME_PACKING (V4L2_CID_MPEG_BASE+368)
#define V4L2_CID_MPEG_VIDEO_H264_SEI_FP_CURRENT_FRAME_0 (V4L2_CID_MPEG_BASE+369)
#define V4L2_CID_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE (V4L2_CID_MPEG_BASE+370)
enum v4l2_mpeg_video_h264_sei_fp_arrangement_type {
V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_CHECKERBOARD = 0,
V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_COLUMN = 1,
V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_ROW = 2,
V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_SIDE_BY_SIDE = 3,
V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_TOP_BOTTOM = 4,
V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_TEMPORAL = 5,
};
#define V4L2_CID_MPEG_VIDEO_H264_FMO (V4L2_CID_MPEG_BASE+371)
#define V4L2_CID_MPEG_VIDEO_H264_FMO_MAP_TYPE (V4L2_CID_MPEG_BASE+372)
enum v4l2_mpeg_video_h264_fmo_map_type {
V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_INTERLEAVED_SLICES = 0,
V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_SCATTERED_SLICES = 1,
V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_FOREGROUND_WITH_LEFT_OVER = 2,
V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_BOX_OUT = 3,
V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_RASTER_SCAN = 4,
V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_WIPE_SCAN = 5,
V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_EXPLICIT = 6,
};
#define V4L2_CID_MPEG_VIDEO_H264_FMO_SLICE_GROUP (V4L2_CID_MPEG_BASE+373)
#define V4L2_CID_MPEG_VIDEO_H264_FMO_CHANGE_DIRECTION (V4L2_CID_MPEG_BASE+374)
enum v4l2_mpeg_video_h264_fmo_change_dir {
V4L2_MPEG_VIDEO_H264_FMO_CHANGE_DIR_RIGHT = 0,
V4L2_MPEG_VIDEO_H264_FMO_CHANGE_DIR_LEFT = 1,
};
#define V4L2_CID_MPEG_VIDEO_H264_FMO_CHANGE_RATE (V4L2_CID_MPEG_BASE+375)
#define V4L2_CID_MPEG_VIDEO_H264_FMO_RUN_LENGTH (V4L2_CID_MPEG_BASE+376)
#define V4L2_CID_MPEG_VIDEO_H264_ASO (V4L2_CID_MPEG_BASE+377)
#define V4L2_CID_MPEG_VIDEO_H264_ASO_SLICE_ORDER (V4L2_CID_MPEG_BASE+378)
#define V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING (V4L2_CID_MPEG_BASE+379)
#define V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_TYPE (V4L2_CID_MPEG_BASE+380)
enum v4l2_mpeg_video_h264_hierarchical_coding_type {
V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_B = 0,
V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_P = 1,
};
#define V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_LAYER (V4L2_CID_MPEG_BASE+381)
#define V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_LAYER_QP (V4L2_CID_MPEG_BASE+382)
#define V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP (V4L2_CID_MPEG_BASE+400)
#define V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP (V4L2_CID_MPEG_BASE+401)
#define V4L2_CID_MPEG_VIDEO_MPEG4_B_FRAME_QP (V4L2_CID_MPEG_BASE+402)
#define V4L2_CID_MPEG_VIDEO_MPEG4_MIN_QP (V4L2_CID_MPEG_BASE+403)
#define V4L2_CID_MPEG_VIDEO_MPEG4_MAX_QP (V4L2_CID_MPEG_BASE+404)
#define V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL (V4L2_CID_MPEG_BASE+405)
enum v4l2_mpeg_video_mpeg4_level {
V4L2_MPEG_VIDEO_MPEG4_LEVEL_0 = 0,
V4L2_MPEG_VIDEO_MPEG4_LEVEL_0B = 1,
V4L2_MPEG_VIDEO_MPEG4_LEVEL_1 = 2,
V4L2_MPEG_VIDEO_MPEG4_LEVEL_2 = 3,
V4L2_MPEG_VIDEO_MPEG4_LEVEL_3 = 4,
V4L2_MPEG_VIDEO_MPEG4_LEVEL_3B = 5,
V4L2_MPEG_VIDEO_MPEG4_LEVEL_4 = 6,
V4L2_MPEG_VIDEO_MPEG4_LEVEL_5 = 7,
};
#define V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE (V4L2_CID_MPEG_BASE+406)
enum v4l2_mpeg_video_mpeg4_profile {
V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE = 0,
V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_SIMPLE = 1,
V4L2_MPEG_VIDEO_MPEG4_PROFILE_CORE = 2,
V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE_SCALABLE = 3,
V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_CODING_EFFICIENCY = 4,
};
#define V4L2_CID_MPEG_VIDEO_MPEG4_QPEL (V4L2_CID_MPEG_BASE+407)
/* Control IDs for VP8 streams
* Although VP8 is not part of MPEG we add these controls to the MPEG class
* as that class is already handling other video compression standards
*/
#define V4L2_CID_MPEG_VIDEO_VPX_NUM_PARTITIONS (V4L2_CID_MPEG_BASE+500)
enum v4l2_vp8_num_partitions {
V4L2_CID_MPEG_VIDEO_VPX_1_PARTITION = 0,
V4L2_CID_MPEG_VIDEO_VPX_2_PARTITIONS = 1,
V4L2_CID_MPEG_VIDEO_VPX_4_PARTITIONS = 2,
V4L2_CID_MPEG_VIDEO_VPX_8_PARTITIONS = 3,
};
#define V4L2_CID_MPEG_VIDEO_VPX_IMD_DISABLE_4X4 (V4L2_CID_MPEG_BASE+501)
#define V4L2_CID_MPEG_VIDEO_VPX_NUM_REF_FRAMES (V4L2_CID_MPEG_BASE+502)
enum v4l2_vp8_num_ref_frames {
V4L2_CID_MPEG_VIDEO_VPX_1_REF_FRAME = 0,
V4L2_CID_MPEG_VIDEO_VPX_2_REF_FRAME = 1,
V4L2_CID_MPEG_VIDEO_VPX_3_REF_FRAME = 2,
};
#define V4L2_CID_MPEG_VIDEO_VPX_FILTER_LEVEL (V4L2_CID_MPEG_BASE+503)
#define V4L2_CID_MPEG_VIDEO_VPX_FILTER_SHARPNESS (V4L2_CID_MPEG_BASE+504)
#define V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_REF_PERIOD (V4L2_CID_MPEG_BASE+505)
#define V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_SEL (V4L2_CID_MPEG_BASE+506)
enum v4l2_vp8_golden_frame_sel {
V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_USE_PREV = 0,
V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_USE_REF_PERIOD = 1,
};
/* MPEG-class control IDs specific to the CX2341x driver as defined by V4L2 */
#define V4L2_CID_MPEG_CX2341X_BASE (V4L2_CTRL_CLASS_MPEG | 0x1000)
#define V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE (V4L2_CID_MPEG_CX2341X_BASE+0)
enum v4l2_mpeg_cx2341x_video_spatial_filter_mode {
V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_MANUAL = 0,
V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO = 1,
};
#define V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER (V4L2_CID_MPEG_CX2341X_BASE+1)
#define V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE (V4L2_CID_MPEG_CX2341X_BASE+2)
enum v4l2_mpeg_cx2341x_video_luma_spatial_filter_type {
V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_OFF = 0,
V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_1D_HOR = 1,
V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_1D_VERT = 2,
V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_2D_HV_SEPARABLE = 3,
V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_2D_SYM_NON_SEPARABLE = 4,
};
#define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE (V4L2_CID_MPEG_CX2341X_BASE+3)
enum v4l2_mpeg_cx2341x_video_chroma_spatial_filter_type {
V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_OFF = 0,
V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_1D_HOR = 1,
};
#define V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE (V4L2_CID_MPEG_CX2341X_BASE+4)
enum v4l2_mpeg_cx2341x_video_temporal_filter_mode {
V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_MANUAL = 0,
V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_AUTO = 1,
};
#define V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER (V4L2_CID_MPEG_CX2341X_BASE+5)
#define V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE (V4L2_CID_MPEG_CX2341X_BASE+6)
enum v4l2_mpeg_cx2341x_video_median_filter_type {
V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF = 0,
V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_HOR = 1,
V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_VERT = 2,
V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_HOR_VERT = 3,
V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_DIAG = 4,
};
#define V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM (V4L2_CID_MPEG_CX2341X_BASE+7)
#define V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP (V4L2_CID_MPEG_CX2341X_BASE+8)
#define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM (V4L2_CID_MPEG_CX2341X_BASE+9)
#define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP (V4L2_CID_MPEG_CX2341X_BASE+10)
#define V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS (V4L2_CID_MPEG_CX2341X_BASE+11)
/* MPEG-class control IDs specific to the Samsung MFC 5.1 driver as defined by V4L2 */
#define V4L2_CID_MPEG_MFC51_BASE (V4L2_CTRL_CLASS_MPEG | 0x1100)
#define V4L2_CID_MPEG_MFC51_VIDEO_DECODER_H264_DISPLAY_DELAY (V4L2_CID_MPEG_MFC51_BASE+0)
#define V4L2_CID_MPEG_MFC51_VIDEO_DECODER_H264_DISPLAY_DELAY_ENABLE (V4L2_CID_MPEG_MFC51_BASE+1)
#define V4L2_CID_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE (V4L2_CID_MPEG_MFC51_BASE+2)
enum v4l2_mpeg_mfc51_video_frame_skip_mode {
V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_DISABLED = 0,
V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_LEVEL_LIMIT = 1,
V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT = 2,
};
#define V4L2_CID_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE (V4L2_CID_MPEG_MFC51_BASE+3)
enum v4l2_mpeg_mfc51_video_force_frame_type {
V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_DISABLED = 0,
V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_I_FRAME = 1,
V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_NOT_CODED = 2,
};
#define V4L2_CID_MPEG_MFC51_VIDEO_PADDING (V4L2_CID_MPEG_MFC51_BASE+4)
#define V4L2_CID_MPEG_MFC51_VIDEO_PADDING_YUV (V4L2_CID_MPEG_MFC51_BASE+5)
#define V4L2_CID_MPEG_MFC51_VIDEO_RC_FIXED_TARGET_BIT (V4L2_CID_MPEG_MFC51_BASE+6)
#define V4L2_CID_MPEG_MFC51_VIDEO_RC_REACTION_COEFF (V4L2_CID_MPEG_MFC51_BASE+7)
#define V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_ACTIVITY (V4L2_CID_MPEG_MFC51_BASE+50)
#define V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_DARK (V4L2_CID_MPEG_MFC51_BASE+51)
#define V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_SMOOTH (V4L2_CID_MPEG_MFC51_BASE+52)
#define V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_STATIC (V4L2_CID_MPEG_MFC51_BASE+53)
#define V4L2_CID_MPEG_MFC51_VIDEO_H264_NUM_REF_PIC_FOR_P (V4L2_CID_MPEG_MFC51_BASE+54)
/* Camera class control IDs */
#define V4L2_CID_CAMERA_CLASS_BASE (V4L2_CTRL_CLASS_CAMERA | 0x900)
#define V4L2_CID_CAMERA_CLASS (V4L2_CTRL_CLASS_CAMERA | 1)
#define V4L2_CID_EXPOSURE_AUTO (V4L2_CID_CAMERA_CLASS_BASE+1)
enum v4l2_exposure_auto_type {
V4L2_EXPOSURE_AUTO = 0,
V4L2_EXPOSURE_MANUAL = 1,
V4L2_EXPOSURE_SHUTTER_PRIORITY = 2,
V4L2_EXPOSURE_APERTURE_PRIORITY = 3
};
#define V4L2_CID_EXPOSURE_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+2)
#define V4L2_CID_EXPOSURE_AUTO_PRIORITY (V4L2_CID_CAMERA_CLASS_BASE+3)
#define V4L2_CID_PAN_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+4)
#define V4L2_CID_TILT_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+5)
#define V4L2_CID_PAN_RESET (V4L2_CID_CAMERA_CLASS_BASE+6)
#define V4L2_CID_TILT_RESET (V4L2_CID_CAMERA_CLASS_BASE+7)
#define V4L2_CID_PAN_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+8)
#define V4L2_CID_TILT_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+9)
#define V4L2_CID_FOCUS_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+10)
#define V4L2_CID_FOCUS_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+11)
#define V4L2_CID_FOCUS_AUTO (V4L2_CID_CAMERA_CLASS_BASE+12)
#define V4L2_CID_ZOOM_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+13)
#define V4L2_CID_ZOOM_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+14)
#define V4L2_CID_ZOOM_CONTINUOUS (V4L2_CID_CAMERA_CLASS_BASE+15)
#define V4L2_CID_PRIVACY (V4L2_CID_CAMERA_CLASS_BASE+16)
#define V4L2_CID_IRIS_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+17)
#define V4L2_CID_IRIS_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+18)
#define V4L2_CID_AUTO_EXPOSURE_BIAS (V4L2_CID_CAMERA_CLASS_BASE+19)
#define V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE (V4L2_CID_CAMERA_CLASS_BASE+20)
enum v4l2_auto_n_preset_white_balance {
V4L2_WHITE_BALANCE_MANUAL = 0,
V4L2_WHITE_BALANCE_AUTO = 1,
V4L2_WHITE_BALANCE_INCANDESCENT = 2,
V4L2_WHITE_BALANCE_FLUORESCENT = 3,
V4L2_WHITE_BALANCE_FLUORESCENT_H = 4,
V4L2_WHITE_BALANCE_HORIZON = 5,
V4L2_WHITE_BALANCE_DAYLIGHT = 6,
V4L2_WHITE_BALANCE_FLASH = 7,
V4L2_WHITE_BALANCE_CLOUDY = 8,
V4L2_WHITE_BALANCE_SHADE = 9,
};
#define V4L2_CID_WIDE_DYNAMIC_RANGE (V4L2_CID_CAMERA_CLASS_BASE+21)
#define V4L2_CID_IMAGE_STABILIZATION (V4L2_CID_CAMERA_CLASS_BASE+22)
#define V4L2_CID_ISO_SENSITIVITY (V4L2_CID_CAMERA_CLASS_BASE+23)
#define V4L2_CID_ISO_SENSITIVITY_AUTO (V4L2_CID_CAMERA_CLASS_BASE+24)
enum v4l2_iso_sensitivity_auto_type {
V4L2_ISO_SENSITIVITY_MANUAL = 0,
V4L2_ISO_SENSITIVITY_AUTO = 1,
};
#define V4L2_CID_EXPOSURE_METERING (V4L2_CID_CAMERA_CLASS_BASE+25)
enum v4l2_exposure_metering {
V4L2_EXPOSURE_METERING_AVERAGE = 0,
V4L2_EXPOSURE_METERING_CENTER_WEIGHTED = 1,
V4L2_EXPOSURE_METERING_SPOT = 2,
V4L2_EXPOSURE_METERING_MATRIX = 3,
};
#define V4L2_CID_SCENE_MODE (V4L2_CID_CAMERA_CLASS_BASE+26)
enum v4l2_scene_mode {
V4L2_SCENE_MODE_NONE = 0,
V4L2_SCENE_MODE_BACKLIGHT = 1,
V4L2_SCENE_MODE_BEACH_SNOW = 2,
V4L2_SCENE_MODE_CANDLE_LIGHT = 3,
V4L2_SCENE_MODE_DAWN_DUSK = 4,
V4L2_SCENE_MODE_FALL_COLORS = 5,
V4L2_SCENE_MODE_FIREWORKS = 6,
V4L2_SCENE_MODE_LANDSCAPE = 7,
V4L2_SCENE_MODE_NIGHT = 8,
V4L2_SCENE_MODE_PARTY_INDOOR = 9,
V4L2_SCENE_MODE_PORTRAIT = 10,
V4L2_SCENE_MODE_SPORTS = 11,
V4L2_SCENE_MODE_SUNSET = 12,
V4L2_SCENE_MODE_TEXT = 13,
};
#define V4L2_CID_3A_LOCK (V4L2_CID_CAMERA_CLASS_BASE+27)
#define V4L2_LOCK_EXPOSURE (1 << 0)
#define V4L2_LOCK_WHITE_BALANCE (1 << 1)
#define V4L2_LOCK_FOCUS (1 << 2)
#define V4L2_CID_AUTO_FOCUS_START (V4L2_CID_CAMERA_CLASS_BASE+28)
#define V4L2_CID_AUTO_FOCUS_STOP (V4L2_CID_CAMERA_CLASS_BASE+29)
#define V4L2_CID_AUTO_FOCUS_STATUS (V4L2_CID_CAMERA_CLASS_BASE+30)
#define V4L2_AUTO_FOCUS_STATUS_IDLE (0 << 0)
#define V4L2_AUTO_FOCUS_STATUS_BUSY (1 << 0)
#define V4L2_AUTO_FOCUS_STATUS_REACHED (1 << 1)
#define V4L2_AUTO_FOCUS_STATUS_FAILED (1 << 2)
#define V4L2_CID_AUTO_FOCUS_RANGE (V4L2_CID_CAMERA_CLASS_BASE+31)
enum v4l2_auto_focus_range {
V4L2_AUTO_FOCUS_RANGE_AUTO = 0,
V4L2_AUTO_FOCUS_RANGE_NORMAL = 1,
V4L2_AUTO_FOCUS_RANGE_MACRO = 2,
V4L2_AUTO_FOCUS_RANGE_INFINITY = 3,
};
/* FM Modulator class control IDs */
#define V4L2_CID_FM_TX_CLASS_BASE (V4L2_CTRL_CLASS_FM_TX | 0x900)
#define V4L2_CID_FM_TX_CLASS (V4L2_CTRL_CLASS_FM_TX | 1)
#define V4L2_CID_RDS_TX_DEVIATION (V4L2_CID_FM_TX_CLASS_BASE + 1)
#define V4L2_CID_RDS_TX_PI (V4L2_CID_FM_TX_CLASS_BASE + 2)
#define V4L2_CID_RDS_TX_PTY (V4L2_CID_FM_TX_CLASS_BASE + 3)
#define V4L2_CID_RDS_TX_PS_NAME (V4L2_CID_FM_TX_CLASS_BASE + 5)
#define V4L2_CID_RDS_TX_RADIO_TEXT (V4L2_CID_FM_TX_CLASS_BASE + 6)
#define V4L2_CID_AUDIO_LIMITER_ENABLED (V4L2_CID_FM_TX_CLASS_BASE + 64)
#define V4L2_CID_AUDIO_LIMITER_RELEASE_TIME (V4L2_CID_FM_TX_CLASS_BASE + 65)
#define V4L2_CID_AUDIO_LIMITER_DEVIATION (V4L2_CID_FM_TX_CLASS_BASE + 66)
#define V4L2_CID_AUDIO_COMPRESSION_ENABLED (V4L2_CID_FM_TX_CLASS_BASE + 80)
#define V4L2_CID_AUDIO_COMPRESSION_GAIN (V4L2_CID_FM_TX_CLASS_BASE + 81)
#define V4L2_CID_AUDIO_COMPRESSION_THRESHOLD (V4L2_CID_FM_TX_CLASS_BASE + 82)
#define V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME (V4L2_CID_FM_TX_CLASS_BASE + 83)
#define V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME (V4L2_CID_FM_TX_CLASS_BASE + 84)
#define V4L2_CID_PILOT_TONE_ENABLED (V4L2_CID_FM_TX_CLASS_BASE + 96)
#define V4L2_CID_PILOT_TONE_DEVIATION (V4L2_CID_FM_TX_CLASS_BASE + 97)
#define V4L2_CID_PILOT_TONE_FREQUENCY (V4L2_CID_FM_TX_CLASS_BASE + 98)
#define V4L2_CID_TUNE_PREEMPHASIS (V4L2_CID_FM_TX_CLASS_BASE + 112)
enum v4l2_preemphasis {
V4L2_PREEMPHASIS_DISABLED = 0,
V4L2_PREEMPHASIS_50_uS = 1,
V4L2_PREEMPHASIS_75_uS = 2,
};
#define V4L2_CID_TUNE_POWER_LEVEL (V4L2_CID_FM_TX_CLASS_BASE + 113)
#define V4L2_CID_TUNE_ANTENNA_CAPACITOR (V4L2_CID_FM_TX_CLASS_BASE + 114)
/* Flash and privacy (indicator) light controls */
#define V4L2_CID_FLASH_CLASS_BASE (V4L2_CTRL_CLASS_FLASH | 0x900)
#define V4L2_CID_FLASH_CLASS (V4L2_CTRL_CLASS_FLASH | 1)
#define V4L2_CID_FLASH_LED_MODE (V4L2_CID_FLASH_CLASS_BASE + 1)
enum v4l2_flash_led_mode {
V4L2_FLASH_LED_MODE_NONE,
V4L2_FLASH_LED_MODE_FLASH,
V4L2_FLASH_LED_MODE_TORCH,
};
#define V4L2_CID_FLASH_STROBE_SOURCE (V4L2_CID_FLASH_CLASS_BASE + 2)
enum v4l2_flash_strobe_source {
V4L2_FLASH_STROBE_SOURCE_SOFTWARE,
V4L2_FLASH_STROBE_SOURCE_EXTERNAL,
};
#define V4L2_CID_FLASH_STROBE (V4L2_CID_FLASH_CLASS_BASE + 3)
#define V4L2_CID_FLASH_STROBE_STOP (V4L2_CID_FLASH_CLASS_BASE + 4)
#define V4L2_CID_FLASH_STROBE_STATUS (V4L2_CID_FLASH_CLASS_BASE + 5)
#define V4L2_CID_FLASH_TIMEOUT (V4L2_CID_FLASH_CLASS_BASE + 6)
#define V4L2_CID_FLASH_INTENSITY (V4L2_CID_FLASH_CLASS_BASE + 7)
#define V4L2_CID_FLASH_TORCH_INTENSITY (V4L2_CID_FLASH_CLASS_BASE + 8)
#define V4L2_CID_FLASH_INDICATOR_INTENSITY (V4L2_CID_FLASH_CLASS_BASE + 9)
#define V4L2_CID_FLASH_FAULT (V4L2_CID_FLASH_CLASS_BASE + 10)
#define V4L2_FLASH_FAULT_OVER_VOLTAGE (1 << 0)
#define V4L2_FLASH_FAULT_TIMEOUT (1 << 1)
#define V4L2_FLASH_FAULT_OVER_TEMPERATURE (1 << 2)
#define V4L2_FLASH_FAULT_SHORT_CIRCUIT (1 << 3)
#define V4L2_FLASH_FAULT_OVER_CURRENT (1 << 4)
#define V4L2_FLASH_FAULT_INDICATOR (1 << 5)
#define V4L2_CID_FLASH_CHARGE (V4L2_CID_FLASH_CLASS_BASE + 11)
#define V4L2_CID_FLASH_READY (V4L2_CID_FLASH_CLASS_BASE + 12)
/* JPEG-class control IDs */
#define V4L2_CID_JPEG_CLASS_BASE (V4L2_CTRL_CLASS_JPEG | 0x900)
#define V4L2_CID_JPEG_CLASS (V4L2_CTRL_CLASS_JPEG | 1)
#define V4L2_CID_JPEG_CHROMA_SUBSAMPLING (V4L2_CID_JPEG_CLASS_BASE + 1)
enum v4l2_jpeg_chroma_subsampling {
V4L2_JPEG_CHROMA_SUBSAMPLING_444 = 0,
V4L2_JPEG_CHROMA_SUBSAMPLING_422 = 1,
V4L2_JPEG_CHROMA_SUBSAMPLING_420 = 2,
V4L2_JPEG_CHROMA_SUBSAMPLING_411 = 3,
V4L2_JPEG_CHROMA_SUBSAMPLING_410 = 4,
V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY = 5,
};
#define V4L2_CID_JPEG_RESTART_INTERVAL (V4L2_CID_JPEG_CLASS_BASE + 2)
#define V4L2_CID_JPEG_COMPRESSION_QUALITY (V4L2_CID_JPEG_CLASS_BASE + 3)
#define V4L2_CID_JPEG_ACTIVE_MARKER (V4L2_CID_JPEG_CLASS_BASE + 4)
#define V4L2_JPEG_ACTIVE_MARKER_APP0 (1 << 0)
#define V4L2_JPEG_ACTIVE_MARKER_APP1 (1 << 1)
#define V4L2_JPEG_ACTIVE_MARKER_COM (1 << 16)
#define V4L2_JPEG_ACTIVE_MARKER_DQT (1 << 17)
#define V4L2_JPEG_ACTIVE_MARKER_DHT (1 << 18)
/* Image source controls */
#define V4L2_CID_IMAGE_SOURCE_CLASS_BASE (V4L2_CTRL_CLASS_IMAGE_SOURCE | 0x900)
#define V4L2_CID_IMAGE_SOURCE_CLASS (V4L2_CTRL_CLASS_IMAGE_SOURCE | 1)
#define V4L2_CID_VBLANK (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 1)
#define V4L2_CID_HBLANK (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 2)
#define V4L2_CID_ANALOGUE_GAIN (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 3)
/* Image processing controls */
#define V4L2_CID_IMAGE_PROC_CLASS_BASE (V4L2_CTRL_CLASS_IMAGE_PROC | 0x900)
#define V4L2_CID_IMAGE_PROC_CLASS (V4L2_CTRL_CLASS_IMAGE_PROC | 1)
#define V4L2_CID_LINK_FREQ (V4L2_CID_IMAGE_PROC_CLASS_BASE + 1)
#define V4L2_CID_PIXEL_RATE (V4L2_CID_IMAGE_PROC_CLASS_BASE + 2)
#define V4L2_CID_TEST_PATTERN (V4L2_CID_IMAGE_PROC_CLASS_BASE + 3)
/* DV-class control IDs defined by V4L2 */
#define V4L2_CID_DV_CLASS_BASE (V4L2_CTRL_CLASS_DV | 0x900)
#define V4L2_CID_DV_CLASS (V4L2_CTRL_CLASS_DV | 1)
#define V4L2_CID_DV_TX_HOTPLUG (V4L2_CID_DV_CLASS_BASE + 1)
#define V4L2_CID_DV_TX_RXSENSE (V4L2_CID_DV_CLASS_BASE + 2)
#define V4L2_CID_DV_TX_EDID_PRESENT (V4L2_CID_DV_CLASS_BASE + 3)
#define V4L2_CID_DV_TX_MODE (V4L2_CID_DV_CLASS_BASE + 4)
enum v4l2_dv_tx_mode {
V4L2_DV_TX_MODE_DVI_D = 0,
V4L2_DV_TX_MODE_HDMI = 1,
};
#define V4L2_CID_DV_TX_RGB_RANGE (V4L2_CID_DV_CLASS_BASE + 5)
enum v4l2_dv_rgb_range {
V4L2_DV_RGB_RANGE_AUTO = 0,
V4L2_DV_RGB_RANGE_LIMITED = 1,
V4L2_DV_RGB_RANGE_FULL = 2,
};
#define V4L2_CID_DV_RX_POWER_PRESENT (V4L2_CID_DV_CLASS_BASE + 100)
#define V4L2_CID_DV_RX_RGB_RANGE (V4L2_CID_DV_CLASS_BASE + 101)
#define V4L2_CID_FM_RX_CLASS_BASE (V4L2_CTRL_CLASS_FM_RX | 0x900)
#define V4L2_CID_FM_RX_CLASS (V4L2_CTRL_CLASS_FM_RX | 1)
#define V4L2_CID_TUNE_DEEMPHASIS (V4L2_CID_FM_RX_CLASS_BASE + 1)
enum v4l2_deemphasis {
V4L2_DEEMPHASIS_DISABLED = V4L2_PREEMPHASIS_DISABLED,
V4L2_DEEMPHASIS_50_uS = V4L2_PREEMPHASIS_50_uS,
V4L2_DEEMPHASIS_75_uS = V4L2_PREEMPHASIS_75_uS,
};
#define V4L2_CID_RDS_RECEPTION (V4L2_CID_FM_RX_CLASS_BASE + 2)
#endif

View file

@ -0,0 +1,696 @@
/*
V4L2 controls support header.
Copyright (C) 2010 Hans Verkuil <hverkuil@xs4all.nl>
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _V4L2_CTRLS_H
#define _V4L2_CTRLS_H
#if 0
#include <linux/list.h>
#include <linux/mutex.h>
#endif
#include "v4l2-osdep.h"
#include "videodev2.h"
/* forward references */
//struct file;
struct v4l2_ctrl_handler;
struct v4l2_ctrl_helper;
struct v4l2_ctrl;
struct video_device;
struct v4l2_subdev;
struct v4l2_subscribed_event;
struct v4l2_fh;
//struct poll_table_struct;
/** struct v4l2_ctrl_ops - The control operations that the driver has to provide.
* @g_volatile_ctrl: Get a new value for this control. Generally only relevant
* for volatile (and usually read-only) controls such as a control
* that returns the current signal strength which changes
* continuously.
* If not set, then the currently cached value will be returned.
* @try_ctrl: Test whether the control's value is valid. Only relevant when
* the usual min/max/step checks are not sufficient.
* @s_ctrl: Actually set the new control value. s_ctrl is compulsory. The
* ctrl->handler->lock is held when these ops are called, so no
* one else can access controls owned by that handler.
*/
struct v4l2_ctrl_ops {
int (*g_volatile_ctrl)(struct v4l2_ctrl *ctrl);
int (*try_ctrl)(struct v4l2_ctrl *ctrl);
int (*s_ctrl)(struct v4l2_ctrl *ctrl);
};
typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv);
/** struct v4l2_ctrl - The control structure.
* @node: The list node.
* @ev_subs: The list of control event subscriptions.
* @handler: The handler that owns the control.
* @cluster: Point to start of cluster array.
* @ncontrols: Number of controls in cluster array.
* @done: Internal flag: set for each processed control.
* @is_new: Set when the user specified a new value for this control. It
* is also set when called from v4l2_ctrl_handler_setup. Drivers
* should never set this flag.
* @is_private: If set, then this control is private to its handler and it
* will not be added to any other handlers. Drivers can set
* this flag.
* @is_auto: If set, then this control selects whether the other cluster
* members are in 'automatic' mode or 'manual' mode. This is
* used for autogain/gain type clusters. Drivers should never
* set this flag directly.
* @has_volatiles: If set, then one or more members of the cluster are volatile.
* Drivers should never touch this flag.
* @call_notify: If set, then call the handler's notify function whenever the
* control's value changes.
* @manual_mode_value: If the is_auto flag is set, then this is the value
* of the auto control that determines if that control is in
* manual mode. So if the value of the auto control equals this
* value, then the whole cluster is in manual mode. Drivers should
* never set this flag directly.
* @ops: The control ops.
* @id: The control ID.
* @name: The control name.
* @type: The control type.
* @minimum: The control's minimum value.
* @maximum: The control's maximum value.
* @default_value: The control's default value.
* @step: The control's step value for non-menu controls.
* @menu_skip_mask: The control's skip mask for menu controls. This makes it
* easy to skip menu items that are not valid. If bit X is set,
* then menu item X is skipped. Of course, this only works for
* menus with <= 32 menu items. There are no menus that come
* close to that number, so this is OK. Should we ever need more,
* then this will have to be extended to a u64 or a bit array.
* @qmenu: A const char * array for all menu items. Array entries that are
* empty strings ("") correspond to non-existing menu items (this
* is in addition to the menu_skip_mask above). The last entry
* must be NULL.
* @flags: The control's flags.
* @cur: The control's current value.
* @val: The control's new s32 value.
* @val64: The control's new s64 value.
* @string: The control's new string value.
* @priv: The control's private pointer. For use by the driver. It is
* untouched by the control framework. Note that this pointer is
* not freed when the control is deleted. Should this be needed
* then a new internal bitfield can be added to tell the framework
* to free this pointer.
*/
struct v4l2_ctrl {
/* Administrative fields */
struct list_head node;
struct list_head ev_subs;
struct v4l2_ctrl_handler *handler;
struct v4l2_ctrl **cluster;
unsigned ncontrols;
unsigned int done:1;
unsigned int is_new:1;
unsigned int is_private:1;
unsigned int is_auto:1;
unsigned int has_volatiles:1;
unsigned int call_notify:1;
unsigned int manual_mode_value:8;
const struct v4l2_ctrl_ops *ops;
u32 id;
const char *name;
enum v4l2_ctrl_type type;
s32 minimum, maximum, default_value;
union {
u32 step;
u32 menu_skip_mask;
};
union {
const char * const *qmenu;
const s64 *qmenu_int;
};
unsigned long flags;
union {
s32 val;
s64 val64;
char *string;
} cur;
union {
s32 val;
s64 val64;
char *string;
};
void *priv;
};
/** struct v4l2_ctrl_ref - The control reference.
* @node: List node for the sorted list.
* @next: Single-link list node for the hash.
* @ctrl: The actual control information.
* @helper: Pointer to helper struct. Used internally in prepare_ext_ctrls().
*
* Each control handler has a list of these refs. The list_head is used to
* keep a sorted-by-control-ID list of all controls, while the next pointer
* is used to link the control in the hash's bucket.
*/
struct v4l2_ctrl_ref {
struct list_head node;
struct v4l2_ctrl_ref *next;
struct v4l2_ctrl *ctrl;
struct v4l2_ctrl_helper *helper;
};
/** struct v4l2_ctrl_handler - The control handler keeps track of all the
* controls: both the controls owned by the handler and those inherited
* from other handlers.
* @_lock: Default for "lock".
* @lock: Lock to control access to this handler and its controls.
* May be replaced by the user right after init.
* @ctrls: The list of controls owned by this handler.
* @ctrl_refs: The list of control references.
* @cached: The last found control reference. It is common that the same
* control is needed multiple times, so this is a simple
* optimization.
* @buckets: Buckets for the hashing. Allows for quick control lookup.
* @notify: A notify callback that is called whenever the control changes value.
* Note that the handler's lock is held when the notify function
* is called!
* @notify_priv: Passed as argument to the v4l2_ctrl notify callback.
* @nr_of_buckets: Total number of buckets in the array.
* @error: The error code of the first failed control addition.
*/
struct v4l2_ctrl_handler {
//struct mutex _lock;
//struct mutex *lock;
_Mutex _lock;
_Mutex *lock;
struct list_head ctrls;
struct list_head ctrl_refs;
struct v4l2_ctrl_ref *cached;
struct v4l2_ctrl_ref **buckets;
v4l2_ctrl_notify_fnc notify;
void *notify_priv;
u16 nr_of_buckets;
int error;
};
/** struct v4l2_ctrl_config - Control configuration structure.
* @ops: The control ops.
* @id: The control ID.
* @name: The control name.
* @type: The control type.
* @min: The control's minimum value.
* @max: The control's maximum value.
* @step: The control's step value for non-menu controls.
* @def: The control's default value.
* @flags: The control's flags.
* @menu_skip_mask: The control's skip mask for menu controls. This makes it
* easy to skip menu items that are not valid. If bit X is set,
* then menu item X is skipped. Of course, this only works for
* menus with <= 32 menu items. There are no menus that come
* close to that number, so this is OK. Should we ever need more,
* then this will have to be extended to a u64 or a bit array.
* @qmenu: A const char * array for all menu items. Array entries that are
* empty strings ("") correspond to non-existing menu items (this
* is in addition to the menu_skip_mask above). The last entry
* must be NULL.
* @is_private: If set, then this control is private to its handler and it
* will not be added to any other handlers.
*/
struct v4l2_ctrl_config {
const struct v4l2_ctrl_ops *ops;
u32 id;
const char *name;
enum v4l2_ctrl_type type;
s32 min;
s32 max;
u32 step;
s32 def;
u32 flags;
u32 menu_skip_mask;
const char * const *qmenu;
const s64 *qmenu_int;
unsigned int is_private:1;
};
/** v4l2_ctrl_fill() - Fill in the control fields based on the control ID.
*
* This works for all standard V4L2 controls.
* For non-standard controls it will only fill in the given arguments
* and @name will be NULL.
*
* This function will overwrite the contents of @name, @type and @flags.
* The contents of @min, @max, @step and @def may be modified depending on
* the type.
*
* Do not use in drivers! It is used internally for backwards compatibility
* control handling only. Once all drivers are converted to use the new
* control framework this function will no longer be exported.
*/
void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
s32 *min, s32 *max, s32 *step, s32 *def, u32 *flags);
/** v4l2_ctrl_handler_init_class() - Initialize the control handler.
* @hdl: The control handler.
* @nr_of_controls_hint: A hint of how many controls this handler is
* expected to refer to. This is the total number, so including
* any inherited controls. It doesn't have to be precise, but if
* it is way off, then you either waste memory (too many buckets
* are allocated) or the control lookup becomes slower (not enough
* buckets are allocated, so there are more slow list lookups).
* It will always work, though.
* @key: Used by the lock validator if CONFIG_LOCKDEP is set.
* @name: Used by the lock validator if CONFIG_LOCKDEP is set.
*
* Returns an error if the buckets could not be allocated. This error will
* also be stored in @hdl->error.
*
* Never use this call directly, always use the v4l2_ctrl_handler_init
* macro that hides the @key and @name arguments.
*/
#if 0
int v4l2_ctrl_handler_init_class(struct v4l2_ctrl_handler *hdl,
unsigned nr_of_controls_hint,
struct lock_class_key *key, const char *name);
#ifdef CONFIG_LOCKDEP
#define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \
( \
({ \
static struct lock_class_key _key; \
v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, \
&_key, \
KBUILD_BASENAME ":" \
__stringify(__LINE__) ":" \
"(" #hdl ")->_lock"); \
}) \
)
#else
#define v4l2_ctrl_handler_init(hdl, nr_of_controls_hint) \
v4l2_ctrl_handler_init_class(hdl, nr_of_controls_hint, NULL, NULL)
#endif
#endif
/** v4l2_ctrl_handler_free() - Free all controls owned by the handler and free
* the control list.
* @hdl: The control handler.
*
* Does nothing if @hdl == NULL.
*/
void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler *hdl);
/** v4l2_ctrl_handler_setup() - Call the s_ctrl op for all controls belonging
* to the handler to initialize the hardware to the current control values.
* @hdl: The control handler.
*
* Button controls will be skipped, as are read-only controls.
*
* If @hdl == NULL, then this just returns 0.
*/
int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl);
/** v4l2_ctrl_handler_log_status() - Log all controls owned by the handler.
* @hdl: The control handler.
* @prefix: The prefix to use when logging the control values. If the
* prefix does not end with a space, then ": " will be added
* after the prefix. If @prefix == NULL, then no prefix will be
* used.
*
* For use with VIDIOC_LOG_STATUS.
*
* Does nothing if @hdl == NULL.
*/
void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl,
const char *prefix);
/** v4l2_ctrl_new_custom() - Allocate and initialize a new custom V4L2
* control.
* @hdl: The control handler.
* @cfg: The control's configuration data.
* @priv: The control's driver-specific private data.
*
* If the &v4l2_ctrl struct could not be allocated then NULL is returned
* and @hdl->error is set to the error code (if it wasn't set already).
*/
struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
const struct v4l2_ctrl_config *cfg, void *priv);
/** v4l2_ctrl_new_std() - Allocate and initialize a new standard V4L2 non-menu control.
* @hdl: The control handler.
* @ops: The control ops.
* @id: The control ID.
* @min: The control's minimum value.
* @max: The control's maximum value.
* @step: The control's step value
* @def: The control's default value.
*
* If the &v4l2_ctrl struct could not be allocated, or the control
* ID is not known, then NULL is returned and @hdl->error is set to the
* appropriate error code (if it wasn't set already).
*
* If @id refers to a menu control, then this function will return NULL.
*
* Use v4l2_ctrl_new_std_menu() when adding menu controls.
*/
struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl,
const struct v4l2_ctrl_ops *ops,
u32 id, s32 min, s32 max, u32 step, s32 def);
/** v4l2_ctrl_new_std_menu() - Allocate and initialize a new standard V4L2 menu control.
* @hdl: The control handler.
* @ops: The control ops.
* @id: The control ID.
* @max: The control's maximum value.
* @mask: The control's skip mask for menu controls. This makes it
* easy to skip menu items that are not valid. If bit X is set,
* then menu item X is skipped. Of course, this only works for
* menus with <= 32 menu items. There are no menus that come
* close to that number, so this is OK. Should we ever need more,
* then this will have to be extended to a u64 or a bit array.
* @def: The control's default value.
*
* Same as v4l2_ctrl_new_std(), but @min is set to 0 and the @mask value
* determines which menu items are to be skipped.
*
* If @id refers to a non-menu control, then this function will return NULL.
*/
struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
const struct v4l2_ctrl_ops *ops,
u32 id, s32 max, s32 mask, s32 def);
/** v4l2_ctrl_new_std_menu_items() - Create a new standard V4L2 menu control
* with driver specific menu.
* @hdl: The control handler.
* @ops: The control ops.
* @id: The control ID.
* @max: The control's maximum value.
* @mask: The control's skip mask for menu controls. This makes it
* easy to skip menu items that are not valid. If bit X is set,
* then menu item X is skipped. Of course, this only works for
* menus with <= 32 menu items. There are no menus that come
* close to that number, so this is OK. Should we ever need more,
* then this will have to be extended to a u64 or a bit array.
* @def: The control's default value.
* @qmenu: The new menu.
*
* Same as v4l2_ctrl_new_std_menu(), but @qmenu will be the driver specific
* menu of this control.
*
*/
struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl,
const struct v4l2_ctrl_ops *ops, u32 id, s32 max,
s32 mask, s32 def, const char * const *qmenu);
/** v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control.
* @hdl: The control handler.
* @ops: The control ops.
* @id: The control ID.
* @max: The control's maximum value.
* @def: The control's default value.
* @qmenu_int: The control's menu entries.
*
* Same as v4l2_ctrl_new_std_menu(), but @mask is set to 0 and it additionaly
* takes as an argument an array of integers determining the menu items.
*
* If @id refers to a non-integer-menu control, then this function will return NULL.
*/
struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl,
const struct v4l2_ctrl_ops *ops,
u32 id, s32 max, s32 def, const s64 *qmenu_int);
/** v4l2_ctrl_add_ctrl() - Add a control from another handler to this handler.
* @hdl: The control handler.
* @ctrl: The control to add.
*
* It will return NULL if it was unable to add the control reference.
* If the control already belonged to the handler, then it will do
* nothing and just return @ctrl.
*/
struct v4l2_ctrl *v4l2_ctrl_add_ctrl(struct v4l2_ctrl_handler *hdl,
struct v4l2_ctrl *ctrl);
/** v4l2_ctrl_add_handler() - Add all controls from handler @add to
* handler @hdl.
* @hdl: The control handler.
* @add: The control handler whose controls you want to add to
* the @hdl control handler.
* @filter: This function will filter which controls should be added.
*
* Does nothing if either of the two handlers is a NULL pointer.
* If @filter is NULL, then all controls are added. Otherwise only those
* controls for which @filter returns true will be added.
* In case of an error @hdl->error will be set to the error code (if it
* wasn't set already).
*/
int v4l2_ctrl_add_handler(struct v4l2_ctrl_handler *hdl,
struct v4l2_ctrl_handler *add,
bool (*filter)(const struct v4l2_ctrl *ctrl));
/** v4l2_ctrl_radio_filter() - Standard filter for radio controls.
* @ctrl: The control that is filtered.
*
* This will return true for any controls that are valid for radio device
* nodes. Those are all of the V4L2_CID_AUDIO_* user controls and all FM
* transmitter class controls.
*
* This function is to be used with v4l2_ctrl_add_handler().
*/
bool v4l2_ctrl_radio_filter(const struct v4l2_ctrl *ctrl);
/** v4l2_ctrl_cluster() - Mark all controls in the cluster as belonging to that cluster.
* @ncontrols: The number of controls in this cluster.
* @controls: The cluster control array of size @ncontrols.
*/
void v4l2_ctrl_cluster(unsigned ncontrols, struct v4l2_ctrl **controls);
/** v4l2_ctrl_auto_cluster() - Mark all controls in the cluster as belonging to
* that cluster and set it up for autofoo/foo-type handling.
* @ncontrols: The number of controls in this cluster.
* @controls: The cluster control array of size @ncontrols. The first control
* must be the 'auto' control (e.g. autogain, autoexposure, etc.)
* @manual_val: The value for the first control in the cluster that equals the
* manual setting.
* @set_volatile: If true, then all controls except the first auto control will
* be volatile.
*
* Use for control groups where one control selects some automatic feature and
* the other controls are only active whenever the automatic feature is turned
* off (manual mode). Typical examples: autogain vs gain, auto-whitebalance vs
* red and blue balance, etc.
*
* The behavior of such controls is as follows:
*
* When the autofoo control is set to automatic, then any manual controls
* are set to inactive and any reads will call g_volatile_ctrl (if the control
* was marked volatile).
*
* When the autofoo control is set to manual, then any manual controls will
* be marked active, and any reads will just return the current value without
* going through g_volatile_ctrl.
*
* In addition, this function will set the V4L2_CTRL_FLAG_UPDATE flag
* on the autofoo control and V4L2_CTRL_FLAG_INACTIVE on the foo control(s)
* if autofoo is in auto mode.
*/
void v4l2_ctrl_auto_cluster(unsigned ncontrols, struct v4l2_ctrl **controls,
u8 manual_val, bool set_volatile);
/** v4l2_ctrl_find() - Find a control with the given ID.
* @hdl: The control handler.
* @id: The control ID to find.
*
* If @hdl == NULL this will return NULL as well. Will lock the handler so
* do not use from inside &v4l2_ctrl_ops.
*/
struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);
/** v4l2_ctrl_activate() - Make the control active or inactive.
* @ctrl: The control to (de)activate.
* @active: True if the control should become active.
*
* This sets or clears the V4L2_CTRL_FLAG_INACTIVE flag atomically.
* Does nothing if @ctrl == NULL.
* This will usually be called from within the s_ctrl op.
* The V4L2_EVENT_CTRL event will be generated afterwards.
*
* This function assumes that the control handler is locked.
*/
void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active);
/** v4l2_ctrl_grab() - Mark the control as grabbed or not grabbed.
* @ctrl: The control to (de)activate.
* @grabbed: True if the control should become grabbed.
*
* This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically.
* Does nothing if @ctrl == NULL.
* The V4L2_EVENT_CTRL event will be generated afterwards.
* This will usually be called when starting or stopping streaming in the
* driver.
*
* This function assumes that the control handler is not locked and will
* take the lock itself.
*/
void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed);
/** v4l2_ctrl_modify_range() - Update the range of a control.
* @ctrl: The control to update.
* @min: The control's minimum value.
* @max: The control's maximum value.
* @step: The control's step value
* @def: The control's default value.
*
* Update the range of a control on the fly. This works for control types
* INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the
* @step value is interpreted as a menu_skip_mask.
*
* An error is returned if one of the range arguments is invalid for this
* control type.
*
* This function assumes that the control handler is not locked and will
* take the lock itself.
*/
int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
s32 min, s32 max, u32 step, s32 def);
/** v4l2_ctrl_lock() - Helper function to lock the handler
* associated with the control.
* @ctrl: The control to lock.
*/
static inline void v4l2_ctrl_lock(struct v4l2_ctrl *ctrl)
{
mutex_lock(ctrl->handler->lock);
}
/** v4l2_ctrl_lock() - Helper function to unlock the handler
* associated with the control.
* @ctrl: The control to unlock.
*/
static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl)
{
mutex_unlock(ctrl->handler->lock);
}
/** v4l2_ctrl_notify() - Function to set a notify callback for a control.
* @ctrl: The control.
* @notify: The callback function.
* @priv: The callback private handle, passed as argument to the callback.
*
* This function sets a callback function for the control. If @ctrl is NULL,
* then it will do nothing. If @notify is NULL, then the notify callback will
* be removed.
*
* There can be only one notify. If another already exists, then a WARN_ON
* will be issued and the function will do nothing.
*/
void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify, void *priv);
/** v4l2_ctrl_g_ctrl() - Helper function to get the control's value from within a driver.
* @ctrl: The control.
*
* This returns the control's value safely by going through the control
* framework. This function will lock the control's handler, so it cannot be
* used from within the &v4l2_ctrl_ops functions.
*
* This function is for integer type controls only.
*/
s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl);
/** v4l2_ctrl_s_ctrl() - Helper function to set the control's value from within a driver.
* @ctrl: The control.
* @val: The new value.
*
* This set the control's new value safely by going through the control
* framework. This function will lock the control's handler, so it cannot be
* used from within the &v4l2_ctrl_ops functions.
*
* This function is for integer type controls only.
*/
int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val);
/** v4l2_ctrl_g_ctrl_int64() - Helper function to get a 64-bit control's value from within a driver.
* @ctrl: The control.
*
* This returns the control's value safely by going through the control
* framework. This function will lock the control's handler, so it cannot be
* used from within the &v4l2_ctrl_ops functions.
*
* This function is for 64-bit integer type controls only.
*/
s64 v4l2_ctrl_g_ctrl_int64(struct v4l2_ctrl *ctrl);
/** v4l2_ctrl_s_ctrl_int64() - Helper function to set a 64-bit control's value from within a driver.
* @ctrl: The control.
* @val: The new value.
*
* This set the control's new value safely by going through the control
* framework. This function will lock the control's handler, so it cannot be
* used from within the &v4l2_ctrl_ops functions.
*
* This function is for 64-bit integer type controls only.
*/
int v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val);
/* Internal helper functions that deal with control events. */
extern const struct v4l2_subscribed_event_ops v4l2_ctrl_sub_ev_ops;
void v4l2_ctrl_replace(struct v4l2_event *old, const struct v4l2_event *new);
void v4l2_ctrl_merge(const struct v4l2_event *old, struct v4l2_event *new);
/* Can be used as a vidioc_log_status function that just dumps all controls
associated with the filehandle. */
int v4l2_ctrl_log_status(void *fh);
/* Can be used as a vidioc_subscribe_event function that just subscribes
control events. */
int v4l2_ctrl_subscribe_event(struct v4l2_fh *fh,
const struct v4l2_event_subscription *sub);
/* Can be used as a poll function that just polls for control events. */
//unsigned int v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait);
/* Helpers for ioctl_ops. If hdl == NULL then they will all return -EINVAL. */
int v4l2_queryctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_queryctrl *qc);
int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, struct v4l2_querymenu *qm);
int v4l2_g_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_control *ctrl);
int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
struct v4l2_control *ctrl);
int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *c);
int v4l2_try_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *c);
int v4l2_s_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
struct v4l2_ext_controls *c);
/* Helpers for subdevices. If the associated ctrl_handler == NULL then they
will all return -EINVAL. */
int v4l2_subdev_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc);
int v4l2_subdev_querymenu(struct v4l2_subdev *sd, struct v4l2_querymenu *qm);
int v4l2_subdev_g_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs);
int v4l2_subdev_try_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs);
int v4l2_subdev_s_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs);
int v4l2_subdev_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
int v4l2_subdev_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
/* Can be used as a subscribe_event function that just subscribes control
events. */
int v4l2_ctrl_subdev_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
struct v4l2_event_subscription *sub);
/* Log all controls owned by subdev's control handler. */
int v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd);
#endif

View file

@ -0,0 +1,273 @@
/*
*
* V 4 L 2 D R I V E R H E L P E R A P I
*
* Moved from videodev2.h
*
* Some commonly needed functions for drivers (v4l2-common.o module)
*/
#ifndef _V4L2_DEV_H
#define _V4L2_DEV_H
#if 0
#include <linux/poll.h>
#include <linux/fs.h>
#include <linux/device.h>
#include <linux/cdev.h>
#include <linux/mutex.h>
#endif
#include "v4l2-osdep.h"
#include "uapi_videodev2.h"
#include "media-entity.h"
#define VIDEO_MAJOR 81
#define VFL_TYPE_GRABBER 0
#define VFL_TYPE_VBI 1
#define VFL_TYPE_RADIO 2
#define VFL_TYPE_SUBDEV 3
#define VFL_TYPE_MAX 4
/* Is this a receiver, transmitter or mem-to-mem? */
/* Ignored for VFL_TYPE_SUBDEV. */
#define VFL_DIR_RX 0
#define VFL_DIR_TX 1
#define VFL_DIR_M2M 2
//struct v4l2_ioctl_callbacks; // can't find out from the kernel source code
struct video_device;
struct v4l2_device;
struct v4l2_ctrl_handler;
enum v4l2_priority;
/* Flag to mark the video_device struct as registered.
Drivers can clear this flag if they want to block all future
device access. It is cleared by video_unregister_device. */
#define V4L2_FL_REGISTERED (0)
/* file->private_data points to struct v4l2_fh */
#define V4L2_FL_USES_V4L2_FH (1)
/* Use the prio field of v4l2_fh for core priority checking */
#define V4L2_FL_USE_FH_PRIO (2)
/* Priority helper functions */
struct v4l2_prio_state {
atomic_t prios[4];
};
/*
enum v4l2_priority {
V4L2_PRIORITY_UNSET = 0, // 不初始化
V4L2_PRIORITY_BACKGROUND = 1, // 背景
V4L2_PRIORITY_INTERACTIVE = 2, // 互動
V4L2_PRIORITY_RECORD = 3, // 紀錄
V4L2_PRIORITY_DEFAULT = V4L2_PRIORITY_INTERACTIVE,
};
Multiple Opens操作device同時被多個thread (i.e open())
使prios[4]
*/
void v4l2_prio_init(struct v4l2_prio_state *global);
int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local,
enum v4l2_priority new);
void v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local);
void v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority local);
enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global);
int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
struct v4l2_file_operations {
//struct module *owner;
//ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
//ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
//unsigned int (*poll) (struct file *, struct poll_table_struct *);
long (*ioctl) (unsigned int, unsigned long);
long (*unlocked_ioctl) (unsigned int, unsigned long);
#ifdef CONFIG_COMPAT
long (*compat_ioctl32) (unsigned int, unsigned long);
#endif
//unsigned long (*get_unmapped_area) (struct file *, unsigned long,
// unsigned long, unsigned long, unsigned long);
int (*mmap) ();
int (*open) ();
int (*release) ();
};
/*
* Newer version of video_device, handled by videodev2.c
* This version moves redundant code from video device code to
* the common handler
*/
struct video_device
{
#if defined(CONFIG_MEDIA_CONTROLLER)
struct media_entity entity;
#endif
/* device ops */
const struct v4l2_file_operations *fops;
/* sysfs */
//struct device dev; /* v4l device,this is mainlt for sysfs */
unsigned long dev; /* replace to the reference count */
void *dev_driver_data;
const char *init_name; /* initial name of the device */
void (*dev_release)(); /* release call back in origonal dev */
//struct cdev *cdev; /* character device, which video device register */
//struct file_operations *cdev_ops;/* file_operations in origonal cdev */
struct v4l2_device *v4l2_dev; /* v4l2_device parent */
/* Only set parent if that can't be deduced from v4l2_dev */
//struct device *dev_parent; /* device parent */
/* Control handler associated with this device node. May be NULL.
* look up v4l2_ctrls.h for more detail */
struct v4l2_ctrl_handler *ctrl_handler;
/* vb2_queue associated with this device node. May be NULL. */
struct vb2_queue *queue;
/* Priority state. If NULL, then v4l2_dev->prio will be used. */
struct v4l2_prio_state *prio;
/* device info */
char name[32];
int vfl_type; /* device type,usally assign the define VFL_TYPE_XXX value */
int vfl_dir; /* receiver, transmitter or m2m,usally assign the define VFL_DIR_XXX value */
/* 'minor' is set to -1 if the registration failed */
int minor;
u16 num; /* record the registered video device node number */
/* use bitops to set/clear/test flags,usally assign the define VFL_FL_XXX value */
unsigned long flags;
/* attribute to differentiate multiple indices on one physical device */
int index;
/* V4L2 file handles */
//spinlock_t fh_lock; /* Lock for all v4l2_fhs */
_Lock fh_lock;
struct list_head fh_list; /* List of struct v4l2_fh */
int debug; /* Activates debug level*/
/* Video standard vars (v4l2_std_id = u64)*/
//v4l2_std_id tvnorms; /* Supported tv norms,usally assign the define VFL_STD_XXX value */
u64 tvnorms;
/* callbacks,this must non-NULL,in usually use the video_device_release()to replace of */
void (*release)(struct video_device *vdev);
/* ioctl callbacks,look up v4l2-ioctl.h for more detail */
const struct v4l2_ioctl_ops *ioctl_ops;
//DECLARE_BITMAP(valid_ioctls, BASE_VIDIOC_PRIVATE); /* unsigned long valid_ioctls[6] */
unsigned long valid_ioctls[6];
/* serialization lock */
//DECLARE_BITMAP(disable_locking, BASE_VIDIOC_PRIVATE); /* unsigned long disable_locking[6] */
unsigned long disable_locking[6];
//struct mutex *lock; /* make serilized ioctl lock possible */
_Mutex *lock;
};
/* todo need to modify */
#if 0
#define media_entity_to_video_device(__e) \
container_of(__e, struct video_device, entity)
/* dev to video-device */
#define to_video_device(cd) container_of(cd, struct video_device, dev)
#endif
int __video_register_device(struct video_device *vdev, int type,
int nr, int warn_if_nr_in_use/*, struct module *owner*/);
/* Register video devices. Note that if video_register_device fails,
the release() callback of the video_device structure is *not* called, so
the caller is responsible for freeing any data. Usually that means that
you call video_device_release() on failure. */
static inline int video_register_device(struct video_device *vdev,
int type, int nr)
{
// type = VFL_TYPE_GRABBER, nr = -1, 1, "THIS_MODULE"
return __video_register_device(vdev, type, nr, 1/*, vdev->fops->owner*/);
}
/* Same as video_register_device, but no warning is issued if the desired
device node number was already in use. */
static inline int video_register_device_no_warn(
struct video_device *vdev, int type, int nr)
{
return __video_register_device(vdev, type, nr, 0/*, vdev->fops->owner*/);
}
/* Unregister video devices. Will do nothing if vdev == NULL or
video_is_registered() returns false. */
void video_unregister_device(struct video_device *vdev);
/* helper functions to alloc/release struct video_device, the
latter can also be used for video_device->release(). */
struct video_device *video_device_alloc(void);
/* this release function frees the vdev pointer */
void video_device_release(struct video_device *vdev);
/* this release function does nothing, use when the video_device is a
static global struct. Note that having a static video_device is
a dubious construction at best. */
void video_device_release_empty(struct video_device *vdev);
/* returns true if cmd is a known V4L2 ioctl */
bool v4l2_is_known_ioctl(unsigned int cmd);
/* mark that this command shouldn't use core locking */
static inline void v4l2_disable_ioctl_locking(struct video_device *vdev, unsigned int cmd)
{
#define BASE_VIDIOC_PRIVATE 192
if (_IOC_NR(cmd) < BASE_VIDIOC_PRIVATE)
set_bit(_IOC_NR(cmd), vdev->disable_locking);
}
/* Mark that this command isn't implemented. This must be called before
video_device_register. See also the comments in determine_valid_ioctls().
This function allows drivers to provide just one v4l2_ioctl_ops struct, but
disable ioctls based on the specific card that is actually found. */
static inline void v4l2_disable_ioctl(struct video_device *vdev, unsigned int cmd)
{
#define BASE_VIDIOC_PRIVATE 192
if (_IOC_NR(cmd) < BASE_VIDIOC_PRIVATE)
set_bit(_IOC_NR(cmd), vdev->valid_ioctls);
}
/* helper functions to access driver private data. */
static inline void *video_get_drvdata(struct video_device *vdev)
{
//return dev_get_drvdata(&vdev->dev);
return (vdev->dev_driver_data);
}
static inline void video_set_drvdata(struct video_device *vdev, void *data)
{
//dev_set_drvdata(&vdev->dev, data);
vdev->dev_driver_data = data;
}
struct video_device *video_devdata();
/* Combine video_get_drvdata and video_devdata as this is
used very often. */
static inline void *video_drvdata()
{
return video_get_drvdata(video_devdata());
}
static inline const char *video_device_node_name(struct video_device *vdev)
{
//return dev_name(&vdev->dev);
return (vdev->init_name);
}
static inline int video_is_registered(struct video_device *vdev)
{
return test_bit(V4L2_FL_REGISTERED, &vdev->flags);
}
#endif /* _V4L2_DEV_H */

View file

@ -0,0 +1,216 @@
/*
V4L2 device support header.
Copyright (C) 2008 Hans Verkuil <hverkuil@xs4all.nl>
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _V4L2_DEVICE_H
#define _V4L2_DEVICE_H
#include "media-device.h"
#include "v4l2-subdev.h"
#include "v4l2-dev.h"
/* Each instance of a V4L2 device should create the v4l2_device struct,
either stand-alone or embedded in a larger struct.
It allows easy access to sub-devices (see v4l2-subdev.h) and provides
basic V4L2 device-level support.
*/
#define V4L2_DEVICE_NAME_SIZE (20 + 16)
struct v4l2_ctrl_handler;
struct v4l2_device {
/* dev->driver_data points to this struct.
Note: dev might be NULL if there is no parent device
as is the case with e.g. ISA devices. */
//struct device *dev;
//void *dev;
void *dev_driver_data;
//edit by Ian
//unsigned long dev_ref_count;
#if defined(CONFIG_MEDIA_CONTROLLER)
struct media_device *mdev;
#endif
/* used to keep track of the registered subdevs */
struct list_head subdevs;
/* lock this struct; can be used by the driver as well if this
struct is embedded into a larger struct. */
//spinlock_t lock;
_Lock lock;
/* unique device name, by default the driver name + bus ID */
char name[V4L2_DEVICE_NAME_SIZE];
/* notify callback called by some sub-devices. */
void (*notify)(struct v4l2_subdev *sd, unsigned int notification, void *arg);
/* The control handler. May be NULL. */
struct v4l2_ctrl_handler *ctrl_handler;
/* Device's priority state */
struct v4l2_prio_state prio;
/* BKL replacement mutex. Temporary solution only. */
//struct mutex ioctl_lock;
_Mutex ioctl_lock;
/* Keep track of the references to this struct. */
//struct kref ref;
unsigned long ref;
/* Release function that is called when the ref count goes to 0. */
void (*release)(struct v4l2_device *v4l2_dev);
};
static inline void v4l2_device_get(struct v4l2_device *v4l2_dev)
{
//kref_get(&v4l2_dev->ref);
atomic_inc((atomic_t *)&v4l2_dev->ref);
}
int v4l2_device_put(struct v4l2_device *v4l2_dev);
/* Initialize v4l2_dev and make dev->driver_data point to v4l2_dev.
dev may be NULL in rare cases (ISA devices). In that case you
must fill in the v4l2_dev->name field before calling this function. */
//int v4l2_device_register(struct v4l2_device *v4l2_dev);
int v4l2_device_register(void *dev_prive_date, struct v4l2_device *v4l2_dev);
/* Optional function to initialize the name field of struct v4l2_device using
the driver name and a driver-global atomic_t instance.
This function will increment the instance counter and returns the instance
value used in the name.
Example:
static atomic_t drv_instance = ATOMIC_INIT(0);
...
instance = v4l2_device_set_name(&v4l2_dev, "foo", &drv_instance);
The first time this is called the name field will be set to foo0 and
this function returns 0. If the name ends with a digit (e.g. cx18),
then the name will be set to cx18-0 since cx180 looks really odd. */
int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
atomic_t *instance);
/* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
Since the parent disappears this ensures that v4l2_dev doesn't have an
invalid parent pointer. */
void v4l2_device_disconnect(struct v4l2_device *v4l2_dev);
/* Unregister all sub-devices and any other resources related to v4l2_dev. */
void v4l2_device_unregister(struct v4l2_device *v4l2_dev);
/* Register a subdev with a v4l2 device. While registered the subdev module
is marked as in-use. An error is returned if the module is no longer
loaded when you attempt to register it. */
int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
struct v4l2_subdev *sd);
/* Unregister a subdev with a v4l2 device. Can also be called if the subdev
wasn't registered. In that case it will do nothing. */
void v4l2_device_unregister_subdev(struct v4l2_subdev *sd);
/* Register device nodes for all subdev of the v4l2 device that are marked with
* the V4L2_SUBDEV_FL_HAS_DEVNODE flag.
*/
int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev);
/* Iterate over all subdevs. */
#define v4l2_device_for_each_subdev(sd, v4l2_dev) \
list_for_each_entry(sd, &(v4l2_dev)->subdevs, list, struct v4l2_subdev)
/* Call the specified callback for all subdevs matching the condition.
Ignore any errors. Note that you cannot add or delete a subdev
while walking the subdevs list. */
#define __v4l2_device_call_subdevs_p(v4l2_dev, sd, cond, o, f, args...) \
do { \
list_for_each_entry((sd), &(v4l2_dev)->subdevs, list, struct v4l2_subdev) \
if ((cond) && (sd)->ops->o && (sd)->ops->o->f) \
(sd)->ops->o->f((sd) , ##args); \
} while (0)
#define __v4l2_device_call_subdevs(v4l2_dev, cond, o, f, args...) \
do { \
struct v4l2_subdev *__sd; \
\
__v4l2_device_call_subdevs_p(v4l2_dev, __sd, cond, o, \
f , ##args); \
} while (0)
/* Call the specified callback for all subdevs matching the condition.
If the callback returns an error other than 0 or -ENOIOCTLCMD, then
return with that error code. Note that you cannot add or delete a
subdev while walking the subdevs list. */
#define __v4l2_device_call_subdevs_until_err_p(v4l2_dev, sd, cond, o, f, args...) \
({ \
long __err = 0; \
\
list_for_each_entry((sd), &(v4l2_dev)->subdevs, list, struct v4l2_subdev) { \
if ((cond) && (sd)->ops->o && (sd)->ops->o->f) \
__err = (sd)->ops->o->f((sd) , ##args); \
if (__err && __err != -ENOIOCTLCMD) \
break; \
} \
(__err == -ENOIOCTLCMD) ? 0 : __err; \
})
#define __v4l2_device_call_subdevs_until_err(v4l2_dev, cond, o, f, args...) \
({ \
struct v4l2_subdev *__sd; \
__v4l2_device_call_subdevs_until_err_p(v4l2_dev, __sd, cond, o, \
f , ##args); \
})
/* Call the specified callback for all subdevs matching grp_id (if 0, then
match them all). Ignore any errors. Note that you cannot add or delete
a subdev while walking the subdevs list. */
#define v4l2_device_call_all(v4l2_dev, grpid, o, f, args...) \
do { \
struct v4l2_subdev *__sd; \
\
__v4l2_device_call_subdevs_p(v4l2_dev, __sd, \
!(grpid) || __sd->grp_id == (grpid), o, f , \
##args); \
} while (0)
/* Call the specified callback for all subdevs matching grp_id (if 0, then
match them all). If the callback returns an error other than 0 or
-ENOIOCTLCMD, then return with that error code. Note that you cannot
add or delete a subdev while walking the subdevs list. */
#define v4l2_device_call_until_err(v4l2_dev, grpid, o, f, args...) \
({ \
struct v4l2_subdev *__sd; \
__v4l2_device_call_subdevs_until_err_p(v4l2_dev, __sd, \
!(grpid) || __sd->grp_id == (grpid), o, f , \
##args); \
})
#define v4l2_device_has_op(v4l2_dev, o, f) \
({ \
struct v4l2_subdev *__sd; \
bool __result = FALSE; \
list_for_each_entry(__sd, &(v4l2_dev)->subdevs, list, struct v4l2_subdev) { \
if (v4l2_subdev_has_op(__sd, o, f)) { \
__result = true; \
break; \
} \
} \
__result; \
})
#endif

View file

@ -0,0 +1,139 @@
/*
* v4l2-event.h
*
* V4L2 events.
*
* Copyright (C) 2009--2010 Nokia Corporation.
*
* Contact: Sakari Ailus <sakari.ailus@iki.fi>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#ifndef V4L2_EVENT_H
#define V4L2_EVENT_H
#if 0
#include <linux/types.h>
#include <linux/wait.h>
#endif
#include "v4l2-osdep.h"
#include "videodev2.h"
/*
* Overview:
*
* Events are subscribed per-filehandle. An event specification consists of a
* type and is optionally associated with an object identified through the
* 'id' field. So an event is uniquely identified by the (type, id) tuple.
*
* The v4l2-fh struct has a list of subscribed events. The v4l2_subscribed_event
* struct is added to that list, one for every subscribed event.
*
* Each v4l2_subscribed_event struct ends with an array of v4l2_kevent structs.
* This array (ringbuffer, really) is used to store any events raised by the
* driver. The v4l2_kevent struct links into the 'available' list of the
* v4l2_fh struct so VIDIOC_DQEVENT will know which event to dequeue first.
*
* Finally, if the event subscription is associated with a particular object
* such as a V4L2 control, then that object needs to know about that as well
* so that an event can be raised by that object. So the 'node' field can
* be used to link the v4l2_subscribed_event struct into a list of that
* object.
*
* So to summarize:
*
* struct v4l2_fh has two lists: one of the subscribed events, and one of the
* pending events.
*
* struct v4l2_subscribed_event has a ringbuffer of raised (pending) events of
* that particular type.
*
* If struct v4l2_subscribed_event is associated with a specific object, then
* that object will have an internal list of struct v4l2_subscribed_event so
* it knows who subscribed an event to that object.
*/
struct v4l2_fh;
struct v4l2_subdev;
struct v4l2_subscribed_event;
struct video_device;
/** struct v4l2_kevent - Internal kernel event struct.
* @list: List node for the v4l2_fh->available list.
* @sev: Pointer to parent v4l2_subscribed_event.
* @event: The event itself.
*/
struct v4l2_kevent {
struct list_head list;
struct v4l2_subscribed_event *sev;
struct v4l2_event event;
};
/** struct v4l2_subscribed_event_ops - Subscribed event operations.
* @add: Optional callback, called when a new listener is added
* @del: Optional callback, called when a listener stops listening
* @replace: Optional callback that can replace event 'old' with event 'new'.
* @merge: Optional callback that can merge event 'old' into event 'new'.
*/
struct v4l2_subscribed_event_ops {
int (*add)(struct v4l2_subscribed_event *sev, unsigned elems);
void (*del)(struct v4l2_subscribed_event *sev);
void (*replace)(struct v4l2_event *old, const struct v4l2_event *new);
void (*merge)(const struct v4l2_event *old, struct v4l2_event *new);
};
/** struct v4l2_subscribed_event - Internal struct representing a subscribed event.
* @list: List node for the v4l2_fh->subscribed list.
* @type: Event type.
* @id: Associated object ID (e.g. control ID). 0 if there isn't any.
* @flags: Copy of v4l2_event_subscription->flags.
* @fh: Filehandle that subscribed to this event.
* @node: List node that hooks into the object's event list (if there is one).
* @ops: v4l2_subscribed_event_ops
* @elems: The number of elements in the events array.
* @first: The index of the events containing the oldest available event.
* @in_use: The number of queued events.
* @events: An array of @elems events.
*/
struct v4l2_subscribed_event {
struct list_head list;
u32 type;
u32 id;
u32 flags;
struct v4l2_fh *fh;
struct list_head node;
const struct v4l2_subscribed_event_ops *ops;
unsigned elems;
unsigned first;
unsigned in_use;
struct v4l2_kevent events[];
};
int v4l2_event_dequeue(struct v4l2_fh *fh, struct v4l2_event *event,
int nonblocking);
void v4l2_event_queue(struct video_device *vdev, const struct v4l2_event *ev);
void v4l2_event_queue_fh(struct v4l2_fh *fh, const struct v4l2_event *ev);
int v4l2_event_pending(struct v4l2_fh *fh);
int v4l2_event_subscribe(struct v4l2_fh *fh,
const struct v4l2_event_subscription *sub, unsigned elems,
const struct v4l2_subscribed_event_ops *ops);
int v4l2_event_unsubscribe(struct v4l2_fh *fh,
const struct v4l2_event_subscription *sub);
void v4l2_event_unsubscribe_all(struct v4l2_fh *fh);
int v4l2_event_subdev_unsubscribe(struct v4l2_subdev *sd, struct v4l2_fh *fh,
struct v4l2_event_subscription *sub);
#endif /* V4L2_EVENT_H */

View file

@ -0,0 +1,108 @@
/*
* v4l2-fh.h
*
* V4L2 file handle. Store per file handle data for the V4L2
* framework. Using file handles is optional for the drivers.
*
* Copyright (C) 2009--2010 Nokia Corporation.
*
* Contact: Sakari Ailus <sakari.ailus@iki.fi>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#ifndef V4L2_FH_H
#define V4L2_FH_H
//#include <linux/list.h>
#include "v4l2-osdep.h"
struct video_device;
struct v4l2_ctrl_handler;
struct v4l2_fh {
struct list_head list;
struct video_device *vdev;
struct v4l2_ctrl_handler *ctrl_handler;
enum v4l2_priority prio;
/* Events */
//wait_queue_head_t wait;
_Sema wait;
struct list_head subscribed; /* Subscribed events */
struct list_head available; /* Dequeueable event */
unsigned int navailable;
u32 sequence;
};
/*
* Initialise the file handle. Parts of the V4L2 framework using the
* file handles should be initialised in this function. Must be called
* from driver's v4l2_file_operations->open() handler if the driver
* uses v4l2_fh.
*/
void v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev);
/*
* Add the fh to the list of file handles on a video_device. The file
* handle must be initialised first.
*/
void v4l2_fh_add(struct v4l2_fh *fh);
/*
* Can be used as the open() op of v4l2_file_operations.
* It allocates a v4l2_fh and inits and adds it to the video_device associated
* with the file pointer.
*/
int v4l2_fh_open();
/*
* Remove file handle from the list of file handles. Must be called in
* v4l2_file_operations->release() handler if the driver uses v4l2_fh.
* On error filp->private_data will be NULL, otherwise it will point to
* the v4l2_fh struct.
*/
void v4l2_fh_del(struct v4l2_fh *fh);
/*
* Release resources related to a file handle. Parts of the V4L2
* framework using the v4l2_fh must release their resources here, too.
* Must be called in v4l2_file_operations->release() handler if the
* driver uses v4l2_fh.
*/
void v4l2_fh_exit(struct v4l2_fh *fh);
/*
* Can be used as the release() op of v4l2_file_operations.
* It deletes and exits the v4l2_fh associated with the file pointer and
* frees it. It will do nothing if filp->private_data (the pointer to the
* v4l2_fh struct) is NULL. This function always returns 0.
*/
int v4l2_fh_release();
/*
* Returns 1 if this filehandle is the only filehandle opened for the
* associated video_device. If fh is NULL, then it returns 0.
*/
int v4l2_fh_is_singular(struct v4l2_fh *fh);
/*
* Helper function with struct file as argument. If filp->private_data is
* NULL, then it will return 0.
*/
extern void *replace_files[16];
static inline int v4l2_fh_is_singular_file()
{
//struct v4l2_fh *fh = replace_files[0];
struct video_device *vdev = video_devdata();
struct v4l2_fh *fh = replace_files[vdev->minor];
return v4l2_fh_is_singular(fh);
}
#endif /* V4L2_EVENT_H */

View file

@ -0,0 +1,306 @@
/*
* include/media/v4l2-int-device.h
*
* V4L2 internal ioctl interface.
*
* Copyright (C) 2007 Nokia Corporation.
*
* Contact: Sakari Ailus <sakari.ailus@nokia.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#ifndef V4L2_INT_DEVICE_H
#define V4L2_INT_DEVICE_H
#include "v4l2-common.h"
#define V4L2NAMESIZE 32
/*
*
* The internal V4L2 device interface core.
*
*/
enum v4l2_int_type {
v4l2_int_type_master = 1,
v4l2_int_type_slave
};
//struct module;
struct v4l2_int_device;
struct v4l2_int_master {
int (*attach)(struct v4l2_int_device *slave);
void (*detach)(struct v4l2_int_device *slave);
};
typedef int (v4l2_int_ioctl_func)(struct v4l2_int_device *);
typedef int (v4l2_int_ioctl_func_0)(struct v4l2_int_device *);
typedef int (v4l2_int_ioctl_func_1)(struct v4l2_int_device *, void *);
struct v4l2_int_ioctl_desc {
int num;
v4l2_int_ioctl_func *func;
};
struct v4l2_int_slave {
/* Don't touch master. */
struct v4l2_int_device *master;
char attach_to[V4L2NAMESIZE];
int num_ioctls;
struct v4l2_int_ioctl_desc *ioctls;
};
struct v4l2_int_device {
/* Don't touch head. */
struct LIST_HEADER head;
//struct module *module;
char name[V4L2NAMESIZE];
enum v4l2_int_type type;
union {
struct v4l2_int_master *master;
struct v4l2_int_slave *slave;
} u;
void *priv;
};
void v4l2_int_device_try_attach_all(void);
int v4l2_int_device_register(struct v4l2_int_device *d);
void v4l2_int_device_unregister(struct v4l2_int_device *d);
int v4l2_int_ioctl_0(struct v4l2_int_device *d, int cmd);
int v4l2_int_ioctl_1(struct v4l2_int_device *d, int cmd, void *arg);
/*
*
* Types and definitions for IOCTL commands.
*
*/
enum v4l2_power {
V4L2_POWER_OFF = 0,
V4L2_POWER_ON,
V4L2_POWER_STANDBY,
};
/* Slave interface type. */
enum v4l2_if_type {
/*
* Parallel 8-, 10- or 12-bit interface, used by for example
* on certain image sensors.
*/
V4L2_IF_TYPE_BT656,
};
enum v4l2_if_type_bt656_mode {
/*
* Modes without Bt synchronisation codes. Separate
* synchronisation signal lines are used.
*/
V4L2_IF_TYPE_BT656_MODE_NOBT_8BIT,
V4L2_IF_TYPE_BT656_MODE_NOBT_10BIT,
V4L2_IF_TYPE_BT656_MODE_NOBT_12BIT,
/*
* Use Bt synchronisation codes. The vertical and horizontal
* synchronisation is done based on synchronisation codes.
*/
V4L2_IF_TYPE_BT656_MODE_BT_8BIT,
V4L2_IF_TYPE_BT656_MODE_BT_10BIT,
};
struct v4l2_if_type_bt656 {
/*
* 0: Frame begins when vsync is high.
* 1: Frame begins when vsync changes from low to high.
*/
unsigned frame_start_on_rising_vs:1;
/* Use Bt synchronisation codes for sync correction. */
unsigned bt_sync_correct:1;
/* Swap every two adjacent image data elements. */
unsigned swap:1;
/* Inverted latch clock polarity from slave. */
unsigned latch_clk_inv:1;
/* Hs polarity. 0 is active high, 1 active low. */
unsigned nobt_hs_inv:1;
/* Vs polarity. 0 is active high, 1 active low. */
unsigned nobt_vs_inv:1;
enum v4l2_if_type_bt656_mode mode;
/* Minimum accepted bus clock for slave (in Hz). */
u32 clock_min;
/* Maximum accepted bus clock for slave. */
u32 clock_max;
/*
* Current wish of the slave. May only change in response to
* ioctls that affect image capture.
*/
u32 clock_curr;
};
struct v4l2_ifparm {
enum v4l2_if_type if_type;
union {
struct v4l2_if_type_bt656 bt656;
} u;
};
/* IOCTL command numbers. */
enum v4l2_int_ioctl_num {
/*
*
* "Proper" V4L ioctls, as in struct video_device.
*
*/
vidioc_int_enum_fmt_cap_num = 1,
vidioc_int_g_fmt_cap_num,
vidioc_int_s_fmt_cap_num,
vidioc_int_try_fmt_cap_num,
vidioc_int_queryctrl_num,
vidioc_int_g_ctrl_num,
vidioc_int_s_ctrl_num,
vidioc_int_cropcap_num,
vidioc_int_g_crop_num,
vidioc_int_s_crop_num,
vidioc_int_g_parm_num,
vidioc_int_s_parm_num,
vidioc_int_querystd_num,
vidioc_int_s_std_num,
vidioc_int_s_video_routing_num,
/*
*
* Strictly internal ioctls.
*
*/
/* Initialise the device when slave attaches to the master. */
vidioc_int_dev_init_num = 1000,
/* Delinitialise the device at slave detach. */
vidioc_int_dev_exit_num,
/* Set device power state. */
vidioc_int_s_power_num,
/*
* Get slave private data, e.g. platform-specific slave
* configuration used by the master.
*/
vidioc_int_g_priv_num,
/* Get slave interface parameters. */
vidioc_int_g_ifparm_num,
/* Does the slave need to be reset after VIDIOC_DQBUF? */
vidioc_int_g_needs_reset_num,
vidioc_int_enum_framesizes_num,
vidioc_int_enum_frameintervals_num,
/*
*
* VIDIOC_INT_* ioctls.
*
*/
/* VIDIOC_INT_RESET */
vidioc_int_reset_num,
/* VIDIOC_INT_INIT */
vidioc_int_init_num,
/*
*
* Start of private ioctls.
*
*/
vidioc_int_priv_start_num = 2000,
};
/*
*
* IOCTL wrapper functions for better type checking.
*
*/
#define V4L2_INT_WRAPPER_0(name) \
static inline int vidioc_int_##name(struct v4l2_int_device *d) \
{ \
return v4l2_int_ioctl_0(d, vidioc_int_##name##_num); \
} \
\
static inline struct v4l2_int_ioctl_desc \
vidioc_int_##name##_cb(int (*func) \
(struct v4l2_int_device *)) \
{ \
struct v4l2_int_ioctl_desc desc; \
\
desc.num = vidioc_int_##name##_num; \
desc.func = (v4l2_int_ioctl_func *)func; \
\
return desc; \
}
#define V4L2_INT_WRAPPER_1(name, arg_type, asterisk) \
static inline int vidioc_int_##name(struct v4l2_int_device *d, \
arg_type asterisk arg) \
{ \
return v4l2_int_ioctl_1(d, vidioc_int_##name##_num, \
(void *)(unsigned long)arg); \
} \
\
static inline struct v4l2_int_ioctl_desc \
vidioc_int_##name##_cb(int (*func) \
(struct v4l2_int_device *, \
arg_type asterisk)) \
{ \
struct v4l2_int_ioctl_desc desc; \
\
desc.num = vidioc_int_##name##_num; \
desc.func = (v4l2_int_ioctl_func *)func; \
\
return desc; \
}
V4L2_INT_WRAPPER_1(enum_fmt_cap, struct v4l2_fmtdesc, *);
V4L2_INT_WRAPPER_1(g_fmt_cap, struct v4l2_format, *);
V4L2_INT_WRAPPER_1(s_fmt_cap, struct v4l2_format, *);
V4L2_INT_WRAPPER_1(try_fmt_cap, struct v4l2_format, *);
V4L2_INT_WRAPPER_1(queryctrl, struct v4l2_queryctrl, *);
V4L2_INT_WRAPPER_1(g_ctrl, struct v4l2_control, *);
V4L2_INT_WRAPPER_1(s_ctrl, struct v4l2_control, *);
V4L2_INT_WRAPPER_1(cropcap, struct v4l2_cropcap, *);
V4L2_INT_WRAPPER_1(g_crop, struct v4l2_crop, *);
V4L2_INT_WRAPPER_1(s_crop, struct v4l2_crop, *);
V4L2_INT_WRAPPER_1(g_parm, struct v4l2_streamparm, *);
V4L2_INT_WRAPPER_1(s_parm, struct v4l2_streamparm, *);
V4L2_INT_WRAPPER_1(querystd, v4l2_std_id, *);
V4L2_INT_WRAPPER_1(s_std, v4l2_std_id, *);
V4L2_INT_WRAPPER_1(s_video_routing, struct v4l2_routing, *);
V4L2_INT_WRAPPER_0(dev_init);
V4L2_INT_WRAPPER_0(dev_exit);
V4L2_INT_WRAPPER_1(s_power, enum v4l2_power, );
V4L2_INT_WRAPPER_1(g_priv, void, *);
V4L2_INT_WRAPPER_1(g_ifparm, struct v4l2_ifparm, *);
V4L2_INT_WRAPPER_1(g_needs_reset, void, *);
V4L2_INT_WRAPPER_1(enum_framesizes, struct v4l2_frmsizeenum, *);
V4L2_INT_WRAPPER_1(enum_frameintervals, struct v4l2_frmivalenum, *);
V4L2_INT_WRAPPER_0(reset);
V4L2_INT_WRAPPER_0(init);
#endif

View file

@ -0,0 +1,320 @@
/*
*
* V 4 L 2 D R I V E R H E L P E R A P I
*
* Moved from videodev2.h
*
* Some commonly needed functions for drivers (v4l2-common.o module)
*/
#ifndef _V4L2_IOCTL_H
#define _V4L2_IOCTL_H
#if 0
#include <linux/poll.h>
#include <linux/fs.h>
#include <linux/mutex.h>
#include <linux/compiler.h> /* need __user */
#endif
#include "v4l2-osdep.h"
#include "videodev2.h"
struct v4l2_fh;
struct v4l2_ioctl_ops {
/* ioctl callbacks */
/* VIDIOC_QUERYCAP handler */
int (*vidioc_querycap)(void *fh, struct v4l2_capability *cap);
/* Priority handling */
int (*vidioc_g_priority) (void *fh,
enum v4l2_priority *p);
int (*vidioc_s_priority) (void *fh,
enum v4l2_priority p);
/* VIDIOC_ENUM_FMT handlers */
int (*vidioc_enum_fmt_vid_cap) (void *fh,
struct v4l2_fmtdesc *f);
int (*vidioc_enum_fmt_vid_overlay) (void *fh,
struct v4l2_fmtdesc *f);
int (*vidioc_enum_fmt_vid_out) (void *fh,
struct v4l2_fmtdesc *f);
int (*vidioc_enum_fmt_vid_cap_mplane)(void *fh,
struct v4l2_fmtdesc *f);
int (*vidioc_enum_fmt_vid_out_mplane)(void *fh,
struct v4l2_fmtdesc *f);
/* VIDIOC_G_FMT handlers */
int (*vidioc_g_fmt_vid_cap) (void *fh,
struct v4l2_format *f);
int (*vidioc_g_fmt_vid_overlay)(void *fh,
struct v4l2_format *f);
int (*vidioc_g_fmt_vid_out) (void *fh,
struct v4l2_format *f);
int (*vidioc_g_fmt_vid_out_overlay)(void *fh,
struct v4l2_format *f);
int (*vidioc_g_fmt_vbi_cap) (void *fh,
struct v4l2_format *f);
int (*vidioc_g_fmt_vbi_out) (void *fh,
struct v4l2_format *f);
int (*vidioc_g_fmt_sliced_vbi_cap)(void *fh,
struct v4l2_format *f);
int (*vidioc_g_fmt_sliced_vbi_out)(void *fh,
struct v4l2_format *f);
int (*vidioc_g_fmt_vid_cap_mplane)(void *fh,
struct v4l2_format *f);
int (*vidioc_g_fmt_vid_out_mplane)(void *fh,
struct v4l2_format *f);
/* VIDIOC_S_FMT handlers */
int (*vidioc_s_fmt_vid_cap) (void *fh,
struct v4l2_format *f);
int (*vidioc_s_fmt_vid_overlay)(void *fh,
struct v4l2_format *f);
int (*vidioc_s_fmt_vid_out) (void *fh,
struct v4l2_format *f);
int (*vidioc_s_fmt_vid_out_overlay)(void *fh,
struct v4l2_format *f);
int (*vidioc_s_fmt_vbi_cap) (void *fh,
struct v4l2_format *f);
int (*vidioc_s_fmt_vbi_out) (void *fh,
struct v4l2_format *f);
int (*vidioc_s_fmt_sliced_vbi_cap)(void *fh,
struct v4l2_format *f);
int (*vidioc_s_fmt_sliced_vbi_out)(void *fh,
struct v4l2_format *f);
int (*vidioc_s_fmt_vid_cap_mplane)(void *fh,
struct v4l2_format *f);
int (*vidioc_s_fmt_vid_out_mplane)(void *fh,
struct v4l2_format *f);
/* VIDIOC_TRY_FMT handlers */
int (*vidioc_try_fmt_vid_cap) (void *fh,
struct v4l2_format *f);
int (*vidioc_try_fmt_vid_overlay)(void *fh,
struct v4l2_format *f);
int (*vidioc_try_fmt_vid_out) (void *fh,
struct v4l2_format *f);
int (*vidioc_try_fmt_vid_out_overlay)(void *fh,
struct v4l2_format *f);
int (*vidioc_try_fmt_vbi_cap) (void *fh,
struct v4l2_format *f);
int (*vidioc_try_fmt_vbi_out) (void *fh,
struct v4l2_format *f);
int (*vidioc_try_fmt_sliced_vbi_cap)(void *fh,
struct v4l2_format *f);
int (*vidioc_try_fmt_sliced_vbi_out)(void *fh,
struct v4l2_format *f);
int (*vidioc_try_fmt_vid_cap_mplane)(void *fh,
struct v4l2_format *f);
int (*vidioc_try_fmt_vid_out_mplane)(void *fh,
struct v4l2_format *f);
/* Buffer handlers */
int (*vidioc_reqbufs) (void *fh, struct v4l2_requestbuffers *b);
int (*vidioc_querybuf)(void *fh, struct v4l2_buffer *b);
int (*vidioc_qbuf) (void *fh, struct v4l2_buffer *b);
int (*vidioc_expbuf) (void *fh,
struct v4l2_exportbuffer *e);
int (*vidioc_dqbuf) (void *fh, struct v4l2_buffer *b);
int (*vidioc_create_bufs)(void *fh, struct v4l2_create_buffers *b);
int (*vidioc_prepare_buf)(void *fh, struct v4l2_buffer *b);
int (*vidioc_overlay) (void *fh, unsigned int i);
int (*vidioc_g_fbuf) (void *fh,
struct v4l2_framebuffer *a);
int (*vidioc_s_fbuf) (void *fh,
const struct v4l2_framebuffer *a);
/* Stream on/off */
int (*vidioc_streamon) (void *fh, enum v4l2_buf_type i);
int (*vidioc_streamoff)(void *fh, enum v4l2_buf_type i);
/* Standard handling
ENUMSTD is handled by videodev.c
*/
int (*vidioc_g_std) (void *fh, v4l2_std_id *norm);
int (*vidioc_s_std) (void *fh, v4l2_std_id norm);
int (*vidioc_querystd) (void *fh, v4l2_std_id *a);
/* Input handling */
int (*vidioc_enum_input)(void *fh,
struct v4l2_input *inp);
int (*vidioc_g_input) (void *fh, unsigned int *i);
int (*vidioc_s_input) (void *fh, unsigned int i);
/* Output handling */
int (*vidioc_enum_output) (void *fh,
struct v4l2_output *a);
int (*vidioc_g_output) (void *fh, unsigned int *i);
int (*vidioc_s_output) (void *fh, unsigned int i);
/* Control handling */
int (*vidioc_queryctrl) (void *fh,
struct v4l2_queryctrl *a);
int (*vidioc_g_ctrl) (void *fh,
struct v4l2_control *a);
int (*vidioc_s_ctrl) (void *fh,
struct v4l2_control *a);
int (*vidioc_g_ext_ctrls) (void *fh,
struct v4l2_ext_controls *a);
int (*vidioc_s_ext_ctrls) (void *fh,
struct v4l2_ext_controls *a);
int (*vidioc_try_ext_ctrls) (void *fh,
struct v4l2_ext_controls *a);
int (*vidioc_querymenu) (void *fh,
struct v4l2_querymenu *a);
/* Audio ioctls */
int (*vidioc_enumaudio) (void *fh,
struct v4l2_audio *a);
int (*vidioc_g_audio) (void *fh,
struct v4l2_audio *a);
int (*vidioc_s_audio) (void *fh,
const struct v4l2_audio *a);
/* Audio out ioctls */
int (*vidioc_enumaudout) (void *fh,
struct v4l2_audioout *a);
int (*vidioc_g_audout) (void *fh,
struct v4l2_audioout *a);
int (*vidioc_s_audout) (void *fh,
const struct v4l2_audioout *a);
int (*vidioc_g_modulator) (void *fh,
struct v4l2_modulator *a);
int (*vidioc_s_modulator) (void *fh,
const struct v4l2_modulator *a);
/* Crop ioctls */
int (*vidioc_cropcap) (void *fh,
struct v4l2_cropcap *a);
int (*vidioc_g_crop) (void *fh,
struct v4l2_crop *a);
int (*vidioc_s_crop) (void *fh,
const struct v4l2_crop *a);
int (*vidioc_g_selection) (void *fh,
struct v4l2_selection *s);
int (*vidioc_s_selection) (void *fh,
struct v4l2_selection *s);
/* Compression ioctls */
int (*vidioc_g_jpegcomp) (void *fh,
struct v4l2_jpegcompression *a);
int (*vidioc_s_jpegcomp) (void *fh,
const struct v4l2_jpegcompression *a);
int (*vidioc_g_enc_index) ( void *fh,
struct v4l2_enc_idx *a);
int (*vidioc_encoder_cmd) (void *fh,
struct v4l2_encoder_cmd *a);
int (*vidioc_try_encoder_cmd) (void *fh,
struct v4l2_encoder_cmd *a);
int (*vidioc_decoder_cmd) (void *fh,
struct v4l2_decoder_cmd *a);
int (*vidioc_try_decoder_cmd) (void *fh,
struct v4l2_decoder_cmd *a);
/* Stream type-dependent parameter ioctls */
int (*vidioc_g_parm) (void *fh,
struct v4l2_streamparm *a);
int (*vidioc_s_parm) (void *fh,
struct v4l2_streamparm *a);
/* Tuner ioctls */
int (*vidioc_g_tuner) (void *fh,
struct v4l2_tuner *a);
int (*vidioc_s_tuner) (void *fh,
const struct v4l2_tuner *a);
int (*vidioc_g_frequency) (void *fh,
struct v4l2_frequency *a);
int (*vidioc_s_frequency) (void *fh,
const struct v4l2_frequency *a);
int (*vidioc_enum_freq_bands) (void *fh,
struct v4l2_frequency_band *band);
/* Sliced VBI cap */
int (*vidioc_g_sliced_vbi_cap) (void *fh,
struct v4l2_sliced_vbi_cap *a);
/* Log status ioctl */
int (*vidioc_log_status) ( void *fh);
int (*vidioc_s_hw_freq_seek) (void *fh,
const struct v4l2_hw_freq_seek *a);
/* Debugging ioctls */
#ifdef CONFIG_VIDEO_ADV_DEBUG
int (*vidioc_g_register) (void *fh,
struct v4l2_dbg_register *reg);
int (*vidioc_s_register) (void *fh,
const struct v4l2_dbg_register *reg);
int (*vidioc_g_chip_info) (void *fh,
struct v4l2_dbg_chip_info *chip);
#endif
int (*vidioc_enum_framesizes) (void *fh,
struct v4l2_frmsizeenum *fsize);
int (*vidioc_enum_frameintervals) (void *fh,
struct v4l2_frmivalenum *fival);
/* DV Timings IOCTLs */
int (*vidioc_s_dv_timings) (void *fh,
struct v4l2_dv_timings *timings);
int (*vidioc_g_dv_timings) (void *fh,
struct v4l2_dv_timings *timings);
int (*vidioc_query_dv_timings) ( void *fh,
struct v4l2_dv_timings *timings);
int (*vidioc_enum_dv_timings) (void *fh,
struct v4l2_enum_dv_timings *timings);
int (*vidioc_dv_timings_cap) (void *fh,
struct v4l2_dv_timings_cap *cap);
int (*vidioc_subscribe_event) (struct v4l2_fh *fh,
const struct v4l2_event_subscription *sub);
int (*vidioc_unsubscribe_event)(struct v4l2_fh *fh,
const struct v4l2_event_subscription *sub);
/* For other private ioctls */
long (*vidioc_default) (void *fh,
bool valid_prio, unsigned int cmd, void *arg);
};
/* v4l debugging and diagnostics */
/* Debug bitmask flags to be used on V4L2 */
#define V4L2_DEBUG_IOCTL 0x01
#define V4L2_DEBUG_IOCTL_ARG 0x02
/* Video standard functions */
extern const char *v4l2_norm_to_name(v4l2_std_id id);
extern void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod);
extern int v4l2_video_std_construct(struct v4l2_standard *vs,
int id, const char *name);
/* Prints the ioctl in a human-readable format. If prefix != NULL,
then do printk(KERN_DEBUG "%s: ", prefix) first. */
extern void v4l_printk_ioctl(const char *prefix, unsigned int cmd);
/* Internal use only: get the mutex (if any) that we need to lock for the
given command. */
struct video_device;
extern _Mutex *v4l2_ioctl_get_lock(struct video_device *vdev, unsigned cmd);
/* names for fancy debug output */
extern const char *v4l2_field_names[];
extern const char *v4l2_type_names[];
#ifdef CONFIG_COMPAT
/* 32 Bits compatibility layer for 64 bits processors */
extern long v4l2_compat_ioctl32(unsigned int cmd, unsigned long arg);
#endif
typedef long (*v4l2_kioctl)(unsigned int cmd, void *arg);
/* Include support for obsoleted stuff */
extern long video_usercopy(unsigned int cmd, unsigned long arg, v4l2_kioctl func);
/* Standard handlers for V4L ioctl's */
extern long video_ioctl2(unsigned int cmd, unsigned long arg);
#endif /* _V4L2_IOCTL_H */

View file

@ -0,0 +1,112 @@
/*
* Media Bus API header
*
* Copyright (C) 2009, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
*
* 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.
*/
#ifndef V4L2_MEDIABUS_H
#define V4L2_MEDIABUS_H
#include "v4l2-mediabus.h"
/* Parallel flags */
/*
* Can the client run in master or in slave mode. By "Master mode" an operation
* mode is meant, when the client (e.g., a camera sensor) is producing
* horizontal and vertical synchronisation. In "Slave mode" the host is
* providing these signals to the slave.
*/
#define V4L2_MBUS_MASTER (1 << 0)
#define V4L2_MBUS_SLAVE (1 << 1)
/*
* Signal polarity flags
* Note: in BT.656 mode HSYNC, FIELD, and VSYNC are unused
* V4L2_MBUS_[HV]SYNC* flags should be also used for specifying
* configuration of hardware that uses [HV]REF signals
*/
#define V4L2_MBUS_HSYNC_ACTIVE_HIGH (1 << 2)
#define V4L2_MBUS_HSYNC_ACTIVE_LOW (1 << 3)
#define V4L2_MBUS_VSYNC_ACTIVE_HIGH (1 << 4)
#define V4L2_MBUS_VSYNC_ACTIVE_LOW (1 << 5)
#define V4L2_MBUS_PCLK_SAMPLE_RISING (1 << 6)
#define V4L2_MBUS_PCLK_SAMPLE_FALLING (1 << 7)
#define V4L2_MBUS_DATA_ACTIVE_HIGH (1 << 8)
#define V4L2_MBUS_DATA_ACTIVE_LOW (1 << 9)
/* FIELD = 0/1 - Field1 (odd)/Field2 (even) */
#define V4L2_MBUS_FIELD_EVEN_HIGH (1 << 10)
/* FIELD = 1/0 - Field1 (odd)/Field2 (even) */
#define V4L2_MBUS_FIELD_EVEN_LOW (1 << 11)
/* Active state of Sync-on-green (SoG) signal, 0/1 for LOW/HIGH respectively. */
#define V4L2_MBUS_VIDEO_SOG_ACTIVE_HIGH (1 << 12)
#define V4L2_MBUS_VIDEO_SOG_ACTIVE_LOW (1 << 13)
/* Serial flags */
/* How many lanes the client can use */
#define V4L2_MBUS_CSI2_1_LANE (1 << 0)
#define V4L2_MBUS_CSI2_2_LANE (1 << 1)
#define V4L2_MBUS_CSI2_3_LANE (1 << 2)
#define V4L2_MBUS_CSI2_4_LANE (1 << 3)
/* On which channels it can send video data */
#define V4L2_MBUS_CSI2_CHANNEL_0 (1 << 4)
#define V4L2_MBUS_CSI2_CHANNEL_1 (1 << 5)
#define V4L2_MBUS_CSI2_CHANNEL_2 (1 << 6)
#define V4L2_MBUS_CSI2_CHANNEL_3 (1 << 7)
/* Does it support only continuous or also non-continuous clock mode */
#define V4L2_MBUS_CSI2_CONTINUOUS_CLOCK (1 << 8)
#define V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK (1 << 9)
#define V4L2_MBUS_CSI2_LANES (V4L2_MBUS_CSI2_1_LANE | V4L2_MBUS_CSI2_2_LANE | \
V4L2_MBUS_CSI2_3_LANE | V4L2_MBUS_CSI2_4_LANE)
#define V4L2_MBUS_CSI2_CHANNELS (V4L2_MBUS_CSI2_CHANNEL_0 | V4L2_MBUS_CSI2_CHANNEL_1 | \
V4L2_MBUS_CSI2_CHANNEL_2 | V4L2_MBUS_CSI2_CHANNEL_3)
/**
* v4l2_mbus_type - media bus type
* @V4L2_MBUS_PARALLEL: parallel interface with hsync and vsync
* @V4L2_MBUS_BT656: parallel interface with embedded synchronisation, can
* also be used for BT.1120
* @V4L2_MBUS_CSI2: MIPI CSI-2 serial interface
*/
enum v4l2_mbus_type {
V4L2_MBUS_PARALLEL,
V4L2_MBUS_BT656,
V4L2_MBUS_CSI2,
};
/**
* v4l2_mbus_config - media bus configuration
* @type: in: interface type
* @flags: in / out: configuration flags, depending on @type
*/
struct v4l2_mbus_config {
enum v4l2_mbus_type type;
unsigned int flags;
};
#if 0
static inline void v4l2_fill_pix_format(struct v4l2_pix_format *pix_fmt,
const struct v4l2_mbus_framefmt *mbus_fmt)
{
pix_fmt->width = mbus_fmt->width;
pix_fmt->height = mbus_fmt->height;
pix_fmt->field = mbus_fmt->field;
pix_fmt->colorspace = mbus_fmt->colorspace;
}
static inline void v4l2_fill_mbus_format(struct v4l2_mbus_framefmt *mbus_fmt,
const struct v4l2_pix_format *pix_fmt,
enum v4l2_mbus_pixelcode code)
{
mbus_fmt->width = pix_fmt->width;
mbus_fmt->height = pix_fmt->height;
mbus_fmt->field = pix_fmt->field;
mbus_fmt->colorspace = pix_fmt->colorspace;
mbus_fmt->code = code;
}
#endif
#endif

View file

@ -0,0 +1,846 @@
#ifndef _V4L2_OSDEP_H_
#define _V4L2_OSDEP_H_
#include "platform/platform_stdlib.h"
#include "basic_types.h"
#include "osdep_api.h"
#include "usb_defs.h"
#include "errno.h"
//#include "hal_util.h"
#include "dlist.h"
#define V4L2_LAYER_DEBUG 0
#if V4L2_LAYER_DEBUG
#define V4L2_PRINTF(fmt, args...) printf("\n\r%s: " fmt, __FUNCTION__, ## args)
#define V4L2_ERROR(fmt, args...) printf("\n\r%s: " fmt, __FUNCTION__, ## args)
#else
#define V4L2_PRINTF(fmt, args...)
#define V4L2_ERROR(fmt, args...) printf("\n\r%s: " fmt, __FUNCTION__, ## args)
#endif
/* misc items */
#ifndef ssize_t
#define ssize_t SSIZE_T
#endif
#ifndef size_t
#define size_t SIZE_T
#endif
#ifndef __user
#define __user
#endif
#ifndef loff_t
#define loff_t long
#endif
#ifndef __u8
#define __u8 u8
#endif
#ifndef __u16
#define __u16 u16
#endif
#ifndef __u32
#define __u32 u32
#endif
#ifndef __u64
#define __u64 u64
#endif
#ifndef __s8
#define __s8 s8
#endif
#ifndef __s16
#define __s16 s16
#endif
#ifndef __s32
#define __s32 s32
#endif
#ifndef __s64
#define __s64 s64
#endif
#ifndef spinlock_t
#define spinlock_t _Lock
#endif
#ifndef gfp_t
#define gfp_t u32
#endif
#ifndef _atomic_spin_lock_irqsave
#define _atomic_spin_lock_irqsave(p, flags) SaveAndCli()
#endif
#ifndef _atomic_spin_unlock_irqrestore
#define _atomic_spin_unlock_irqrestore(p, flags) RestoreFlags()
#endif
#ifndef local_irq_save
#define local_irq_save(flags) SaveAndCli()
#endif
#ifndef local_irq_restore
#define local_irq_restore(flags) RestoreFlags()
#endif
#ifndef cris_atomic_save
#define cris_atomic_save(addr, flags) local_irq_save(flags)
#endif
#ifndef cris_atomic_restore
#define cris_atomic_restore(addr, flags) local_irq_restore(flags)
#endif
/*
* abs() handles unsigned and signed longs, ints, shorts and chars. For all
* input types abs() returns a signed long.
* abs() should not be used for 64-bit types (s64, u64, long long) - use abs64()
* for those.
*/
#ifndef abs
#define abs(x) ((x >= 0) ? (x) : (x * -1))
#endif
#ifndef min
#define min(x, y) ((x) < (y) ? (x) : (y))
#endif
#ifndef max
#define max(x, y) ((x) > (y) ? (x) : (y))
#endif
#ifndef min_t
#define min_t(type, x, y) ({ \
type __min1 = (x); \
type __min2 = (y); \
(__min1 < __min2) ? (__min1) : (__min2); })
#endif
#ifndef max_t
#define max_t(type, x, y) ({ \
type __max1 = (x); \
type __max2 = (y); \
(__max1 > __max2) ? (__max1) : (__max2); })
#endif
#ifndef max_tt
#define max_tt(ret,type,x,y) do{ \
type __max1 = (x); \
type __max2 = (y); \
ret = (__max1 > __max2) ? (__max1) : (__max2); }while(0)
#endif
#ifndef min_tt
#define min_tt(ret,type, x, y) do{ \
type __min1 = (x); \
type __min2 = (y); \
ret = (__min1 < __min2) ? (__min1) : (__min2); }while(0)
#endif
/**
* container_of - cast a member of a structure out to the containing structure
* @p(ptr): the pointer to the member.
* @t(type): the type of the container struct this is embedded in.
* @m(member): the name of the member within the struct.
*
*/
#ifndef container_of
#define container_of(ptr, type, member) \
((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member)))
#endif
/**
* list_next_entry - get the next element in list
* @pos: the type * to cursor
* @member: the name of the list_struct within the struct.
*/
#define list_next_entry(pos, member, type) \
list_entry((pos)->member.next, type, member)
/**
* list_for_each_entry_continue - continue iteration over list of given type
* @pos: the type * to use as a loop cursor.
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*
* Continue to iterate over list of given type, continuing after
* the current position.
*/
#define list_for_each_entry_continue(pos, head, member, type) \
for (pos = list_next_entry(pos, member, type); \
&pos->member != (head); \
pos = list_next_entry(pos, member, type))
/* spin lock */
#ifndef spin_lock_init
#define spin_lock_init(plock) RtlSpinlockInit((plock))
#endif
#ifndef spin_lock_free
#define spin_lock_free(plock) RtlSpinlockFree((plock))
#endif
#ifndef spin_lock
#define spin_lock(plock) RtlSpinlock((plock))
#endif
#ifndef spin_unlock
#define spin_unlock(plock) RtlSpinunlock((plock))
#endif
/* mutex */
#ifndef Mutex
#define Mutex _Mutex
#endif
#ifndef mutex_init
#define mutex_init(pmutex) RtlMutexInit((pmutex))
#endif
#ifndef mutex_lock
#define mutex_lock(pmutex) RtlDownSema((pmutex))
#endif
#ifndef mutex_unlock
#define mutex_unlock(pmutex) RtlUpSema((pmutex))
#endif
#ifndef mutex_destory
#define mutex_destory(pmutex) RtlMutexFree((pmutex))
#endif
/* semaphore */
#ifndef Sema
#define Sema _Sema
#endif
#ifndef Sema_Init
#define Sema_Init(pmutex, pval) RtlInitSema(pmutex, pval)
#endif
#ifndef Sema_Free
#define Sema_Free(pmutex) RtlFreeSema(pmutex)
#endif
#ifndef Sema_Up
#define Sema_Up(pmutex) RtlUpSema(pmutex)
#endif
#ifndef Sema_Down
#define Sema_Down(pmutex) RtlDownSema(pmutex)
#endif
#ifndef Sema_Sown_WithTimeout
#define Sema_Down_WithTimeout(pmutex,ptimeout) RtlDownSemaWithTimeout(pmutex,ptimeout) //
#endif
/* Atomic integer operations */
#ifndef atomic_set
#define atomic_set(v, i) RTL_ATOMIC_SET((v), (i))
#endif
#ifndef atomic_read
#define atomic_read(v) RTL_ATOMIC_READ((v))
#endif
#ifndef atomic_add
#define atomic_add(v, i) RTL_ATOMIC_ADD((v), (i))
#endif
#ifndef atomic_sub
#define atomic_sub(v, i) RTL_ATOMIC_SUB((v), (i))
#endif
#ifndef atomic_inc
#define atomic_inc(v) RTL_ATOMIC_INC((v))
#endif
#ifndef atomic_dec
#define atomic_dec(v) RTL_ATOMIC_DEC((v))
#endif
// IOCTL ...
#ifndef _IOC_NRBITS
#define _IOC_NRBITS (8)
#endif
#ifndef _IOC_TYPEBITS
#define _IOC_TYPEBITS (8)
#endif
#ifndef _IOC_SIZEBITS
#define _IOC_SIZEBITS (14)
#endif
#ifndef _IOC_DIRBITS
#define _IOC_DIRBITS (2)
#endif
#ifndef _IOC_NRMASK
#define _IOC_NRMASK ((1 << _IOC_NRBITS) - 1)
#endif
#ifndef _IOC_TYPEMASK
#define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS) - 1)
#endif
#ifndef _IOC_SIZEMASK
#define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS) - 1)
#endif
#ifndef _IOC_DIRMASK
#define _IOC_DIRMASK ((1 << _IOC_DIRBITS) - 1)
#endif
#ifndef _IOC_NRSHIFT
#define _IOC_NRSHIFT (0)
#endif
#ifndef _IOC_TYPESHIFT
#define _IOC_TYPESHIFT (_IOC_NRSHIFT + _IOC_NRBITS)
#endif
#ifndef _IOC_SIZESHIFT
#define _IOC_SIZESHIFT (_IOC_TYPESHIFT + _IOC_TYPEBITS)
#endif
#ifndef _IOC_DIRSHIFT
#define _IOC_DIRSHIFT (_IOC_SIZESHIFT + _IOC_SIZEBITS)
#endif
/*
* Direction bits.
*/
#ifndef _IOC_NONE
#define _IOC_NONE (0U)
#endif
#ifndef _IOC_WRITE
#define _IOC_WRITE (1U)
#endif
#ifndef _IOC_READ
#define _IOC_READ (2U)
#endif
/*
* combine the four dirtypenrsize parameters to one cmd parameter
*
*/
#ifndef _IOC
#define _IOC(dir,type,nr,size) \
(((dir) << _IOC_DIRSHIFT) | \
((type) << _IOC_TYPESHIFT) | \
((nr) << _IOC_NRSHIFT) | \
((size) << _IOC_SIZESHIFT))
#endif
/*
* used to create IOCTL cmd
*/
#ifndef _IO
#define _IO(type,nr) _IOC(_IOC_NONE,(type), (nr), 0)
#endif
#ifndef _IOR
#define _IOR(type,nr,size) _IOC(_IOC_READ,(type), (nr), sizeof(size))
#endif
#ifndef _IOW
#define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type), (nr), sizeof(size))
#endif
#ifndef _IOWR
#define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE, (type), (nr), sizeof(size))
#endif
/*
* used to decode ioctl infoations..
*/
#ifndef _IOC_DIR
#define _IOC_DIR(nr) (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
#endif
#ifndef _IOC_TYPE
#define _IOC_TYPE(nr) (((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
#endif
#ifndef _IOC_NR
#define _IOC_NR(nr) (((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
#endif
#ifndef _IOC_SIZE
#define _IOC_SIZE(nr) (((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
#endif
/* ...and for the drivers/sound files... */
#ifndef IOC_IN
#define IOC_IN (_IOC_WRITE << _IOC_DIRSHIFT)
#endif
#ifndef IOC_OUT
#define IOC_OUT (_IOC_READ << _IOC_DIRSHIFT)
#endif
#ifndef IOC_INOUT
#define IOC_INOUT ((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT)
#endif
#ifndef IOCSIZE_MASK
#define IOCSIZE_MASK (_IOC_SIZEMASK << _IOC_SIZESHIFT)
#endif
#ifndef IOCSIZE_SHIFT
#define IOCSIZE_SHIFT (_IOC_SIZESHIFT)
#endif
#ifndef DIV_ROUND_UP
#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
#endif
#ifndef BITS_PER_LONG
#define BITS_PER_LONG (32)
#endif
#ifndef BITS_PER_LONG_LONG
#define BITS_PER_LONG_LONG (32)
#endif
#ifndef BIT
#define BIT(nr) (1UL << (nr))
#endif
#ifndef BIT_ULL
#define BIT_ULL(nr) (1ULL << (nr))
#endif
#ifndef BIT_MASK
#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
#endif
#ifndef BIT_WORD
#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
#endif
#ifndef BIT_ULL_MASK
#define BIT_ULL_MASK(nr) (1ULL << ((nr) % BITS_PER_LONG_LONG))
#endif
#ifndef BIT_ULL_WORD
#define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG)
#endif
#ifndef BITS_PER_BYTE
#define BITS_PER_BYTE (8)
#endif
#ifndef BITS_TO_LONGS
#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
#endif
/* __ffs to find out the first exist 1 offset, from bit 0 ~ 31 */
#ifndef ffz
#define ffz(x) __ffs(~(x))
#endif
/* __builtin_constant_p is gcc build-in function to check the parameter is const or not */
#ifndef small_const_nbits
#define small_const_nbits(nbits) \
(__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG)
#endif
/**
* __ffs - find first bit in word.
* @word: The word to search
*
* Undefined if no bit exists, so code should check against 0 first.
*/
static inline unsigned long __ffs(unsigned long word)
{
int num = 0;
#if BITS_PER_LONG == 64
if ((word & 0xffffffff) == 0) {
num += 32;
word >>= 32;
}
#endif
if ((word & 0xffff) == 0) {
num += 16;
word >>= 16;
}
if ((word & 0xff) == 0) {
num += 8;
word >>= 8;
}
if ((word & 0xf) == 0) {
num += 4;
word >>= 4;
}
if ((word & 0x3) == 0) {
num += 2;
word >>= 2;
}
if ((word & 0x1) == 0)
num += 1;
return num;
}
/**
* __fls - find last (most-significant) set bit in a long word
* @word: the word to search
*
* Undefined if no set bit exists, so code should check against 0 first.
*/
static inline unsigned long __fls(unsigned long word)
{
int num = BITS_PER_LONG - 1;
#if BITS_PER_LONG == 64
if (!(word & (~0ul << 32))) {
num -= 32;
word <<= 32;
}
#endif
if (!(word & (~0ul << (BITS_PER_LONG-16)))) {
num -= 16;
word <<= 16;
}
if (!(word & (~0ul << (BITS_PER_LONG-8)))) {
num -= 8;
word <<= 8;
}
if (!(word & (~0ul << (BITS_PER_LONG-4)))) {
num -= 4;
word <<= 4;
}
if (!(word & (~0ul << (BITS_PER_LONG-2)))) {
num -= 2;
word <<= 2;
}
if (!(word & (~0ul << (BITS_PER_LONG-1))))
num -= 1;
return num;
}
/**
* test_bit - Determine whether a bit is set
* @nr: bit number to test
* @addr: Address to start counting from
*/
static inline int test_bit(int nr, const volatile unsigned long *addr)
{
return ((1UL << (nr & 31)) & (addr[nr >> 5])) != 0;
}
/*
* Find the first cleared bit in a memory region.
*/
static inline unsigned long find_first_zero_bit(
const unsigned long *addr, unsigned long size)
{
const unsigned long *p = addr;
unsigned long result = 0;
unsigned long tmp;
while (size & ~(BITS_PER_LONG-1)) {
if (~(tmp = *(p++)))
goto found;
result += BITS_PER_LONG;
size -= BITS_PER_LONG;
}
if (!size)
return result;
tmp = (*p) | (~0UL << size);
if (tmp == ~0UL) /* Are any bits zero? */
return result + size; /* Nope. */
found:
return result + ffz(tmp);
//tmp = 0;
//return result;
}
static inline unsigned long find_next_zero_bit(
const unsigned long *addr,unsigned long size, unsigned long offset)
{
const unsigned long *p = addr + BIT_WORD(offset); // offset位于p指向的long地址32位空?
unsigned long result = offset & ~(BITS_PER_LONG-1); // offset是第result?4字?
unsigned long tmp;
if (offset >= size)
return size;
size -= result; // ?整32位整倍?上
offset %= BITS_PER_LONG; // offset位于32位的第几位
if (offset) { // offset不在一?long?据的第0位上,在1-31位中[luther.gliethttp]
tmp = *(p++);
tmp |= ~0UL >> (BITS_PER_LONG - offset); // ?0-offset?据填充上1.
if (size < BITS_PER_LONG) // 不足32bits
goto found_first;
if (~tmp) // 取非非0?明含有0值
goto found_middle;
size -= BITS_PER_LONG; // 如果上面~tmp等于0,那么?明?*p?据?32位全1.[luther.gliethttp]
result += BITS_PER_LONG;
}
while (size & ~(BITS_PER_LONG-1)) { // 好了,?行到?里,我?的offset已??在4字?的第0位上,下面?行
if (~(tmp = *(p++))) // 4字?快速查?.如果~tmp非0,?明?32位?据中含有0?据,找到.[luther.gliethttp]
goto found_middle;
result += BITS_PER_LONG; // 到下一?4字?空?
size -= BITS_PER_LONG; // ?少4字??据
}
if (!size) // size等于0,?明首先size等于4字?整倍?,其次所有?据已?查完,
return result; // 所有?据全部?1,?有??0位,result等于size.[luther.gliethttp]
tmp = *p; // size不是32位整倍?,?剩几?bit?有?查,???行下面?查工作.[luther.gliethtp]
found_first:
tmp |= ~0UL << size; // ?在0-size?有效?据,size-31?未使用空?,所以先?size-31置成全1.
if (tmp == ~0UL) /* Are any bits zero? */ // 如果tmp全1,那么?明就?找找1?
return result + size; /* Nope. */ // result+size就等于函??入的??size大小.[luther.gliethttp]
found_middle:
return result + ffz(tmp); // 我?在32位?据的0-31中??必定存在0位值,?算他是第几位.[luther.gliethttp]
}
//int find_next_zero_bit(const void * p, int size, int offset);
//int find_first_bit(const unsigned long *p, unsigned size);
//int find_next_bit(const unsigned long *p, int size, int offset);
/**
* set_bit - Atomically set a bit in memory
* @nr: the bit to set
* @addr: the address to start counting from
*
* This function is atomic and may not be reordered. See __set_bit()
* if you do not require the atomic guarantees.
*
* Note: there are no guarantees that this function will not be reordered
* on non x86 architectures, so if you are writing portable code,
* make sure not to rely on its reordering guarantees.
*
* Note that @nr may be almost arbitrarily large; this function is not
* restricted to acting on a single-word quantity.
*/
static inline void set_bit(int nr, volatile unsigned long *addr)
{
unsigned long mask = BIT_MASK(nr);
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
unsigned long flags;
//taskENTER_CRITICAL();
_atomic_spin_lock_irqsave(p, flags);
*p |= mask;
_atomic_spin_unlock_irqrestore(p, flags);
//taskEXIT_CRITICAL();
}
/**
* clear_bit - Clears a bit in memory
* @nr: Bit to clear
* @addr: Address to start counting from
*
* clear_bit() is atomic and may not be reordered. However, it does
* not contain a memory barrier, so if it is used for locking purposes,
* you should call smp_mb__before_clear_bit() and/or smp_mb__after_clear_bit()
* in order to ensure changes are visible on other processors.
*/
static inline void clear_bit(int nr, volatile unsigned long *addr)
{
unsigned long mask = BIT_MASK(nr);
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
unsigned long flags;
_atomic_spin_lock_irqsave(p, flags);
//taskENTER_CRITICAL();
*p &= ~mask;
_atomic_spin_unlock_irqrestore(p, flags);
//taskEXIT_CRITICAL();
}
/**
* change_bit - Toggle a bit in memory
* @nr: Bit to change
* @addr: Address to start counting from
*
* change_bit() is atomic and may not be reordered. It may be
* reordered on other architectures than x86.
* Note that @nr may be almost arbitrarily large; this function is not
* restricted to acting on a single-word quantity.
*/
static inline void change_bit(int nr, volatile unsigned long *addr)
{
unsigned long mask = BIT_MASK(nr);
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
unsigned long flags;
//taskENTER_CRITICAL();
_atomic_spin_lock_irqsave(p, flags);
*p ^= mask;
_atomic_spin_unlock_irqrestore(p, flags);
//taskEXIT_CRITICAL();
}
/**
* test_and_set_bit - Set a bit and return its old value
* @nr: Bit to set
* @addr: Address to count from
*
* This operation is atomic and cannot be reordered.
* It may be reordered on other architectures than x86.
* It also implies a memory barrier.
*/
static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
{
unsigned long mask = BIT_MASK(nr);
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
unsigned long old;
//unsigned long flags;
//taskENTER_CRITICAL();
_atomic_spin_lock_irqsave(p, flags);
old = *p;
*p = old | mask;
_atomic_spin_unlock_irqrestore(p, flags);
//taskEXIT_CRITICAL();
return (old & mask) != 0;
}
/**
* test_and_clear_bit - Clear a bit and return its old value
* @nr: Bit to clear
* @addr: Address to count from
*
* This operation is atomic and cannot be reordered.
* It can be reorderdered on other architectures other than x86.
* It also implies a memory barrier.
*/
static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
{
unsigned long mask = BIT_MASK(nr);
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
unsigned long old;
unsigned long flags;
//taskENTER_CRITICAL();
_atomic_spin_lock_irqsave(p, flags);
old = *p;
*p = old & ~mask;
_atomic_spin_unlock_irqrestore(p, flags);
//taskEXIT_CRITICAL();
return (old & mask) != 0;
}
/**
* test_and_change_bit - Change a bit and return its old value
* @nr: Bit to change
* @addr: Address to count from
*
* This operation is atomic and cannot be reordered.
* It also implies a memory barrier.
*/
static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
{
unsigned long mask = BIT_MASK(nr);
unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
unsigned long old;
unsigned long flags;
_atomic_spin_lock_irqsave(p, flags);
old = *p;
*p = old ^ mask;
_atomic_spin_unlock_irqrestore(p, flags);
return (old & mask) != 0;
}
static inline int __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
const unsigned long *bitmap2, int bits)
{
int k;
int nr = BITS_TO_LONGS(bits);
unsigned long result = 0;
for (k = 0; k < nr; k++)
result |= (dst[k] = bitmap1[k] & ~bitmap2[k]);
return result != 0;
}
static inline int bitmap_andnot(unsigned long *dst, const unsigned long *src1,
const unsigned long *src2, int nbits)
{
// if (small_const_nbits(nbits))
// return (*dst = *src1 & ~(*src2)) != 0;
return __bitmap_andnot(dst, src1, src2, nbits);
}
static inline int atomic_inc_return(volatile atomic_t *v)
{
unsigned long flags;
int retval;
cris_atomic_save(v, flags);
retval = ++(v->counter);
cris_atomic_restore(v, flags);
return retval;
}
typedef __u16 __le16;
typedef __u16 __be16;
typedef __u32 __le32;
typedef __u32 __be32;
typedef __u64 __le64;
typedef __u64 __be64;
typedef __u16 __sum16;
typedef __u32 __wsum;
#ifndef __GFP_WAIT
#define __GFP_WAIT (0x10u)
#endif
#ifndef __GFP_HIGH
#define __GFP_HIGH (0x20u)
#endif
#ifndef __GFP_IO
#define __GFP_IO (0x40u)
#endif
#ifndef __GFP_FS
#define __GFP_FS (0x80u)
#endif
#ifndef GFP_NOIO
#define GFP_NOIO (0x10u)
#endif
#ifndef __GFP_NOWARN
#define __GFP_NOWARN (0x200u)
#endif
#ifndef GFP_KERNEL
#define GFP_KERNEL (__GFP_WAIT | __GFP_IO | __GFP_FS)
#endif
#ifndef copy_from_user
#define copy_from_user(to, from, sz) _memcpy((to), (from), (sz))
#endif
#ifndef copy_to_user
#define copy_to_user(to, from, sz) _memcpy((to), (from), (sz))
#endif
#if 0 /*comment since we are not using polling*/
/* These are specified by iBCS2 */
#ifndef POLLIN
#define POLLIN 0x0001
#endif
#ifndef POLLPRI
#define POLLPRI 0x0002
#endif
#ifndef POLLOUT
#define POLLOUT 0x0004
#endif
#ifndef POLLERR
#define POLLERR 0x0008
#endif
#ifndef POLLHUP
#define POLLHUP 0x0010
#endif
#ifndef POLLNVAL
#define POLLNVAL 0x0020
#endif
/* The rest seem to be more-or-less nonstandard. Check them! */
#ifndef POLLRDNORM
#define POLLRDNORM 0x0040
#endif
#ifndef POLLRDBAND
#define POLLRDBAND 0x0080
#endif
#ifndef POLLWRNORM
#define POLLWRNORM 0x0100
#endif
#ifndef POLLWRBAND
#define POLLWRBAND 0x0200
#endif
#ifndef POLLMSG
#define POLLMSG 0x0400
#endif
#ifndef POLLREMOVE
#define POLLREMOVE 0x1000
#endif
#ifndef POLLRDHUP
#define POLLRDHUP 0x2000
#endif
#ifndef POLLFREE
#define POLLFREE 0x4000 /* currently only for epoll */
#endif
#ifndef POLL_BUSY_LOOP
#define POLL_BUSY_LOOP 0x8000
#endif
#endif
struct __wait_queue_head {
_Sema lock;
struct list_head task_list;
};
typedef struct __wait_queue_head wait_queue_head_t;
static inline void __init_waitqueue_head(wait_queue_head_t *q)
{
//spin_lock_init(&q->lock);
RtlInitSema(&q->lock,0);
INIT_LIST_HEAD(&q->task_list);
}
#ifndef init_waitqueue_head
#define init_waitqueue_head(q) \
do { \
__init_waitqueue_head((q)); \
} while (0)
#endif
#ifndef DEFAULT_POLLMASK
#define DEFAULT_POLLMASK (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)
#endif
#endif /*_V4L2_OSDEP_H_*/

View file

@ -0,0 +1,700 @@
/*
V4L2 sub-device support header.
Copyright (C) 2008 Hans Verkuil <hverkuil@xs4all.nl>
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _V4L2_SUBDEV_H
#define _V4L2_SUBDEV_H
#if 0
#include <linux/types.h>
#endif
#include "v4l2-subdev.h"
#include "media-entity.h"
#include "v4l2-async.h"
#include "v4l2-common.h"
#include "v4l2-dev.h"
#include "v4l2-fh.h"
#include "v4l2-mediabus.h"
/* generic v4l2_device notify callback notification values */
#define V4L2_SUBDEV_IR_RX_NOTIFY _IOW('v', 0, u32)
#define V4L2_SUBDEV_IR_RX_FIFO_SERVICE_REQ 0x00000001
#define V4L2_SUBDEV_IR_RX_END_OF_RX_DETECTED 0x00000002
#define V4L2_SUBDEV_IR_RX_HW_FIFO_OVERRUN 0x00000004
#define V4L2_SUBDEV_IR_RX_SW_FIFO_OVERRUN 0x00000008
#define V4L2_SUBDEV_IR_TX_NOTIFY _IOW('v', 1, u32)
#define V4L2_SUBDEV_IR_TX_FIFO_SERVICE_REQ 0x00000001
struct v4l2_device;
struct v4l2_ctrl_handler;
struct v4l2_event_subscription;
struct v4l2_fh;
struct v4l2_subdev;
struct v4l2_subdev_fh;
//struct tuner_setup;
struct v4l2_mbus_frame_desc;
/* decode_vbi_line */
struct v4l2_decode_vbi_line {
u32 is_second_field; /* Set to 0 for the first (odd) field,
set to 1 for the second (even) field. */
u8 *p; /* Pointer to the sliced VBI data from the decoder.
On exit points to the start of the payload. */
u32 line; /* Line number of the sliced VBI data (1-23) */
u32 type; /* VBI service type (V4L2_SLICED_*). 0 if no service found */
};
/* Sub-devices are devices that are connected somehow to the main bridge
device. These devices are usually audio/video muxers/encoders/decoders or
sensors and webcam controllers.
Usually these devices are controlled through an i2c bus, but other busses
may also be used.
The v4l2_subdev struct provides a way of accessing these devices in a
generic manner. Most operations that these sub-devices support fall in
a few categories: core ops, audio ops, video ops and tuner ops.
More categories can be added if needed, although this should remain a
limited set (no more than approx. 8 categories).
Each category has its own set of ops that subdev drivers can implement.
A subdev driver can leave the pointer to the category ops NULL if
it does not implement them (e.g. an audio subdev will generally not
implement the video category ops). The exception is the core category:
this must always be present.
These ops are all used internally so it is no problem to change, remove
or add ops or move ops from one to another category. Currently these
ops are based on the original ioctls, but since ops are not limited to
one argument there is room for improvement here once all i2c subdev
drivers are converted to use these ops.
*/
/* Core ops: it is highly recommended to implement at least these ops:
log_status
g_register
s_register
This provides basic debugging support.
The ioctl ops is meant for generic ioctl-like commands. Depending on
the use-case it might be better to use subdev-specific ops (currently
not yet implemented) since ops provide proper type-checking.
*/
/* Subdevice external IO pin configuration */
#define V4L2_SUBDEV_IO_PIN_DISABLE (1 << 0) /* ENABLE assumed */
#define V4L2_SUBDEV_IO_PIN_OUTPUT (1 << 1)
#define V4L2_SUBDEV_IO_PIN_INPUT (1 << 2)
#define V4L2_SUBDEV_IO_PIN_SET_VALUE (1 << 3) /* Set output value */
#define V4L2_SUBDEV_IO_PIN_ACTIVE_LOW (1 << 4) /* ACTIVE HIGH assumed */
struct v4l2_subdev_io_pin_config {
u32 flags; /* V4L2_SUBDEV_IO_PIN_* flags for this pin's config */
u8 pin; /* Chip external IO pin to configure */
u8 function; /* Internal signal pad/function to route to IO pin */
u8 value; /* Initial value for pin - e.g. GPIO output value */
u8 strength; /* Pin drive strength */
};
/*
s_io_pin_config: configure one or more chip I/O pins for chips that
multiplex different internal signal pads out to IO pins. This function
takes a pointer to an array of 'n' pin configuration entries, one for
each pin being configured. This function could be called at times
other than just subdevice initialization.
init: initialize the sensor registers to some sort of reasonable default
values. Do not use for new drivers and should be removed in existing
drivers.
load_fw: load firmware.
reset: generic reset command. The argument selects which subsystems to
reset. Passing 0 will always reset the whole chip. Do not use for new
drivers without discussing this first on the linux-media mailinglist.
There should be no reason normally to reset a device.
s_gpio: set GPIO pins. Very simple right now, might need to be extended with
a direction argument if needed.
s_power: puts subdevice in power saving mode (on == 0) or normal operation
mode (on == 1).
interrupt_service_routine: Called by the bridge chip's interrupt service
handler, when an interrupt status has be raised due to this subdev,
so that this subdev can handle the details. It may schedule work to be
performed later. It must not sleep. *Called from an IRQ context*.
*/
struct v4l2_subdev_core_ops {
int (*log_status)(struct v4l2_subdev *sd);
int (*s_io_pin_config)(struct v4l2_subdev *sd, size_t n,
struct v4l2_subdev_io_pin_config *pincfg);
int (*init)(struct v4l2_subdev *sd, u32 val);
int (*load_fw)(struct v4l2_subdev *sd);
int (*reset)(struct v4l2_subdev *sd, u32 val);
int (*s_gpio)(struct v4l2_subdev *sd, u32 val);
int (*queryctrl)(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc);
int (*g_ctrl)(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
int (*s_ctrl)(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
int (*g_ext_ctrls)(struct v4l2_subdev *sd, struct v4l2_ext_controls *ctrls);
int (*s_ext_ctrls)(struct v4l2_subdev *sd, struct v4l2_ext_controls *ctrls);
int (*try_ext_ctrls)(struct v4l2_subdev *sd, struct v4l2_ext_controls *ctrls);
int (*querymenu)(struct v4l2_subdev *sd, struct v4l2_querymenu *qm);
int (*g_std)(struct v4l2_subdev *sd, v4l2_std_id *norm);
int (*s_std)(struct v4l2_subdev *sd, v4l2_std_id norm);
long (*ioctl)(struct v4l2_subdev *sd, unsigned int cmd, void *arg);
#ifdef CONFIG_VIDEO_ADV_DEBUG
int (*g_register)(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg);
int (*s_register)(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg);
#endif
int (*s_power)(struct v4l2_subdev *sd, int on);
int (*interrupt_service_routine)(struct v4l2_subdev *sd,
u32 status, bool *handled);
int (*subscribe_event)(struct v4l2_subdev *sd, struct v4l2_fh *fh,
struct v4l2_event_subscription *sub);
int (*unsubscribe_event)(struct v4l2_subdev *sd, struct v4l2_fh *fh,
struct v4l2_event_subscription *sub);
};
/* s_radio: v4l device was opened in radio mode.
g_frequency: freq->type must be filled in. Normally done by video_ioctl2
or the bridge driver.
g_tuner:
s_tuner: vt->type must be filled in. Normally done by video_ioctl2 or the
bridge driver.
s_type_addr: sets tuner type and its I2C addr.
s_config: sets tda9887 specific stuff, like port1, port2 and qss
*/
struct v4l2_subdev_tuner_ops {
int (*s_radio)(struct v4l2_subdev *sd);
int (*s_frequency)(struct v4l2_subdev *sd, const struct v4l2_frequency *freq);
int (*g_frequency)(struct v4l2_subdev *sd, struct v4l2_frequency *freq);
int (*g_tuner)(struct v4l2_subdev *sd, struct v4l2_tuner *vt);
int (*s_tuner)(struct v4l2_subdev *sd, const struct v4l2_tuner *vt);
int (*g_modulator)(struct v4l2_subdev *sd, struct v4l2_modulator *vm);
int (*s_modulator)(struct v4l2_subdev *sd, const struct v4l2_modulator *vm);
//edit by Ian
//int (*s_type_addr)(struct v4l2_subdev *sd, struct tuner_setup *type);
//int (*s_config)(struct v4l2_subdev *sd, const struct v4l2_priv_tun_config *config);
};
/* s_clock_freq: set the frequency (in Hz) of the audio clock output.
Used to slave an audio processor to the video decoder, ensuring that
audio and video remain synchronized. Usual values for the frequency
are 48000, 44100 or 32000 Hz. If the frequency is not supported, then
-EINVAL is returned.
s_i2s_clock_freq: sets I2S speed in bps. This is used to provide a standard
way to select I2S clock used by driving digital audio streams at some
board designs. Usual values for the frequency are 1024000 and 2048000.
If the frequency is not supported, then -EINVAL is returned.
s_routing: used to define the input and/or output pins of an audio chip,
and any additional configuration data.
Never attempt to use user-level input IDs (e.g. Composite, S-Video,
Tuner) at this level. An i2c device shouldn't know about whether an
input pin is connected to a Composite connector, become on another
board or platform it might be connected to something else entirely.
The calling driver is responsible for mapping a user-level input to
the right pins on the i2c device.
*/
struct v4l2_subdev_audio_ops {
int (*s_clock_freq)(struct v4l2_subdev *sd, u32 freq);
int (*s_i2s_clock_freq)(struct v4l2_subdev *sd, u32 freq);
int (*s_routing)(struct v4l2_subdev *sd, u32 input, u32 output, u32 config);
int (*s_stream)(struct v4l2_subdev *sd, int enable);
};
/* Indicates the @length field specifies maximum data length. */
#define V4L2_MBUS_FRAME_DESC_FL_LEN_MAX (1U << 0)
/* Indicates user defined data format, i.e. non standard frame format. */
#define V4L2_MBUS_FRAME_DESC_FL_BLOB (1U << 1)
/**
* struct v4l2_mbus_frame_desc_entry - media bus frame description structure
* @flags: V4L2_MBUS_FRAME_DESC_FL_* flags
* @pixelcode: media bus pixel code, valid if FRAME_DESC_FL_BLOB is not set
* @length: number of octets per frame, valid for compressed or unspecified
* formats
*/
struct v4l2_mbus_frame_desc_entry {
u16 flags;
u32 pixelcode;
u32 length;
};
#define V4L2_FRAME_DESC_ENTRY_MAX 4
/**
* struct v4l2_mbus_frame_desc - media bus data frame description
* @entry: frame descriptors array
* @num_entries: number of entries in @entry array
*/
struct v4l2_mbus_frame_desc {
struct v4l2_mbus_frame_desc_entry entry[V4L2_FRAME_DESC_ENTRY_MAX];
unsigned short num_entries;
};
/*
s_std_output: set v4l2_std_id for video OUTPUT devices. This is ignored by
video input devices.
g_std_output: get current standard for video OUTPUT devices. This is ignored
by video input devices.
g_tvnorms_output: get v4l2_std_id with all standards supported by video
OUTPUT device. This is ignored by video input devices.
s_crystal_freq: sets the frequency of the crystal used to generate the
clocks in Hz. An extra flags field allows device specific configuration
regarding clock frequency dividers, etc. If not used, then set flags
to 0. If the frequency is not supported, then -EINVAL is returned.
g_input_status: get input status. Same as the status field in the v4l2_input
struct.
s_routing: see s_routing in audio_ops, except this version is for video
devices.
s_dv_timings(): Set custom dv timings in the sub device. This is used
when sub device is capable of setting detailed timing information
in the hardware to generate/detect the video signal.
g_dv_timings(): Get custom dv timings in the sub device.
enum_mbus_fmt: enumerate pixel formats, provided by a video data source
g_mbus_fmt: get the current pixel format, provided by a video data source
try_mbus_fmt: try to set a pixel format on a video data source
s_mbus_fmt: set a pixel format on a video data source
g_mbus_config: get supported mediabus configurations
s_mbus_config: set a certain mediabus configuration. This operation is added
for compatibility with soc-camera drivers and should not be used by new
software.
s_rx_buffer: set a host allocated memory buffer for the subdev. The subdev
can adjust @size to a lower value and must not write more data to the
buffer starting at @data than the original value of @size.
*/
struct v4l2_subdev_video_ops {
int (*s_routing)(struct v4l2_subdev *sd, u32 input, u32 output, u32 config);
int (*s_crystal_freq)(struct v4l2_subdev *sd, u32 freq, u32 flags);
int (*s_std_output)(struct v4l2_subdev *sd, v4l2_std_id std);
int (*g_std_output)(struct v4l2_subdev *sd, v4l2_std_id *std);
int (*querystd)(struct v4l2_subdev *sd, v4l2_std_id *std);
int (*g_tvnorms_output)(struct v4l2_subdev *sd, v4l2_std_id *std);
int (*g_input_status)(struct v4l2_subdev *sd, u32 *status);
int (*s_stream)(struct v4l2_subdev *sd, int enable);
int (*cropcap)(struct v4l2_subdev *sd, struct v4l2_cropcap *cc);
int (*g_crop)(struct v4l2_subdev *sd, struct v4l2_crop *crop);
int (*s_crop)(struct v4l2_subdev *sd, const struct v4l2_crop *crop);
int (*g_parm)(struct v4l2_subdev *sd, struct v4l2_streamparm *param);
int (*s_parm)(struct v4l2_subdev *sd, struct v4l2_streamparm *param);
// edit by Ian
#if 0
int (*g_frame_interval)(struct v4l2_subdev *sd,
struct v4l2_subdev_frame_interval *interval);
int (*s_frame_interval)(struct v4l2_subdev *sd,
struct v4l2_subdev_frame_interval *interval);
#endif
int (*enum_framesizes)(struct v4l2_subdev *sd, struct v4l2_frmsizeenum *fsize);
int (*enum_frameintervals)(struct v4l2_subdev *sd, struct v4l2_frmivalenum *fival);
int (*s_dv_timings)(struct v4l2_subdev *sd,
struct v4l2_dv_timings *timings);
int (*g_dv_timings)(struct v4l2_subdev *sd,
struct v4l2_dv_timings *timings);
int (*enum_dv_timings)(struct v4l2_subdev *sd,
struct v4l2_enum_dv_timings *timings);
int (*query_dv_timings)(struct v4l2_subdev *sd,
struct v4l2_dv_timings *timings);
int (*dv_timings_cap)(struct v4l2_subdev *sd,
struct v4l2_dv_timings_cap *cap);
#if 0
int (*enum_mbus_fmt)(struct v4l2_subdev *sd, unsigned int index,
enum v4l2_mbus_pixelcode *code);
int (*enum_mbus_fsizes)(struct v4l2_subdev *sd,
struct v4l2_frmsizeenum *fsize);
int (*g_mbus_fmt)(struct v4l2_subdev *sd,
struct v4l2_mbus_framefmt *fmt);
int (*try_mbus_fmt)(struct v4l2_subdev *sd,
struct v4l2_mbus_framefmt *fmt);
int (*s_mbus_fmt)(struct v4l2_subdev *sd,
struct v4l2_mbus_framefmt *fmt);
int (*g_mbus_config)(struct v4l2_subdev *sd,
struct v4l2_mbus_config *cfg);
int (*s_mbus_config)(struct v4l2_subdev *sd,
const struct v4l2_mbus_config *cfg);
#endif
int (*s_rx_buffer)(struct v4l2_subdev *sd, void *buf,
unsigned int *size);
};
/*
decode_vbi_line: video decoders that support sliced VBI need to implement
this ioctl. Field p of the v4l2_sliced_vbi_line struct is set to the
start of the VBI data that was generated by the decoder. The driver
then parses the sliced VBI data and sets the other fields in the
struct accordingly. The pointer p is updated to point to the start of
the payload which can be copied verbatim into the data field of the
v4l2_sliced_vbi_data struct. If no valid VBI data was found, then the
type field is set to 0 on return.
s_vbi_data: used to generate VBI signals on a video signal.
v4l2_sliced_vbi_data is filled with the data packets that should be
output. Note that if you set the line field to 0, then that VBI signal
is disabled. If no valid VBI data was found, then the type field is
set to 0 on return.
g_vbi_data: used to obtain the sliced VBI packet from a readback register.
Not all video decoders support this. If no data is available because
the readback register contains invalid or erroneous data -EIO is
returned. Note that you must fill in the 'id' member and the 'field'
member (to determine whether CC data from the first or second field
should be obtained).
s_raw_fmt: setup the video encoder/decoder for raw VBI.
g_sliced_fmt: retrieve the current sliced VBI settings.
s_sliced_fmt: setup the sliced VBI settings.
*/
struct v4l2_subdev_vbi_ops {
int (*decode_vbi_line)(struct v4l2_subdev *sd, struct v4l2_decode_vbi_line *vbi_line);
int (*s_vbi_data)(struct v4l2_subdev *sd, const struct v4l2_sliced_vbi_data *vbi_data);
int (*g_vbi_data)(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_data *vbi_data);
int (*g_sliced_vbi_cap)(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_cap *cap);
int (*s_raw_fmt)(struct v4l2_subdev *sd, struct v4l2_vbi_format *fmt);
int (*g_sliced_fmt)(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *fmt);
int (*s_sliced_fmt)(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *fmt);
};
/**
* struct v4l2_subdev_sensor_ops - v4l2-subdev sensor operations
* @g_skip_top_lines: number of lines at the top of the image to be skipped.
* This is needed for some sensors, which always corrupt
* several top lines of the output image, or which send their
* metadata in them.
* @g_skip_frames: number of frames to skip at stream start. This is needed for
* buggy sensors that generate faulty frames when they are
* turned on.
*/
struct v4l2_subdev_sensor_ops {
int (*g_skip_top_lines)(struct v4l2_subdev *sd, u32 *lines);
int (*g_skip_frames)(struct v4l2_subdev *sd, u32 *frames);
};
/*
[rt]x_g_parameters: Get the current operating parameters and state of the
the IR receiver or transmitter.
[rt]x_s_parameters: Set the current operating parameters and state of the
the IR receiver or transmitter. It is recommended to call
[rt]x_g_parameters first to fill out the current state, and only change
the fields that need to be changed. Upon return, the actual device
operating parameters and state will be returned. Note that hardware
limitations may prevent the actual settings from matching the requested
settings - e.g. an actual carrier setting of 35,904 Hz when 36,000 Hz
was requested. An exception is when the shutdown parameter is true.
The last used operational parameters will be returned, but the actual
state of the hardware be different to minimize power consumption and
processing when shutdown is true.
rx_read: Reads received codes or pulse width data.
The semantics are similar to a non-blocking read() call.
tx_write: Writes codes or pulse width data for transmission.
The semantics are similar to a non-blocking write() call.
*/
enum v4l2_subdev_ir_mode {
V4L2_SUBDEV_IR_MODE_PULSE_WIDTH, /* uses struct ir_raw_event records */
};
struct v4l2_subdev_ir_parameters {
/* Either Rx or Tx */
unsigned int bytes_per_data_element; /* of data in read or write call */
enum v4l2_subdev_ir_mode mode;
bool enable;
bool interrupt_enable;
bool shutdown; /* true: set hardware to low/no power, false: normal */
bool modulation; /* true: uses carrier, false: baseband */
u32 max_pulse_width; /* ns, valid only for baseband signal */
unsigned int carrier_freq; /* Hz, valid only for modulated signal*/
unsigned int duty_cycle; /* percent, valid only for modulated signal*/
bool invert_level; /* invert signal level */
/* Tx only */
bool invert_carrier_sense; /* Send 0/space as a carrier burst */
/* Rx only */
u32 noise_filter_min_width; /* ns, min time of a valid pulse */
unsigned int carrier_range_lower; /* Hz, valid only for modulated sig */
unsigned int carrier_range_upper; /* Hz, valid only for modulated sig */
u32 resolution; /* ns */
};
struct v4l2_subdev_ir_ops {
/* Receiver */
int (*rx_read)(struct v4l2_subdev *sd, u8 *buf, size_t count,
ssize_t *num);
int (*rx_g_parameters)(struct v4l2_subdev *sd,
struct v4l2_subdev_ir_parameters *params);
int (*rx_s_parameters)(struct v4l2_subdev *sd,
struct v4l2_subdev_ir_parameters *params);
/* Transmitter */
int (*tx_write)(struct v4l2_subdev *sd, u8 *buf, size_t count,
ssize_t *num);
int (*tx_g_parameters)(struct v4l2_subdev *sd,
struct v4l2_subdev_ir_parameters *params);
int (*tx_s_parameters)(struct v4l2_subdev *sd,
struct v4l2_subdev_ir_parameters *params);
};
/**
* struct v4l2_subdev_pad_ops - v4l2-subdev pad level operations
* @get_frame_desc: get the current low level media bus frame parameters.
* @get_frame_desc: set the low level media bus frame parameters, @fd array
* may be adjusted by the subdev driver to device capabilities.
*/
struct v4l2_subdev_pad_ops {
#if 0
int (*enum_mbus_code)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
struct v4l2_subdev_mbus_code_enum *code);
int (*enum_frame_size)(struct v4l2_subdev *sd,
struct v4l2_subdev_fh *fh,
struct v4l2_subdev_frame_size_enum *fse);
int (*enum_frame_interval)(struct v4l2_subdev *sd,
struct v4l2_subdev_fh *fh,
struct v4l2_subdev_frame_interval_enum *fie);
int (*get_fmt)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
struct v4l2_subdev_format *format);
int (*set_fmt)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
struct v4l2_subdev_format *format);
int (*set_crop)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
struct v4l2_subdev_crop *crop);
int (*get_crop)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
struct v4l2_subdev_crop *crop);
int (*get_selection)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
struct v4l2_subdev_selection *sel);
int (*set_selection)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
struct v4l2_subdev_selection *sel);
int (*get_edid)(struct v4l2_subdev *sd, struct v4l2_subdev_edid *edid);
int (*set_edid)(struct v4l2_subdev *sd, struct v4l2_subdev_edid *edid);
#ifdef CONFIG_MEDIA_CONTROLLER
int (*link_validate)(struct v4l2_subdev *sd, struct media_link *link,
struct v4l2_subdev_format *source_fmt,
struct v4l2_subdev_format *sink_fmt);
#endif /* CONFIG_MEDIA_CONTROLLER */
#endif
int (*get_frame_desc)(struct v4l2_subdev *sd, unsigned int pad,
struct v4l2_mbus_frame_desc *fd);
int (*set_frame_desc)(struct v4l2_subdev *sd, unsigned int pad,
struct v4l2_mbus_frame_desc *fd);
};
struct v4l2_subdev_ops {
const struct v4l2_subdev_core_ops *core;
const struct v4l2_subdev_tuner_ops *tuner;
const struct v4l2_subdev_audio_ops *audio;
const struct v4l2_subdev_video_ops *video;
const struct v4l2_subdev_vbi_ops *vbi;
const struct v4l2_subdev_ir_ops *ir;
const struct v4l2_subdev_sensor_ops *sensor;
const struct v4l2_subdev_pad_ops *pad;
};
/*
* Internal ops. Never call this from drivers, only the v4l2 framework can call
* these ops.
*
* registered: called when this subdev is registered. When called the v4l2_dev
* field is set to the correct v4l2_device.
*
* unregistered: called when this subdev is unregistered. When called the
* v4l2_dev field is still set to the correct v4l2_device.
*
* open: called when the subdev device node is opened by an application.
*
* close: called when the subdev device node is closed.
*/
struct v4l2_subdev_internal_ops {
int (*registered)(struct v4l2_subdev *sd);
void (*unregistered)(struct v4l2_subdev *sd);
int (*open)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh);
int (*close)(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh);
};
#define V4L2_SUBDEV_NAME_SIZE 32
/* Set this flag if this subdev is a i2c device. */
#define V4L2_SUBDEV_FL_IS_I2C (1U << 0)
/* Set this flag if this subdev is a spi device. */
#define V4L2_SUBDEV_FL_IS_SPI (1U << 1)
/* Set this flag if this subdev needs a device node. */
#define V4L2_SUBDEV_FL_HAS_DEVNODE (1U << 2)
/* Set this flag if this subdev generates events. */
#define V4L2_SUBDEV_FL_HAS_EVENTS (1U << 3)
/* Each instance of a subdev driver should create this struct, either
stand-alone or embedded in a larger struct.
*/
struct v4l2_subdev {
#if defined(CONFIG_MEDIA_CONTROLLER)
struct media_entity entity;
#endif
struct list_head list;
//struct module *owner;
u32 flags;
struct v4l2_device *v4l2_dev;
const struct v4l2_subdev_ops *ops;
/* Never call these internal ops from within a sub_dev driver! */
const struct v4l2_subdev_internal_ops *internal_ops;
/* The control handler of this subdev. May be NULL. */
struct v4l2_ctrl_handler *ctrl_handler;
/* name must be unique */
char name[V4L2_SUBDEV_NAME_SIZE];
/* can be used to group similar subdevs, value is driver-specific */
u32 grp_id;
/* pointer to private data */
void *dev_priv;
void *host_priv;
/* subdev device node */
struct video_device *devnode;
/* pointer to the physical device, if any */
//struct device *dev;
const char *dev_init_name; /* initial name of the device */
void *dev_prive_date;
/* Links this subdev to a global subdev_list or @notifier->done list. */
struct list_head async_list;
/* Pointer to respective struct v4l2_async_subdev. */
struct v4l2_async_subdev *asd;
/* Pointer to the managing notifier. */
struct v4l2_async_notifier *notifier;
};
#define media_entity_to_v4l2_subdev(ent) \
container_of(ent, struct v4l2_subdev, entity)
#define vdev_to_v4l2_subdev(vdev) \
((struct v4l2_subdev *)video_get_drvdata(vdev))
/*
* Used for storing subdev information per file handle
*/
struct v4l2_subdev_fh {
struct v4l2_fh vfh;
#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
struct {
struct v4l2_mbus_framefmt try_fmt;
struct v4l2_rect try_crop;
struct v4l2_rect try_compose;
} *pad;
#endif
};
#define to_v4l2_subdev_fh(fh) \
container_of(fh, struct v4l2_subdev_fh, vfh)
#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
#define __V4L2_SUBDEV_MK_GET_TRY(rtype, fun_name, field_name) \
static inline struct rtype * \
v4l2_subdev_get_try_##fun_name(struct v4l2_subdev_fh *fh, \
unsigned int pad) \
{ \
BUG_ON(unlikely(pad >= vdev_to_v4l2_subdev( \
fh->vfh.vdev)->entity.num_pads)); \
return &fh->pad[pad].field_name; \
}
__V4L2_SUBDEV_MK_GET_TRY(v4l2_mbus_framefmt, format, try_fmt)
__V4L2_SUBDEV_MK_GET_TRY(v4l2_rect, crop, try_compose)
__V4L2_SUBDEV_MK_GET_TRY(v4l2_rect, compose, try_compose)
#endif
extern const struct v4l2_file_operations v4l2_subdev_fops;
static inline void v4l2_set_subdevdata(struct v4l2_subdev *sd, void *p)
{
sd->dev_priv = p;
}
static inline void *v4l2_get_subdevdata(const struct v4l2_subdev *sd)
{
return sd->dev_priv;
}
static inline void v4l2_set_subdev_hostdata(struct v4l2_subdev *sd, void *p)
{
sd->host_priv = p;
}
static inline void *v4l2_get_subdev_hostdata(const struct v4l2_subdev *sd)
{
return sd->host_priv;
}
#ifdef CONFIG_MEDIA_CONTROLLER
int v4l2_subdev_link_validate_default(struct v4l2_subdev *sd,
struct media_link *link,
struct v4l2_subdev_format *source_fmt,
struct v4l2_subdev_format *sink_fmt);
int v4l2_subdev_link_validate(struct media_link *link);
#endif /* CONFIG_MEDIA_CONTROLLER */
void v4l2_subdev_init(struct v4l2_subdev *sd,
const struct v4l2_subdev_ops *ops);
/* Call an ops of a v4l2_subdev, doing the right checks against
NULL pointers.
Example: err = v4l2_subdev_call(sd, core, s_std, norm);
*/
#define v4l2_subdev_call(sd, o, f, args...) \
(!(sd) ? -ENODEV : (((sd)->ops->o && (sd)->ops->o->f) ? \
(sd)->ops->o->f((sd) , ##args) : -ENOIOCTLCMD))
/* Send a notification to v4l2_device. */
#define v4l2_subdev_notify(sd, notification, arg) \
((!(sd) || !(sd)->v4l2_dev || !(sd)->v4l2_dev->notify) ? -ENODEV : \
(sd)->v4l2_dev->notify((sd), (notification), (arg)))
#define v4l2_subdev_has_op(sd, o, f) \
((sd)->ops->o && (sd)->ops->o->f)
#endif

View file

@ -0,0 +1,9 @@
#ifndef V4L2_DRIVER_H
#define V4L2_DRIVER_H /*structure needed for video caputure*/
#include <platform/platform_stdlib.h>
#include "dlist.h"
#include "basic_types.h"
#endif //V4L2_DRIVER_H

View file

@ -0,0 +1,24 @@
#ifndef _V4L2_INTF_H_
#define _V4L2_INTF_H_
#define VIDEO_NUM_DEVICES 4//should be aligned with value in v4l2-dev.c
typedef enum _streaming_state streaming_state;
enum _streaming_state {
STREAMING_OFF = 0,
STREAMING_ON = 1,
STREAMING_PAUSED = 2,
STREAMING_READY = 3,
};
long v4l_usr_ioctl(int fd, unsigned int cmd, void *arg);
int v4l_dev_open();
void v4l_dev_release();
void stop_capturing();
int start_capturing();
void uninit_v4l2_device ();
int init_v4l2_device ();
int v4l_set_param(u32 format_type, int *width, int *height, int *frame_rate, int *compression_ratio);
int v4l_getset_usb_ctrl(u8 bRequestType, u8 bRequest, u16 wValue, u16 wIndex, u16 wLength, void *data, int timeout, int set);
extern void spec_v4l2_probe();
#endif

View file

@ -0,0 +1,522 @@
/*
* videobuf2-core.h - V4L2 driver helper framework
*
* Copyright (C) 2010 Samsung Electronics
*
* Author: Pawel Osciak <pawel@osciak.com>
*
* 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.
*/
#ifndef _MEDIA_VIDEOBUF2_CORE_H
#define _MEDIA_VIDEOBUF2_CORE_H
#if 0
#include <linux/mm_types.h>
#include <linux/mutex.h>
#include <linux/poll.h>
#include <linux/videodev2.h>
#include <linux/dma-buf.h>
#endif
#include "v4l2-osdep.h"
#include "videodev2.h"
typedef int _LOCK_T;
struct vb2_alloc_ctx;
struct vb2_fileio_data;
/**
* struct vb2_mem_ops - memory handling/memory allocator operations
* @alloc: allocate video memory and, optionally, allocator private data,
* return NULL on failure or a pointer to allocator private,
* per-buffer data on success; the returned private structure
* will then be passed as buf_priv argument to other ops in this
* structure. Additional gfp_flags to use when allocating the
* are also passed to this operation. These flags are from the
* gfp_flags field of vb2_queue.
* @put: inform the allocator that the buffer will no longer be used;
* usually will result in the allocator freeing the buffer (if
* no other users of this buffer are present); the buf_priv
* argument is the allocator private per-buffer structure
* previously returned from the alloc callback
* @get_userptr: acquire userspace memory for a hardware operation; used for
* USERPTR memory types; vaddr is the address passed to the
* videobuf layer when queuing a video buffer of USERPTR type;
* should return an allocator private per-buffer structure
* associated with the buffer on success, NULL on failure;
* the returned private structure will then be passed as buf_priv
* argument to other ops in this structure
* @put_userptr: inform the allocator that a USERPTR buffer will no longer
* be used
* @attach_dmabuf: attach a shared struct dma_buf for a hardware operation;
* used for DMABUF memory types; alloc_ctx is the alloc context
* dbuf is the shared dma_buf; returns NULL on failure;
* allocator private per-buffer structure on success;
* this needs to be used for further accesses to the buffer
* @detach_dmabuf: inform the exporter of the buffer that the current DMABUF
* buffer is no longer used; the buf_priv argument is the
* allocator private per-buffer structure previously returned
* from the attach_dmabuf callback
* @map_dmabuf: request for access to the dmabuf from allocator; the allocator
* of dmabuf is informed that this driver is going to use the
* dmabuf
* @unmap_dmabuf: releases access control to the dmabuf - allocator is notified
* that this driver is done using the dmabuf for now
* @prepare: called every time the buffer is passed from userspace to the
* driver, useful for cache synchronisation, optional
* @finish: called every time the buffer is passed back from the driver
* to the userspace, also optional
* @vaddr: return a kernel virtual address to a given memory buffer
* associated with the passed private structure or NULL if no
* such mapping exists
* @cookie: return allocator specific cookie for a given memory buffer
* associated with the passed private structure or NULL if not
* available
* @num_users: return the current number of users of a memory buffer;
* return 1 if the videobuf layer (or actually the driver using
* it) is the only user
* @mmap: setup a userspace mapping for a given memory buffer under
* the provided virtual memory region
*
* Required ops for USERPTR types: get_userptr, put_userptr.
* Required ops for MMAP types: alloc, put, num_users, mmap.
* Required ops for read/write access types: alloc, put, num_users, vaddr
* Required ops for DMABUF types: attach_dmabuf, detach_dmabuf, map_dmabuf,
* unmap_dmabuf.
*/
struct vb2_mem_ops {
void *(*alloc)(void *alloc_ctx, unsigned long size, gfp_t gfp_flags);
void (*put)(void *buf_priv);
struct dma_buf *(*get_dmabuf)(void *buf_priv);
void *(*get_userptr)(void *alloc_ctx, unsigned long vaddr,
unsigned long size, int write);
void (*put_userptr)(void *buf_priv);
void (*prepare)(void *buf_priv);
void (*finish)(void *buf_priv);
void *(*attach_dmabuf)(void *alloc_ctx, struct dma_buf *dbuf,
unsigned long size, int write);
void (*detach_dmabuf)(void *buf_priv);
int (*map_dmabuf)(void *buf_priv);
void (*unmap_dmabuf)(void *buf_priv);
void *(*vaddr)(void *buf_priv);
void *(*cookie)(void *buf_priv);
unsigned int (*num_users)(void *buf_priv);
int (*mmap)(void *buf_priv);
};
struct vb2_plane {
void *mem_priv;
struct dma_buf *dbuf;
unsigned int dbuf_mapped;
};
/**
* enum vb2_io_modes - queue access methods
* @VB2_MMAP: driver supports MMAP with streaming API
* @VB2_USERPTR: driver supports USERPTR with streaming API
* @VB2_READ: driver supports read() style access
* @VB2_WRITE: driver supports write() style access
* @VB2_DMABUF: driver supports DMABUF with streaming API
*/
enum vb2_io_modes {
VB2_MMAP = (1 << 0),
VB2_USERPTR = (1 << 1),
VB2_READ = (1 << 2),
VB2_WRITE = (1 << 3),
VB2_DMABUF = (1 << 4),
};
/**
* enum vb2_fileio_flags - flags for selecting a mode of the file io emulator,
* by default the 'streaming' style is used by the file io emulator
* @VB2_FILEIO_READ_ONCE: report EOF after reading the first buffer
* @VB2_FILEIO_WRITE_IMMEDIATELY: queue buffer after each write() call
*/
enum vb2_fileio_flags {
VB2_FILEIO_READ_ONCE = (1 << 0),
VB2_FILEIO_WRITE_IMMEDIATELY = (1 << 1),
};
/**
* enum vb2_buffer_state - current video buffer state
* @VB2_BUF_STATE_DEQUEUED: buffer under userspace control
* @VB2_BUF_STATE_PREPARED: buffer prepared in videobuf and by the driver
* @VB2_BUF_STATE_QUEUED: buffer queued in videobuf, but not in driver
* @VB2_BUF_STATE_ACTIVE: buffer queued in driver and possibly used
* in a hardware operation
* @VB2_BUF_STATE_DONE: buffer returned from driver to videobuf, but
* not yet dequeued to userspace
* @VB2_BUF_STATE_ERROR: same as above, but the operation on the buffer
* has ended with an error, which will be reported
* to the userspace when it is dequeued
*/
enum vb2_buffer_state {
VB2_BUF_STATE_DEQUEUED,
VB2_BUF_STATE_PREPARED,
VB2_BUF_STATE_QUEUED,
VB2_BUF_STATE_ACTIVE,
VB2_BUF_STATE_DONE,
VB2_BUF_STATE_ERROR,
};
struct vb2_queue;
/**
* struct vb2_buffer - represents a video buffer
* @v4l2_buf: struct v4l2_buffer associated with this buffer; can
* be read by the driver and relevant entries can be
* changed by the driver in case of CAPTURE types
* (such as timestamp)
* @v4l2_planes: struct v4l2_planes associated with this buffer; can
* be read by the driver and relevant entries can be
* changed by the driver in case of CAPTURE types
* (such as bytesused); NOTE that even for single-planar
* types, the v4l2_planes[0] struct should be used
* instead of v4l2_buf for filling bytesused - drivers
* should use the vb2_set_plane_payload() function for that
* @vb2_queue: the queue to which this driver belongs
* @num_planes: number of planes in the buffer
* on an internal driver queue
* @state: current buffer state; do not change
* @queued_entry: entry on the queued buffers list, which holds all
* buffers queued from userspace
* @done_entry: entry on the list that stores all buffers ready to
* be dequeued to userspace
* @planes: private per-plane information; do not change
*/
struct vb2_buffer {
struct v4l2_buffer v4l2_buf;
struct v4l2_plane v4l2_planes[VIDEO_MAX_PLANES];
struct vb2_queue *vb2_queue;
unsigned int num_planes;
/* Private: internal use only */
enum vb2_buffer_state state;
struct list_head queued_entry;
struct list_head done_entry;
struct vb2_plane planes[VIDEO_MAX_PLANES];
};
/**
* struct vb2_ops - driver-specific callbacks
*
* @queue_setup: called from VIDIOC_REQBUFS and VIDIOC_CREATE_BUFS
* handlers before memory allocation, or, if
* *num_planes != 0, after the allocation to verify a
* smaller number of buffers. Driver should return
* the required number of buffers in *num_buffers, the
* required number of planes per buffer in *num_planes; the
* size of each plane should be set in the sizes[] array
* and optional per-plane allocator specific context in the
* alloc_ctxs[] array. When called from VIDIOC_REQBUFS,
* fmt == NULL, the driver has to use the currently
* configured format and *num_buffers is the total number
* of buffers, that are being allocated. When called from
* VIDIOC_CREATE_BUFS, fmt != NULL and it describes the
* target frame format (if the format isn't valid the
* callback must return -EINVAL). In this case *num_buffers
* are being allocated additionally to q->num_buffers.
* @wait_prepare: release any locks taken while calling vb2 functions;
* it is called before an ioctl needs to wait for a new
* buffer to arrive; required to avoid a deadlock in
* blocking access type
* @wait_finish: reacquire all locks released in the previous callback;
* required to continue operation after sleeping while
* waiting for a new buffer to arrive
* @buf_init: called once after allocating a buffer (in MMAP case)
* or after acquiring a new USERPTR buffer; drivers may
* perform additional buffer-related initialization;
* initialization failure (return != 0) will prevent
* queue setup from completing successfully; optional
* @buf_prepare: called every time the buffer is queued from userspace
* and from the VIDIOC_PREPARE_BUF ioctl; drivers may
* perform any initialization required before each hardware
* operation in this callback; drivers that support
* VIDIOC_CREATE_BUFS must also validate the buffer size;
* if an error is returned, the buffer will not be queued
* in driver; optional
* @buf_finish: called before every dequeue of the buffer back to
* userspace; drivers may perform any operations required
* before userspace accesses the buffer; optional
* @buf_cleanup: called once before the buffer is freed; drivers may
* perform any additional cleanup; optional
* @start_streaming: called once to enter 'streaming' state; the driver may
* receive buffers with @buf_queue callback before
* @start_streaming is called; the driver gets the number
* of already queued buffers in count parameter; driver
* can return an error if hardware fails or not enough
* buffers has been queued, in such case all buffers that
* have been already given by the @buf_queue callback are
* invalidated.
* @stop_streaming: called when 'streaming' state must be disabled; driver
* should stop any DMA transactions or wait until they
* finish and give back all buffers it got from buf_queue()
* callback; may use vb2_wait_for_all_buffers() function
* @buf_queue: passes buffer vb to the driver; driver may start
* hardware operation on this buffer; driver should give
* the buffer back by calling vb2_buffer_done() function;
* it is allways called after calling STREAMON ioctl;
* might be called before start_streaming callback if user
* pre-queued buffers before calling STREAMON
*/
struct vb2_ops {
int (*queue_setup)(struct vb2_queue *q, const struct v4l2_format *fmt,
unsigned int *num_buffers, unsigned int *num_planes,
unsigned int sizes[], void *alloc_ctxs[]);
void (*wait_prepare)(struct vb2_queue *q);
void (*wait_finish)(struct vb2_queue *q);
int (*buf_init)(struct vb2_buffer *vb);
//int (*buf_prepare)(struct vb2_buffer *vb);
int (*buf_prepare)(struct vb2_buffer *vb, unsigned int index);
int (*buf_finish)(struct vb2_buffer *vb);
void (*buf_cleanup)(struct vb2_buffer *vb);
int (*start_streaming)(struct vb2_queue *q, unsigned int count);
int (*stop_streaming)(struct vb2_queue *q);
void (*buf_queue)(struct vb2_buffer *vb);
};
struct v4l2_fh;
/**
* struct vb2_queue - a videobuf queue
*
* @type: queue type (see V4L2_BUF_TYPE_* in linux/videodev2.h
* @io_modes: supported io methods (see vb2_io_modes enum)
* @io_flags: additional io flags (see vb2_fileio_flags enum)
* @lock: pointer to a mutex that protects the vb2_queue struct. The
* driver can set this to a mutex to let the v4l2 core serialize
* the queuing ioctls. If the driver wants to handle locking
* itself, then this should be set to NULL. This lock is not used
* by the videobuf2 core API.
* @owner: The filehandle that 'owns' the buffers, i.e. the filehandle
* that called reqbufs, create_buffers or started fileio.
* This field is not used by the videobuf2 core API, but it allows
* drivers to easily associate an owner filehandle with the queue.
* @ops: driver-specific callbacks
* @mem_ops: memory allocator specific callbacks
* @drv_priv: driver private data
* @buf_struct_size: size of the driver-specific buffer structure;
* "0" indicates the driver doesn't want to use a custom buffer
* structure type, so sizeof(struct vb2_buffer) will is used
* @gfp_flags: additional gfp flags used when allocating the buffers.
* Typically this is 0, but it may be e.g. GFP_DMA or __GFP_DMA32
* to force the buffer allocation to a specific memory zone.
*
* @memory: current memory type used
* @bufs: videobuf buffer structures
* @num_buffers: number of allocated/used buffers
* @queued_list: list of buffers currently queued from userspace
* @queued_count: number of buffers owned by the driver
* @done_list: list of buffers ready to be dequeued to userspace
* @done_lock: lock to protect done_list list
* @done_wq: waitqueue for processes waiting for buffers ready to be dequeued
* @alloc_ctx: memory type/allocator-specific contexts for each plane
* @streaming: current streaming state
* @fileio: file io emulator internal data, used only if emulator is active
*/
struct vb2_queue {
enum v4l2_buf_type type;
unsigned int io_modes;
unsigned int io_flags;
//struct mutex *lock;
_Mutex *lock;
struct v4l2_fh *owner;
const struct vb2_ops *ops;
const struct vb2_mem_ops *mem_ops;
void *drv_priv;
unsigned int buf_struct_size;
u32 timestamp_type;
gfp_t gfp_flags;
/* private: internal use only */
enum v4l2_memory memory;
struct vb2_buffer *bufs[VIDEO_MAX_FRAME];
unsigned int num_buffers;
struct list_head queued_list;
atomic_t queued_count;
struct list_head done_list;
//spinlock_t done_lock;
//_LOCK_T done_lock;
_Mutex done_lock;
//wait_queue_head_t done_wq;
_Sema done_wq; //counting semaphore
void *alloc_ctx[VIDEO_MAX_PLANES];
unsigned int plane_sizes[VIDEO_MAX_PLANES];
//unsigned int streaming:1;
unsigned int streaming;
//unsigned int start_streaming_called;//added by Ian
struct vb2_fileio_data *fileio;
};
void *vb2_plane_vaddr(struct vb2_buffer *vb, unsigned int plane_no);
void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int plane_no);
void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state);
int vb2_wait_for_all_buffers(struct vb2_queue *q);
int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b);
int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req);
int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create);
int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b);
int vb2_queue_init(struct vb2_queue *q);
void vb2_queue_release(struct vb2_queue *q);
int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b);
int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb);
int vb2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking);
int vb2_streamon(struct vb2_queue *q, enum v4l2_buf_type type);
int vb2_streamoff(struct vb2_queue *q, enum v4l2_buf_type type);
int vb2_mmap(struct vb2_queue *q);
#ifndef CONFIG_MMU
unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
unsigned long addr,
unsigned long len,
unsigned long pgoff,
unsigned long flags);
#endif
#if 0
unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait);
size_t vb2_read(struct vb2_queue *q, char __user *data, size_t count,
loff_t *ppos, int nonblock);
size_t vb2_write(struct vb2_queue *q, char __user *data, size_t count,
loff_t *ppos, int nonblock);
#endif
/**
* vb2_is_streaming() - return streaming status of the queue
* @q: videobuf queue
*/
static inline bool vb2_is_streaming(struct vb2_queue *q)
{
return q->streaming;
}
/**
* vb2_is_busy() - return busy status of the queue
* @q: videobuf queue
*
* This function checks if queue has any buffers allocated.
*/
static inline bool vb2_is_busy(struct vb2_queue *q)
{
return (q->num_buffers > 0);
}
/**
* vb2_get_drv_priv() - return driver private data associated with the queue
* @q: videobuf queue
*/
static inline void *vb2_get_drv_priv(struct vb2_queue *q)
{
return q->drv_priv;
}
/**
* vb2_set_plane_payload() - set bytesused for the plane plane_no
* @vb: buffer for which plane payload should be set
* @plane_no: plane number for which payload should be set
* @size: payload in bytes
*/
static inline void vb2_set_plane_payload(struct vb2_buffer *vb,
unsigned int plane_no, unsigned long size)
{
if (plane_no < vb->num_planes)
vb->v4l2_planes[plane_no].bytesused = size;
}
/**
* vb2_get_plane_payload() - get bytesused for the plane plane_no
* @vb: buffer for which plane payload should be set
* @plane_no: plane number for which payload should be set
* @size: payload in bytes
*/
static inline unsigned long vb2_get_plane_payload(struct vb2_buffer *vb,
unsigned int plane_no)
{
if (plane_no < vb->num_planes)
return vb->v4l2_planes[plane_no].bytesused;
return 0;
}
/**
* vb2_plane_size() - return plane size in bytes
* @vb: buffer for which plane size should be returned
* @plane_no: plane number for which size should be returned
*/
static inline unsigned long
vb2_plane_size(struct vb2_buffer *vb, unsigned int plane_no)
{
if (plane_no < vb->num_planes)
return vb->v4l2_planes[plane_no].length;
return 0;
}
/*
* The following functions are not part of the vb2 core API, but are simple
* helper functions that you can use in your struct v4l2_file_operations,
* struct v4l2_ioctl_ops and struct vb2_ops. They will serialize if vb2_queue->lock
* or video_device->lock is set, and they will set and test vb2_queue->owner
* to check if the calling filehandle is permitted to do the queuing operation.
*/
/* struct v4l2_ioctl_ops helpers */
int vb2_ioctl_reqbufs(void *priv, struct v4l2_requestbuffers *p);
int vb2_ioctl_create_bufs(void *priv, struct v4l2_create_buffers *p);
int vb2_ioctl_prepare_buf(void *priv, struct v4l2_buffer *p);
int vb2_ioctl_querybuf(void *priv, struct v4l2_buffer *p);
int vb2_ioctl_qbuf(void *priv, struct v4l2_buffer *p);
int vb2_ioctl_dqbuf(void *priv, struct v4l2_buffer *p);
int vb2_ioctl_streamon(void *priv, enum v4l2_buf_type i);
int vb2_ioctl_streamoff(void *priv, enum v4l2_buf_type i);
int vb2_ioctl_expbuf(void *priv, struct v4l2_exportbuffer *p);
/* struct v4l2_file_operations helpers */
int vb2_fop_mmap();
int vb2_fop_release();
#if 0
ssize_t vb2_fop_write(struct file *file, char __user *buf,
size_t count, loff_t *ppos);
ssize_t vb2_fop_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos);
unsigned int vb2_fop_poll(struct file *file, poll_table *wait);
#endif
#ifndef CONFIG_MMU
unsigned long vb2_fop_get_unmapped_area(unsigned long addr,
unsigned long len, unsigned long pgoff, unsigned long flags);
#endif
/* struct vb2_ops helpers, only use if vq->lock is non-NULL. */
void vb2_ops_wait_prepare(struct vb2_queue *vq);
void vb2_ops_wait_finish(struct vb2_queue *vq);
#endif /* _MEDIA_VIDEOBUF2_CORE_H */

View file

@ -0,0 +1,41 @@
/*
* videobuf2-memops.h - generic memory handling routines for videobuf2
*
* Copyright (C) 2010 Samsung Electronics
*
* Author: Pawel Osciak <pawel@osciak.com>
* Marek Szyprowski <m.szyprowski@samsung.com>
*
* 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.
*/
#ifndef _MEDIA_VIDEOBUF2_MEMOPS_H
#define _MEDIA_VIDEOBUF2_MEMOPS_H
#include "videobuf2-core.h"
/**
* vb2_vmarea_handler - common vma refcount tracking handler
* @refcount: pointer to refcount entry in the buffer
* @put: callback to function that decreases buffer refcount
* @arg: argument for @put callback
*/
struct vb2_vmarea_handler {
atomic_t *refcount;
void (*put)(void *arg);
void *arg;
};
extern const struct vm_operations_struct vb2_common_vm_ops;
int vb2_get_contig_userptr(unsigned long vaddr, unsigned long size,
struct vm_area_struct **res_vma, dma_addr_t *res_pa);
struct vm_area_struct *vb2_get_vma(struct vm_area_struct *vma);
void vb2_put_vma(struct vm_area_struct *vma);
#endif

View file

@ -0,0 +1,21 @@
/*
* videobuf2-vmalloc.h - vmalloc memory allocator for videobuf2
*
* Copyright (C) 2010 Samsung Electronics
*
* Author: Pawel Osciak <pawel@osciak.com>
*
* 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.
*/
#ifndef _MEDIA_VIDEOBUF2_VMALLOC_H
#define _MEDIA_VIDEOBUF2_VMALLOC_H
#include "videobuf2-core.h"
extern const struct vb2_mem_ops vb2_vmalloc_memops;
#endif

View file

@ -0,0 +1,62 @@
/*
* Video for Linux Two header file
*
* Copyright (C) 1999-2012 the contributors
*
* 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.
*
* Alternatively you can redistribute this file under the terms of the
* BSD license as stated below:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. The names of its contributors may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Header file for v4l or V4L2 drivers and applications
* with public API.
* All kernel-specific stuff were moved to media/v4l2-dev.h, so
* no #if __KERNEL tests are allowed here
*
* See http://linuxtv.org for more info
*
* Author: Bill Dirks <bill@thedirks.org>
* Justin Schoeman
* Hans Verkuil <hverkuil@xs4all.nl>
* et al.
*/
#ifndef __LINUX_VIDEODEV2_H
#define __LINUX_VIDEODEV2_H
//#include <linux/time.h> /* need struct timeval */
#include "uapi_videodev2.h"
#endif /* __LINUX_VIDEODEV2_H */

View file

@ -165,13 +165,13 @@ static size_t xBlockAllocatedBit = 0;
/* Realtek test code start */
//TODO: remove section when combine BD and BF
#if ((defined CONFIG_PLATFORM_8195A) || (defined CONFIG_PLATFORM_8711B))
#if (defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8711B))
#include "section_config.h"
SRAM_BF_DATA_SECTION
#endif
static unsigned char ucHeap[ configTOTAL_HEAP_SIZE ];
static unsigned char ucHeap[configTOTAL_HEAP_SIZE];
#if (defined CONFIG_PLATFORM_8195A)
#if defined(CONFIG_PLATFORM_8195A)
HeapRegion_t xHeapRegions[] =
{
{ (uint8_t*)0x10002300, 0x3D00 }, // Image1 recycle heap (15616 bytes)
@ -179,7 +179,8 @@ HeapRegion_t xHeapRegions[] =
#if 0
{ (uint8_t*)0x301b5000, 300*1024 }, // SDRAM heap
#endif
{ NULL, 0 } // Terminates the array.
// { NULL, 0 }, // add SDRAM heap
{ NULL, 0 } // Terminates the array.
};
#elif (defined CONFIG_PLATFORM_8711B)
HeapRegion_t xHeapRegions[] =
@ -220,6 +221,9 @@ void *pvReturn = NULL;
/* Realtek test code start */
if(pxEnd == NULL)
{
#if defined(CONFIG_PLATFORM_8195A)
xHeapRegions[1].xSizeInBytes = (u32)0x10070000 - (u32)xHeapRegions[1].pucStartAddress;
#endif
vPortDefineHeapRegions( xHeapRegions );
}
/* Realtek test code end */
@ -649,3 +653,11 @@ void* pvPortReAlloc( void *pv, size_t xWantedSize )
return NULL;
}
/*
#ifdef ARDUINO_SDK
int vPortAddHeapRegion(uint8_t *addr, size_t size)
{
return 0;
}
#endif
*/

View file

@ -98,9 +98,9 @@ void *tcm_heap_allocmem(int size)
{
/* Just remove this chunk from the free list */
prev->next = chunk->next;
#ifdef _DEBUG
memset(chunk, ALLOC_FILL_CODE, size);
#endif
#ifdef _DEBUG
memset(chunk, ALLOC_FILL_CODE, size);
#endif
rtw_exit_critical(&tcm_lock, &irqL);
//printf("----ALLOC1-----\n\r");
@ -112,9 +112,9 @@ void *tcm_heap_allocmem(int size)
{
/* Allocate from the END of an existing chunk */
chunk->size -= size;
#ifdef _DEBUG
memset((uint8_t *)chunk + chunk->size, ALLOC_FILL_CODE, size);
#endif
#ifdef _DEBUG
memset((uint8_t *)chunk + chunk->size, ALLOC_FILL_CODE, size);
#endif
rtw_exit_critical(&tcm_lock, &irqL);
//printf("----ALLOC2-----\n\r");
// tcm_heap_dump();

View file

@ -102,21 +102,20 @@ VOID ShowRamBuildInfo(VOID)
_WEAK int main(void)
{
gpio_t gpio_led;
#ifndef CONFIG_WITHOUT_MONITOR
ReRegisterPlatformLogUart();
#endif
HalPinCtrlRtl8195A(JTAG, 0, 1);
// Init LED control pin
gpio_init(&gpio_led, PC_5);
gpio_dir(&gpio_led, PIN_OUTPUT); // Direction: Output
gpio_mode(&gpio_led, PullNone); // No pull
while(1){
gpio_write(&gpio_led, !gpio_read(&gpio_led));
RtlMsleepOS(1000);
DiagPrintf("\r\nRTL Console ROM: Start - press key 'Up', Help '?'\r\n");
while(pUartLogCtl[5] != 1);
pUartLogCtl[3] = 0;
pUartLogCtl[6] = 1;
DiagPrintf("\r<RTL8710AF>");
while(1) {
while(pUartLogCtl[4] != 1 );
UartLogCmdExecute(pUartLogCtl);
DiagPrintf("\r<RTL8710AF>");
pUartLogCtl[4] = 0;
}
return 0;
}
#else

View file

@ -0,0 +1,170 @@
/*
* loader.c
*
* Created on: 17 нояб. 2016 г.
* Author: PVV
*/
#include "rtl8195a.h"
#include "diag.h"
#include "hal_spi_flash.h"
#include "hal_api.h"
#include "hal_platform.h"
#include "diag.h"
#include "hal_diag.h"
#include "rtl8195a_uart.h"
#include "rtl8195a/rtl8195a_peri_on.h"
#include "hal_peri_on.h"
#include "wifi_conf.h"
//-------------------------------------------------------------------------
// Data declarations
extern u32 * NewVectorTable; // LD: NewVectorTable = 0x10000000;
extern START_FUNC __image2_entry_func__;
extern u8 __image2_validate_code__;
extern u8 __image1_bss_start__, __image1_bss_end__;
extern u8 __rom_bss_start__, __rom_bss_end__;
extern u8 __bss_start__, __bss_end__;
typedef struct __RAM_IMG2_VALID_PATTEN__ {
char rtkwin[7];
u8 x[13];
} _RAM_IMG2_VALID_PATTEN, *_PRAM_IMG2_VALID_PATTEN;
const uint8_t __attribute__((section(".image1.validate.rodata"))) RAM_IMG1_VALID_PATTEN[8] =
{ 0x23, 0x79, 0x16, 0x88, 0xff, 0xff, 0xff, 0xff };
PRAM_FUNCTION_START_TABLE __attribute__((section(".data.pRamStartFun"))) pRamStartFun =
(PRAM_FUNCTION_START_TABLE) 0x10000BC8;
RAM_START_FUNCTION __attribute__((section(".start.ram.data.a"))) gRamStartFun =
{ PreProcessForVendor + 1 };
RAM_START_FUNCTION __attribute__((section(".start.ram.data.b"))) gRamPatchWAKE =
{ RtlBootToSram + 1 };
RAM_START_FUNCTION __attribute__((section(".start.ram.data.c"))) gRamPatchFun0 =
{ RtlBootToSram + 1 };
RAM_START_FUNCTION __attribute__((section(".start.ram.data.d"))) gRamPatchFun1 =
{ RtlBootToSram + 1 };
RAM_START_FUNCTION __attribute__((section(".start.ram.data.e"))) gRamPatchFun2 =
{ RtlBootToSram + 1 };
RAM_START_FUNCTION __attribute__((section(".image2.ram.data"))) gImage2EntryFun0 =
{ InfraStart + 1 };
_RAM_IMG2_VALID_PATTEN __attribute__((section(".image2.validate.rodata"))) RAM_IMG2_VALID_PATTEN =
{ { "RTKWin" }, { 0xff, 0, 1, 1, 0, 0x95, 0x81, 1, 1, 0, 0, 0, 0 } };
HAL_GPIO_ADAPTER __attribute__((section(".hal.ram.data"))) gBoot_Gpio_Adapter;
void sub_100037EC(void)
{
HAL_SYS_CTRL_WRITE32(REG_SYS_REGU_CTRL0, (HAL_SYS_CTRL_READ32(REG_SYS_REGU_CTRL0) & 0xFFFFF) | 0xE00000);
HAL_SYS_CTRL_WRITE32(REG_SYS_REGU_CTRL0, HAL_SYS_CTRL_READ32(REG_SYS_REGU_CTRL0) | 2);
}
void __attribute__((section(".hal.ram.text"))) PreProcessForVendor(void) {
u8 efuse0xF8_data;
// memset((void *)0x10000300, 0 , 0x10000BC8-0x10000300); ???
HalPinCtrlRtl8195A(JTAG, 0, 1);
HalDelayUs(1000);
HALEFUSEOneByteReadROM(HAL_SYS_CTRL_READ32(REG_SYS_EFUSE_CTRL), 0xF8,
&efuse0xF8_data, L25EOUTVOLTAGE);
if(efuse0xF8_data == CHIP_ID_8711AF) { // ??
HAL_PERI_ON_WRITE32(REG_SOC_FUNC_EN, HAL_PERI_ON_READ32(REG_SOC_FUNC_EN) | 0x200000) ; 1<<21
sub_100037EC();
}
int flash_enable = HAL_PERI_ON_READ32(REG_SOC_FUNC_EN) & BIT_SOC_FLASH_EN;
}
void sub_1000441A(void)
{
ConfigDebugErr = -1;
ConfigDebugWarn = 0;
ConfigDebugInfo = 0;
}
//----- InfraStart
void __attribute__((section(".infra.ram.start"))) InfraStart(void) {
NewVectorTable[2] = HalNMIHandler_Patch;
sub_100022F0();
memset((void *)0x10000300, 0 , 0x10000BC8-0x10000300);
HAL_PERI_ON_WRITE32(REG_PESOC_CLK_CTRL, HAL_PERI_ON_READ32(REG_PESOC_CLK_CTRL) | BIT_SOC_ACTCK_VENDOR_REG_EN);
HAL_PERI_ON_WRITE32(REG_PESOC_CLK_CTRL, HAL_PERI_ON_READ32(REG_PESOC_CLK_CTRL) | BIT_SOC_SLPCK_VENDOR_REG_EN);
HalPinCtrlRtl8195A(JTAG, 0, 1);
HAL_PERI_ON_WRITE32(REG_GPIO_SHTDN_CTRL, 0x7FF);
HAL_PERI_ON_WRITE32(REG_CPU_PERIPHERAL_CTRL, HAL_PERI_ON_READ32(REG_CPU_PERIPHERAL_CTRL) | BIT_SPI_FLSH_PIN_EN);
HAL_PERI_ON_WRITE32(REG_CPU_PERIPHERAL_CTRL, HAL_SYHAL_PERI_ON_READ32S_CTRL_READ32(REG_CPU_PERIPHERAL_CTRL) | BIT_LOG_UART_PIN_EN);
VectorTableInitRtl8195A(0x1FFFFFFC); // 0x1FFFFFFC StackP
HAL_PERI_ON_WRITE32(REG_SOC_FUNC_EN, HAL_PERI_ON_READ32(REG_SOC_FUNC_EN) | BIT_SOC_FLASH_EN) ;
HAL_PERI_ON_WRITE32(REG_PESOC_CLK_CTRL, HAL_PERI_ON_READ32(REG_PESOC_CLK_CTRL) | BIT_SOC_ACTCK_FLASH_EN);
HAL_PERI_ON_WRITE32(REG_PESOC_CLK_CTRL, HAL_PERI_ON_READ32(REG_PESOC_CLK_CTRL) | BIT_SOC_SLPCK_FLASH_EN);
HalPinCtrlRtl8195A(SPI_FLASH, 0, 1);
sub_1000367C();
HAL_SYS_CTRL_WRITE32(REG_SYS_CLK_CTRL1, HAL_SYS_CTRL_READ32(REG_SYS_CLK_CTRL1) & 0x8F);
sub_1000441A();
HAL_UART_READ32(UART_REV_BUF_OFF);
HAL_PERI_ON_WRITE32(REG_SOC_FUNC_EN, HAL_PERI_ON_READ32(REG_SOC_FUNC_EN) & (~BIT_SOC_LOG_UART_EN));
HAL_PERI_ON_WRITE32(REG_SOC_FUNC_EN, HAL_PERI_ON_READ32(REG_SOC_FUNC_EN) | BIT_SOC_LOG_UART_EN);
HAL_PERI_ON_WRITE32(REG_PESOC_CLK_CTRL, HAL_PERI_ON_READ32(REG_PESOC_CLK_CTRL) | BIT_SOC_ACTCK_LOG_UART_EN);
LOG_UART_ADAPTER UartAdapter;
UartAdapter.BaudRate = UART_BAUD_RATE_38400;
UartAdapter.FIFOControl = 0xC1;
UartAdapter.IntEnReg = 0x00;
UartAdapter.Parity = UART_PARITY_DISABLE;
UartAdapter.Stop = UART_STOP_1BIT;
UartAdapter.DataLength = UART_DATA_LEN_8BIT;
HalLogUartInit(UartAdapter); // sub_10004434(38400, 193, 0, v14);
TIMER_ADAPTER tim_adapter;
tim_adapter.IrqHandle.IrqFun = &UartLogIrqHandle;
tim_adapter.IrqHandle.IrqNum = UART_LOG_IRQ;
tim_adapter.IrqHandle.Data = 0;
tim_adapter.IrqHandle.Priority = 5;
VectorIrqRegisterRtl8195A(&tim_adapter.IrqHandle);
UartAdapter.IntEnReg = 0x05;
HalLogUartInit(UartAdapter);
HAL_PERI_ON_WRITE32(REG_PON_ISO_CTRL, 3); // ? USB ?
HAL_PERI_ON_WRITE32(REG_OSC32K_CTRL, HAL_PERI_ON_READ32(REG_OSC32K_CTRL) | BIT_32K_POW_CKGEN_EN);
HAL_PERI_ON_WRITE32(REG_SOC_FUNC_EN, HAL_PERI_ON_READ32(REG_SOC_FUNC_EN) | BIT_SOC_GTIMER_EN);
HAL_PERI_ON_WRITE32(REG_PESOC_CLK_CTRL, HAL_PERI_ON_READ32(REG_PESOC_CLK_CTRL) | BIT_SOC_ACTCK_TIMER_EN);
HAL_PERI_ON_WRITE32(REG_PESOC_CLK_CTRL, HAL_PERI_ON_READ32(REG_PESOC_CLK_CTRL) | BIT_SOC_SLPCK_TIMER_EN);
tim_adapter.TimerIrqPriority = 0;
tim_adapter.TimerLoadValueUs = 0;
tim_adapter.TimerMode = FREE_RUN_MODE;
tim_adapter.IrqDis = 1;
tim_adapter.TimerId = 1;
HalTimerInitRtl8195a((PTIMER_ADAPTER) &tim_adapter);
SpicInitRtl8195A(1, 1); // InitBaudRate 1, SpicBitMode 1
SpicFlashInitRtl8195A(1); // SpicBitMode 1
DBG_8195A("===== Enter Image 1.5 ====\nImg2 Sign: %s, InfaStart @ 0x%08x\n",
&__image2_validate_code__, __image2_entry_func__);
HAL_SYS_CTRL_WRITE32(REG_SYS_CLK_CTRL0,
HAL_SYS_CTRL_READ32(REG_SYS_CLK_CTRL0) | BIT4);
if (HalCommonInit() != HAL_OK) DBG_8195A("Hal Common Init Failed.\n");
DBG_8195A("===== Enter Image 2 ====\n");
ShowRamBuildInfo(); // app_start.c: VOID ShowRamBuildInfo(VOID)
memset(&__bss_start__, 0, &__bss_end__ - &__bss_start__);
int clk = (HAL_SYS_CTRL_READ32(REG_SYS_CLK_CTRL0)
>> BIT_SHIFT_PESOC_OCP_CPU_CK_SEL) & 1;
if (clk) {
SpicNVMCalLoadAll();
SpicReadIDRtl8195A();
}
SystemCoreClockUpdate();
SYSPlatformInit();
En32KCalibration();
InitSoCPM();
SDIO_Device_Off();
VectorTableInitForOSRtl8195A(&vPortSVCHandler, &xPortPendSVHandler,
&xPortSysTickHandler);
if (clk) SpicDisableRtl8195A();
_AppStart();
}

View file

@ -1,6 +1,6 @@
/*
startup.o sdk-ameba-rtl8710af-v3.5a_without_NDA_GCC_V1.0.0
pvvx 2016
* startup.o sdk-ameba-rtl8710af-v3.5a_without_NDA_GCC_V1.0.0
* pvvx 2016
*/
#include "rtl8195a.h"
@ -41,7 +41,7 @@ void StartupHalInitPlatformLogUart(void);
void RtlBootToSram(void);
int IsForceLoadDefaultImg2(void);
void StartupHalSpicInit(int InitBaudRate);
void PreProcessForVendor(u32 def_fuse, u32 Img2Addr, int a3);
void PreProcessForVendor(void);
void HalHardFaultHandler_Patch_c(u32 HardDefaultArg);
void VectorTableOverrideRtl8195A(u32 StackP);
void SYSPlatformInit(void);
@ -220,7 +220,7 @@ void __attribute__((section(".hal.ram.text"))) SYSCpuClkConfig(int ChipID, int S
SpicWaitWipRtl8195A(); // extern u32 SpicWaitWipRtl8195A(VOID);
flg = 1;
}
if (ChipID == 0xFC && (!SysCpuClk)) SysCpuClk = 1;
if (ChipID == CHIP_ID_8710AF && (!SysCpuClk)) SysCpuClk = 1;
HalCpuClkConfig(SysCpuClk);
HalDelayUs(1000);
StartupHalInitPlatformLogUart();
@ -283,13 +283,12 @@ void __attribute__((section(".hal.ram.text"))) StartupHalSpicInit(
}
//----- PreProcessForVendor
void __attribute__((section(".hal.ram.text"))) PreProcessForVendor(u32 def_fuse,
u32 Img2Addr, int a3) {
void __attribute__((section(".hal.ram.text"))) PreProcessForVendor(void) {
START_FUNC entry_func;
u32 run_image;
u32 Image2Addr = Img2Addr;
u32 Image2Addr;
u32 v16 = 0, v17;
u8 efuse0xD3_data = def_fuse >> 24;
u8 efuse0xD3_data;
HALEFUSEOneByteReadROM(HAL_SYS_CTRL_READ32(REG_SYS_EFUSE_CTRL), 0xD3,
&efuse0xD3_data, L25EOUTVOLTAGE);
if (efuse0xD3_data & 1) v16 = HalPinCtrlRtl8195A(JTAG, 0, 1);
@ -303,7 +302,7 @@ void __attribute__((section(".hal.ram.text"))) PreProcessForVendor(u32 def_fuse,
} else {
memcpy(&Image2Addr, (const void *) 0x1006FFFC, 4); // ???
entry_func = Image2Addr;
if (chip_id != 0xFB) {
if (chip_id != CHIP_ID_8711AN) { // 0xFB
StartupHalSpicInit(1); // BaudRate 1
x_enable = 1;
}
@ -319,7 +318,10 @@ void __attribute__((section(".hal.ram.text"))) PreProcessForVendor(u32 def_fuse,
sdr_enable = 1;
}
#else
SdrPowerOff();
// SdrPowerOff();
SDR_PIN_FCTRL(OFF);
LDO25M_CTRL(OFF);
HAL_WRITE32(PERI_ON_BASE, REG_SOC_FUNC_EN, HAL_READ32(PERI_ON_BASE, REG_SOC_FUNC_EN) | BIT(21));
#endif
ConfigDebugErr = -1;
ConfigDebugWarn = 0;
@ -331,7 +333,7 @@ void __attribute__((section(".hal.ram.text"))) PreProcessForVendor(u32 def_fuse,
DBG_8195A("===== Enter Image 1 ====\n");
if (x_enable) {
SpicReadIDRtl8195A();
SpicFlashInitRtl8195A(1); // SpicBitMode 1
SpicFlashInitRtl8195A(SpicDualBitMode); // SpicBitMode 1
}
// if (sdr_enable) SdrControllerInit();
if (flash_enable) {
@ -362,10 +364,8 @@ void __attribute__((section(".hal.ram.text"))) PreProcessForVendor(u32 def_fuse,
sign1 = *prdflash++;
sign2 = *prdflash;
if (sign2 == 0x31313738) {
if (sign1 == 0x35393138)
v16 = OTA_addr;
else if (sign1 == 0x35393130)
v17 = OTA_addr;
if (sign1 == 0x35393138) v16 = OTA_addr;
else if (sign1 == 0x35393130) v17 = OTA_addr;
}
LABEL_41: if (IsForceLoadDefaultImg2()) {
if (v17 != -1) run_image = v17;
@ -373,8 +373,7 @@ LABEL_41: if (IsForceLoadDefaultImg2()) {
run_image = v16;
if (run_image == -1) {
DiagPrintf("Fatal: no fw\n");
while (1)
RtlConsolRom(1000);
while (1) RtlConsolRom(1000);
}
}
} else {
@ -383,8 +382,7 @@ LABEL_41: if (IsForceLoadDefaultImg2()) {
run_image = v17;
if (run_image == -1) {
DiagPrintf("Fatal: no fw\n");
while (1)
RtlConsolRom(1000);
while (1) RtlConsolRom(1000);
}
}
}

View file

@ -0,0 +1,149 @@
#ifndef _GENERIC_ERRNO_H
#define _GENERIC_ERRNO_H
#define EPERM 1 /* Operation not permitted */
#define ENOENT 2 /* No such file or directory */
#define ESRCH 3 /* No such process */
#define EINTR 4 /* Interrupted system call */
#define EIO 5 /* I/O error */
#define ENXIO 6 /* No such device or address */
#define E2BIG 7 /* Argument list too long */
#define ENOEXEC 8 /* Exec format error */
#define EBADF 9 /* Bad file number */
#define ECHILD 10 /* No child processes */
#define EAGAIN 11 /* Try again */
#define ENOMEM 12 /* Out of memory */
#define EACCES 13 /* Permission denied */
#define EFAULT 14 /* Bad address */
#define ENOTBLK 15 /* Block device required */
#define EBUSY 16 /* Device or resource busy */
#define EEXIST 17 /* File exists */
#define EXDEV 18 /* Cross-device link */
#define ENODEV 19 /* No such device */
#define ENOTDIR 20 /* Not a directory */
#define EISDIR 21 /* Is a directory */
#define EINVAL 22 /* Invalid argument */
#define ENFILE 23 /* File table overflow */
#define EMFILE 24 /* Too many open files */
#define ENOTTY 25 /* Not a typewriter */
#define ETXTBSY 26 /* Text file busy */
#define EFBIG 27 /* File too large */
#define ENOSPC 28 /* No space left on device */
#define ESPIPE 29 /* Illegal seek */
#define EROFS 30 /* Read-only file system */
#define EMLINK 31 /* Too many links */
#define EPIPE 32 /* Broken pipe */
#define EDOM 33 /* Math argument out of domain of func */
#define ERANGE 34 /* Math result not representable */
#define EDEADLK 35 /* Resource deadlock would occur */
#define ENAMETOOLONG 36 /* File name too long */
#define ENOLCK 37 /* No record locks available */
#define ENOSYS 38 /* Function not implemented */
#define ENOTEMPTY 39 /* Directory not empty */
#define ELOOP 40 /* Too many symbolic links encountered */
#define EWOULDBLOCK EAGAIN /* Operation would block */
#define ENOMSG 42 /* No message of desired type */
#define EIDRM 43 /* Identifier removed */
#define ECHRNG 44 /* Channel number out of range */
#define EL2NSYNC 45 /* Level 2 not synchronized */
#define EL3HLT 46 /* Level 3 halted */
#define EL3RST 47 /* Level 3 reset */
#define ELNRNG 48 /* Link number out of range */
#define EUNATCH 49 /* Protocol driver not attached */
#define ENOCSI 50 /* No CSI structure available */
#define EL2HLT 51 /* Level 2 halted */
#define EBADE 52 /* Invalid exchange */
#define EBADR 53 /* Invalid request descriptor */
#define EXFULL 54 /* Exchange full */
#define ENOANO 55 /* No anode */
#define EBADRQC 56 /* Invalid request code */
#define EBADSLT 57 /* Invalid slot */
#define EDEADLOCK EDEADLK
#define EBFONT 59 /* Bad font file format */
#define ENOSTR 60 /* Device not a stream */
#define ENODATA 61 /* No data available */
#define ETIME 62 /* Timer expired */
#define ENOSR 63 /* Out of streams resources */
#define ENONET 64 /* Machine is not on the network */
#define ENOPKG 65 /* Package not installed */
#define EREMOTE 66 /* Object is remote */
#define ENOLINK 67 /* Link has been severed */
#define EADV 68 /* Advertise error */
#define ESRMNT 69 /* Srmount error */
#define ECOMM 70 /* Communication error on send */
#define EPROTO 71 /* Protocol error */
#define EMULTIHOP 72 /* Multihop attempted */
#define EDOTDOT 73 /* RFS specific error */
#define EBADMSG 74 /* Not a data message */
#define EOVERFLOW 75 /* Value too large for defined data type */
#define ENOTUNIQ 76 /* Name not unique on network */
#define EBADFD 77 /* File descriptor in bad state */
#define EREMCHG 78 /* Remote address changed */
#define ELIBACC 79 /* Can not access a needed shared library */
#define ELIBBAD 80 /* Accessing a corrupted shared library */
#define ELIBSCN 81 /* .lib section in a.out corrupted */
#define ELIBMAX 82 /* Attempting to link in too many shared libraries */
#define ELIBEXEC 83 /* Cannot exec a shared library directly */
#define EILSEQ 84 /* Illegal byte sequence */
#define ERESTART 85 /* Interrupted system call should be restarted */
#define ESTRPIPE 86 /* Streams pipe error */
#define EUSERS 87 /* Too many users */
#define ENOTSOCK 88 /* Socket operation on non-socket */
#define EDESTADDRREQ 89 /* Destination address required */
#define EMSGSIZE 90 /* Message too long */
#define EPROTOTYPE 91 /* Protocol wrong type for socket */
#define ENOPROTOOPT 92 /* Protocol not available */
#define EPROTONOSUPPORT 93 /* Protocol not supported */
#define ESOCKTNOSUPPORT 94 /* Socket type not supported */
#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
#define EPFNOSUPPORT 96 /* Protocol family not supported */
#define EAFNOSUPPORT 97 /* Address family not supported by protocol */
#define EADDRINUSE 98 /* Address already in use */
#define EADDRNOTAVAIL 99 /* Cannot assign requested address */
#define ENETDOWN 100 /* Network is down */
#define ENETUNREACH 101 /* Network is unreachable */
#define ENETRESET 102 /* Network dropped connection because of reset */
#define ECONNABORTED 103 /* Software caused connection abort */
#define ECONNRESET 104 /* Connection reset by peer */
#define ENOBUFS 105 /* No buffer space available */
#define EISCONN 106 /* Transport endpoint is already connected */
#define ENOTCONN 107 /* Transport endpoint is not connected */
#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
#define ETOOMANYREFS 109 /* Too many references: cannot splice */
#define ETIMEDOUT 110 /* Connection timed out */
#define ECONNREFUSED 111 /* Connection refused */
#define EHOSTDOWN 112 /* Host is down */
#define EHOSTUNREACH 113 /* No route to host */
#define EALREADY 114 /* Operation already in progress */
#define EINPROGRESS 115 /* Operation now in progress */
#define ESTALE 116 /* Stale NFS file handle */
#define EUCLEAN 117 /* Structure needs cleaning */
#define ENOTNAM 118 /* Not a XENIX named type file */
#define ENAVAIL 119 /* No XENIX semaphores available */
#define EISNAM 120 /* Is a named type file */
#define EREMOTEIO 121 /* Remote I/O error */
#define EDQUOT 122 /* Quota exceeded */
#define ENOMEDIUM 123 /* No medium found */
#define EMEDIUMTYPE 124 /* Wrong medium type */
#define ECANCELED 125 /* Operation Canceled */
#define ENOKEY 126 /* Required key not available */
#define EKEYEXPIRED 127 /* Key has expired */
#define EKEYREVOKED 128 /* Key has been revoked */
#define EKEYREJECTED 129 /* Key was rejected by service */
/* for robust mutexes */
#define EOWNERDEAD 130 /* Owner died */
#define ENOTRECOVERABLE 131 /* State not recoverable */
#define ERFKILL 132 /* Operation not possible due to RF-kill */
#define EHWPOISON 133 /* Memory page has hardware error */
#define ENOTSUPP 524 /* Operation is not supported */
#endif

View file

@ -933,11 +933,11 @@ VOID SpicNVMCalLoad(u8 BitMode, u8 CpuClk)
uint32_t spci_para; // [sp+Ch] [bp-2Ch]@4
v2 = CpuClk + 6 * BitMode;
v3 = 40006120;
v4 = 40006014;
v3 = 0x40006120;
v4 = 0x40006014;
v5 = BitMode;
v6 = CpuClk;
if (40006014 == 1) {
if (0x40006014 == 1) {
BitMode = HalGetCpuClk(BitMode, CpuClk);
if (BitMode == 166666666) {
40006120 |= 0x202u;
@ -1012,39 +1012,38 @@ VOID HAL_FLASH_TEXT_SECTION SpicNVMCalStore(u8 BitMode, u8 CpuClk)
v4);
v5 = v4 + 6 * v3;
v6 = v5;
if (*(u32 *) (8 * v5 - 1744793472) == -1) {
if (*(u32 *) (8 * v5 + 0x98009080) == -1) {
LOBYTE (spci_para) = SpicInitParaAllClk[0][v5].BaudRate;
BYTE1 (spci_para) = SpicInitParaAllClk[0][v6].RdDummyCyle;
BYTE2 (spci_para) = SpicInitParaAllClk[0][v6].DelayLine;
BYTE3 (spci_para) = SpicInitParaAllClk[0][v6]._anon_0.Rsvd;
*(u32 *) (8 * v5 - 1744793472) = spci_para;
*(u32 *) (8 * v5 + 0x98009080) = spci_para;
if (SpicInitParaAllClk[0][v6].flashtype == 4)
SpicWaitOperationDoneRtl8195A(SpicInitPara, spci_para);
else
SpicWaitWipDoneRefinedRtl8195A(SpicInitPara, spci_para);
*(u32 *) (8 * v5 - 1744793468) = ~spci_para;
*(u32 *) (8 * v5 + 0x98009084) = ~spci_para;
v7 = SpicInitParaAllClk[0][v4 + 6 * v3].flashtype;
if (v7 == 4)
SpicWaitOperationDoneRtl8195A(SpicInitPara, 4);
else
SpicWaitWipDoneRefinedRtl8195A(SpicInitPara, v7);
DBG_SPIF_INFO("SpicNVMCalStore(BitMode %d, CPUClk %d): Calibration Stored: BaudRate=0x%x RdDummyCyle=0x%x DelayLine=0x%x\r\n",
DBG_SPIF_INFO("SpicNVMCalStore(BitMode %d, CPUClk %d): Calibration Stored: BaudRate=0x%x RdDummyCyle=0x%x DelayLine=0x%x\r\n",
v3, v4, SpicInitParaAllClk[0][v4 + 6 * v3].BaudRate,
SpicInitParaAllClk[0][v4 + 6 * v3].RdDummyCyle,
SpicInitParaAllClk[0][v4 + 6 * v3].DelayLine);
if (*(u32 *) (8 * v5 - 1744793472) != spci_para) {
v8 = *(u32 *) (8 * v5 - 1744793472);
if (*(u32 *) (8 * v5 + 0x98009080) != spci_para) {
v8 = *(u32 *) (8 * v5 + 0x98009080);
DBG_SPIF_ERR("SpicNVMCalStore Err(Offset=0x%x), Wr=0x%x Rd=0x%x \r\n",
8 * v5);
}
if (*(u32 *) (8 * v5 - 1744793468) != ~spci_para) {
v9 = *(u32 *) (8 * v5 - 1744793468);
if (*(u32 *) (8 * v5 + 0x98009084) != ~spci_para) {
v9 = *(u32 *) (8 * v5 + 0x98009084);
DBG_SPIF_ERR("SpicNVMCalStore Err(Offset=0x%x), Wr=0x%x Rd=0x%x \r\n",
v6 * 8 + 4);
}
} else DBG_SPIF_ERR("SpicNVMCalStore: The flash memory(@0x%x = 0x%x) is not able to be write, Erase it first!!\r\n",
v6 * 8 + 36992);
v6 * 8 + 0x9080);
}
//----- SpicCalibrationRtl8195A
@ -1226,7 +1225,7 @@ extern BOOLEAN HAL_FLASH_TEXT_SECTION SpicFlashInitRtl8195A(u8 SpicBitMode)
DefRdDummyCycle = 8;
break;
default:
DBG_MISC_ERR("No Support SPI Mode!!!!!!!!\n");
DBG_MISC_ERR("No Support SPI Mode!\n");
SpicConfigAutoModeRtl8195A(SpicOneBitMode);
DefRdDummyCycle = 0;
}

Some files were not shown because too many files have changed in this diff Show more