CARPLAY版本整理

This commit is contained in:
2025-01-21 16:49:37 +08:00
commit f0fb64e4e6
26542 changed files with 13719676 additions and 0 deletions

View File

@ -0,0 +1,279 @@
/******************************************************************************
* Copyright (c) 2013-2016 Realtek Semiconductor Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
#ifndef __LIST_H
#define __LIST_H
#if defined ( __CC_ARM )
#ifndef inline
#define inline __inline
#endif
#endif
/* This file is from Linux Kernel (include/linux/list.h)
* and modified by simply removing hardware prefetching of list items.
* Here by copyright, credits attributed to wherever they belong.
* Kulesh Shanmugasundaram (kulesh [squiggly] isis.poly.edu)
*/
/*
* Simple doubly linked list implementation.
*
* Some of the internal functions ("__xxx") are useful when
* manipulating whole lists rather than single entries, as
* sometimes we already know the next/prev entries and we can
* generate better code by using them directly rather than
* using the generic single-entry routines.
*/
struct list_head {
struct list_head *next, *prev;
};
#define LIST_HEAD_INIT(name) { &(name), &(name) }
#define LIST_HEAD(name) \
struct list_head name = LIST_HEAD_INIT(name)
#define INIT_LIST_HEAD(ptr) do { \
(ptr)->next = (ptr); (ptr)->prev = (ptr); \
} while (0)
/*
* Insert a new entry between two known consecutive entries.
*
* This is only for internal list manipulation where we know
* the prev/next entries already!
*/
static inline void __list_add(struct list_head *newitem,
struct list_head *prev,
struct list_head *next)
{
next->prev = newitem;
newitem->next = next;
newitem->prev = prev;
prev->next = newitem;
}
/**
* list_add - add a new entry
* @new: new entry to be added
* @head: list head to add it after
*
* Insert a new entry after the specified head.
* This is good for implementing stacks.
*/
static inline void list_add(struct list_head *newitem, struct list_head *head)
{
__list_add(newitem, head, head->next);
}
/**
* list_add_tail - add a new entry
* @new: new entry to be added
* @head: list head to add it before
*
* Insert a new entry before the specified head.
* This is useful for implementing queues.
*/
static inline void list_add_tail(struct list_head *newitem, struct list_head *head)
{
__list_add(newitem, head->prev, head);
}
/*
* Delete a list entry by making the prev/next entries
* point to each other.
*
* This is only for internal list manipulation where we know
* the prev/next entries already!
*/
static inline void __list_del(struct list_head *prev, struct list_head *next)
{
next->prev = prev;
prev->next = next;
}
/**
* list_del - deletes entry from list.
* @entry: the element to delete from the list.
* Note: list_empty on entry does not return true after this, the entry is in an undefined state.
*/
static inline void list_del(struct list_head *entry)
{
__list_del(entry->prev, entry->next);
entry->next = (struct list_head *) 0;
entry->prev = (struct list_head *) 0;
}
/**
* list_del_init - deletes entry from list and reinitialize it.
* @entry: the element to delete from the list.
*/
static inline void list_del_init(struct list_head *entry)
{
__list_del(entry->prev, entry->next);
INIT_LIST_HEAD(entry);
}
/**
* list_move - delete from one list and add as another's head
* @list: the entry to move
* @head: the head that will precede our entry
*/
static inline void list_move(struct list_head *list, struct list_head *head)
{
__list_del(list->prev, list->next);
list_add(list, head);
}
/**
* list_move_tail - delete from one list and add as another's tail
* @list: the entry to move
* @head: the head that will follow our entry
*/
static inline void list_move_tail(struct list_head *list,
struct list_head *head)
{
__list_del(list->prev, list->next);
list_add_tail(list, head);
}
/**
* list_empty - tests whether a list is empty
* @head: the list to test.
*/
static inline int list_empty(struct list_head *head)
{
return head->next == head;
}
static inline void __list_splice(struct list_head *list,
struct list_head *head)
{
struct list_head *first = list->next;
struct list_head *last = list->prev;
struct list_head *at = head->next;
first->prev = head;
head->next = first;
last->next = at;
at->prev = last;
}
/**
* list_splice - join two lists
* @list: the new list to add.
* @head: the place to add it in the first list.
*/
static inline void list_splice(struct list_head *list, struct list_head *head)
{
if (!list_empty(list))
__list_splice(list, head);
}
/**
* list_splice_init - join two lists and reinitialise the emptied list.
* @list: the new list to add.
* @head: the place to add it in the first list.
*
* The list at @list is reinitialised
*/
static inline void list_splice_init(struct list_head *list,
struct list_head *head)
{
if (!list_empty(list)) {
__list_splice(list, head);
INIT_LIST_HEAD(list);
}
}
/**
* list_entry - get the struct for this entry
* @ptr: the &struct list_head pointer.
* @type: the type of the struct this is embedded in.
* @member: the name of the list_struct within the struct.
*/
#define list_entry(ptr, type, member) \
((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
/**
* list_first_entry - get the first element from a list
* @ptr: the list head to take the element from.
* @type: the type of the struct this is embedded in.
* @member: the name of the list_head within the struct.
*
* Note, that list is expected to be not empty.
*/
#define list_first_entry(ptr, type, member) \
list_entry((ptr)->next, type, member)
/**
* list_for_each - iterate over a list
* @pos: the &struct list_head to use as a loop counter.
* @head: the head for your list.
*/
#define list_for_each(pos, head) \
for (pos = (head)->next; pos != (head); \
pos = pos->next)
/**
* list_for_each_prev - iterate over a list backwards
* @pos: the &struct list_head to use as a loop counter.
* @head: the head for your list.
*/
#define list_for_each_prev(pos, head) \
for (pos = (head)->prev; pos != (head); \
pos = pos->prev)
/**
* list_for_each_safe - iterate over a list safe against removal of list entry
* @pos: the &struct list_head to use as a loop counter.
* @n: another &struct list_head to use as temporary storage
* @head: the head for your list.
*/
#define list_for_each_safe(pos, n, head) \
for (pos = (head)->next, n = pos->next; pos != (head); \
pos = n, n = pos->next)
/**
* list_for_each_entry - iterate over list of given type
* @pos: the type * to use as a loop counter.
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*/
#define list_for_each_entry(pos, head, member, type) \
for (pos = list_entry((head)->next, type, member); \
&pos->member != (head); \
pos = list_entry(pos->member.next, type, member))
/**
* list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
* @pos: the type * to use as a loop counter.
* @n: another type * to use as temporary storage
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*/
#define list_for_each_entry_safe(pos, n, head, member, type) \
for (pos = list_entry((head)->next, type, member), \
n = list_entry(pos->member.next, type, member); \
&pos->member != (head); \
pos = n, n = list_entry(n->member.next, type, member))
#endif

View File

@ -0,0 +1,18 @@
#ifndef __RTWLAN_CONFIG_H
#define __RTWLAN_CONFIG_H
#include "FreeRTOSConfig.h"
#define CONFIG_PLATFOMR_CUSTOMER_RTOS
#define DRV_NAME "RTL8821CS"
#define DRIVERVERSION "c9c2594a99792ec4c03af05362d0c1faa313be44"
#define CONFIG_DEBUG 1
#define CONFIG_MP_INCLUDED 1
#define CONFIG_MP_NORMAL_IWPRIV_SUPPORT 1
#define CONFIG_HARDWARE_8821C 1
#define CONFIG_ENABLE_P2P 1
#define CONFIG_WPS 1
#define CONFIG_WPS_AP 1
#define CONFIG_ENABLE_WPS_AP 1
#endif

View File

@ -0,0 +1,34 @@
#include <stdint.h>
#include "timer.h"
/*static inline void sys_ctl_delay(unsigned long ulCount)
{
while(ulCount--);
}*/
/**
* Customer provide us level delay
* FreeRTOS does not provide us level delay. Use busy wait
* It is CPU platform dependent
*/
void WLAN_BSP_UsLoop(int us)
{
//unsigned long nloops = us * (configCPU_CLOCK_HZ / 3000000);
//sys_ctl_delay(nloops);
udelay(us);
}
/* Customer function to control HW specific wlan gpios */
void Set_WLAN_Power_On(void)
{
}
/* Customer function to control HW specific wlan gpios */
void Set_WLAN_Power_Off(void)
{
}

View File

@ -0,0 +1,21 @@
/**
******************************************************************************
* @file rtwlan_bsp.h
* @author Realtek software team
* @version V0.1
* @date 05-March-2013
* @brief Realtek WLAN hardware configuration.
******************************************************************************
*/
#ifndef __REALTEK_WLAN_BSP_H__
#define __REALTEK_WLAN_BSP_H__
/* Includes ---------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void Set_WLAN_Power_On(void);
void Set_WLAN_Power_Off(void);
void WLAN_BSP_UsLoop(int us);
#endif// __REALTEK_WLAN_BSP_H__

View File

@ -0,0 +1,11 @@
#ifndef _MMC_SDIO_IRQ_H
#define _MMC_SDIO_IRQ_H
//#include "../include/card.h"
#include "mmcsd_card.h"
int sdio_claim_irq(struct sdio_func *func, void(*handler)(struct sdio_func *));
int sdio_release_irq(struct sdio_func *func);
void sdio_irq_thread(void* exinf);
#endif

View File

@ -0,0 +1,76 @@
#ifndef _MMC_SDIO_CARD_H
#define _MMC_SDIO_CARD_H
#ifdef CONFIG_READ_CIS
/*
* SDIO function CIS tuple (unknown to the core)
*/
struct sdio_func_tuple {
struct sdio_func_tuple *next;
unsigned char code;
unsigned char size;
unsigned char data[0];
};
#endif
/*
* SDIO function devices
*/
struct sdio_func {
struct mmc_card *card; /* the card this device belongs to */
void (*irq_handler)(struct sdio_func *); /* IRQ callback */
unsigned int max_blksize; /* maximum block size */ //add
unsigned int cur_blksize; /* current block size */ //add
unsigned int enable_timeout; /* max enable timeout in msec */ //add
unsigned int num; /* function number *///add
unsigned short vendor; /* vendor id */ //add
unsigned short device; /* device id */ //add
unsigned num_info; /* number of info strings */ //add
const char **info; /* info strings */ //add
unsigned char class; /* standard interface class *///add
unsigned int tmpbuf_reserved; //for tmpbuf 4 byte alignment
unsigned char tmpbuf[4]; /* DMA:able scratch buffer */
#ifdef CONFIG_READ_CIS
struct sdio_func_tuple *tuples;
#endif
void *drv_priv;
};
struct sdio_cccr {
unsigned int sdio_vsn;
unsigned int sd_vsn;
unsigned int multi_block:1;
unsigned int low_speed:1;
unsigned int wide_bus:1;
unsigned int high_power:1;
unsigned int high_speed:1;
unsigned int disable_cd:1;
};
struct sdio_cis {
unsigned short vendor;
unsigned short device;
unsigned short blksize;
unsigned int max_dtr;
};
struct mmc_card {
struct mmc_host *host; /* the host this device belongs to */
struct sdio_cccr cccr; /* common card info */
struct sdio_cis cis; /* common tuple info */ //add
struct sdio_func *sdio_func[7]; /* SDIO functions (devices) *///add
unsigned int sdio_funcs; /* number of SDIO functions *///add
unsigned int rca; /* relative card address of device */
unsigned int type; /* card type */
unsigned num_info; /* number of info strings *///add
const char **info; /* info strings *///add
#ifdef CONFIG_READ_CIS
struct sdio_func_tuple *tuples; /* unknown common tuples *///add
#endif
};
#endif

View File

@ -0,0 +1,258 @@
//#include "include/common.h"
#include "FreeRTOS.h"
#include "board.h"
#ifdef SDMMC_SUPPORT
#include "sdio.h"
#include "wifi_io.h"
#include "mmcsd_core.h"
/* test wifi driver */
#define ADDR_MASK 0x10000
#define LOCAL_ADDR_MASK 0x00000
int sdio_bus_probe(void)
{
return 0;
}
int sdio_bus_remove(void)
{
return 0;
}
void sdio_claim_host(struct sdio_func*func)
{
mmcsd_host_lock(func->card->host);
}
void sdio_release_host(struct sdio_func *func)
{
mmcsd_host_unlock(func->card->host);
}
int32_t sdio_claim_irq(struct sdio_func *func,
void(*handler)(struct sdio_func *))
{
return sdio_attach_irq(func, handler);
}
int32_t sdio_release_irq(struct sdio_func *func)
{
return sdio_detach_irq(func);
}
unsigned char sdio_readb(struct sdio_func *func, unsigned int addr, int *err_ret)
{
unsigned char ret;
int32_t err = -1;
ret = sdio_io_readb(func, addr, (int32_t *)&err);
//printf("%s addr:%08x\r\n", __func__, addr);
if (err_ret)
*err_ret = (int)err;
return ret;
}
void sdio_writeb(struct sdio_func *func, unsigned char b, unsigned int addr, int *err_ret)
{
int err = 0;//printf("%s addr:%08x\r\n", __func__, addr);
err= sdio_io_writeb(func, addr, b);
if (NULL != err_ret)
*err_ret = err;
}
uint16_t sdio_readw(struct sdio_func *func, unsigned int addr, int *err_ret)
{//printf("%s addr:%08x\r\n", __func__, addr);
return sdio_io_readw(func, addr, err_ret);
}
void sdio_writew(struct sdio_func *func, uint16_t v, unsigned int addr, int *err_ret)
{
int err = 0;//printf("%s addr:%08x\r\n", __func__, addr);
err= sdio_io_writew(func, v, addr);
if (NULL != err_ret)
*err_ret = err;
}
uint32_t sdio_readl(struct sdio_func *func, unsigned int addr, int *err_ret)
{//printf("%s addr:%08x\r\n", __func__, addr);
return sdio_io_readl(func, addr, err_ret);
}
void sdio_writel(struct sdio_func *func, uint32_t v, unsigned int addr, int *err_ret)
{
int err = 0;//printf("%s addr:%08x\r\n", __func__, addr);
err= sdio_io_writel(func, v, addr);
if (NULL != err_ret)
*err_ret = err;
}
int sdio_memcpy_fromio(struct sdio_func *func, void *dst,
unsigned int addr, int count)
{
return sdio_io_rw_extended_block(func, 0, addr, 1, (uint8_t *)dst, count);
}
int sdio_memcpy_toio(struct sdio_func *func, unsigned int addr,
void *src, int count)
{
return sdio_io_rw_extended_block(func, 1, addr, 1, (uint8_t *)src, count);
}
int wifi_read(struct sdio_func *func, u32 addr, u32 cnt, void *pdata)
{
int err;//printf("%s addr:%08x\r\n", __func__, addr);
sdio_claim_host(func);
err = sdio_memcpy_fromio(func, pdata, (unsigned int)addr, (int)cnt);
if (err) {
//dbg_host("%s: FAIL(%d)! ADDR=%#x Size=%d\n", __func__, err, addr, cnt);
}
sdio_release_host(func);
return err;
}
int wifi_write(struct sdio_func *func, u32 addr, u32 cnt, void *pdata)
{
int err;
u32 size;//printf("%s addr:%08x\r\n", __func__, addr);
sdio_claim_host(func);
size = cnt;
err = sdio_memcpy_toio(func, addr, pdata, size);
if (err) {
//dbg_host("%s: FAIL(%d)! ADDR=%#x Size=%d(%d)\n", __func__, err, addr, cnt, size);
}
sdio_release_host(func);
return err;
}
u8 wifi_readb(struct sdio_func *func, u32 addr)
{
int err;
u8 ret = 0;//printf("%s addr:%08x\r\n", __func__, addr);
sdio_claim_host(func);
ret = sdio_readb(func, ADDR_MASK | addr, &err);
sdio_release_host(func);
if (err) {
//dbg_host("%s: FAIL!(%d) addr=0x%05x\n", __func__, err, addr);
}
return ret;
}
u16 wifi_readw(struct sdio_func *func, u32 addr)
{
int err;
u16 v;//printf("%s addr:%08x\r\n", __func__, addr);
sdio_claim_host(func);
v = sdio_readw(func, ADDR_MASK | addr, &err);
sdio_release_host(func);
if (err) {
//dbg_host("%s: FAIL!(%d) addr=0x%05x\n", __func__, err, addr);
}
return v;
}
u32 wifi_readl(struct sdio_func *func, u32 addr)
{
int err;
u32 v;//printf("%s addr:%08x\r\n", __func__, addr);
sdio_claim_host(func);
v = sdio_readl(func, ADDR_MASK | addr, &err);
sdio_release_host(func);
return v;
}
void wifi_writeb(struct sdio_func *func, u32 addr, u8 val)
{
int err;
//printf("%s addr:%08x\r\n", __func__, addr);
sdio_claim_host(func);
sdio_writeb(func, val, ADDR_MASK | addr, &err);
sdio_release_host(func);
if (err) {
//dbg_host("%s: FAIL!(%d) addr=0x%05x val=0x%02x\n", __func__, err, addr, val);
}
}
void wifi_writew(struct sdio_func *func, u32 addr, u16 v)
{
int err;
//printf("%s addr:%08x\r\n", __func__, addr);
sdio_claim_host(func);
sdio_writew(func, v, ADDR_MASK | addr, &err);
sdio_release_host(func);
if (err) {
//dbg_host("%s: FAIL!(%d) addr=0x%05x val=0x%04x\n", __func__, err, addr, v);
}
}
void wifi_writel(struct sdio_func *func, u32 addr, u32 v)
{
int err;
//printf("%s addr:%08x\r\n", __func__, addr);
sdio_claim_host(func);
sdio_writel(func, v, ADDR_MASK | addr, &err);
sdio_release_host(func);
}
u8 wifi_readb_local(struct sdio_func *func, u32 addr)
{
int err;
u8 ret = 0;//printf("%s addr:%08x\r\n", __func__, addr);
ret = sdio_readb(func, LOCAL_ADDR_MASK | addr, &err);
return ret;
}
void wifi_writeb_local(struct sdio_func *func, u32 addr, u8 val)
{
int err;//printf("%s addr:%08x\r\n", __func__, addr);
sdio_writeb(func, val, LOCAL_ADDR_MASK | addr, &err);
}
extern int rtw_fake_driver_probe(struct sdio_func *func);
void wifi_fake_driver_probe_rtlwifi(struct sdio_func *func)
{
rtw_fake_driver_probe(func);//todo1
}
extern int sdio_bus_probe(void);
extern int sdio_bus_remove(void);
SDIO_BUS_OPS rtw_sdio_bus_ops = {
sdio_bus_probe,
sdio_bus_remove,
sdio_enable_func,
sdio_disable_func,
NULL,
NULL,
sdio_claim_irq,
sdio_release_irq,
sdio_claim_host,
sdio_release_host,
sdio_readb,
sdio_readw,
sdio_readl,
sdio_writeb,
sdio_writew,
sdio_writel,
sdio_memcpy_fromio,
sdio_memcpy_toio
};
#endif

View File

@ -0,0 +1,62 @@
#ifndef _WIFI_IO_H
#define _WIFI_IO_H
//#include "core/sdio_irq.h"
struct sdio_driver {
int fake;
};
//#define sdio_func sdio_function
#ifndef u32
#define u32 uint32_t
#endif
#ifndef u16
#define u16 uint16_t
#endif
#ifndef u8
#define u8 uint8_t
#endif
#ifndef BIT
#define BIT(_x) (1 << (_x))
#endif
int wifi_read(struct sdio_func *func, u32 addr, u32 cnt, void *pdata);
int wifi_write(struct sdio_func *func, u32 addr, u32 cnt, void *pdata);
u8 wifi_readb(struct sdio_func *func, u32 addr);
u16 wifi_readw(struct sdio_func *func, u32 addr);
u32 wifi_readl(struct sdio_func *func, u32 addr);
void wifi_writeb(struct sdio_func *func, u32 addr, u8 val);
void wifi_writew(struct sdio_func *func, u32 addr, u16 v);
void wifi_writel(struct sdio_func *func, u32 addr, u32 v);
u8 wifi_readb_local(struct sdio_func *func, u32 addr);
void wifi_writeb_local(struct sdio_func *func, u32 addr, u8 val);
//typedef unsigned long UINT32;
typedef struct _SDIO_BUS_OPS{
int (*bus_probe)(void);
int (*bus_remove)(void);
int (*enable)(struct sdio_func*func); /*enables a SDIO function for usage*/
int (*disable)(struct sdio_func *func);
int (*reg_driver)(struct sdio_driver*); /*register sdio function device driver callback*/
void (*unreg_driver)(struct sdio_driver *);
int (*claim_irq)(struct sdio_func *func, void(*handler)(struct sdio_func *));
int (*release_irq)(struct sdio_func*func);
void (*claim_host)(struct sdio_func*func); /*exclusively claim a bus for a certain SDIO function*/
void (*release_host)(struct sdio_func *func);
unsigned char (*readb)(struct sdio_func *func, unsigned int addr, int *err_ret);/*read a single byte from a SDIO function*/
unsigned short (*readw)(struct sdio_func *func, unsigned int addr, int *err_ret); /*read a 16 bit integer from a SDIO function*/
unsigned int (*readl)(struct sdio_func *func, unsigned int addr, int *err_ret); /*read a 32 bit integer from a SDIO function*/
void (*writeb)(struct sdio_func *func, unsigned char b,unsigned int addr, int *err_ret); /*write a single byte to a SDIO function*/
void (*writew)(struct sdio_func *func, unsigned short b,unsigned int addr, int *err_ret); /*write a 16 bit integer to a SDIO function*/
void (*writel)(struct sdio_func *func, unsigned int b,unsigned int addr, int *err_ret); /*write a 32 bit integer to a SDIO function*/
int (*memcpy_fromio)(struct sdio_func *func, void *dst,unsigned int addr, int count);/*read a chunk of memory from a SDIO functio*/
int (*memcpy_toio)(struct sdio_func *func, unsigned int addr,void *src, int count); /*write a chunk of memory to a SDIO function*/
}SDIO_BUS_OPS;
extern SDIO_BUS_OPS rtw_sdio_bus_ops;
extern struct sdio_func *wifi_sdio_func;
extern int sdio_bus_probe(void);
extern int sdio_bus_remove(void);
#endif

View File

@ -0,0 +1,454 @@
#include "usb_io_realtek.h"
#define REALTEK_USB_VENQT_READ 0xC0
#define REALTEK_USB_VENQT_WRITE 0x40
#define RTW_USB_CONTROL_MSG_TIMEOUT 500//ms
#define FW_START_ADDRESS 0x1000
#define VENDOR_CMD_MAX_DATA_LEN 254
#define ALIGNMENT_UNIT 32
#define MAX_VENDOR_REQ_CMD_SIZE 254 /* 8188cu SIE Support */
#define MAX_USB_IO_CTL_SIZE (MAX_VENDOR_REQ_CMD_SIZE + ALIGNMENT_UNIT)
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#ifndef NULL
#define NULL 0
#endif
#ifndef BIT
#define BIT(_x) (1 << (_x))
#endif
struct rtw_urb
{
struct urb urb;
bool is_used;
};
#define MaxurbNum 40
static struct rtw_urb rtw_urb_read[MaxurbNum];
static struct rtw_urb rtw_urb_write[MaxurbNum];
int rtw_usb_rcvctrlpipe(struct usb_device *dev, u32 endpoint)
{
return usb_rcvctrlpipe(dev,endpoint);
}
int rtw_usb_sndctrlpipe(struct usb_device *dev, u32 endpoint)
{
return usb_sndctrlpipe(dev,endpoint);
}
int rtw_usb_get_bulk_in_pipe(void *priv,unsigned char ep_addr)
{
struct usb_interface *pusb_intf = (struct usb_interface *)priv;
struct usb_device *udev = pusb_intf->usb_dev;
return usb_rcvbulkpipe(udev,ep_addr);
}
int rtw_usb_get_bulk_out_pipe(void *priv,unsigned char ep_addr)
{
struct usb_interface *pusb_intf = (struct usb_interface *)priv;
struct usb_device *udev = pusb_intf->usb_dev;
return usb_sndbulkpipe(udev,ep_addr);
}
struct urb * rtw_usb_alloc_urb(u16 iso_packets, int mem_flags)
{
//return usb_alloc_urb(iso_packets,mem_flags);
return usb_alloc_urb(iso_packets); //xhl
}
void rtw_usb_free_urb(struct urb *urb)
{
usb_free_urb(urb);
}
void rtw_usb_kill_urb(struct urb *urb)
{
usb_kill_urb(urb);
}
int rtw_usb_submit_urb(struct urb *urb, int mem_flags)
{
// return usb_submit_urb(urb, mem_flags);
return usb_submit_urb(urb); //xhl
}
void rtw_usb_fill_bulk_urb(struct urb *urb,struct usb_device *pDev,u32 Pipe,void *pTransferBuffer,s32 Length,usb_complete_t tCompleteFunc,void *pContext)
{
usb_fill_bulk_urb(urb,pDev, Pipe,pTransferBuffer,Length, tCompleteFunc,pContext);
}
int rtw_usb_register(struct usb_driver *driver)
{
return usb_register_driver(driver);
}
void rtw_usb_deregister(struct usb_driver *driver)
{
usb_deregister(driver);
}
int usbctrl_vendorreq(void *priv,unsigned char bdir_in,unsigned short value,unsigned char *buf,unsigned int len)
{
struct usb_interface *pusb_intf = (struct usb_interface *)priv;
struct usb_device *udev = pusb_intf->usb_dev;
unsigned char request = 0x05;
unsigned int pipe;
int status = 0;
unsigned char reqtype;
unsigned char *pIo_buf;
int vendorreq_times = 0;
unsigned char tmp_buf[MAX_USB_IO_CTL_SIZE];
/* Acquire IO memory for vendorreq */
if (len > MAX_VENDOR_REQ_CMD_SIZE) {
printf("[%s] Buffer len error ,vendor request failed\n", __FUNCTION__);
status = -22;
goto exit;
}
/* Added by Albert 2010/02/09 */
/* For mstar platform, mstar suggests the address for USB IO should be 32 bytes alignment. */
/* Trying to fix it here. */
pIo_buf = tmp_buf + ALIGNMENT_UNIT - ((unsigned int)(tmp_buf) & 0x1f);//32字节对齐
while (++vendorreq_times <= 10) {
rtw_memset(pIo_buf, 0, len);
if (bdir_in == 0x01) {
pipe = usb_rcvctrlpipe(udev, 0);/* read_in */
reqtype = REALTEK_USB_VENQT_READ;
} else {
pipe = usb_sndctrlpipe(udev, 0);/* write_out */
reqtype = REALTEK_USB_VENQT_WRITE;
rtw_memcpy(pIo_buf, buf, len);
}
status = usb_control_msg(udev, pipe, request, reqtype, value, 0, pIo_buf, len, RTW_USB_CONTROL_MSG_TIMEOUT);
if (status == len) { /* Success this control transfer. */
if (bdir_in == 0x01) {
/* For Control read transfer, we have to copy the read data from pIo_buf to pdata. */
rtw_memcpy(buf, pIo_buf, len);
}
} else { /* error cases */
printf("reg 0x%x, usb %s %u fail, status:%d value=0x%x, vendorreq_times:%d\n"
, value, (bdir_in == 0x01) ? "read" : "write" , len, status, *(u32 *)buf, vendorreq_times);
}
/* firmware download is checksumed, don't retry */
if ((value >= FW_START_ADDRESS) || status == len)
break;
}
exit:
return status;
}
extern void usb_read_port_complete(void *arg, unsigned int result);
static int rtw_usb_read_complete(struct urb* purb)
{
int i =0;
usb_read_port_complete(purb->context, purb->actual_length);
if (purb->status != 0){
printf("\r\n###=> rtw_usb_read_port_complete => urb.status(%d)\n", purb->status);
}
for(;i<MaxurbNum;i++){
if(&(rtw_urb_read[i].urb) == purb){
rtw_memset(purb, 0, sizeof(rtw_urb_read[i].urb));
rtw_urb_read[i].is_used = 0;
break;
}
}
if(i ==MaxurbNum ){
printf("\r\n Error: some urb pointer we want read have not recored!");
}
usb_free_urb(purb);
return purb->status;
}
static int rtw_usb_bulk_in(void *priv,unsigned char pipe,unsigned char *buf,unsigned int len,usb_complete_t callback,void *arg){
struct usb_interface *pusb_intf = (struct usb_interface *)priv;
struct usb_device *udev = pusb_intf->usb_dev;
int status;
int i = 0;
struct urb *purb;
for(;i<MaxurbNum;i++){
if(!(rtw_urb_read[i].is_used)){
rtw_urb_read[i].is_used = 1; //set the used to 1 first then use it
purb = &rtw_urb_read[i].urb;
rtw_memset(purb, 0, sizeof(rtw_urb_read[i].urb));
break;
}
}
if(i == MaxurbNum)
printf("\r\n Error: something error in urb allocate in %s",__func__);
usb_fill_bulk_urb(purb,
udev,
pipe,
buf,
len,
rtw_usb_read_complete,
arg);
status = usb_submit_urb(purb);
return status;
}
extern void usb_write_port_complete(void *arg, unsigned int result);
static int rtw_usb_write_complete(struct urb* purb)
{
int i = 0;
if (purb->status == 0){
usb_write_port_complete(purb->context, purb->actual_length);
}else{
printf("\r\n###=> rtw_usb_write_port_complete => urb.status(%d)\n", purb->status);
}
for(;i<MaxurbNum;i++){
if(&(rtw_urb_write[i].urb) == purb){
rtw_memset(purb, 0, sizeof(rtw_urb_write[i].urb));
rtw_urb_write[i].is_used = 0;
break;
}
}
if(i ==MaxurbNum ){
printf("\r\n Error: some urb pointer we want write have not recored!");
}
usb_free_urb(purb);
return purb->status;
}
static int rtw_usb_bulk_out(void *priv,unsigned char pipe,unsigned char *buf,unsigned int len,usb_complete callback,void *arg){
struct usb_interface *pusb_intf = (struct usb_interface *)priv;
struct usb_device *udev = pusb_intf->usb_dev;
int status;
int i = 0;
struct urb *purb;
for(;i<MaxurbNum;i++){
if(!(rtw_urb_write[i].is_used)){
rtw_urb_write[i].is_used = 1; //set the used to 1 first then use it
purb = &(rtw_urb_write[i].urb);
rtw_memset(purb, 0, sizeof(rtw_urb_write[i].urb));
break;
}
}
if(i == MaxurbNum)
printf("\r\n Error: something error in urb allocate in %s",__func__);
usb_fill_bulk_urb(purb,
udev,
pipe,
buf,
len,
rtw_usb_write_complete,
arg);
status = usb_submit_urb(purb);
return status;
}
static int rtw_usb_cancel_bulk_out(void *priv)
{
struct usb_interface *pusb_intf = (struct usb_interface *)priv;
int i = 0;
for(;i<MaxurbNum;i++){
if(rtw_urb_write[i].is_used){
usb_kill_urb(&(rtw_urb_write[i].urb));
rtw_memset(&(rtw_urb_write[i].urb), 0, sizeof(rtw_urb_write[i].urb));
rtw_urb_write[i].is_used = 0;
}
}
return 0;
}
static int rtw_usb_cancel_bulk_in(void *priv)
{
struct usb_interface *pusb_intf = (struct usb_interface *)priv;
int i = 0;
for(;i<MaxurbNum;i++){
if(rtw_urb_read[i].is_used){
usb_kill_urb(&(rtw_urb_read[i].urb));
rtw_memset(&(rtw_urb_read[i].urb), 0, sizeof(rtw_urb_read[i].urb));
rtw_urb_read[i].is_used = 0;
}
}
return 0;
}
static int rtw_usb_ctrl_req(void *priv,unsigned char bdir_in,unsigned short wvalue,unsigned char *buf,unsigned int len)
{
return usbctrl_vendorreq(priv,bdir_in,wvalue,buf,len);
}
enum RTW_USB_SPEED {
RTW_USB_SPEED_UNKNOWN = 0,
RTW_USB_SPEED_1_1 = 1,
RTW_USB_SPEED_2 = 2,
RTW_USB_SPEED_3 = 3,
};
static inline int RT_usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd)
{
return (epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN;
}
static inline int RT_usb_endpoint_dir_out(const struct usb_endpoint_descriptor *epd)
{
return (epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT;
}
static inline int RT_usb_endpoint_xfer_int(const struct usb_endpoint_descriptor *epd)
{
return (epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT;
}
static inline int RT_usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor *epd)
{
return (epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK;
}
static inline int RT_usb_endpoint_is_bulk_in(const struct usb_endpoint_descriptor *epd)
{
return RT_usb_endpoint_xfer_bulk(epd) && RT_usb_endpoint_dir_in(epd);
}
static inline int RT_usb_endpoint_is_bulk_out(const struct usb_endpoint_descriptor *epd)
{
return RT_usb_endpoint_xfer_bulk(epd) && RT_usb_endpoint_dir_out(epd);
}
static inline u8 RT_usb_endpoint_is_int_in(const struct usb_endpoint_descriptor *epd)
{
return RT_usb_endpoint_xfer_int(epd) && RT_usb_endpoint_dir_in(epd);
}
static inline u8 RT_usb_endpoint_num(const struct usb_endpoint_descriptor *epd)
{
return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
}
void rtw_usb_disendpoint(u8 nr_endpoint,void *priv)
{
struct usb_interface *pusb_intf = (struct usb_interface *)priv;
struct usb_device *pusbd = pusb_intf->usb_dev;
struct usb_host_interface *phost_iface;
struct usb_host_endpoint *phost_endp;
int i;
phost_iface = &pusb_intf->altsetting[0];
for (i = 0; i < nr_endpoint; i++) {
phost_endp = phost_iface->endpoint + i;
if (phost_endp) {
usb_hcd_disable_endpoint(pusbd, phost_endp);
}
}
pusb_intf->user_data = NULL;
}
static int rtw_usb_get_speed_info(void *priv)
{
struct usb_interface *pusb_intf = (struct usb_interface *)priv;
struct usb_device *pusbd;
pusbd = pusb_intf->usb_dev;
int speed;
switch (pusbd->speed) {
case 1:
printf("Low Speed Case \n");
(speed) = RTW_USB_SPEED_1_1;
break;
case 2:
printf("full speed Case \n");
(speed) = RTW_USB_SPEED_1_1;
break;
case 3:
printf("high speed Case \n");
(speed) = RTW_USB_SPEED_2;
break;
default:
(speed) = RTW_USB_SPEED_UNKNOWN;
break;
}
if ((speed) == RTW_USB_SPEED_UNKNOWN)
pusb_intf->user_data = NULL;
return speed;
}
static int rtw_usb_get_in_ep_info(void *priv,unsigned char *pipe_num_arrays)
{
struct usb_interface *pusb_intf = (struct usb_interface *)priv;
struct usb_host_endpoint *phost_endp;
struct usb_endpoint_descriptor *pendp_desc;
struct usb_host_interface *phost_iface;
struct usb_interface_descriptor *piface_desc;
int NumInPipes = 0;
int nr_endpoint;
int i;
phost_iface = &pusb_intf->cur_altsetting[0];
piface_desc = &phost_iface->desc;
nr_endpoint = piface_desc->bNumEndpoints;
for (i = 0; i < (nr_endpoint); i++) {
phost_endp = phost_iface->endpoint + i;
if (phost_endp) {
pendp_desc = &phost_endp->desc;
printf("\nusb_endpoint_descriptor(%d):\n", i);
printf("bLength=%x\n", pendp_desc->bLength);
printf("bDescriptorType=%x\n", pendp_desc->bDescriptorType);
printf("bEndpointAddress=%x\n", pendp_desc->bEndpointAddress);
printf("wMaxPacketSize=%d\n", pendp_desc->wMaxPacketSize);
printf("bInterval=%x\n", pendp_desc->bInterval);
if (RT_usb_endpoint_is_bulk_in(pendp_desc)) {
pipe_num_arrays[NumInPipes] = RT_usb_endpoint_num(pendp_desc);
(NumInPipes)++;
} else if (RT_usb_endpoint_is_int_in(pendp_desc)) {
printf("\r\n RT_usb_endpoint_is_int_in = %x, Interval = %x", RT_usb_endpoint_num(pendp_desc), pendp_desc->bInterval);
pipe_num_arrays[NumInPipes] = RT_usb_endpoint_num(pendp_desc);
(NumInPipes)++;
}
}
}
return NumInPipes;
}
static int rtw_usb_get_out_ep_info(void *priv,u8 *pipe_num_array)
{
struct usb_interface *pusb_intf = (struct usb_interface *)priv;
struct usb_host_endpoint *phost_endp;
struct usb_endpoint_descriptor *pendp_desc;
struct usb_host_interface *phost_iface;
struct usb_interface_descriptor *piface_desc;
int NumOutPipes = 0;
int nr_endpoint;
int i;
phost_iface = &pusb_intf->cur_altsetting[0];
piface_desc = &phost_iface->desc;
nr_endpoint = piface_desc->bNumEndpoints;
for (i = 0; i < (nr_endpoint); i++) {
phost_endp = phost_iface->endpoint + i;
if (phost_endp) {
pendp_desc = &phost_endp->desc;
if (RT_usb_endpoint_is_bulk_out(pendp_desc)) {
printf("\r\n RT_usb_endpoint_is_bulk_out = %x\n", RT_usb_endpoint_num(pendp_desc));
pipe_num_array[NumOutPipes] = RT_usb_endpoint_num(pendp_desc);
(NumOutPipes)++;
}
}
}
return NumOutPipes;
}
extern USB_BUS_OPS rtw_usb_bus_ops= {
rtw_usb_register,
rtw_usb_deregister,
rtw_usb_disendpoint,
rtw_usb_ctrl_req,
rtw_usb_get_speed_info,
rtw_usb_get_in_ep_info,
rtw_usb_get_out_ep_info,
rtw_usb_get_bulk_in_pipe,
rtw_usb_get_bulk_out_pipe,
rtw_usb_bulk_in,
rtw_usb_bulk_out,
rtw_usb_cancel_bulk_in,
rtw_usb_cancel_bulk_out,
};

View File

@ -0,0 +1,31 @@
#ifndef _USB_IO_REALTEK_H
#define _USB_IO_REALTEK_H
#include "customer_rtos_service.h"
#include <usb.h>
typedef struct USB_DATA_S{
void *usb_intf;
}USB_DATA,*PUSB_DATA;
typedef void (*usb_complete)(void *arg, unsigned int result);
typedef struct _USB_BUS_OPS{
int (*register_drv)(struct usb_driver *driver);
void (*deregister_drv)(struct usb_driver *driver);
void (*usb_disendpoint)(u8 nr_endpoint,void *priv);
int (*usb_ctrl_req)(void *priv,unsigned char bdir_in,unsigned short wvalue,unsigned char *buf,unsigned int len);
int (*usb_get_speed_info)(void *priv);
int (*usb_get_in_ep_info)(void *priv,unsigned char *pipe_num_array);
int (*usb_get_out_ep_info)(void *priv,unsigned char *pipe_num_array);
unsigned char(*usb_get_bulk_in_pipe)(void *priv,unsigned char ep_addr);
unsigned char(*usb_get_bulk_out_pipe)(void *priv,unsigned char ep_addr);
int (*usb_bulk_in)(void *priv,unsigned char pipe,unsigned char *buf,unsigned int len,usb_complete callback,void *arg);
int (*usb_bulk_out)(void *priv,unsigned char pipe,unsigned char *buf,unsigned int len,usb_complete callback,void *arg);
int (*usb_cancel_bulk_in)(void *priv);
int (*usb_cancel_bulk_out)(void *priv);
}USB_BUS_OPS;
extern USB_BUS_OPS rtw_usb_bus_ops;
#endif