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

📄 usb_phci.c

📁 philips公司ISP1362 USB OTG控制芯片的驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
		return -ENOMEM;
	}

	phci->bus->root_hub = usb_dev;

	/* Connect the virtual hub to the usb bus, host stack will do all the enumeration,
	   configuration etc.. */
	usb_connect (usb_dev); 

	if(phci_hub_new_device(usb_dev) != 0) {
		usb_free_dev(usb_dev);
		phci->disabled = 1;
		return -ENODEV;
	}

	return 0;
} /* End of fnuPhciHostInit() */



/*--------------------------------------------------------------*
 * HC  TD-PTD functions 										* 
 *--------------------------------------------------------------*/

static __u8		td_ptd_buff_type_max_ptds[TD_PTD_TOTAL_BUFF_TYPES] = {
	TD_PTD_MAX_ATL_TDS,
	TD_PTD_MAX_INTL_TDS,
	TD_PTD_MAX_ISTL_TDS,
	TD_PTD_MAX_ISTL_TDS
};

static __u8		hc_ram_buff_port_reg[TD_PTD_TOTAL_BUFF_TYPES] = {
	REG_ATL_BUFF_PORT,
	REG_INTL_BUFF_PORT,
	REG_ISTL0_BUFF_PORT,
	REG_ISTL1_BUFF_PORT
};

static __u16	hc_ram_buff_lengths[TD_PTD_TOTAL_BUFF_TYPES] = {
	HC_ATL_BUFFER_LENGTH,
	HC_INTL_BUFFER_LENGTH,
	HC_ISTL_BUFFER_LENGTH,
	HC_ISTL_BUFFER_LENGTH
};

static __u16	hc_ram_buff_block_pl_size[TD_PTD_TOTAL_BUFF_TYPES] = {
	HC_ATL_BLK_PL_SIZE,
	HC_INTL_BLK_PL_SIZE,
	HC_ISTL_BLK_PL_SIZE,
	HC_ISTL_BLK_PL_SIZE
};

static __u16	hc_ram_buff_address[TD_PTD_TOTAL_BUFF_TYPES] = {
	HC_ATL_ADDRESS,
	HC_INTL_ADDRESS,
	HC_ISTL_0_ADDRESS,
	HC_ISTL_1_ADDRESS
};

#ifdef __PHCI_DEBUG_DETAIL__

/*--------------------------------------------------------------*
 * HC TD-PTD map buffers print functions 						* 
 *--------------------------------------------------------------*/
void phci_print_map_buffers(__u8	index) {
	__u8	index1;
	td_ptd_map_buff_t	*ptd_map_buff;

	ptd_map_buff = &(td_ptd_map_buff[index]);
	isp1362_printk("buffer:: %p, buffer type:: %d\n",ptd_map_buff, ptd_map_buff->buffer_type);
	isp1362_printk("\tbuffer active_ptds:: %d \n\tbuffer total_ptds:: %d\n",ptd_map_buff->active_ptds, ptd_map_buff->total_ptds);
	isp1362_printk("\tbuffer max_ptds:: %d \n\tbuffer active_ptd_bitmap:: %x\n",ptd_map_buff->max_ptds, ptd_map_buff->active_ptd_bitmap);
	isp1362_printk("\tbuffer skip_ptd_bitmap:: %x \n\tbuffer ram_buff_addr:: %x \n",ptd_map_buff->skip_ptd_bitmap, ptd_map_buff->ram_buff_addr);

	isp1362_printk("\tbuffer buffer_length:: %d \n\tbuffer buffer_port:: %d\n",ptd_map_buff->regs.buffer_length, ptd_map_buff->regs.buffer_port);
	isp1362_printk("\tbuffer block_pl_size:: %d \n\tbuffer toggle_rate:: %d\n",ptd_map_buff->regs.block_pl_size, ptd_map_buff->regs.toggle_rate);
	isp1362_printk("\tbuffer last_ptd:: %d \n\tbuffer ptd_done_map:: %x\n",ptd_map_buff->regs.last_ptd, ptd_map_buff->regs.ptd_done_map);
	isp1362_printk("\tbuffer ptd_skip_map:: %x \n\tbuffer curr_active_ptd:: %d\n",ptd_map_buff->regs.ptd_skip_map, ptd_map_buff->regs.curr_active_ptd);
	isp1362_printk("\tbuffer threshold_count:: %d \n\tbuffer threshold_timeout:: %d\n",ptd_map_buff->regs.threshold_count, ptd_map_buff->regs.threshold_timeout);

	for(index1=0; index1<ptd_map_buff->max_ptds;index1++){
		isp1362_printk("td_ptd_map = %p\n", &(ptd_map_buff->map_list[index1]));
		isp1362_printk("\t\tbuffer state:: %d \n\t\tbuffer total_bytes:: %d\n",ptd_map_buff->map_list[index1].state, ptd_map_buff->map_list[index1].total_bytes);
		isp1362_printk("\t\tbuffer ptd_bitmap:: %x \n\t\tbuffer td:: %p\n",ptd_map_buff->map_list[index1].ptd_bitmap, ptd_map_buff->map_list[index1].td);
	}

} /* phci_print_map_buffers */

/*--------------------------------------------------------------*
 * print buffer data in hex format functions 					* 
 *--------------------------------------------------------------*/
void phci_print_hex_data(__u8	*data, __u32	length) {
	__u32	index;

	for(index = 0; index < length; index++) {
		if(index%8 == 0) isp1362_printk("\n");
		isp1362_printk(" 0x%2x  ", data[index]);
	}
	isp1362_printk("\n");
	
	return;
}

/*--------------------------------------------------------------*
 * HC TD-PTD map buffers print functions 						* 
 *--------------------------------------------------------------*/
void phci_print_ptd_header(__u8	*header, __u32	pipe) {
	
	__u16	data;
	
#ifdef CONFIG_USB_PHCD_EVEN_SCH
	__u8	poll_int;
#endif /* CONFIG_USB_PHCD_EVEN_SCH */

	isp1362_printk("  0x%x  0x%x  0x%x  0x%x  0x%x  0x%x  0x%x  0x%x\n",header[0],header[1],header[2],header[3],header[4],header[5],header[6],header[7]);

	isp1362_printk("PTD_HEADER for pipe :: %s\n", ((pipe==PIPE_CONTROL) ? "CONTROL" : ((pipe == PIPE_INTERRUPT) ? "INTERRUPT" : ((pipe == PIPE_BULK) ? "BULK" : "ISOCHRONOUS"))));
	data = ((header[1] & 0x03) << 8);
	data |= header[0];
	isp1362_printk("     Actual Bytes: %d\n", data);
	data = header[1];
	isp1362_printk("     CC: 0x%x     %s     toggle: %d\n", ((data & 0xF0)>>4), (data&0x8) ? "ACTIVE" : "NOT ACTIVE", (data&0x4)>>2);
	data = ((header[3] & 0x03) << 8);
	data |= header[2];
	isp1362_printk("     Max Packet Size: %d\n", data);
	data = header[3];
	if(pipe == PIPE_ISOCHRONOUS) {
		isp1362_printk("     EN: %x     %s    %s\n", ((data & 0xF0)>>4), (data&0x8) ? "LAST PTD" : "", (data&0x4) ? "LOW SPEED" : "FULL SPEED");
	} else {
		isp1362_printk("     EN: %x     %s\n", ((data & 0xF0)>>4), (data&0x4) ? "LOW SPEED" : "FULL SPEED");
	}
	data = ((header[5] & 0x03) << 8);
	data |= header[4];
	isp1362_printk("     Total Bytes: %d\n", data);
	data = header[5];
	if(pipe == PIPE_INTERRUPT) {
		isp1362_printk("     Dir:: %s\n", ( ((data & 0xC) == 0) ? "SETUP" : (((data & 0xC) == 0x4) ? "OUT" : "IN")));
		data = header[6];
#ifdef CONFIG_USB_PHCD_EVEN_SCH
		poll_int = ((header[6] & 0xE0) >> 5) ;
		isp1362_printk("     Addr: %d     poll interval = %d milli seconds, start fn# = %d\n", data & 0x7F, ((poll_int == 0) ? 1 : ( (poll_int == 2) ? 2 : ((poll_int == 4) ? 4 : ((poll_int == 6) ? 8 : ((poll_int == 8) ? 16 : 32))))), (header[7] & 0x1F));
#else
		isp1362_printk("     Addr: %d     poll interval = %d milli seconds\n", data & 0x7F, ((header[7] == 0) ? 1 : ( (header[7] == 2) ? 2 : ((header[7] == 4) ? 4 : ((header[7] == 6) ? 8 : ((header[7] == 8) ? 16 : 32))))));
#endif /* CONFIG_USB_PHCD_EVEN_SCH */
	} else if( pipe == PIPE_ISOCHRONOUS) {
		isp1362_printk("     Dir:: %s\n", ( ((data & 0xC) == 0) ? "SETUP" : (((data & 0xC) == 0x4) ? "OUT" : "IN")));
		data = header[6];
		isp1362_printk("     Addr: %d     fn = 0x%x\n", data & 0x7F, header[7]);
	} else {
		if(data & 0x80) {
			isp1362_printk("     PAIRED  %s  Dir:: %s\n", (data & 0x40) ? "PONG" : "PING", ( ((data & 0xC) == 0) ? "SETUP" : (((data & 0xC) == 0x4) ? "OUT" : "IN")));
		} else {
			isp1362_printk("     NOT PAIRED     Dir:: %s\n", ( ((data & 0xC) == 0) ? "SETUP" : (((data & 0xC) == 0x4) ? "OUT" : "IN")));
		}
		data = header[6];
		isp1362_printk("     Addr: %d\n", data & 0x7F);
	}

} /* phci_print_ptd_header */

void phci_print_hc_regs(phci_t	*phci, __u8	buff_type) {
	__u32	data_read = 0;

	if(buff_type ==  TD_PTD_BUFF_TYPE_ATL) {
		phci_reg_read16(REG_BUFF_STS,&data_read);
		isp1362_printk("Buffer Status = %x", data_read);
		data_read = 0;
		phci_reg_read16(REG_IRQ_MASK, &data_read);
		isp1362_printk("  Irq_mask = %x\n", data_read);
		data_read = 0;
		phci_reg_read16(REG_ISTL_BUFF_LEN, &data_read);
		isp1362_printk("  Istl Buffer_len = %x", data_read);
		data_read = 0;
		phci_reg_read16(REG_INTL_BUFF_LEN, &data_read);
		isp1362_printk("  INTL Buffer_len = %x", data_read);
		data_read = 0;
		phci_reg_read16(REG_ATL_BUFF_LEN, &data_read);
		isp1362_printk(" Buffer_len = %x", data_read);
		data_read = 0;
		phci_reg_read16(REG_ATL_BLK_PL_SIZE, &data_read);
		isp1362_printk("  Block_pl_size = %x\n", data_read);
		data_read = 0;
		phci_reg_read16(REG_ATL_THRESHOLD_COUNT,&data_read);
		isp1362_printk("threshold_count = %x", data_read);
		data_read = 0;
		phci_reg_read16(REG_ATL_THRESHOLD_TIMEOUT,&data_read);
		isp1362_printk("  threshold_timeout = %x\n", data_read);
		data_read = 0;
		phci_reg_read32(REG_ATL_PTD_DONE_MAP, &data_read);
		isp1362_printk("done_map = %x", data_read);
		data_read = 0;
		phci_reg_read32(REG_ATL_PTD_SKIP_MAP, &data_read);
		isp1362_printk("  skip_map %x\n", data_read);
		data_read = 0;
		phci_reg_read32(REG_ATL_PTD_LAST_PTD,&data_read);		
		isp1362_printk("last_ptd_map %x", data_read);
		data_read = 0;
		phci_reg_read16(REG_ATL_CURR_ACTIVE_PTD,&data_read);		
		isp1362_printk("  curr_act_ptd %x\n", data_read);
	} else if(buff_type ==  TD_PTD_BUFF_TYPE_INTL) {
		phci_reg_read16(REG_BUFF_STS,&data_read);
		isp1362_printk("Buffer Status = %x", data_read);
		data_read = 0;
		phci_reg_read16(REG_IRQ_MASK, &data_read);
		isp1362_printk("  Irq_mask = %x\n", data_read);
		data_read = 0;
		phci_reg_read16(REG_ISTL_BUFF_LEN, &data_read);
		isp1362_printk("  Istl Buffer_len = %x", data_read);
		data_read = 0;
		phci_reg_read16(REG_INTL_BUFF_LEN, &data_read);
		isp1362_printk("  INTL Buffer_len = %x", data_read);
		data_read = 0;
		phci_reg_read16(REG_ATL_BUFF_LEN, &data_read);
		isp1362_printk(" Buffer_len = %x", data_read);
		data_read = 0;
		phci_reg_read16(REG_INTL_BLK_PL_SIZE, &data_read);
		isp1362_printk("  Block_pl_size = %x\n", data_read);
		data_read = 0;
		phci_reg_read32(REG_INTL_PTD_DONE_MAP, &data_read);
		isp1362_printk("done_map = %x", data_read);
		data_read = 0;
		phci_reg_read32(REG_INTL_PTD_SKIP_MAP, &data_read);
		isp1362_printk("  skip_map %x\n", data_read);
		data_read = 0;
		phci_reg_read32(REG_INTL_PTD_LAST_PTD,&data_read);		
		isp1362_printk("last_ptd_map %x", data_read);
	}
}

void phci_urb_print (struct urb * urb, char * str, int small) {
	unsigned int pipe= urb->pipe;
	
	if (!urb->dev || !urb->dev->bus) {
		isp1362_printk("%s URB: no dev", str);
		return;
	}
	
	if (urb->status != 0)
	isp1362_printk("%s URB:[%4x] dev:%2d,ep:%2d-%c,type:%s,flags:%4x,len:%d/%d,stat:%d(%x)", 
			str,
		 	sphci_get_current_frame_number (urb->dev), 
		 	usb_pipedevice (pipe),
		 	usb_pipeendpoint (pipe), 
		 	usb_pipeout (pipe)? 'O': 'I',
		 	usb_pipetype (pipe) < 2? (usb_pipeint (pipe)? "INTR": "ISOC"):
		 		(usb_pipecontrol (pipe)? "CTRL": "BULK"),
		 	urb->transfer_flags, 
		 	urb->actual_length, 
		 	urb->transfer_buffer_length,
		 	urb->status, urb->status);

	if (!small) {
		int i, len;

		if (usb_pipecontrol (pipe)) {
			isp1362_printk (KERN_DEBUG __FILE__ ": cmd(8):");
			for (i = 0; i < 8 ; i++) 
				isp1362_printk (" %02x", ((__u8 *) urb->setup_packet) [i]);
			isp1362_printk ("\n");
		}
		if (urb->transfer_buffer_length > 0 && urb->transfer_buffer) {
			isp1362_printk (KERN_DEBUG __FILE__ ": data(%d/%d):", 
				urb->actual_length, 
				urb->transfer_buffer_length);
			len = usb_pipeout (pipe)? 
						urb->transfer_buffer_length: urb->actual_length;
			for (i = 0; i < 16 && i < len; i++) 
				isp1362_printk (" %02x", ((__u8 *) urb->transfer_buffer) [i]);
			isp1362_printk ("%s stat:%d\n", i < len? "...": "", urb->status);
		}
	} 
}
#endif /* __PHCI_DEBUG_DETAIL__ */


/*--------------------------------------------------------------*
 * HC TD-PTD map buffers initialization functions 			* 
 *--------------------------------------------------------------*/
void phci_init_map_buffers(phci_t	*phci) {

	td_ptd_map_buff_t	*ptd_map_buff;
	__u8				buff_type, ptd_index;
	__u32				bitmap;

	func_debug(("phci_init_map_buffers(phci = 0x%p)\n",phci))
	
	/* initialize for each buffer type */
	for(buff_type = 0; buff_type < TD_PTD_TOTAL_BUFF_TYPES; buff_type++) {
	
		ptd_map_buff = &(td_ptd_map_buff[buff_type]);

		ptd_map_buff->buffer_type = buff_type;					/* Set buffer type */

#ifdef CONFIG_USB_PHCD_PING_PONG
		ptd_map_buff->ping_pong.fill_status = 0;							/* Set ping pong status to not in use */
		ptd_map_buff->ping_pong.fill_seq = PP_SEQ_PING_PONG;
		ptd_map_buff->ping_pong.fill_count = 0;
		ptd_map_buff->ping_ptd_index = TD_PTD_INV_PTD_INDEX;		/* ping ptd index is invalid index */
		ptd_map_buff->pong_ptd_index = TD_PTD_INV_PTD_INDEX;		/* pong ptd index is invalid index */
#endif /* CONFIG_USB_PHCD_PING_PONG */

		ptd_map_buff->active_ptds = 0;								/* active td's = 0 */
		ptd_map_buff->total_ptds = 0;								/* total td's = 0 */
		ptd_map_buff->max_ptds = td_ptd_buff_type_max_ptds[buff_type];	/* set maximum ptds for this buffer type */
		ptd_map_buff->active_ptd_bitmap = 0;						/* no active ptds */
		ptd_map_buff->skip_ptd_bitmap = 0xFFFFFFFF;					/* Skip all ptds */
		ptd_map_buff->pending_ptd_bitmap = 0x00000000;				/* Initially no pending ptds */

		bitmap = 0x00000001;

		for(ptd_index = 0; ptd_index < ptd_map_buff->max_ptds; ptd_index++) {
			ptd_map_buff->active_ptd_bitmask |= bitmap;
			bitmap <<= 1;
		}
		
		ptd_map_buff->ram_buff_addr = hc_ram_buff_address[buff_type];		/* Buffer lengths for each buffer */
		ptd_map_buff->done_head = NULL;										/* No done ptd's */
		ptd_map_buff->frame_number = INVALID_FRAME_NUMBER;					/* Invalid frame number */
		
		ptd_map_buff->regs.buffer_length = hc_ram_buff_lengths[buff_type];			/* Buffer lengths for each buffer */
		ptd_map_buff->regs.buffer_port = hc_ram_buff_port_reg[buff_type];			/* Buffer accessing port register */
		ptd_map_buff->regs.block_pl_size = hc_ram_buff_block_pl_size[buff_type];	/* Block pay load size */
		ptd_map_buff->regs.toggle_rate = HC_ISTL_DEF_TOGGLE_RATE;					/* toggle rate for ISTL buffer */
		ptd_map_buff->regs.last_ptd = 0;								/* Last PTD for ATL & INTL is zero */
		ptd_map_buff->regs.ptd_done_map = 0;							/* No PTD is done */
		ptd_map_buff->regs.ptd_skip_map = 0;							/* Skip all PTD */
		ptd_map_buff->regs.curr_active_ptd = 0;							/* current active ptd is zero */
		ptd_map_buff->regs.threshold_count = HC_DEF_ATL_THRESHOLD_COUNT;		/* Default ptd thereshold for ATL */
		ptd_map_buff->regs.threshold_timeout = 0xFF;					/* Default thereshold timeout for ATL */

		/* For each ptd index of this buffer, set the fiedls */
		bitmap = 0x00000001;
//		for(ptd_index = 0; ptd_index < ptd_map_buff->max_ptds; ptd_index++)
		for(ptd_index = 0; ptd_index < TD_PTD_MAX_BUFF_TDS; ptd_index++){
			ptd_map_buff->map_list[ptd_index].state = TD_PTD_NEW;	/* Set the td_ptd as new */
			ptd_map_buff->map_list[ptd_index].total_bytes = 0;		/* total bytes to 0 */
			ptd_map_buff->map_list[ptd_index].ptd_bitmap = bitmap;	/* set the bitmap for this buffer */
			ptd_map_buff->map_list[ptd_index].td = NULL;
			ptd_map_buff->map_list[ptd_index].ed = NULL;
			ptd_map_buff->map_list[ptd_index].ping_pong = TD_PTD_NO_PING_PONG;
			ptd_map_buff->map_list[ptd_index].ram_addr = 0xFFFF;
			bitmap <<= 1;

		}/* for( ptd_index */

	}	/* for(buff_type */

⌨️ 快捷键说明

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