dwc_otg_attr.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450
  1. /* ==========================================================================
  2. * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.c $
  3. * $Revision: #44 $
  4. * $Date: 2010/11/29 $
  5. * $Change: 1636033 $
  6. *
  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.
  10. *
  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.
  20. *
  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
  31. * DAMAGE.
  32. * ========================================================================== */
  33. /** @file
  34. *
  35. * The diagnostic interface will provide access to the controller for
  36. * bringing up the hardware and testing. The Linux driver attributes
  37. * feature will be used to provide the Linux Diagnostic
  38. * Interface. These attributes are accessed through sysfs.
  39. */
  40. /** @page "Linux Module Attributes"
  41. *
  42. * The Linux module attributes feature is used to provide the Linux
  43. * Diagnostic Interface. These attributes are accessed through sysfs.
  44. * The diagnostic interface will provide access to the controller for
  45. * bringing up the hardware and testing.
  46. The following table shows the attributes.
  47. <table>
  48. <tr>
  49. <td><b> Name</b></td>
  50. <td><b> Description</b></td>
  51. <td><b> Access</b></td>
  52. </tr>
  53. <tr>
  54. <td> mode </td>
  55. <td> Returns the current mode: 0 for device mode, 1 for host mode</td>
  56. <td> Read</td>
  57. </tr>
  58. <tr>
  59. <td> hnpcapable </td>
  60. <td> Gets or sets the "HNP-capable" bit in the Core USB Configuraton Register.
  61. Read returns the current value.</td>
  62. <td> Read/Write</td>
  63. </tr>
  64. <tr>
  65. <td> srpcapable </td>
  66. <td> Gets or sets the "SRP-capable" bit in the Core USB Configuraton Register.
  67. Read returns the current value.</td>
  68. <td> Read/Write</td>
  69. </tr>
  70. <tr>
  71. <td> hsic_connect </td>
  72. <td> Gets or sets the "HSIC-Connect" bit in the GLPMCFG Register.
  73. Read returns the current value.</td>
  74. <td> Read/Write</td>
  75. </tr>
  76. <tr>
  77. <td> inv_sel_hsic </td>
  78. <td> Gets or sets the "Invert Select HSIC" bit in the GLPMFG Register.
  79. Read returns the current value.</td>
  80. <td> Read/Write</td>
  81. </tr>
  82. <tr>
  83. <td> hnp </td>
  84. <td> Initiates the Host Negotiation Protocol. Read returns the status.</td>
  85. <td> Read/Write</td>
  86. </tr>
  87. <tr>
  88. <td> srp </td>
  89. <td> Initiates the Session Request Protocol. Read returns the status.</td>
  90. <td> Read/Write</td>
  91. </tr>
  92. <tr>
  93. <td> buspower </td>
  94. <td> Gets or sets the Power State of the bus (0 - Off or 1 - On)</td>
  95. <td> Read/Write</td>
  96. </tr>
  97. <tr>
  98. <td> bussuspend </td>
  99. <td> Suspends the USB bus.</td>
  100. <td> Read/Write</td>
  101. </tr>
  102. <tr>
  103. <td> busconnected </td>
  104. <td> Gets the connection status of the bus</td>
  105. <td> Read</td>
  106. </tr>
  107. <tr>
  108. <td> gotgctl </td>
  109. <td> Gets or sets the Core Control Status Register.</td>
  110. <td> Read/Write</td>
  111. </tr>
  112. <tr>
  113. <td> gusbcfg </td>
  114. <td> Gets or sets the Core USB Configuration Register</td>
  115. <td> Read/Write</td>
  116. </tr>
  117. <tr>
  118. <td> grxfsiz </td>
  119. <td> Gets or sets the Receive FIFO Size Register</td>
  120. <td> Read/Write</td>
  121. </tr>
  122. <tr>
  123. <td> gnptxfsiz </td>
  124. <td> Gets or sets the non-periodic Transmit Size Register</td>
  125. <td> Read/Write</td>
  126. </tr>
  127. <tr>
  128. <td> gpvndctl </td>
  129. <td> Gets or sets the PHY Vendor Control Register</td>
  130. <td> Read/Write</td>
  131. </tr>
  132. <tr>
  133. <td> ggpio </td>
  134. <td> Gets the value in the lower 16-bits of the General Purpose IO Register
  135. or sets the upper 16 bits.</td>
  136. <td> Read/Write</td>
  137. </tr>
  138. <tr>
  139. <td> guid </td>
  140. <td> Gets or sets the value of the User ID Register</td>
  141. <td> Read/Write</td>
  142. </tr>
  143. <tr>
  144. <td> gsnpsid </td>
  145. <td> Gets the value of the Synopsys ID Regester</td>
  146. <td> Read</td>
  147. </tr>
  148. <tr>
  149. <td> devspeed </td>
  150. <td> Gets or sets the device speed setting in the DCFG register</td>
  151. <td> Read/Write</td>
  152. </tr>
  153. <tr>
  154. <td> enumspeed </td>
  155. <td> Gets the device enumeration Speed.</td>
  156. <td> Read</td>
  157. </tr>
  158. <tr>
  159. <td> hptxfsiz </td>
  160. <td> Gets the value of the Host Periodic Transmit FIFO</td>
  161. <td> Read</td>
  162. </tr>
  163. <tr>
  164. <td> hprt0 </td>
  165. <td> Gets or sets the value in the Host Port Control and Status Register</td>
  166. <td> Read/Write</td>
  167. </tr>
  168. <tr>
  169. <td> regoffset </td>
  170. <td> Sets the register offset for the next Register Access</td>
  171. <td> Read/Write</td>
  172. </tr>
  173. <tr>
  174. <td> regvalue </td>
  175. <td> Gets or sets the value of the register at the offset in the regoffset attribute.</td>
  176. <td> Read/Write</td>
  177. </tr>
  178. <tr>
  179. <td> remote_wakeup </td>
  180. <td> On read, shows the status of Remote Wakeup. On write, initiates a remote
  181. wakeup of the host. When bit 0 is 1 and Remote Wakeup is enabled, the Remote
  182. Wakeup signalling bit in the Device Control Register is set for 1
  183. milli-second.</td>
  184. <td> Read/Write</td>
  185. </tr>
  186. <tr>
  187. <td> rem_wakeup_pwrdn </td>
  188. <td> On read, shows the status core - hibernated or not. On write, initiates
  189. a remote wakeup of the device from Hibernation. </td>
  190. <td> Read/Write</td>
  191. </tr>
  192. <tr>
  193. <td> mode_ch_tim_en </td>
  194. <td> This bit is used to enable or disable the host core to wait for 200 PHY
  195. clock cycles at the end of Resume to change the opmode signal to the PHY to 00
  196. after Suspend or LPM. </td>
  197. <td> Read/Write</td>
  198. </tr>
  199. <tr>
  200. <td> fr_interval </td>
  201. <td> On read, shows the value of HFIR Frame Interval. On write, dynamically
  202. reload HFIR register during runtime. The application can write a value to this
  203. register only after the Port Enable bit of the Host Port Control and Status
  204. register (HPRT.PrtEnaPort) has been set </td>
  205. <td> Read/Write</td>
  206. </tr>
  207. <tr>
  208. <td> disconnect_us </td>
  209. <td> On read, shows the status of disconnect_device_us. On write, sets disconnect_us
  210. which causes soft disconnect for 100us. Applicable only for device mode of operation.</td>
  211. <td> Read/Write</td>
  212. </tr>
  213. <tr>
  214. <td> regdump </td>
  215. <td> Dumps the contents of core registers.</td>
  216. <td> Read</td>
  217. </tr>
  218. <tr>
  219. <td> spramdump </td>
  220. <td> Dumps the contents of core registers.</td>
  221. <td> Read</td>
  222. </tr>
  223. <tr>
  224. <td> hcddump </td>
  225. <td> Dumps the current HCD state.</td>
  226. <td> Read</td>
  227. </tr>
  228. <tr>
  229. <td> hcd_frrem </td>
  230. <td> Shows the average value of the Frame Remaining
  231. field in the Host Frame Number/Frame Remaining register when an SOF interrupt
  232. occurs. This can be used to determine the average interrupt latency. Also
  233. shows the average Frame Remaining value for start_transfer and the "a" and
  234. "b" sample points. The "a" and "b" sample points may be used during debugging
  235. bto determine how long it takes to execute a section of the HCD code.</td>
  236. <td> Read</td>
  237. </tr>
  238. <tr>
  239. <td> rd_reg_test </td>
  240. <td> Displays the time required to read the GNPTXFSIZ register many times
  241. (the output shows the number of times the register is read).
  242. <td> Read</td>
  243. </tr>
  244. <tr>
  245. <td> wr_reg_test </td>
  246. <td> Displays the time required to write the GNPTXFSIZ register many times
  247. (the output shows the number of times the register is written).
  248. <td> Read</td>
  249. </tr>
  250. <tr>
  251. <td> lpm_response </td>
  252. <td> Gets or sets lpm_response mode. Applicable only in device mode.
  253. <td> Write</td>
  254. </tr>
  255. <tr>
  256. <td> sleep_status </td>
  257. <td> Shows sleep status of device.
  258. <td> Read</td>
  259. </tr>
  260. </table>
  261. Example usage:
  262. To get the current mode:
  263. cat /sys/devices/lm0/mode
  264. To power down the USB:
  265. echo 0 > /sys/devices/lm0/buspower
  266. */
  267. #include "dwc_otg_os_dep.h"
  268. #include "dwc_os.h"
  269. #include "dwc_otg_driver.h"
  270. #include "dwc_otg_attr.h"
  271. #include "dwc_otg_core_if.h"
  272. #include "dwc_otg_pcd_if.h"
  273. #include "dwc_otg_hcd_if.h"
  274. #include "dwc_otg_cil.h"
  275. /*
  276. * MACROs for defining sysfs attribute
  277. */
  278. #ifdef LM_INTERFACE
  279. #define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  280. static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  281. { \
  282. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  283. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  284. uint32_t val; \
  285. val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  286. return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  287. }
  288. #define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  289. static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  290. const char *buf, size_t count) \
  291. { \
  292. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  293. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  294. uint32_t set = simple_strtoul(buf, NULL, 16); \
  295. dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  296. return count; \
  297. }
  298. #elif defined(PCI_INTERFACE)
  299. #define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  300. static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  301. { \
  302. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  303. uint32_t val; \
  304. val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  305. return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  306. }
  307. #define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  308. static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  309. const char *buf, size_t count) \
  310. { \
  311. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  312. uint32_t set = simple_strtoul(buf, NULL, 16); \
  313. dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  314. return count; \
  315. }
  316. #endif
  317. /*
  318. * MACROs for defining sysfs attribute for 32-bit registers
  319. */
  320. #ifdef LM_INTERFACE
  321. #define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  322. static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  323. { \
  324. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  325. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  326. uint32_t val; \
  327. val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  328. return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  329. }
  330. #define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  331. static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  332. const char *buf, size_t count) \
  333. { \
  334. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  335. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  336. uint32_t val = simple_strtoul(buf, NULL, 16); \
  337. dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  338. return count; \
  339. }
  340. #elif defined(PCI_INTERFACE)
  341. #define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  342. static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  343. { \
  344. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  345. uint32_t val; \
  346. val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  347. return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  348. }
  349. #define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  350. static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  351. const char *buf, size_t count) \
  352. { \
  353. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  354. uint32_t val = simple_strtoul(buf, NULL, 16); \
  355. dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  356. return count; \
  357. }
  358. #endif
  359. #define DWC_OTG_DEVICE_ATTR_BITFIELD_RW(_otg_attr_name_,_string_) \
  360. DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  361. DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  362. DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
  363. #define DWC_OTG_DEVICE_ATTR_BITFIELD_RO(_otg_attr_name_,_string_) \
  364. DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  365. DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
  366. #define DWC_OTG_DEVICE_ATTR_REG32_RW(_otg_attr_name_,_addr_,_string_) \
  367. DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  368. DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  369. DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
  370. #define DWC_OTG_DEVICE_ATTR_REG32_RO(_otg_attr_name_,_addr_,_string_) \
  371. DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  372. DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
  373. /** @name Functions for Show/Store of Attributes */
  374. /**@{*/
  375. /**
  376. * Show the register offset of the Register Access.
  377. */
  378. static ssize_t regoffset_show(struct device *_dev,
  379. struct device_attribute *attr, char *buf)
  380. {
  381. #ifdef LM_INTERFACE
  382. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  383. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  384. #elif defined(PCI_INTERFACE)
  385. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  386. #endif
  387. return snprintf(buf, sizeof("0xFFFFFFFF\n") + 1, "0x%08x\n",
  388. otg_dev->os_dep.reg_offset);
  389. }
  390. /**
  391. * Set the register offset for the next Register Access Read/Write
  392. */
  393. static ssize_t regoffset_store(struct device *_dev,
  394. struct device_attribute *attr,
  395. const char *buf, size_t count)
  396. {
  397. #ifdef LM_INTERFACE
  398. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  399. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  400. #elif defined(PCI_INTERFACE)
  401. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  402. #endif
  403. uint32_t offset = simple_strtoul(buf, NULL, 16);
  404. #ifdef LM_INTERFACE
  405. if (offset < SZ_256K) {
  406. #elif defined(PCI_INTERFACE)
  407. if (offset < 0x00040000) {
  408. #endif
  409. otg_dev->os_dep.reg_offset = offset;
  410. } else {
  411. dev_err(_dev, "invalid offset\n");
  412. }
  413. return count;
  414. }
  415. DEVICE_ATTR(regoffset, S_IRUGO | S_IWUSR, regoffset_show, regoffset_store);
  416. /**
  417. * Show the value of the register at the offset in the reg_offset
  418. * attribute.
  419. */
  420. static ssize_t regvalue_show(struct device *_dev,
  421. struct device_attribute *attr, char *buf)
  422. {
  423. #ifdef LM_INTERFACE
  424. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  425. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  426. #elif defined(PCI_INTERFACE)
  427. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  428. #endif
  429. uint32_t val;
  430. volatile uint32_t *addr;
  431. if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF && 0 != otg_dev->os_dep.base) {
  432. /* Calculate the address */
  433. addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
  434. (uint8_t *) otg_dev->os_dep.base);
  435. val = DWC_READ_REG32(addr);
  436. return snprintf(buf,
  437. sizeof("Reg@0xFFFFFFFF = 0xFFFFFFFF\n") + 1,
  438. "Reg@0x%06x = 0x%08x\n", otg_dev->os_dep.reg_offset,
  439. val);
  440. } else {
  441. dev_err(_dev, "Invalid offset (0x%0x)\n", otg_dev->os_dep.reg_offset);
  442. return sprintf(buf, "invalid offset\n");
  443. }
  444. }
  445. /**
  446. * Store the value in the register at the offset in the reg_offset
  447. * attribute.
  448. *
  449. */
  450. static ssize_t regvalue_store(struct device *_dev,
  451. struct device_attribute *attr,
  452. const char *buf, size_t count)
  453. {
  454. #ifdef LM_INTERFACE
  455. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  456. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  457. #elif defined(PCI_INTERFACE)
  458. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  459. #endif
  460. volatile uint32_t *addr;
  461. uint32_t val = simple_strtoul(buf, NULL, 16);
  462. //dev_dbg(_dev, "Offset=0x%08x Val=0x%08x\n", otg_dev->reg_offset, val);
  463. if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF && 0 != otg_dev->os_dep.base) {
  464. /* Calculate the address */
  465. addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
  466. (uint8_t *) otg_dev->os_dep.base);
  467. DWC_WRITE_REG32(addr, val);
  468. } else {
  469. dev_err(_dev, "Invalid Register Offset (0x%08x)\n",
  470. otg_dev->os_dep.reg_offset);
  471. }
  472. return count;
  473. }
  474. DEVICE_ATTR(regvalue, S_IRUGO | S_IWUSR, regvalue_show, regvalue_store);
  475. /*
  476. * Attributes
  477. */
  478. DWC_OTG_DEVICE_ATTR_BITFIELD_RO(mode, "Mode");
  479. DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hnpcapable, "HNPCapable");
  480. DWC_OTG_DEVICE_ATTR_BITFIELD_RW(srpcapable, "SRPCapable");
  481. DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hsic_connect, "HSIC Connect");
  482. DWC_OTG_DEVICE_ATTR_BITFIELD_RW(inv_sel_hsic, "Invert Select HSIC");
  483. //DWC_OTG_DEVICE_ATTR_BITFIELD_RW(buspower,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
  484. //DWC_OTG_DEVICE_ATTR_BITFIELD_RW(bussuspend,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
  485. DWC_OTG_DEVICE_ATTR_BITFIELD_RO(busconnected, "Bus Connected");
  486. DWC_OTG_DEVICE_ATTR_REG32_RW(gotgctl, 0, "GOTGCTL");
  487. DWC_OTG_DEVICE_ATTR_REG32_RW(gusbcfg,
  488. &(otg_dev->core_if->core_global_regs->gusbcfg),
  489. "GUSBCFG");
  490. DWC_OTG_DEVICE_ATTR_REG32_RW(grxfsiz,
  491. &(otg_dev->core_if->core_global_regs->grxfsiz),
  492. "GRXFSIZ");
  493. DWC_OTG_DEVICE_ATTR_REG32_RW(gnptxfsiz,
  494. &(otg_dev->core_if->core_global_regs->gnptxfsiz),
  495. "GNPTXFSIZ");
  496. DWC_OTG_DEVICE_ATTR_REG32_RW(gpvndctl,
  497. &(otg_dev->core_if->core_global_regs->gpvndctl),
  498. "GPVNDCTL");
  499. DWC_OTG_DEVICE_ATTR_REG32_RW(ggpio,
  500. &(otg_dev->core_if->core_global_regs->ggpio),
  501. "GGPIO");
  502. DWC_OTG_DEVICE_ATTR_REG32_RW(guid, &(otg_dev->core_if->core_global_regs->guid),
  503. "GUID");
  504. DWC_OTG_DEVICE_ATTR_REG32_RO(gsnpsid,
  505. &(otg_dev->core_if->core_global_regs->gsnpsid),
  506. "GSNPSID");
  507. DWC_OTG_DEVICE_ATTR_BITFIELD_RW(devspeed, "Device Speed");
  508. DWC_OTG_DEVICE_ATTR_BITFIELD_RO(enumspeed, "Device Enumeration Speed");
  509. DWC_OTG_DEVICE_ATTR_REG32_RO(hptxfsiz,
  510. &(otg_dev->core_if->core_global_regs->hptxfsiz),
  511. "HPTXFSIZ");
  512. DWC_OTG_DEVICE_ATTR_REG32_RW(hprt0,
  513. otg_dev->core_if->host_if->hprt0, "HPRT0");
  514. /* peri regs */
  515. static ssize_t peri_iddq_show(struct device *_dev,
  516. struct device_attribute *attr, char *buf)
  517. {
  518. usb_dbg_uart_data_t uart;
  519. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  520. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  521. uart.d32 = DWC_READ_REG32(&otg_dev->core_if->usb_peri_reg->dbg_uart);
  522. return sprintf(buf, "IDDQ = 0x%x\n",uart.b.set_iddq);
  523. }
  524. /**
  525. * Set the HNP Request bit
  526. */
  527. static ssize_t peri_iddq_store(struct device *_dev,
  528. struct device_attribute *attr,
  529. const char *buf, size_t count)
  530. {
  531. usb_dbg_uart_data_t uart;
  532. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  533. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  534. uint32_t in = simple_strtoul(buf, NULL, 16);
  535. uart.d32 = DWC_READ_REG32(&otg_dev->core_if->usb_peri_reg->dbg_uart);
  536. uart.b.set_iddq = in;
  537. DWC_WRITE_REG32(&otg_dev->core_if->usb_peri_reg->dbg_uart,uart.d32);
  538. return count;
  539. }
  540. DEVICE_ATTR(peri_iddq, 0644, peri_iddq_show, peri_iddq_store);
  541. static ssize_t peri_otg_disable_show(struct device *_dev,
  542. struct device_attribute *attr, char *buf)
  543. {
  544. usb_adp_bc_data_t adp_bc;
  545. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  546. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  547. adp_bc.d32 = DWC_READ_REG32(&otg_dev->core_if->usb_peri_reg->dbg_uart);
  548. return sprintf(buf, "IDDQ = 0x%x\n",adp_bc.b.otgdisable);
  549. }
  550. /**
  551. * Set the HNP Request bit
  552. */
  553. static ssize_t peri_otg_disable_store(struct device *_dev,
  554. struct device_attribute *attr,
  555. const char *buf, size_t count)
  556. {
  557. usb_adp_bc_data_t adp_bc;
  558. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  559. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  560. uint32_t in = simple_strtoul(buf, NULL, 16);
  561. adp_bc.d32 = DWC_READ_REG32(&otg_dev->core_if->usb_peri_reg->adp_bc);
  562. adp_bc.b.otgdisable = in;
  563. DWC_WRITE_REG32(&otg_dev->core_if->usb_peri_reg->adp_bc,adp_bc.d32);
  564. return count;
  565. }
  566. DEVICE_ATTR(peri_otg_disable, 0644, peri_otg_disable_show, peri_otg_disable_store);
  567. /* PHY Power control get */
  568. static ssize_t peri_power_show(struct device *_dev,
  569. struct device_attribute *attr, char *buf)
  570. {
  571. usb_ctrl_data_t ctrl;
  572. int power;
  573. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  574. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  575. ctrl.d32 = DWC_READ_REG32(&otg_dev->core_if->usb_peri_reg->ctrl);
  576. power = ctrl.b.por?0:1;
  577. return sprintf(buf, "PHY Power = %d\n",power);
  578. }
  579. /* PHY Power control set */
  580. static ssize_t peri_power_store(struct device *_dev,
  581. struct device_attribute *attr,
  582. const char *buf, size_t count)
  583. {
  584. int power;
  585. usb_ctrl_data_t ctrl;
  586. usb_adp_bc_data_t adp_bc;
  587. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  588. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  589. power = simple_strtoul(buf, NULL, 16);
  590. if(power != 0 && power != 1){
  591. dev_err(_dev,"power (%d) mode error\n",power);
  592. return count;
  593. }
  594. if(power == 0) {
  595. adp_bc.d32 = DWC_READ_REG32(&otg_dev->core_if->usb_peri_reg->adp_bc);
  596. adp_bc.b.vbusvldextsel = 1;
  597. adp_bc.b.vbusvldext = 0;
  598. DWC_WRITE_REG32(&otg_dev->core_if->usb_peri_reg->adp_bc,adp_bc.d32);
  599. }
  600. ctrl.d32 = DWC_READ_REG32(&otg_dev->core_if->usb_peri_reg->ctrl);
  601. ctrl.b.por = power?0:1;
  602. DWC_WRITE_REG32(&otg_dev->core_if->usb_peri_reg->ctrl,ctrl.d32);
  603. if(power == 1) {
  604. adp_bc.d32 = DWC_READ_REG32(&otg_dev->core_if->usb_peri_reg->adp_bc);
  605. adp_bc.b.vbusvldextsel = 0;
  606. adp_bc.b.vbusvldext = 0;
  607. DWC_WRITE_REG32(&otg_dev->core_if->usb_peri_reg->adp_bc,adp_bc.d32);
  608. }
  609. return count;
  610. }
  611. DEVICE_ATTR(peri_power, 0644, peri_power_show, peri_power_store);
  612. /**
  613. * @todo Add code to initiate the HNP.
  614. */
  615. /**
  616. * Show the HNP status bit
  617. */
  618. static ssize_t hnp_show(struct device *_dev,
  619. struct device_attribute *attr, char *buf)
  620. {
  621. #ifdef LM_INTERFACE
  622. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  623. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  624. #elif defined(PCI_INTERFACE)
  625. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  626. #endif
  627. return sprintf(buf, "HstNegScs = 0x%x\n",
  628. dwc_otg_get_hnpstatus(otg_dev->core_if));
  629. }
  630. /**
  631. * Set the HNP Request bit
  632. */
  633. static ssize_t hnp_store(struct device *_dev,
  634. struct device_attribute *attr,
  635. const char *buf, size_t count)
  636. {
  637. #ifdef LM_INTERFACE
  638. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  639. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  640. #elif defined(PCI_INTERFACE)
  641. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  642. #endif
  643. uint32_t in = simple_strtoul(buf, NULL, 16);
  644. dwc_otg_set_hnpreq(otg_dev->core_if, in);
  645. return count;
  646. }
  647. DEVICE_ATTR(hnp, 0644, hnp_show, hnp_store);
  648. /**
  649. * @todo Add code to initiate the SRP.
  650. */
  651. /**
  652. * Show the SRP status bit
  653. */
  654. static ssize_t srp_show(struct device *_dev,
  655. struct device_attribute *attr, char *buf)
  656. {
  657. #ifndef DWC_HOST_ONLY
  658. #ifdef LM_INTERFACE
  659. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  660. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  661. #elif defined(PCI_INTERFACE)
  662. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  663. #endif
  664. return sprintf(buf, "SesReqScs = 0x%x\n",
  665. dwc_otg_get_srpstatus(otg_dev->core_if));
  666. #else
  667. return sprintf(buf, "Host Only Mode!\n");
  668. #endif
  669. }
  670. /**
  671. * Set the SRP Request bit
  672. */
  673. static ssize_t srp_store(struct device *_dev,
  674. struct device_attribute *attr,
  675. const char *buf, size_t count)
  676. {
  677. #ifndef DWC_HOST_ONLY
  678. #ifdef LM_INTERFACE
  679. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  680. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  681. #elif defined(PCI_INTERFACE)
  682. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  683. #endif
  684. dwc_otg_pcd_initiate_srp(otg_dev->pcd);
  685. #endif
  686. return count;
  687. }
  688. DEVICE_ATTR(srp, 0644, srp_show, srp_store);
  689. /**
  690. * @todo Need to do more for power on/off?
  691. */
  692. /**
  693. * Show the Bus Power status
  694. */
  695. static ssize_t buspower_show(struct device *_dev,
  696. struct device_attribute *attr, char *buf)
  697. {
  698. #ifdef LM_INTERFACE
  699. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  700. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  701. #elif defined(PCI_INTERFACE)
  702. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  703. #endif
  704. return sprintf(buf, "Bus Power = 0x%x\n",
  705. dwc_otg_get_prtpower(otg_dev->core_if));
  706. }
  707. /**
  708. * Set the Bus Power status
  709. */
  710. static ssize_t buspower_store(struct device *_dev,
  711. struct device_attribute *attr,
  712. const char *buf, size_t count)
  713. {
  714. #ifdef LM_INTERFACE
  715. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  716. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  717. #elif defined(PCI_INTERFACE)
  718. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  719. #endif
  720. uint32_t on = simple_strtoul(buf, NULL, 16);
  721. dwc_otg_set_prtpower(otg_dev->core_if, on);
  722. return count;
  723. }
  724. DEVICE_ATTR(buspower, 0644, buspower_show, buspower_store);
  725. /**
  726. * @todo Need to do more for suspend?
  727. */
  728. /**
  729. * Show the Bus Suspend status
  730. */
  731. static ssize_t bussuspend_show(struct device *_dev,
  732. struct device_attribute *attr, char *buf)
  733. {
  734. #ifdef LM_INTERFACE
  735. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  736. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  737. #elif defined(PCI_INTERFACE)
  738. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  739. #endif
  740. return sprintf(buf, "Bus Suspend = 0x%x\n",
  741. dwc_otg_get_prtsuspend(otg_dev->core_if));
  742. }
  743. /**
  744. * Set the Bus Suspend status
  745. */
  746. static ssize_t bussuspend_store(struct device *_dev,
  747. struct device_attribute *attr,
  748. const char *buf, size_t count)
  749. {
  750. #ifdef LM_INTERFACE
  751. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  752. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  753. #elif defined(PCI_INTERFACE)
  754. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  755. #endif
  756. uint32_t in = simple_strtoul(buf, NULL, 16);
  757. dwc_otg_set_prtsuspend(otg_dev->core_if, in);
  758. return count;
  759. }
  760. DEVICE_ATTR(bussuspend, 0644, bussuspend_show, bussuspend_store);
  761. /**
  762. * Show the Mode Change Ready Timer status
  763. */
  764. static ssize_t mode_ch_tim_en_show(struct device *_dev,
  765. struct device_attribute *attr, char *buf)
  766. {
  767. #ifdef LM_INTERFACE
  768. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  769. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  770. #elif defined(PCI_INTERFACE)
  771. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  772. #endif
  773. return sprintf(buf, "Mode Change Ready Timer Enable = 0x%x\n",
  774. dwc_otg_get_mode_ch_tim(otg_dev->core_if));
  775. }
  776. /**
  777. * Set the Mode Change Ready Timer status
  778. */
  779. static ssize_t mode_ch_tim_en_store(struct device *_dev,
  780. struct device_attribute *attr,
  781. const char *buf, size_t count)
  782. {
  783. #ifdef LM_INTERFACE
  784. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  785. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  786. #elif defined(PCI_INTERFACE)
  787. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  788. #endif
  789. uint32_t in = simple_strtoul(buf, NULL, 16);
  790. dwc_otg_set_mode_ch_tim(otg_dev->core_if, in);
  791. return count;
  792. }
  793. DEVICE_ATTR(mode_ch_tim_en, 0644, mode_ch_tim_en_show, mode_ch_tim_en_store);
  794. /**
  795. * Show the value of HFIR Frame Interval bitfield
  796. */
  797. static ssize_t fr_interval_show(struct device *_dev,
  798. struct device_attribute *attr, char *buf)
  799. {
  800. #ifdef LM_INTERFACE
  801. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  802. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  803. #elif defined(PCI_INTERFACE)
  804. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  805. #endif
  806. return sprintf(buf, "Frame Interval = 0x%x\n",
  807. dwc_otg_get_fr_interval(otg_dev->core_if));
  808. }
  809. /**
  810. * Set the HFIR Frame Interval value
  811. */
  812. static ssize_t fr_interval_store(struct device *_dev,
  813. struct device_attribute *attr,
  814. const char *buf, size_t count)
  815. {
  816. #ifdef LM_INTERFACE
  817. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  818. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  819. #elif defined(PCI_INTERFACE)
  820. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  821. #endif
  822. uint32_t in = simple_strtoul(buf, NULL, 10);
  823. dwc_otg_set_fr_interval(otg_dev->core_if, in);
  824. return count;
  825. }
  826. DEVICE_ATTR(fr_interval, 0644, fr_interval_show, fr_interval_store);
  827. /**
  828. * Show the status of Remote Wakeup.
  829. */
  830. static ssize_t remote_wakeup_show(struct device *_dev,
  831. struct device_attribute *attr, char *buf)
  832. {
  833. #ifndef DWC_HOST_ONLY
  834. #ifdef LM_INTERFACE
  835. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  836. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  837. #elif defined(PCI_INTERFACE)
  838. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  839. #endif
  840. return sprintf(buf,
  841. "Remote Wakeup Sig = %d Enabled = %d LPM Remote Wakeup = %d\n",
  842. dwc_otg_get_remotewakesig(otg_dev->core_if),
  843. dwc_otg_pcd_get_rmwkup_enable(otg_dev->pcd),
  844. dwc_otg_get_lpm_remotewakeenabled(otg_dev->core_if));
  845. #else
  846. return sprintf(buf, "Host Only Mode!\n");
  847. #endif /* DWC_HOST_ONLY */
  848. }
  849. /**
  850. * Initiate a remote wakeup of the host. The Device control register
  851. * Remote Wakeup Signal bit is written if the PCD Remote wakeup enable
  852. * flag is set.
  853. *
  854. */
  855. static ssize_t remote_wakeup_store(struct device *_dev,
  856. struct device_attribute *attr,
  857. const char *buf, size_t count)
  858. {
  859. #ifndef DWC_HOST_ONLY
  860. #ifdef LM_INTERFACE
  861. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  862. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  863. #elif defined(PCI_INTERFACE)
  864. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  865. #endif
  866. uint32_t val = simple_strtoul(buf, NULL, 16);
  867. if (val & 1) {
  868. dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 1);
  869. } else {
  870. dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 0);
  871. }
  872. #endif /* DWC_HOST_ONLY */
  873. return count;
  874. }
  875. DEVICE_ATTR(remote_wakeup, S_IRUGO | S_IWUSR, remote_wakeup_show,
  876. remote_wakeup_store);
  877. /**
  878. * Show the whether core is hibernated or not.
  879. */
  880. static ssize_t rem_wakeup_pwrdn_show(struct device *_dev,
  881. struct device_attribute *attr, char *buf)
  882. {
  883. #ifndef DWC_HOST_ONLY
  884. #ifdef LM_INTERFACE
  885. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  886. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  887. #elif defined(PCI_INTERFACE)
  888. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  889. #endif
  890. if (dwc_otg_get_core_state(otg_dev->core_if)) {
  891. DWC_PRINTF("Core is in hibernation\n");
  892. } else {
  893. DWC_PRINTF("Core is not in hibernation\n");
  894. }
  895. #endif /* DWC_HOST_ONLY */
  896. return 0;
  897. }
  898. extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  899. int rem_wakeup, int reset);
  900. /**
  901. * Initiate a remote wakeup of the device to exit from hibernation.
  902. */
  903. static ssize_t rem_wakeup_pwrdn_store(struct device *_dev,
  904. struct device_attribute *attr,
  905. const char *buf, size_t count)
  906. {
  907. #ifndef DWC_HOST_ONLY
  908. #ifdef LM_INTERFACE
  909. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  910. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  911. #elif defined(PCI_INTERFACE)
  912. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  913. #endif
  914. dwc_otg_device_hibernation_restore(otg_dev->core_if, 1, 0);
  915. #endif
  916. return count;
  917. }
  918. DEVICE_ATTR(rem_wakeup_pwrdn, S_IRUGO | S_IWUSR, rem_wakeup_pwrdn_show,
  919. rem_wakeup_pwrdn_store);
  920. static ssize_t disconnect_us(struct device *_dev,
  921. struct device_attribute *attr,
  922. const char *buf, size_t count)
  923. {
  924. #ifndef DWC_HOST_ONLY
  925. #ifdef LM_INTERFACE
  926. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  927. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  928. #elif defined(PCI_INTERFACE)
  929. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  930. #endif
  931. uint32_t val = simple_strtoul(buf, NULL, 16);
  932. DWC_PRINTF("The Passed value is %04x\n", val);
  933. dwc_otg_pcd_disconnect_us(otg_dev->pcd, 50);
  934. #endif /* DWC_HOST_ONLY */
  935. return count;
  936. }
  937. DEVICE_ATTR(disconnect_us, S_IWUSR, 0, disconnect_us);
  938. /**
  939. * Dump global registers and either host or device registers (depending on the
  940. * current mode of the core).
  941. */
  942. static ssize_t regdump_show(struct device *_dev,
  943. struct device_attribute *attr, char *buf)
  944. {
  945. #ifdef LM_INTERFACE
  946. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  947. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  948. #elif defined(PCI_INTERFACE)
  949. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  950. #endif
  951. dwc_otg_dump_global_registers(otg_dev->core_if);
  952. if (dwc_otg_is_host_mode(otg_dev->core_if)) {
  953. dwc_otg_dump_host_registers(otg_dev->core_if);
  954. } else {
  955. dwc_otg_dump_dev_registers(otg_dev->core_if);
  956. }
  957. return sprintf(buf, "Register Dump\n");
  958. }
  959. DEVICE_ATTR(regdump, S_IRUGO | S_IWUSR, regdump_show, 0);
  960. /**
  961. * Dump global registers and either host or device registers (depending on the
  962. * current mode of the core).
  963. */
  964. static ssize_t spramdump_show(struct device *_dev,
  965. struct device_attribute *attr, char *buf)
  966. {
  967. #ifdef LM_INTERFACE
  968. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  969. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  970. #elif defined(PCI_INTERFACE)
  971. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  972. #endif
  973. dwc_otg_dump_spram(otg_dev->core_if);
  974. return sprintf(buf, "SPRAM Dump\n");
  975. }
  976. DEVICE_ATTR(spramdump, S_IRUGO | S_IWUSR, spramdump_show, 0);
  977. /**
  978. * Dump the current hcd state.
  979. */
  980. static ssize_t hcddump_show(struct device *_dev,
  981. struct device_attribute *attr, char *buf)
  982. {
  983. #ifndef DWC_DEVICE_ONLY
  984. #ifdef LM_INTERFACE
  985. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  986. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  987. #elif defined(PCI_INTERFACE)
  988. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  989. #endif
  990. dwc_otg_hcd_dump_state(otg_dev->hcd);
  991. #endif /* DWC_DEVICE_ONLY */
  992. return sprintf(buf, "HCD Dump\n");
  993. }
  994. DEVICE_ATTR(hcddump, S_IRUGO | S_IWUSR, hcddump_show, 0);
  995. /**
  996. * Dump the average frame remaining at SOF. This can be used to
  997. * determine average interrupt latency. Frame remaining is also shown for
  998. * start transfer and two additional sample points.
  999. */
  1000. static ssize_t hcd_frrem_show(struct device *_dev,
  1001. struct device_attribute *attr, char *buf)
  1002. {
  1003. #ifndef DWC_DEVICE_ONLY
  1004. #ifdef LM_INTERFACE
  1005. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  1006. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  1007. #elif defined(PCI_INTERFACE)
  1008. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  1009. #endif
  1010. dwc_otg_hcd_dump_frrem(otg_dev->hcd);
  1011. #endif /* DWC_DEVICE_ONLY */
  1012. return sprintf(buf, "HCD Dump Frame Remaining\n");
  1013. }
  1014. DEVICE_ATTR(hcd_frrem, S_IRUGO | S_IWUSR, hcd_frrem_show, 0);
  1015. /**
  1016. * Displays the time required to read the GNPTXFSIZ register many times (the
  1017. * output shows the number of times the register is read).
  1018. */
  1019. #define RW_REG_COUNT 10000000
  1020. #define MSEC_PER_JIFFIE 1000/HZ
  1021. static ssize_t rd_reg_test_show(struct device *_dev,
  1022. struct device_attribute *attr, char *buf)
  1023. {
  1024. #ifdef LM_INTERFACE
  1025. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  1026. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  1027. #elif defined(PCI_INTERFACE)
  1028. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  1029. #endif
  1030. int i;
  1031. int time;
  1032. int start_jiffies;
  1033. printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
  1034. HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
  1035. start_jiffies = jiffies;
  1036. for (i = 0; i < RW_REG_COUNT; i++) {
  1037. dwc_otg_get_gnptxfsiz(otg_dev->core_if);
  1038. }
  1039. time = jiffies - start_jiffies;
  1040. return sprintf(buf,
  1041. "Time to read GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
  1042. RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
  1043. }
  1044. DEVICE_ATTR(rd_reg_test, S_IRUGO | S_IWUSR, rd_reg_test_show, 0);
  1045. /**
  1046. * Displays the time required to write the GNPTXFSIZ register many times (the
  1047. * output shows the number of times the register is written).
  1048. */
  1049. static ssize_t wr_reg_test_show(struct device *_dev,
  1050. struct device_attribute *attr, char *buf)
  1051. {
  1052. #ifdef LM_INTERFACE
  1053. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  1054. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  1055. #elif defined(PCI_INTERFACE)
  1056. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  1057. #endif
  1058. uint32_t reg_val;
  1059. int i;
  1060. int time;
  1061. int start_jiffies;
  1062. printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
  1063. HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
  1064. reg_val = dwc_otg_get_gnptxfsiz(otg_dev->core_if);
  1065. start_jiffies = jiffies;
  1066. for (i = 0; i < RW_REG_COUNT; i++) {
  1067. dwc_otg_set_gnptxfsiz(otg_dev->core_if, reg_val);
  1068. }
  1069. time = jiffies - start_jiffies;
  1070. return sprintf(buf,
  1071. "Time to write GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
  1072. RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
  1073. }
  1074. DEVICE_ATTR(wr_reg_test, S_IRUGO | S_IWUSR, wr_reg_test_show, 0);
  1075. #ifdef CONFIG_USB_DWC_OTG_LPM
  1076. /**
  1077. * Show the lpm_response attribute.
  1078. */
  1079. static ssize_t lpmresp_show(struct device *_dev,
  1080. struct device_attribute *attr, char *buf)
  1081. {
  1082. #ifdef LM_INTERFACE
  1083. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  1084. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  1085. #elif defined(PCI_INTERFACE)
  1086. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  1087. #endif
  1088. if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if))
  1089. return sprintf(buf, "** LPM is DISABLED **\n");
  1090. if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
  1091. return sprintf(buf, "** Current mode is not device mode\n");
  1092. }
  1093. return sprintf(buf, "lpm_response = %d\n",
  1094. dwc_otg_get_lpmresponse(otg_dev->core_if));
  1095. }
  1096. /**
  1097. * Store the lpm_response attribute.
  1098. */
  1099. static ssize_t lpmresp_store(struct device *_dev,
  1100. struct device_attribute *attr,
  1101. const char *buf, size_t count)
  1102. {
  1103. #ifdef LM_INTERFACE
  1104. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  1105. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  1106. #elif defined(PCI_INTERFACE)
  1107. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  1108. #endif
  1109. uint32_t val = simple_strtoul(buf, NULL, 16);
  1110. if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if)) {
  1111. return 0;
  1112. }
  1113. if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
  1114. return 0;
  1115. }
  1116. dwc_otg_set_lpmresponse(otg_dev->core_if, val);
  1117. return count;
  1118. }
  1119. DEVICE_ATTR(lpm_response, S_IRUGO | S_IWUSR, lpmresp_show, lpmresp_store);
  1120. /**
  1121. * Show the sleep_status attribute.
  1122. */
  1123. static ssize_t sleepstatus_show(struct device *_dev,
  1124. struct device_attribute *attr, char *buf)
  1125. {
  1126. #ifdef LM_INTERFACE
  1127. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  1128. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  1129. #elif defined(PCI_INTERFACE)
  1130. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  1131. #endif
  1132. return sprintf(buf, "Sleep Status = %d\n",
  1133. dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if));
  1134. }
  1135. /**
  1136. * Store the sleep_status attribure.
  1137. */
  1138. static ssize_t sleepstatus_store(struct device *_dev,
  1139. struct device_attribute *attr,
  1140. const char *buf, size_t count)
  1141. {
  1142. #ifdef LM_INTERFACE
  1143. struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev);
  1144. dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev);
  1145. #elif defined(PCI_INTERFACE)
  1146. dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev);
  1147. #endif
  1148. dwc_otg_core_if_t *core_if = otg_dev->core_if;
  1149. if (dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if)) {
  1150. if (dwc_otg_is_host_mode(core_if)) {
  1151. DWC_PRINTF("Host initiated resume\n");
  1152. dwc_otg_set_prtresume(otg_dev->core_if, 1);
  1153. }
  1154. }
  1155. return count;
  1156. }
  1157. DEVICE_ATTR(sleep_status, S_IRUGO | S_IWUSR, sleepstatus_show,
  1158. sleepstatus_store);
  1159. #endif /* CONFIG_USB_DWC_OTG_LPM_ENABLE */
  1160. /**@}*/
  1161. /**
  1162. * Create the device files
  1163. */
  1164. void dwc_otg_attr_create(
  1165. #ifdef LM_INTERFACE
  1166. struct lm_device *dev
  1167. #elif defined(PCI_INTERFACE)
  1168. struct pci_dev *dev
  1169. #endif
  1170. )
  1171. {
  1172. int error;
  1173. error = device_create_file(&dev->dev, &dev_attr_regoffset);
  1174. error = device_create_file(&dev->dev, &dev_attr_regvalue);
  1175. error = device_create_file(&dev->dev, &dev_attr_mode);
  1176. error = device_create_file(&dev->dev, &dev_attr_hnpcapable);
  1177. error = device_create_file(&dev->dev, &dev_attr_srpcapable);
  1178. error = device_create_file(&dev->dev, &dev_attr_hsic_connect);
  1179. error = device_create_file(&dev->dev, &dev_attr_inv_sel_hsic);
  1180. error = device_create_file(&dev->dev, &dev_attr_hnp);
  1181. error = device_create_file(&dev->dev, &dev_attr_srp);
  1182. error = device_create_file(&dev->dev, &dev_attr_buspower);
  1183. error = device_create_file(&dev->dev, &dev_attr_bussuspend);
  1184. error = device_create_file(&dev->dev, &dev_attr_mode_ch_tim_en);
  1185. error = device_create_file(&dev->dev, &dev_attr_fr_interval);
  1186. error = device_create_file(&dev->dev, &dev_attr_busconnected);
  1187. error = device_create_file(&dev->dev, &dev_attr_gotgctl);
  1188. error = device_create_file(&dev->dev, &dev_attr_gusbcfg);
  1189. error = device_create_file(&dev->dev, &dev_attr_grxfsiz);
  1190. error = device_create_file(&dev->dev, &dev_attr_gnptxfsiz);
  1191. error = device_create_file(&dev->dev, &dev_attr_gpvndctl);
  1192. error = device_create_file(&dev->dev, &dev_attr_ggpio);
  1193. error = device_create_file(&dev->dev, &dev_attr_guid);
  1194. error = device_create_file(&dev->dev, &dev_attr_gsnpsid);
  1195. error = device_create_file(&dev->dev, &dev_attr_devspeed);
  1196. error = device_create_file(&dev->dev, &dev_attr_enumspeed);
  1197. error = device_create_file(&dev->dev, &dev_attr_hptxfsiz);
  1198. error = device_create_file(&dev->dev, &dev_attr_hprt0);
  1199. error = device_create_file(&dev->dev, &dev_attr_remote_wakeup);
  1200. error = device_create_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
  1201. error = device_create_file(&dev->dev, &dev_attr_disconnect_us);
  1202. error = device_create_file(&dev->dev, &dev_attr_regdump);
  1203. error = device_create_file(&dev->dev, &dev_attr_spramdump);
  1204. error = device_create_file(&dev->dev, &dev_attr_hcddump);
  1205. error = device_create_file(&dev->dev, &dev_attr_hcd_frrem);
  1206. error = device_create_file(&dev->dev, &dev_attr_rd_reg_test);
  1207. error = device_create_file(&dev->dev, &dev_attr_wr_reg_test);
  1208. #ifdef CONFIG_USB_DWC_OTG_LPM
  1209. error = device_create_file(&dev->dev, &dev_attr_lpm_response);
  1210. error = device_create_file(&dev->dev, &dev_attr_sleep_status);
  1211. #endif
  1212. error = device_create_file(&dev->dev, &dev_attr_peri_iddq);
  1213. error = device_create_file(&dev->dev, &dev_attr_peri_otg_disable);
  1214. error = device_create_file(&dev->dev, &dev_attr_peri_power);
  1215. }
  1216. /**
  1217. * Remove the device files
  1218. */
  1219. void dwc_otg_attr_remove(
  1220. #ifdef LM_INTERFACE
  1221. struct lm_device *dev
  1222. #elif defined(PCI_INTERFACE)
  1223. struct pci_dev *dev
  1224. #endif
  1225. )
  1226. {
  1227. device_remove_file(&dev->dev, &dev_attr_regoffset);
  1228. device_remove_file(&dev->dev, &dev_attr_regvalue);
  1229. device_remove_file(&dev->dev, &dev_attr_mode);
  1230. device_remove_file(&dev->dev, &dev_attr_hnpcapable);
  1231. device_remove_file(&dev->dev, &dev_attr_srpcapable);
  1232. device_remove_file(&dev->dev, &dev_attr_hsic_connect);
  1233. device_remove_file(&dev->dev, &dev_attr_inv_sel_hsic);
  1234. device_remove_file(&dev->dev, &dev_attr_hnp);
  1235. device_remove_file(&dev->dev, &dev_attr_srp);
  1236. device_remove_file(&dev->dev, &dev_attr_buspower);
  1237. device_remove_file(&dev->dev, &dev_attr_bussuspend);
  1238. device_remove_file(&dev->dev, &dev_attr_mode_ch_tim_en);
  1239. device_remove_file(&dev->dev, &dev_attr_fr_interval);
  1240. device_remove_file(&dev->dev, &dev_attr_busconnected);
  1241. device_remove_file(&dev->dev, &dev_attr_gotgctl);
  1242. device_remove_file(&dev->dev, &dev_attr_gusbcfg);
  1243. device_remove_file(&dev->dev, &dev_attr_grxfsiz);
  1244. device_remove_file(&dev->dev, &dev_attr_gnptxfsiz);
  1245. device_remove_file(&dev->dev, &dev_attr_gpvndctl);
  1246. device_remove_file(&dev->dev, &dev_attr_ggpio);
  1247. device_remove_file(&dev->dev, &dev_attr_guid);
  1248. device_remove_file(&dev->dev, &dev_attr_gsnpsid);
  1249. device_remove_file(&dev->dev, &dev_attr_devspeed);
  1250. device_remove_file(&dev->dev, &dev_attr_enumspeed);
  1251. device_remove_file(&dev->dev, &dev_attr_hptxfsiz);
  1252. device_remove_file(&dev->dev, &dev_attr_hprt0);
  1253. device_remove_file(&dev->dev, &dev_attr_remote_wakeup);
  1254. device_remove_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
  1255. device_remove_file(&dev->dev, &dev_attr_disconnect_us);
  1256. device_remove_file(&dev->dev, &dev_attr_regdump);
  1257. device_remove_file(&dev->dev, &dev_attr_spramdump);
  1258. device_remove_file(&dev->dev, &dev_attr_hcddump);
  1259. device_remove_file(&dev->dev, &dev_attr_hcd_frrem);
  1260. device_remove_file(&dev->dev, &dev_attr_rd_reg_test);
  1261. device_remove_file(&dev->dev, &dev_attr_wr_reg_test);
  1262. #ifdef CONFIG_USB_DWC_OTG_LPM
  1263. device_remove_file(&dev->dev, &dev_attr_lpm_response);
  1264. device_remove_file(&dev->dev, &dev_attr_sleep_status);
  1265. #endif
  1266. device_remove_file(&dev->dev, &dev_attr_peri_iddq);
  1267. device_remove_file(&dev->dev, &dev_attr_peri_otg_disable);
  1268. device_remove_file(&dev->dev, &dev_attr_peri_power);
  1269. }