1 /* ==========================================================================
2 * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.c $
7 * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
8 * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
9 * otherwise expressly agreed to in writing between Synopsys and you.
11 * The Software IS NOT an item of Licensed Software or Licensed Product under
12 * any End User Software License Agreement or Agreement for Licensed Product
13 * with Synopsys or any supplement thereto. You are permitted to use and
14 * redistribute this Software in source and binary forms, with or without
15 * modification, provided that redistributions of source code must retain this
16 * notice. You may not view, use, disclose, copy or distribute this file or
17 * any information contained herein except pursuant to this license grant from
18 * Synopsys. If you do not agree with this notice, including the disclaimer
19 * below, then you are not authorized to use the Software.
21 * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
32 * ========================================================================== */
36 * The diagnostic interface will provide access to the controller for
37 * bringing up the hardware and testing. The Linux driver attributes
38 * feature will be used to provide the Linux Diagnostic
39 * Interface. These attributes are accessed through sysfs.
42 /** @page "Linux Module Attributes"
44 * The Linux module attributes feature is used to provide the Linux
45 * Diagnostic Interface. These attributes are accessed through sysfs.
46 * The diagnostic interface will provide access to the controller for
47 * bringing up the hardware and testing.
49 The following table shows the attributes.
53 <td><b> Description</b></td>
54 <td><b> Access</b></td>
59 <td> Returns the current mode: 0 for device mode, 1 for host mode</td>
65 <td> Gets or sets the "HNP-capable" bit in the Core USB Configuraton Register.
66 Read returns the current value.</td>
72 <td> Gets or sets the "SRP-capable" bit in the Core USB Configuraton Register.
73 Read returns the current value.</td>
78 <td> hsic_connect </td>
79 <td> Gets or sets the "HSIC-Connect" bit in the GLPMCFG Register.
80 Read returns the current value.</td>
85 <td> inv_sel_hsic </td>
86 <td> Gets or sets the "Invert Select HSIC" bit in the GLPMFG Register.
87 Read returns the current value.</td>
93 <td> Initiates the Host Negotiation Protocol. Read returns the status.</td>
99 <td> Initiates the Session Request Protocol. Read returns the status.</td>
105 <td> Gets or sets the Power State of the bus (0 - Off or 1 - On)</td>
110 <td> bussuspend </td>
111 <td> Suspends the USB bus.</td>
116 <td> busconnected </td>
117 <td> Gets the connection status of the bus</td>
123 <td> Gets or sets the Core Control Status Register.</td>
129 <td> Gets or sets the Core USB Configuration Register</td>
135 <td> Gets or sets the Receive FIFO Size Register</td>
141 <td> Gets or sets the non-periodic Transmit Size Register</td>
147 <td> Gets or sets the PHY Vendor Control Register</td>
153 <td> Gets the value in the lower 16-bits of the General Purpose IO Register
154 or sets the upper 16 bits.</td>
160 <td> Gets or sets the value of the User ID Register</td>
166 <td> Gets the value of the Synopsys ID Regester</td>
172 <td> Gets or sets the device speed setting in the DCFG register</td>
178 <td> Gets the device enumeration Speed.</td>
184 <td> Gets the value of the Host Periodic Transmit FIFO</td>
190 <td> Gets or sets the value in the Host Port Control and Status Register</td>
196 <td> Sets the register offset for the next Register Access</td>
202 <td> Gets or sets the value of the register at the offset in the regoffset attribute.</td>
207 <td> remote_wakeup </td>
208 <td> On read, shows the status of Remote Wakeup. On write, initiates a remote
209 wakeup of the host. When bit 0 is 1 and Remote Wakeup is enabled, the Remote
210 Wakeup signalling bit in the Device Control Register is set for 1
216 <td> rem_wakeup_pwrdn </td>
217 <td> On read, shows the status core - hibernated or not. On write, initiates
218 a remote wakeup of the device from Hibernation. </td>
223 <td> mode_ch_tim_en </td>
224 <td> This bit is used to enable or disable the host core to wait for 200 PHY
225 clock cycles at the end of Resume to change the opmode signal to the PHY to 00
226 after Suspend or LPM. </td>
231 <td> fr_interval </td>
232 <td> On read, shows the value of HFIR Frame Interval. On write, dynamically
233 reload HFIR register during runtime. The application can write a value to this
234 register only after the Port Enable bit of the Host Port Control and Status
235 register (HPRT.PrtEnaPort) has been set </td>
240 <td> disconnect_us </td>
241 <td> On read, shows the status of disconnect_device_us. On write, sets disconnect_us
242 which causes soft disconnect for 100us. Applicable only for device mode of operation.</td>
248 <td> Dumps the contents of core registers.</td>
254 <td> Dumps the contents of core registers.</td>
260 <td> Dumps the current HCD state.</td>
266 <td> Shows the average value of the Frame Remaining
267 field in the Host Frame Number/Frame Remaining register when an SOF interrupt
268 occurs. This can be used to determine the average interrupt latency. Also
269 shows the average Frame Remaining value for start_transfer and the "a" and
270 "b" sample points. The "a" and "b" sample points may be used during debugging
271 bto determine how long it takes to execute a section of the HCD code.</td>
276 <td> rd_reg_test </td>
277 <td> Displays the time required to read the GNPTXFSIZ register many times
278 (the output shows the number of times the register is read).
283 <td> wr_reg_test </td>
284 <td> Displays the time required to write the GNPTXFSIZ register many times
285 (the output shows the number of times the register is written).
290 <td> lpm_response </td>
291 <td> Gets or sets lpm_response mode. Applicable only in device mode.
296 <td> sleep_status </td>
297 <td> Shows sleep status of device.
302 <td> hird_thres </td>
303 <td> Gets or sets the "HIRD_Thres[3:0]" bits in the Core LPM Configuration Register.
308 <td> besl_reject </td>
309 <td> Gets or sets the "besl_reject" bit in the Device Control Register.
316 To get the current mode:
317 cat /sys/devices/lm0/mode
319 To power down the USB:
320 echo 0 > /sys/devices/lm0/buspower
323 #include "dwc_otg_os_dep.h"
324 #include "common_port/dwc_os.h"
325 #include "dwc_otg_driver.h"
326 #include "dwc_otg_attr.h"
327 #include "dwc_otg_core_if.h"
328 #include "dwc_otg_pcd_if.h"
329 #include "dwc_otg_hcd_if.h"
332 * MACROs for defining sysfs attribute
336 #define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
337 static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
340 dwc_otg_device_t *otg_dev = _dev->platform_data; \
342 val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
343 return sprintf (buf, "%s = 0x%x\n", _string_, val); \
345 #define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
346 static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
347 const char *buf, size_t count) \
350 dwc_otg_device_t *otg_dev = _dev->platform_data; \
351 uint32_t set = simple_strtoul(buf, NULL, 16); \
352 dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
357 * MACROs for defining sysfs attribute for 32-bit registers
360 #define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
361 static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
364 dwc_otg_device_t *otg_dev = _dev->platform_data; \
366 val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
367 return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
369 #define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
370 static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
371 const char *buf, size_t count) \
374 dwc_otg_device_t *otg_dev = _dev->platform_data; \
375 uint32_t val = simple_strtoul(buf, NULL, 16); \
376 dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
380 #define DWC_OTG_DEVICE_ATTR_BITFIELD_RW(_otg_attr_name_,_string_) \
381 DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
382 DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
383 DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
385 #define DWC_OTG_DEVICE_ATTR_BITFIELD_RO(_otg_attr_name_,_string_) \
386 DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
387 DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
389 #define DWC_OTG_DEVICE_ATTR_REG32_RW(_otg_attr_name_,_addr_,_string_) \
390 DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
391 DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
392 DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
394 #define DWC_OTG_DEVICE_ATTR_REG32_RO(_otg_attr_name_,_addr_,_string_) \
395 DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
396 DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
398 void dwc_set_device_platform_data(struct platform_device *pdev, void *data)
400 if(NULL == pdev || NULL == &pdev->dev)
401 DWC_ERROR("NULL Pointer in func %s \n", __func__);
403 pdev->dev.platform_data = data;
406 void *dwc_get_device_platform_data(const struct platform_device *pdev)
408 if(NULL == pdev || NULL == &pdev->dev)
409 DWC_ERROR("NULL Pointer in func %s \n", __func__);
411 return pdev->dev.platform_data;
414 /** @name Functions for Show/Store of Attributes */
418 * Show the register offset of the Register Access.
420 static ssize_t regoffset_show(struct device *_dev,
421 struct device_attribute *attr, char *buf)
425 dwc_otg_device_t *otg_dev = _dev->platform_data;
427 return snprintf(buf, sizeof("0xFFFFFFFF\n") + 1, "0x%08x\n",
428 otg_dev->os_dep.reg_offset);
432 * Set the register offset for the next Register Access Read/Write
434 static ssize_t regoffset_store(struct device *_dev,
435 struct device_attribute *attr,
436 const char *buf, size_t count)
440 dwc_otg_device_t *otg_dev = _dev->platform_data;
441 uint32_t offset = simple_strtoul(buf, NULL, 16);
443 if (offset < SZ_256K) {
444 otg_dev->os_dep.reg_offset = offset;
446 dev_err(_dev, "invalid offset\n");
452 DEVICE_ATTR(regoffset, S_IRUGO | S_IWUSR, regoffset_show, regoffset_store);
455 * Show the value of the register at the offset in the reg_offset
458 static ssize_t regvalue_show(struct device *_dev,
459 struct device_attribute *attr, char *buf)
463 dwc_otg_device_t *otg_dev = _dev->platform_data;
465 volatile uint32_t *addr;
467 if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF && 0 != otg_dev->os_dep.base) {
468 /* Calculate the address */
469 addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
470 (uint8_t *) otg_dev->os_dep.base);
471 val = DWC_READ_REG32(addr);
473 sizeof("Reg@0xFFFFFFFF = 0xFFFFFFFF\n") + 1,
474 "Reg@0x%06x = 0x%08x\n", otg_dev->os_dep.reg_offset,
477 dev_err(_dev, "Invalid offset (0x%0x)\n", otg_dev->os_dep.reg_offset);
478 return sprintf(buf, "invalid offset\n");
483 * Store the value in the register at the offset in the reg_offset
487 static ssize_t regvalue_store(struct device *_dev,
488 struct device_attribute *attr,
489 const char *buf, size_t count)
493 dwc_otg_device_t *otg_dev = _dev->platform_data;
494 volatile uint32_t *addr;
495 uint32_t val = simple_strtoul(buf, NULL, 16);
496 //dev_dbg(_dev, "Offset=0x%08x Val=0x%08x\n", otg_dev->reg_offset, val);
497 if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF && 0 != otg_dev->os_dep.base) {
498 /* Calculate the address */
499 addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
500 (uint8_t *) otg_dev->os_dep.base);
501 DWC_WRITE_REG32(addr, val);
503 dev_err(_dev, "Invalid Register Offset (0x%08x)\n",
504 otg_dev->os_dep.reg_offset);
509 DEVICE_ATTR(regvalue, S_IRUGO | S_IWUSR, regvalue_show, regvalue_store);
514 DWC_OTG_DEVICE_ATTR_BITFIELD_RO(mode, "Mode");
515 DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hnpcapable, "HNPCapable");
516 DWC_OTG_DEVICE_ATTR_BITFIELD_RW(srpcapable, "SRPCapable");
517 DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hsic_connect, "HSIC Connect");
518 DWC_OTG_DEVICE_ATTR_BITFIELD_RW(inv_sel_hsic, "Invert Select HSIC");
520 //DWC_OTG_DEVICE_ATTR_BITFIELD_RW(buspower,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
521 //DWC_OTG_DEVICE_ATTR_BITFIELD_RW(bussuspend,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
522 DWC_OTG_DEVICE_ATTR_BITFIELD_RO(busconnected, "Bus Connected");
524 DWC_OTG_DEVICE_ATTR_REG32_RW(gotgctl, 0, "GOTGCTL");
525 DWC_OTG_DEVICE_ATTR_REG32_RW(gusbcfg,
526 &(otg_dev->core_if->core_global_regs->gusbcfg),
528 DWC_OTG_DEVICE_ATTR_REG32_RW(grxfsiz,
529 &(otg_dev->core_if->core_global_regs->grxfsiz),
531 DWC_OTG_DEVICE_ATTR_REG32_RW(gnptxfsiz,
532 &(otg_dev->core_if->core_global_regs->gnptxfsiz),
534 DWC_OTG_DEVICE_ATTR_REG32_RW(gpvndctl,
535 &(otg_dev->core_if->core_global_regs->gpvndctl),
537 DWC_OTG_DEVICE_ATTR_REG32_RW(ggpio,
538 &(otg_dev->core_if->core_global_regs->ggpio),
540 DWC_OTG_DEVICE_ATTR_REG32_RW(guid, &(otg_dev->core_if->core_global_regs->guid),
542 DWC_OTG_DEVICE_ATTR_REG32_RO(gsnpsid,
543 &(otg_dev->core_if->core_global_regs->gsnpsid),
545 DWC_OTG_DEVICE_ATTR_BITFIELD_RW(devspeed, "Device Speed");
546 DWC_OTG_DEVICE_ATTR_BITFIELD_RO(enumspeed, "Device Enumeration Speed");
548 DWC_OTG_DEVICE_ATTR_REG32_RO(hptxfsiz,
549 &(otg_dev->core_if->core_global_regs->hptxfsiz),
551 DWC_OTG_DEVICE_ATTR_REG32_RW(hprt0, otg_dev->core_if->host_if->hprt0, "HPRT0");
554 * @todo Add code to initiate the HNP.
557 * Show the HNP status bit
559 static ssize_t hnp_show(struct device *_dev,
560 struct device_attribute *attr, char *buf)
564 dwc_otg_device_t *otg_dev = _dev->platform_data;
565 return sprintf(buf, "HstNegScs = 0x%x\n",
566 dwc_otg_get_hnpstatus(otg_dev->core_if));
570 * Set the HNP Request bit
572 static ssize_t hnp_store(struct device *_dev,
573 struct device_attribute *attr,
574 const char *buf, size_t count)
578 dwc_otg_device_t *otg_dev = _dev->platform_data;
579 uint32_t in = simple_strtoul(buf, NULL, 16);
580 dwc_otg_set_hnpreq(otg_dev->core_if, in);
584 DEVICE_ATTR(hnp, 0644, hnp_show, hnp_store);
587 * @todo Add code to initiate the SRP.
590 * Show the SRP status bit
592 static ssize_t srp_show(struct device *_dev,
593 struct device_attribute *attr, char *buf)
595 #ifndef DWC_HOST_ONLY
598 dwc_otg_device_t *otg_dev = _dev->platform_data;
599 return sprintf(buf, "SesReqScs = 0x%x\n",
600 dwc_otg_get_srpstatus(otg_dev->core_if));
602 return sprintf(buf, "Host Only Mode!\n");
607 * Set the SRP Request bit
609 static ssize_t srp_store(struct device *_dev,
610 struct device_attribute *attr,
611 const char *buf, size_t count)
613 #ifndef DWC_HOST_ONLY
616 dwc_otg_device_t *otg_dev = _dev->platform_data;
617 dwc_otg_pcd_initiate_srp(otg_dev->pcd);
622 DEVICE_ATTR(srp, 0644, srp_show, srp_store);
625 * @todo Need to do more for power on/off?
628 * Show the Bus Power status
630 static ssize_t buspower_show(struct device *_dev,
631 struct device_attribute *attr, char *buf)
635 dwc_otg_device_t *otg_dev = _dev->platform_data;
636 return sprintf(buf, "Bus Power = 0x%x\n",
637 dwc_otg_get_prtpower(otg_dev->core_if));
641 * Set the Bus Power status
643 static ssize_t buspower_store(struct device *_dev,
644 struct device_attribute *attr,
645 const char *buf, size_t count)
649 dwc_otg_device_t *otg_dev = _dev->platform_data;
650 uint32_t on = simple_strtoul(buf, NULL, 16);
651 dwc_otg_set_prtpower(otg_dev->core_if, on);
655 DEVICE_ATTR(buspower, 0644, buspower_show, buspower_store);
658 * @todo Need to do more for suspend?
661 * Show the Bus Suspend status
663 static ssize_t bussuspend_show(struct device *_dev,
664 struct device_attribute *attr, char *buf)
668 dwc_otg_device_t *otg_dev = _dev->platform_data;
669 return sprintf(buf, "Bus Suspend = 0x%x\n",
670 dwc_otg_get_prtsuspend(otg_dev->core_if));
674 * Set the Bus Suspend status
676 static ssize_t bussuspend_store(struct device *_dev,
677 struct device_attribute *attr,
678 const char *buf, size_t count)
682 dwc_otg_device_t *otg_dev = _dev->platform_data;
683 uint32_t in = simple_strtoul(buf, NULL, 16);
684 dwc_otg_set_prtsuspend(otg_dev->core_if, in);
688 DEVICE_ATTR(bussuspend, 0644, bussuspend_show, bussuspend_store);
691 * Show the Mode Change Ready Timer status
693 static ssize_t mode_ch_tim_en_show(struct device *_dev,
694 struct device_attribute *attr, char *buf)
698 dwc_otg_device_t *otg_dev = _dev->platform_data;
699 return sprintf(buf, "Mode Change Ready Timer Enable = 0x%x\n",
700 dwc_otg_get_mode_ch_tim(otg_dev->core_if));
704 * Set the Mode Change Ready Timer status
706 static ssize_t mode_ch_tim_en_store(struct device *_dev,
707 struct device_attribute *attr,
708 const char *buf, size_t count)
712 dwc_otg_device_t *otg_dev = _dev->platform_data;
713 uint32_t in = simple_strtoul(buf, NULL, 16);
714 dwc_otg_set_mode_ch_tim(otg_dev->core_if, in);
718 DEVICE_ATTR(mode_ch_tim_en, 0644, mode_ch_tim_en_show, mode_ch_tim_en_store);
721 * Show the value of HFIR Frame Interval bitfield
723 static ssize_t fr_interval_show(struct device *_dev,
724 struct device_attribute *attr, char *buf)
728 dwc_otg_device_t *otg_dev = _dev->platform_data;
729 return sprintf(buf, "Frame Interval = 0x%x\n",
730 dwc_otg_get_fr_interval(otg_dev->core_if));
734 * Set the HFIR Frame Interval value
736 static ssize_t fr_interval_store(struct device *_dev,
737 struct device_attribute *attr,
738 const char *buf, size_t count)
742 dwc_otg_device_t *otg_dev = _dev->platform_data;
743 uint32_t in = simple_strtoul(buf, NULL, 10);
744 dwc_otg_set_fr_interval(otg_dev->core_if, in);
748 DEVICE_ATTR(fr_interval, 0644, fr_interval_show, fr_interval_store);
751 * Show the status of Remote Wakeup.
753 static ssize_t remote_wakeup_show(struct device *_dev,
754 struct device_attribute *attr, char *buf)
756 #ifndef DWC_HOST_ONLY
759 dwc_otg_device_t *otg_dev = _dev->platform_data;
761 "Remote Wakeup Sig = %d Enabled = %d LPM Remote Wakeup = %d\n",
762 dwc_otg_get_remotewakesig(otg_dev->core_if),
763 dwc_otg_pcd_get_rmwkup_enable(otg_dev->pcd),
764 dwc_otg_get_lpm_remotewakeenabled(otg_dev->core_if));
766 return sprintf(buf, "Host Only Mode!\n");
767 #endif /* DWC_HOST_ONLY */
771 * Initiate a remote wakeup of the host. The Device control register
772 * Remote Wakeup Signal bit is written if the PCD Remote wakeup enable
776 static ssize_t remote_wakeup_store(struct device *_dev,
777 struct device_attribute *attr,
778 const char *buf, size_t count)
780 #ifndef DWC_HOST_ONLY
783 dwc_otg_device_t *otg_dev = _dev->platform_data;
784 uint32_t val = simple_strtoul(buf, NULL, 16);
787 dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 1);
789 dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 0);
791 #endif /* DWC_HOST_ONLY */
795 DEVICE_ATTR(remote_wakeup, S_IRUGO | S_IWUSR, remote_wakeup_show,
796 remote_wakeup_store);
799 * Show the whether core is hibernated or not.
801 static ssize_t rem_wakeup_pwrdn_show(struct device *_dev,
802 struct device_attribute *attr, char *buf)
804 #ifndef DWC_HOST_ONLY
807 dwc_otg_device_t *otg_dev = _dev->platform_data;
808 if (dwc_otg_get_core_state(otg_dev->core_if)) {
809 DWC_PRINTF("Core is in hibernation\n");
811 DWC_PRINTF("Core is not in hibernation\n");
813 #endif /* DWC_HOST_ONLY */
817 extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
818 int rem_wakeup, int reset);
821 * Initiate a remote wakeup of the device to exit from hibernation.
823 static ssize_t rem_wakeup_pwrdn_store(struct device *_dev,
824 struct device_attribute *attr,
825 const char *buf, size_t count)
827 #ifndef DWC_HOST_ONLY
830 dwc_otg_device_t *otg_dev = _dev->platform_data;
831 dwc_otg_device_hibernation_restore(otg_dev->core_if, 1, 0);
836 DEVICE_ATTR(rem_wakeup_pwrdn, S_IRUGO | S_IWUSR, rem_wakeup_pwrdn_show,
837 rem_wakeup_pwrdn_store);
839 static ssize_t disconnect_us(struct device *_dev,
840 struct device_attribute *attr,
841 const char *buf, size_t count)
844 #ifndef DWC_HOST_ONLY
847 dwc_otg_device_t *otg_dev = _dev->platform_data;
848 uint32_t val = simple_strtoul(buf, NULL, 16);
849 DWC_PRINTF("The Passed value is %04x\n", val);
851 dwc_otg_pcd_disconnect_us(otg_dev->pcd, 50);
853 #endif /* DWC_HOST_ONLY */
857 DEVICE_ATTR(disconnect_us, S_IWUSR, 0, disconnect_us);
860 * Dump global registers and either host or device registers (depending on the
861 * current mode of the core).
863 static ssize_t regdump_show(struct device *_dev,
864 struct device_attribute *attr, char *buf)
868 dwc_otg_device_t *otg_dev = _dev->platform_data;
869 dwc_otg_dump_global_registers(otg_dev->core_if);
870 if (dwc_otg_is_host_mode(otg_dev->core_if)) {
871 dwc_otg_dump_host_registers(otg_dev->core_if);
873 dwc_otg_dump_dev_registers(otg_dev->core_if);
876 return sprintf(buf, "Register Dump\n");
879 DEVICE_ATTR(regdump, S_IRUGO, regdump_show, 0);
882 * Dump global registers and either host or device registers (depending on the
883 * current mode of the core).
885 static ssize_t spramdump_show(struct device *_dev,
886 struct device_attribute *attr, char *buf)
890 dwc_otg_device_t *otg_dev = _dev->platform_data;
891 dwc_otg_dump_spram(otg_dev->core_if);
893 return sprintf(buf, "SPRAM Dump\n");
896 DEVICE_ATTR(spramdump, S_IRUGO, spramdump_show, 0);
899 * Dump the current hcd state.
901 static ssize_t hcddump_show(struct device *_dev,
902 struct device_attribute *attr, char *buf)
904 #ifndef DWC_DEVICE_ONLY
907 dwc_otg_device_t *otg_dev = _dev->platform_data;
908 dwc_otg_hcd_dump_state(otg_dev->hcd);
909 #endif /* DWC_DEVICE_ONLY */
910 return sprintf(buf, "HCD Dump\n");
913 DEVICE_ATTR(hcddump, S_IRUGO, hcddump_show, 0);
916 * Dump the average frame remaining at SOF. This can be used to
917 * determine average interrupt latency. Frame remaining is also shown for
918 * start transfer and two additional sample points.
920 static ssize_t hcd_frrem_show(struct device *_dev,
921 struct device_attribute *attr, char *buf)
923 #ifndef DWC_DEVICE_ONLY
926 dwc_otg_device_t *otg_dev = _dev->platform_data;
927 dwc_otg_hcd_dump_frrem(otg_dev->hcd);
928 #endif /* DWC_DEVICE_ONLY */
929 return sprintf(buf, "HCD Dump Frame Remaining\n");
932 DEVICE_ATTR(hcd_frrem, S_IRUGO, hcd_frrem_show, 0);
935 * Displays the time required to read the GNPTXFSIZ register many times (the
936 * output shows the number of times the register is read).
938 #define RW_REG_COUNT 10000000
939 #define MSEC_PER_JIFFIE 1000/HZ
940 static ssize_t rd_reg_test_show(struct device *_dev,
941 struct device_attribute *attr, char *buf)
945 dwc_otg_device_t *otg_dev = _dev->platform_data;
950 printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
951 HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
952 start_jiffies = jiffies;
953 for (i = 0; i < RW_REG_COUNT; i++) {
954 dwc_otg_get_gnptxfsiz(otg_dev->core_if);
956 time = jiffies - start_jiffies;
958 "Time to read GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
959 RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
962 DEVICE_ATTR(rd_reg_test, S_IRUGO, rd_reg_test_show, 0);
965 * Displays the time required to write the GNPTXFSIZ register many times (the
966 * output shows the number of times the register is written).
968 static ssize_t wr_reg_test_show(struct device *_dev,
969 struct device_attribute *attr, char *buf)
973 dwc_otg_device_t *otg_dev = _dev->platform_data;
979 printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
980 HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
981 reg_val = dwc_otg_get_gnptxfsiz(otg_dev->core_if);
982 start_jiffies = jiffies;
983 for (i = 0; i < RW_REG_COUNT; i++) {
984 dwc_otg_set_gnptxfsiz(otg_dev->core_if, reg_val);
986 time = jiffies - start_jiffies;
988 "Time to write GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
989 RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
992 DEVICE_ATTR(wr_reg_test, S_IRUGO, wr_reg_test_show, 0);
994 #ifdef CONFIG_USB_DWC_OTG_LPM
997 * Show the lpm_response attribute.
999 static ssize_t lpmresp_show(struct device *_dev,
1000 struct device_attribute *attr, char *buf)
1004 dwc_otg_device_t *otg_dev = _dev->platform_data;
1005 if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if))
1006 return sprintf(buf, "** LPM is DISABLED **\n");
1008 if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
1009 return sprintf(buf, "** Current mode is not device mode\n");
1011 return sprintf(buf, "lpm_response = %d\n",
1012 dwc_otg_get_lpmresponse(otg_dev->core_if));
1016 * Store the lpm_response attribute.
1018 static ssize_t lpmresp_store(struct device *_dev,
1019 struct device_attribute *attr,
1020 const char *buf, size_t count)
1024 dwc_otg_device_t *otg_dev = _dev->platform_data;
1025 uint32_t val = simple_strtoul(buf, NULL, 16);
1027 if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if)) {
1031 if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
1035 dwc_otg_set_lpmresponse(otg_dev->core_if, val);
1039 DEVICE_ATTR(lpm_response, S_IRUGO | S_IWUSR, lpmresp_show, lpmresp_store);
1042 * Show the besl_reject attribute.
1044 static ssize_t beslreject_show(struct device *_dev,
1045 struct device_attribute *attr, char *buf)
1049 dwc_otg_device_t *otg_dev = _dev->platform_data;
1051 if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if))
1052 return sprintf(buf, "** LPM is DISABLED **\n");
1053 if (!dwc_otg_get_param_besl_enable(otg_dev->core_if))
1054 return sprintf(buf, "** EnBesl is DISABLED **\n");
1056 if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
1057 return sprintf(buf, "** Current mode is not device mode\n");
1060 return sprintf(buf, "besl_reject = %d\n",
1061 dwc_otg_get_beslreject(otg_dev->core_if));
1065 * Store the besl_reject attribute.
1067 static ssize_t beslreject_store(struct device *_dev,
1068 struct device_attribute *attr,
1069 const char *buf, size_t count)
1073 dwc_otg_device_t *otg_dev = _dev->platform_data;
1074 uint32_t val = simple_strtoul(buf, NULL, 16);
1076 if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if)) {
1080 if (!dwc_otg_get_param_besl_enable(otg_dev->core_if)) {
1084 if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
1088 dwc_otg_set_beslreject(otg_dev->core_if,val);
1093 DEVICE_ATTR(besl_reject, S_IRUGO | S_IWUSR, beslreject_show, beslreject_store);
1096 * Show the hird_thresh attribute.
1098 static ssize_t hirdthresh_show(struct device *_dev,
1099 struct device_attribute *attr, char *buf)
1103 dwc_otg_device_t *otg_dev = _dev->platform_data;
1105 if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if))
1106 return sprintf(buf, "** LPM is DISABLED **\n");
1108 if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
1109 return sprintf(buf, "** Current mode is not device mode\n");
1112 return sprintf(buf, "hirdthresh = 0x%x\n",
1113 dwc_otg_get_hirdthresh(otg_dev->core_if));
1117 * Store the hird_thresh attribute.
1119 static ssize_t hirdthresh_store(struct device *_dev,
1120 struct device_attribute *attr,
1121 const char *buf, size_t count)
1125 dwc_otg_device_t *otg_dev = _dev->platform_data;
1127 uint32_t val = simple_strtoul(buf, NULL, 16);
1129 if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if)) {
1133 if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
1137 dwc_otg_set_hirdthresh(otg_dev->core_if,val);
1142 DEVICE_ATTR(hird_thres, S_IRUGO | S_IWUSR, hirdthresh_show, hirdthresh_store);
1145 * Show the sleep_status attribute.
1147 static ssize_t sleepstatus_show(struct device *_dev,
1148 struct device_attribute *attr, char *buf)
1152 dwc_otg_device_t *otg_dev = _dev->platform_data;
1153 return sprintf(buf, "Sleep Status = %d\n",
1154 dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if));
1158 * Store the sleep_status attribure.
1160 static ssize_t sleepstatus_store(struct device *_dev,
1161 struct device_attribute *attr,
1162 const char *buf, size_t count)
1166 dwc_otg_device_t *otg_dev = _dev->platform_data;
1167 dwc_otg_core_if_t *core_if = otg_dev->core_if;
1169 if (dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if)) {
1170 if (dwc_otg_is_host_mode(core_if)) {
1172 DWC_PRINTF("Host initiated resume\n");
1173 dwc_otg_set_prtresume(otg_dev->core_if, 1);
1180 DEVICE_ATTR(sleep_status, S_IRUGO | S_IWUSR, sleepstatus_show,
1183 #endif /* CONFIG_USB_DWC_OTG_LPM_ENABLE */
1188 * Create the device files
1190 void dwc_otg_attr_create(
1192 struct platform_device *dev
1197 error = device_create_file(&dev->dev, &dev_attr_regoffset);
1198 error = device_create_file(&dev->dev, &dev_attr_regvalue);
1199 error = device_create_file(&dev->dev, &dev_attr_mode);
1200 error = device_create_file(&dev->dev, &dev_attr_hnpcapable);
1201 error = device_create_file(&dev->dev, &dev_attr_srpcapable);
1202 error = device_create_file(&dev->dev, &dev_attr_hsic_connect);
1203 error = device_create_file(&dev->dev, &dev_attr_inv_sel_hsic);
1204 error = device_create_file(&dev->dev, &dev_attr_hnp);
1205 error = device_create_file(&dev->dev, &dev_attr_srp);
1206 error = device_create_file(&dev->dev, &dev_attr_buspower);
1207 error = device_create_file(&dev->dev, &dev_attr_bussuspend);
1208 error = device_create_file(&dev->dev, &dev_attr_mode_ch_tim_en);
1209 error = device_create_file(&dev->dev, &dev_attr_fr_interval);
1210 error = device_create_file(&dev->dev, &dev_attr_busconnected);
1211 error = device_create_file(&dev->dev, &dev_attr_gotgctl);
1212 error = device_create_file(&dev->dev, &dev_attr_gusbcfg);
1213 error = device_create_file(&dev->dev, &dev_attr_grxfsiz);
1214 error = device_create_file(&dev->dev, &dev_attr_gnptxfsiz);
1215 error = device_create_file(&dev->dev, &dev_attr_gpvndctl);
1216 error = device_create_file(&dev->dev, &dev_attr_ggpio);
1217 error = device_create_file(&dev->dev, &dev_attr_guid);
1218 error = device_create_file(&dev->dev, &dev_attr_gsnpsid);
1219 error = device_create_file(&dev->dev, &dev_attr_devspeed);
1220 error = device_create_file(&dev->dev, &dev_attr_enumspeed);
1221 error = device_create_file(&dev->dev, &dev_attr_hptxfsiz);
1222 error = device_create_file(&dev->dev, &dev_attr_hprt0);
1223 error = device_create_file(&dev->dev, &dev_attr_remote_wakeup);
1224 error = device_create_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
1225 error = device_create_file(&dev->dev, &dev_attr_disconnect_us);
1226 error = device_create_file(&dev->dev, &dev_attr_regdump);
1227 error = device_create_file(&dev->dev, &dev_attr_spramdump);
1228 error = device_create_file(&dev->dev, &dev_attr_hcddump);
1229 error = device_create_file(&dev->dev, &dev_attr_hcd_frrem);
1230 error = device_create_file(&dev->dev, &dev_attr_rd_reg_test);
1231 error = device_create_file(&dev->dev, &dev_attr_wr_reg_test);
1232 #ifdef CONFIG_USB_DWC_OTG_LPM
1233 error = device_create_file(&dev->dev, &dev_attr_lpm_response);
1234 error = device_create_file(&dev->dev, &dev_attr_sleep_status);
1235 error = device_create_file(&dev->dev, &dev_attr_besl_reject);
1236 error = device_create_file(&dev->dev, &dev_attr_hird_thres);
1241 * Remove the device files
1243 void dwc_otg_attr_remove(
1245 struct platform_device *dev
1248 device_remove_file(&dev->dev, &dev_attr_regoffset);
1249 device_remove_file(&dev->dev, &dev_attr_regvalue);
1250 device_remove_file(&dev->dev, &dev_attr_mode);
1251 device_remove_file(&dev->dev, &dev_attr_hnpcapable);
1252 device_remove_file(&dev->dev, &dev_attr_srpcapable);
1253 device_remove_file(&dev->dev, &dev_attr_hsic_connect);
1254 device_remove_file(&dev->dev, &dev_attr_inv_sel_hsic);
1255 device_remove_file(&dev->dev, &dev_attr_hnp);
1256 device_remove_file(&dev->dev, &dev_attr_srp);
1257 device_remove_file(&dev->dev, &dev_attr_buspower);
1258 device_remove_file(&dev->dev, &dev_attr_bussuspend);
1259 device_remove_file(&dev->dev, &dev_attr_mode_ch_tim_en);
1260 device_remove_file(&dev->dev, &dev_attr_fr_interval);
1261 device_remove_file(&dev->dev, &dev_attr_busconnected);
1262 device_remove_file(&dev->dev, &dev_attr_gotgctl);
1263 device_remove_file(&dev->dev, &dev_attr_gusbcfg);
1264 device_remove_file(&dev->dev, &dev_attr_grxfsiz);
1265 device_remove_file(&dev->dev, &dev_attr_gnptxfsiz);
1266 device_remove_file(&dev->dev, &dev_attr_gpvndctl);
1267 device_remove_file(&dev->dev, &dev_attr_ggpio);
1268 device_remove_file(&dev->dev, &dev_attr_guid);
1269 device_remove_file(&dev->dev, &dev_attr_gsnpsid);
1270 device_remove_file(&dev->dev, &dev_attr_devspeed);
1271 device_remove_file(&dev->dev, &dev_attr_enumspeed);
1272 device_remove_file(&dev->dev, &dev_attr_hptxfsiz);
1273 device_remove_file(&dev->dev, &dev_attr_hprt0);
1274 device_remove_file(&dev->dev, &dev_attr_remote_wakeup);
1275 device_remove_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
1276 device_remove_file(&dev->dev, &dev_attr_disconnect_us);
1277 device_remove_file(&dev->dev, &dev_attr_regdump);
1278 device_remove_file(&dev->dev, &dev_attr_spramdump);
1279 device_remove_file(&dev->dev, &dev_attr_hcddump);
1280 device_remove_file(&dev->dev, &dev_attr_hcd_frrem);
1281 device_remove_file(&dev->dev, &dev_attr_rd_reg_test);
1282 device_remove_file(&dev->dev, &dev_attr_wr_reg_test);
1283 #ifdef CONFIG_USB_DWC_OTG_LPM
1284 device_remove_file(&dev->dev, &dev_attr_lpm_response);
1285 device_remove_file(&dev->dev, &dev_attr_sleep_status);
1286 device_remove_file(&dev->dev, &dev_attr_besl_reject);
1287 device_remove_file(&dev->dev, &dev_attr_hird_thres);