⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hal_intf.h

📁 philips公司ISP1362 USB OTG控制芯片的驱动
💻 H
📖 第 1 页 / 共 2 页
字号:
 * DC endpoint interrupt for endpoint (x: 1<=x<=14)
 */
#define		DC_EP_INT(x)			((0x00000200) << x)

/***** OTG Registers ****/
#define		OTG_CTRL_REG			0x62	/* OTG Control Register */
#define		OTG_STATUS_REG			0x67	/* OTG Status Register (read only) */
#define		OTG_INT_REG				0x68	/* OTG Interrupt Register */
#define		OTG_INT_EN_REG			0x69	/* OTG interrupt Enable register */
#define		OTG_TIMER_REG			0x6A	/* OTG timer register */
#define		OTG_ALT_TIMER_REG		0x6C	/* OTG alternate timer register
											   used for caliberation */

/* OTG_INT_REG */
#define 		OTG_ID_INT			0x0001
#define 		OTG_A_VBUS_VLD_INT	0x0002
#define 		OTG_B_SESS_END_INT	0x0004
#define			OTG_A_SESS_VLD_INT	0x0008
#define			OTG_B_SESS_VLD_INT	0x0010
#define 		OTG_RMT_CONN_INT	0x0020
#define 		OTG_SUSPEND_INT		0x0040
#define 		OTG_RESUME_INT		0x0080
#define 		OTG_SRP_DET_INT		0x0100
#define 		OTG_SE0_SRP_INT		0x0200
#define 		OTG_TMR_INT			0x0400

#define			OTG_INT_MASK		(OTG_ID_INT | OTG_A_VBUS_VLD_INT | OTG_B_SESS_END_INT | OTG_A_SESS_VLD_INT | OTG_B_SESS_VLD_INT | OTG_RMT_CONN_INT | OTG_SUSPEND_INT | OTG_RESUME_INT | OTG_SRP_DET_INT | OTG_SE0_SRP_INT | OTG_TMR_INT )

#include <linux/list.h>

typedef struct isp1362_dev {
	struct	isp1362_driver *driver;			/* which driver has allocated this 
											device */
	void			*driver_data;	/* data private to the driver */
	unsigned char	index;		/* local controller (HC/DC/OTG) */
	unsigned int	irq;	/* Interrupt Channel allocated for this device */
    void (*handler)(struct isp1362_dev *dev, 
					void *isr_data);	/* Interrupt Serrvice Routine */
	void			*isr_data;			/* isr data of the driver */
	unsigned long	int_reg;			/* Interrupt register */
	unsigned long	alt_int_reg;			/* Interrupt register 2*/

	struct resource	*io_res;
	unsigned long	io_base;			/* Start Io address space for this device */
	unsigned long	io_len;				/* IO address space length for this device */
	unsigned long	io_data;			/* IO Port for Data access */
	unsigned long	io_cmd;				/* IO Port for Command access */
	unsigned short	chip_id;			/* Chip Id */

	char			name[80];			/* device name */
	int				active;				/* device status */

	/* DMA resources should come TODO */
	unsigned long	dma;

}isp1362_dev_t ;

typedef struct isp1362_driver {
	struct list_head node;
	char 			*name;
	unsigned long	index;						/* HC or DC or OTG */
	int (*probe)(struct isp1362_dev *dev);		/* New device inserted */
	void (*remove)(struct isp1362_dev *dev);	/* Device removed (NULL if not a hot-plug capable driver) */

#ifdef CONFIG_PM
	void (*suspend)(struct isp1362_dev *dev);	/* Device suspended */
	void (*resume)(struct isp1362_dev *dev);	/* Device woken up */
#endif /* CONFIG_PM */

} isp_1362_driver_t;


extern	int		isp1362_register_driver(struct isp1362_driver *drv);
extern	void	isp1362_unregister_driver(struct isp1362_driver *drv);

/* these external functions for porting  */
extern	int	isp1362_check_io_region(struct isp1362_dev *dev);
extern	struct resource*	isp1362_request_io_region(struct isp1362_dev	*dev);
extern	void isp1362_release_io_region(struct isp1362_dev *dev);
extern int isp1362_request_irq(void (*handler)(struct isp1362_dev *dev, void *isr_data),
                       struct isp1362_dev *dev, void *isr_data);
extern void isp1362_free_irq(struct isp1362_dev *dev, void *isr_data);

extern __u16	isp1362_reg_read16(struct isp1362_dev *dev, __u16 reg);
extern void	isp1362_reg_write16(struct isp1362_dev *dev, __u16 reg, __u16 data);
extern __u32	isp1362_reg_read32(struct isp1362_dev *dev, __u16 reg);
extern void	isp1362_reg_write32(struct isp1362_dev *dev, __u16 reg, __u32 data);

/* DMA relared functions */
extern	void*	isp1362_alloc_dma_buff(void);
extern	void	isp1362_free_dma_buff(void* dma_buff);
extern 	void	isp1362_set_dma_config(unsigned long	controller);
extern	int 	isp1362_request_dma(unsigned int dmanr, const char * device_id);
extern 	void 	isp1362_free_dma(unsigned int dmanr);
extern 	void 	isp1362_enable_dma_tx(unsigned long dmanr, char mode, void *dma_buff);
extern 	void 	isp1362_disable_dma_tx(unsigned long dmanr, char mode, void *dma_buff);

extern 	void 	isp1362_set_hw_config(struct isp1362_dev *dev);


extern	void	isp1362_enable_interrupt(int	irq);
extern	void	isp1362_disable_interrupt(int	irq);

/* The bus interface header file should provide the following macros
isp1362_command(reg,dev)
isp1362_read8(dev)
isp1362_read16(dev)
isp1362_write8(data,dev)
isp1362_write16(data,dev)
isp1362_printk()
isp1362_vendor_id
isp1362_product_id
*/
#ifdef CONFIG_1362_PCI
#include "x86pci/hal_pci.h"
#endif

#ifdef CONFIG_1362_PXA250
#include "pxa250/hal_pxa250.h"
#endif

/* IO Access Functions */
#define	 isp1362_reg_read16(dev,reg,data)	\
			isp1362_command(reg,dev);		\
			isp1362_cmd_delay();			\
			data = isp1362_read16(dev)

#define	 isp1362_reg_write16(dev,reg,data)	\
			isp1362_command(reg,dev);		\
			isp1362_cmd_delay();			\
			isp1362_write16(data,dev)

#define	 isp1362_reg_read32(dev,reg,data)	\
			isp1362_command(reg,dev);		\
			isp1362_cmd_delay();			\
			data = isp1362_read16(dev);		\
			data |= (isp1362_read16(dev) <<16)

#define	 isp1362_reg_write32(dev,reg,data)			\
			isp1362_command(reg,dev);				\
			isp1362_cmd_delay();					\
			isp1362_write16((data&0x0000FFFF),dev);	\
			isp1362_write16(((data&0xFFFF0000)>>16),dev)

/* This method uses PIO to transfer data to ISP1362
 * Assumptions for HC:
 *  This program uses IO access to the nearest next
 *  even number. So this program assumes that the
 *  HC transfer counter is programmed to the nearest
 *  even number
 *  Assumptions for DC:
 *  This program reads the bytes from the end point
 *  buffer and if the buffer suze from,DC is less
 *  than the 'len' the 'len' will get updataed to the
 *  endpoint buffer length
 */
#define	isp1362_buff_read(dev, reg, bufp, len)	\
{												\
	__u16	cnt = 0,data;						\
	__u8	*buff = bufp;						\
												\
	isp1362_command(reg, dev);					\
	isp1362_cmd_delay();						\
	isp1362_cmd_delay();						\
	if(dev->index == ISP1362_DC) {				\
		len = isp1362_read16(dev);				\
	}											\
	while((cnt + 1) < len) {					\
		data = isp1362_read16(dev);				\
		*buff++ = data; 						\
		*buff++ = (data >> 8);					\
		cnt+=2;									\
	}											\
	if(len%2 == 1){								\
		data = isp1362_read16(dev);				\
		*buff++ = data;							\
	}											\
}

/* This method uses PIO to transfer data from ISP1362
 * Assumptions for HC:
 *  This program uses IO access to the nearest next
 *  even number. So this program assumes that the
 *  HC transfer counter is programmed to the nearest
 *  even number
 *  Assumptions for DC:
 *  This program reads the bytes from the end point
 *  buffer and if the buffer suze from,DC is less
 *  than the 'len' the 'len' will get updataed to the
 *  endpoint buffer length
 */
#define	isp1362_buff_write(dev, reg, bufp, len)	\
{												\
	__u16	cnt = 0,data;						\
	__u8	*buff = bufp;						\
												\
	isp1362_command(reg, dev);					\
	isp1362_cmd_delay();						\
	isp1362_cmd_delay();						\
	if(dev->index == ISP1362_DC) {				\
		isp1362_write16(len,dev);				\
	}											\
	while((cnt + 1) < len) {					\
		data = *buff++;							\
		data |= ((*buff++) << 8);				\
		cnt+=2;									\
		isp1362_write16(data,dev);				\
	}											\
	if(len%2 == 1){								\
		data = *buff++;							\
		isp1362_write16(data,dev);				\
	}											\
}


#define	isp1362_lock_irq(irq)					\
	do { 										\
		if(!(isp1362_in_int_lock(irq)))	{		\
			isp1362_disable_interrupt(irq);		\
			isp1362_set_int_lock(irq);			\
		}										\
	} while(0)

#define	isp1362_unlock_irq(irq)				\
	do { 									\
		if((isp1362_in_int_lock(irq)))	{	\
			isp1362_clear_int_lock(irq);	\
			isp1362_enable_interrupt(irq);	\
		}									\
	} while(0)

#if defined(CONFIG_FUNC_DEBUG) ||  defined(CONFIG_DETAIL_DEBUG)
#define	func_debug(args)	isp1362_printk args;
#else
#define	func_debug(args)
#endif /* CONFIG_FUNC_DEBUG || CONFIG_DETAIL_DEBUG */

#ifdef CONFIG_DETAIL_DEBUG
#define	detail_debug(args)	isp1362_printk args;
#else
#define	detail_debug(args)
#endif /*CONFIG_DETAIL_DEBUG */

/* This interface is used for sending information to the user
  of any stack activities from the kernel space. This is different
  from xxx_debug. This is used for some err cases to notify user */
#define isp1362_kernel_user_mesg(format, arg...) isp1362_printk(KERN_ERR __FILE__ ": " format "\n" , ## arg)


#endif /* __HAL_INTF_H__ */

⌨️ 快捷键说明

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