fimc-is.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Samsung EXYNOS4x12 FIMC-IS (Imaging Subsystem) driver
  4. *
  5. * Copyright (C) 2013 Samsung Electronics Co., Ltd.
  6. *
  7. * Authors: Younghwan Joo <yhwan.joo@samsung.com>
  8. * Sylwester Nawrocki <s.nawrocki@samsung.com>
  9. */
  10. #ifndef FIMC_IS_H_
  11. #define FIMC_IS_H_
  12. #include <asm/barrier.h>
  13. #include <linux/clk.h>
  14. #include <linux/device.h>
  15. #include <linux/kernel.h>
  16. #include <linux/pinctrl/consumer.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/sizes.h>
  19. #include <linux/spinlock.h>
  20. #include <linux/types.h>
  21. #include <media/videobuf2-v4l2.h>
  22. #include <media/v4l2-ctrls.h>
  23. #include "fimc-isp.h"
  24. #include "fimc-is-command.h"
  25. #include "fimc-is-sensor.h"
  26. #include "fimc-is-param.h"
  27. #include "fimc-is-regs.h"
  28. #define FIMC_IS_DRV_NAME "exynos4-fimc-is"
  29. #define FIMC_IS_FW_FILENAME "exynos4_fimc_is_fw.bin"
  30. #define FIMC_IS_SETFILE_6A3 "exynos4_s5k6a3_setfile.bin"
  31. #define FIMC_IS_FW_LOAD_TIMEOUT 1000 /* ms */
  32. #define FIMC_IS_POWER_ON_TIMEOUT 1000 /* us */
  33. #define FIMC_IS_SENSORS_NUM 2
  34. /* Memory definitions */
  35. #define FIMC_IS_CPU_MEM_SIZE (0xa00000)
  36. #define FIMC_IS_CPU_BASE_MASK ((1 << 26) - 1)
  37. #define FIMC_IS_REGION_SIZE 0x5000
  38. #define FIMC_IS_DEBUG_REGION_OFFSET 0x0084b000
  39. #define FIMC_IS_SHARED_REGION_OFFSET 0x008c0000
  40. #define FIMC_IS_FW_INFO_LEN 31
  41. #define FIMC_IS_FW_VER_LEN 7
  42. #define FIMC_IS_FW_DESC_LEN (FIMC_IS_FW_INFO_LEN + \
  43. FIMC_IS_FW_VER_LEN)
  44. #define FIMC_IS_SETFILE_INFO_LEN 39
  45. #define FIMC_IS_EXTRA_MEM_SIZE (FIMC_IS_EXTRA_FW_SIZE + \
  46. FIMC_IS_EXTRA_SETFILE_SIZE + 0x1000)
  47. #define FIMC_IS_EXTRA_FW_SIZE 0x180000
  48. #define FIMC_IS_EXTRA_SETFILE_SIZE 0x4b000
  49. /* TODO: revisit */
  50. #define FIMC_IS_FW_ADDR_MASK ((1 << 26) - 1)
  51. #define FIMC_IS_FW_SIZE_MAX (SZ_4M)
  52. #define FIMC_IS_FW_SIZE_MIN (SZ_32K)
  53. #define ATCLK_MCUISP_FREQUENCY 100000000UL
  54. #define ACLK_AXI_FREQUENCY 100000000UL
  55. enum {
  56. ISS_CLK_PPMUISPX,
  57. ISS_CLK_PPMUISPMX,
  58. ISS_CLK_LITE0,
  59. ISS_CLK_LITE1,
  60. ISS_CLK_MPLL,
  61. ISS_CLK_ISP,
  62. ISS_CLK_DRC,
  63. ISS_CLK_FD,
  64. ISS_CLK_MCUISP,
  65. ISS_CLK_GICISP,
  66. ISS_CLK_PWM_ISP,
  67. ISS_CLK_MCUCTL_ISP,
  68. ISS_CLK_UART,
  69. ISS_GATE_CLKS_MAX,
  70. ISS_CLK_ISP_DIV0 = ISS_GATE_CLKS_MAX,
  71. ISS_CLK_ISP_DIV1,
  72. ISS_CLK_MCUISP_DIV0,
  73. ISS_CLK_MCUISP_DIV1,
  74. ISS_CLK_ACLK200,
  75. ISS_CLK_ACLK200_DIV,
  76. ISS_CLK_ACLK400MCUISP,
  77. ISS_CLK_ACLK400MCUISP_DIV,
  78. ISS_CLKS_MAX
  79. };
  80. /* The driver's internal state flags */
  81. enum {
  82. IS_ST_IDLE,
  83. IS_ST_PWR_ON,
  84. IS_ST_A5_PWR_ON,
  85. IS_ST_FW_LOADED,
  86. IS_ST_OPEN_SENSOR,
  87. IS_ST_SETFILE_LOADED,
  88. IS_ST_INIT_DONE,
  89. IS_ST_STREAM_ON,
  90. IS_ST_STREAM_OFF,
  91. IS_ST_CHANGE_MODE,
  92. IS_ST_BLOCK_CMD_CLEARED,
  93. IS_ST_SET_ZOOM,
  94. IS_ST_PWR_SUBIP_ON,
  95. IS_ST_END,
  96. };
  97. enum af_state {
  98. FIMC_IS_AF_IDLE = 0,
  99. FIMC_IS_AF_SETCONFIG = 1,
  100. FIMC_IS_AF_RUNNING = 2,
  101. FIMC_IS_AF_LOCK = 3,
  102. FIMC_IS_AF_ABORT = 4,
  103. FIMC_IS_AF_FAILED = 5,
  104. };
  105. enum af_lock_state {
  106. FIMC_IS_AF_UNLOCKED = 0,
  107. FIMC_IS_AF_LOCKED = 2
  108. };
  109. enum ae_lock_state {
  110. FIMC_IS_AE_UNLOCKED = 0,
  111. FIMC_IS_AE_LOCKED = 1
  112. };
  113. enum awb_lock_state {
  114. FIMC_IS_AWB_UNLOCKED = 0,
  115. FIMC_IS_AWB_LOCKED = 1
  116. };
  117. enum {
  118. IS_METERING_CONFIG_CMD,
  119. IS_METERING_CONFIG_WIN_POS_X,
  120. IS_METERING_CONFIG_WIN_POS_Y,
  121. IS_METERING_CONFIG_WIN_WIDTH,
  122. IS_METERING_CONFIG_WIN_HEIGHT,
  123. IS_METERING_CONFIG_MAX
  124. };
  125. struct is_setfile {
  126. const struct firmware *info;
  127. int state;
  128. u32 sub_index;
  129. u32 base;
  130. size_t size;
  131. };
  132. struct is_fd_result_header {
  133. u32 offset;
  134. u32 count;
  135. u32 index;
  136. u32 curr_index;
  137. u32 width;
  138. u32 height;
  139. };
  140. struct is_af_info {
  141. u16 mode;
  142. u32 af_state;
  143. u32 af_lock_state;
  144. u32 ae_lock_state;
  145. u32 awb_lock_state;
  146. u16 pos_x;
  147. u16 pos_y;
  148. u16 prev_pos_x;
  149. u16 prev_pos_y;
  150. u16 use_af;
  151. };
  152. struct fimc_is_firmware {
  153. const struct firmware *f_w;
  154. dma_addr_t paddr;
  155. void *vaddr;
  156. unsigned int size;
  157. char info[FIMC_IS_FW_INFO_LEN + 1];
  158. char version[FIMC_IS_FW_VER_LEN + 1];
  159. char setfile_info[FIMC_IS_SETFILE_INFO_LEN + 1];
  160. u8 state;
  161. };
  162. struct fimc_is_memory {
  163. /* physical base address */
  164. dma_addr_t paddr;
  165. /* virtual base address */
  166. void *vaddr;
  167. /* total length */
  168. unsigned int size;
  169. };
  170. #define FIMC_IS_I2H_MAX_ARGS 12
  171. struct i2h_cmd {
  172. u32 cmd;
  173. u32 sensor_id;
  174. u16 num_args;
  175. u32 args[FIMC_IS_I2H_MAX_ARGS];
  176. };
  177. struct h2i_cmd {
  178. u16 cmd_type;
  179. u32 entry_id;
  180. };
  181. #define FIMC_IS_DEBUG_MSG 0x3f
  182. #define FIMC_IS_DEBUG_LEVEL 3
  183. struct fimc_is_setfile {
  184. const struct firmware *info;
  185. unsigned int state;
  186. unsigned int size;
  187. u32 sub_index;
  188. u32 base;
  189. };
  190. struct chain_config {
  191. struct global_param global;
  192. struct sensor_param sensor;
  193. struct isp_param isp;
  194. struct drc_param drc;
  195. struct fd_param fd;
  196. unsigned long p_region_index[2];
  197. };
  198. /**
  199. * struct fimc_is - fimc-is data structure
  200. * @pdev: pointer to FIMC-IS platform device
  201. * @pctrl: pointer to pinctrl structure for this device
  202. * @v4l2_dev: pointer to top the level v4l2_device
  203. * @lock: mutex serializing video device and the subdev operations
  204. * @slock: spinlock protecting this data structure and the hw registers
  205. * @clocks: FIMC-LITE gate clock
  206. * @regs: MCUCTL mmapped registers region
  207. * @pmu_regs: PMU ISP mmapped registers region
  208. * @irq_queue: interrupt handling waitqueue
  209. * @lpm: low power mode flag
  210. * @state: internal driver's state flags
  211. */
  212. struct fimc_is {
  213. struct platform_device *pdev;
  214. struct pinctrl *pctrl;
  215. struct v4l2_device *v4l2_dev;
  216. struct fimc_is_firmware fw;
  217. struct fimc_is_memory memory;
  218. struct firmware *f_w;
  219. struct fimc_isp isp;
  220. struct fimc_is_sensor sensor[FIMC_IS_SENSORS_NUM];
  221. struct fimc_is_setfile setfile;
  222. struct v4l2_ctrl_handler ctrl_handler;
  223. struct mutex lock;
  224. spinlock_t slock;
  225. struct clk *clocks[ISS_CLKS_MAX];
  226. void __iomem *regs;
  227. void __iomem *pmu_regs;
  228. int irq;
  229. wait_queue_head_t irq_queue;
  230. u8 lpm;
  231. unsigned long state;
  232. unsigned int sensor_index;
  233. struct i2h_cmd i2h_cmd;
  234. struct h2i_cmd h2i_cmd;
  235. struct is_fd_result_header fd_header;
  236. struct chain_config config[IS_SC_MAX];
  237. unsigned config_index;
  238. struct is_region *is_p_region;
  239. dma_addr_t is_dma_p_region;
  240. struct is_share_region *is_shared_region;
  241. struct is_af_info af;
  242. struct dentry *debugfs_entry;
  243. };
  244. static inline struct fimc_is *fimc_isp_to_is(struct fimc_isp *isp)
  245. {
  246. return container_of(isp, struct fimc_is, isp);
  247. }
  248. static inline struct chain_config *__get_curr_is_config(struct fimc_is *is)
  249. {
  250. return &is->config[is->config_index];
  251. }
  252. static inline void fimc_is_mem_barrier(void)
  253. {
  254. mb();
  255. }
  256. static inline void fimc_is_set_param_bit(struct fimc_is *is, int num)
  257. {
  258. struct chain_config *cfg = &is->config[is->config_index];
  259. set_bit(num, &cfg->p_region_index[0]);
  260. }
  261. static inline void fimc_is_set_param_ctrl_cmd(struct fimc_is *is, int cmd)
  262. {
  263. is->is_p_region->parameter.isp.control.cmd = cmd;
  264. }
  265. static inline void mcuctl_write(u32 v, struct fimc_is *is, unsigned int offset)
  266. {
  267. writel(v, is->regs + offset);
  268. }
  269. static inline u32 mcuctl_read(struct fimc_is *is, unsigned int offset)
  270. {
  271. return readl(is->regs + offset);
  272. }
  273. static inline void pmuisp_write(u32 v, struct fimc_is *is, unsigned int offset)
  274. {
  275. writel(v, is->pmu_regs + offset);
  276. }
  277. static inline u32 pmuisp_read(struct fimc_is *is, unsigned int offset)
  278. {
  279. return readl(is->pmu_regs + offset);
  280. }
  281. int fimc_is_wait_event(struct fimc_is *is, unsigned long bit,
  282. unsigned int state, unsigned int timeout);
  283. int fimc_is_cpu_set_power(struct fimc_is *is, int on);
  284. int fimc_is_start_firmware(struct fimc_is *is);
  285. int fimc_is_hw_initialize(struct fimc_is *is);
  286. void fimc_is_log_dump(const char *level, const void *buf, size_t len);
  287. #endif /* FIMC_IS_H_ */