ispccp2.c 34 KB

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