ispccp2.c 34 KB

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