isp.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. /*
  2. * isp.h
  3. *
  4. * TI OMAP3 ISP - Core
  5. *
  6. * Copyright (C) 2009-2010 Nokia Corporation
  7. * Copyright (C) 2009 Texas Instruments, Inc.
  8. *
  9. * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
  10. * Sakari Ailus <sakari.ailus@iki.fi>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2 as
  14. * published by the Free Software Foundation.
  15. */
  16. #ifndef OMAP3_ISP_CORE_H
  17. #define OMAP3_ISP_CORE_H
  18. #include <media/omap3isp.h>
  19. #include <media/v4l2-async.h>
  20. #include <media/v4l2-device.h>
  21. #include <linux/clk-provider.h>
  22. #include <linux/device.h>
  23. #include <linux/io.h>
  24. #include <linux/iommu.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/wait.h>
  27. #include "ispstat.h"
  28. #include "ispccdc.h"
  29. #include "ispreg.h"
  30. #include "ispresizer.h"
  31. #include "isppreview.h"
  32. #include "ispcsiphy.h"
  33. #include "ispcsi2.h"
  34. #include "ispccp2.h"
  35. #define ISP_TOK_TERM 0xFFFFFFFF /*
  36. * terminating token for ISP
  37. * modules reg list
  38. */
  39. #define to_isp_device(ptr_module) \
  40. container_of(ptr_module, struct isp_device, isp_##ptr_module)
  41. #define to_device(ptr_module) \
  42. (to_isp_device(ptr_module)->dev)
  43. enum isp_mem_resources {
  44. OMAP3_ISP_IOMEM_MAIN,
  45. OMAP3_ISP_IOMEM_CCP2,
  46. OMAP3_ISP_IOMEM_CCDC,
  47. OMAP3_ISP_IOMEM_HIST,
  48. OMAP3_ISP_IOMEM_H3A,
  49. OMAP3_ISP_IOMEM_PREV,
  50. OMAP3_ISP_IOMEM_RESZ,
  51. OMAP3_ISP_IOMEM_SBL,
  52. OMAP3_ISP_IOMEM_CSI2A_REGS1,
  53. OMAP3_ISP_IOMEM_CSIPHY2,
  54. OMAP3_ISP_IOMEM_CSI2A_REGS2,
  55. OMAP3_ISP_IOMEM_CSI2C_REGS1,
  56. OMAP3_ISP_IOMEM_CSIPHY1,
  57. OMAP3_ISP_IOMEM_CSI2C_REGS2,
  58. OMAP3_ISP_IOMEM_LAST
  59. };
  60. enum isp_sbl_resource {
  61. OMAP3_ISP_SBL_CSI1_READ = 0x1,
  62. OMAP3_ISP_SBL_CSI1_WRITE = 0x2,
  63. OMAP3_ISP_SBL_CSI2A_WRITE = 0x4,
  64. OMAP3_ISP_SBL_CSI2C_WRITE = 0x8,
  65. OMAP3_ISP_SBL_CCDC_LSC_READ = 0x10,
  66. OMAP3_ISP_SBL_CCDC_WRITE = 0x20,
  67. OMAP3_ISP_SBL_PREVIEW_READ = 0x40,
  68. OMAP3_ISP_SBL_PREVIEW_WRITE = 0x80,
  69. OMAP3_ISP_SBL_RESIZER_READ = 0x100,
  70. OMAP3_ISP_SBL_RESIZER_WRITE = 0x200,
  71. };
  72. enum isp_subclk_resource {
  73. OMAP3_ISP_SUBCLK_CCDC = (1 << 0),
  74. OMAP3_ISP_SUBCLK_AEWB = (1 << 1),
  75. OMAP3_ISP_SUBCLK_AF = (1 << 2),
  76. OMAP3_ISP_SUBCLK_HIST = (1 << 3),
  77. OMAP3_ISP_SUBCLK_PREVIEW = (1 << 4),
  78. OMAP3_ISP_SUBCLK_RESIZER = (1 << 5),
  79. };
  80. /* ISP: OMAP 34xx ES 1.0 */
  81. #define ISP_REVISION_1_0 0x10
  82. /* ISP2: OMAP 34xx ES 2.0, 2.1 and 3.0 */
  83. #define ISP_REVISION_2_0 0x20
  84. /* ISP2P: OMAP 36xx */
  85. #define ISP_REVISION_15_0 0xF0
  86. #define ISP_PHY_TYPE_3430 0
  87. #define ISP_PHY_TYPE_3630 1
  88. struct regmap;
  89. /*
  90. * struct isp_res_mapping - Map ISP io resources to ISP revision.
  91. * @isp_rev: ISP_REVISION_x_x
  92. * @offset: register offsets of various ISP sub-blocks
  93. * @syscon_offset: offset of the syscon register for 343x / 3630
  94. * (CONTROL_CSIRXFE / CONTROL_CAMERA_PHY_CTRL, respectively)
  95. * from the syscon base address
  96. * @phy_type: ISP_PHY_TYPE_{3430,3630}
  97. */
  98. struct isp_res_mapping {
  99. u32 isp_rev;
  100. u32 offset[OMAP3_ISP_IOMEM_LAST];
  101. u32 syscon_offset;
  102. u32 phy_type;
  103. };
  104. /*
  105. * struct isp_reg - Structure for ISP register values.
  106. * @reg: 32-bit Register address.
  107. * @val: 32-bit Register value.
  108. */
  109. struct isp_reg {
  110. enum isp_mem_resources mmio_range;
  111. u32 reg;
  112. u32 val;
  113. };
  114. enum isp_xclk_id {
  115. ISP_XCLK_A,
  116. ISP_XCLK_B,
  117. };
  118. struct isp_xclk {
  119. struct isp_device *isp;
  120. struct clk_hw hw;
  121. struct clk *clk;
  122. enum isp_xclk_id id;
  123. spinlock_t lock; /* Protects enabled and divider */
  124. bool enabled;
  125. unsigned int divider;
  126. };
  127. /*
  128. * struct isp_device - ISP device structure.
  129. * @dev: Device pointer specific to the OMAP3 ISP.
  130. * @revision: Stores current ISP module revision.
  131. * @irq_num: Currently used IRQ number.
  132. * @mmio_base: Array with kernel base addresses for ioremapped ISP register
  133. * regions.
  134. * @mmio_hist_base_phys: Physical L4 bus address for ISP hist block register
  135. * region.
  136. * @syscon: Regmap for the syscon register space
  137. * @syscon_offset: Offset of the CSIPHY control register in syscon
  138. * @phy_type: ISP_PHY_TYPE_{3430,3630}
  139. * @mapping: IOMMU mapping
  140. * @stat_lock: Spinlock for handling statistics
  141. * @isp_mutex: Mutex for serializing requests to ISP.
  142. * @stop_failure: Indicates that an entity failed to stop.
  143. * @crashed: Bitmask of crashed entities (indexed by entity ID)
  144. * @has_context: Context has been saved at least once and can be restored.
  145. * @ref_count: Reference count for handling multiple ISP requests.
  146. * @cam_ick: Pointer to camera interface clock structure.
  147. * @cam_mclk: Pointer to camera functional clock structure.
  148. * @csi2_fck: Pointer to camera CSI2 complexIO clock structure.
  149. * @l3_ick: Pointer to OMAP3 L3 bus interface clock.
  150. * @xclks: External clocks provided by the ISP
  151. * @irq: Currently attached ISP ISR callbacks information structure.
  152. * @isp_af: Pointer to current settings for ISP AutoFocus SCM.
  153. * @isp_hist: Pointer to current settings for ISP Histogram SCM.
  154. * @isp_h3a: Pointer to current settings for ISP Auto Exposure and
  155. * White Balance SCM.
  156. * @isp_res: Pointer to current settings for ISP Resizer.
  157. * @isp_prev: Pointer to current settings for ISP Preview.
  158. * @isp_ccdc: Pointer to current settings for ISP CCDC.
  159. * @platform_cb: ISP driver callback function pointers for platform code
  160. *
  161. * This structure is used to store the OMAP ISP Information.
  162. */
  163. struct isp_device {
  164. struct v4l2_device v4l2_dev;
  165. struct v4l2_async_notifier notifier;
  166. struct media_device media_dev;
  167. struct device *dev;
  168. u32 revision;
  169. /* platform HW resources */
  170. struct isp_platform_data *pdata;
  171. unsigned int irq_num;
  172. void __iomem *mmio_base[OMAP3_ISP_IOMEM_LAST];
  173. unsigned long mmio_hist_base_phys;
  174. struct regmap *syscon;
  175. u32 syscon_offset;
  176. u32 phy_type;
  177. struct dma_iommu_mapping *mapping;
  178. /* ISP Obj */
  179. spinlock_t stat_lock; /* common lock for statistic drivers */
  180. struct mutex isp_mutex; /* For handling ref_count field */
  181. bool stop_failure;
  182. u32 crashed;
  183. int has_context;
  184. int ref_count;
  185. unsigned int autoidle;
  186. #define ISP_CLK_CAM_ICK 0
  187. #define ISP_CLK_CAM_MCLK 1
  188. #define ISP_CLK_CSI2_FCK 2
  189. #define ISP_CLK_L3_ICK 3
  190. struct clk *clock[4];
  191. struct isp_xclk xclks[2];
  192. /* ISP modules */
  193. struct ispstat isp_af;
  194. struct ispstat isp_aewb;
  195. struct ispstat isp_hist;
  196. struct isp_res_device isp_res;
  197. struct isp_prev_device isp_prev;
  198. struct isp_ccdc_device isp_ccdc;
  199. struct isp_csi2_device isp_csi2a;
  200. struct isp_csi2_device isp_csi2c;
  201. struct isp_ccp2_device isp_ccp2;
  202. struct isp_csiphy isp_csiphy1;
  203. struct isp_csiphy isp_csiphy2;
  204. unsigned int sbl_resources;
  205. unsigned int subclk_resources;
  206. #define ISP_MAX_SUBDEVS 8
  207. struct v4l2_subdev *subdevs[ISP_MAX_SUBDEVS];
  208. };
  209. struct isp_async_subdev {
  210. struct v4l2_subdev *sd;
  211. struct isp_bus_cfg bus;
  212. struct v4l2_async_subdev asd;
  213. };
  214. #define v4l2_dev_to_isp_device(dev) \
  215. container_of(dev, struct isp_device, v4l2_dev)
  216. void omap3isp_hist_dma_done(struct isp_device *isp);
  217. void omap3isp_flush(struct isp_device *isp);
  218. int omap3isp_module_sync_idle(struct media_entity *me, wait_queue_head_t *wait,
  219. atomic_t *stopping);
  220. int omap3isp_module_sync_is_stopping(wait_queue_head_t *wait,
  221. atomic_t *stopping);
  222. int omap3isp_pipeline_set_stream(struct isp_pipeline *pipe,
  223. enum isp_pipeline_stream_state state);
  224. void omap3isp_pipeline_cancel_stream(struct isp_pipeline *pipe);
  225. void omap3isp_configure_bridge(struct isp_device *isp,
  226. enum ccdc_input_entity input,
  227. const struct isp_parallel_cfg *buscfg,
  228. unsigned int shift, unsigned int bridge);
  229. struct isp_device *omap3isp_get(struct isp_device *isp);
  230. void omap3isp_put(struct isp_device *isp);
  231. void omap3isp_print_status(struct isp_device *isp);
  232. void omap3isp_sbl_enable(struct isp_device *isp, enum isp_sbl_resource res);
  233. void omap3isp_sbl_disable(struct isp_device *isp, enum isp_sbl_resource res);
  234. void omap3isp_subclk_enable(struct isp_device *isp,
  235. enum isp_subclk_resource res);
  236. void omap3isp_subclk_disable(struct isp_device *isp,
  237. enum isp_subclk_resource res);
  238. int omap3isp_pipeline_pm_use(struct media_entity *entity, int use);
  239. int omap3isp_register_entities(struct platform_device *pdev,
  240. struct v4l2_device *v4l2_dev);
  241. void omap3isp_unregister_entities(struct platform_device *pdev);
  242. /*
  243. * isp_reg_readl - Read value of an OMAP3 ISP register
  244. * @isp: Device pointer specific to the OMAP3 ISP.
  245. * @isp_mmio_range: Range to which the register offset refers to.
  246. * @reg_offset: Register offset to read from.
  247. *
  248. * Returns an unsigned 32 bit value with the required register contents.
  249. */
  250. static inline
  251. u32 isp_reg_readl(struct isp_device *isp, enum isp_mem_resources isp_mmio_range,
  252. u32 reg_offset)
  253. {
  254. return __raw_readl(isp->mmio_base[isp_mmio_range] + reg_offset);
  255. }
  256. /*
  257. * isp_reg_writel - Write value to an OMAP3 ISP register
  258. * @isp: Device pointer specific to the OMAP3 ISP.
  259. * @reg_value: 32 bit value to write to the register.
  260. * @isp_mmio_range: Range to which the register offset refers to.
  261. * @reg_offset: Register offset to write into.
  262. */
  263. static inline
  264. void isp_reg_writel(struct isp_device *isp, u32 reg_value,
  265. enum isp_mem_resources isp_mmio_range, u32 reg_offset)
  266. {
  267. __raw_writel(reg_value, isp->mmio_base[isp_mmio_range] + reg_offset);
  268. }
  269. /*
  270. * isp_reg_clr - Clear individual bits in an OMAP3 ISP register
  271. * @isp: Device pointer specific to the OMAP3 ISP.
  272. * @mmio_range: Range to which the register offset refers to.
  273. * @reg: Register offset to work on.
  274. * @clr_bits: 32 bit value which would be cleared in the register.
  275. */
  276. static inline
  277. void isp_reg_clr(struct isp_device *isp, enum isp_mem_resources mmio_range,
  278. u32 reg, u32 clr_bits)
  279. {
  280. u32 v = isp_reg_readl(isp, mmio_range, reg);
  281. isp_reg_writel(isp, v & ~clr_bits, mmio_range, reg);
  282. }
  283. /*
  284. * isp_reg_set - Set individual bits in an OMAP3 ISP register
  285. * @isp: Device pointer specific to the OMAP3 ISP.
  286. * @mmio_range: Range to which the register offset refers to.
  287. * @reg: Register offset to work on.
  288. * @set_bits: 32 bit value which would be set in the register.
  289. */
  290. static inline
  291. void isp_reg_set(struct isp_device *isp, enum isp_mem_resources mmio_range,
  292. u32 reg, u32 set_bits)
  293. {
  294. u32 v = isp_reg_readl(isp, mmio_range, reg);
  295. isp_reg_writel(isp, v | set_bits, mmio_range, reg);
  296. }
  297. /*
  298. * isp_reg_clr_set - Clear and set invidial bits in an OMAP3 ISP register
  299. * @isp: Device pointer specific to the OMAP3 ISP.
  300. * @mmio_range: Range to which the register offset refers to.
  301. * @reg: Register offset to work on.
  302. * @clr_bits: 32 bit value which would be cleared in the register.
  303. * @set_bits: 32 bit value which would be set in the register.
  304. *
  305. * The clear operation is done first, and then the set operation.
  306. */
  307. static inline
  308. void isp_reg_clr_set(struct isp_device *isp, enum isp_mem_resources mmio_range,
  309. u32 reg, u32 clr_bits, u32 set_bits)
  310. {
  311. u32 v = isp_reg_readl(isp, mmio_range, reg);
  312. isp_reg_writel(isp, (v & ~clr_bits) | set_bits, mmio_range, reg);
  313. }
  314. static inline enum v4l2_buf_type
  315. isp_pad_buffer_type(const struct v4l2_subdev *subdev, int pad)
  316. {
  317. if (pad >= subdev->entity.num_pads)
  318. return 0;
  319. if (subdev->entity.pads[pad].flags & MEDIA_PAD_FL_SINK)
  320. return V4L2_BUF_TYPE_VIDEO_OUTPUT;
  321. else
  322. return V4L2_BUF_TYPE_VIDEO_CAPTURE;
  323. }
  324. #endif /* OMAP3_ISP_CORE_H */