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