dm644x_ccdc.c 30 KB

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