isp.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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/v4l2-async.h>
  19. #include <media/v4l2-device.h>
  20. #include <linux/clk-provider.h>
  21. #include <linux/device.h>
  22. #include <linux/io.h>
  23. #include <linux/iommu.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/wait.h>
  26. #include "omap3isp.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. * @phy_type: ISP_PHY_TYPE_{3430,3630}
  94. */
  95. struct isp_res_mapping {
  96. u32 isp_rev;
  97. u32 offset[OMAP3_ISP_IOMEM_LAST];
  98. u32 phy_type;
  99. };
  100. /*
  101. * struct isp_reg - Structure for ISP register values.
  102. * @reg: 32-bit Register address.
  103. * @val: 32-bit Register value.
  104. */
  105. struct isp_reg {
  106. enum isp_mem_resources mmio_range;
  107. u32 reg;
  108. u32 val;
  109. };
  110. enum isp_xclk_id {
  111. ISP_XCLK_A,
  112. ISP_XCLK_B,
  113. };
  114. struct isp_xclk {
  115. struct isp_device *isp;
  116. struct clk_hw hw;
  117. struct clk *clk;
  118. enum isp_xclk_id id;
  119. spinlock_t lock; /* Protects enabled and divider */
  120. bool enabled;
  121. unsigned int divider;
  122. };
  123. /*
  124. * struct isp_device - ISP device structure.
  125. * @dev: Device pointer specific to the OMAP3 ISP.
  126. * @revision: Stores current ISP module revision.
  127. * @irq_num: Currently used IRQ number.
  128. * @mmio_base: Array with kernel base addresses for ioremapped ISP register
  129. * regions.
  130. * @mmio_hist_base_phys: Physical L4 bus address for ISP hist block register
  131. * region.
  132. * @syscon: Regmap for the syscon register space
  133. * @syscon_offset: Offset of the CSIPHY control register in syscon
  134. * @phy_type: ISP_PHY_TYPE_{3430,3630}
  135. * @mapping: IOMMU mapping
  136. * @stat_lock: Spinlock for handling statistics
  137. * @isp_mutex: Mutex for serializing requests to ISP.
  138. * @stop_failure: Indicates that an entity failed to stop.
  139. * @crashed: Bitmask of crashed entities (indexed by entity ID)
  140. * @has_context: Context has been saved at least once and can be restored.
  141. * @ref_count: Reference count for handling multiple ISP requests.
  142. * @cam_ick: Pointer to camera interface clock structure.
  143. * @cam_mclk: Pointer to camera functional clock structure.
  144. * @csi2_fck: Pointer to camera CSI2 complexIO clock structure.
  145. * @l3_ick: Pointer to OMAP3 L3 bus interface clock.
  146. * @xclks: External clocks provided by the ISP
  147. * @irq: Currently attached ISP ISR callbacks information structure.
  148. * @isp_af: Pointer to current settings for ISP AutoFocus SCM.
  149. * @isp_hist: Pointer to current settings for ISP Histogram SCM.
  150. * @isp_h3a: Pointer to current settings for ISP Auto Exposure and
  151. * White Balance SCM.
  152. * @isp_res: Pointer to current settings for ISP Resizer.
  153. * @isp_prev: Pointer to current settings for ISP Preview.
  154. * @isp_ccdc: Pointer to current settings for ISP CCDC.
  155. * @platform_cb: ISP driver callback function pointers for platform code
  156. *
  157. * This structure is used to store the OMAP ISP Information.
  158. */
  159. struct isp_device {
  160. struct v4l2_device v4l2_dev;
  161. struct v4l2_async_notifier notifier;
  162. struct media_device media_dev;
  163. struct device *dev;
  164. u32 revision;
  165. /* platform HW resources */
  166. unsigned int irq_num;
  167. void __iomem *mmio_base[OMAP3_ISP_IOMEM_LAST];
  168. unsigned long mmio_hist_base_phys;
  169. struct regmap *syscon;
  170. u32 syscon_offset;
  171. u32 phy_type;
  172. struct dma_iommu_mapping *mapping;
  173. /* ISP Obj */
  174. spinlock_t stat_lock; /* common lock for statistic drivers */
  175. struct mutex isp_mutex; /* For handling ref_count field */
  176. bool stop_failure;
  177. u32 crashed;
  178. int has_context;
  179. int ref_count;
  180. unsigned int autoidle;
  181. #define ISP_CLK_CAM_ICK 0
  182. #define ISP_CLK_CAM_MCLK 1
  183. #define ISP_CLK_CSI2_FCK 2
  184. #define ISP_CLK_L3_ICK 3
  185. struct clk *clock[4];
  186. struct isp_xclk xclks[2];
  187. /* ISP modules */
  188. struct ispstat isp_af;
  189. struct ispstat isp_aewb;
  190. struct ispstat isp_hist;
  191. struct isp_res_device isp_res;
  192. struct isp_prev_device isp_prev;
  193. struct isp_ccdc_device isp_ccdc;
  194. struct isp_csi2_device isp_csi2a;
  195. struct isp_csi2_device isp_csi2c;
  196. struct isp_ccp2_device isp_ccp2;
  197. struct isp_csiphy isp_csiphy1;
  198. struct isp_csiphy isp_csiphy2;
  199. unsigned int sbl_resources;
  200. unsigned int subclk_resources;
  201. #define ISP_MAX_SUBDEVS 8
  202. struct v4l2_subdev *subdevs[ISP_MAX_SUBDEVS];
  203. };
  204. struct isp_async_subdev {
  205. struct v4l2_subdev *sd;
  206. struct isp_bus_cfg bus;
  207. struct v4l2_async_subdev asd;
  208. };
  209. #define v4l2_dev_to_isp_device(dev) \
  210. container_of(dev, struct isp_device, v4l2_dev)
  211. void omap3isp_hist_dma_done(struct isp_device *isp);
  212. void omap3isp_flush(struct isp_device *isp);
  213. int omap3isp_module_sync_idle(struct media_entity *me, wait_queue_head_t *wait,
  214. atomic_t *stopping);
  215. int omap3isp_module_sync_is_stopping(wait_queue_head_t *wait,
  216. atomic_t *stopping);
  217. int omap3isp_pipeline_set_stream(struct isp_pipeline *pipe,
  218. enum isp_pipeline_stream_state state);
  219. void omap3isp_pipeline_cancel_stream(struct isp_pipeline *pipe);
  220. void omap3isp_configure_bridge(struct isp_device *isp,
  221. enum ccdc_input_entity input,
  222. const struct isp_parallel_cfg *buscfg,
  223. unsigned int shift, unsigned int bridge);
  224. struct isp_device *omap3isp_get(struct isp_device *isp);
  225. void omap3isp_put(struct isp_device *isp);
  226. void omap3isp_print_status(struct isp_device *isp);
  227. void omap3isp_sbl_enable(struct isp_device *isp, enum isp_sbl_resource res);
  228. void omap3isp_sbl_disable(struct isp_device *isp, enum isp_sbl_resource res);
  229. void omap3isp_subclk_enable(struct isp_device *isp,
  230. enum isp_subclk_resource res);
  231. void omap3isp_subclk_disable(struct isp_device *isp,
  232. enum isp_subclk_resource res);
  233. int omap3isp_pipeline_pm_use(struct media_entity *entity, int use);
  234. int omap3isp_register_entities(struct platform_device *pdev,
  235. struct v4l2_device *v4l2_dev);
  236. void omap3isp_unregister_entities(struct platform_device *pdev);
  237. /*
  238. * isp_reg_readl - Read value of an OMAP3 ISP register
  239. * @isp: Device pointer specific to the OMAP3 ISP.
  240. * @isp_mmio_range: Range to which the register offset refers to.
  241. * @reg_offset: Register offset to read from.
  242. *
  243. * Returns an unsigned 32 bit value with the required register contents.
  244. */
  245. static inline
  246. u32 isp_reg_readl(struct isp_device *isp, enum isp_mem_resources isp_mmio_range,
  247. u32 reg_offset)
  248. {
  249. return __raw_readl(isp->mmio_base[isp_mmio_range] + reg_offset);
  250. }
  251. /*
  252. * isp_reg_writel - Write value to an OMAP3 ISP register
  253. * @isp: Device pointer specific to the OMAP3 ISP.
  254. * @reg_value: 32 bit value to write to the register.
  255. * @isp_mmio_range: Range to which the register offset refers to.
  256. * @reg_offset: Register offset to write into.
  257. */
  258. static inline
  259. void isp_reg_writel(struct isp_device *isp, u32 reg_value,
  260. enum isp_mem_resources isp_mmio_range, u32 reg_offset)
  261. {
  262. __raw_writel(reg_value, isp->mmio_base[isp_mmio_range] + reg_offset);
  263. }
  264. /*
  265. * isp_reg_clr - Clear individual bits in an OMAP3 ISP register
  266. * @isp: Device pointer specific to the OMAP3 ISP.
  267. * @mmio_range: Range to which the register offset refers to.
  268. * @reg: Register offset to work on.
  269. * @clr_bits: 32 bit value which would be cleared in the register.
  270. */
  271. static inline
  272. void isp_reg_clr(struct isp_device *isp, enum isp_mem_resources mmio_range,
  273. u32 reg, u32 clr_bits)
  274. {
  275. u32 v = isp_reg_readl(isp, mmio_range, reg);
  276. isp_reg_writel(isp, v & ~clr_bits, mmio_range, reg);
  277. }
  278. /*
  279. * isp_reg_set - Set individual bits in an OMAP3 ISP register
  280. * @isp: Device pointer specific to the OMAP3 ISP.
  281. * @mmio_range: Range to which the register offset refers to.
  282. * @reg: Register offset to work on.
  283. * @set_bits: 32 bit value which would be set in the register.
  284. */
  285. static inline
  286. void isp_reg_set(struct isp_device *isp, enum isp_mem_resources mmio_range,
  287. u32 reg, u32 set_bits)
  288. {
  289. u32 v = isp_reg_readl(isp, mmio_range, reg);
  290. isp_reg_writel(isp, v | set_bits, mmio_range, reg);
  291. }
  292. /*
  293. * isp_reg_clr_set - Clear and set invidial bits in an OMAP3 ISP register
  294. * @isp: Device pointer specific to the OMAP3 ISP.
  295. * @mmio_range: Range to which the register offset refers to.
  296. * @reg: Register offset to work on.
  297. * @clr_bits: 32 bit value which would be cleared in the register.
  298. * @set_bits: 32 bit value which would be set in the register.
  299. *
  300. * The clear operation is done first, and then the set operation.
  301. */
  302. static inline
  303. void isp_reg_clr_set(struct isp_device *isp, enum isp_mem_resources mmio_range,
  304. u32 reg, u32 clr_bits, u32 set_bits)
  305. {
  306. u32 v = isp_reg_readl(isp, mmio_range, reg);
  307. isp_reg_writel(isp, (v & ~clr_bits) | set_bits, mmio_range, reg);
  308. }
  309. static inline enum v4l2_buf_type
  310. isp_pad_buffer_type(const struct v4l2_subdev *subdev, int pad)
  311. {
  312. if (pad >= subdev->entity.num_pads)
  313. return 0;
  314. if (subdev->entity.pads[pad].flags & MEDIA_PAD_FL_SINK)
  315. return V4L2_BUF_TYPE_VIDEO_OUTPUT;
  316. else
  317. return V4L2_BUF_TYPE_VIDEO_CAPTURE;
  318. }
  319. #endif /* OMAP3_ISP_CORE_H */