usb_common.h

来自「AMLOGIC DPF source code」· C头文件 代码 · 共 236 行

H
236
字号
/*******************************************************************
 * 
 *  Copyright C 2005 by Amlogic, Inc. All Rights Reserved.
 *
 *  Description: 
 *
 *  Author: Amlogic Software
 *  Created: Fri Nov 11 00:10:37 2005
 *
 *******************************************************************/
#ifndef __USB_COMMON_H_
#define __USB_COMMON_H_
#ifndef AVOS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#endif

#ifdef AVOS
#include <stdint.h>
#include <volatile_read.h>
#endif

typedef unsigned long  uint64_t;

typedef unsigned long	loff_t;
typedef unsigned long	dma_addr_t;
typedef unsigned long	spinlock_t;

/*
 * IRQ_NONE means we didn't handle it.
 * IRQ_HANDLED means that we did have a valid interrupt and handled it.
 * IRQ_RETVAL(x) selects on the two depending on x being non-zero (for handled)
 */
typedef int irqreturn_t;

#define IRQ_NONE	(0)
#define IRQ_HANDLED	(1)
#define IRQ_RETVAL(x)	((x) != 0)

/* for portability, arc is already little endian */
#define	__constant_cpu_to_le16(x)	(x)
#define	__constant_cpu_to_le32(x)	(x)
#define	cpu_to_le16(x)			(x)
#define  cpu_to_le32(x)			(x)
#define	le16_to_cpu(x)			(x)
#define	le32_to_cpu(x)			(x)

#define	local_irq_disable()		OS_ENTER_CRITICAL()
#define	local_irq_enable()		OS_EXIT_CRITICAL()
#define	local_irq_save(x)		(x = OSCPUSaveSR())    /* Disable interrupts  */
#define	local_irq_restore(x)	(OSCPURestoreSR(x))    /* Enable  interrupts  */

#define	spin_lock_irqsave(x,flag)		local_irq_save(flag)
#define	spin_unlock_irqrestore(x,flag)	local_irq_restore(flag)

/* need not to be defined, 
 * for they used in_irq which is always high priority
 */
#define spin_lock(x)		do {} while (0)
#define spin_unlock(x)	do {} while (0)

#define spin_lock_irq(x)		do {} while (0)
#define spin_unlock_irq(x)	do {} while (0)

#define container_of(ptr, type, member) 	\
	((type *)(unsigned)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))

#define 	HZ 	(1000)		//1000ms

#ifndef __ROM_
//#define USB_DEBUG
#endif /* __ROM_ */

#ifdef __ROMDBG_
#define USB_DEBUG
int printk(const char * format, ...);
#else
/* debug utils */
#ifdef USB_DEBUG
#define printk	AVOS_printf_ext
#else
#define printk(x...)
#endif /* USB_DEBUG */
#endif

#define print_error     printk
#ifndef __BT_BUFF_H
    #define BUG()           while(1) {}
#endif

#define __func__        "func"

#define WARN_ON(x)		{ if(x) \
	printk("WARN_ON file %s, line %d\n", __FILE__, __LINE__); \
}

#define kmalloc(x)         AVMem_kmalloc(x)
#define kfree(x)        { if(x) AVMem_free(x); }

void wait_ns(unsigned int count);
#define wait_ms(x)		wait_ticks(OS_MILLIS_TO_TICKS(x))
void wait_ticks(unsigned int ticks);	// ticks < 65535
#define msleep wait_ms

/* debugging and troubleshooting/diagnostic helpers. */
#define dev_printk(level, arg...)	\
	printk(level arg)

#ifdef USB_DEBUG
#define dev_dbg(dev,  arg...)		\
    dev_printk(KERN_DEBUG ,  arg)
#else
#define dev_dbg(dev, arg...)        \
    do { (void)(dev); } while (0)
#endif

#define dev_err(dev,  arg...)		\
	dev_printk(KERN_ERR ,  arg)
#define dev_info(dev,  arg...)		\
	dev_printk(KERN_INFO ,  arg)
#define dev_warn(dev,  arg...)		\
	dev_printk(KERN_WARNING , arg)


/**********************************************************************/

#define MS_DEVICE_STYLE	0
#define PTP_DEVICE_STYLE	1

int find_next_zero_bit (void *addr, int size, int offset);
int clear_bit(int nr, void *addr);
int set_bit(int nr, void *addr);
int test_bit(int nr, const void * addr);
int test_and_set_bit(int nr, void * addr);
int test_and_clear_bit(int nr, void * addr);

int in_interrupt(void);

struct device {
	struct device 	* parent;

	void		*driver_data;	/* data private to the driver */
	void		*platform_data;	/* Platform specific data, device
					   core doesn't touch it */
	void		*firmware_data; /* Firmware specific data (e.g. ACPI,
					   BIOS data),reserved for device core*/
};


/**
 * struct usb_device_id - identifies USB devices for probing and hotplugging
 * @match_flags: Bit mask controlling of the other fields are used to match
 *	against new devices.  Any field except for driver_info may be used,
 *	although some only make sense in conjunction with other fields.
 *	This is usually set by a USB_DEVICE_*() macro, which sets all
 *	other fields in this structure except for driver_info.
 * @idVendor: USB vendor ID for a device; numbers are assigned
 *	by the USB forum to its members.
 * @idProduct: Vendor-assigned product ID.
 * @bcdDevice_lo: Low end of range of vendor-assigned product version numbers.
 *	This is also used to identify individual product versions, for
 *	a range consisting of a single device.
 * @bcdDevice_hi: High end of version number range.  The range of product
 *	versions is inclusive.
 * @bDeviceClass: Class of device; numbers are assigned
 *	by the USB forum.  Products may choose to implement classes,
 *	or be vendor-specific.  Device classes specify behavior of all
 *	the interfaces on a devices.
 * @bDeviceSubClass: Subclass of device; associated with bDeviceClass.
 * @bDeviceProtocol: Protocol of device; associated with bDeviceClass.
 * @bInterfaceClass: Class of interface; numbers are assigned
 *	by the USB forum.  Products may choose to implement classes,
 *	or be vendor-specific.  Interface classes specify behavior only
 *	of a given interface; other interfaces may support other classes.
 * @bInterfaceSubClass: Subclass of interface; associated with bInterfaceClass.
 * @bInterfaceProtocol: Protocol of interface; associated with bInterfaceClass.
 * @driver_info: Holds information used by the driver.  Usually it holds
 *	a pointer to a descriptor understood by the driver, or perhaps
 *	device flags.
 *
 * In most cases, drivers will create a table of device IDs by using
 * USB_DEVICE(), or similar macros designed for that purpose.
 * They will then export it to userspace using MODULE_DEVICE_TABLE(),
 * and provide it to the USB core through their usb_driver structure.
 *
 * See the usb_match_id() function for information about how matches are
 * performed.  Briefly, you will normally use one of several macros to help
 * construct these entries.  Each entry you provide will either identify
 * one or more specific products, or will identify a class of products
 * which have agreed to behave the same.  You should put the more specific
 * matches towards the beginning of your table, so that driver_info can
 * record quirks of specific products.
 */
struct usb_device_id {
	/* which fields to match against? */
	__u16		match_flags;

	/* Used for product specific matches; range is inclusive */
	__u16		idVendor;
	__u16		idProduct;
//	__u16		bcdDevice_lo;
//	__u16		bcdDevice_hi;

	/* Used for device class matches */
//	__u8		bDeviceClass;
//	__u8		bDeviceSubClass;
//	__u8		bDeviceProtocol;

	/* Used for interface class matches */
//	__u8		bInterfaceClass;
//	__u8		bInterfaceSubClass;
//	__u8		bInterfaceProtocol;

	/* not matched against */
//	kernel_ulong_t	driver_info;
};

/* Some useful macros to use to create struct usb_device_id */
#define USB_DEVICE_ID_MATCH_VENDOR		0x0001
#define USB_DEVICE_ID_MATCH_PRODUCT		0x0002
#define USB_DEVICE_ID_MATCH_DEV_LO		0x0004
#define USB_DEVICE_ID_MATCH_DEV_HI		0x0008
#define USB_DEVICE_ID_MATCH_DEV_CLASS		0x0010
#define USB_DEVICE_ID_MATCH_DEV_SUBCLASS	0x0020
#define USB_DEVICE_ID_MATCH_DEV_PROTOCOL	0x0040
#define USB_DEVICE_ID_MATCH_INT_CLASS		0x0080
#define USB_DEVICE_ID_MATCH_INT_SUBCLASS	0x0100
#define USB_DEVICE_ID_MATCH_INT_PROTOCOL	0x0200
#define USB_DEVICE_ID_MATCH_DEVICE          (USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT)

#define USB_DEVICE_DECL(vend,prod) \
    USB_DEVICE_ID_MATCH_DEVICE, (vend), (prod)

#endif /* __USB_COMMON_H_ */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?