isp.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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/v4l2-device.h>
  29. #include <linux/device.h>
  30. #include <linux/io.h>
  31. #include <linux/platform_device.h>
  32. #include <linux/wait.h>
  33. #include <linux/iommu.h>
  34. #include <plat/iommu.h>
  35. #include <plat/iovmm.h>
  36. #include "ispstat.h"
  37. #include "ispccdc.h"
  38. #include "ispreg.h"
  39. #include "ispresizer.h"
  40. #include "isppreview.h"
  41. #include "ispcsiphy.h"
  42. #include "ispcsi2.h"
  43. #include "ispccp2.h"
  44. #define IOMMU_FLAG (IOVMF_ENDIAN_LITTLE | IOVMF_ELSZ_8)
  45. #define ISP_TOK_TERM 0xFFFFFFFF /*
  46. * terminating token for ISP
  47. * modules reg list
  48. */
  49. #define to_isp_device(ptr_module) \
  50. container_of(ptr_module, struct isp_device, isp_##ptr_module)
  51. #define to_device(ptr_module) \
  52. (to_isp_device(ptr_module)->dev)
  53. enum isp_mem_resources {
  54. OMAP3_ISP_IOMEM_MAIN,
  55. OMAP3_ISP_IOMEM_CCP2,
  56. OMAP3_ISP_IOMEM_CCDC,
  57. OMAP3_ISP_IOMEM_HIST,
  58. OMAP3_ISP_IOMEM_H3A,
  59. OMAP3_ISP_IOMEM_PREV,
  60. OMAP3_ISP_IOMEM_RESZ,
  61. OMAP3_ISP_IOMEM_SBL,
  62. OMAP3_ISP_IOMEM_CSI2A_REGS1,
  63. OMAP3_ISP_IOMEM_CSIPHY2,
  64. OMAP3_ISP_IOMEM_CSI2A_REGS2,
  65. OMAP3_ISP_IOMEM_CSI2C_REGS1,
  66. OMAP3_ISP_IOMEM_CSIPHY1,
  67. OMAP3_ISP_IOMEM_CSI2C_REGS2,
  68. OMAP3_ISP_IOMEM_LAST
  69. };
  70. enum isp_sbl_resource {
  71. OMAP3_ISP_SBL_CSI1_READ = 0x1,
  72. OMAP3_ISP_SBL_CSI1_WRITE = 0x2,
  73. OMAP3_ISP_SBL_CSI2A_WRITE = 0x4,
  74. OMAP3_ISP_SBL_CSI2C_WRITE = 0x8,
  75. OMAP3_ISP_SBL_CCDC_LSC_READ = 0x10,
  76. OMAP3_ISP_SBL_CCDC_WRITE = 0x20,
  77. OMAP3_ISP_SBL_PREVIEW_READ = 0x40,
  78. OMAP3_ISP_SBL_PREVIEW_WRITE = 0x80,
  79. OMAP3_ISP_SBL_RESIZER_READ = 0x100,
  80. OMAP3_ISP_SBL_RESIZER_WRITE = 0x200,
  81. };
  82. enum isp_subclk_resource {
  83. OMAP3_ISP_SUBCLK_CCDC = (1 << 0),
  84. OMAP3_ISP_SUBCLK_H3A = (1 << 1),
  85. OMAP3_ISP_SUBCLK_HIST = (1 << 2),
  86. OMAP3_ISP_SUBCLK_PREVIEW = (1 << 3),
  87. OMAP3_ISP_SUBCLK_RESIZER = (1 << 4),
  88. };
  89. enum isp_interface_type {
  90. ISP_INTERFACE_PARALLEL,
  91. ISP_INTERFACE_CSI2A_PHY2,
  92. ISP_INTERFACE_CCP2B_PHY1,
  93. ISP_INTERFACE_CCP2B_PHY2,
  94. ISP_INTERFACE_CSI2C_PHY1,
  95. };
  96. /* ISP: OMAP 34xx ES 1.0 */
  97. #define ISP_REVISION_1_0 0x10
  98. /* ISP2: OMAP 34xx ES 2.0, 2.1 and 3.0 */
  99. #define ISP_REVISION_2_0 0x20
  100. /* ISP2P: OMAP 36xx */
  101. #define ISP_REVISION_15_0 0xF0
  102. /*
  103. * struct isp_res_mapping - Map ISP io resources to ISP revision.
  104. * @isp_rev: ISP_REVISION_x_x
  105. * @map: bitmap for enum isp_mem_resources
  106. */
  107. struct isp_res_mapping {
  108. u32 isp_rev;
  109. u32 map;
  110. };
  111. /*
  112. * struct isp_reg - Structure for ISP register values.
  113. * @reg: 32-bit Register address.
  114. * @val: 32-bit Register value.
  115. */
  116. struct isp_reg {
  117. enum isp_mem_resources mmio_range;
  118. u32 reg;
  119. u32 val;
  120. };
  121. /**
  122. * struct isp_parallel_platform_data - Parallel interface platform data
  123. * @data_lane_shift: Data lane shifter
  124. * 0 - CAMEXT[13:0] -> CAM[13:0]
  125. * 1 - CAMEXT[13:2] -> CAM[11:0]
  126. * 2 - CAMEXT[13:4] -> CAM[9:0]
  127. * 3 - CAMEXT[13:6] -> CAM[7:0]
  128. * @clk_pol: Pixel clock polarity
  129. * 0 - Non Inverted, 1 - Inverted
  130. * @hs_pol: Horizontal synchronization polarity
  131. * 0 - Active high, 1 - Active low
  132. * @vs_pol: Vertical synchronization polarity
  133. * 0 - Active high, 1 - Active low
  134. * @bridge: CCDC Bridge input control
  135. * ISPCTRL_PAR_BRIDGE_DISABLE - Disable
  136. * ISPCTRL_PAR_BRIDGE_LENDIAN - Little endian
  137. * ISPCTRL_PAR_BRIDGE_BENDIAN - Big endian
  138. */
  139. struct isp_parallel_platform_data {
  140. unsigned int data_lane_shift:2;
  141. unsigned int clk_pol:1;
  142. unsigned int hs_pol:1;
  143. unsigned int vs_pol:1;
  144. unsigned int bridge:4;
  145. };
  146. /**
  147. * struct isp_ccp2_platform_data - CCP2 interface platform data
  148. * @strobe_clk_pol: Strobe/clock polarity
  149. * 0 - Non Inverted, 1 - Inverted
  150. * @crc: Enable the cyclic redundancy check
  151. * @ccp2_mode: Enable CCP2 compatibility mode
  152. * 0 - MIPI-CSI1 mode, 1 - CCP2 mode
  153. * @phy_layer: Physical layer selection
  154. * ISPCCP2_CTRL_PHY_SEL_CLOCK - Data/clock physical layer
  155. * ISPCCP2_CTRL_PHY_SEL_STROBE - Data/strobe physical layer
  156. * @vpclk_div: Video port output clock control
  157. */
  158. struct isp_ccp2_platform_data {
  159. unsigned int strobe_clk_pol:1;
  160. unsigned int crc:1;
  161. unsigned int ccp2_mode:1;
  162. unsigned int phy_layer:1;
  163. unsigned int vpclk_div:2;
  164. };
  165. /**
  166. * struct isp_csi2_platform_data - CSI2 interface platform data
  167. * @crc: Enable the cyclic redundancy check
  168. * @vpclk_div: Video port output clock control
  169. */
  170. struct isp_csi2_platform_data {
  171. unsigned crc:1;
  172. unsigned vpclk_div:2;
  173. };
  174. struct isp_subdev_i2c_board_info {
  175. struct i2c_board_info *board_info;
  176. int i2c_adapter_id;
  177. };
  178. struct isp_v4l2_subdevs_group {
  179. struct isp_subdev_i2c_board_info *subdevs;
  180. enum isp_interface_type interface;
  181. union {
  182. struct isp_parallel_platform_data parallel;
  183. struct isp_ccp2_platform_data ccp2;
  184. struct isp_csi2_platform_data csi2;
  185. } bus; /* gcc < 4.6.0 chokes on anonymous union initializers */
  186. };
  187. struct isp_platform_data {
  188. struct isp_v4l2_subdevs_group *subdevs;
  189. void (*set_constraints)(struct isp_device *isp, bool enable);
  190. };
  191. struct isp_platform_callback {
  192. u32 (*set_xclk)(struct isp_device *isp, u32 xclk, u8 xclksel);
  193. int (*csiphy_config)(struct isp_csiphy *phy,
  194. struct isp_csiphy_dphy_cfg *dphy,
  195. struct isp_csiphy_lanes_cfg *lanes);
  196. void (*set_pixel_clock)(struct isp_device *isp, unsigned int pixelclk);
  197. };
  198. /*
  199. * struct isp_device - ISP device structure.
  200. * @dev: Device pointer specific to the OMAP3 ISP.
  201. * @revision: Stores current ISP module revision.
  202. * @irq_num: Currently used IRQ number.
  203. * @mmio_base: Array with kernel base addresses for ioremapped ISP register
  204. * regions.
  205. * @mmio_base_phys: Array with physical L4 bus addresses for ISP register
  206. * regions.
  207. * @mmio_size: Array with ISP register regions size in bytes.
  208. * @raw_dmamask: Raw DMA mask
  209. * @stat_lock: Spinlock for handling statistics
  210. * @isp_mutex: Mutex for serializing requests to ISP.
  211. * @has_context: Context has been saved at least once and can be restored.
  212. * @ref_count: Reference count for handling multiple ISP requests.
  213. * @cam_ick: Pointer to camera interface clock structure.
  214. * @cam_mclk: Pointer to camera functional clock structure.
  215. * @dpll4_m5_ck: Pointer to DPLL4 M5 clock structure.
  216. * @csi2_fck: Pointer to camera CSI2 complexIO clock structure.
  217. * @l3_ick: Pointer to OMAP3 L3 bus interface clock.
  218. * @irq: Currently attached ISP ISR callbacks information structure.
  219. * @isp_af: Pointer to current settings for ISP AutoFocus SCM.
  220. * @isp_hist: Pointer to current settings for ISP Histogram SCM.
  221. * @isp_h3a: Pointer to current settings for ISP Auto Exposure and
  222. * White Balance SCM.
  223. * @isp_res: Pointer to current settings for ISP Resizer.
  224. * @isp_prev: Pointer to current settings for ISP Preview.
  225. * @isp_ccdc: Pointer to current settings for ISP CCDC.
  226. * @iommu: Pointer to requested IOMMU instance for ISP.
  227. * @platform_cb: ISP driver callback function pointers for platform code
  228. *
  229. * This structure is used to store the OMAP ISP Information.
  230. */
  231. struct isp_device {
  232. struct v4l2_device v4l2_dev;
  233. struct media_device media_dev;
  234. struct device *dev;
  235. u32 revision;
  236. /* platform HW resources */
  237. struct isp_platform_data *pdata;
  238. unsigned int irq_num;
  239. void __iomem *mmio_base[OMAP3_ISP_IOMEM_LAST];
  240. unsigned long mmio_base_phys[OMAP3_ISP_IOMEM_LAST];
  241. resource_size_t mmio_size[OMAP3_ISP_IOMEM_LAST];
  242. u64 raw_dmamask;
  243. /* ISP Obj */
  244. spinlock_t stat_lock; /* common lock for statistic drivers */
  245. struct mutex isp_mutex; /* For handling ref_count field */
  246. bool needs_reset;
  247. int has_context;
  248. int ref_count;
  249. unsigned int autoidle;
  250. u32 xclk_divisor[2]; /* Two clocks, a and b. */
  251. #define ISP_CLK_CAM_ICK 0
  252. #define ISP_CLK_CAM_MCLK 1
  253. #define ISP_CLK_DPLL4_M5_CK 2
  254. #define ISP_CLK_CSI2_FCK 3
  255. #define ISP_CLK_L3_ICK 4
  256. struct clk *clock[5];
  257. /* ISP modules */
  258. struct ispstat isp_af;
  259. struct ispstat isp_aewb;
  260. struct ispstat isp_hist;
  261. struct isp_res_device isp_res;
  262. struct isp_prev_device isp_prev;
  263. struct isp_ccdc_device isp_ccdc;
  264. struct isp_csi2_device isp_csi2a;
  265. struct isp_csi2_device isp_csi2c;
  266. struct isp_ccp2_device isp_ccp2;
  267. struct isp_csiphy isp_csiphy1;
  268. struct isp_csiphy isp_csiphy2;
  269. unsigned int sbl_resources;
  270. unsigned int subclk_resources;
  271. struct omap_iommu *iommu;
  272. struct iommu_domain *domain;
  273. struct device *iommu_dev;
  274. struct isp_platform_callback platform_cb;
  275. };
  276. #define v4l2_dev_to_isp_device(dev) \
  277. container_of(dev, struct isp_device, v4l2_dev)
  278. void omap3isp_hist_dma_done(struct isp_device *isp);
  279. void omap3isp_flush(struct isp_device *isp);
  280. int omap3isp_module_sync_idle(struct media_entity *me, wait_queue_head_t *wait,
  281. atomic_t *stopping);
  282. int omap3isp_module_sync_is_stopping(wait_queue_head_t *wait,
  283. atomic_t *stopping);
  284. int omap3isp_pipeline_set_stream(struct isp_pipeline *pipe,
  285. enum isp_pipeline_stream_state state);
  286. void omap3isp_configure_bridge(struct isp_device *isp,
  287. enum ccdc_input_entity input,
  288. const struct isp_parallel_platform_data *pdata,
  289. unsigned int shift);
  290. #define ISP_XCLK_NONE 0
  291. #define ISP_XCLK_A 1
  292. #define ISP_XCLK_B 2
  293. struct isp_device *omap3isp_get(struct isp_device *isp);
  294. void omap3isp_put(struct isp_device *isp);
  295. void omap3isp_print_status(struct isp_device *isp);
  296. void omap3isp_sbl_enable(struct isp_device *isp, enum isp_sbl_resource res);
  297. void omap3isp_sbl_disable(struct isp_device *isp, enum isp_sbl_resource res);
  298. void omap3isp_subclk_enable(struct isp_device *isp,
  299. enum isp_subclk_resource res);
  300. void omap3isp_subclk_disable(struct isp_device *isp,
  301. enum isp_subclk_resource res);
  302. int omap3isp_pipeline_pm_use(struct media_entity *entity, int use);
  303. int omap3isp_register_entities(struct platform_device *pdev,
  304. struct v4l2_device *v4l2_dev);
  305. void omap3isp_unregister_entities(struct platform_device *pdev);
  306. /*
  307. * isp_reg_readl - Read value of an OMAP3 ISP register
  308. * @dev: Device pointer specific to the OMAP3 ISP.
  309. * @isp_mmio_range: Range to which the register offset refers to.
  310. * @reg_offset: Register offset to read from.
  311. *
  312. * Returns an unsigned 32 bit value with the required register contents.
  313. */
  314. static inline
  315. u32 isp_reg_readl(struct isp_device *isp, enum isp_mem_resources isp_mmio_range,
  316. u32 reg_offset)
  317. {
  318. return __raw_readl(isp->mmio_base[isp_mmio_range] + reg_offset);
  319. }
  320. /*
  321. * isp_reg_writel - Write value to an OMAP3 ISP register
  322. * @dev: Device pointer specific to the OMAP3 ISP.
  323. * @reg_value: 32 bit value to write to the register.
  324. * @isp_mmio_range: Range to which the register offset refers to.
  325. * @reg_offset: Register offset to write into.
  326. */
  327. static inline
  328. void isp_reg_writel(struct isp_device *isp, u32 reg_value,
  329. enum isp_mem_resources isp_mmio_range, u32 reg_offset)
  330. {
  331. __raw_writel(reg_value, isp->mmio_base[isp_mmio_range] + reg_offset);
  332. }
  333. /*
  334. * isp_reg_and - Clear individual bits in an OMAP3 ISP register
  335. * @dev: Device pointer specific to the OMAP3 ISP.
  336. * @mmio_range: Range to which the register offset refers to.
  337. * @reg: Register offset to work on.
  338. * @clr_bits: 32 bit value which would be cleared in the register.
  339. */
  340. static inline
  341. void isp_reg_clr(struct isp_device *isp, enum isp_mem_resources mmio_range,
  342. u32 reg, u32 clr_bits)
  343. {
  344. u32 v = isp_reg_readl(isp, mmio_range, reg);
  345. isp_reg_writel(isp, v & ~clr_bits, mmio_range, reg);
  346. }
  347. /*
  348. * isp_reg_set - Set individual bits in an OMAP3 ISP register
  349. * @dev: Device pointer specific to the OMAP3 ISP.
  350. * @mmio_range: Range to which the register offset refers to.
  351. * @reg: Register offset to work on.
  352. * @set_bits: 32 bit value which would be set in the register.
  353. */
  354. static inline
  355. void isp_reg_set(struct isp_device *isp, enum isp_mem_resources mmio_range,
  356. u32 reg, u32 set_bits)
  357. {
  358. u32 v = isp_reg_readl(isp, mmio_range, reg);
  359. isp_reg_writel(isp, v | set_bits, mmio_range, reg);
  360. }
  361. /*
  362. * isp_reg_clr_set - Clear and set invidial bits in an OMAP3 ISP register
  363. * @dev: Device pointer specific to the OMAP3 ISP.
  364. * @mmio_range: Range to which the register offset refers to.
  365. * @reg: Register offset to work on.
  366. * @clr_bits: 32 bit value which would be cleared in the register.
  367. * @set_bits: 32 bit value which would be set in the register.
  368. *
  369. * The clear operation is done first, and then the set operation.
  370. */
  371. static inline
  372. void isp_reg_clr_set(struct isp_device *isp, enum isp_mem_resources mmio_range,
  373. u32 reg, u32 clr_bits, u32 set_bits)
  374. {
  375. u32 v = isp_reg_readl(isp, mmio_range, reg);
  376. isp_reg_writel(isp, (v & ~clr_bits) | set_bits, mmio_range, reg);
  377. }
  378. static inline enum v4l2_buf_type
  379. isp_pad_buffer_type(const struct v4l2_subdev *subdev, int pad)
  380. {
  381. if (pad >= subdev->entity.num_pads)
  382. return 0;
  383. if (subdev->entity.pads[pad].flags & MEDIA_PAD_FL_SINK)
  384. return V4L2_BUF_TYPE_VIDEO_OUTPUT;
  385. else
  386. return V4L2_BUF_TYPE_VIDEO_CAPTURE;
  387. }
  388. #endif /* OMAP3_ISP_CORE_H */