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