ispccp2.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196
  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)
  221. dev_warn(isp->dev, "OMAP3 CCP2 bus not available\n");
  222. if (pdata->phy_layer == ISPCCP2_CTRL_PHY_SEL_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. * ccp2_init_entities - Initialize ccp2 subdev and media entity.
  889. * @ccp2: Pointer to ISP CCP2 device
  890. * return negative error code or zero on success
  891. */
  892. static int ccp2_init_entities(struct isp_ccp2_device *ccp2)
  893. {
  894. struct v4l2_subdev *sd = &ccp2->subdev;
  895. struct media_pad *pads = ccp2->pads;
  896. struct media_entity *me = &sd->entity;
  897. int ret;
  898. ccp2->input = CCP2_INPUT_NONE;
  899. ccp2->output = CCP2_OUTPUT_NONE;
  900. v4l2_subdev_init(sd, &ccp2_sd_ops);
  901. sd->internal_ops = &ccp2_sd_internal_ops;
  902. strlcpy(sd->name, "OMAP3 ISP CCP2", sizeof(sd->name));
  903. sd->grp_id = 1 << 16; /* group ID for isp subdevs */
  904. v4l2_set_subdevdata(sd, ccp2);
  905. sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
  906. pads[CCP2_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
  907. pads[CCP2_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;
  908. me->ops = &ccp2_media_ops;
  909. ret = media_entity_init(me, CCP2_PADS_NUM, pads, 0);
  910. if (ret < 0)
  911. return ret;
  912. ccp2_init_formats(sd, NULL);
  913. /*
  914. * The CCP2 has weird line alignment requirements, possibly caused by
  915. * DPCM8 decompression. Line length for data read from memory must be a
  916. * multiple of 128 bits (16 bytes) in continuous mode (when no padding
  917. * is present at end of lines). Additionally, if padding is used, the
  918. * padded line length must be a multiple of 32 bytes. To simplify the
  919. * implementation we use a fixed 32 bytes alignment regardless of the
  920. * input format and width. If strict 128 bits alignment support is
  921. * required ispvideo will need to be made aware of this special dual
  922. * alignement requirements.
  923. */
  924. ccp2->video_in.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
  925. ccp2->video_in.bpl_alignment = 32;
  926. ccp2->video_in.bpl_max = 0xffffffe0;
  927. ccp2->video_in.isp = to_isp_device(ccp2);
  928. ccp2->video_in.ops = &ccp2_video_ops;
  929. ccp2->video_in.capture_mem = PAGE_ALIGN(4096 * 4096) * 3;
  930. ret = omap3isp_video_init(&ccp2->video_in, "CCP2");
  931. if (ret < 0)
  932. return ret;
  933. /* Connect the video node to the ccp2 subdev. */
  934. ret = media_entity_create_link(&ccp2->video_in.video.entity, 0,
  935. &ccp2->subdev.entity, CCP2_PAD_SINK, 0);
  936. if (ret < 0)
  937. return ret;
  938. return 0;
  939. }
  940. /*
  941. * omap3isp_ccp2_unregister_entities - Unregister media entities: subdev
  942. * @ccp2: Pointer to ISP CCP2 device
  943. */
  944. void omap3isp_ccp2_unregister_entities(struct isp_ccp2_device *ccp2)
  945. {
  946. media_entity_cleanup(&ccp2->subdev.entity);
  947. v4l2_device_unregister_subdev(&ccp2->subdev);
  948. omap3isp_video_unregister(&ccp2->video_in);
  949. }
  950. /*
  951. * omap3isp_ccp2_register_entities - Register the subdev media entity
  952. * @ccp2: Pointer to ISP CCP2 device
  953. * @vdev: Pointer to v4l device
  954. * return negative error code or zero on success
  955. */
  956. int omap3isp_ccp2_register_entities(struct isp_ccp2_device *ccp2,
  957. struct v4l2_device *vdev)
  958. {
  959. int ret;
  960. /* Register the subdev and video nodes. */
  961. ret = v4l2_device_register_subdev(vdev, &ccp2->subdev);
  962. if (ret < 0)
  963. goto error;
  964. ret = omap3isp_video_register(&ccp2->video_in, vdev);
  965. if (ret < 0)
  966. goto error;
  967. return 0;
  968. error:
  969. omap3isp_ccp2_unregister_entities(ccp2);
  970. return ret;
  971. }
  972. /* -----------------------------------------------------------------------------
  973. * ISP ccp2 initialisation and cleanup
  974. */
  975. /*
  976. * omap3isp_ccp2_cleanup - CCP2 un-initialization
  977. * @isp : Pointer to ISP device
  978. */
  979. void omap3isp_ccp2_cleanup(struct isp_device *isp)
  980. {
  981. struct isp_ccp2_device *ccp2 = &isp->isp_ccp2;
  982. regulator_put(ccp2->vdds_csib);
  983. }
  984. /*
  985. * omap3isp_ccp2_init - CCP2 initialization.
  986. * @isp : Pointer to ISP device
  987. * return negative error code or zero on success
  988. */
  989. int omap3isp_ccp2_init(struct isp_device *isp)
  990. {
  991. struct isp_ccp2_device *ccp2 = &isp->isp_ccp2;
  992. int ret;
  993. init_waitqueue_head(&ccp2->wait);
  994. /*
  995. * On the OMAP34xx the CSI1 receiver is operated in the CSIb IO
  996. * complex, which is powered by vdds_csib power rail. Hence the
  997. * request for the regulator.
  998. *
  999. * On the OMAP36xx, the CCP2 uses the CSI PHY1 or PHY2, shared with
  1000. * the CSI2c or CSI2a receivers. The PHY then needs to be explicitly
  1001. * configured.
  1002. *
  1003. * TODO: Don't hardcode the usage of PHY1 (shared with CSI2c).
  1004. */
  1005. if (isp->revision == ISP_REVISION_2_0) {
  1006. ccp2->vdds_csib = regulator_get(isp->dev, "vdds_csib");
  1007. if (IS_ERR(ccp2->vdds_csib)) {
  1008. dev_dbg(isp->dev,
  1009. "Could not get regulator vdds_csib\n");
  1010. ccp2->vdds_csib = NULL;
  1011. }
  1012. } else if (isp->revision == ISP_REVISION_15_0) {
  1013. ccp2->phy = &isp->isp_csiphy1;
  1014. }
  1015. ret = ccp2_init_entities(ccp2);
  1016. if (ret < 0)
  1017. goto out;
  1018. ccp2_reset(ccp2);
  1019. out:
  1020. if (ret)
  1021. omap3isp_ccp2_cleanup(isp);
  1022. return ret;
  1023. }