fimc-is.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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 "/*(DEBLOBBED)*/"
  33. #define FIMC_IS_SETFILE_6A3 "/*(DEBLOBBED)*/"
  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_GICISP,
  69. ISS_CLK_PWM_ISP,
  70. ISS_CLK_MCUCTL_ISP,
  71. ISS_CLK_UART,
  72. ISS_GATE_CLKS_MAX,
  73. ISS_CLK_ISP_DIV0 = ISS_GATE_CLKS_MAX,
  74. ISS_CLK_ISP_DIV1,
  75. ISS_CLK_MCUISP_DIV0,
  76. ISS_CLK_MCUISP_DIV1,
  77. ISS_CLK_ACLK200,
  78. ISS_CLK_ACLK200_DIV,
  79. ISS_CLK_ACLK400MCUISP,
  80. ISS_CLK_ACLK400MCUISP_DIV,
  81. ISS_CLKS_MAX
  82. };
  83. /* The driver's internal state flags */
  84. enum {
  85. IS_ST_IDLE,
  86. IS_ST_PWR_ON,
  87. IS_ST_A5_PWR_ON,
  88. IS_ST_FW_LOADED,
  89. IS_ST_OPEN_SENSOR,
  90. IS_ST_SETFILE_LOADED,
  91. IS_ST_INIT_DONE,
  92. IS_ST_STREAM_ON,
  93. IS_ST_STREAM_OFF,
  94. IS_ST_CHANGE_MODE,
  95. IS_ST_BLOCK_CMD_CLEARED,
  96. IS_ST_SET_ZOOM,
  97. IS_ST_PWR_SUBIP_ON,
  98. IS_ST_END,
  99. };
  100. enum af_state {
  101. FIMC_IS_AF_IDLE = 0,
  102. FIMC_IS_AF_SETCONFIG = 1,
  103. FIMC_IS_AF_RUNNING = 2,
  104. FIMC_IS_AF_LOCK = 3,
  105. FIMC_IS_AF_ABORT = 4,
  106. FIMC_IS_AF_FAILED = 5,
  107. };
  108. enum af_lock_state {
  109. FIMC_IS_AF_UNLOCKED = 0,
  110. FIMC_IS_AF_LOCKED = 2
  111. };
  112. enum ae_lock_state {
  113. FIMC_IS_AE_UNLOCKED = 0,
  114. FIMC_IS_AE_LOCKED = 1
  115. };
  116. enum awb_lock_state {
  117. FIMC_IS_AWB_UNLOCKED = 0,
  118. FIMC_IS_AWB_LOCKED = 1
  119. };
  120. enum {
  121. IS_METERING_CONFIG_CMD,
  122. IS_METERING_CONFIG_WIN_POS_X,
  123. IS_METERING_CONFIG_WIN_POS_Y,
  124. IS_METERING_CONFIG_WIN_WIDTH,
  125. IS_METERING_CONFIG_WIN_HEIGHT,
  126. IS_METERING_CONFIG_MAX
  127. };
  128. struct is_setfile {
  129. const struct firmware *info;
  130. int state;
  131. u32 sub_index;
  132. u32 base;
  133. size_t size;
  134. };
  135. struct is_fd_result_header {
  136. u32 offset;
  137. u32 count;
  138. u32 index;
  139. u32 curr_index;
  140. u32 width;
  141. u32 height;
  142. };
  143. struct is_af_info {
  144. u16 mode;
  145. u32 af_state;
  146. u32 af_lock_state;
  147. u32 ae_lock_state;
  148. u32 awb_lock_state;
  149. u16 pos_x;
  150. u16 pos_y;
  151. u16 prev_pos_x;
  152. u16 prev_pos_y;
  153. u16 use_af;
  154. };
  155. struct fimc_is_firmware {
  156. const struct firmware *f_w;
  157. dma_addr_t paddr;
  158. void *vaddr;
  159. unsigned int size;
  160. char info[FIMC_IS_FW_INFO_LEN + 1];
  161. char version[FIMC_IS_FW_VER_LEN + 1];
  162. char setfile_info[FIMC_IS_SETFILE_INFO_LEN + 1];
  163. u8 state;
  164. };
  165. struct fimc_is_memory {
  166. /* physical base address */
  167. dma_addr_t paddr;
  168. /* virtual base address */
  169. void *vaddr;
  170. /* total length */
  171. unsigned int size;
  172. };
  173. #define FIMC_IS_I2H_MAX_ARGS 12
  174. struct i2h_cmd {
  175. u32 cmd;
  176. u32 sensor_id;
  177. u16 num_args;
  178. u32 args[FIMC_IS_I2H_MAX_ARGS];
  179. };
  180. struct h2i_cmd {
  181. u16 cmd_type;
  182. u32 entry_id;
  183. };
  184. #define FIMC_IS_DEBUG_MSG 0x3f
  185. #define FIMC_IS_DEBUG_LEVEL 3
  186. struct fimc_is_setfile {
  187. const struct firmware *info;
  188. unsigned int state;
  189. unsigned int size;
  190. u32 sub_index;
  191. u32 base;
  192. };
  193. struct chain_config {
  194. struct global_param global;
  195. struct sensor_param sensor;
  196. struct isp_param isp;
  197. struct drc_param drc;
  198. struct fd_param fd;
  199. unsigned long p_region_index[2];
  200. };
  201. /**
  202. * struct fimc_is - fimc-is data structure
  203. * @pdev: pointer to FIMC-IS platform device
  204. * @pctrl: pointer to pinctrl structure for this device
  205. * @v4l2_dev: pointer to top the level v4l2_device
  206. * @lock: mutex serializing video device and the subdev operations
  207. * @slock: spinlock protecting this data structure and the hw registers
  208. * @clocks: FIMC-LITE gate clock
  209. * @regs: MCUCTL mmapped registers region
  210. * @pmu_regs: PMU ISP mmapped registers region
  211. * @irq_queue: interrupt handling waitqueue
  212. * @lpm: low power mode flag
  213. * @state: internal driver's state flags
  214. */
  215. struct fimc_is {
  216. struct platform_device *pdev;
  217. struct pinctrl *pctrl;
  218. struct v4l2_device *v4l2_dev;
  219. struct fimc_is_firmware fw;
  220. struct fimc_is_memory memory;
  221. struct firmware *f_w;
  222. struct fimc_isp isp;
  223. struct fimc_is_sensor sensor[FIMC_IS_SENSORS_NUM];
  224. struct fimc_is_setfile setfile;
  225. struct v4l2_ctrl_handler ctrl_handler;
  226. struct mutex lock;
  227. spinlock_t slock;
  228. struct clk *clocks[ISS_CLKS_MAX];
  229. void __iomem *regs;
  230. void __iomem *pmu_regs;
  231. int irq;
  232. wait_queue_head_t irq_queue;
  233. u8 lpm;
  234. unsigned long state;
  235. unsigned int sensor_index;
  236. struct i2h_cmd i2h_cmd;
  237. struct h2i_cmd h2i_cmd;
  238. struct is_fd_result_header fd_header;
  239. struct chain_config config[IS_SC_MAX];
  240. unsigned config_index;
  241. struct is_region *is_p_region;
  242. dma_addr_t is_dma_p_region;
  243. struct is_share_region *is_shared_region;
  244. struct is_af_info af;
  245. struct dentry *debugfs_entry;
  246. };
  247. static inline struct fimc_is *fimc_isp_to_is(struct fimc_isp *isp)
  248. {
  249. return container_of(isp, struct fimc_is, isp);
  250. }
  251. static inline struct chain_config *__get_curr_is_config(struct fimc_is *is)
  252. {
  253. return &is->config[is->config_index];
  254. }
  255. static inline void fimc_is_mem_barrier(void)
  256. {
  257. mb();
  258. }
  259. static inline void fimc_is_set_param_bit(struct fimc_is *is, int num)
  260. {
  261. struct chain_config *cfg = &is->config[is->config_index];
  262. set_bit(num, &cfg->p_region_index[0]);
  263. }
  264. static inline void fimc_is_set_param_ctrl_cmd(struct fimc_is *is, int cmd)
  265. {
  266. is->is_p_region->parameter.isp.control.cmd = cmd;
  267. }
  268. static inline void mcuctl_write(u32 v, struct fimc_is *is, unsigned int offset)
  269. {
  270. writel(v, is->regs + offset);
  271. }
  272. static inline u32 mcuctl_read(struct fimc_is *is, unsigned int offset)
  273. {
  274. return readl(is->regs + offset);
  275. }
  276. static inline void pmuisp_write(u32 v, struct fimc_is *is, unsigned int offset)
  277. {
  278. writel(v, is->pmu_regs + offset);
  279. }
  280. static inline u32 pmuisp_read(struct fimc_is *is, unsigned int offset)
  281. {
  282. return readl(is->pmu_regs + offset);
  283. }
  284. int fimc_is_wait_event(struct fimc_is *is, unsigned long bit,
  285. unsigned int state, unsigned int timeout);
  286. int fimc_is_cpu_set_power(struct fimc_is *is, int on);
  287. int fimc_is_start_firmware(struct fimc_is *is);
  288. int fimc_is_hw_initialize(struct fimc_is *is);
  289. void fimc_is_log_dump(const char *level, const void *buf, size_t len);
  290. #endif /* FIMC_IS_H_ */