dm644x_ccdc.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034
  1. /*
  2. * Copyright (C) 2006-2009 Texas Instruments Inc
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * CCDC hardware module for DM6446
  15. * ------------------------------
  16. *
  17. * This module is for configuring CCD controller of DM6446 VPFE to capture
  18. * Raw yuv or Bayer RGB data from a decoder. CCDC has several modules
  19. * such as Defect Pixel Correction, Color Space Conversion etc to
  20. * pre-process the Raw Bayer RGB data, before writing it to SDRAM. This
  21. * module also allows application to configure individual
  22. * module parameters through VPFE_CMD_S_CCDC_RAW_PARAMS IOCTL.
  23. * To do so, application includes dm644x_ccdc.h and vpfe_capture.h header
  24. * files. The setparams() API is called by vpfe_capture driver
  25. * to configure module parameters. This file is named DM644x so that other
  26. * variants such DM6443 may be supported using the same module.
  27. *
  28. * TODO: Test Raw bayer parameter settings and bayer capture
  29. * Split module parameter structure to module specific ioctl structs
  30. * investigate if enum used for user space type definition
  31. * to be replaced by #defines or integer
  32. */
  33. #include <linux/platform_device.h>
  34. #include <linux/uaccess.h>
  35. #include <linux/videodev2.h>
  36. #include <linux/gfp.h>
  37. #include <linux/err.h>
  38. #include <linux/module.h>
  39. #include <media/davinci/dm644x_ccdc.h>
  40. #include <media/davinci/vpss.h>
  41. #include "dm644x_ccdc_regs.h"
  42. #include "ccdc_hw_device.h"
  43. MODULE_LICENSE("GPL");
  44. MODULE_DESCRIPTION("CCDC Driver for DM6446");
  45. MODULE_AUTHOR("Texas Instruments");
  46. static struct ccdc_oper_config {
  47. struct device *dev;
  48. /* CCDC interface type */
  49. enum vpfe_hw_if_type if_type;
  50. /* Raw Bayer configuration */
  51. struct ccdc_params_raw bayer;
  52. /* YCbCr configuration */
  53. struct ccdc_params_ycbcr ycbcr;
  54. /* ccdc base address */
  55. void __iomem *base_addr;
  56. } ccdc_cfg = {
  57. /* Raw configurations */
  58. .bayer = {
  59. .pix_fmt = CCDC_PIXFMT_RAW,
  60. .frm_fmt = CCDC_FRMFMT_PROGRESSIVE,
  61. .win = CCDC_WIN_VGA,
  62. .fid_pol = VPFE_PINPOL_POSITIVE,
  63. .vd_pol = VPFE_PINPOL_POSITIVE,
  64. .hd_pol = VPFE_PINPOL_POSITIVE,
  65. .config_params = {
  66. .data_sz = CCDC_DATA_10BITS,
  67. },
  68. },
  69. .ycbcr = {
  70. .pix_fmt = CCDC_PIXFMT_YCBCR_8BIT,
  71. .frm_fmt = CCDC_FRMFMT_INTERLACED,
  72. .win = CCDC_WIN_PAL,
  73. .fid_pol = VPFE_PINPOL_POSITIVE,
  74. .vd_pol = VPFE_PINPOL_POSITIVE,
  75. .hd_pol = VPFE_PINPOL_POSITIVE,
  76. .bt656_enable = 1,
  77. .pix_order = CCDC_PIXORDER_CBYCRY,
  78. .buf_type = CCDC_BUFTYPE_FLD_INTERLEAVED
  79. },
  80. };
  81. #define CCDC_MAX_RAW_YUV_FORMATS 2
  82. /* Raw Bayer formats */
  83. static u32 ccdc_raw_bayer_pix_formats[] =
  84. {V4L2_PIX_FMT_SBGGR8, V4L2_PIX_FMT_SBGGR16};
  85. /* Raw YUV formats */
  86. static u32 ccdc_raw_yuv_pix_formats[] =
  87. {V4L2_PIX_FMT_UYVY, V4L2_PIX_FMT_YUYV};
  88. /* CCDC Save/Restore context */
  89. static u32 ccdc_ctx[CCDC_REG_END / sizeof(u32)];
  90. /* register access routines */
  91. static inline u32 regr(u32 offset)
  92. {
  93. return __raw_readl(ccdc_cfg.base_addr + offset);
  94. }
  95. static inline void regw(u32 val, u32 offset)
  96. {
  97. __raw_writel(val, ccdc_cfg.base_addr + offset);
  98. }
  99. static void ccdc_enable(int flag)
  100. {
  101. regw(flag, CCDC_PCR);
  102. }
  103. static void ccdc_enable_vport(int flag)
  104. {
  105. if (flag)
  106. /* enable video port */
  107. regw(CCDC_ENABLE_VIDEO_PORT, CCDC_FMTCFG);
  108. else
  109. regw(CCDC_DISABLE_VIDEO_PORT, CCDC_FMTCFG);
  110. }
  111. /*
  112. * ccdc_setwin()
  113. * This function will configure the window size
  114. * to be capture in CCDC reg
  115. */
  116. static void ccdc_setwin(struct v4l2_rect *image_win,
  117. enum ccdc_frmfmt frm_fmt,
  118. int ppc)
  119. {
  120. int horz_start, horz_nr_pixels;
  121. int vert_start, vert_nr_lines;
  122. int val = 0, mid_img = 0;
  123. dev_dbg(ccdc_cfg.dev, "\nStarting ccdc_setwin...");
  124. /*
  125. * ppc - per pixel count. indicates how many pixels per cell
  126. * output to SDRAM. example, for ycbcr, it is one y and one c, so 2.
  127. * raw capture this is 1
  128. */
  129. horz_start = image_win->left << (ppc - 1);
  130. horz_nr_pixels = (image_win->width << (ppc - 1)) - 1;
  131. regw((horz_start << CCDC_HORZ_INFO_SPH_SHIFT) | horz_nr_pixels,
  132. CCDC_HORZ_INFO);
  133. vert_start = image_win->top;
  134. if (frm_fmt == CCDC_FRMFMT_INTERLACED) {
  135. vert_nr_lines = (image_win->height >> 1) - 1;
  136. vert_start >>= 1;
  137. /* Since first line doesn't have any data */
  138. vert_start += 1;
  139. /* configure VDINT0 */
  140. val = (vert_start << CCDC_VDINT_VDINT0_SHIFT);
  141. regw(val, CCDC_VDINT);
  142. } else {
  143. /* Since first line doesn't have any data */
  144. vert_start += 1;
  145. vert_nr_lines = image_win->height - 1;
  146. /*
  147. * configure VDINT0 and VDINT1. VDINT1 will be at half
  148. * of image height
  149. */
  150. mid_img = vert_start + (image_win->height / 2);
  151. val = (vert_start << CCDC_VDINT_VDINT0_SHIFT) |
  152. (mid_img & CCDC_VDINT_VDINT1_MASK);
  153. regw(val, CCDC_VDINT);
  154. }
  155. regw((vert_start << CCDC_VERT_START_SLV0_SHIFT) | vert_start,
  156. CCDC_VERT_START);
  157. regw(vert_nr_lines, CCDC_VERT_LINES);
  158. dev_dbg(ccdc_cfg.dev, "\nEnd of ccdc_setwin...");
  159. }
  160. static void ccdc_readregs(void)
  161. {
  162. unsigned int val = 0;
  163. val = regr(CCDC_ALAW);
  164. dev_notice(ccdc_cfg.dev, "\nReading 0x%x to ALAW...\n", val);
  165. val = regr(CCDC_CLAMP);
  166. dev_notice(ccdc_cfg.dev, "\nReading 0x%x to CLAMP...\n", val);
  167. val = regr(CCDC_DCSUB);
  168. dev_notice(ccdc_cfg.dev, "\nReading 0x%x to DCSUB...\n", val);
  169. val = regr(CCDC_BLKCMP);
  170. dev_notice(ccdc_cfg.dev, "\nReading 0x%x to BLKCMP...\n", val);
  171. val = regr(CCDC_FPC_ADDR);
  172. dev_notice(ccdc_cfg.dev, "\nReading 0x%x to FPC_ADDR...\n", val);
  173. val = regr(CCDC_FPC);
  174. dev_notice(ccdc_cfg.dev, "\nReading 0x%x to FPC...\n", val);
  175. val = regr(CCDC_FMTCFG);
  176. dev_notice(ccdc_cfg.dev, "\nReading 0x%x to FMTCFG...\n", val);
  177. val = regr(CCDC_COLPTN);
  178. dev_notice(ccdc_cfg.dev, "\nReading 0x%x to COLPTN...\n", val);
  179. val = regr(CCDC_FMT_HORZ);
  180. dev_notice(ccdc_cfg.dev, "\nReading 0x%x to FMT_HORZ...\n", val);
  181. val = regr(CCDC_FMT_VERT);
  182. dev_notice(ccdc_cfg.dev, "\nReading 0x%x to FMT_VERT...\n", val);
  183. val = regr(CCDC_HSIZE_OFF);
  184. dev_notice(ccdc_cfg.dev, "\nReading 0x%x to HSIZE_OFF...\n", val);
  185. val = regr(CCDC_SDOFST);
  186. dev_notice(ccdc_cfg.dev, "\nReading 0x%x to SDOFST...\n", val);
  187. val = regr(CCDC_VP_OUT);
  188. dev_notice(ccdc_cfg.dev, "\nReading 0x%x to VP_OUT...\n", val);
  189. val = regr(CCDC_SYN_MODE);
  190. dev_notice(ccdc_cfg.dev, "\nReading 0x%x to SYN_MODE...\n", val);
  191. val = regr(CCDC_HORZ_INFO);
  192. dev_notice(ccdc_cfg.dev, "\nReading 0x%x to HORZ_INFO...\n", val);
  193. val = regr(CCDC_VERT_START);
  194. dev_notice(ccdc_cfg.dev, "\nReading 0x%x to VERT_START...\n", val);
  195. val = regr(CCDC_VERT_LINES);
  196. dev_notice(ccdc_cfg.dev, "\nReading 0x%x to VERT_LINES...\n", val);
  197. }
  198. static int validate_ccdc_param(struct ccdc_config_params_raw *ccdcparam)
  199. {
  200. if (ccdcparam->alaw.enable) {
  201. u8 max_gamma = ccdc_gamma_width_max_bit(ccdcparam->alaw.gamma_wd);
  202. u8 max_data = ccdc_data_size_max_bit(ccdcparam->data_sz);
  203. if ((ccdcparam->alaw.gamma_wd > CCDC_GAMMA_BITS_09_0) ||
  204. (ccdcparam->alaw.gamma_wd < CCDC_GAMMA_BITS_15_6) ||
  205. (max_gamma > max_data)) {
  206. dev_dbg(ccdc_cfg.dev, "\nInvalid data line select");
  207. return -1;
  208. }
  209. }
  210. return 0;
  211. }
  212. static int ccdc_update_raw_params(struct ccdc_config_params_raw *raw_params)
  213. {
  214. struct ccdc_config_params_raw *config_params =
  215. &ccdc_cfg.bayer.config_params;
  216. unsigned int *fpc_virtaddr = NULL;
  217. unsigned int *fpc_physaddr = NULL;
  218. memcpy(config_params, raw_params, sizeof(*raw_params));
  219. /*
  220. * allocate memory for fault pixel table and copy the user
  221. * values to the table
  222. */
  223. if (!config_params->fault_pxl.enable)
  224. return 0;
  225. fpc_physaddr = (unsigned int *)config_params->fault_pxl.fpc_table_addr;
  226. fpc_virtaddr = (unsigned int *)phys_to_virt(
  227. (unsigned long)fpc_physaddr);
  228. /*
  229. * Allocate memory for FPC table if current
  230. * FPC table buffer is not big enough to
  231. * accommodate FPC Number requested
  232. */
  233. if (raw_params->fault_pxl.fp_num != config_params->fault_pxl.fp_num) {
  234. if (fpc_physaddr != NULL) {
  235. free_pages((unsigned long)fpc_virtaddr,
  236. get_order
  237. (config_params->fault_pxl.fp_num *
  238. FP_NUM_BYTES));
  239. }
  240. /* Allocate memory for FPC table */
  241. fpc_virtaddr =
  242. (unsigned int *)__get_free_pages(GFP_KERNEL | GFP_DMA,
  243. get_order(raw_params->
  244. fault_pxl.fp_num *
  245. FP_NUM_BYTES));
  246. if (fpc_virtaddr == NULL) {
  247. dev_dbg(ccdc_cfg.dev,
  248. "\nUnable to allocate memory for FPC");
  249. return -EFAULT;
  250. }
  251. fpc_physaddr =
  252. (unsigned int *)virt_to_phys((void *)fpc_virtaddr);
  253. }
  254. /* Copy number of fault pixels and FPC table */
  255. config_params->fault_pxl.fp_num = raw_params->fault_pxl.fp_num;
  256. if (copy_from_user(fpc_virtaddr,
  257. (void __user *)raw_params->fault_pxl.fpc_table_addr,
  258. config_params->fault_pxl.fp_num * FP_NUM_BYTES)) {
  259. dev_dbg(ccdc_cfg.dev, "\n copy_from_user failed");
  260. return -EFAULT;
  261. }
  262. config_params->fault_pxl.fpc_table_addr = (unsigned long)fpc_physaddr;
  263. return 0;
  264. }
  265. static int ccdc_close(struct device *dev)
  266. {
  267. struct ccdc_config_params_raw *config_params =
  268. &ccdc_cfg.bayer.config_params;
  269. unsigned int *fpc_physaddr = NULL, *fpc_virtaddr = NULL;
  270. fpc_physaddr = (unsigned int *)config_params->fault_pxl.fpc_table_addr;
  271. if (fpc_physaddr != NULL) {
  272. fpc_virtaddr = (unsigned int *)
  273. phys_to_virt((unsigned long)fpc_physaddr);
  274. free_pages((unsigned long)fpc_virtaddr,
  275. get_order(config_params->fault_pxl.fp_num *
  276. FP_NUM_BYTES));
  277. }
  278. return 0;
  279. }
  280. /*
  281. * ccdc_restore_defaults()
  282. * This function will write defaults to all CCDC registers
  283. */
  284. static void ccdc_restore_defaults(void)
  285. {
  286. int i;
  287. /* disable CCDC */
  288. ccdc_enable(0);
  289. /* set all registers to default value */
  290. for (i = 4; i <= 0x94; i += 4)
  291. regw(0, i);
  292. regw(CCDC_NO_CULLING, CCDC_CULLING);
  293. regw(CCDC_GAMMA_BITS_11_2, CCDC_ALAW);
  294. }
  295. static int ccdc_open(struct device *device)
  296. {
  297. ccdc_restore_defaults();
  298. if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
  299. ccdc_enable_vport(1);
  300. return 0;
  301. }
  302. static void ccdc_sbl_reset(void)
  303. {
  304. vpss_clear_wbl_overflow(VPSS_PCR_CCDC_WBL_O);
  305. }
  306. /* Parameter operations */
  307. static int ccdc_set_params(void __user *params)
  308. {
  309. struct ccdc_config_params_raw ccdc_raw_params;
  310. int x;
  311. if (ccdc_cfg.if_type != VPFE_RAW_BAYER)
  312. return -EINVAL;
  313. x = copy_from_user(&ccdc_raw_params, params, sizeof(ccdc_raw_params));
  314. if (x) {
  315. dev_dbg(ccdc_cfg.dev, "ccdc_set_params: error in copyingccdc params, %d\n",
  316. x);
  317. return -EFAULT;
  318. }
  319. if (!validate_ccdc_param(&ccdc_raw_params)) {
  320. if (!ccdc_update_raw_params(&ccdc_raw_params))
  321. return 0;
  322. }
  323. return -EINVAL;
  324. }
  325. /*
  326. * ccdc_config_ycbcr()
  327. * This function will configure CCDC for YCbCr video capture
  328. */
  329. static void ccdc_config_ycbcr(void)
  330. {
  331. struct ccdc_params_ycbcr *params = &ccdc_cfg.ycbcr;
  332. u32 syn_mode;
  333. dev_dbg(ccdc_cfg.dev, "\nStarting ccdc_config_ycbcr...");
  334. /*
  335. * first restore the CCDC registers to default values
  336. * This is important since we assume default values to be set in
  337. * a lot of registers that we didn't touch
  338. */
  339. ccdc_restore_defaults();
  340. /*
  341. * configure pixel format, frame format, configure video frame
  342. * format, enable output to SDRAM, enable internal timing generator
  343. * and 8bit pack mode
  344. */
  345. syn_mode = (((params->pix_fmt & CCDC_SYN_MODE_INPMOD_MASK) <<
  346. CCDC_SYN_MODE_INPMOD_SHIFT) |
  347. ((params->frm_fmt & CCDC_SYN_FLDMODE_MASK) <<
  348. CCDC_SYN_FLDMODE_SHIFT) | CCDC_VDHDEN_ENABLE |
  349. CCDC_WEN_ENABLE | CCDC_DATA_PACK_ENABLE);
  350. /* setup BT.656 sync mode */
  351. if (params->bt656_enable) {
  352. regw(CCDC_REC656IF_BT656_EN, CCDC_REC656IF);
  353. /*
  354. * configure the FID, VD, HD pin polarity,
  355. * fld,hd pol positive, vd negative, 8-bit data
  356. */
  357. syn_mode |= CCDC_SYN_MODE_VD_POL_NEGATIVE;
  358. if (ccdc_cfg.if_type == VPFE_BT656_10BIT)
  359. syn_mode |= CCDC_SYN_MODE_10BITS;
  360. else
  361. syn_mode |= CCDC_SYN_MODE_8BITS;
  362. } else {
  363. /* y/c external sync mode */
  364. syn_mode |= (((params->fid_pol & CCDC_FID_POL_MASK) <<
  365. CCDC_FID_POL_SHIFT) |
  366. ((params->hd_pol & CCDC_HD_POL_MASK) <<
  367. CCDC_HD_POL_SHIFT) |
  368. ((params->vd_pol & CCDC_VD_POL_MASK) <<
  369. CCDC_VD_POL_SHIFT));
  370. }
  371. regw(syn_mode, CCDC_SYN_MODE);
  372. /* configure video window */
  373. ccdc_setwin(&params->win, params->frm_fmt, 2);
  374. /*
  375. * configure the order of y cb cr in SDRAM, and disable latch
  376. * internal register on vsync
  377. */
  378. if (ccdc_cfg.if_type == VPFE_BT656_10BIT)
  379. regw((params->pix_order << CCDC_CCDCFG_Y8POS_SHIFT) |
  380. CCDC_LATCH_ON_VSYNC_DISABLE | CCDC_CCDCFG_BW656_10BIT,
  381. CCDC_CCDCFG);
  382. else
  383. regw((params->pix_order << CCDC_CCDCFG_Y8POS_SHIFT) |
  384. CCDC_LATCH_ON_VSYNC_DISABLE, CCDC_CCDCFG);
  385. /*
  386. * configure the horizontal line offset. This should be a
  387. * on 32 byte boundary. So clear LSB 5 bits
  388. */
  389. regw(((params->win.width * 2 + 31) & ~0x1f), CCDC_HSIZE_OFF);
  390. /* configure the memory line offset */
  391. if (params->buf_type == CCDC_BUFTYPE_FLD_INTERLEAVED)
  392. /* two fields are interleaved in memory */
  393. regw(CCDC_SDOFST_FIELD_INTERLEAVED, CCDC_SDOFST);
  394. ccdc_sbl_reset();
  395. dev_dbg(ccdc_cfg.dev, "\nEnd of ccdc_config_ycbcr...\n");
  396. }
  397. static void ccdc_config_black_clamp(struct ccdc_black_clamp *bclamp)
  398. {
  399. u32 val;
  400. if (!bclamp->enable) {
  401. /* configure DCSub */
  402. val = (bclamp->dc_sub) & CCDC_BLK_DC_SUB_MASK;
  403. regw(val, CCDC_DCSUB);
  404. dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to DCSUB...\n", val);
  405. regw(CCDC_CLAMP_DEFAULT_VAL, CCDC_CLAMP);
  406. dev_dbg(ccdc_cfg.dev, "\nWriting 0x0000 to CLAMP...\n");
  407. return;
  408. }
  409. /*
  410. * Configure gain, Start pixel, No of line to be avg,
  411. * No of pixel/line to be avg, & Enable the Black clamping
  412. */
  413. val = ((bclamp->sgain & CCDC_BLK_SGAIN_MASK) |
  414. ((bclamp->start_pixel & CCDC_BLK_ST_PXL_MASK) <<
  415. CCDC_BLK_ST_PXL_SHIFT) |
  416. ((bclamp->sample_ln & CCDC_BLK_SAMPLE_LINE_MASK) <<
  417. CCDC_BLK_SAMPLE_LINE_SHIFT) |
  418. ((bclamp->sample_pixel & CCDC_BLK_SAMPLE_LN_MASK) <<
  419. CCDC_BLK_SAMPLE_LN_SHIFT) | CCDC_BLK_CLAMP_ENABLE);
  420. regw(val, CCDC_CLAMP);
  421. dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to CLAMP...\n", val);
  422. /* If Black clamping is enable then make dcsub 0 */
  423. regw(CCDC_DCSUB_DEFAULT_VAL, CCDC_DCSUB);
  424. dev_dbg(ccdc_cfg.dev, "\nWriting 0x00000000 to DCSUB...\n");
  425. }
  426. static void ccdc_config_black_compense(struct ccdc_black_compensation *bcomp)
  427. {
  428. u32 val;
  429. val = ((bcomp->b & CCDC_BLK_COMP_MASK) |
  430. ((bcomp->gb & CCDC_BLK_COMP_MASK) <<
  431. CCDC_BLK_COMP_GB_COMP_SHIFT) |
  432. ((bcomp->gr & CCDC_BLK_COMP_MASK) <<
  433. CCDC_BLK_COMP_GR_COMP_SHIFT) |
  434. ((bcomp->r & CCDC_BLK_COMP_MASK) <<
  435. CCDC_BLK_COMP_R_COMP_SHIFT));
  436. regw(val, CCDC_BLKCMP);
  437. }
  438. static void ccdc_config_fpc(struct ccdc_fault_pixel *fpc)
  439. {
  440. u32 val;
  441. /* Initially disable FPC */
  442. val = CCDC_FPC_DISABLE;
  443. regw(val, CCDC_FPC);
  444. if (!fpc->enable)
  445. return;
  446. /* Configure Fault pixel if needed */
  447. regw(fpc->fpc_table_addr, CCDC_FPC_ADDR);
  448. dev_dbg(ccdc_cfg.dev, "\nWriting 0x%lx to FPC_ADDR...\n",
  449. (fpc->fpc_table_addr));
  450. /* Write the FPC params with FPC disable */
  451. val = fpc->fp_num & CCDC_FPC_FPC_NUM_MASK;
  452. regw(val, CCDC_FPC);
  453. dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to FPC...\n", val);
  454. /* read the FPC register */
  455. val = regr(CCDC_FPC) | CCDC_FPC_ENABLE;
  456. regw(val, CCDC_FPC);
  457. dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to FPC...\n", val);
  458. }
  459. /*
  460. * ccdc_config_raw()
  461. * This function will configure CCDC for Raw capture mode
  462. */
  463. static void ccdc_config_raw(void)
  464. {
  465. struct ccdc_params_raw *params = &ccdc_cfg.bayer;
  466. struct ccdc_config_params_raw *config_params =
  467. &ccdc_cfg.bayer.config_params;
  468. unsigned int syn_mode = 0;
  469. unsigned int val;
  470. dev_dbg(ccdc_cfg.dev, "\nStarting ccdc_config_raw...");
  471. /* Reset CCDC */
  472. ccdc_restore_defaults();
  473. /* Disable latching function registers on VSYNC */
  474. regw(CCDC_LATCH_ON_VSYNC_DISABLE, CCDC_CCDCFG);
  475. /*
  476. * Configure the vertical sync polarity(SYN_MODE.VDPOL),
  477. * horizontal sync polarity (SYN_MODE.HDPOL), frame id polarity
  478. * (SYN_MODE.FLDPOL), frame format(progressive or interlace),
  479. * data size(SYNMODE.DATSIZ), &pixel format (Input mode), output
  480. * SDRAM, enable internal timing generator
  481. */
  482. syn_mode =
  483. (((params->vd_pol & CCDC_VD_POL_MASK) << CCDC_VD_POL_SHIFT) |
  484. ((params->hd_pol & CCDC_HD_POL_MASK) << CCDC_HD_POL_SHIFT) |
  485. ((params->fid_pol & CCDC_FID_POL_MASK) << CCDC_FID_POL_SHIFT) |
  486. ((params->frm_fmt & CCDC_FRM_FMT_MASK) << CCDC_FRM_FMT_SHIFT) |
  487. ((config_params->data_sz & CCDC_DATA_SZ_MASK) <<
  488. CCDC_DATA_SZ_SHIFT) |
  489. ((params->pix_fmt & CCDC_PIX_FMT_MASK) << CCDC_PIX_FMT_SHIFT) |
  490. CCDC_WEN_ENABLE | CCDC_VDHDEN_ENABLE);
  491. /* Enable and configure aLaw register if needed */
  492. if (config_params->alaw.enable) {
  493. val = ((config_params->alaw.gamma_wd &
  494. CCDC_ALAW_GAMMA_WD_MASK) | CCDC_ALAW_ENABLE);
  495. regw(val, CCDC_ALAW);
  496. dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to ALAW...\n", val);
  497. }
  498. /* Configure video window */
  499. ccdc_setwin(&params->win, params->frm_fmt, CCDC_PPC_RAW);
  500. /* Configure Black Clamp */
  501. ccdc_config_black_clamp(&config_params->blk_clamp);
  502. /* Configure Black level compensation */
  503. ccdc_config_black_compense(&config_params->blk_comp);
  504. /* Configure Fault Pixel Correction */
  505. ccdc_config_fpc(&config_params->fault_pxl);
  506. /* If data size is 8 bit then pack the data */
  507. if ((config_params->data_sz == CCDC_DATA_8BITS) ||
  508. config_params->alaw.enable)
  509. syn_mode |= CCDC_DATA_PACK_ENABLE;
  510. /* disable video port */
  511. val = CCDC_DISABLE_VIDEO_PORT;
  512. if (config_params->data_sz == CCDC_DATA_8BITS)
  513. val |= (CCDC_DATA_10BITS & CCDC_FMTCFG_VPIN_MASK)
  514. << CCDC_FMTCFG_VPIN_SHIFT;
  515. else
  516. val |= (config_params->data_sz & CCDC_FMTCFG_VPIN_MASK)
  517. << CCDC_FMTCFG_VPIN_SHIFT;
  518. /* Write value in FMTCFG */
  519. regw(val, CCDC_FMTCFG);
  520. dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to FMTCFG...\n", val);
  521. /* Configure the color pattern according to mt9t001 sensor */
  522. regw(CCDC_COLPTN_VAL, CCDC_COLPTN);
  523. dev_dbg(ccdc_cfg.dev, "\nWriting 0xBB11BB11 to COLPTN...\n");
  524. /*
  525. * Configure Data formatter(Video port) pixel selection
  526. * (FMT_HORZ, FMT_VERT)
  527. */
  528. val = ((params->win.left & CCDC_FMT_HORZ_FMTSPH_MASK) <<
  529. CCDC_FMT_HORZ_FMTSPH_SHIFT) |
  530. (params->win.width & CCDC_FMT_HORZ_FMTLNH_MASK);
  531. regw(val, CCDC_FMT_HORZ);
  532. dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to FMT_HORZ...\n", val);
  533. val = (params->win.top & CCDC_FMT_VERT_FMTSLV_MASK)
  534. << CCDC_FMT_VERT_FMTSLV_SHIFT;
  535. if (params->frm_fmt == CCDC_FRMFMT_PROGRESSIVE)
  536. val |= (params->win.height) & CCDC_FMT_VERT_FMTLNV_MASK;
  537. else
  538. val |= (params->win.height >> 1) & CCDC_FMT_VERT_FMTLNV_MASK;
  539. dev_dbg(ccdc_cfg.dev, "\nparams->win.height 0x%x ...\n",
  540. params->win.height);
  541. regw(val, CCDC_FMT_VERT);
  542. dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to FMT_VERT...\n", val);
  543. dev_dbg(ccdc_cfg.dev, "\nbelow regw(val, FMT_VERT)...");
  544. /*
  545. * Configure Horizontal offset register. If pack 8 is enabled then
  546. * 1 pixel will take 1 byte
  547. */
  548. if ((config_params->data_sz == CCDC_DATA_8BITS) ||
  549. config_params->alaw.enable)
  550. regw((params->win.width + CCDC_32BYTE_ALIGN_VAL) &
  551. CCDC_HSIZE_OFF_MASK, CCDC_HSIZE_OFF);
  552. else
  553. /* else one pixel will take 2 byte */
  554. regw(((params->win.width * CCDC_TWO_BYTES_PER_PIXEL) +
  555. CCDC_32BYTE_ALIGN_VAL) & CCDC_HSIZE_OFF_MASK,
  556. CCDC_HSIZE_OFF);
  557. /* Set value for SDOFST */
  558. if (params->frm_fmt == CCDC_FRMFMT_INTERLACED) {
  559. if (params->image_invert_enable) {
  560. /* For intelace inverse mode */
  561. regw(CCDC_INTERLACED_IMAGE_INVERT, CCDC_SDOFST);
  562. dev_dbg(ccdc_cfg.dev, "\nWriting 0x4B6D to SDOFST..\n");
  563. }
  564. else {
  565. /* For intelace non inverse mode */
  566. regw(CCDC_INTERLACED_NO_IMAGE_INVERT, CCDC_SDOFST);
  567. dev_dbg(ccdc_cfg.dev, "\nWriting 0x0249 to SDOFST..\n");
  568. }
  569. } else if (params->frm_fmt == CCDC_FRMFMT_PROGRESSIVE) {
  570. regw(CCDC_PROGRESSIVE_NO_IMAGE_INVERT, CCDC_SDOFST);
  571. dev_dbg(ccdc_cfg.dev, "\nWriting 0x0000 to SDOFST...\n");
  572. }
  573. /*
  574. * Configure video port pixel selection (VPOUT)
  575. * Here -1 is to make the height value less than FMT_VERT.FMTLNV
  576. */
  577. if (params->frm_fmt == CCDC_FRMFMT_PROGRESSIVE)
  578. val = (((params->win.height - 1) & CCDC_VP_OUT_VERT_NUM_MASK))
  579. << CCDC_VP_OUT_VERT_NUM_SHIFT;
  580. else
  581. val =
  582. ((((params->win.height >> CCDC_INTERLACED_HEIGHT_SHIFT) -
  583. 1) & CCDC_VP_OUT_VERT_NUM_MASK)) <<
  584. CCDC_VP_OUT_VERT_NUM_SHIFT;
  585. val |= ((((params->win.width))) & CCDC_VP_OUT_HORZ_NUM_MASK)
  586. << CCDC_VP_OUT_HORZ_NUM_SHIFT;
  587. val |= (params->win.left) & CCDC_VP_OUT_HORZ_ST_MASK;
  588. regw(val, CCDC_VP_OUT);
  589. dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to VP_OUT...\n", val);
  590. regw(syn_mode, CCDC_SYN_MODE);
  591. dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to SYN_MODE...\n", syn_mode);
  592. ccdc_sbl_reset();
  593. dev_dbg(ccdc_cfg.dev, "\nend of ccdc_config_raw...");
  594. ccdc_readregs();
  595. }
  596. static int ccdc_configure(void)
  597. {
  598. if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
  599. ccdc_config_raw();
  600. else
  601. ccdc_config_ycbcr();
  602. return 0;
  603. }
  604. static int ccdc_set_buftype(enum ccdc_buftype buf_type)
  605. {
  606. if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
  607. ccdc_cfg.bayer.buf_type = buf_type;
  608. else
  609. ccdc_cfg.ycbcr.buf_type = buf_type;
  610. return 0;
  611. }
  612. static enum ccdc_buftype ccdc_get_buftype(void)
  613. {
  614. if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
  615. return ccdc_cfg.bayer.buf_type;
  616. return ccdc_cfg.ycbcr.buf_type;
  617. }
  618. static int ccdc_enum_pix(u32 *pix, int i)
  619. {
  620. int ret = -EINVAL;
  621. if (ccdc_cfg.if_type == VPFE_RAW_BAYER) {
  622. if (i < ARRAY_SIZE(ccdc_raw_bayer_pix_formats)) {
  623. *pix = ccdc_raw_bayer_pix_formats[i];
  624. ret = 0;
  625. }
  626. } else {
  627. if (i < ARRAY_SIZE(ccdc_raw_yuv_pix_formats)) {
  628. *pix = ccdc_raw_yuv_pix_formats[i];
  629. ret = 0;
  630. }
  631. }
  632. return ret;
  633. }
  634. static int ccdc_set_pixel_format(u32 pixfmt)
  635. {
  636. if (ccdc_cfg.if_type == VPFE_RAW_BAYER) {
  637. ccdc_cfg.bayer.pix_fmt = CCDC_PIXFMT_RAW;
  638. if (pixfmt == V4L2_PIX_FMT_SBGGR8)
  639. ccdc_cfg.bayer.config_params.alaw.enable = 1;
  640. else if (pixfmt != V4L2_PIX_FMT_SBGGR16)
  641. return -EINVAL;
  642. } else {
  643. if (pixfmt == V4L2_PIX_FMT_YUYV)
  644. ccdc_cfg.ycbcr.pix_order = CCDC_PIXORDER_YCBYCR;
  645. else if (pixfmt == V4L2_PIX_FMT_UYVY)
  646. ccdc_cfg.ycbcr.pix_order = CCDC_PIXORDER_CBYCRY;
  647. else
  648. return -EINVAL;
  649. }
  650. return 0;
  651. }
  652. static u32 ccdc_get_pixel_format(void)
  653. {
  654. struct ccdc_a_law *alaw = &ccdc_cfg.bayer.config_params.alaw;
  655. u32 pixfmt;
  656. if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
  657. if (alaw->enable)
  658. pixfmt = V4L2_PIX_FMT_SBGGR8;
  659. else
  660. pixfmt = V4L2_PIX_FMT_SBGGR16;
  661. else {
  662. if (ccdc_cfg.ycbcr.pix_order == CCDC_PIXORDER_YCBYCR)
  663. pixfmt = V4L2_PIX_FMT_YUYV;
  664. else
  665. pixfmt = V4L2_PIX_FMT_UYVY;
  666. }
  667. return pixfmt;
  668. }
  669. static int ccdc_set_image_window(struct v4l2_rect *win)
  670. {
  671. if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
  672. ccdc_cfg.bayer.win = *win;
  673. else
  674. ccdc_cfg.ycbcr.win = *win;
  675. return 0;
  676. }
  677. static void ccdc_get_image_window(struct v4l2_rect *win)
  678. {
  679. if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
  680. *win = ccdc_cfg.bayer.win;
  681. else
  682. *win = ccdc_cfg.ycbcr.win;
  683. }
  684. static unsigned int ccdc_get_line_length(void)
  685. {
  686. struct ccdc_config_params_raw *config_params =
  687. &ccdc_cfg.bayer.config_params;
  688. unsigned int len;
  689. if (ccdc_cfg.if_type == VPFE_RAW_BAYER) {
  690. if ((config_params->alaw.enable) ||
  691. (config_params->data_sz == CCDC_DATA_8BITS))
  692. len = ccdc_cfg.bayer.win.width;
  693. else
  694. len = ccdc_cfg.bayer.win.width * 2;
  695. } else
  696. len = ccdc_cfg.ycbcr.win.width * 2;
  697. return ALIGN(len, 32);
  698. }
  699. static int ccdc_set_frame_format(enum ccdc_frmfmt frm_fmt)
  700. {
  701. if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
  702. ccdc_cfg.bayer.frm_fmt = frm_fmt;
  703. else
  704. ccdc_cfg.ycbcr.frm_fmt = frm_fmt;
  705. return 0;
  706. }
  707. static enum ccdc_frmfmt ccdc_get_frame_format(void)
  708. {
  709. if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
  710. return ccdc_cfg.bayer.frm_fmt;
  711. else
  712. return ccdc_cfg.ycbcr.frm_fmt;
  713. }
  714. static int ccdc_getfid(void)
  715. {
  716. return (regr(CCDC_SYN_MODE) >> 15) & 1;
  717. }
  718. /* misc operations */
  719. static inline void ccdc_setfbaddr(unsigned long addr)
  720. {
  721. regw(addr & 0xffffffe0, CCDC_SDR_ADDR);
  722. }
  723. static int ccdc_set_hw_if_params(struct vpfe_hw_if_param *params)
  724. {
  725. ccdc_cfg.if_type = params->if_type;
  726. switch (params->if_type) {
  727. case VPFE_BT656:
  728. case VPFE_YCBCR_SYNC_16:
  729. case VPFE_YCBCR_SYNC_8:
  730. case VPFE_BT656_10BIT:
  731. ccdc_cfg.ycbcr.vd_pol = params->vdpol;
  732. ccdc_cfg.ycbcr.hd_pol = params->hdpol;
  733. break;
  734. default:
  735. /* TODO add support for raw bayer here */
  736. return -EINVAL;
  737. }
  738. return 0;
  739. }
  740. static void ccdc_save_context(void)
  741. {
  742. ccdc_ctx[CCDC_PCR >> 2] = regr(CCDC_PCR);
  743. ccdc_ctx[CCDC_SYN_MODE >> 2] = regr(CCDC_SYN_MODE);
  744. ccdc_ctx[CCDC_HD_VD_WID >> 2] = regr(CCDC_HD_VD_WID);
  745. ccdc_ctx[CCDC_PIX_LINES >> 2] = regr(CCDC_PIX_LINES);
  746. ccdc_ctx[CCDC_HORZ_INFO >> 2] = regr(CCDC_HORZ_INFO);
  747. ccdc_ctx[CCDC_VERT_START >> 2] = regr(CCDC_VERT_START);
  748. ccdc_ctx[CCDC_VERT_LINES >> 2] = regr(CCDC_VERT_LINES);
  749. ccdc_ctx[CCDC_CULLING >> 2] = regr(CCDC_CULLING);
  750. ccdc_ctx[CCDC_HSIZE_OFF >> 2] = regr(CCDC_HSIZE_OFF);
  751. ccdc_ctx[CCDC_SDOFST >> 2] = regr(CCDC_SDOFST);
  752. ccdc_ctx[CCDC_SDR_ADDR >> 2] = regr(CCDC_SDR_ADDR);
  753. ccdc_ctx[CCDC_CLAMP >> 2] = regr(CCDC_CLAMP);
  754. ccdc_ctx[CCDC_DCSUB >> 2] = regr(CCDC_DCSUB);
  755. ccdc_ctx[CCDC_COLPTN >> 2] = regr(CCDC_COLPTN);
  756. ccdc_ctx[CCDC_BLKCMP >> 2] = regr(CCDC_BLKCMP);
  757. ccdc_ctx[CCDC_FPC >> 2] = regr(CCDC_FPC);
  758. ccdc_ctx[CCDC_FPC_ADDR >> 2] = regr(CCDC_FPC_ADDR);
  759. ccdc_ctx[CCDC_VDINT >> 2] = regr(CCDC_VDINT);
  760. ccdc_ctx[CCDC_ALAW >> 2] = regr(CCDC_ALAW);
  761. ccdc_ctx[CCDC_REC656IF >> 2] = regr(CCDC_REC656IF);
  762. ccdc_ctx[CCDC_CCDCFG >> 2] = regr(CCDC_CCDCFG);
  763. ccdc_ctx[CCDC_FMTCFG >> 2] = regr(CCDC_FMTCFG);
  764. ccdc_ctx[CCDC_FMT_HORZ >> 2] = regr(CCDC_FMT_HORZ);
  765. ccdc_ctx[CCDC_FMT_VERT >> 2] = regr(CCDC_FMT_VERT);
  766. ccdc_ctx[CCDC_FMT_ADDR0 >> 2] = regr(CCDC_FMT_ADDR0);
  767. ccdc_ctx[CCDC_FMT_ADDR1 >> 2] = regr(CCDC_FMT_ADDR1);
  768. ccdc_ctx[CCDC_FMT_ADDR2 >> 2] = regr(CCDC_FMT_ADDR2);
  769. ccdc_ctx[CCDC_FMT_ADDR3 >> 2] = regr(CCDC_FMT_ADDR3);
  770. ccdc_ctx[CCDC_FMT_ADDR4 >> 2] = regr(CCDC_FMT_ADDR4);
  771. ccdc_ctx[CCDC_FMT_ADDR5 >> 2] = regr(CCDC_FMT_ADDR5);
  772. ccdc_ctx[CCDC_FMT_ADDR6 >> 2] = regr(CCDC_FMT_ADDR6);
  773. ccdc_ctx[CCDC_FMT_ADDR7 >> 2] = regr(CCDC_FMT_ADDR7);
  774. ccdc_ctx[CCDC_PRGEVEN_0 >> 2] = regr(CCDC_PRGEVEN_0);
  775. ccdc_ctx[CCDC_PRGEVEN_1 >> 2] = regr(CCDC_PRGEVEN_1);
  776. ccdc_ctx[CCDC_PRGODD_0 >> 2] = regr(CCDC_PRGODD_0);
  777. ccdc_ctx[CCDC_PRGODD_1 >> 2] = regr(CCDC_PRGODD_1);
  778. ccdc_ctx[CCDC_VP_OUT >> 2] = regr(CCDC_VP_OUT);
  779. }
  780. static void ccdc_restore_context(void)
  781. {
  782. regw(ccdc_ctx[CCDC_SYN_MODE >> 2], CCDC_SYN_MODE);
  783. regw(ccdc_ctx[CCDC_HD_VD_WID >> 2], CCDC_HD_VD_WID);
  784. regw(ccdc_ctx[CCDC_PIX_LINES >> 2], CCDC_PIX_LINES);
  785. regw(ccdc_ctx[CCDC_HORZ_INFO >> 2], CCDC_HORZ_INFO);
  786. regw(ccdc_ctx[CCDC_VERT_START >> 2], CCDC_VERT_START);
  787. regw(ccdc_ctx[CCDC_VERT_LINES >> 2], CCDC_VERT_LINES);
  788. regw(ccdc_ctx[CCDC_CULLING >> 2], CCDC_CULLING);
  789. regw(ccdc_ctx[CCDC_HSIZE_OFF >> 2], CCDC_HSIZE_OFF);
  790. regw(ccdc_ctx[CCDC_SDOFST >> 2], CCDC_SDOFST);
  791. regw(ccdc_ctx[CCDC_SDR_ADDR >> 2], CCDC_SDR_ADDR);
  792. regw(ccdc_ctx[CCDC_CLAMP >> 2], CCDC_CLAMP);
  793. regw(ccdc_ctx[CCDC_DCSUB >> 2], CCDC_DCSUB);
  794. regw(ccdc_ctx[CCDC_COLPTN >> 2], CCDC_COLPTN);
  795. regw(ccdc_ctx[CCDC_BLKCMP >> 2], CCDC_BLKCMP);
  796. regw(ccdc_ctx[CCDC_FPC >> 2], CCDC_FPC);
  797. regw(ccdc_ctx[CCDC_FPC_ADDR >> 2], CCDC_FPC_ADDR);
  798. regw(ccdc_ctx[CCDC_VDINT >> 2], CCDC_VDINT);
  799. regw(ccdc_ctx[CCDC_ALAW >> 2], CCDC_ALAW);
  800. regw(ccdc_ctx[CCDC_REC656IF >> 2], CCDC_REC656IF);
  801. regw(ccdc_ctx[CCDC_CCDCFG >> 2], CCDC_CCDCFG);
  802. regw(ccdc_ctx[CCDC_FMTCFG >> 2], CCDC_FMTCFG);
  803. regw(ccdc_ctx[CCDC_FMT_HORZ >> 2], CCDC_FMT_HORZ);
  804. regw(ccdc_ctx[CCDC_FMT_VERT >> 2], CCDC_FMT_VERT);
  805. regw(ccdc_ctx[CCDC_FMT_ADDR0 >> 2], CCDC_FMT_ADDR0);
  806. regw(ccdc_ctx[CCDC_FMT_ADDR1 >> 2], CCDC_FMT_ADDR1);
  807. regw(ccdc_ctx[CCDC_FMT_ADDR2 >> 2], CCDC_FMT_ADDR2);
  808. regw(ccdc_ctx[CCDC_FMT_ADDR3 >> 2], CCDC_FMT_ADDR3);
  809. regw(ccdc_ctx[CCDC_FMT_ADDR4 >> 2], CCDC_FMT_ADDR4);
  810. regw(ccdc_ctx[CCDC_FMT_ADDR5 >> 2], CCDC_FMT_ADDR5);
  811. regw(ccdc_ctx[CCDC_FMT_ADDR6 >> 2], CCDC_FMT_ADDR6);
  812. regw(ccdc_ctx[CCDC_FMT_ADDR7 >> 2], CCDC_FMT_ADDR7);
  813. regw(ccdc_ctx[CCDC_PRGEVEN_0 >> 2], CCDC_PRGEVEN_0);
  814. regw(ccdc_ctx[CCDC_PRGEVEN_1 >> 2], CCDC_PRGEVEN_1);
  815. regw(ccdc_ctx[CCDC_PRGODD_0 >> 2], CCDC_PRGODD_0);
  816. regw(ccdc_ctx[CCDC_PRGODD_1 >> 2], CCDC_PRGODD_1);
  817. regw(ccdc_ctx[CCDC_VP_OUT >> 2], CCDC_VP_OUT);
  818. regw(ccdc_ctx[CCDC_PCR >> 2], CCDC_PCR);
  819. }
  820. static struct ccdc_hw_device ccdc_hw_dev = {
  821. .name = "DM6446 CCDC",
  822. .owner = THIS_MODULE,
  823. .hw_ops = {
  824. .open = ccdc_open,
  825. .close = ccdc_close,
  826. .reset = ccdc_sbl_reset,
  827. .enable = ccdc_enable,
  828. .set_hw_if_params = ccdc_set_hw_if_params,
  829. .set_params = ccdc_set_params,
  830. .configure = ccdc_configure,
  831. .set_buftype = ccdc_set_buftype,
  832. .get_buftype = ccdc_get_buftype,
  833. .enum_pix = ccdc_enum_pix,
  834. .set_pixel_format = ccdc_set_pixel_format,
  835. .get_pixel_format = ccdc_get_pixel_format,
  836. .set_frame_format = ccdc_set_frame_format,
  837. .get_frame_format = ccdc_get_frame_format,
  838. .set_image_window = ccdc_set_image_window,
  839. .get_image_window = ccdc_get_image_window,
  840. .get_line_length = ccdc_get_line_length,
  841. .setfbaddr = ccdc_setfbaddr,
  842. .getfid = ccdc_getfid,
  843. },
  844. };
  845. static int dm644x_ccdc_probe(struct platform_device *pdev)
  846. {
  847. struct resource *res;
  848. int status = 0;
  849. /*
  850. * first try to register with vpfe. If not correct platform, then we
  851. * don't have to iomap
  852. */
  853. status = vpfe_register_ccdc_device(&ccdc_hw_dev);
  854. if (status < 0)
  855. return status;
  856. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  857. if (!res) {
  858. status = -ENODEV;
  859. goto fail_nores;
  860. }
  861. res = request_mem_region(res->start, resource_size(res), res->name);
  862. if (!res) {
  863. status = -EBUSY;
  864. goto fail_nores;
  865. }
  866. ccdc_cfg.base_addr = ioremap_nocache(res->start, resource_size(res));
  867. if (!ccdc_cfg.base_addr) {
  868. status = -ENOMEM;
  869. goto fail_nomem;
  870. }
  871. ccdc_cfg.dev = &pdev->dev;
  872. printk(KERN_NOTICE "%s is registered with vpfe.\n", ccdc_hw_dev.name);
  873. return 0;
  874. fail_nomem:
  875. release_mem_region(res->start, resource_size(res));
  876. fail_nores:
  877. vpfe_unregister_ccdc_device(&ccdc_hw_dev);
  878. return status;
  879. }
  880. static int dm644x_ccdc_remove(struct platform_device *pdev)
  881. {
  882. struct resource *res;
  883. iounmap(ccdc_cfg.base_addr);
  884. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  885. if (res)
  886. release_mem_region(res->start, resource_size(res));
  887. vpfe_unregister_ccdc_device(&ccdc_hw_dev);
  888. return 0;
  889. }
  890. static int dm644x_ccdc_suspend(struct device *dev)
  891. {
  892. /* Save CCDC context */
  893. ccdc_save_context();
  894. /* Disable CCDC */
  895. ccdc_enable(0);
  896. return 0;
  897. }
  898. static int dm644x_ccdc_resume(struct device *dev)
  899. {
  900. /* Restore CCDC context */
  901. ccdc_restore_context();
  902. return 0;
  903. }
  904. static const struct dev_pm_ops dm644x_ccdc_pm_ops = {
  905. .suspend = dm644x_ccdc_suspend,
  906. .resume = dm644x_ccdc_resume,
  907. };
  908. static struct platform_driver dm644x_ccdc_driver = {
  909. .driver = {
  910. .name = "dm644x_ccdc",
  911. .pm = &dm644x_ccdc_pm_ops,
  912. },
  913. .remove = dm644x_ccdc_remove,
  914. .probe = dm644x_ccdc_probe,
  915. };
  916. module_platform_driver(dm644x_ccdc_driver);