dwc_otg_attr.c

Go to the documentation of this file.
00001 /* ==========================================================================
00002  * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.c $
00003  * $Revision: #35 $
00004  * $Date: 2009/04/03 $
00005  * $Change: 1225160 $
00006  *
00007  * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
00008  * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
00009  * otherwise expressly agreed to in writing between Synopsys and you.
00010  *
00011  * The Software IS NOT an item of Licensed Software or Licensed Product under
00012  * any End User Software License Agreement or Agreement for Licensed Product
00013  * with Synopsys or any supplement thereto. You are permitted to use and
00014  * redistribute this Software in source and binary forms, with or without
00015  * modification, provided that redistributions of source code must retain this
00016  * notice. You may not view, use, disclose, copy or distribute this file or
00017  * any information contained herein except pursuant to this license grant from
00018  * Synopsys. If you do not agree with this notice, including the disclaimer
00019  * below, then you are not authorized to use the Software.
00020  *
00021  * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
00022  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00024  * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
00025  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00026  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00027  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00028  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00030  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00031  * DAMAGE.
00032  * ========================================================================== */
00033 
00286 #include <linux/kernel.h>
00287 #include <linux/module.h>
00288 #include <linux/moduleparam.h>
00289 #include <linux/init.h>
00290 #include <linux/device.h>
00291 #include <linux/errno.h>
00292 #include <linux/types.h>
00293 #include <linux/stat.h>         /* permission constants */
00294 #include <linux/version.h>
00295 #include <linux/param.h>
00296 #include <linux/delay.h>
00297 #include <linux/jiffies.h>
00298 
00299 
00300 #ifdef LM_INTERFACE
00301 #include <asm/sizes.h>
00302 #include <asm/arch/lm.h>
00303 #endif
00304 
00305 #include <asm/io.h>
00306 
00307 #include "dwc_os.h"
00308 #include "dwc_otg_driver.h"
00309 #include "dwc_otg_attr.h"
00310 #include "dwc_otg_core_if.h"
00311 #include "dwc_otg_pcd_if.h"
00312 #include "dwc_otg_hcd_if.h"
00313 
00314 /*
00315  * MACROs for defining sysfs attribute
00316  */
00317 #ifdef LM_INTERFACE
00318 
00319 #define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
00320 static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
00321 { \
00322         struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
00323         dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);             \
00324         uint32_t val; \
00325         val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
00326         return sprintf (buf, "%s = 0x%x\n", _string_, val); \
00327 }
00328 #define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
00329 static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
00330                                         const char *buf, size_t count) \
00331 { \
00332         struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
00333         dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
00334         uint32_t set = simple_strtoul(buf, NULL, 16); \
00335         dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
00336         return count; \
00337 }
00338 
00339 #elif PCI_INTERFACE
00340 
00341 #define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
00342 static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
00343 { \
00344         dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);      \
00345         uint32_t val; \
00346         val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
00347         return sprintf (buf, "%s = 0x%x\n", _string_, val); \
00348 }
00349 #define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
00350 static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
00351                                         const char *buf, size_t count) \
00352 { \
00353         dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);  \
00354         uint32_t set = simple_strtoul(buf, NULL, 16); \
00355         dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
00356         return count; \
00357 }
00358 
00359 #endif
00360 
00361 /*
00362  * MACROs for defining sysfs attribute for 32-bit registers
00363  */
00364 #ifdef LM_INTERFACE
00365 #define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
00366 static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
00367 { \
00368         struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
00369         dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
00370         uint32_t val; \
00371         val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
00372         return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
00373 }
00374 #define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
00375 static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
00376                                         const char *buf, size_t count) \
00377 { \
00378         struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
00379         dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
00380         uint32_t val = simple_strtoul(buf, NULL, 16); \
00381         dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
00382         return count; \
00383 }
00384 #elif PCI_INTERFACE
00385 #define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
00386 static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
00387 { \
00388         dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);  \
00389         uint32_t val; \
00390         val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
00391         return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
00392 }
00393 #define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
00394 static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
00395                                         const char *buf, size_t count) \
00396 { \
00397         dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);  \
00398         uint32_t val = simple_strtoul(buf, NULL, 16); \
00399         dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
00400         return count; \
00401 }
00402 
00403 #endif
00404 
00405 #define DWC_OTG_DEVICE_ATTR_BITFIELD_RW(_otg_attr_name_,_string_) \
00406 DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
00407 DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
00408 DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
00409 
00410 #define DWC_OTG_DEVICE_ATTR_BITFIELD_RO(_otg_attr_name_,_string_) \
00411 DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
00412 DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
00413 
00414 #define DWC_OTG_DEVICE_ATTR_REG32_RW(_otg_attr_name_,_addr_,_string_) \
00415 DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
00416 DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
00417 DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
00418 
00419 #define DWC_OTG_DEVICE_ATTR_REG32_RO(_otg_attr_name_,_addr_,_string_) \
00420 DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
00421 DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
00422 
00429 static ssize_t regoffset_show(struct device *_dev,
00430                               struct device_attribute *attr, char *buf)
00431 {
00432 #ifdef LM_INTERFACE
00433         struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
00434         dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
00435 #elif PCI_INTERFACE
00436         dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
00437 #endif
00438 
00439         return snprintf(buf, sizeof("0xFFFFFFFF\n") + 1, "0x%08x\n",
00440                         otg_dev->reg_offset);
00441 }
00442 
00446 static ssize_t regoffset_store(struct device *_dev,
00447                                struct device_attribute *attr,
00448                                const char *buf, size_t count)
00449 {
00450 #ifdef LM_INTERFACE
00451         struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
00452         dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
00453 #elif PCI_INTERFACE
00454         dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
00455 #endif
00456 
00457         uint32_t offset = simple_strtoul(buf, NULL, 16);
00458 #ifdef LM_INTERFACE
00459         if (offset < SZ_256K) {
00460 #elif  PCI_INTERFACE
00461         if (offset < 0x00040000) {
00462 #endif
00463                 otg_dev->reg_offset = offset;
00464         } else {
00465                 dev_err(_dev, "invalid offset\n");
00466         }
00467 
00468         return count;
00469 }
00470 
00471 DEVICE_ATTR(regoffset, S_IRUGO | S_IWUSR, regoffset_show, regoffset_store);
00472 
00477 static ssize_t regvalue_show(struct device *_dev,
00478                              struct device_attribute *attr, char *buf)
00479 {
00480 #ifdef LM_INTERFACE
00481         struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
00482         dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
00483 #elif PCI_INTERFACE
00484         dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
00485 #endif
00486 
00487         uint32_t val;
00488         volatile uint32_t *addr;
00489 
00490         if (otg_dev->reg_offset != 0xFFFFFFFF && 0 != otg_dev->base) {
00491                 /* Calculate the address */
00492                 addr = (uint32_t *) (otg_dev->reg_offset +
00493                                      (uint8_t *) otg_dev->base);
00494                 val = dwc_read_reg32(addr);
00495                 return snprintf(buf,
00496                                 sizeof("Reg@0xFFFFFFFF = 0xFFFFFFFF\n") + 1,
00497                                 "Reg@0x%06x = 0x%08x\n", otg_dev->reg_offset,
00498                                 val);
00499         } else {
00500                 dev_err(_dev, "Invalid offset (0x%0x)\n", otg_dev->reg_offset);
00501                 return sprintf(buf, "invalid offset\n");
00502         }
00503 }
00504 
00510 static ssize_t regvalue_store(struct device *_dev,
00511                               struct device_attribute *attr,
00512                               const char *buf, size_t count)
00513 {
00514 #ifdef LM_INTERFACE
00515         struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
00516         dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
00517 #elif PCI_INTERFACE
00518         dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
00519 #endif
00520 
00521         volatile uint32_t *addr;
00522         uint32_t val = simple_strtoul(buf, NULL, 16);
00523         //dev_dbg(_dev, "Offset=0x%08x Val=0x%08x\n", otg_dev->reg_offset, val);
00524         if (otg_dev->reg_offset != 0xFFFFFFFF && 0 != otg_dev->base) {
00525                 /* Calculate the address */
00526                 addr = (uint32_t *) (otg_dev->reg_offset +
00527                                      (uint8_t *) otg_dev->base);
00528                 dwc_write_reg32(addr, val);
00529         } else {
00530                 dev_err(_dev, "Invalid Register Offset (0x%08x)\n",
00531                         otg_dev->reg_offset);
00532         }
00533         return count;
00534 }
00535 
00536 DEVICE_ATTR(regvalue, S_IRUGO | S_IWUSR, regvalue_show, regvalue_store);
00537 
00538 /*
00539  * Attributes
00540  */
00541 DWC_OTG_DEVICE_ATTR_BITFIELD_RO(mode, "Mode");
00542 DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hnpcapable, "HNPCapable");
00543 DWC_OTG_DEVICE_ATTR_BITFIELD_RW(srpcapable, "Mode");
00544 DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hsic_connect, "HSIC Connect");
00545 DWC_OTG_DEVICE_ATTR_BITFIELD_RW(inv_sel_hsic, "Invert Select HSIC");
00546 
00547 //DWC_OTG_DEVICE_ATTR_BITFIELD_RW(buspower,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
00548 //DWC_OTG_DEVICE_ATTR_BITFIELD_RW(bussuspend,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
00549 DWC_OTG_DEVICE_ATTR_BITFIELD_RO(busconnected, "Bus Connected");
00550 
00551 DWC_OTG_DEVICE_ATTR_REG32_RW(gotgctl, 0, "GOTGCTL");
00552 DWC_OTG_DEVICE_ATTR_REG32_RW(gusbcfg,
00553                              &(otg_dev->core_if->core_global_regs->gusbcfg),
00554                              "GUSBCFG");
00555 DWC_OTG_DEVICE_ATTR_REG32_RW(grxfsiz,
00556                              &(otg_dev->core_if->core_global_regs->grxfsiz),
00557                              "GRXFSIZ");
00558 DWC_OTG_DEVICE_ATTR_REG32_RW(gnptxfsiz,
00559                              &(otg_dev->core_if->core_global_regs->gnptxfsiz),
00560                              "GNPTXFSIZ");
00561 DWC_OTG_DEVICE_ATTR_REG32_RW(gpvndctl,
00562                              &(otg_dev->core_if->core_global_regs->gpvndctl),
00563                              "GPVNDCTL");
00564 DWC_OTG_DEVICE_ATTR_REG32_RW(ggpio,
00565                              &(otg_dev->core_if->core_global_regs->ggpio),
00566                              "GGPIO");
00567 DWC_OTG_DEVICE_ATTR_REG32_RW(guid, &(otg_dev->core_if->core_global_regs->guid),
00568                              "GUID");
00569 DWC_OTG_DEVICE_ATTR_REG32_RO(gsnpsid,
00570                              &(otg_dev->core_if->core_global_regs->gsnpsid),
00571                              "GSNPSID");
00572 DWC_OTG_DEVICE_ATTR_BITFIELD_RW(devspeed, "Device Speed");
00573 DWC_OTG_DEVICE_ATTR_BITFIELD_RO(enumspeed, "Device Enumeration Speed");
00574 
00575 DWC_OTG_DEVICE_ATTR_REG32_RO(hptxfsiz,
00576                              &(otg_dev->core_if->core_global_regs->hptxfsiz),
00577                              "HPTXFSIZ");
00578 DWC_OTG_DEVICE_ATTR_REG32_RW(hprt0, otg_dev->core_if->host_if->hprt0, "HPRT0");
00579 
00586 static ssize_t hnp_show(struct device *_dev,
00587                         struct device_attribute *attr, char *buf)
00588 {
00589 #ifdef LM_INTERFACE
00590         struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
00591         dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
00592 #elif PCI_INTERFACE
00593         dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
00594 #endif
00595         return sprintf(buf, "HstNegScs = 0x%x\n",
00596                        dwc_otg_get_hnpstatus(otg_dev->core_if));
00597 }
00598 
00602 static ssize_t hnp_store(struct device *_dev,
00603                          struct device_attribute *attr,
00604                          const char *buf, size_t count)
00605 {
00606 #ifdef LM_INTERFACE
00607         struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
00608         dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
00609 #elif PCI_INTERFACE
00610         dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
00611 #endif
00612         uint32_t in = simple_strtoul(buf, NULL, 16);
00613         dwc_otg_set_hnpreq(otg_dev->core_if, in);
00614         return count;
00615 }
00616 
00617 DEVICE_ATTR(hnp, 0644, hnp_show, hnp_store);
00618 
00625 static ssize_t srp_show(struct device *_dev,
00626                         struct device_attribute *attr, char *buf)
00627 {
00628 #ifndef DWC_HOST_ONLY
00629 #ifdef LM_INTERFACE
00630         struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
00631         dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
00632 #elif PCI_INTERFACE
00633         dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
00634 #endif
00635         return sprintf(buf, "SesReqScs = 0x%x\n",
00636                        dwc_otg_get_srpstatus(otg_dev->core_if));
00637 #else
00638         return sprintf(buf, "Host Only Mode!\n");
00639 #endif
00640 }
00641 
00645 static ssize_t srp_store(struct device *_dev,
00646                          struct device_attribute *attr,
00647                          const char *buf, size_t count)
00648 {
00649 #ifndef DWC_HOST_ONLY
00650 #ifdef LM_INTERFACE
00651         struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
00652         dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
00653 #elif PCI_INTERFACE
00654         dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
00655 #endif
00656         dwc_otg_pcd_initiate_srp(otg_dev->pcd);
00657 #endif
00658         return count;
00659 }
00660 
00661 DEVICE_ATTR(srp, 0644, srp_show, srp_store);
00662 
00669 static ssize_t buspower_show(struct device *_dev,
00670                              struct device_attribute *attr, char *buf)
00671 {
00672 #ifdef LM_INTERFACE
00673         struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
00674         dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
00675 #elif PCI_INTERFACE
00676         dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
00677 #endif
00678         return sprintf(buf, "Bus Power = 0x%x\n",
00679                        dwc_otg_get_prtpower(otg_dev->core_if));
00680 }
00681 
00685 static ssize_t buspower_store(struct device *_dev,
00686                               struct device_attribute *attr,
00687                               const char *buf, size_t count)
00688 {
00689 #ifdef LM_INTERFACE
00690         struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
00691         dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
00692 #elif PCI_INTERFACE
00693         dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
00694 #endif
00695         uint32_t on = simple_strtoul(buf, NULL, 16);
00696         dwc_otg_set_prtpower(otg_dev->core_if, on);
00697         return count;
00698 }
00699 
00700 DEVICE_ATTR(buspower, 0644, buspower_show, buspower_store);
00701 
00708 static ssize_t bussuspend_show(struct device *_dev,
00709                                struct device_attribute *attr, char *buf)
00710 {
00711 #ifdef LM_INTERFACE
00712         struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
00713         dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
00714 #elif PCI_INTERFACE
00715         dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
00716 #endif
00717 
00718         return sprintf(buf, "Bus Suspend = 0x%x\n",
00719                        dwc_otg_get_prtsuspend(otg_dev->core_if));
00720 }
00721 
00725 static ssize_t bussuspend_store(struct device *_dev,
00726                                 struct device_attribute *attr,
00727                                 const char *buf, size_t count)
00728 {
00729 #ifdef LM_INTERFACE
00730         struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
00731         dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
00732 #elif PCI_INTERFACE
00733         dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
00734 #endif
00735 
00736         uint32_t in = simple_strtoul(buf, NULL, 16);
00737         dwc_otg_set_prtsuspend(otg_dev->core_if, in);
00738         return count;
00739 }
00740 
00741 DEVICE_ATTR(bussuspend, 0644, bussuspend_show, bussuspend_store);
00742 
00746 static ssize_t remote_wakeup_show(struct device *_dev,
00747                                   struct device_attribute *attr, char *buf)
00748 {
00749 #ifndef DWC_HOST_ONLY
00750 #ifdef LM_INTERFACE
00751         struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
00752         dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
00753 #elif PCI_INTERFACE
00754         dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
00755 #endif
00756 
00757         return sprintf(buf,
00758                        "Remote Wakeup Sig = %d Enabled = %d LPM Remote Wakeup = %d\n",
00759                        dwc_otg_get_remotewakesig(otg_dev->core_if),
00760                        dwc_otg_pcd_get_rmwkup_enable(otg_dev->pcd),
00761                        dwc_otg_get_lpm_remotewakeenabled(otg_dev->core_if));
00762 #else
00763         return sprintf(buf, "Host Only Mode!\n");
00764 #endif /* DWC_HOST_ONLY */
00765 }
00766 
00773 static ssize_t remote_wakeup_store(struct device *_dev,
00774                                    struct device_attribute *attr,
00775                                    const char *buf, size_t count)
00776 {
00777 #ifndef DWC_HOST_ONLY
00778 #ifdef LM_INTERFACE
00779         struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
00780         dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
00781 #elif PCI_INTERFACE
00782         dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
00783 #endif
00784 
00785         uint32_t val = simple_strtoul(buf, NULL, 16);
00786 
00787         if (val & 1) {
00788                 dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 1);
00789         } else {
00790                 dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 0);
00791         }
00792 #endif /* DWC_HOST_ONLY */
00793         return count;
00794 }
00795 
00796 DEVICE_ATTR(remote_wakeup, S_IRUGO | S_IWUSR, remote_wakeup_show,
00797             remote_wakeup_store);
00798 
00803 static ssize_t regdump_show(struct device *_dev,
00804                             struct device_attribute *attr, char *buf)
00805 {
00806 #ifdef LM_INTERFACE
00807         struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
00808         dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
00809 #elif PCI_INTERFACE
00810         dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
00811 #endif
00812 
00813         dwc_otg_dump_global_registers(otg_dev->core_if);
00814         if (dwc_otg_is_host_mode(otg_dev->core_if)) {
00815                 dwc_otg_dump_host_registers(otg_dev->core_if);
00816         } else {
00817                 dwc_otg_dump_dev_registers(otg_dev->core_if);
00818 
00819         }
00820         return sprintf(buf, "Register Dump\n");
00821 }
00822 
00823 DEVICE_ATTR(regdump, S_IRUGO | S_IWUSR, regdump_show, 0);
00824 
00829 static ssize_t spramdump_show(struct device *_dev,
00830                               struct device_attribute *attr, char *buf)
00831 {
00832 #ifdef LM_INTERFACE
00833         struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
00834         dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
00835 #elif PCI_INTERFACE
00836         dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
00837 #endif
00838 
00839         dwc_otg_dump_spram(otg_dev->core_if);
00840 
00841         return sprintf(buf, "SPRAM Dump\n");
00842 }
00843 
00844 DEVICE_ATTR(spramdump, S_IRUGO | S_IWUSR, spramdump_show, 0);
00845 
00849 static ssize_t hcddump_show(struct device *_dev,
00850                             struct device_attribute *attr, char *buf)
00851 {
00852 #ifndef DWC_DEVICE_ONLY
00853 #ifdef LM_INTERFACE
00854         struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
00855         dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
00856 #elif PCI_INTERFACE
00857         dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
00858 #endif
00859 
00860         dwc_otg_hcd_dump_state(otg_dev->hcd);
00861 #endif /* DWC_DEVICE_ONLY */
00862         return sprintf(buf, "HCD Dump\n");
00863 }
00864 
00865 DEVICE_ATTR(hcddump, S_IRUGO | S_IWUSR, hcddump_show, 0);
00866 
00872 static ssize_t hcd_frrem_show(struct device *_dev,
00873                               struct device_attribute *attr, char *buf)
00874 {
00875 #ifndef DWC_DEVICE_ONLY
00876 #ifdef LM_INTERFACE
00877         struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
00878         dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
00879 #elif PCI_INTERFACE
00880         dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
00881 #endif
00882 
00883         dwc_otg_hcd_dump_frrem(otg_dev->hcd);
00884 #endif /* DWC_DEVICE_ONLY */
00885         return sprintf(buf, "HCD Dump Frame Remaining\n");
00886 }
00887 
00888 DEVICE_ATTR(hcd_frrem, S_IRUGO | S_IWUSR, hcd_frrem_show, 0);
00889 
00894 #define RW_REG_COUNT 10000000
00895 #define MSEC_PER_JIFFIE 1000/HZ
00896 static ssize_t rd_reg_test_show(struct device *_dev,
00897                                 struct device_attribute *attr, char *buf)
00898 {
00899 #ifdef LM_INTERFACE
00900         struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
00901         dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
00902 #elif PCI_INTERFACE
00903         dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
00904 #endif
00905 
00906         int i;
00907         int time;
00908         int start_jiffies;
00909 
00910         printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
00911                HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
00912         start_jiffies = jiffies;
00913         for (i = 0; i < RW_REG_COUNT; i++) {
00914                 dwc_otg_get_gnptxfsiz(otg_dev->core_if);
00915         }
00916         time = jiffies - start_jiffies;
00917         return sprintf(buf,
00918                        "Time to read GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
00919                        RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
00920 }
00921 
00922 DEVICE_ATTR(rd_reg_test, S_IRUGO | S_IWUSR, rd_reg_test_show, 0);
00923 
00928 static ssize_t wr_reg_test_show(struct device *_dev,
00929                                 struct device_attribute *attr, char *buf)
00930 {
00931 #ifdef LM_INTERFACE
00932         struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
00933         dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
00934 #elif PCI_INTERFACE
00935         dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
00936 #endif
00937 
00938         uint32_t reg_val;
00939         int i;
00940         int time;
00941         int start_jiffies;
00942 
00943         printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
00944                HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
00945         reg_val = dwc_otg_get_gnptxfsiz(otg_dev->core_if);
00946         start_jiffies = jiffies;
00947         for (i = 0; i < RW_REG_COUNT; i++) {
00948                 dwc_otg_set_gnptxfsiz(otg_dev->core_if, reg_val);
00949         }
00950         time = jiffies - start_jiffies;
00951         return sprintf(buf,
00952                        "Time to write GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
00953                        RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
00954 }
00955 
00956 DEVICE_ATTR(wr_reg_test, S_IRUGO | S_IWUSR, wr_reg_test_show, 0);
00957 
00958 #ifdef CONFIG_USB_DWC_OTG_LPM
00959 
00963 static ssize_t lpmresp_show(struct device *_dev,
00964                             struct device_attribute *attr, char *buf)
00965 {
00966 #ifdef LM_INTERFACE
00967         struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
00968         dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
00969 #elif PCI_INTERFACE
00970         dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
00971 #endif
00972 
00973         if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if))
00974                 return sprintf(buf, "** LPM is DISABLED **\n");
00975 
00976         if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
00977                 return sprintf(buf, "** Current mode is not device mode\n");
00978         }
00979         return sprintf(buf, "lpm_response = %d\n",
00980                        dwc_otg_get_lpmresponse(otg_dev->core_if));
00981 }
00982 
00986 static ssize_t lpmresp_store(struct device *_dev,
00987                              struct device_attribute *attr,
00988                              const char *buf, size_t count)
00989 {
00990 #ifdef LM_INTERFACE
00991         struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
00992         dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
00993 #elif PCI_INTERFACE
00994         dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
00995 #endif
00996 
00997         uint32_t val = simple_strtoul(buf, NULL, 16);
00998 
00999         if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if)) {
01000                 return 0;
01001         }
01002 
01003         if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
01004                 return 0;
01005         }
01006 
01007         dwc_otg_set_lpmresponse(otg_dev->core_if, val);
01008         return count;
01009 }
01010 
01011 DEVICE_ATTR(lpm_response, S_IRUGO | S_IWUSR, lpmresp_show, lpmresp_store);
01012 
01016 static ssize_t sleepstatus_show(struct device *_dev,
01017                                 struct device_attribute *attr, char *buf)
01018 {
01019 #ifdef LM_INTERFACE
01020         struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
01021         dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
01022 #elif PCI_INTERFACE
01023         dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
01024 #endif
01025 
01026 
01027         return sprintf(buf, "Sleep Status = %d\n",
01028                        dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if));
01029 }
01030 
01034 static ssize_t sleepstatus_store(struct device *_dev,
01035                                  struct device_attribute *attr,
01036                                  const char *buf, size_t count)
01037 {
01038 #ifdef LM_INTERFACE
01039         struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
01040         dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
01041 #elif PCI_INTERFACE
01042         dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
01043 #endif
01044 
01045         dwc_otg_core_if_t *core_if = otg_dev->core_if;
01046 
01047         if (dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if)) {
01048                 if (dwc_otg_is_host_mode(core_if)) {
01049 
01050                         DWC_PRINTF("Host initiated resume\n");
01051                         dwc_otg_set_prtresume(otg_dev->core_if, 1);
01052                 }
01053         }
01054 
01055         return count;
01056 }
01057 
01058 DEVICE_ATTR(sleep_status, S_IRUGO | S_IWUSR, sleepstatus_show,
01059             sleepstatus_store);
01060 
01061 #endif                          /* CONFIG_USB_DWC_OTG_LPM_ENABLE */
01062 
01068 void dwc_otg_attr_create (
01069 #ifdef LM_INTERFACE
01070         struct lm_device *dev
01071 #elif  PCI_INTERFACE
01072         struct pci_dev *dev
01073 #endif
01074         )
01075 
01076 {
01077         int error;
01078 
01079         error = device_create_file(&dev->dev, &dev_attr_regoffset);
01080         error = device_create_file(&dev->dev, &dev_attr_regvalue);
01081         error = device_create_file(&dev->dev, &dev_attr_mode);
01082         error = device_create_file(&dev->dev, &dev_attr_hnpcapable);
01083         error = device_create_file(&dev->dev, &dev_attr_srpcapable);
01084         error = device_create_file(&dev->dev, &dev_attr_hsic_connect);
01085         error = device_create_file(&dev->dev, &dev_attr_inv_sel_hsic);
01086         error = device_create_file(&dev->dev, &dev_attr_hnp);
01087         error = device_create_file(&dev->dev, &dev_attr_srp);
01088         error = device_create_file(&dev->dev, &dev_attr_buspower);
01089         error = device_create_file(&dev->dev, &dev_attr_bussuspend);
01090         error = device_create_file(&dev->dev, &dev_attr_busconnected);
01091         error = device_create_file(&dev->dev, &dev_attr_gotgctl);
01092         error = device_create_file(&dev->dev, &dev_attr_gusbcfg);
01093         error = device_create_file(&dev->dev, &dev_attr_grxfsiz);
01094         error = device_create_file(&dev->dev, &dev_attr_gnptxfsiz);
01095         error = device_create_file(&dev->dev, &dev_attr_gpvndctl);
01096         error = device_create_file(&dev->dev, &dev_attr_ggpio);
01097         error = device_create_file(&dev->dev, &dev_attr_guid);
01098         error = device_create_file(&dev->dev, &dev_attr_gsnpsid);
01099         error = device_create_file(&dev->dev, &dev_attr_devspeed);
01100         error = device_create_file(&dev->dev, &dev_attr_enumspeed);
01101         error = device_create_file(&dev->dev, &dev_attr_hptxfsiz);
01102         error = device_create_file(&dev->dev, &dev_attr_hprt0);
01103         error = device_create_file(&dev->dev, &dev_attr_remote_wakeup);
01104         error = device_create_file(&dev->dev, &dev_attr_regdump);
01105         error = device_create_file(&dev->dev, &dev_attr_spramdump);
01106         error = device_create_file(&dev->dev, &dev_attr_hcddump);
01107         error = device_create_file(&dev->dev, &dev_attr_hcd_frrem);
01108         error = device_create_file(&dev->dev, &dev_attr_rd_reg_test);
01109         error = device_create_file(&dev->dev, &dev_attr_wr_reg_test);
01110 #ifdef CONFIG_USB_DWC_OTG_LPM
01111         error = device_create_file(&dev->dev, &dev_attr_lpm_response);
01112         error = device_create_file(&dev->dev, &dev_attr_sleep_status);
01113 #endif
01114 }
01115 
01119 void dwc_otg_attr_remove (
01120 #ifdef LM_INTERFACE
01121         struct lm_device *dev
01122 #elif  PCI_INTERFACE
01123         struct pci_dev *dev
01124 #endif
01125        )
01126 
01127 {
01128         device_remove_file(&dev->dev, &dev_attr_regoffset);
01129         device_remove_file(&dev->dev, &dev_attr_regvalue);
01130         device_remove_file(&dev->dev, &dev_attr_mode);
01131         device_remove_file(&dev->dev, &dev_attr_hnpcapable);
01132         device_remove_file(&dev->dev, &dev_attr_srpcapable);
01133         device_remove_file(&dev->dev, &dev_attr_hsic_connect);
01134         device_remove_file(&dev->dev, &dev_attr_inv_sel_hsic);
01135         device_remove_file(&dev->dev, &dev_attr_hnp);
01136         device_remove_file(&dev->dev, &dev_attr_srp);
01137         device_remove_file(&dev->dev, &dev_attr_buspower);
01138         device_remove_file(&dev->dev, &dev_attr_bussuspend);
01139         device_remove_file(&dev->dev, &dev_attr_busconnected);
01140         device_remove_file(&dev->dev, &dev_attr_gotgctl);
01141         device_remove_file(&dev->dev, &dev_attr_gusbcfg);
01142         device_remove_file(&dev->dev, &dev_attr_grxfsiz);
01143         device_remove_file(&dev->dev, &dev_attr_gnptxfsiz);
01144         device_remove_file(&dev->dev, &dev_attr_gpvndctl);
01145         device_remove_file(&dev->dev, &dev_attr_ggpio);
01146         device_remove_file(&dev->dev, &dev_attr_guid);
01147         device_remove_file(&dev->dev, &dev_attr_gsnpsid);
01148         device_remove_file(&dev->dev, &dev_attr_devspeed);
01149         device_remove_file(&dev->dev, &dev_attr_enumspeed);
01150         device_remove_file(&dev->dev, &dev_attr_hptxfsiz);
01151         device_remove_file(&dev->dev, &dev_attr_hprt0);
01152         device_remove_file(&dev->dev, &dev_attr_remote_wakeup);
01153         device_remove_file(&dev->dev, &dev_attr_regdump);
01154         device_remove_file(&dev->dev, &dev_attr_spramdump);
01155         device_remove_file(&dev->dev, &dev_attr_hcddump);
01156         device_remove_file(&dev->dev, &dev_attr_hcd_frrem);
01157         device_remove_file(&dev->dev, &dev_attr_rd_reg_test);
01158         device_remove_file(&dev->dev, &dev_attr_wr_reg_test);
01159 #ifdef CONFIG_USB_DWC_OTG_LPM
01160         device_remove_file(&dev->dev, &dev_attr_lpm_response);
01161         device_remove_file(&dev->dev, &dev_attr_sleep_status);
01162 #endif
01163 }

Generated on Tue May 5 02:22:48 2009 for DesignWare USB 2.0 OTG Controller (DWC_otg) Device Driver by  doxygen 1.4.7