?? dwc_otg_attr.c
字號:
{ \ dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);\ uint32_t val; \ val = dwc_read_reg32 (_addr_); \ return sprintf (buf, "%s = 0x%08x\n", _string_, val); \}#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_addr_,_string_) \static ssize_t _otg_attr_name_##_store (struct device *_dev, const char *buf, size_t count) \{ \ dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);\ uint32_t val = simple_strtoul(buf, NULL, 16); \ dev_dbg(_dev, "Storing Address=0x%08x Val=0x%08x\n", (uint32_t)_addr_, val); \ dwc_write_reg32(_addr_, val); \ return count; \}#endif#define DWC_OTG_DEVICE_ATTR_BITFIELD_RW(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);#define DWC_OTG_DEVICE_ATTR_BITFIELD_RO(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_addr_,_mask_,_shift_,_string_) \DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);#define DWC_OTG_DEVICE_ATTR_REG32_RW(_otg_attr_name_,_addr_,_string_) \DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_addr_,_string_) \DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_addr_,_string_) \DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);#define DWC_OTG_DEVICE_ATTR_REG32_RO(_otg_attr_name_,_addr_,_string_) \DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_addr_,_string_) \DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);/** @name Functions for Show/Store of Attributes *//**@{*//** * Show the register offset of the Register Access. */static ssize_t regoffset_show( struct device *_dev,#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20) struct device_attribute *attr,#endif char *buf) {#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20) struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);#else dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);#endif return snprintf(buf, sizeof("0xFFFFFFFF\n")+1,"0x%08x\n", otg_dev->reg_offset);}/** * Set the register offset for the next Register Access Read/Write */static ssize_t regoffset_store( struct device *_dev,#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20) struct device_attribute *attr,#endif const char *buf, size_t count ) {#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20) struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);#else dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);#endif uint32_t offset = simple_strtoul(buf, NULL, 16); //dev_dbg(_dev, "Offset=0x%08x\n", offset); if (offset < SZ_256K ) { otg_dev->reg_offset = offset; } else { dev_err( _dev, "invalid offset\n" ); } return count;}DEVICE_ATTR(regoffset, S_IRUGO|S_IWUSR, (void *)regoffset_show, regoffset_store);/** * Show the value of the register at the offset in the reg_offset * attribute. */static ssize_t regvalue_show( struct device *_dev,#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20) struct device_attribute *attr,#endif char *buf) {#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20) struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);#else dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);#endif uint32_t val; volatile uint32_t *addr; if (otg_dev->reg_offset != 0xFFFFFFFF && 0 != otg_dev->base) { /* Calculate the address */ addr = (uint32_t*)(otg_dev->reg_offset + (uint8_t*)otg_dev->base); //dev_dbg(_dev, "@0x%08x\n", (unsigned)addr); val = dwc_read_reg32( addr ); return snprintf(buf, sizeof("Reg@0xFFFFFFFF = 0xFFFFFFFF\n")+1, "Reg@0x%06x = 0x%08x\n", otg_dev->reg_offset, val); } else { dev_err(_dev, "Invalid offset (0x%0x)\n", otg_dev->reg_offset); return sprintf(buf, "invalid offset\n" ); }}/** * Store the value in the register at the offset in the reg_offset * attribute. * */static ssize_t regvalue_store( struct device *_dev,#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20) struct device_attribute *attr,#endif const char *buf, size_t count ) {#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20) struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);#else dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);#endif volatile uint32_t * addr; uint32_t val = simple_strtoul(buf, NULL, 16); //dev_dbg(_dev, "Offset=0x%08x Val=0x%08x\n", otg_dev->reg_offset, val); if (otg_dev->reg_offset != 0xFFFFFFFF && 0 != otg_dev->base) { /* Calculate the address */ addr = (uint32_t*)(otg_dev->reg_offset + (uint8_t*)otg_dev->base); //dev_dbg(_dev, "@0x%08x\n", (unsigned)addr); dwc_write_reg32( addr, val ); } else { dev_err(_dev, "Invalid Register Offset (0x%08x)\n", otg_dev->reg_offset); } return count;}DEVICE_ATTR(regvalue, S_IRUGO|S_IWUSR, regvalue_show, regvalue_store);/* * Attributes */DWC_OTG_DEVICE_ATTR_BITFIELD_RO(mode,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<20),20,"Mode");DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hnpcapable,&(otg_dev->core_if->core_global_regs->gusbcfg),(1<<9),9,"Mode");DWC_OTG_DEVICE_ATTR_BITFIELD_RW(srpcapable,&(otg_dev->core_if->core_global_regs->gusbcfg),(1<<8),8,"Mode");//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(buspower,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(bussuspend,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");DWC_OTG_DEVICE_ATTR_BITFIELD_RO(busconnected,otg_dev->core_if->host_if->hprt0,0x01,0,"Bus Connected");DWC_OTG_DEVICE_ATTR_REG32_RW(gotgctl,&(otg_dev->core_if->core_global_regs->gotgctl),"GOTGCTL");DWC_OTG_DEVICE_ATTR_REG32_RW(gusbcfg,&(otg_dev->core_if->core_global_regs->gusbcfg),"GUSBCFG");DWC_OTG_DEVICE_ATTR_REG32_RW(grxfsiz,&(otg_dev->core_if->core_global_regs->grxfsiz),"GRXFSIZ");DWC_OTG_DEVICE_ATTR_REG32_RW(gnptxfsiz,&(otg_dev->core_if->core_global_regs->gnptxfsiz),"GNPTXFSIZ");DWC_OTG_DEVICE_ATTR_REG32_RW(gpvndctl,&(otg_dev->core_if->core_global_regs->gpvndctl),"GPVNDCTL");DWC_OTG_DEVICE_ATTR_REG32_RW(ggpio,&(otg_dev->core_if->core_global_regs->ggpio),"GGPIO");DWC_OTG_DEVICE_ATTR_REG32_RW(guid,&(otg_dev->core_if->core_global_regs->guid),"GUID");DWC_OTG_DEVICE_ATTR_REG32_RO(gsnpsid,&(otg_dev->core_if->core_global_regs->gsnpsid),"GSNPSID");DWC_OTG_DEVICE_ATTR_BITFIELD_RW(devspeed,&(otg_dev->core_if->dev_if->dev_global_regs->dcfg),0x3,0,"Device Speed");DWC_OTG_DEVICE_ATTR_BITFIELD_RO(enumspeed,&(otg_dev->core_if->dev_if->dev_global_regs->dsts),0x6,1,"Device Enumeration Speed");DWC_OTG_DEVICE_ATTR_REG32_RO(hptxfsiz,&(otg_dev->core_if->core_global_regs->hptxfsiz),"HPTXFSIZ");DWC_OTG_DEVICE_ATTR_REG32_RW(hprt0,otg_dev->core_if->host_if->hprt0,"HPRT0");/** * @todo Add code to initiate the HNP. *//** * Show the HNP status bit */static ssize_t hnp_show( struct device *_dev,#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20) struct device_attribute *attr,#endif char *buf) {#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20) struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);#else dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);#endif gotgctl_data_t val; val.d32 = dwc_read_reg32 (&(otg_dev->core_if->core_global_regs->gotgctl)); return sprintf (buf, "HstNegScs = 0x%x\n", val.b.hstnegscs);}/** * Set the HNP Request bit */static ssize_t hnp_store( struct device *_dev,#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20) struct device_attribute *attr,#endif const char *buf, size_t count ) {#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20) struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);#else dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);#endif uint32_t in = simple_strtoul(buf, NULL, 16); uint32_t *addr = (uint32_t *)&(otg_dev->core_if->core_global_regs->gotgctl); gotgctl_data_t mem; mem.d32 = dwc_read_reg32(addr); mem.b.hnpreq = in; dev_dbg(_dev, "Storing Address=0x%08x Data=0x%08x\n", (uint32_t)addr, mem.d32); dwc_write_reg32(addr, mem.d32); return count;}DEVICE_ATTR(hnp, 0644, hnp_show, hnp_store);/** * @todo Add code to initiate the SRP. *//** * Show the SRP status bit */static ssize_t srp_show( struct device *_dev,#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20) struct device_attribute *attr,#endif char *buf) {#ifndef DWC_HOST_ONLY#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20) struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);#else dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);#endif gotgctl_data_t val; val.d32 = dwc_read_reg32 (&(otg_dev->core_if->core_global_regs->gotgctl)); return sprintf (buf, "SesReqScs = 0x%x\n", val.b.sesreqscs);#else return sprintf(buf, "Host Only Mode!\n");#endif}/** * Set the SRP Request bit */static ssize_t srp_store( struct device *_dev,#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20) struct device_attribute *attr,#endif const char *buf, size_t count ) {#ifndef DWC_HOST_ONLY#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20) struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);#else dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);#endif dwc_otg_pcd_initiate_srp(otg_dev->pcd);#endif return count;}DEVICE_ATTR(srp, 0644, srp_show, srp_store);/** * @todo Need to do more for power on/off? *//** * Show the Bus Power status */static ssize_t buspower_show( struct device *_dev,#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20) struct device_attribute *attr,#endif char *buf) {#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20) struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);#else dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);#endif hprt0_data_t val; val.d32 = dwc_read_reg32 (otg_dev->core_if->host_if->hprt0); return sprintf (buf, "Bus Power = 0x%x\n", val.b.prtpwr);}/** * Set the Bus Power status */static ssize_t buspower_store( struct device *_dev,#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20) struct device_attribute *attr,#endif const char *buf, size_t count ) {#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20) struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);#else dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);#endif uint32_t on = simple_strtoul(buf, NULL, 16); uint32_t *addr = (uint32_t *)otg_dev->core_if->host_if->hprt0; hprt0_data_t mem; mem.d32 = dwc_read_reg32(addr); mem.b.prtpwr = on; //dev_dbg(_dev, "Storing Address=0x%08x Data=0x%08x\n", (uint32_t)addr, mem.d32); dwc_write_reg32(addr, mem.d32); return count;}DEVICE_ATTR(buspower, 0644, buspower_show, buspower_store);/** * @todo Need to do more for suspend? *//** * Show the Bus Suspend status */static ssize_t bussuspend_show( struct device *_dev,#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20) struct device_attribute *attr,#endif char *buf) {#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20) struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);#else dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -