dw-dphy-sysfs.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2018-2019 Synopsys, Inc. and/or its affiliates.
  4. *
  5. * Synopsys DesignWare MIPI D-PHY controller driver.
  6. * SysFS components for the platform driver
  7. *
  8. * Author: Luis Oliveira <luis.oliveira@synopsys.com>
  9. */
  10. //#define DEBUG 1
  11. #include "dw-dphy-rx.h"
  12. #include "bm_csi_hw.h"
  13. static ssize_t dphy_reset_show(struct device *dev,
  14. struct device_attribute *attr, char *buf)
  15. {
  16. struct platform_device *pdev = to_platform_device(dev);
  17. struct bm_csi_drvdata *drvdata = platform_get_drvdata(pdev);
  18. struct dw_dphy_rx *dphy = drvdata->dphy;
  19. char buffer[15];
  20. dw_dphy_write(dphy, R_CSI2_DPHY_RSTZ, 0);
  21. usleep_range(100, 200);
  22. dw_dphy_write(dphy, R_CSI2_DPHY_RSTZ, 1);
  23. return strlcpy(buf, buffer, PAGE_SIZE);
  24. }
  25. static ssize_t dphy_freq_store(struct device *dev,
  26. struct device_attribute *attr,
  27. const char *buf,
  28. size_t count)
  29. {
  30. int ret;
  31. unsigned long freq;
  32. struct platform_device *pdev = to_platform_device(dev);
  33. struct bm_csi_drvdata *drvdata = platform_get_drvdata(pdev);
  34. struct dw_dphy_rx *dphy = drvdata->dphy;
  35. ret = kstrtoul(buf, 10, &freq);
  36. if (ret < 0)
  37. return ret;
  38. if (freq > 2500) {
  39. dev_info(dev, "Freq must be under 2500 Mhz\n");
  40. return count;
  41. }
  42. if (freq < 80) {
  43. dev_info(dev, "Freq must be over 80 Mhz\n");
  44. return count;
  45. }
  46. dev_vdbg(dev, "Data Rate %lu Mbps\n", freq);
  47. dphy->dphy_freq = freq*1000;
  48. return count;
  49. }
  50. static ssize_t dphy_freq_show(struct device *dev, struct device_attribute *attr,
  51. char *buf)
  52. {
  53. struct platform_device *pdev = to_platform_device(dev);
  54. struct bm_csi_drvdata *drvdata = platform_get_drvdata(pdev);
  55. struct dw_dphy_rx *dphy = drvdata->dphy;
  56. char buffer[15];
  57. snprintf(buffer,
  58. sizeof(buffer),
  59. "Freq %d\n", dphy->dphy_freq);
  60. return strlcpy(buf, buffer, PAGE_SIZE);
  61. }
  62. static ssize_t dphy_addr_store(struct device *dev,
  63. struct device_attribute *attr,
  64. const char *buf,
  65. size_t count)
  66. {
  67. struct platform_device *pdev = to_platform_device(dev);
  68. struct bm_csi_drvdata *drvdata = platform_get_drvdata(pdev);
  69. struct dw_dphy_rx *dphy = drvdata->dphy;
  70. unsigned long addr;
  71. int ret;
  72. ret = kstrtoul(buf, 10, &addr);
  73. if (ret < 0)
  74. return ret;
  75. //payload = (u16)val;
  76. //addr = (u16)(val >> 16);
  77. //dev_vdbg(dev, "addr 0x%lX\n", val);
  78. //dev_vdbg(dev, "payload: 0x%X\n", addr);
  79. //dev_vdbg(dev, "Addr [0x%x] -> 0x%x\n", (unsigned int)addr,
  80. // dw_dphy_te_read(dphy, addr));
  81. printk("<0>""addr 0x%lX\n", addr);
  82. printk("<0>""Addr [0x%x] -> 0x%x\n", (unsigned int)addr,
  83. dw_dphy_te_read(dphy, addr));
  84. return count;
  85. }
  86. #if IS_ENABLED(CONFIG_DWC_MIPI_TC_DPHY_GEN3)
  87. #if 0
  88. static ssize_t idelay_show(struct device *dev, struct device_attribute *attr,
  89. char *buf)
  90. {
  91. struct platform_device *pdev = to_platform_device(dev);
  92. struct bm_csi_drvdata *drvdata = platform_get_drvdata(pdev);
  93. struct dw_dphy_rx *dphy = drvdata->dphy;
  94. char buffer[15];
  95. snprintf(buffer,
  96. sizeof(buffer), "idelay %d\n", dw_dphy_if_get_idelay(dphy));
  97. return strlcpy(buf, buffer, PAGE_SIZE);
  98. }
  99. static ssize_t idelay_store(struct device *dev, struct device_attribute *attr,
  100. const char *buf, size_t count)
  101. {
  102. struct platform_device *pdev = to_platform_device(dev);
  103. struct bm_csi_drvdata *drvdata = platform_get_drvdata(pdev);
  104. struct dw_dphy_rx *dphy = drvdata->dphy;
  105. unsigned long val;
  106. u8 lane, delay;
  107. int ret;
  108. ret = kstrtoul(buf, 16, &val);
  109. if (ret < 0)
  110. return ret;
  111. lane = (u8)val;
  112. delay = (u8)(val >> 8);
  113. dev_vdbg(dev, "Lanes %u\n", lane);
  114. dev_vdbg(dev, "Delay %u\n", delay);
  115. dw_dphy_if_set_idelay_lane(dphy, delay, lane);
  116. return count;
  117. }
  118. #endif
  119. #endif
  120. static ssize_t len_config_store(struct device *dev,
  121. struct device_attribute *attr,
  122. const char *buf,
  123. size_t count)
  124. {
  125. struct platform_device *pdev = to_platform_device(dev);
  126. struct bm_csi_drvdata *drvdata = platform_get_drvdata(pdev);
  127. struct dw_dphy_rx *dphy = drvdata->dphy;
  128. unsigned long length;
  129. int ret;
  130. ret = kstrtoul(buf, 10, &length);
  131. if (ret < 0)
  132. return ret;
  133. if (length == BIT8)
  134. dev_vdbg(dev, "Configured for 8-bit interface\n");
  135. else if (length == BIT12)
  136. dev_vdbg(dev, "Configured for 12-bit interface\n");
  137. else
  138. return count;
  139. dphy->dphy_te_len = length;
  140. return count;
  141. }
  142. static ssize_t len_config_show(struct device *dev,
  143. struct device_attribute *attr, char *buf)
  144. {
  145. struct platform_device *pdev = to_platform_device(dev);
  146. struct bm_csi_drvdata *drvdata = platform_get_drvdata(pdev);
  147. struct dw_dphy_rx *dphy = drvdata->dphy;
  148. char buffer[20];
  149. snprintf(buffer, sizeof(buffer), "Length %d\n", dphy->dphy_te_len);
  150. return strlcpy(buf, buffer, PAGE_SIZE);
  151. }
  152. static ssize_t dw_dphy_g118_settle_store(struct device *dev,
  153. struct device_attribute *attr,
  154. const char *buf, size_t count)
  155. {
  156. struct platform_device *pdev = to_platform_device(dev);
  157. struct bm_csi_drvdata *drvdata = platform_get_drvdata(pdev);
  158. struct dw_dphy_rx *dphy = drvdata->dphy;
  159. unsigned long lp_time;
  160. int ret;
  161. ret = kstrtoul(buf, 10, &lp_time);
  162. if (ret < 0)
  163. return ret;
  164. if (lp_time > 1 && lp_time < 10000) {
  165. dphy->lp_time = lp_time;
  166. } else {
  167. dev_vdbg(dev, "Invalid Value configuring for 1000 ns\n");
  168. dphy->lp_time = 1000;
  169. }
  170. dphy->lp_time = lp_time;
  171. return count;
  172. }
  173. static ssize_t dw_dphy_g118_settle_show(struct device *dev,
  174. struct device_attribute *attr,
  175. char *buf)
  176. {
  177. struct platform_device *pdev = to_platform_device(dev);
  178. struct bm_csi_drvdata *drvdata = platform_get_drvdata(pdev);
  179. struct dw_dphy_rx *dphy = drvdata->dphy;
  180. char buffer[10];
  181. snprintf(buffer, sizeof(buffer), "Settle %d ns\n", dphy->lp_time);
  182. return strlcpy(buf, buffer, PAGE_SIZE);
  183. }
  184. static DEVICE_ATTR_RO(dphy_reset);
  185. static DEVICE_ATTR_RW(dphy_freq);
  186. static DEVICE_ATTR_WO(dphy_addr);
  187. #if IS_ENABLED(CONFIG_DWC_MIPI_TC_DPHY_GEN3)
  188. //static DEVICE_ATTR_RW(idelay);
  189. #endif
  190. static DEVICE_ATTR_RW(len_config);
  191. static DEVICE_ATTR_RW(dw_dphy_g118_settle);
  192. int dw_dphy_create_capabilities_sysfs(struct platform_device *pdev)
  193. {
  194. device_create_file(&pdev->dev, &dev_attr_dphy_reset);
  195. device_create_file(&pdev->dev, &dev_attr_dphy_freq);
  196. device_create_file(&pdev->dev, &dev_attr_dphy_addr);
  197. #if IS_ENABLED(CONFIG_DWC_MIPI_TC_DPHY_GEN3)
  198. // device_create_file(&pdev->dev, &dev_attr_idelay);
  199. #endif
  200. device_create_file(&pdev->dev, &dev_attr_len_config);
  201. device_create_file(&pdev->dev, &dev_attr_dw_dphy_g118_settle);
  202. return 0;
  203. }
  204. int dw_dphy_remove_capabilities_sysfs(struct platform_device *pdev)
  205. {
  206. device_remove_file(&pdev->dev, &dev_attr_dphy_reset);
  207. device_remove_file(&pdev->dev, &dev_attr_dphy_freq);
  208. device_remove_file(&pdev->dev, &dev_attr_dphy_addr);
  209. #if IS_ENABLED(CONFIG_DWC_MIPI_TC_DPHY_GEN3)
  210. // device_create_file(&pdev->dev, &dev_attr_idelay);
  211. #endif
  212. device_remove_file(&pdev->dev, &dev_attr_len_config);
  213. device_remove_file(&pdev->dev, &dev_attr_dw_dphy_g118_settle);
  214. return 0;
  215. }