ispccp2.c 34 KB

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