nwl_ioctl.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. #ifdef __KERNEL__
  54. #include "nwl_driver.h"
  55. #endif
  56. #include "nwl_ioctl.h"
  57. #include "nwl_regs.h"
  58. #ifndef __KERNEL__
  59. #include <hal/hal_api.h>
  60. #include "common_dev.h"
  61. #define NWL_EXTREG_OFFSET 0x308244
  62. #define NWL_REG_OFFSET 0x300000
  63. static HalHandle_t hal_handle;
  64. void nwl_ic_set_hal(HalHandle_t hal)
  65. {
  66. hal_handle = hal;
  67. }
  68. void nwl_write_reg(u32 offset, u32 val)
  69. {
  70. offset += NWL_REG_OFFSET;
  71. HalWriteReg(hal_handle, offset, val);
  72. }
  73. u32 nwl_read_reg(u32 offset)
  74. {
  75. offset += NWL_REG_OFFSET;
  76. return HalReadReg(hal_handle, offset);
  77. }
  78. u32 nwl_write_extreg(u32 offset, u32 val)
  79. {
  80. offset += NWL_EXTREG_OFFSET;
  81. return HalReadReg(hal_handle, offset);
  82. }
  83. int nwl_set_stream(void *dev, int enable)
  84. {
  85. u32 clock_status;
  86. u32 data_status;
  87. nwl_write_reg(MRV_MIPICSI1_NUM_LANES, 0x4);
  88. if (enable == true) {
  89. clock_status = 0x1;
  90. data_status = 0xFF;
  91. } else {
  92. clock_status = 0x0;
  93. data_status = 0x0;
  94. }
  95. nwl_write_reg(MRV_MIPICSI1_LANES_CLK, clock_status);
  96. nwl_write_reg(MRV_MIPICSI1_LANES_DATA, data_status);
  97. return 0;
  98. }
  99. int nwl_init(void)
  100. {
  101. nwl_write_reg(MRV_MIPICSI1_NUM_LANES, 0x4);
  102. nwl_write_reg(MRV_MIPICSI1_LANES_CLK, 0x1);
  103. nwl_write_reg(MRV_MIPICSI1_LANES_DATA, 0xF);
  104. nwl_write_reg(MRV_MIPICSI1_IGNORE_VC, 0x1);
  105. nwl_write_extreg(MRV_MIPICSI1_OUT_SHIFT, 0x4);
  106. return 0;
  107. }
  108. #endif
  109. int nwl_ioc_init(void)
  110. {
  111. nwl_init();
  112. return 0;
  113. }
  114. int nwl_ioc_s_stream(void *dev, void *__user args)
  115. {
  116. int enable;
  117. copy_from_user(&enable, args, sizeof(enable));
  118. nwl_set_stream(dev, enable);
  119. return 0;
  120. }
  121. long nwl_priv_ioctl(void *dev, unsigned int cmd, void *args)
  122. {
  123. int ret = -1;
  124. switch (cmd) {
  125. case CSIIOC_INIT:
  126. ret = nwl_ioc_init();
  127. break;
  128. case CSIIOC_S_STREAM:{
  129. ret = nwl_ioc_s_stream(dev, args);
  130. }
  131. break;
  132. default:
  133. pr_err("Unsupported csi command %d.\n", cmd);
  134. break;
  135. }
  136. return ret;
  137. }