ispccp2.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167
  1. /*
  2. * ispccp2.c
  3. *
  4. * TI OMAP3 ISP - CCP2 module
  5. *
  6. * Copyright (C) 2010 Nokia Corporation
  7. * Copyright (C) 2010 Texas Instruments, Inc.
  8. *
  9. * Contacts: Laurent Pinchart <[email protected]>
  10. * Sakari Ailus <[email protected]>
  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. #include <linux/delay.h>
  17. #include <linux/device.h>
  18. #include <linux/mm.h>
  19. #include <linux/module.h>
  20. #include <linux/mutex.h>
  21. #include <linux/uaccess.h>
  22. #include <linux/regulator/consumer.h>
  23. #include "isp.h"
  24. #include "ispreg.h"
  25. #include "ispccp2.h"
  26. /* Number of LCX channels */
  27. #define CCP2_LCx_CHANS_NUM 3
  28. /* Max/Min size for CCP2 video port */
  29. #define ISPCCP2_DAT_START_MIN 0
  30. #define ISPCCP2_DAT_START_MAX 4095
  31. #define ISPCCP2_DAT_SIZE_MIN 0
  32. #define ISPCCP2_DAT_SIZE_MAX 4095
  33. #define ISPCCP2_VPCLK_FRACDIV 65536
  34. #define ISPCCP2_LCx_CTRL_FORMAT_RAW8_DPCM10_VP 0x12
  35. #define ISPCCP2_LCx_CTRL_FORMAT_RAW10_VP 0x16
  36. /* Max/Min size for CCP2 memory channel */
  37. #define ISPCCP2_LCM_HSIZE_COUNT_MIN 16
  38. #define ISPCCP2_LCM_HSIZE_COUNT_MAX 8191
  39. #define ISPCCP2_LCM_HSIZE_SKIP_MIN 0
  40. #define ISPCCP2_LCM_HSIZE_SKIP_MAX 8191
  41. #define ISPCCP2_LCM_VSIZE_MIN 1
  42. #define ISPCCP2_LCM_VSIZE_MAX 8191
  43. #define ISPCCP2_LCM_HWORDS_MIN 1
  44. #define ISPCCP2_LCM_HWORDS_MAX 4095
  45. #define ISPCCP2_LCM_CTRL_BURST_SIZE_32X 5
  46. #define ISPCCP2_LCM_CTRL_READ_THROTTLE_FULL 0
  47. #define ISPCCP2_LCM_CTRL_SRC_DECOMPR_DPCM10 2
  48. #define ISPCCP2_LCM_CTRL_SRC_FORMAT_RAW8 2
  49. #define ISPCCP2_LCM_CTRL_SRC_FORMAT_RAW10 3
  50. #define ISPCCP2_LCM_CTRL_DST_FORMAT_RAW10 3
  51. #define ISPCCP2_LCM_CTRL_DST_PORT_VP 0
  52. #define ISPCCP2_LCM_CTRL_DST_PORT_MEM 1
  53. /* Set only the required bits */
  54. #define BIT_SET(var, shift, mask, val) \
  55. do { \
  56. var = ((var) & ~((mask) << (shift))) \
  57. | ((val) << (shift)); \
  58. } while (0)
  59. /*
  60. * ccp2_print_status - Print current CCP2 module register values.
  61. */
  62. #define CCP2_PRINT_REGISTER(isp, name)\
  63. dev_dbg(isp->dev, "###CCP2 " #name "=0x%08x\n", \
  64. isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCP2, ISPCCP2_##name))
  65. static void ccp2_print_status(struct isp_ccp2_device *ccp2)
  66. {
  67. struct isp_device *isp = to_isp_device(ccp2);
  68. dev_dbg(isp->dev, "-------------CCP2 Register dump-------------\n");
  69. CCP2_PRINT_REGISTER(isp, SYSCONFIG);
  70. CCP2_PRINT_REGISTER(isp, SYSSTATUS);
  71. CCP2_PRINT_REGISTER(isp, LC01_IRQENABLE);
  72. CCP2_PRINT_REGISTER(isp, LC01_IRQSTATUS);
  73. CCP2_PRINT_REGISTER(isp, LC23_IRQENABLE);
  74. CCP2_PRINT_REGISTER(isp, LC23_IRQSTATUS);
  75. CCP2_PRINT_REGISTER(isp, LCM_IRQENABLE);
  76. CCP2_PRINT_REGISTER(isp, LCM_IRQSTATUS);
  77. CCP2_PRINT_REGISTER(isp, CTRL);
  78. CCP2_PRINT_REGISTER(isp, LCx_CTRL(0));
  79. CCP2_PRINT_REGISTER(isp, LCx_CODE(0));
  80. CCP2_PRINT_REGISTER(isp, LCx_STAT_START(0));
  81. CCP2_PRINT_REGISTER(isp, LCx_STAT_SIZE(0));
  82. CCP2_PRINT_REGISTER(isp, LCx_SOF_ADDR(0));
  83. CCP2_PRINT_REGISTER(isp, LCx_EOF_ADDR(0));
  84. CCP2_PRINT_REGISTER(isp, LCx_DAT_START(0));
  85. CCP2_PRINT_REGISTER(isp, LCx_DAT_SIZE(0));
  86. CCP2_PRINT_REGISTER(isp, LCx_DAT_PING_ADDR(0));
  87. CCP2_PRINT_REGISTER(isp, LCx_DAT_PONG_ADDR(0));
  88. CCP2_PRINT_REGISTER(isp, LCx_DAT_OFST(0));
  89. CCP2_PRINT_REGISTER(isp, LCM_CTRL);
  90. CCP2_PRINT_REGISTER(isp, LCM_VSIZE);
  91. CCP2_PRINT_REGISTER(isp, LCM_HSIZE);
  92. CCP2_PRINT_REGISTER(isp, LCM_PREFETCH);
  93. CCP2_PRINT_REGISTER(isp, LCM_SRC_ADDR);
  94. CCP2_PRINT_REGISTER(isp, LCM_SRC_OFST);
  95. CCP2_PRINT_REGISTER(isp, LCM_DST_ADDR);
  96. CCP2_PRINT_REGISTER(isp, LCM_DST_OFST);
  97. dev_dbg(isp->dev, "--------------------------------------------\n");
  98. }
  99. /*
  100. * ccp2_reset - Reset the CCP2
  101. * @ccp2: pointer to ISP CCP2 device
  102. */
  103. static void ccp2_reset(struct isp_ccp2_device *ccp2)
  104. {
  105. struct isp_device *isp = to_isp_device(ccp2);
  106. int i = 0;
  107. /* Reset the CSI1/CCP2B and wait for reset to complete */
  108. isp_reg_set(isp, OMAP3_ISP_IOMEM_CCP2, ISPCCP2_SYSCONFIG,
  109. ISPCCP2_SYSCONFIG_SOFT_RESET);
  110. while (!(isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCP2, ISPCCP2_SYSSTATUS) &
  111. ISPCCP2_SYSSTATUS_RESET_DONE)) {
  112. udelay(10);
  113. if (i++ > 10) { /* try read 10 times */
  114. dev_warn(isp->dev,
  115. "omap3_isp: timeout waiting for ccp2 reset\n");
  116. break;
  117. }
  118. }
  119. }
  120. /*
  121. * ccp2_pwr_cfg - Configure the power mode settings
  122. * @ccp2: pointer to ISP CCP2 device
  123. */
  124. static void ccp2_pwr_cfg(struct isp_ccp2_device *ccp2)
  125. {
  126. struct isp_device *isp = to_isp_device(ccp2);
  127. isp_reg_writel(isp, ISPCCP2_SYSCONFIG_MSTANDBY_MODE_SMART |
  128. ((isp->revision == ISP_REVISION_15_0 && isp->autoidle) ?
  129. ISPCCP2_SYSCONFIG_AUTO_IDLE : 0),
  130. OMAP3_ISP_IOMEM_CCP2, ISPCCP2_SYSCONFIG);
  131. }
  132. /*
  133. * ccp2_if_enable - Enable CCP2 interface.
  134. * @ccp2: pointer to ISP CCP2 device
  135. * @enable: enable/disable flag
  136. */
  137. static int ccp2_if_enable(struct isp_ccp2_device *ccp2, u8 enable)
  138. {
  139. struct isp_device *isp = to_isp_device(ccp2);
  140. int ret;
  141. int i;
  142. if (enable && ccp2->vdds_csib) {
  143. ret = regulator_enable(ccp2->vdds_csib);
  144. if (ret < 0)
  145. return ret;
  146. }
  147. /* Enable/Disable all the LCx channels */
  148. for (i = 0; i < CCP2_LCx_CHANS_NUM; i++)
  149. isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_CCP2, ISPCCP2_LCx_CTRL(i),
  150. ISPCCP2_LCx_CTRL_CHAN_EN,
  151. enable ? ISPCCP2_LCx_CTRL_CHAN_EN : 0);
  152. /* Enable/Disable ccp2 interface in ccp2 mode */
  153. isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_CCP2, ISPCCP2_CTRL,
  154. ISPCCP2_CTRL_MODE | ISPCCP2_CTRL_IF_EN,
  155. enable ? (ISPCCP2_CTRL_MODE | ISPCCP2_CTRL_IF_EN) : 0);
  156. if (!enable && ccp2->vdds_csib)
  157. regulator_disable(ccp2->vdds_csib);
  158. return 0;
  159. }
  160. /*
  161. * ccp2_mem_enable - Enable CCP2 memory interface.
  162. * @ccp2: pointer to ISP CCP2 device
  163. * @enable: enable/disable flag
  164. */
  165. static void ccp2_mem_enable(struct isp_ccp2_device *ccp2, u8 enable)
  166. {
  167. struct isp_device *isp = to_isp_device(ccp2);
  168. if (enable)
  169. ccp2_if_enable(ccp2, 0);
  170. /* Enable/Disable ccp2 interface in ccp2 mode */
  171. isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_CCP2, ISPCCP2_CTRL,
  172. ISPCCP2_CTRL_MODE, enable ? ISPCCP2_CTRL_MODE : 0);
  173. isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_CCP2, ISPCCP2_LCM_CTRL,
  174. ISPCCP2_LCM_CTRL_CHAN_EN,
  175. enable ? ISPCCP2_LCM_CTRL_CHAN_EN : 0);
  176. }
  177. /*
  178. * ccp2_phyif_config - Initialize CCP2 phy interface config
  179. * @ccp2: Pointer to ISP CCP2 device
  180. * @buscfg: CCP2 platform data
  181. *
  182. * Configure the CCP2 physical interface module from platform data.
  183. *
  184. * Returns -EIO if strobe is chosen in CSI1 mode, or 0 on success.
  185. */
  186. static int ccp2_phyif_config(struct isp_ccp2_device *ccp2,
  187. const struct isp_ccp2_cfg *buscfg)
  188. {
  189. struct isp_device *isp = to_isp_device(ccp2);
  190. u32 val;
  191. /* CCP2B mode */
  192. val = isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCP2, ISPCCP2_CTRL) |
  193. ISPCCP2_CTRL_IO_OUT_SEL | ISPCCP2_CTRL_MODE;
  194. /* Data/strobe physical layer */
  195. BIT_SET(val, ISPCCP2_CTRL_PHY_SEL_SHIFT, ISPCCP2_CTRL_PHY_SEL_MASK,
  196. buscfg->phy_layer);
  197. BIT_SET(val, ISPCCP2_CTRL_INV_SHIFT, ISPCCP2_CTRL_INV_MASK,
  198. buscfg->strobe_clk_pol);
  199. isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_CCP2, ISPCCP2_CTRL);
  200. val = isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCP2, ISPCCP2_CTRL);
  201. if (!(val & ISPCCP2_CTRL_MODE)) {
  202. if (buscfg->ccp2_mode == ISP_CCP2_MODE_CCP2)
  203. dev_warn(isp->dev, "OMAP3 CCP2 bus not available\n");
  204. if (buscfg->phy_layer == ISP_CCP2_PHY_DATA_STROBE)
  205. /* Strobe mode requires CCP2 */
  206. return -EIO;
  207. }
  208. return 0;
  209. }
  210. /*
  211. * ccp2_vp_config - Initialize CCP2 video port interface.
  212. * @ccp2: Pointer to ISP CCP2 device
  213. * @vpclk_div: Video port divisor
  214. *
  215. * Configure the CCP2 video port with the given clock divisor. The valid divisor
  216. * values depend on the ISP revision:
  217. *
  218. * - revision 1.0 and 2.0 1 to 4
  219. * - revision 15.0 1 to 65536
  220. *
  221. * The exact divisor value used might differ from the requested value, as ISP
  222. * revision 15.0 represent the divisor by 65536 divided by an integer.
  223. */
  224. static void ccp2_vp_config(struct isp_ccp2_device *ccp2,
  225. unsigned int vpclk_div)
  226. {
  227. struct isp_device *isp = to_isp_device(ccp2);
  228. u32 val;
  229. /* ISPCCP2_CTRL Video port */
  230. val = isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCP2, ISPCCP2_CTRL);
  231. val |= ISPCCP2_CTRL_VP_ONLY_EN; /* Disable the memory write port */
  232. if (isp->revision == ISP_REVISION_15_0) {
  233. vpclk_div = clamp_t(unsigned int, vpclk_div, 1, 65536);
  234. vpclk_div = min(ISPCCP2_VPCLK_FRACDIV / vpclk_div, 65535U);
  235. BIT_SET(val, ISPCCP2_CTRL_VPCLK_DIV_SHIFT,
  236. ISPCCP2_CTRL_VPCLK_DIV_MASK, vpclk_div);
  237. } else {
  238. vpclk_div = clamp_t(unsigned int, vpclk_div, 1, 4);
  239. BIT_SET(val, ISPCCP2_CTRL_VP_OUT_CTRL_SHIFT,
  240. ISPCCP2_CTRL_VP_OUT_CTRL_MASK, vpclk_div - 1);
  241. }
  242. isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_CCP2, ISPCCP2_CTRL);
  243. }
  244. /*
  245. * ccp2_lcx_config - Initialize CCP2 logical channel interface.
  246. * @ccp2: Pointer to ISP CCP2 device
  247. * @config: Pointer to ISP LCx config structure.
  248. *
  249. * This will analyze the parameters passed by the interface config
  250. * and configure CSI1/CCP2 logical channel
  251. *
  252. */
  253. static void ccp2_lcx_config(struct isp_ccp2_device *ccp2,
  254. struct isp_interface_lcx_config *config)
  255. {
  256. struct isp_device *isp = to_isp_device(ccp2);
  257. u32 val, format;
  258. switch (config->format) {
  259. case MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8:
  260. format = ISPCCP2_LCx_CTRL_FORMAT_RAW8_DPCM10_VP;
  261. break;
  262. case MEDIA_BUS_FMT_SGRBG10_1X10:
  263. default:
  264. format = ISPCCP2_LCx_CTRL_FORMAT_RAW10_VP; /* RAW10+VP */
  265. break;
  266. }
  267. /* ISPCCP2_LCx_CTRL logical channel #0 */
  268. val = isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCP2, ISPCCP2_LCx_CTRL(0))
  269. | (ISPCCP2_LCx_CTRL_REGION_EN); /* Region */
  270. if (isp->revision == ISP_REVISION_15_0) {
  271. /* CRC */
  272. BIT_SET(val, ISPCCP2_LCx_CTRL_CRC_SHIFT_15_0,
  273. ISPCCP2_LCx_CTRL_CRC_MASK,
  274. config->crc);
  275. /* Format = RAW10+VP or RAW8+DPCM10+VP*/
  276. BIT_SET(val, ISPCCP2_LCx_CTRL_FORMAT_SHIFT_15_0,
  277. ISPCCP2_LCx_CTRL_FORMAT_MASK_15_0, format);
  278. } else {
  279. BIT_SET(val, ISPCCP2_LCx_CTRL_CRC_SHIFT,
  280. ISPCCP2_LCx_CTRL_CRC_MASK,
  281. config->crc);
  282. BIT_SET(val, ISPCCP2_LCx_CTRL_FORMAT_SHIFT,
  283. ISPCCP2_LCx_CTRL_FORMAT_MASK, format);
  284. }
  285. isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_CCP2, ISPCCP2_LCx_CTRL(0));
  286. /* ISPCCP2_DAT_START for logical channel #0 */
  287. isp_reg_writel(isp, config->data_start << ISPCCP2_LCx_DAT_SHIFT,
  288. OMAP3_ISP_IOMEM_CCP2, ISPCCP2_LCx_DAT_START(0));
  289. /* ISPCCP2_DAT_SIZE for logical channel #0 */
  290. isp_reg_writel(isp, config->data_size << ISPCCP2_LCx_DAT_SHIFT,
  291. OMAP3_ISP_IOMEM_CCP2, ISPCCP2_LCx_DAT_SIZE(0));
  292. /* Enable error IRQs for logical channel #0 */
  293. val = ISPCCP2_LC01_IRQSTATUS_LC0_FIFO_OVF_IRQ |
  294. ISPCCP2_LC01_IRQSTATUS_LC0_CRC_IRQ |
  295. ISPCCP2_LC01_IRQSTATUS_LC0_FSP_IRQ |
  296. ISPCCP2_LC01_IRQSTATUS_LC0_FW_IRQ |
  297. ISPCCP2_LC01_IRQSTATUS_LC0_FSC_IRQ |
  298. ISPCCP2_LC01_IRQSTATUS_LC0_SSC_IRQ;
  299. isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_CCP2, ISPCCP2_LC01_IRQSTATUS);
  300. isp_reg_set(isp, OMAP3_ISP_IOMEM_CCP2, ISPCCP2_LC01_IRQENABLE, val);
  301. }
  302. /*
  303. * ccp2_if_configure - Configure ccp2 with data from sensor
  304. * @ccp2: Pointer to ISP CCP2 device
  305. *
  306. * Return 0 on success or a negative error code
  307. */
  308. static int ccp2_if_configure(struct isp_ccp2_device *ccp2)
  309. {
  310. const struct isp_bus_cfg *buscfg;
  311. struct v4l2_mbus_framefmt *format;
  312. struct media_pad *pad;
  313. struct v4l2_subdev *sensor;
  314. u32 lines = 0;
  315. int ret;
  316. ccp2_pwr_cfg(ccp2);
  317. pad = media_entity_remote_pad(&ccp2->pads[CCP2_PAD_SINK]);
  318. sensor = media_entity_to_v4l2_subdev(pad->entity);
  319. buscfg = sensor->host_priv;
  320. ret = ccp2_phyif_config(ccp2, &buscfg->bus.ccp2);
  321. if (ret < 0)
  322. return ret;
  323. ccp2_vp_config(ccp2, buscfg->bus.ccp2.vpclk_div + 1);
  324. v4l2_subdev_call(sensor, sensor, g_skip_top_lines, &lines);
  325. format = &ccp2->formats[CCP2_PAD_SINK];
  326. ccp2->if_cfg.data_start = lines;
  327. ccp2->if_cfg.crc = buscfg->bus.ccp2.crc;
  328. ccp2->if_cfg.format = format->code;
  329. ccp2->if_cfg.data_size = format->height;
  330. ccp2_lcx_config(ccp2, &ccp2->if_cfg);
  331. return 0;
  332. }
  333. static int ccp2_adjust_bandwidth(struct isp_ccp2_device *ccp2)
  334. {
  335. struct isp_pipeline *pipe = to_isp_pipeline(&ccp2->subdev.entity);
  336. struct isp_device *isp = to_isp_device(ccp2);
  337. const struct v4l2_mbus_framefmt *ofmt = &ccp2->formats[CCP2_PAD_SOURCE];
  338. unsigned long l3_ick = pipe->l3_ick;
  339. struct v4l2_fract *timeperframe;
  340. unsigned int vpclk_div = 2;
  341. unsigned int value;
  342. u64 bound;
  343. u64 area;
  344. /* Compute the minimum clock divisor, based on the pipeline maximum
  345. * data rate. This is an absolute lower bound if we don't want SBL
  346. * overflows, so round the value up.
  347. */
  348. vpclk_div = max_t(unsigned int, DIV_ROUND_UP(l3_ick, pipe->max_rate),
  349. vpclk_div);
  350. /* Compute the maximum clock divisor, based on the requested frame rate.
  351. * This is a soft lower bound to achieve a frame rate equal or higher
  352. * than the requested value, so round the value down.
  353. */
  354. timeperframe = &pipe->max_timeperframe;
  355. if (timeperframe->numerator) {
  356. area = ofmt->width * ofmt->height;
  357. bound = div_u64(area * timeperframe->denominator,
  358. timeperframe->numerator);
  359. value = min_t(u64, bound, l3_ick);
  360. vpclk_div = max_t(unsigned int, l3_ick / value, vpclk_div);
  361. }
  362. dev_dbg(isp->dev, "%s: minimum clock divisor = %u\n", __func__,
  363. vpclk_div);
  364. return vpclk_div;
  365. }
  366. /*
  367. * ccp2_mem_configure - Initialize CCP2 memory input/output interface
  368. * @ccp2: Pointer to ISP CCP2 device
  369. * @config: Pointer to ISP mem interface config structure
  370. *
  371. * This will analyze the parameters passed by the interface config
  372. * structure, and configure the respective registers for proper
  373. * CSI1/CCP2 memory input.
  374. */
  375. static void ccp2_mem_configure(struct isp_ccp2_device *ccp2,
  376. struct isp_interface_mem_config *config)
  377. {
  378. struct isp_device *isp = to_isp_device(ccp2);
  379. u32 sink_pixcode = ccp2->formats[CCP2_PAD_SINK].code;
  380. u32 source_pixcode = ccp2->formats[CCP2_PAD_SOURCE].code;
  381. unsigned int dpcm_decompress = 0;
  382. u32 val, hwords;
  383. if (sink_pixcode != source_pixcode &&
  384. sink_pixcode == MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8)
  385. dpcm_decompress = 1;
  386. ccp2_pwr_cfg(ccp2);
  387. /* Hsize, Skip */
  388. isp_reg_writel(isp, ISPCCP2_LCM_HSIZE_SKIP_MIN |
  389. (config->hsize_count << ISPCCP2_LCM_HSIZE_SHIFT),
  390. OMAP3_ISP_IOMEM_CCP2, ISPCCP2_LCM_HSIZE);
  391. /* Vsize, no. of lines */
  392. isp_reg_writel(isp, config->vsize_count << ISPCCP2_LCM_VSIZE_SHIFT,
  393. OMAP3_ISP_IOMEM_CCP2, ISPCCP2_LCM_VSIZE);
  394. if (ccp2->video_in.bpl_padding == 0)
  395. config->src_ofst = 0;
  396. else
  397. config->src_ofst = ccp2->video_in.bpl_value;
  398. isp_reg_writel(isp, config->src_ofst, OMAP3_ISP_IOMEM_CCP2,
  399. ISPCCP2_LCM_SRC_OFST);
  400. /* Source and Destination formats */
  401. val = ISPCCP2_LCM_CTRL_DST_FORMAT_RAW10 <<
  402. ISPCCP2_LCM_CTRL_DST_FORMAT_SHIFT;
  403. if (dpcm_decompress) {
  404. /* source format is RAW8 */
  405. val |= ISPCCP2_LCM_CTRL_SRC_FORMAT_RAW8 <<
  406. ISPCCP2_LCM_CTRL_SRC_FORMAT_SHIFT;
  407. /* RAW8 + DPCM10 - simple predictor */
  408. val |= ISPCCP2_LCM_CTRL_SRC_DPCM_PRED;
  409. /* enable source DPCM decompression */
  410. val |= ISPCCP2_LCM_CTRL_SRC_DECOMPR_DPCM10 <<
  411. ISPCCP2_LCM_CTRL_SRC_DECOMPR_SHIFT;
  412. } else {
  413. /* source format is RAW10 */
  414. val |= ISPCCP2_LCM_CTRL_SRC_FORMAT_RAW10 <<
  415. ISPCCP2_LCM_CTRL_SRC_FORMAT_SHIFT;
  416. }
  417. /* Burst size to 32x64 */
  418. val |= ISPCCP2_LCM_CTRL_BURST_SIZE_32X <<
  419. ISPCCP2_LCM_CTRL_BURST_SIZE_SHIFT;
  420. isp_reg_writel(isp, val, OMAP3_ISP_IOMEM_CCP2, ISPCCP2_LCM_CTRL);
  421. /* Prefetch setup */
  422. if (dpcm_decompress)
  423. hwords = (ISPCCP2_LCM_HSIZE_SKIP_MIN +
  424. config->hsize_count) >> 3;
  425. else
  426. hwords = (ISPCCP2_LCM_HSIZE_SKIP_MIN +
  427. config->hsize_count) >> 2;
  428. isp_reg_writel(isp, hwords << ISPCCP2_LCM_PREFETCH_SHIFT,
  429. OMAP3_ISP_IOMEM_CCP2, ISPCCP2_LCM_PREFETCH);
  430. /* Video port */
  431. isp_reg_set(isp, OMAP3_ISP_IOMEM_CCP2, ISPCCP2_CTRL,
  432. ISPCCP2_CTRL_IO_OUT_SEL | ISPCCP2_CTRL_MODE);
  433. ccp2_vp_config(ccp2, ccp2_adjust_bandwidth(ccp2));
  434. /* Clear LCM interrupts */
  435. isp_reg_writel(isp, ISPCCP2_LCM_IRQSTATUS_OCPERROR_IRQ |
  436. ISPCCP2_LCM_IRQSTATUS_EOF_IRQ,
  437. OMAP3_ISP_IOMEM_CCP2, ISPCCP2_LCM_IRQSTATUS);
  438. /* Enable LCM interrupts */
  439. isp_reg_set(isp, OMAP3_ISP_IOMEM_CCP2, ISPCCP2_LCM_IRQENABLE,
  440. ISPCCP2_LCM_IRQSTATUS_EOF_IRQ |
  441. ISPCCP2_LCM_IRQSTATUS_OCPERROR_IRQ);
  442. }
  443. /*
  444. * ccp2_set_inaddr - Sets memory address of input frame.
  445. * @ccp2: Pointer to ISP CCP2 device
  446. * @addr: 32bit memory address aligned on 32byte boundary.
  447. *
  448. * Configures the memory address from which the input frame is to be read.
  449. */
  450. static void ccp2_set_inaddr(struct isp_ccp2_device *ccp2, u32 addr)
  451. {
  452. struct isp_device *isp = to_isp_device(ccp2);
  453. isp_reg_writel(isp, addr, OMAP3_ISP_IOMEM_CCP2, ISPCCP2_LCM_SRC_ADDR);
  454. }
  455. /* -----------------------------------------------------------------------------
  456. * Interrupt handling
  457. */
  458. static void ccp2_isr_buffer(struct isp_ccp2_device *ccp2)
  459. {
  460. struct isp_pipeline *pipe = to_isp_pipeline(&ccp2->subdev.entity);
  461. struct isp_buffer *buffer;
  462. buffer = omap3isp_video_buffer_next(&ccp2->video_in);
  463. if (buffer != NULL)
  464. ccp2_set_inaddr(ccp2, buffer->dma);
  465. pipe->state |= ISP_PIPELINE_IDLE_INPUT;
  466. if (ccp2->state == ISP_PIPELINE_STREAM_SINGLESHOT) {
  467. if (isp_pipeline_ready(pipe))
  468. omap3isp_pipeline_set_stream(pipe,
  469. ISP_PIPELINE_STREAM_SINGLESHOT);
  470. }
  471. }
  472. /*
  473. * omap3isp_ccp2_isr - Handle ISP CCP2 interrupts
  474. * @ccp2: Pointer to ISP CCP2 device
  475. *
  476. * This will handle the CCP2 interrupts
  477. */
  478. void omap3isp_ccp2_isr(struct isp_ccp2_device *ccp2)
  479. {
  480. struct isp_pipeline *pipe = to_isp_pipeline(&ccp2->subdev.entity);
  481. struct isp_device *isp = to_isp_device(ccp2);
  482. static const u32 ISPCCP2_LC01_ERROR =
  483. ISPCCP2_LC01_IRQSTATUS_LC0_FIFO_OVF_IRQ |
  484. ISPCCP2_LC01_IRQSTATUS_LC0_CRC_IRQ |
  485. ISPCCP2_LC01_IRQSTATUS_LC0_FSP_IRQ |
  486. ISPCCP2_LC01_IRQSTATUS_LC0_FW_IRQ |
  487. ISPCCP2_LC01_IRQSTATUS_LC0_FSC_IRQ |
  488. ISPCCP2_LC01_IRQSTATUS_LC0_SSC_IRQ;
  489. u32 lcx_irqstatus, lcm_irqstatus;
  490. /* First clear the interrupts */
  491. lcx_irqstatus = isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCP2,
  492. ISPCCP2_LC01_IRQSTATUS);
  493. isp_reg_writel(isp, lcx_irqstatus, OMAP3_ISP_IOMEM_CCP2,
  494. ISPCCP2_LC01_IRQSTATUS);
  495. lcm_irqstatus = isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCP2,
  496. ISPCCP2_LCM_IRQSTATUS);
  497. isp_reg_writel(isp, lcm_irqstatus, OMAP3_ISP_IOMEM_CCP2,
  498. ISPCCP2_LCM_IRQSTATUS);
  499. /* Errors */
  500. if (lcx_irqstatus & ISPCCP2_LC01_ERROR) {
  501. pipe->error = true;
  502. dev_dbg(isp->dev, "CCP2 err:%x\n", lcx_irqstatus);
  503. return;
  504. }
  505. if (lcm_irqstatus & ISPCCP2_LCM_IRQSTATUS_OCPERROR_IRQ) {
  506. pipe->error = true;
  507. dev_dbg(isp->dev, "CCP2 OCP err:%x\n", lcm_irqstatus);
  508. }
  509. if (omap3isp_module_sync_is_stopping(&ccp2->wait, &ccp2->stopping))
  510. return;
  511. /* Handle queued buffers on frame end interrupts */
  512. if (lcm_irqstatus & ISPCCP2_LCM_IRQSTATUS_EOF_IRQ)
  513. ccp2_isr_buffer(ccp2);
  514. }
  515. /* -----------------------------------------------------------------------------
  516. * V4L2 subdev operations
  517. */
  518. static const unsigned int ccp2_fmts[] = {
  519. MEDIA_BUS_FMT_SGRBG10_1X10,
  520. MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8,
  521. };
  522. /*
  523. * __ccp2_get_format - helper function for getting ccp2 format
  524. * @ccp2 : Pointer to ISP CCP2 device
  525. * @cfg: V4L2 subdev pad configuration
  526. * @pad : pad number
  527. * @which : wanted subdev format
  528. * return format structure or NULL on error
  529. */
  530. static struct v4l2_mbus_framefmt *
  531. __ccp2_get_format(struct isp_ccp2_device *ccp2, struct v4l2_subdev_pad_config *cfg,
  532. unsigned int pad, enum v4l2_subdev_format_whence which)
  533. {
  534. if (which == V4L2_SUBDEV_FORMAT_TRY)
  535. return v4l2_subdev_get_try_format(&ccp2->subdev, cfg, pad);
  536. else
  537. return &ccp2->formats[pad];
  538. }
  539. /*
  540. * ccp2_try_format - Handle try format by pad subdev method
  541. * @ccp2 : Pointer to ISP CCP2 device
  542. * @cfg: V4L2 subdev pad configuration
  543. * @pad : pad num
  544. * @fmt : pointer to v4l2 mbus format structure
  545. * @which : wanted subdev format
  546. */
  547. static void ccp2_try_format(struct isp_ccp2_device *ccp2,
  548. struct v4l2_subdev_pad_config *cfg, unsigned int pad,
  549. struct v4l2_mbus_framefmt *fmt,
  550. enum v4l2_subdev_format_whence which)
  551. {
  552. struct v4l2_mbus_framefmt *format;
  553. switch (pad) {
  554. case CCP2_PAD_SINK:
  555. if (fmt->code != MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8)
  556. fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10;
  557. if (ccp2->input == CCP2_INPUT_SENSOR) {
  558. fmt->width = clamp_t(u32, fmt->width,
  559. ISPCCP2_DAT_START_MIN,
  560. ISPCCP2_DAT_START_MAX);
  561. fmt->height = clamp_t(u32, fmt->height,
  562. ISPCCP2_DAT_SIZE_MIN,
  563. ISPCCP2_DAT_SIZE_MAX);
  564. } else if (ccp2->input == CCP2_INPUT_MEMORY) {
  565. fmt->width = clamp_t(u32, fmt->width,
  566. ISPCCP2_LCM_HSIZE_COUNT_MIN,
  567. ISPCCP2_LCM_HSIZE_COUNT_MAX);
  568. fmt->height = clamp_t(u32, fmt->height,
  569. ISPCCP2_LCM_VSIZE_MIN,
  570. ISPCCP2_LCM_VSIZE_MAX);
  571. }
  572. break;
  573. case CCP2_PAD_SOURCE:
  574. /* Source format - copy sink format and change pixel code
  575. * to SGRBG10_1X10 as we don't support CCP2 write to memory.
  576. * When CCP2 write to memory feature will be added this
  577. * should be changed properly.
  578. */
  579. format = __ccp2_get_format(ccp2, cfg, CCP2_PAD_SINK, which);
  580. memcpy(fmt, format, sizeof(*fmt));
  581. fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10;
  582. break;
  583. }
  584. fmt->field = V4L2_FIELD_NONE;
  585. fmt->colorspace = V4L2_COLORSPACE_SRGB;
  586. }
  587. /*
  588. * ccp2_enum_mbus_code - Handle pixel format enumeration
  589. * @sd : pointer to v4l2 subdev structure
  590. * @cfg: V4L2 subdev pad configuration
  591. * @code : pointer to v4l2_subdev_mbus_code_enum structure
  592. * return -EINVAL or zero on success
  593. */
  594. static int ccp2_enum_mbus_code(struct v4l2_subdev *sd,
  595. struct v4l2_subdev_pad_config *cfg,
  596. struct v4l2_subdev_mbus_code_enum *code)
  597. {
  598. struct isp_ccp2_device *ccp2 = v4l2_get_subdevdata(sd);
  599. struct v4l2_mbus_framefmt *format;
  600. if (code->pad == CCP2_PAD_SINK) {
  601. if (code->index >= ARRAY_SIZE(ccp2_fmts))
  602. return -EINVAL;
  603. code->code = ccp2_fmts[code->index];
  604. } else {
  605. if (code->index != 0)
  606. return -EINVAL;
  607. format = __ccp2_get_format(ccp2, cfg, CCP2_PAD_SINK,
  608. code->which);
  609. code->code = format->code;
  610. }
  611. return 0;
  612. }
  613. static int ccp2_enum_frame_size(struct v4l2_subdev *sd,
  614. struct v4l2_subdev_pad_config *cfg,
  615. struct v4l2_subdev_frame_size_enum *fse)
  616. {
  617. struct isp_ccp2_device *ccp2 = v4l2_get_subdevdata(sd);
  618. struct v4l2_mbus_framefmt format;
  619. if (fse->index != 0)
  620. return -EINVAL;
  621. format.code = fse->code;
  622. format.width = 1;
  623. format.height = 1;
  624. ccp2_try_format(ccp2, cfg, fse->pad, &format, fse->which);
  625. fse->min_width = format.width;
  626. fse->min_height = format.height;
  627. if (format.code != fse->code)
  628. return -EINVAL;
  629. format.code = fse->code;
  630. format.width = -1;
  631. format.height = -1;
  632. ccp2_try_format(ccp2, cfg, fse->pad, &format, fse->which);
  633. fse->max_width = format.width;
  634. fse->max_height = format.height;
  635. return 0;
  636. }
  637. /*
  638. * ccp2_get_format - Handle get format by pads subdev method
  639. * @sd : pointer to v4l2 subdev structure
  640. * @cfg: V4L2 subdev pad configuration
  641. * @fmt : pointer to v4l2 subdev format structure
  642. * return -EINVAL or zero on success
  643. */
  644. static int ccp2_get_format(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg,
  645. struct v4l2_subdev_format *fmt)
  646. {
  647. struct isp_ccp2_device *ccp2 = v4l2_get_subdevdata(sd);
  648. struct v4l2_mbus_framefmt *format;
  649. format = __ccp2_get_format(ccp2, cfg, fmt->pad, fmt->which);
  650. if (format == NULL)
  651. return -EINVAL;
  652. fmt->format = *format;
  653. return 0;
  654. }
  655. /*
  656. * ccp2_set_format - Handle set format by pads subdev method
  657. * @sd : pointer to v4l2 subdev structure
  658. * @cfg: V4L2 subdev pad configuration
  659. * @fmt : pointer to v4l2 subdev format structure
  660. * returns zero
  661. */
  662. static int ccp2_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg,
  663. struct v4l2_subdev_format *fmt)
  664. {
  665. struct isp_ccp2_device *ccp2 = v4l2_get_subdevdata(sd);
  666. struct v4l2_mbus_framefmt *format;
  667. format = __ccp2_get_format(ccp2, cfg, fmt->pad, fmt->which);
  668. if (format == NULL)
  669. return -EINVAL;
  670. ccp2_try_format(ccp2, cfg, fmt->pad, &fmt->format, fmt->which);
  671. *format = fmt->format;
  672. /* Propagate the format from sink to source */
  673. if (fmt->pad == CCP2_PAD_SINK) {
  674. format = __ccp2_get_format(ccp2, cfg, CCP2_PAD_SOURCE,
  675. fmt->which);
  676. *format = fmt->format;
  677. ccp2_try_format(ccp2, cfg, CCP2_PAD_SOURCE, format, fmt->which);
  678. }
  679. return 0;
  680. }
  681. /*
  682. * ccp2_init_formats - Initialize formats on all pads
  683. * @sd: ISP CCP2 V4L2 subdevice
  684. * @fh: V4L2 subdev file handle
  685. *
  686. * Initialize all pad formats with default values. If fh is not NULL, try
  687. * formats are initialized on the file handle. Otherwise active formats are
  688. * initialized on the device.
  689. */
  690. static int ccp2_init_formats(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
  691. {
  692. struct v4l2_subdev_format format;
  693. memset(&format, 0, sizeof(format));
  694. format.pad = CCP2_PAD_SINK;
  695. format.which = fh ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTIVE;
  696. format.format.code = MEDIA_BUS_FMT_SGRBG10_1X10;
  697. format.format.width = 4096;
  698. format.format.height = 4096;
  699. ccp2_set_format(sd, fh ? fh->pad : NULL, &format);
  700. return 0;
  701. }
  702. /*
  703. * ccp2_s_stream - Enable/Disable streaming on ccp2 subdev
  704. * @sd : pointer to v4l2 subdev structure
  705. * @enable: 1 == Enable, 0 == Disable
  706. * return zero
  707. */
  708. static int ccp2_s_stream(struct v4l2_subdev *sd, int enable)
  709. {
  710. struct isp_ccp2_device *ccp2 = v4l2_get_subdevdata(sd);
  711. struct isp_device *isp = to_isp_device(ccp2);
  712. struct device *dev = to_device(ccp2);
  713. int ret;
  714. if (ccp2->state == ISP_PIPELINE_STREAM_STOPPED) {
  715. if (enable == ISP_PIPELINE_STREAM_STOPPED)
  716. return 0;
  717. atomic_set(&ccp2->stopping, 0);
  718. }
  719. switch (enable) {
  720. case ISP_PIPELINE_STREAM_CONTINUOUS:
  721. if (ccp2->phy) {
  722. ret = omap3isp_csiphy_acquire(ccp2->phy);
  723. if (ret < 0)
  724. return ret;
  725. }
  726. ccp2_if_configure(ccp2);
  727. ccp2_print_status(ccp2);
  728. /* Enable CSI1/CCP2 interface */
  729. ret = ccp2_if_enable(ccp2, 1);
  730. if (ret < 0) {
  731. if (ccp2->phy)
  732. omap3isp_csiphy_release(ccp2->phy);
  733. return ret;
  734. }
  735. break;
  736. case ISP_PIPELINE_STREAM_SINGLESHOT:
  737. if (ccp2->state != ISP_PIPELINE_STREAM_SINGLESHOT) {
  738. struct v4l2_mbus_framefmt *format;
  739. format = &ccp2->formats[CCP2_PAD_SINK];
  740. ccp2->mem_cfg.hsize_count = format->width;
  741. ccp2->mem_cfg.vsize_count = format->height;
  742. ccp2->mem_cfg.src_ofst = 0;
  743. ccp2_mem_configure(ccp2, &ccp2->mem_cfg);
  744. omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_CSI1_READ);
  745. ccp2_print_status(ccp2);
  746. }
  747. ccp2_mem_enable(ccp2, 1);
  748. break;
  749. case ISP_PIPELINE_STREAM_STOPPED:
  750. if (omap3isp_module_sync_idle(&sd->entity, &ccp2->wait,
  751. &ccp2->stopping))
  752. dev_dbg(dev, "%s: module stop timeout.\n", sd->name);
  753. if (ccp2->input == CCP2_INPUT_MEMORY) {
  754. ccp2_mem_enable(ccp2, 0);
  755. omap3isp_sbl_disable(isp, OMAP3_ISP_SBL_CSI1_READ);
  756. } else if (ccp2->input == CCP2_INPUT_SENSOR) {
  757. /* Disable CSI1/CCP2 interface */
  758. ccp2_if_enable(ccp2, 0);
  759. if (ccp2->phy)
  760. omap3isp_csiphy_release(ccp2->phy);
  761. }
  762. break;
  763. }
  764. ccp2->state = enable;
  765. return 0;
  766. }
  767. /* subdev video operations */
  768. static const struct v4l2_subdev_video_ops ccp2_sd_video_ops = {
  769. .s_stream = ccp2_s_stream,
  770. };
  771. /* subdev pad operations */
  772. static const struct v4l2_subdev_pad_ops ccp2_sd_pad_ops = {
  773. .enum_mbus_code = ccp2_enum_mbus_code,
  774. .enum_frame_size = ccp2_enum_frame_size,
  775. .get_fmt = ccp2_get_format,
  776. .set_fmt = ccp2_set_format,
  777. };
  778. /* subdev operations */
  779. static const struct v4l2_subdev_ops ccp2_sd_ops = {
  780. .video = &ccp2_sd_video_ops,
  781. .pad = &ccp2_sd_pad_ops,
  782. };
  783. /* subdev internal operations */
  784. static const struct v4l2_subdev_internal_ops ccp2_sd_internal_ops = {
  785. .open = ccp2_init_formats,
  786. };
  787. /* --------------------------------------------------------------------------
  788. * ISP ccp2 video device node
  789. */
  790. /*
  791. * ccp2_video_queue - Queue video buffer.
  792. * @video : Pointer to isp video structure
  793. * @buffer: Pointer to isp_buffer structure
  794. * return -EIO or zero on success
  795. */
  796. static int ccp2_video_queue(struct isp_video *video, struct isp_buffer *buffer)
  797. {
  798. struct isp_ccp2_device *ccp2 = &video->isp->isp_ccp2;
  799. ccp2_set_inaddr(ccp2, buffer->dma);
  800. return 0;
  801. }
  802. static const struct isp_video_operations ccp2_video_ops = {
  803. .queue = ccp2_video_queue,
  804. };
  805. /* -----------------------------------------------------------------------------
  806. * Media entity operations
  807. */
  808. /*
  809. * ccp2_link_setup - Setup ccp2 connections.
  810. * @entity : Pointer to media entity structure
  811. * @local : Pointer to local pad array
  812. * @remote : Pointer to remote pad array
  813. * @flags : Link flags
  814. * return -EINVAL on error or zero on success
  815. */
  816. static int ccp2_link_setup(struct media_entity *entity,
  817. const struct media_pad *local,
  818. const struct media_pad *remote, u32 flags)
  819. {
  820. struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
  821. struct isp_ccp2_device *ccp2 = v4l2_get_subdevdata(sd);
  822. unsigned int index = local->index;
  823. /* FIXME: this is actually a hack! */
  824. if (is_media_entity_v4l2_subdev(remote->entity))
  825. index |= 2 << 16;
  826. switch (index) {
  827. case CCP2_PAD_SINK:
  828. /* read from memory */
  829. if (flags & MEDIA_LNK_FL_ENABLED) {
  830. if (ccp2->input == CCP2_INPUT_SENSOR)
  831. return -EBUSY;
  832. ccp2->input = CCP2_INPUT_MEMORY;
  833. } else {
  834. if (ccp2->input == CCP2_INPUT_MEMORY)
  835. ccp2->input = CCP2_INPUT_NONE;
  836. }
  837. break;
  838. case CCP2_PAD_SINK | 2 << 16:
  839. /* read from sensor/phy */
  840. if (flags & MEDIA_LNK_FL_ENABLED) {
  841. if (ccp2->input == CCP2_INPUT_MEMORY)
  842. return -EBUSY;
  843. ccp2->input = CCP2_INPUT_SENSOR;
  844. } else {
  845. if (ccp2->input == CCP2_INPUT_SENSOR)
  846. ccp2->input = CCP2_INPUT_NONE;
  847. } break;
  848. case CCP2_PAD_SOURCE | 2 << 16:
  849. /* write to video port/ccdc */
  850. if (flags & MEDIA_LNK_FL_ENABLED)
  851. ccp2->output = CCP2_OUTPUT_CCDC;
  852. else
  853. ccp2->output = CCP2_OUTPUT_NONE;
  854. break;
  855. default:
  856. return -EINVAL;
  857. }
  858. return 0;
  859. }
  860. /* media operations */
  861. static const struct media_entity_operations ccp2_media_ops = {
  862. .link_setup = ccp2_link_setup,
  863. .link_validate = v4l2_subdev_link_validate,
  864. };
  865. /*
  866. * omap3isp_ccp2_unregister_entities - Unregister media entities: subdev
  867. * @ccp2: Pointer to ISP CCP2 device
  868. */
  869. void omap3isp_ccp2_unregister_entities(struct isp_ccp2_device *ccp2)
  870. {
  871. v4l2_device_unregister_subdev(&ccp2->subdev);
  872. omap3isp_video_unregister(&ccp2->video_in);
  873. }
  874. /*
  875. * omap3isp_ccp2_register_entities - Register the subdev media entity
  876. * @ccp2: Pointer to ISP CCP2 device
  877. * @vdev: Pointer to v4l device
  878. * return negative error code or zero on success
  879. */
  880. int omap3isp_ccp2_register_entities(struct isp_ccp2_device *ccp2,
  881. struct v4l2_device *vdev)
  882. {
  883. int ret;
  884. /* Register the subdev and video nodes. */
  885. ccp2->subdev.dev = vdev->mdev->dev;
  886. ret = v4l2_device_register_subdev(vdev, &ccp2->subdev);
  887. if (ret < 0)
  888. goto error;
  889. ret = omap3isp_video_register(&ccp2->video_in, vdev);
  890. if (ret < 0)
  891. goto error;
  892. return 0;
  893. error:
  894. omap3isp_ccp2_unregister_entities(ccp2);
  895. return ret;
  896. }
  897. /* -----------------------------------------------------------------------------
  898. * ISP ccp2 initialisation and cleanup
  899. */
  900. /*
  901. * ccp2_init_entities - Initialize ccp2 subdev and media entity.
  902. * @ccp2: Pointer to ISP CCP2 device
  903. * return negative error code or zero on success
  904. */
  905. static int ccp2_init_entities(struct isp_ccp2_device *ccp2)
  906. {
  907. struct v4l2_subdev *sd = &ccp2->subdev;
  908. struct media_pad *pads = ccp2->pads;
  909. struct media_entity *me = &sd->entity;
  910. int ret;
  911. ccp2->input = CCP2_INPUT_NONE;
  912. ccp2->output = CCP2_OUTPUT_NONE;
  913. v4l2_subdev_init(sd, &ccp2_sd_ops);
  914. sd->internal_ops = &ccp2_sd_internal_ops;
  915. strlcpy(sd->name, "OMAP3 ISP CCP2", sizeof(sd->name));
  916. sd->grp_id = 1 << 16; /* group ID for isp subdevs */
  917. v4l2_set_subdevdata(sd, ccp2);
  918. sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
  919. pads[CCP2_PAD_SINK].flags = MEDIA_PAD_FL_SINK
  920. | MEDIA_PAD_FL_MUST_CONNECT;
  921. pads[CCP2_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;
  922. me->ops = &ccp2_media_ops;
  923. ret = media_entity_pads_init(me, CCP2_PADS_NUM, pads);
  924. if (ret < 0)
  925. return ret;
  926. ccp2_init_formats(sd, NULL);
  927. /*
  928. * The CCP2 has weird line alignment requirements, possibly caused by
  929. * DPCM8 decompression. Line length for data read from memory must be a
  930. * multiple of 128 bits (16 bytes) in continuous mode (when no padding
  931. * is present at end of lines). Additionally, if padding is used, the
  932. * padded line length must be a multiple of 32 bytes. To simplify the
  933. * implementation we use a fixed 32 bytes alignment regardless of the
  934. * input format and width. If strict 128 bits alignment support is
  935. * required ispvideo will need to be made aware of this special dual
  936. * alignment requirements.
  937. */
  938. ccp2->video_in.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
  939. ccp2->video_in.bpl_alignment = 32;
  940. ccp2->video_in.bpl_max = 0xffffffe0;
  941. ccp2->video_in.isp = to_isp_device(ccp2);
  942. ccp2->video_in.ops = &ccp2_video_ops;
  943. ccp2->video_in.capture_mem = PAGE_ALIGN(4096 * 4096) * 3;
  944. ret = omap3isp_video_init(&ccp2->video_in, "CCP2");
  945. if (ret < 0)
  946. goto error;
  947. return 0;
  948. error:
  949. media_entity_cleanup(&ccp2->subdev.entity);
  950. return ret;
  951. }
  952. /*
  953. * omap3isp_ccp2_init - CCP2 initialization.
  954. * @isp : Pointer to ISP device
  955. * return negative error code or zero on success
  956. */
  957. int omap3isp_ccp2_init(struct isp_device *isp)
  958. {
  959. struct isp_ccp2_device *ccp2 = &isp->isp_ccp2;
  960. int ret;
  961. init_waitqueue_head(&ccp2->wait);
  962. /*
  963. * On the OMAP34xx the CSI1 receiver is operated in the CSIb IO
  964. * complex, which is powered by vdds_csib power rail. Hence the
  965. * request for the regulator.
  966. *
  967. * On the OMAP36xx, the CCP2 uses the CSI PHY1 or PHY2, shared with
  968. * the CSI2c or CSI2a receivers. The PHY then needs to be explicitly
  969. * configured.
  970. *
  971. * TODO: Don't hardcode the usage of PHY1 (shared with CSI2c).
  972. */
  973. if (isp->revision == ISP_REVISION_2_0) {
  974. ccp2->vdds_csib = devm_regulator_get(isp->dev, "vdds_csib");
  975. if (IS_ERR(ccp2->vdds_csib)) {
  976. dev_dbg(isp->dev,
  977. "Could not get regulator vdds_csib\n");
  978. ccp2->vdds_csib = NULL;
  979. }
  980. } else if (isp->revision == ISP_REVISION_15_0) {
  981. ccp2->phy = &isp->isp_csiphy1;
  982. }
  983. ret = ccp2_init_entities(ccp2);
  984. if (ret < 0)
  985. return ret;
  986. ccp2_reset(ccp2);
  987. return 0;
  988. }
  989. /*
  990. * omap3isp_ccp2_cleanup - CCP2 un-initialization
  991. * @isp : Pointer to ISP device
  992. */
  993. void omap3isp_ccp2_cleanup(struct isp_device *isp)
  994. {
  995. struct isp_ccp2_device *ccp2 = &isp->isp_ccp2;
  996. omap3isp_video_cleanup(&ccp2->video_in);
  997. media_entity_cleanup(&ccp2->subdev.entity);
  998. }