fimc-is.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. /*
  2. * Samsung EXYNOS4x12 FIMC-IS (Imaging Subsystem) driver
  3. *
  4. * Copyright (C) 2013 Samsung Electronics Co., Ltd.
  5. *
  6. * Authors: Younghwan Joo <yhwan.joo@samsung.com>
  7. * Sylwester Nawrocki <s.nawrocki@samsung.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #ifndef FIMC_IS_H_
  14. #define FIMC_IS_H_
  15. #include <asm/barrier.h>
  16. #include <linux/clk.h>
  17. #include <linux/device.h>
  18. #include <linux/kernel.h>
  19. #include <linux/pinctrl/consumer.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/sizes.h>
  22. #include <linux/spinlock.h>
  23. #include <linux/types.h>
  24. #include <media/videobuf2-v4l2.h>
  25. #include <media/v4l2-ctrls.h>
  26. #include "fimc-isp.h"
  27. #include "fimc-is-command.h"
  28. #include "fimc-is-sensor.h"
  29. #include "fimc-is-param.h"
  30. #include "fimc-is-regs.h"
  31. #define FIMC_IS_DRV_NAME "exynos4-fimc-is"
  32. #define FIMC_IS_FW_FILENAME "exynos4_fimc_is_fw.bin"
  33. #define FIMC_IS_SETFILE_6A3 "exynos4_s5k6a3_setfile.bin"
  34. #define FIMC_IS_FW_LOAD_TIMEOUT 1000 /* ms */
  35. #define FIMC_IS_POWER_ON_TIMEOUT 1000 /* us */
  36. #define FIMC_IS_SENSORS_NUM 2
  37. /* Memory definitions */
  38. #define FIMC_IS_CPU_MEM_SIZE (0xa00000)
  39. #define FIMC_IS_CPU_BASE_MASK ((1 << 26) - 1)
  40. #define FIMC_IS_REGION_SIZE 0x5000
  41. #define FIMC_IS_DEBUG_REGION_OFFSET 0x0084b000
  42. #define FIMC_IS_SHARED_REGION_OFFSET 0x008c0000
  43. #define FIMC_IS_FW_INFO_LEN 31
  44. #define FIMC_IS_FW_VER_LEN 7
  45. #define FIMC_IS_FW_DESC_LEN (FIMC_IS_FW_INFO_LEN + \
  46. FIMC_IS_FW_VER_LEN)
  47. #define FIMC_IS_SETFILE_INFO_LEN 39
  48. #define FIMC_IS_EXTRA_MEM_SIZE (FIMC_IS_EXTRA_FW_SIZE + \
  49. FIMC_IS_EXTRA_SETFILE_SIZE + 0x1000)
  50. #define FIMC_IS_EXTRA_FW_SIZE 0x180000
  51. #define FIMC_IS_EXTRA_SETFILE_SIZE 0x4b000
  52. /* TODO: revisit */
  53. #define FIMC_IS_FW_ADDR_MASK ((1 << 26) - 1)
  54. #define FIMC_IS_FW_SIZE_MAX (SZ_4M)
  55. #define FIMC_IS_FW_SIZE_MIN (SZ_32K)
  56. #define ATCLK_MCUISP_FREQUENCY 100000000UL
  57. #define ACLK_AXI_FREQUENCY 100000000UL
  58. enum {
  59. ISS_CLK_PPMUISPX,
  60. ISS_CLK_PPMUISPMX,
  61. ISS_CLK_LITE0,
  62. ISS_CLK_LITE1,
  63. ISS_CLK_MPLL,
  64. ISS_CLK_ISP,
  65. ISS_CLK_DRC,
  66. ISS_CLK_FD,
  67. ISS_CLK_MCUISP,
  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. * @alloc_ctx: videobuf2 memory allocator context
  204. * @lock: mutex serializing video device and the subdev operations
  205. * @slock: spinlock protecting this data structure and the hw registers
  206. * @clocks: FIMC-LITE gate clock
  207. * @regs: MCUCTL mmapped registers region
  208. * @pmu_regs: PMU ISP mmapped registers region
  209. * @irq_queue: interrupt handling waitqueue
  210. * @lpm: low power mode flag
  211. * @state: internal driver's state flags
  212. */
  213. struct fimc_is {
  214. struct platform_device *pdev;
  215. struct pinctrl *pctrl;
  216. struct v4l2_device *v4l2_dev;
  217. struct fimc_is_firmware fw;
  218. struct fimc_is_memory memory;
  219. struct firmware *f_w;
  220. struct fimc_isp isp;
  221. struct fimc_is_sensor sensor[FIMC_IS_SENSORS_NUM];
  222. struct fimc_is_setfile setfile;
  223. struct vb2_alloc_ctx *alloc_ctx;
  224. struct v4l2_ctrl_handler ctrl_handler;
  225. struct mutex lock;
  226. spinlock_t slock;
  227. struct clk *clocks[ISS_CLKS_MAX];
  228. void __iomem *regs;
  229. void __iomem *pmu_regs;
  230. int irq;
  231. wait_queue_head_t irq_queue;
  232. u8 lpm;
  233. unsigned long state;
  234. unsigned int sensor_index;
  235. struct i2h_cmd i2h_cmd;
  236. struct h2i_cmd h2i_cmd;
  237. struct is_fd_result_header fd_header;
  238. struct chain_config config[IS_SC_MAX];
  239. unsigned config_index;
  240. struct is_region *is_p_region;
  241. dma_addr_t is_dma_p_region;
  242. struct is_share_region *is_shared_region;
  243. struct is_af_info af;
  244. struct dentry *debugfs_entry;
  245. };
  246. static inline struct fimc_is *fimc_isp_to_is(struct fimc_isp *isp)
  247. {
  248. return container_of(isp, struct fimc_is, isp);
  249. }
  250. static inline struct chain_config *__get_curr_is_config(struct fimc_is *is)
  251. {
  252. return &is->config[is->config_index];
  253. }
  254. static inline void fimc_is_mem_barrier(void)
  255. {
  256. mb();
  257. }
  258. static inline void fimc_is_set_param_bit(struct fimc_is *is, int num)
  259. {
  260. struct chain_config *cfg = &is->config[is->config_index];
  261. set_bit(num, &cfg->p_region_index[0]);
  262. }
  263. static inline void fimc_is_set_param_ctrl_cmd(struct fimc_is *is, int cmd)
  264. {
  265. is->is_p_region->parameter.isp.control.cmd = cmd;
  266. }
  267. static inline void mcuctl_write(u32 v, struct fimc_is *is, unsigned int offset)
  268. {
  269. writel(v, is->regs + offset);
  270. }
  271. static inline u32 mcuctl_read(struct fimc_is *is, unsigned int offset)
  272. {
  273. return readl(is->regs + offset);
  274. }
  275. static inline void pmuisp_write(u32 v, struct fimc_is *is, unsigned int offset)
  276. {
  277. writel(v, is->pmu_regs + offset);
  278. }
  279. static inline u32 pmuisp_read(struct fimc_is *is, unsigned int offset)
  280. {
  281. return readl(is->pmu_regs + offset);
  282. }
  283. int fimc_is_wait_event(struct fimc_is *is, unsigned long bit,
  284. unsigned int state, unsigned int timeout);
  285. int fimc_is_cpu_set_power(struct fimc_is *is, int on);
  286. int fimc_is_start_firmware(struct fimc_is *is);
  287. int fimc_is_hw_initialize(struct fimc_is *is);
  288. void fimc_is_log_dump(const char *level, const void *buf, size_t len);
  289. #endif /* FIMC_IS_H_ */