nwl_core.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /****************************************************************************
  2. *
  3. * The MIT License (MIT)
  4. *
  5. * Copyright (c) 2020 VeriSilicon Holdings Co., Ltd.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. *
  25. *****************************************************************************
  26. *
  27. * The GPL License (GPL)
  28. *
  29. * Copyright (c) 2020 VeriSilicon Holdings Co., Ltd.
  30. *
  31. * This program is free software; you can redistribute it and/or
  32. * modify it under the terms of the GNU General Public License
  33. * as published by the Free Software Foundation; either version 2
  34. * of the License, or (at your option) any later version.
  35. *
  36. * This program is distributed in the hope that it will be useful,
  37. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  38. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  39. * GNU General Public License for more details.
  40. *
  41. * You should have received a copy of the GNU General Public License
  42. * along with this program;
  43. *
  44. *****************************************************************************
  45. *
  46. * Note: This software is released under dual MIT and GPL licenses. A
  47. * recipient may use this file under the terms of either the MIT license or
  48. * GPL License. If you wish to use only one license not the other, you can
  49. * indicate your decision by deleting one of the above license notices in your
  50. * version of this file.
  51. *
  52. *****************************************************************************/
  53. #include <linux/module.h>
  54. #include <linux/uaccess.h>
  55. #ifdef ISP8000L_V2008
  56. #include <linux/io.h> //Fix thead compile error.
  57. #endif
  58. #include "nwl_regs.h"
  59. #include "../csi_ioctl.h"
  60. int nwl_register_write(void * dev,unsigned int addr, unsigned int data)
  61. {
  62. void __iomem *base_addr;
  63. struct vvcam_csi_dev *nwl_csi_dev;
  64. if (dev == NULL)
  65. return -1;
  66. nwl_csi_dev = dev;
  67. base_addr = nwl_csi_dev->base;
  68. writel(data, base_addr + addr);
  69. return 0;
  70. }
  71. int nwl_register_read(void * dev,unsigned int addr, unsigned int *data)
  72. {
  73. void __iomem *base_addr;
  74. struct vvcam_csi_dev *nwl_csi_dev;
  75. if (dev == NULL)
  76. return -1;
  77. nwl_csi_dev = dev;
  78. base_addr = nwl_csi_dev->base;
  79. *data = readl(base_addr + addr);
  80. return 0;
  81. }
  82. static int nwl_init(void * dev)
  83. {
  84. struct vvcam_csi_dev *nwl_csi_dev;
  85. if (dev == NULL)
  86. return -1;
  87. nwl_csi_dev = dev;
  88. nwl_csi_dev->csi_access.write = nwl_register_write;
  89. nwl_csi_dev->csi_access.read = nwl_register_read;
  90. nwl_csi_dev->csi_access.write(dev,MRV_MIPICSI_NUM_LANES, 0x4);
  91. nwl_csi_dev->csi_access.write(dev,MRV_MIPICSI_LANES_CLK, 0x1);
  92. nwl_csi_dev->csi_access.write(dev,MRV_MIPICSI_LANES_DATA, 0xF);
  93. nwl_csi_dev->csi_access.write(dev,MRV_MIPICSI_IGNORE_VC, 0x1);
  94. if (nwl_csi_dev->device_idx == 0)
  95. {
  96. nwl_csi_dev->csi_access.write(dev,MRV_MIPICSI0_CTRL, 0x4);
  97. }else
  98. {
  99. nwl_csi_dev->csi_access.write(dev,MRV_MIPICSI1_CTRL, 0x4);
  100. }
  101. return 0;
  102. }
  103. static int nwl_exit(void * dev)
  104. {
  105. void __iomem *base_addr;
  106. struct vvcam_csi_dev *nwl_csi_dev;
  107. if (dev == NULL)
  108. return -1;
  109. nwl_csi_dev = dev;
  110. base_addr = nwl_csi_dev->base;
  111. return 0;
  112. }
  113. static int nwl_reset(void * dev)
  114. {
  115. void __iomem *base_addr;
  116. struct vvcam_csi_dev *nwl_csi_dev;
  117. if (dev == NULL)
  118. return -1;
  119. nwl_csi_dev = dev;
  120. base_addr = nwl_csi_dev->base;
  121. return 0;
  122. }
  123. static int nwl_set_power(void * dev)
  124. {
  125. void __iomem *base_addr;
  126. struct vvcam_csi_dev *nwl_csi_dev;
  127. if (dev == NULL)
  128. return -1;
  129. nwl_csi_dev = dev;
  130. base_addr = nwl_csi_dev->base;
  131. return 0;
  132. }
  133. static int nwl_get_power(void * dev)
  134. {
  135. void __iomem *base_addr;
  136. struct vvcam_csi_dev *nwl_csi_dev;
  137. if (dev == NULL)
  138. return -1;
  139. nwl_csi_dev = dev;
  140. base_addr = nwl_csi_dev->base;
  141. return 0;
  142. }
  143. static int nwl_set_clock(void * dev)
  144. {
  145. void __iomem *base_addr;
  146. struct vvcam_csi_dev *nwl_csi_dev;
  147. if (dev == NULL)
  148. return -1;
  149. nwl_csi_dev = dev;
  150. base_addr = nwl_csi_dev->base;
  151. return 0;
  152. }
  153. static int nwl_get_clock(void * dev)
  154. {
  155. void __iomem *base_addr;
  156. struct vvcam_csi_dev *nwl_csi_dev;
  157. if (dev == NULL)
  158. return -1;
  159. nwl_csi_dev = dev;
  160. base_addr = nwl_csi_dev->base;
  161. return 0;
  162. }
  163. static int nwl_set_stream_control(void * dev)
  164. {
  165. struct vvcam_csi_dev *nwl_csi_dev;
  166. u32 clock_status;
  167. u32 data_status;
  168. if (dev == NULL)
  169. return -1;
  170. nwl_csi_dev = dev;
  171. if (nwl_csi_dev->streaming_enable)
  172. {
  173. clock_status = 0x01;
  174. data_status = 0xFF;
  175. }
  176. else
  177. {
  178. clock_status = 0x00;
  179. data_status = 0x00;
  180. }
  181. nwl_csi_dev->csi_access.write(dev,MRV_MIPICSI_LANES_CLK, clock_status);
  182. nwl_csi_dev->csi_access.write(dev,MRV_MIPICSI_LANES_DATA, data_status);
  183. return 0;
  184. }
  185. static int nwl_get_stream_control(void * dev)
  186. {
  187. void __iomem *base_addr;
  188. struct vvcam_csi_dev *nwl_csi_dev;
  189. if (dev == NULL)
  190. return -1;
  191. nwl_csi_dev = dev;
  192. base_addr = nwl_csi_dev->base;
  193. return 0;
  194. }
  195. static int nwl_set_fmt(void * dev)
  196. {
  197. void __iomem *base_addr;
  198. struct vvcam_csi_dev *nwl_csi_dev;
  199. if (dev == NULL)
  200. return -1;
  201. nwl_csi_dev = dev;
  202. base_addr = nwl_csi_dev->base;
  203. return 0;
  204. }
  205. static int nwl_get_fmt(void * dev)
  206. {
  207. void __iomem *base_addr;
  208. struct vvcam_csi_dev *nwl_csi_dev;
  209. if (dev == NULL)
  210. return -1;
  211. nwl_csi_dev = dev;
  212. base_addr = nwl_csi_dev->base;
  213. return 0;
  214. }
  215. static int nwl_set_vc_select(void * dev)
  216. {
  217. void __iomem *base_addr;
  218. struct vvcam_csi_dev *nwl_csi_dev;
  219. if (dev == NULL)
  220. return -1;
  221. nwl_csi_dev = dev;
  222. base_addr = nwl_csi_dev->base;
  223. return 0;
  224. }
  225. static int nwl_get_vc_select(void * dev)
  226. {
  227. void __iomem *base_addr;
  228. struct vvcam_csi_dev *nwl_csi_dev;
  229. if (dev == NULL)
  230. return -1;
  231. nwl_csi_dev = dev;
  232. base_addr = nwl_csi_dev->base;
  233. return 0;
  234. }
  235. static int nwl_set_lane_cfg(void * dev)
  236. {
  237. void __iomem *base_addr;
  238. struct vvcam_csi_dev *nwl_csi_dev;
  239. if (dev == NULL)
  240. return -1;
  241. nwl_csi_dev = dev;
  242. nwl_csi_dev->csi_access.write(dev,MRV_MIPICSI_NUM_LANES, nwl_csi_dev->csi_lane_cfg.mipi_lane_num);
  243. return 0;
  244. }
  245. struct vvcam_csi_hardware_function_s nwl_mipi_function =
  246. {
  247. .init = nwl_init,
  248. .exit = nwl_exit,
  249. .reset = nwl_reset,
  250. .set_power = nwl_set_power,
  251. .get_power = nwl_get_power,
  252. .set_clock = nwl_set_clock,
  253. .get_clock = nwl_get_clock,
  254. .set_stream_control = nwl_set_stream_control,
  255. .get_stream_control = nwl_get_stream_control,
  256. .set_fmt = nwl_set_fmt,
  257. .get_fmt = nwl_get_fmt,
  258. .set_vc_select = nwl_set_vc_select,
  259. .get_vc_select = nwl_get_vc_select,
  260. .set_lane_cfg = nwl_set_lane_cfg,
  261. };