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

📄 pxa.c

📁 Linux2.4.20针对三星公司的s3c2440内核基础上的一些设备驱动代码
💻 C
📖 第 1 页 / 共 4 页
字号:
int udc_connected (){	return 1;}/** * udc_connect - enable pullup resistor * * Turn on the USB connection by enabling the pullup resistor. */void udc_connect (void){#ifdef CONFIG_SABINAL_DISCOVERY        /* Set GPIO pin function to I/O */        GPAFR1_U &= ~(0x3 << ((USBD_CONNECT_GPIO & 0xF) << 1));        /* Set pin direction to output */        GPDR(1) |= GPIO_GPIO(USBD_CONNECT_GPIO);#if defined(USBD_CONNECT_HIGH)	/* Set GPIO pin high to connect */	GPSR(1) = GPIO_GPIO(USBD_CONNECT_GPIO);#else	/* Set GPIO pin low to connect */	GPCR(1) = GPIO_GPIO(USBD_CONNECT_GPIO);#endif#else#warning NO USB Device connect#endif}/** * udc_disconnect - disable pullup resistor * * Turn off the USB connection by disabling the pullup resistor. */void udc_disconnect (void){#ifdef CONFIG_SABINAL_DISCOVERY        /* Set GPIO pin function to I/O */        GPAFR1_U &= ~(0x3 << ((USBD_CONNECT_GPIO & 0xF) << 1));        /* Set pin direction to output */        GPDR(1) |= GPIO_GPIO(USBD_CONNECT_GPIO);#if defined(USBD_CONNECT_HIGH)	/* Set GPIO pin low to disconnect */	GPCR(1) = GPIO_GPIO(USBD_CONNECT_GPIO);#else	/* Set GPIO pin high to disconnect */	GPSR(1) = GPIO_GPIO(USBD_CONNECT_GPIO);#endif#else#warning NO USB Device connect#endif}#if 0/** * udc_int_hndlr_cable - interrupt handler for cable */static void udc_int_hndlr_cable (int irq, void *dev_id, struct pt_regs *regs){	// GPIOn interrupt}#endif/* ********************************************************************************************* *//** * udc_enable_interrupts - enable interrupts * * Switch on UDC interrupts. * */void udc_all_interrupts (struct usb_device_instance *device){        int i;        UDCCR &= ~UDCCR_SRM;    // enable suspend interrupt        UDCCR |= UDCCR_REM;     // disable resume interrupt        // XXX SOF UFNHR &= ~UFNHR_SIM;        // always enable control endpoint        pxa_enable_ep_interrupt(0);        for (i = 1; i < UDC_MAX_ENDPOINTS; i++) {                if (ep_endpoints[i] && ep_endpoints[i]->endpoint_address) {			pxa_enable_ep_interrupt(ep_endpoints[i]->endpoint_address);                }        }}/** * udc_suspended_interrupts - enable suspended interrupts * * Switch on only UDC resume interrupt. * */void udc_suspended_interrupts (struct usb_device_instance *device){        UDCCR &= ~UDCCR_REM;    // enable resume interrupt        UDCCR |= UDCCR_SRM;     // disable suspend interrupt}/** * udc_disable_interrupts - disable interrupts. * * switch off interrupts */void udc_disable_interrupts (struct usb_device_instance *device){        UICR0 = UICR1 = 0xff;                   // disable endpoint interrupts        UFNHR |= UFNHR_SIM;                     // disable sof interrupt        UDCCR |= UDCCR_REM | UDCCR_SRM;         // disable suspend and resume interrupt}/* ********************************************************************************************* *//** * udc_ep0_packetsize - return ep0 packetsize */int udc_ep0_packetsize (void){	return EP0_PACKETSIZE;}/** * udc_enable - enable the UDC * * Switch on the UDC */void udc_enable (struct usb_device_instance *device){	// save the device structure pointer	udc_device = device;	// ep0 urb	if (!ep0_urb) {		if (!(ep0_urb = usbd_alloc_urb (device, device->function_instance_array, 0, 512))) {			printk (KERN_ERR "udc_enable: usbd_alloc_urb failed\n");		}	}         else {		printk (KERN_ERR "udc_enable: ep0_urb already allocated\n");	}	// enable UDC	// c.f. 3.6.2 Clock Enable Register	CKEN |= CKEN11_USB;        // c.f. 12.4.11 GPIOn and GPIOx        // enable cable interrupt                // c.f. 12.5 UDC Operation - after reset on EP0 interrupt is enabled.        // c.f. 12.6.1.1 UDC Enable        UDCCR |= UDCCR_UDE | UDCCR_REM;}/** * udc_disable - disable the UDC * * Switch off the UDC */void udc_disable (void){        printk ("PXA: call udc_disable\n");	// disable UDC        // c.f. 12.6.1.1 UDC Enable        UDCCR &= ~( UDCCR_UDE | UDCCR_REM );	// c.f. 3.6.2 Clock Enable Register	CKEN &= ~CKEN11_USB;        // disable cable interrupt        	// reset device pointer	udc_device = NULL;	// ep0 urb	if (ep0_urb) {		usbd_dealloc_urb (ep0_urb);		ep0_urb = 0;	} else {		printk (KERN_ERR "udc_disable: ep0_urb already NULL\n");	}#ifdef CONFIG_USBD_PXA_DMA_IN        if (usb_pxa_dma_in.dma_buf) {                consistent_free (usb_pxa_dma_in.dma_buf,                                 DMA_IN_BUFSIZE, usb_pxa_dma_in.dma_buf_phys);                usb_pxa_dma_in.dma_buf = NULL;        }#endif#ifdef CONFIG_USBD_PXA_DMA_OUT        if (usb_pxa_dma_out.dma_buf) {                consistent_free (usb_pxa_dma_out.dma_buf,                                 DMA_OUT_BUFSIZE, usb_pxa_dma_out.dma_buf_phys);                usb_pxa_dma_out.dma_buf = NULL;        }#endif}/** * udc_startup - allow udc code to do any additional startup */void udc_startup_events (struct usb_device_instance *device){	usbd_device_event (device, DEVICE_INIT, 0);	usbd_device_event (device, DEVICE_CREATE, 0);	usbd_device_event (device, DEVICE_HUB_CONFIGURED, 0);	usbd_device_event (device, DEVICE_RESET, 0);}/* ********************************************************************************************* */#ifdef PXA_TRACE#ifdef CONFIG_USBD_PROCFS/* Proc Filesystem *************************************************************************** */        /* *     * pxa_proc_read - implement proc file system read. * @file         * @buf          * @count * @pos  *       * Standard proc file system read function. */         static ssize_t pxa_proc_read (struct file *file, char *buf, size_t count, loff_t * pos){                                          unsigned long page;        int len = 0;        int index;        MOD_INC_USE_COUNT;        // get a page, max 4095 bytes of data...        if (!(page = get_free_page (GFP_KERNEL))) {                MOD_DEC_USE_COUNT;                return -ENOMEM;        }        len = 0;        index = (*pos)++;        if (index == 0) {                len += sprintf ((char *) page + len, "   Index     Ints     Jifs    Ticks\n");        }                                        if (index < trace_next) {                u64 jifs = 1111;                u32 ticks = 2222;                pxa_trace_t *p = pxa_traces + index;                unsigned char *cp;                if (index > 0) {                        u32 ocsr = pxa_traces[index-1].ocsr;                        ticks = (p->ocsr > ocsr) ? (p->ocsr - ocsr) : (ocsr - p->ocsr) ;                        jifs = p->jiffies - pxa_traces[index-1].jiffies;                }                                len += sprintf ((char *) page + len, "%8d %8d %8lu ", index, p->interrupts, jifs);                if (ticks > 1024*1024) {                        len += sprintf ((char *) page + len, "%8dM ", ticks>>20);                }                else {                        len += sprintf ((char *) page + len, "%8d  ", ticks);                }                switch (p->trace_type) {                case pxa_regs:                        len += sprintf ((char *) page + len, "CS0[%02x] %s\n", p->trace.regs.cs0, p->trace.regs.msg);                        break;                case pxa_setup:                        cp = (unsigned char *)&p->trace.setup;                        len += sprintf ((char *) page + len,                                         " --               request [%02x %02x %02x %02x %02x %02x %02x %02x]\n",                                         cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]);                        break;                case pxa_xmit:                        len += sprintf ((char *) page + len,                                         " --                   sending [%02x]\n", p->trace.xmit.size);                        break;                case pxa_ccr:                        len += sprintf ((char *) page + len,                                         "CCR[%02x] %s\n", p->trace.ccr.ccr, p->trace.ccr.msg);                        break;                case pxa_iro:                        len += sprintf ((char *) page + len,                                         "IRO[%02x] %s\n", p->trace.iro.iro, p->trace.iro.msg);                        break;                }        }        if (len > count) {                len = -EINVAL;        } else if (len > 0 && copy_to_user (buf, (char *) page, len)) {                len = -EFAULT;        }        free_page (page);        MOD_DEC_USE_COUNT;        return len;}/* * * pxa_proc_write - implement proc file system write. * @file * @buf * @count * @pos * * Proc file system write function, used to signal monitor actions complete. * (Hotplug script (or whatever) writes to the file to signal the completion * of the script.)  An ugly hack. */static ssize_t pxa_proc_write (struct file *file, const char *buf, size_t count, loff_t * pos){        return count;}static struct file_operations pxa_proc_operations_functions = {        read:pxa_proc_read,        write:pxa_proc_write,};#endif#endif/* ********************************************************************************************* *//** * udc_name - return name of USB Device Controller */char *udc_name (void){	return UDC_NAME;}/** * udc_request_udc_irq - request UDC interrupt * * Return non-zero if not successful. */int udc_request_udc_irq (){	// request IRQ  and IO region	if (request_irq (IRQ_USB, int_hndlr, SA_INTERRUPT | SA_SAMPLE_RANDOM,	     UDC_NAME " USBD Bus Interface", NULL) != 0)         {		printk (KERN_INFO "usb_ctl: Couldn't request USB irq\n");		return -EINVAL;	}	return 0;}/** * udc_request_cable_irq - request Cable interrupt * * Return non-zero if not successful. */int udc_request_cable_irq (){#ifdef XXXX_CABLE_IRQ	// request IRQ  and IO region	if (request_irq	    (XXXX_CABLE_IRQ, int_hndlr, SA_INTERRUPT | SA_SAMPLE_RANDOM, UDC_NAME " Cable",	     NULL) != 0) {		printk (KERN_INFO "usb_ctl: Couldn't request USB irq\n");		return -EINVAL;	}#endif	return 0;}/** * udc_request_udc_io - request UDC io region * * Return non-zero if not successful. */int udc_request_io (){#ifdef PXA_TRACE#ifdef CONFIG_USBD_PROCFS        if (!(pxa_traces = vmalloc(sizeof(pxa_trace_t) * TRACE_MAX))) {                printk(KERN_ERR"PXA_TRACE malloc failed %p %d\n", pxa_traces, sizeof(pxa_trace_t) * TRACE_MAX);        }        else {                printk(KERN_ERR"PXA_TRACE malloc ok %p\n", pxa_traces);        }        PXA_REGS(0,"init");        PXA_REGS(0,"test");        {                struct proc_dir_entry *p;                // create proc filesystem entries                if ((p = create_proc_entry ("pxa", 0, 0)) == NULL) {                        printk(KERN_INFO"PXA PROC FS failed\n");                }                else {                        printk(KERN_INFO"PXA PROC FS Created\n");                        p->proc_fops = &pxa_proc_operations_functions;                }        }#endif#endif	return 0;}/** * udc_release_release_io - release UDC io region */void udc_release_io (){#ifdef PXA_TRACE#ifdef CONFIG_USBD_PROCFS        unsigned long flags;        save_flags_cli (flags);        remove_proc_entry ("pxa", NULL);        if (pxa_traces) {                pxa_trace_t *p = pxa_traces;                pxa_traces = 0;                vfree(p);        }        restore_flags (flags);#endif#endif}/** * udc_release_udc_irq - release UDC irq */void udc_release_udc_irq (){	free_irq (IRQ_USB, NULL);}/** * udc_release_cable_irq - release Cable irq */void udc_release_cable_irq (){#ifdef XXXX_IRQ	free_irq (XXXX_CABLE_IRQ, NULL);#endif}/** * udc_regs - dump registers * * Dump registers with printk */void udc_regs (void){	printk ("[%d:%d] CCR[%02x] UICR[%02x %02x] UFNH[%02x %02x] UDCCS[%02x %02x %02x %02x]\n",                         udc_interrupts, jifs(), UDCCR, UICR1, UICR0, UFNHR, UFNLR, UDCCS0, UDCCS1, UDCCS2, UDCCS5);}/* * dma_regs - dump DMA state * G.N.U., but may be useful for DMA debugging. */static void dma_regs (void){#ifdef CONFIG_USBD_PXA_DMA_IN	printk ("  DMA IN: DCSR:%x DCMD:%x DSADR:%x DTADR:%x\n",		DCSR(usb_pxa_dma_in.dmach), DCMD(usb_pxa_dma_in.dmach),		DSADR(usb_pxa_dma_in.dmach), DTADR(usb_pxa_dma_in.dmach));#endif#ifdef CONFIG_USBD_PXA_DMA_OUT	printk ("  DMA OUT: DCSR:%x DCMD:%x DSADR:%x DTADR:%x\n",		DCSR(usb_pxa_dma_out.dmach), DCMD(usb_pxa_dma_out.dmach),		DSADR(usb_pxa_dma_out.dmach), DTADR(usb_pxa_dma_out.dmach));#endif}

⌨️ 快捷键说明

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