isp.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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. * This program is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  24. * 02110-1301 USA
  25. */
  26. #ifndef OMAP3_ISP_CORE_H
  27. #define OMAP3_ISP_CORE_H
  28. #include <media/omap3isp.h>
  29. #include <media/v4l2-device.h>
  30. #include <linux/device.h>
  31. #include <linux/io.h>
  32. #include <linux/platform_device.h>
  33. #include <linux/wait.h>
  34. #include <linux/iommu.h>
  35. #include <plat/iommu.h>
  36. #include <plat/iovmm.h>
  37. #include "ispstat.h"
  38. #include "ispccdc.h"
  39. #include "ispreg.h"
  40. #include "ispresizer.h"
  41. #include "isppreview.h"
  42. #include "ispcsiphy.h"
  43. #include "ispcsi2.h"
  44. #include "ispccp2.h"
  45. #define IOMMU_FLAG (IOVMF_ENDIAN_LITTLE | IOVMF_ELSZ_8)
  46. #define ISP_TOK_TERM 0xFFFFFFFF /*
  47. * terminating token for ISP
  48. * modules reg list
  49. */
  50. #define to_isp_device(ptr_module) \
  51. container_of(ptr_module, struct isp_device, isp_##ptr_module)
  52. #define to_device(ptr_module) \
  53. (to_isp_device(ptr_module)->dev)
  54. enum isp_mem_resources {
  55. OMAP3_ISP_IOMEM_MAIN,
  56. OMAP3_ISP_IOMEM_CCP2,
  57. OMAP3_ISP_IOMEM_CCDC,
  58. OMAP3_ISP_IOMEM_HIST,
  59. OMAP3_ISP_IOMEM_H3A,
  60. OMAP3_ISP_IOMEM_PREV,
  61. OMAP3_ISP_IOMEM_RESZ,
  62. OMAP3_ISP_IOMEM_SBL,
  63. OMAP3_ISP_IOMEM_CSI2A_REGS1,
  64. OMAP3_ISP_IOMEM_CSIPHY2,
  65. OMAP3_ISP_IOMEM_CSI2A_REGS2,
  66. OMAP3_ISP_IOMEM_CSI2C_REGS1,
  67. OMAP3_ISP_IOMEM_CSIPHY1,
  68. OMAP3_ISP_IOMEM_CSI2C_REGS2,
  69. OMAP3_ISP_IOMEM_LAST
  70. };
  71. enum isp_sbl_resource {
  72. OMAP3_ISP_SBL_CSI1_READ = 0x1,
  73. OMAP3_ISP_SBL_CSI1_WRITE = 0x2,
  74. OMAP3_ISP_SBL_CSI2A_WRITE = 0x4,
  75. OMAP3_ISP_SBL_CSI2C_WRITE = 0x8,
  76. OMAP3_ISP_SBL_CCDC_LSC_READ = 0x10,
  77. OMAP3_ISP_SBL_CCDC_WRITE = 0x20,
  78. OMAP3_ISP_SBL_PREVIEW_READ = 0x40,
  79. OMAP3_ISP_SBL_PREVIEW_WRITE = 0x80,
  80. OMAP3_ISP_SBL_RESIZER_READ = 0x100,
  81. OMAP3_ISP_SBL_RESIZER_WRITE = 0x200,
  82. };
  83. enum isp_subclk_resource {
  84. OMAP3_ISP_SUBCLK_CCDC = (1 << 0),
  85. OMAP3_ISP_SUBCLK_H3A = (1 << 1),
  86. OMAP3_ISP_SUBCLK_HIST = (1 << 2),
  87. OMAP3_ISP_SUBCLK_PREVIEW = (1 << 3),
  88. OMAP3_ISP_SUBCLK_RESIZER = (1 << 4),
  89. };
  90. /* ISP: OMAP 34xx ES 1.0 */
  91. #define ISP_REVISION_1_0 0x10
  92. /* ISP2: OMAP 34xx ES 2.0, 2.1 and 3.0 */
  93. #define ISP_REVISION_2_0 0x20
  94. /* ISP2P: OMAP 36xx */
  95. #define ISP_REVISION_15_0 0xF0
  96. /*
  97. * struct isp_res_mapping - Map ISP io resources to ISP revision.
  98. * @isp_rev: ISP_REVISION_x_x
  99. * @map: bitmap for enum isp_mem_resources
  100. */
  101. struct isp_res_mapping {
  102. u32 isp_rev;
  103. u32 map;
  104. };
  105. /*
  106. * struct isp_reg - Structure for ISP register values.
  107. * @reg: 32-bit Register address.
  108. * @val: 32-bit Register value.
  109. */
  110. struct isp_reg {
  111. enum isp_mem_resources mmio_range;
  112. u32 reg;
  113. u32 val;
  114. };
  115. struct isp_platform_callback {
  116. u32 (*set_xclk)(struct isp_device *isp, u32 xclk, u8 xclksel);
  117. int (*csiphy_config)(struct isp_csiphy *phy,
  118. struct isp_csiphy_dphy_cfg *dphy,
  119. struct isp_csiphy_lanes_cfg *lanes);
  120. void (*set_pixel_clock)(struct isp_device *isp, unsigned int pixelclk);
  121. };
  122. /*
  123. * struct isp_device - ISP device structure.
  124. * @dev: Device pointer specific to the OMAP3 ISP.
  125. * @revision: Stores current ISP module revision.
  126. * @irq_num: Currently used IRQ number.
  127. * @mmio_base: Array with kernel base addresses for ioremapped ISP register
  128. * regions.
  129. * @mmio_base_phys: Array with physical L4 bus addresses for ISP register
  130. * regions.
  131. * @mmio_size: Array with ISP register regions size in bytes.
  132. * @raw_dmamask: Raw DMA mask
  133. * @stat_lock: Spinlock for handling statistics
  134. * @isp_mutex: Mutex for serializing requests to ISP.
  135. * @has_context: Context has been saved at least once and can be restored.
  136. * @ref_count: Reference count for handling multiple ISP requests.
  137. * @cam_ick: Pointer to camera interface clock structure.
  138. * @cam_mclk: Pointer to camera functional clock structure.
  139. * @dpll4_m5_ck: Pointer to DPLL4 M5 clock structure.
  140. * @csi2_fck: Pointer to camera CSI2 complexIO clock structure.
  141. * @l3_ick: Pointer to OMAP3 L3 bus interface clock.
  142. * @irq: Currently attached ISP ISR callbacks information structure.
  143. * @isp_af: Pointer to current settings for ISP AutoFocus SCM.
  144. * @isp_hist: Pointer to current settings for ISP Histogram SCM.
  145. * @isp_h3a: Pointer to current settings for ISP Auto Exposure and
  146. * White Balance SCM.
  147. * @isp_res: Pointer to current settings for ISP Resizer.
  148. * @isp_prev: Pointer to current settings for ISP Preview.
  149. * @isp_ccdc: Pointer to current settings for ISP CCDC.
  150. * @iommu: Pointer to requested IOMMU instance for ISP.
  151. * @platform_cb: ISP driver callback function pointers for platform code
  152. *
  153. * This structure is used to store the OMAP ISP Information.
  154. */
  155. struct isp_device {
  156. struct v4l2_device v4l2_dev;
  157. struct media_device media_dev;
  158. struct device *dev;
  159. u32 revision;
  160. /* platform HW resources */
  161. struct isp_platform_data *pdata;
  162. unsigned int irq_num;
  163. void __iomem *mmio_base[OMAP3_ISP_IOMEM_LAST];
  164. unsigned long mmio_base_phys[OMAP3_ISP_IOMEM_LAST];
  165. resource_size_t mmio_size[OMAP3_ISP_IOMEM_LAST];
  166. u64 raw_dmamask;
  167. /* ISP Obj */
  168. spinlock_t stat_lock; /* common lock for statistic drivers */
  169. struct mutex isp_mutex; /* For handling ref_count field */
  170. bool needs_reset;
  171. int has_context;
  172. int ref_count;
  173. unsigned int autoidle;
  174. u32 xclk_divisor[2]; /* Two clocks, a and b. */
  175. #define ISP_CLK_CAM_ICK 0
  176. #define ISP_CLK_CAM_MCLK 1
  177. #define ISP_CLK_DPLL4_M5_CK 2
  178. #define ISP_CLK_CSI2_FCK 3
  179. #define ISP_CLK_L3_ICK 4
  180. struct clk *clock[5];
  181. /* ISP modules */
  182. struct ispstat isp_af;
  183. struct ispstat isp_aewb;
  184. struct ispstat isp_hist;
  185. struct isp_res_device isp_res;
  186. struct isp_prev_device isp_prev;
  187. struct isp_ccdc_device isp_ccdc;
  188. struct isp_csi2_device isp_csi2a;
  189. struct isp_csi2_device isp_csi2c;
  190. struct isp_ccp2_device isp_ccp2;
  191. struct isp_csiphy isp_csiphy1;
  192. struct isp_csiphy isp_csiphy2;
  193. unsigned int sbl_resources;
  194. unsigned int subclk_resources;
  195. struct iommu_domain *domain;
  196. struct isp_platform_callback platform_cb;
  197. };
  198. #define v4l2_dev_to_isp_device(dev) \
  199. container_of(dev, struct isp_device, v4l2_dev)
  200. void omap3isp_hist_dma_done(struct isp_device *isp);
  201. void omap3isp_flush(struct isp_device *isp);
  202. int omap3isp_module_sync_idle(struct media_entity *me, wait_queue_head_t *wait,
  203. atomic_t *stopping);
  204. int omap3isp_module_sync_is_stopping(wait_queue_head_t *wait,
  205. atomic_t *stopping);
  206. int omap3isp_pipeline_set_stream(struct isp_pipeline *pipe,
  207. enum isp_pipeline_stream_state state);
  208. void omap3isp_configure_bridge(struct isp_device *isp,
  209. enum ccdc_input_entity input,
  210. const struct isp_parallel_platform_data *pdata,
  211. unsigned int shift);
  212. #define ISP_XCLK_NONE 0
  213. #define ISP_XCLK_A 1
  214. #define ISP_XCLK_B 2
  215. struct isp_device *omap3isp_get(struct isp_device *isp);
  216. void omap3isp_put(struct isp_device *isp);
  217. void omap3isp_print_status(struct isp_device *isp);
  218. void omap3isp_sbl_enable(struct isp_device *isp, enum isp_sbl_resource res);
  219. void omap3isp_sbl_disable(struct isp_device *isp, enum isp_sbl_resource res);
  220. void omap3isp_subclk_enable(struct isp_device *isp,
  221. enum isp_subclk_resource res);
  222. void omap3isp_subclk_disable(struct isp_device *isp,
  223. enum isp_subclk_resource res);
  224. int omap3isp_pipeline_pm_use(struct media_entity *entity, int use);
  225. int omap3isp_register_entities(struct platform_device *pdev,
  226. struct v4l2_device *v4l2_dev);
  227. void omap3isp_unregister_entities(struct platform_device *pdev);
  228. /*
  229. * isp_reg_readl - Read value of an OMAP3 ISP register
  230. * @dev: Device pointer specific to the OMAP3 ISP.
  231. * @isp_mmio_range: Range to which the register offset refers to.
  232. * @reg_offset: Register offset to read from.
  233. *
  234. * Returns an unsigned 32 bit value with the required register contents.
  235. */
  236. static inline
  237. u32 isp_reg_readl(struct isp_device *isp, enum isp_mem_resources isp_mmio_range,
  238. u32 reg_offset)
  239. {
  240. return __raw_readl(isp->mmio_base[isp_mmio_range] + reg_offset);
  241. }
  242. /*
  243. * isp_reg_writel - Write value to an OMAP3 ISP register
  244. * @dev: Device pointer specific to the OMAP3 ISP.
  245. * @reg_value: 32 bit value to write to the register.
  246. * @isp_mmio_range: Range to which the register offset refers to.
  247. * @reg_offset: Register offset to write into.
  248. */
  249. static inline
  250. void isp_reg_writel(struct isp_device *isp, u32 reg_value,
  251. enum isp_mem_resources isp_mmio_range, u32 reg_offset)
  252. {
  253. __raw_writel(reg_value, isp->mmio_base[isp_mmio_range] + reg_offset);
  254. }
  255. /*
  256. * isp_reg_and - Clear individual bits in an OMAP3 ISP register
  257. * @dev: Device pointer specific to the OMAP3 ISP.
  258. * @mmio_range: Range to which the register offset refers to.
  259. * @reg: Register offset to work on.
  260. * @clr_bits: 32 bit value which would be cleared in the register.
  261. */
  262. static inline
  263. void isp_reg_clr(struct isp_device *isp, enum isp_mem_resources mmio_range,
  264. u32 reg, u32 clr_bits)
  265. {
  266. u32 v = isp_reg_readl(isp, mmio_range, reg);
  267. isp_reg_writel(isp, v & ~clr_bits, mmio_range, reg);
  268. }
  269. /*
  270. * isp_reg_set - Set individual bits in an OMAP3 ISP register
  271. * @dev: 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. * @set_bits: 32 bit value which would be set in the register.
  275. */
  276. static inline
  277. void isp_reg_set(struct isp_device *isp, enum isp_mem_resources mmio_range,
  278. u32 reg, u32 set_bits)
  279. {
  280. u32 v = isp_reg_readl(isp, mmio_range, reg);
  281. isp_reg_writel(isp, v | set_bits, mmio_range, reg);
  282. }
  283. /*
  284. * isp_reg_clr_set - Clear and set invidial bits in an OMAP3 ISP register
  285. * @dev: 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. * @clr_bits: 32 bit value which would be cleared in the register.
  289. * @set_bits: 32 bit value which would be set in the register.
  290. *
  291. * The clear operation is done first, and then the set operation.
  292. */
  293. static inline
  294. void isp_reg_clr_set(struct isp_device *isp, enum isp_mem_resources mmio_range,
  295. u32 reg, u32 clr_bits, u32 set_bits)
  296. {
  297. u32 v = isp_reg_readl(isp, mmio_range, reg);
  298. isp_reg_writel(isp, (v & ~clr_bits) | set_bits, mmio_range, reg);
  299. }
  300. static inline enum v4l2_buf_type
  301. isp_pad_buffer_type(const struct v4l2_subdev *subdev, int pad)
  302. {
  303. if (pad >= subdev->entity.num_pads)
  304. return 0;
  305. if (subdev->entity.pads[pad].flags & MEDIA_PAD_FL_SINK)
  306. return V4L2_BUF_TYPE_VIDEO_OUTPUT;
  307. else
  308. return V4L2_BUF_TYPE_VIDEO_CAPTURE;
  309. }
  310. #endif /* OMAP3_ISP_CORE_H */