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
335 #define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_, _string_) \
336 static ssize_t _otg_attr_name_##_show(struct device *_dev, struct device_attribute *attr, char *buf) \
339 dwc_otg_device_t *otg_dev = _dev->platform_data; \
341 val = dwc_otg_get_##_otg_attr_name_(otg_dev->core_if); \
342 return sprintf(buf, "%s = 0x%x\n", _string_, val); \
344 #define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_, _string_) \
345 static ssize_t _otg_attr_name_##_store(struct device *_dev, struct device_attribute *attr, \
346 const char *buf, size_t count) \
349 dwc_otg_device_t *otg_dev = _dev->platform_data; \
350 uint32_t set = simple_strtoul(buf, NULL, 16); \
351 dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
356 * MACROs for defining sysfs attribute for 32-bit registers
359 #define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_, _string_) \
360 static ssize_t _otg_attr_name_##_show(struct device *_dev, struct device_attribute *attr, char *buf) \
363 dwc_otg_device_t *otg_dev = _dev->platform_data; \
365 val = dwc_otg_get_##_otg_attr_name_(otg_dev->core_if); \
366 return sprintf(buf, "%s = 0x%08x\n", _string_, val); \
368 #define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_, _string_) \
369 static ssize_t _otg_attr_name_##_store(struct device *_dev, struct device_attribute *attr, \
370 const char *buf, size_t count) \
373 dwc_otg_device_t *otg_dev = _dev->platform_data; \
374 uint32_t val = simple_strtoul(buf, NULL, 16); \
375 dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, val); \
379 #define DWC_OTG_DEVICE_ATTR_BITFIELD_RW(_otg_attr_name_, _string_) \
380 DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_, _string_) \
381 DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_, _string_) \
382 DEVICE_ATTR(_otg_attr_name_, 0644, _otg_attr_name_##_show, \
383 _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, \
393 _otg_attr_name_##_store);
395 #define DWC_OTG_DEVICE_ATTR_REG32_RO(_otg_attr_name_, _addr_, _string_) \
396 DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_, _string_) \
397 DEVICE_ATTR(_otg_attr_name_, 0444, _otg_attr_name_##_show, NULL);
399 void dwc_set_device_platform_data(struct platform_device *pdev, void *data)
401 if (NULL == pdev || NULL == &pdev->dev)
402 DWC_ERROR("NULL Pointer in func %s \n", __func__);
404 pdev->dev.platform_data = data;
407 void *dwc_get_device_platform_data(const struct platform_device *pdev)
409 if (NULL == pdev || NULL == &pdev->dev)
410 DWC_ERROR("NULL Pointer in func %s \n", __func__);
412 return pdev->dev.platform_data;
415 /** @name Functions for Show/Store of Attributes */
419 * Show the register offset of the Register Access.
421 static ssize_t regoffset_show(struct device *_dev,
422 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)
439 dwc_otg_device_t *otg_dev = _dev->platform_data;
440 uint32_t offset = simple_strtoul(buf, NULL, 16);
442 if (offset < SZ_256K)
443 otg_dev->os_dep.reg_offset = offset;
445 dev_err(_dev, "invalid offset\n");
450 DEVICE_ATTR(regoffset, S_IRUGO | S_IWUSR, regoffset_show, regoffset_store);
453 * Show the value of the register at the offset in the reg_offset
456 static ssize_t regvalue_show(struct device *_dev,
457 struct device_attribute *attr, char *buf)
460 dwc_otg_device_t *otg_dev = _dev->platform_data;
462 volatile uint32_t *addr;
464 if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF
465 && 0 != otg_dev->os_dep.base) {
466 /* Calculate the address */
467 addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
468 (uint8_t *) otg_dev->os_dep.base);
469 val = DWC_READ_REG32(addr);
471 sizeof("Reg@0xFFFFFFFF = 0xFFFFFFFF\n") + 1,
472 "Reg@0x%06x = 0x%08x\n",
473 otg_dev->os_dep.reg_offset, val);
475 dev_err(_dev, "Invalid offset (0x%0x)\n",
476 otg_dev->os_dep.reg_offset);
477 return sprintf(buf, "invalid offset\n");
482 * Store the value in the register at the offset in the reg_offset
486 static ssize_t regvalue_store(struct device *_dev,
487 struct device_attribute *attr,
488 const char *buf, size_t count)
491 dwc_otg_device_t *otg_dev = _dev->platform_data;
492 volatile uint32_t *addr;
493 uint32_t val = simple_strtoul(buf, NULL, 16);
494 /* dev_dbg(_dev, "Offset=0x%08x Val=0x%08x\n",
495 * otg_dev->reg_offset, val);
497 if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF
498 && 0 != otg_dev->os_dep.base) {
499 /* Calculate the address */
500 addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
501 (uint8_t *) otg_dev->os_dep.base);
502 DWC_WRITE_REG32(addr, val);
504 dev_err(_dev, "Invalid Register Offset (0x%08x)\n",
505 otg_dev->os_dep.reg_offset);
510 DEVICE_ATTR(regvalue, S_IRUGO | S_IWUSR, regvalue_show, regvalue_store);
515 DWC_OTG_DEVICE_ATTR_BITFIELD_RO(mode, "Mode");
516 DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hnpcapable, "HNPCapable");
517 DWC_OTG_DEVICE_ATTR_BITFIELD_RW(srpcapable, "SRPCapable");
518 DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hsic_connect, "HSIC Connect");
519 DWC_OTG_DEVICE_ATTR_BITFIELD_RW(inv_sel_hsic, "Invert Select HSIC");
521 /* DWC_OTG_DEVICE_ATTR_BITFIELD_RW(buspower,
522 * &(otg_dev->core_if->core_global_regs->gotgctl), (1<<8), 8, "Mode");
524 /* DWC_OTG_DEVICE_ATTR_BITFIELD_RW(bussuspend,
525 * &(otg_dev->core_if->core_global_regs->gotgctl), (1<<8), 8, "Mode");
527 DWC_OTG_DEVICE_ATTR_BITFIELD_RO(busconnected, "Bus Connected");
529 DWC_OTG_DEVICE_ATTR_REG32_RW(gotgctl, 0, "GOTGCTL");
530 DWC_OTG_DEVICE_ATTR_REG32_RW(gusbcfg,
531 &(otg_dev->core_if->core_global_regs->gusbcfg),
533 DWC_OTG_DEVICE_ATTR_REG32_RW(grxfsiz,
534 &(otg_dev->core_if->core_global_regs->grxfsiz),
536 DWC_OTG_DEVICE_ATTR_REG32_RW(gnptxfsiz,
537 &(otg_dev->core_if->core_global_regs->gnptxfsiz),
539 DWC_OTG_DEVICE_ATTR_REG32_RW(gpvndctl,
540 &(otg_dev->core_if->core_global_regs->gpvndctl),
542 DWC_OTG_DEVICE_ATTR_REG32_RW(ggpio,
543 &(otg_dev->core_if->core_global_regs->ggpio),
545 DWC_OTG_DEVICE_ATTR_REG32_RW(guid, &(otg_dev->core_if->core_global_regs->guid),
547 DWC_OTG_DEVICE_ATTR_REG32_RO(gsnpsid,
548 &(otg_dev->core_if->core_global_regs->gsnpsid),
550 DWC_OTG_DEVICE_ATTR_BITFIELD_RW(devspeed, "Device Speed");
551 DWC_OTG_DEVICE_ATTR_BITFIELD_RO(enumspeed, "Device Enumeration Speed");
553 DWC_OTG_DEVICE_ATTR_REG32_RO(hptxfsiz,
554 &(otg_dev->core_if->core_global_regs->hptxfsiz),
556 DWC_OTG_DEVICE_ATTR_REG32_RW(hprt0, otg_dev->core_if->host_if->hprt0, "HPRT0");
559 * @todo Add code to initiate the HNP.
562 * Show the HNP status bit
564 static ssize_t hnp_show(struct device *_dev,
565 struct device_attribute *attr, char *buf)
568 dwc_otg_device_t *otg_dev = _dev->platform_data;
569 return sprintf(buf, "HstNegScs = 0x%x\n",
570 dwc_otg_get_hnpstatus(otg_dev->core_if));
574 * Set the HNP Request bit
576 static ssize_t hnp_store(struct device *_dev,
577 struct device_attribute *attr,
578 const char *buf, size_t count)
581 dwc_otg_device_t *otg_dev = _dev->platform_data;
582 uint32_t in = simple_strtoul(buf, NULL, 16);
583 dwc_otg_set_hnpreq(otg_dev->core_if, in);
587 DEVICE_ATTR(hnp, 0644, hnp_show, hnp_store);
590 * @todo Add code to initiate the SRP.
593 * Show the SRP status bit
595 static ssize_t srp_show(struct device *_dev,
596 struct device_attribute *attr, char *buf)
598 #ifndef DWC_HOST_ONLY
600 dwc_otg_device_t *otg_dev = _dev->platform_data;
601 return sprintf(buf, "SesReqScs = 0x%x\n",
602 dwc_otg_get_srpstatus(otg_dev->core_if));
604 return sprintf(buf, "Host Only Mode!\n");
609 * Set the SRP Request bit
611 static ssize_t srp_store(struct device *_dev,
612 struct device_attribute *attr,
613 const char *buf, size_t count)
615 #ifndef DWC_HOST_ONLY
617 dwc_otg_device_t *otg_dev = _dev->platform_data;
618 dwc_otg_pcd_initiate_srp(otg_dev->pcd);
623 DEVICE_ATTR(srp, 0644, srp_show, srp_store);
626 * @todo Need to do more for power on/off?
629 * Show the Bus Power status
631 static ssize_t buspower_show(struct device *_dev,
632 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)
648 dwc_otg_device_t *otg_dev = _dev->platform_data;
649 uint32_t on = simple_strtoul(buf, NULL, 16);
650 dwc_otg_set_prtpower(otg_dev->core_if, on);
654 DEVICE_ATTR(buspower, 0644, buspower_show, buspower_store);
657 * @todo Need to do more for suspend?
660 * Show the Bus Suspend status
662 static ssize_t bussuspend_show(struct device *_dev,
663 struct device_attribute *attr, char *buf)
666 dwc_otg_device_t *otg_dev = _dev->platform_data;
667 return sprintf(buf, "Bus Suspend = 0x%x\n",
668 dwc_otg_get_prtsuspend(otg_dev->core_if));
672 * Set the Bus Suspend status
674 static ssize_t bussuspend_store(struct device *_dev,
675 struct device_attribute *attr,
676 const char *buf, size_t count)
679 dwc_otg_device_t *otg_dev = _dev->platform_data;
680 uint32_t in = simple_strtoul(buf, NULL, 16);
681 dwc_otg_set_prtsuspend(otg_dev->core_if, in);
685 DEVICE_ATTR(bussuspend, 0644, bussuspend_show, bussuspend_store);
688 * Show the Mode Change Ready Timer status
690 static ssize_t mode_ch_tim_en_show(struct device *_dev,
691 struct device_attribute *attr, char *buf)
694 dwc_otg_device_t *otg_dev = _dev->platform_data;
695 return sprintf(buf, "Mode Change Ready Timer Enable = 0x%x\n",
696 dwc_otg_get_mode_ch_tim(otg_dev->core_if));
700 * Set the Mode Change Ready Timer status
702 static ssize_t mode_ch_tim_en_store(struct device *_dev,
703 struct device_attribute *attr,
704 const char *buf, size_t count)
707 dwc_otg_device_t *otg_dev = _dev->platform_data;
708 uint32_t in = simple_strtoul(buf, NULL, 16);
709 dwc_otg_set_mode_ch_tim(otg_dev->core_if, in);
713 DEVICE_ATTR(mode_ch_tim_en, 0644, mode_ch_tim_en_show, mode_ch_tim_en_store);
716 * Show the value of HFIR Frame Interval bitfield
718 static ssize_t fr_interval_show(struct device *_dev,
719 struct device_attribute *attr, char *buf)
722 dwc_otg_device_t *otg_dev = _dev->platform_data;
723 return sprintf(buf, "Frame Interval = 0x%x\n",
724 dwc_otg_get_fr_interval(otg_dev->core_if));
728 * Set the HFIR Frame Interval value
730 static ssize_t fr_interval_store(struct device *_dev,
731 struct device_attribute *attr,
732 const char *buf, size_t count)
735 dwc_otg_device_t *otg_dev = _dev->platform_data;
736 uint32_t in = simple_strtoul(buf, NULL, 10);
737 dwc_otg_set_fr_interval(otg_dev->core_if, in);
741 DEVICE_ATTR(fr_interval, 0644, fr_interval_show, fr_interval_store);
744 * Show the status of Remote Wakeup.
746 static ssize_t remote_wakeup_show(struct device *_dev,
747 struct device_attribute *attr, char *buf)
749 #ifndef DWC_HOST_ONLY
751 dwc_otg_device_t *otg_dev = _dev->platform_data;
753 "Remote Wakeup Sig = %d Enabled = %d LPM Remote Wakeup = %d\n",
754 dwc_otg_get_remotewakesig(otg_dev->core_if),
755 dwc_otg_pcd_get_rmwkup_enable(otg_dev->pcd),
756 dwc_otg_get_lpm_remotewakeenabled(otg_dev->core_if));
758 return sprintf(buf, "Host Only Mode!\n");
759 #endif /* DWC_HOST_ONLY */
763 * Initiate a remote wakeup of the host. The Device control register
764 * Remote Wakeup Signal bit is written if the PCD Remote wakeup enable
768 static ssize_t remote_wakeup_store(struct device *_dev,
769 struct device_attribute *attr,
770 const char *buf, size_t count)
772 #ifndef DWC_HOST_ONLY
774 dwc_otg_device_t *otg_dev = _dev->platform_data;
775 uint32_t val = simple_strtoul(buf, NULL, 16);
778 dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 1);
780 dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 0);
782 #endif /* DWC_HOST_ONLY */
786 DEVICE_ATTR(remote_wakeup, S_IRUGO | S_IWUSR, remote_wakeup_show,
787 remote_wakeup_store);
790 * Show the whether core is hibernated or not.
792 static ssize_t rem_wakeup_pwrdn_show(struct device *_dev,
793 struct device_attribute *attr, char *buf)
795 #ifndef DWC_HOST_ONLY
797 dwc_otg_device_t *otg_dev = _dev->platform_data;
798 if (dwc_otg_get_core_state(otg_dev->core_if))
799 DWC_PRINTF("Core is in hibernation\n");
801 DWC_PRINTF("Core is not in hibernation\n");
803 #endif /* DWC_HOST_ONLY */
807 extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t *core_if,
808 int rem_wakeup, int reset);
811 * Initiate a remote wakeup of the device to exit from hibernation.
813 static ssize_t rem_wakeup_pwrdn_store(struct device *_dev,
814 struct device_attribute *attr,
815 const char *buf, size_t count)
817 #ifndef DWC_HOST_ONLY
819 dwc_otg_device_t *otg_dev = _dev->platform_data;
820 dwc_otg_device_hibernation_restore(otg_dev->core_if, 1, 0);
825 DEVICE_ATTR(rem_wakeup_pwrdn, S_IRUGO | S_IWUSR, rem_wakeup_pwrdn_show,
826 rem_wakeup_pwrdn_store);
828 static ssize_t disconnect_us(struct device *_dev,
829 struct device_attribute *attr,
830 const char *buf, size_t count)
833 #ifndef DWC_HOST_ONLY
835 dwc_otg_device_t *otg_dev = _dev->platform_data;
836 uint32_t val = simple_strtoul(buf, NULL, 16);
837 DWC_PRINTF("The Passed value is %04x\n", val);
839 dwc_otg_pcd_disconnect_us(otg_dev->pcd, 50);
841 #endif /* DWC_HOST_ONLY */
845 DEVICE_ATTR(disconnect_us, S_IWUSR, 0, disconnect_us);
848 * Dump global registers and either host or device registers (depending on the
849 * current mode of the core).
851 static ssize_t regdump_show(struct device *_dev,
852 struct device_attribute *attr, char *buf)
855 dwc_otg_device_t *otg_dev = _dev->platform_data;
856 dwc_otg_dump_global_registers(otg_dev->core_if);
857 if (dwc_otg_is_host_mode(otg_dev->core_if))
858 dwc_otg_dump_host_registers(otg_dev->core_if);
860 dwc_otg_dump_dev_registers(otg_dev->core_if);
862 return sprintf(buf, "Register Dump\n");
865 DEVICE_ATTR(regdump, S_IRUGO, regdump_show, 0);
868 * Dump global registers and either host or device registers (depending on the
869 * current mode of the core).
871 static ssize_t spramdump_show(struct device *_dev,
872 struct device_attribute *attr, char *buf)
875 dwc_otg_device_t *otg_dev = _dev->platform_data;
876 dwc_otg_dump_spram(otg_dev->core_if);
878 return sprintf(buf, "SPRAM Dump\n");
881 DEVICE_ATTR(spramdump, S_IRUGO, spramdump_show, 0);
884 * Dump the current hcd state.
886 static ssize_t hcddump_show(struct device *_dev,
887 struct device_attribute *attr, char *buf)
889 #ifndef DWC_DEVICE_ONLY
891 dwc_otg_device_t *otg_dev = _dev->platform_data;
892 dwc_otg_hcd_dump_state(otg_dev->hcd);
893 #endif /* DWC_DEVICE_ONLY */
894 return sprintf(buf, "HCD Dump\n");
897 DEVICE_ATTR(hcddump, S_IRUGO, hcddump_show, 0);
900 * Dump the average frame remaining at SOF. This can be used to
901 * determine average interrupt latency. Frame remaining is also shown for
902 * start transfer and two additional sample points.
904 static ssize_t hcd_frrem_show(struct device *_dev,
905 struct device_attribute *attr, char *buf)
907 #ifndef DWC_DEVICE_ONLY
909 dwc_otg_device_t *otg_dev = _dev->platform_data;
910 dwc_otg_hcd_dump_frrem(otg_dev->hcd);
911 #endif /* DWC_DEVICE_ONLY */
912 return sprintf(buf, "HCD Dump Frame Remaining\n");
915 DEVICE_ATTR(hcd_frrem, S_IRUGO, hcd_frrem_show, 0);
918 * Displays the time required to read the GNPTXFSIZ register many times (the
919 * output shows the number of times the register is read).
921 #define RW_REG_COUNT 10000000
922 #define MSEC_PER_JIFFIE (1000/HZ)
923 static ssize_t rd_reg_test_show(struct device *_dev,
924 struct device_attribute *attr, char *buf)
927 dwc_otg_device_t *otg_dev = _dev->platform_data;
932 printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
933 HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
934 start_jiffies = jiffies;
935 for (i = 0; i < RW_REG_COUNT; i++)
936 dwc_otg_get_gnptxfsiz(otg_dev->core_if);
937 time = jiffies - start_jiffies;
939 "Time to read GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
940 RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
943 DEVICE_ATTR(rd_reg_test, S_IRUGO, rd_reg_test_show, 0);
946 * Displays the time required to write the GNPTXFSIZ register many times (the
947 * output shows the number of times the register is written).
949 static ssize_t wr_reg_test_show(struct device *_dev,
950 struct device_attribute *attr, char *buf)
953 dwc_otg_device_t *otg_dev = _dev->platform_data;
959 printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
960 HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
961 reg_val = dwc_otg_get_gnptxfsiz(otg_dev->core_if);
962 start_jiffies = jiffies;
963 for (i = 0; i < RW_REG_COUNT; i++)
964 dwc_otg_set_gnptxfsiz(otg_dev->core_if, reg_val);
965 time = jiffies - start_jiffies;
967 "Time to write GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
968 RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
971 DEVICE_ATTR(wr_reg_test, S_IRUGO, wr_reg_test_show, 0);
973 #ifdef CONFIG_USB_DWC_OTG_LPM
976 * Show the lpm_response attribute.
978 static ssize_t lpmresp_show(struct device *_dev,
979 struct device_attribute *attr, char *buf)
982 dwc_otg_device_t *otg_dev = _dev->platform_data;
983 if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if))
984 return sprintf(buf, "** LPM is DISABLED **\n");
986 if (!dwc_otg_is_device_mode(otg_dev->core_if))
987 return sprintf(buf, "** Current mode is not device mode\n");
989 return sprintf(buf, "lpm_response = %d\n",
990 dwc_otg_get_lpmresponse(otg_dev->core_if));
994 * Store the lpm_response attribute.
996 static ssize_t lpmresp_store(struct device *_dev,
997 struct device_attribute *attr,
998 const char *buf, size_t count)
1001 dwc_otg_device_t *otg_dev = _dev->platform_data;
1002 uint32_t val = simple_strtoul(buf, NULL, 16);
1004 if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if))
1007 if (!dwc_otg_is_device_mode(otg_dev->core_if))
1010 dwc_otg_set_lpmresponse(otg_dev->core_if, val);
1014 DEVICE_ATTR(lpm_response, S_IRUGO | S_IWUSR, lpmresp_show, lpmresp_store);
1017 * Show the besl_reject attribute.
1019 static ssize_t beslreject_show(struct device *_dev,
1020 struct device_attribute *attr, char *buf)
1023 dwc_otg_device_t *otg_dev = _dev->platform_data;
1025 if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if))
1026 return sprintf(buf, "** LPM is DISABLED **\n");
1027 if (!dwc_otg_get_param_besl_enable(otg_dev->core_if))
1028 return sprintf(buf, "** EnBesl is DISABLED **\n");
1030 if (!dwc_otg_is_device_mode(otg_dev->core_if))
1031 return sprintf(buf, "** Current mode is not device mode\n");
1033 return sprintf(buf, "besl_reject = %d\n",
1034 dwc_otg_get_beslreject(otg_dev->core_if));
1038 * Store the besl_reject attribute.
1040 static ssize_t beslreject_store(struct device *_dev,
1041 struct device_attribute *attr,
1042 const char *buf, size_t count)
1045 dwc_otg_device_t *otg_dev = _dev->platform_data;
1046 uint32_t val = simple_strtoul(buf, NULL, 16);
1048 if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if))
1051 if (!dwc_otg_get_param_besl_enable(otg_dev->core_if))
1054 if (!dwc_otg_is_device_mode(otg_dev->core_if))
1057 dwc_otg_set_beslreject(otg_dev->core_if, val);
1062 DEVICE_ATTR(besl_reject, S_IRUGO | S_IWUSR, beslreject_show, beslreject_store);
1065 * Show the hird_thresh attribute.
1067 static ssize_t hirdthresh_show(struct device *_dev,
1068 struct device_attribute *attr, char *buf)
1071 dwc_otg_device_t *otg_dev = _dev->platform_data;
1073 if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if))
1074 return sprintf(buf, "** LPM is DISABLED **\n");
1076 if (!dwc_otg_is_device_mode(otg_dev->core_if))
1077 return sprintf(buf, "** Current mode is not device mode\n");
1079 return sprintf(buf, "hirdthresh = 0x%x\n",
1080 dwc_otg_get_hirdthresh(otg_dev->core_if));
1084 * Store the hird_thresh attribute.
1086 static ssize_t hirdthresh_store(struct device *_dev,
1087 struct device_attribute *attr,
1088 const char *buf, size_t count)
1091 dwc_otg_device_t *otg_dev = _dev->platform_data;
1093 uint32_t val = simple_strtoul(buf, NULL, 16);
1095 if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if))
1098 if (!dwc_otg_is_device_mode(otg_dev->core_if))
1101 dwc_otg_set_hirdthresh(otg_dev->core_if, val);
1106 DEVICE_ATTR(hird_thres, S_IRUGO | S_IWUSR, hirdthresh_show, hirdthresh_store);
1109 * Show the sleep_status attribute.
1111 static ssize_t sleepstatus_show(struct device *_dev,
1112 struct device_attribute *attr, char *buf)
1115 dwc_otg_device_t *otg_dev = _dev->platform_data;
1116 return sprintf(buf, "Sleep Status = %d\n",
1117 dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if));
1121 * Store the sleep_status attribure.
1123 static ssize_t sleepstatus_store(struct device *_dev,
1124 struct device_attribute *attr,
1125 const char *buf, size_t count)
1128 dwc_otg_device_t *otg_dev = _dev->platform_data;
1129 dwc_otg_core_if_t *core_if = otg_dev->core_if;
1131 if (dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if)) {
1132 if (dwc_otg_is_host_mode(core_if)) {
1134 DWC_PRINTF("Host initiated resume\n");
1135 dwc_otg_set_prtresume(otg_dev->core_if, 1);
1142 DEVICE_ATTR(sleep_status, S_IRUGO | S_IWUSR, sleepstatus_show,
1145 #endif /* CONFIG_USB_DWC_OTG_LPM_ENABLE */
1150 * Create the device files
1152 void dwc_otg_attr_create(struct platform_device *dev)
1156 error = device_create_file(&dev->dev, &dev_attr_regoffset);
1157 error = device_create_file(&dev->dev, &dev_attr_regvalue);
1158 error = device_create_file(&dev->dev, &dev_attr_mode);
1159 error = device_create_file(&dev->dev, &dev_attr_hnpcapable);
1160 error = device_create_file(&dev->dev, &dev_attr_srpcapable);
1161 error = device_create_file(&dev->dev, &dev_attr_hsic_connect);
1162 error = device_create_file(&dev->dev, &dev_attr_inv_sel_hsic);
1163 error = device_create_file(&dev->dev, &dev_attr_hnp);
1164 error = device_create_file(&dev->dev, &dev_attr_srp);
1165 error = device_create_file(&dev->dev, &dev_attr_buspower);
1166 error = device_create_file(&dev->dev, &dev_attr_bussuspend);
1167 error = device_create_file(&dev->dev, &dev_attr_mode_ch_tim_en);
1168 error = device_create_file(&dev->dev, &dev_attr_fr_interval);
1169 error = device_create_file(&dev->dev, &dev_attr_busconnected);
1170 error = device_create_file(&dev->dev, &dev_attr_gotgctl);
1171 error = device_create_file(&dev->dev, &dev_attr_gusbcfg);
1172 error = device_create_file(&dev->dev, &dev_attr_grxfsiz);
1173 error = device_create_file(&dev->dev, &dev_attr_gnptxfsiz);
1174 error = device_create_file(&dev->dev, &dev_attr_gpvndctl);
1175 error = device_create_file(&dev->dev, &dev_attr_ggpio);
1176 error = device_create_file(&dev->dev, &dev_attr_guid);
1177 error = device_create_file(&dev->dev, &dev_attr_gsnpsid);
1178 error = device_create_file(&dev->dev, &dev_attr_devspeed);
1179 error = device_create_file(&dev->dev, &dev_attr_enumspeed);
1180 error = device_create_file(&dev->dev, &dev_attr_hptxfsiz);
1181 error = device_create_file(&dev->dev, &dev_attr_hprt0);
1182 error = device_create_file(&dev->dev, &dev_attr_remote_wakeup);
1183 error = device_create_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
1184 error = device_create_file(&dev->dev, &dev_attr_disconnect_us);
1185 error = device_create_file(&dev->dev, &dev_attr_regdump);
1186 error = device_create_file(&dev->dev, &dev_attr_spramdump);
1187 error = device_create_file(&dev->dev, &dev_attr_hcddump);
1188 error = device_create_file(&dev->dev, &dev_attr_hcd_frrem);
1189 error = device_create_file(&dev->dev, &dev_attr_rd_reg_test);
1190 error = device_create_file(&dev->dev, &dev_attr_wr_reg_test);
1191 #ifdef CONFIG_USB_DWC_OTG_LPM
1192 error = device_create_file(&dev->dev, &dev_attr_lpm_response);
1193 error = device_create_file(&dev->dev, &dev_attr_sleep_status);
1194 error = device_create_file(&dev->dev, &dev_attr_besl_reject);
1195 error = device_create_file(&dev->dev, &dev_attr_hird_thres);
1200 * Remove the device files
1202 void dwc_otg_attr_remove(struct platform_device *dev)
1204 device_remove_file(&dev->dev, &dev_attr_regoffset);
1205 device_remove_file(&dev->dev, &dev_attr_regvalue);
1206 device_remove_file(&dev->dev, &dev_attr_mode);
1207 device_remove_file(&dev->dev, &dev_attr_hnpcapable);
1208 device_remove_file(&dev->dev, &dev_attr_srpcapable);
1209 device_remove_file(&dev->dev, &dev_attr_hsic_connect);
1210 device_remove_file(&dev->dev, &dev_attr_inv_sel_hsic);
1211 device_remove_file(&dev->dev, &dev_attr_hnp);
1212 device_remove_file(&dev->dev, &dev_attr_srp);
1213 device_remove_file(&dev->dev, &dev_attr_buspower);
1214 device_remove_file(&dev->dev, &dev_attr_bussuspend);
1215 device_remove_file(&dev->dev, &dev_attr_mode_ch_tim_en);
1216 device_remove_file(&dev->dev, &dev_attr_fr_interval);
1217 device_remove_file(&dev->dev, &dev_attr_busconnected);
1218 device_remove_file(&dev->dev, &dev_attr_gotgctl);
1219 device_remove_file(&dev->dev, &dev_attr_gusbcfg);
1220 device_remove_file(&dev->dev, &dev_attr_grxfsiz);
1221 device_remove_file(&dev->dev, &dev_attr_gnptxfsiz);
1222 device_remove_file(&dev->dev, &dev_attr_gpvndctl);
1223 device_remove_file(&dev->dev, &dev_attr_ggpio);
1224 device_remove_file(&dev->dev, &dev_attr_guid);
1225 device_remove_file(&dev->dev, &dev_attr_gsnpsid);
1226 device_remove_file(&dev->dev, &dev_attr_devspeed);
1227 device_remove_file(&dev->dev, &dev_attr_enumspeed);
1228 device_remove_file(&dev->dev, &dev_attr_hptxfsiz);
1229 device_remove_file(&dev->dev, &dev_attr_hprt0);
1230 device_remove_file(&dev->dev, &dev_attr_remote_wakeup);
1231 device_remove_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
1232 device_remove_file(&dev->dev, &dev_attr_disconnect_us);
1233 device_remove_file(&dev->dev, &dev_attr_regdump);
1234 device_remove_file(&dev->dev, &dev_attr_spramdump);
1235 device_remove_file(&dev->dev, &dev_attr_hcddump);
1236 device_remove_file(&dev->dev, &dev_attr_hcd_frrem);
1237 device_remove_file(&dev->dev, &dev_attr_rd_reg_test);
1238 device_remove_file(&dev->dev, &dev_attr_wr_reg_test);
1239 #ifdef CONFIG_USB_DWC_OTG_LPM
1240 device_remove_file(&dev->dev, &dev_attr_lpm_response);
1241 device_remove_file(&dev->dev, &dev_attr_sleep_status);
1242 device_remove_file(&dev->dev, &dev_attr_besl_reject);
1243 device_remove_file(&dev->dev, &dev_attr_hird_thres);