Advertisement
Guest User

jz4760_ipu.c

a guest
Apr 22nd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 38.53 KB | None | 0 0
  1. /********************** BEGIN LICENSE BLOCK ************************************
  2.  *
  3.  * INGENIC CONFIDENTIAL--NOT FOR DISTRIBUTION IN SOURCE CODE FORM
  4.  * Copyright (c) Ingenic Semiconductor Co. Ltd 2005. All rights reserved.
  5.  *
  6.  * This file, and the files included with this file, is distributed and made
  7.  * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  8.  * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  9.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
  10.  * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
  11.  *
  12.  * http://www.ingenic.cn
  13.  *
  14.  ********************** END LICENSE BLOCK **************************************
  15.  *
  16.  *  Author:   <jbyu@ingenic.cn>
  17.  *
  18.  *  Create:   2008-10-15, by jbyu
  19.  *
  20.  *******************************************************************************
  21.  */
  22.  
  23.  
  24. #include <linux/module.h>
  25. #include <linux/kernel.h>
  26.  
  27. #include <asm/irq.h>
  28. #include <linux/signal.h>
  29. #include <linux/sched.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/delay.h>
  32.  
  33.  
  34. #include <linux/module.h>
  35. #include <linux/kernel.h>
  36. #include <linux/errno.h>
  37. #include <linux/string.h>
  38. #include <linux/mm.h>
  39. #include <linux/tty.h>
  40. #include <linux/slab.h>
  41. #include <linux/delay.h>
  42. #include <linux/fb.h>
  43. #include <linux/init.h>
  44. #include <linux/dma-mapping.h>
  45. #include <linux/platform_device.h>
  46. #include <linux/pm.h>
  47. #include <linux/proc_fs.h>
  48.  
  49. #include <asm/irq.h>
  50. #include <asm/pgtable.h>
  51. #include <asm/system.h>
  52. #include <asm/uaccess.h>
  53. #include <asm/processor.h>
  54. #include <asm/jzsoc.h>
  55.  
  56.  
  57.  
  58. #ifndef printf
  59. #define printf printk
  60. #endif
  61.  
  62.  
  63. //#include "jz_ipu.h"
  64. #if defined(CONFIG_FB_JZ4750_LCD)
  65. #include "jz4750_lcd.h"
  66. #elif defined(CONFIG_FB_JZ4760_LCD)
  67. #include "jz4760_lcd.h"
  68. #endif
  69. //#include "jz4760_android_ipu.h"
  70.  
  71.  
  72. #if defined CONFIG_JZ4750
  73. #include <asm/mach-jz4750/jz4750.h>
  74. #include <asm/mach-jz4750/regs.h>
  75. #include <asm/mach-jz4750/ops.h>
  76. #elif defined CONFIG_SOC_JZ4760
  77. #include <asm/mach-jz4760/jz4760lcdc.h>
  78. #include "jz4760_ipu.h"
  79. #include <asm/mach-jz4760/jz4760ipu.h>
  80. #elif defined CONFIG_SOC_JZ4760B
  81. #include <asm/mach-jz4760b/jz4760blcdc.h>
  82. #include "jz4760_ipu.h"
  83. #include <asm/mach-jz4760b/jz4760bipu.h>
  84.  
  85. #elif defined CONFIG_SOC_JZ4770
  86. #include <mach/jz4770.h>
  87. #endif
  88.  
  89. #include <asm/uaccess.h>
  90.  
  91.  
  92.  
  93.  
  94. //#undef printf
  95. //#define IPU_LUT_LEN                           (32)
  96. #define FB_LCD_WIDTH                        5000//lcd_get_width()
  97. #define FB_LCD_HEIGHT                       3000//lcd_get_height()
  98. //#define IPU_OPEN                          (1 << 0)
  99. //#define IPU_INIT                          (1 << 1)
  100. //#define IPU_SET_STATE_BIT                 (25)        // 7 bit
  101. //#define IPU_SET_STATE_MASK                    (0x7f << IPU_SET_STATE_BIT)
  102. //#define SET_BIT(x)                            (1 << (IPU_SET_STATE_BIT+x))
  103. //#define IPU_CHANGE_BUF                        (SET_BIT(0))
  104. //#define IPU_SET_CTRL                      (SET_BIT(1))
  105. //#define IPU_SET_DAT_FMT                       (SET_BIT(2))
  106. //#define IPU_SET_CSC                           (SET_BIT(3))
  107. #define IPU_RATIO_MUL                       (100000)
  108. // І»¶ЁТе
  109. // #define IPU_FUNC_EX
  110.  
  111. #define IPU_INTC_DISABLE()                  OUTREG32(INTC_ICMSR(0), 1 << IRQ_IPU);
  112. #define IPU_INTC_ENABLE()                   OUTREG32(INTC_ICMCR(0), 1 << IRQ_IPU);
  113.  
  114.  
  115. #ifndef PHYS
  116. #define PHYS(n)  virt_to_phys(n)
  117. #endif
  118.  
  119. #if defined(CONFIG_JZ_CIM)
  120. extern unsigned int cim_read_dma();
  121. #endif
  122.  
  123.  
  124. img_param_t g_img_native_data =
  125. {
  126. };
  127.  
  128. //struct ipu_driver_priv *ipu_priv = &g_ipu_native_data;
  129. img_param_t *ipu_def_img = &g_img_native_data;
  130.  
  131. struct YuvStride def_stride =
  132. {
  133. };
  134.  
  135. extern unsigned char * lcd_frame0;
  136. extern unsigned char * lcd_frame1;
  137. extern unsigned char * lcd_frame01;
  138.  
  139.  
  140. static int ipu_inited = 0, ipu_size_cfg = 0;
  141. static int ipu_rtable_len;
  142.  
  143. unsigned int fb_w, fb_h;
  144. unsigned int rsize_w2 = 0, rsize_h2 = 0;
  145.  
  146. static img_param_t *img;
  147. //static struct Ration2m *ipu_ratio_table;
  148. static struct Ration2m ipu_ratio_table[IPU_LUT_LEN*IPU_LUT_LEN];
  149. static rsz_lut h_lut[IPU_LUT_LEN];
  150. static rsz_lut v_lut[IPU_LUT_LEN];
  151. static int ipu_change_buf = 0;
  152. static unsigned int *py_stride, *pu_stride, *pv_stride, *pout_stride;
  153.  
  154.  
  155. /* jz4760's ipu HRSZ_COEF_LUT*/
  156. static int hoft_table[IPU_LUT_LEN+1];
  157. static int hcoef_table[IPU_LUT_LEN+1];
  158. static int hcoef_real_heiht;
  159. /* jz4760's ipu VRSZ_COEF_LUT*/
  160. static int voft_table[IPU_LUT_LEN+1];
  161. static int vcoef_table[IPU_LUT_LEN+1];
  162. static int vcoef_real_heiht;
  163.  
  164.  
  165.  
  166. //cchen 09-11-16
  167. static int OutStride =480*4 ;
  168.  
  169. void set_outstride(int stride)
  170. {
  171.        OutStride = stride ;
  172. }
  173. //cchen
  174.  
  175. /*----------------------------------------------------------------------------------*/
  176.  
  177. extern int get_lcd_width();
  178. extern int get_lcd_hight();
  179. unsigned int lcd_get_width()
  180. {
  181.     return get_lcd_width();
  182. }
  183.  
  184. unsigned int lcd_get_height()
  185. {
  186.     return get_lcd_hight();
  187. }
  188.  
  189.  
  190. static void get_fbaddr_info()  //cchen 09-12-4
  191. {
  192.     fb_w = FB_LCD_WIDTH;
  193.     fb_h = FB_LCD_HEIGHT;
  194. }
  195. /*******************************************************
  196.  * ЕдЦГјДґжЖч
  197.  *******************************************************/
  198. static int jz47_set_ipu_csc_cfg(int outW, int outH, int Wdiff, int Hdiff)
  199. {
  200.     unsigned int in_fmt = img->ipu_d_fmt & IN_FMT_MASK;
  201.     unsigned int out_fmt = img->ipu_d_fmt & OUT_FMT_MASK;
  202.  
  203.     switch (in_fmt)
  204.     {
  205.         case IN_FMT_YUV420:
  206.             Hdiff = (Hdiff + 1) & ~1;
  207.             Wdiff = (Wdiff + 1) & ~1;
  208.             break;
  209.  
  210.         case IN_FMT_YUV422:
  211.         printf("[%s][%d]\n",__FUNCTION__,__LINE__);
  212.             Wdiff = (Wdiff + 1) & ~1;
  213.             break;
  214.  
  215.         case IN_FMT_YUV444:
  216.         case IN_FMT_YUV411:
  217.             break;
  218.         default:
  219.             printk("Error: Input data format isn't support\n");
  220.             return (-1);
  221.     }
  222.  
  223.     switch(out_fmt)
  224.     {
  225.         case OUT_FMT_RGB888:
  226.             outW = outW << 2;
  227.             break;
  228.         case OUT_FMT_RGB555:
  229.         printf("[%s][%d]\n",__FUNCTION__,__LINE__);
  230.             outW = outW << 1;
  231.             break;
  232.         case OUT_FMT_RGB565:
  233.             outW = outW << 1;
  234.             break;
  235.     }
  236.     //printf("\n=====outW=[%d]=outH=[%d]===\n",outW,outH);
  237.     //printf("=====img->in_width=[%d]====img->in_height=[%d]=====\n",img->in_width,img->in_height);
  238.     // ЕдЦГКдИлКдіцјёєОНјРОјДґжЖч
  239.     OUTREG32(IPU_IN_FM_GS, IN_FM_W(img->in_width) | IN_FM_H((img->in_height - Hdiff) & ~0x1));
  240.     //printf("=====IPU_IN_FM_GS=[0x%x]=====\n",REG32(IPU_IN_FM_GS));
  241.     OUTREG32(IPU_OUT_GS, OUT_FM_W(outW) | OUT_FM_H(outH));
  242.     //printf("[%s][%d]\n",__FUNCTION__,__LINE__);
  243.  
  244.     // Set out stirde
  245. #if 1
  246.     if (img->stride != 0)
  247.     {
  248.         printf("[%s][%d]\n",__FUNCTION__,__LINE__);
  249.  
  250.         OUTREG32(IPU_OUT_STRIDE, img->stride->out);
  251.         //OUTREG32(A_IPU_OUT_STRIDE, fb_w * img->in_bpp >> 3);
  252.     }
  253.     else
  254.     {
  255.         //printf("[%s][%d]\n",__FUNCTION__,__LINE__);
  256.  
  257.         //OUTREG32(A_IPU_OUT_STRIDE, outW);
  258.         OUTREG32(IPU_OUT_STRIDE, fb_w * img->in_bpp >> 3);
  259.     }
  260.     //printf("stride->out=0x%x\n",REG32(IPU_OUT_STRIDE));
  261. #else
  262.     /***wyang***/
  263.     //OUTREG32(IPU_OUT_STRIDE, 800*4);
  264. #endif
  265.     // ЙиЦГКэѕЭёсКЅјДґжЖч
  266.     OUTREG32(IPU_D_FMT, img->ipu_d_fmt);
  267.  
  268.     // set CSC parameter
  269.     if ((in_fmt != IN_FMT_YUV444) && (out_fmt != OUT_FMT_YUV422))
  270.     {
  271.         if (in_fmt != IN_FMT_PKG_RGB565){
  272.  
  273.         printk("set csc !\n");
  274.         img->ipu_ctrl |= CSC_EN;
  275.  
  276.         OUTREG32(IPU_CSC_C0_COEF, YUV_CSC_C0);
  277.         OUTREG32(IPU_CSC_C1_COEF, YUV_CSC_C1);
  278.         OUTREG32(IPU_CSC_C2_COEF, YUV_CSC_C2);
  279.         OUTREG32(IPU_CSC_C3_COEF, YUV_CSC_C3);
  280.         OUTREG32(IPU_CSC_C4_COEF, YUV_CSC_C4);
  281.         OUTREG32(IPU_CSC_OFSET_PARA, CHROM(YUV_CSC_CHROM) | LUMA(YUV_CSC_LUMA));
  282.         }
  283.     }
  284.  
  285.     return (0);
  286. }
  287.  
  288. /************************************************
  289.  *  іхКј»ЇЛх·Е±ИВКБР±н
  290.  ************************************************/
  291. static int init_ipu_ratio_table(void)
  292. {
  293. #if 0
  294.     unsigned int i, j, cnt;
  295.     unsigned int r, min;
  296.     int diff;
  297.  
  298.     ipu_ratio_table=(void *)alloc( (IPU_LUT_LEN) * (IPU_LUT_LEN)*sizeof(struct Ration2m) );
  299.  
  300.     //ipu_ratio_table= (struct Ration2m *)img->ratio_table;
  301.     for (i = 1; i <= (IPU_LUT_LEN); i++)
  302.     {
  303.         for (j = 1; j <= (IPU_LUT_LEN); j++)
  304.         {
  305.             ipu_ratio_table[(i - 1) * IPU_LUT_LEN + j - 1].ratio = i * IPU_RATIO_MUL / j;
  306.             ipu_ratio_table[(i - 1) * IPU_LUT_LEN + j - 1].n = i;
  307.             ipu_ratio_table[(i - 1) * IPU_LUT_LEN + j - 1].m = j;
  308.         }
  309.     }
  310.  
  311.     // Eliminate the ratio greater than 1:2
  312.     #if 1
  313.     for (i = 0; i < (IPU_LUT_LEN) * (IPU_LUT_LEN); i++)
  314.     {
  315.         if (ipu_ratio_table[i].ratio < IPU_RATIO_MUL / 2)
  316.         {
  317.             ipu_ratio_table[i].n = ipu_ratio_table[i].m = -1;
  318.         }
  319.     }
  320.     #endif
  321.     // eliminate the same ratio
  322.     for (i = 0; i < (IPU_LUT_LEN) * (IPU_LUT_LEN); i++)
  323.     {
  324.         for (j = i + 1; j < (IPU_LUT_LEN) * (IPU_LUT_LEN); j++)
  325.         {
  326.             diff = ipu_ratio_table[i].ratio - ipu_ratio_table[j].ratio;
  327.             if (diff > -100 && diff < 100)
  328.             {
  329.                 ipu_ratio_table[j].n = -1;
  330.                 ipu_ratio_table[j].m = -1;
  331.             }
  332.         }
  333.     }
  334.  
  335.     // reorder ipu_ratio_table
  336.     cnt = 0;
  337.     for (i = 0; i < (IPU_LUT_LEN) * (IPU_LUT_LEN); i++)
  338.     {
  339.         if (ipu_ratio_table[i].n != -1)
  340.         {
  341.             if (cnt != i)
  342.             {
  343.                 ipu_ratio_table[cnt] = ipu_ratio_table[i];
  344.             }
  345.             cnt++;
  346.         }
  347.     }
  348.     ipu_rtable_len = cnt;
  349.  
  350.     return (0);
  351. #else
  352.     unsigned int i, j, cnt;
  353.     int diff;
  354.  
  355.     //ipu_ratio_table=(void *)alloc( (IPU_LUT_LEN) * (IPU_LUT_LEN)*sizeof(struct Ration2m) );
  356.  
  357.     //ipu_ratio_table= (struct Ration2m *)img->ratio_table;
  358.    
  359.     memset(ipu_ratio_table,0,IPU_LUT_LEN*IPU_LUT_LEN*sizeof(struct Ration2m));
  360.    
  361.     for (i = 1; i <= (IPU_LUT_LEN); i++)
  362.     {
  363.         for (j = 1; j <= (IPU_LUT_LEN); j++)
  364.         {
  365.             ipu_ratio_table[(i - 1) * IPU_LUT_LEN + j - 1].ratio = i * IPU_RATIO_MUL / j;
  366.             ipu_ratio_table[(i - 1) * IPU_LUT_LEN + j - 1].n = i;
  367.             ipu_ratio_table[(i - 1) * IPU_LUT_LEN + j - 1].m = j;
  368.         }
  369.     }
  370.  
  371.     // Eliminate the ratio greater than 1:2
  372.     #if 1
  373.     for (i = 0; i < (IPU_LUT_LEN) * (IPU_LUT_LEN); i++)
  374.     {
  375.         if (ipu_ratio_table[i].ratio < IPU_RATIO_MUL / 2)
  376.         {
  377.             ipu_ratio_table[i].n = ipu_ratio_table[i].m = -1;
  378.         }
  379.     }
  380.     #endif
  381.     // eliminate the same ratio
  382.     for (i = 0; i < (IPU_LUT_LEN) * (IPU_LUT_LEN); i++)
  383.     {
  384.         for (j = i + 1; j < (IPU_LUT_LEN) * (IPU_LUT_LEN); j++)
  385.         {
  386.             diff = ipu_ratio_table[i].ratio - ipu_ratio_table[j].ratio;
  387.             if (diff > -100 && diff < 100)
  388.             {
  389.                 ipu_ratio_table[j].n = -1;
  390.                 ipu_ratio_table[j].m = -1;
  391.             }
  392.         }
  393.     }
  394.  
  395.     // reorder ipu_ratio_table
  396.     cnt = 0;
  397.     for (i = 0; i < (IPU_LUT_LEN) * (IPU_LUT_LEN); i++)
  398.     {
  399.         if (ipu_ratio_table[i].n != -1)
  400.         {
  401.             if (cnt != i)
  402.             {
  403.                 ipu_ratio_table[cnt] = ipu_ratio_table[i];
  404.             }
  405.             cnt++;
  406.         }
  407.     }
  408.     ipu_rtable_len = cnt;
  409.  
  410.     return (0);
  411.  
  412. #endif
  413. }
  414. /************************************************
  415.  *  ІйХТIPUЛх·Е±ИВК±н
  416.  ************************************************/
  417. static int find_ipu_ratio_factor(unsigned int ratio, unsigned int up)
  418. {
  419.     unsigned int i, sel;
  420.     unsigned int diff, min = IPU_RATIO_MUL;
  421.  
  422.     sel = ipu_rtable_len;
  423.  
  424.     for (i = 0; i < ipu_rtable_len; i++)
  425.     {
  426.         if ((up == 0) && ((ipu_ratio_table[i].n & 1) != 0))
  427.         {
  428.             continue;
  429.         }
  430.  
  431.         if (ratio > ipu_ratio_table[i].ratio)
  432.         {
  433.             diff = ratio - ipu_ratio_table[i].ratio;
  434.         }
  435.         else
  436.         {
  437.             diff = ipu_ratio_table[i].ratio - ratio;
  438.         }
  439.  
  440.         if (diff < min || i == 0)
  441.         {
  442.             min = diff;
  443.             sel = i;
  444.         }
  445.     }
  446.  
  447.     return (sel);
  448. }
  449. #ifndef IPU_FUNC_EX
  450. static int resize_lut_cal(int srcN, int dstM, int upScale, rsz_lut lut[]);
  451. static int resize_out_cal(int insize, int outsize, int srcN, int dstM, int upScale, int *diff);
  452. static void caculate_h_lut(rsz_lut *h_lut0, int * hoft_table, int* hcoef_table,  int H_MAX_LUT);
  453. static void caculate_v_lut(rsz_lut *h_lut0, int * hoft_table, int* hcoef_table,  int H_MAX_LUT);
  454. #else
  455. static int (*resize_lut_cal)(int srcN, int dstM, int upScale, rsz_lut lut[]);
  456. static int (*resize_out_cal)(int insize, int outsize, int srcN, int dstM, int upScale, int *diff);
  457.  
  458. void set_ipu_cal_func(void *lut_cal, void *out_cal)
  459. {
  460.     resize_lut_cal = lut_cal;
  461.     resize_out_cal = out_cal;
  462. }
  463. #endif
  464. /****************************************************
  465.  *
  466.  ****************************************************/
  467. static int jz47_set_ipu_resize(int *outWp, int *outHp,int *Wdiff, int *Hdiff)
  468. {
  469.     //printf("%s,%d\n",__FUNCTION__,__LINE__);
  470.     int W = 0, H = 0, Hsel = 0, Wsel = 0;
  471.     int srcN, dstM, width_up, height_up;
  472.     int Height_lut_max, Width_lut_max;
  473.     int i;
  474.     // МхјюІ»ВъЧгresize = img->out_width
  475.     rsize_w2 = ((img->out_width + img->out_x) > fb_w) ? (fb_w  - img->out_x) : img->out_width;
  476.     rsize_h2 = ((img->out_height + img->out_y) > fb_h) ? (fb_h - img->out_y) : img->out_height;
  477.     // КдіціЯґзІ»µГґуУЪКдИлБЅ±¶
  478.     rsize_w2 = (rsize_w2 > 2 * img->in_width) ? (2 * img->in_width) : rsize_w2;
  479.     rsize_h2 = (rsize_h2 > 2 * img->in_height) ? (2 * img->in_height) : rsize_h2;
  480.     *Wdiff = *Hdiff = 0;
  481.  
  482.     printk("img-> out_widht = %d, height = %d in_width = %d in_height = %d rsize_w2 = %d rsize_h2 = %d\n",img->out_width,img->out_height,img->in_width,img->in_height,rsize_w2,rsize_h2);
  483.  
  484.     // ПИ·ЗК№ДЬ·Еґу
  485.     img->ipu_ctrl &= ~(VRSZ_EN | HRSZ_EN);
  486.     // Из№ыІ»·Еґу
  487.     if ((img->in_width == rsize_w2) && (img->in_height == rsize_h2))
  488.     {
  489.         img->out_height = *outHp = rsize_h2;
  490.         img->out_width = *outWp = rsize_w2;
  491.  
  492.         return (0);
  493.     }
  494.     else
  495.     {
  496.         //Из№ыРиТЄЛ®ЖЅ·Еґу
  497.         if (img->in_width != rsize_w2)
  498.             img->ipu_ctrl |= HRSZ_EN;
  499.         //Из№ыРиТЄґ№Ц±·Еґу
  500.         if (img->in_height != rsize_h2)
  501.             img->ipu_ctrl |= VRSZ_EN;
  502.     }
  503. //printf("%s,%d\n",__FUNCTION__,__LINE__);
  504.  
  505.     // іхКј»Ї·ЕЛх±ИВК±н
  506.     //ipu_ratio_table = img->ratio_table;
  507.     init_ipu_ratio_table();
  508. //printf("%s,%d\n",__FUNCTION__,__LINE__);
  509.     // Ѕ«Лх·ЕРЕПўґжґўµЅѕЦІї±дБїЦР
  510.     width_up = (rsize_w2 >= img->in_width);
  511.     height_up = (rsize_h2 >= img->in_height);
  512.  
  513.     // get the resize factor
  514.     if (W != rsize_w2)
  515.     {
  516.         Wsel = find_ipu_ratio_factor(img->in_width * IPU_RATIO_MUL /rsize_w2, 1);
  517.         // printf ("horizontal resize: sel = %d, n=%d, m=%d\n", Wsel, ipu_ratio_table[Wsel].n,ipu_ratio_table[Wsel].m);
  518.         W = rsize_w2;
  519.     }
  520.     if (H != rsize_h2)
  521.     {
  522.         Hsel = find_ipu_ratio_factor(img->in_height * IPU_RATIO_MUL /rsize_h2, height_up);
  523.         // printf ("Vertical resize: sel = %d, n=%d, m=%d\n", Hsel, ipu_ratio_table[Hsel].n, ipu_ratio_table[Hsel].m);
  524.         H = rsize_h2;
  525.     }
  526.  
  527.     // Из№ыЛх·Е---*.m
  528.     Width_lut_max  = width_up  ? ipu_ratio_table[Wsel].m : ipu_ratio_table[Wsel].n;
  529.     Height_lut_max = height_up ? ipu_ratio_table[Hsel].m : ipu_ratio_table[Hsel].n;
  530.     //printf("ipu_ratio_table[Wsel].m=0x%d : ipu_ratio_table[Wsel].n=0x%d ,ipu_ratio_table[Hsel].m=0x%d  : ipu_ratio_table[Hsel].n=0x%d \n",ipu_ratio_table[Wsel].m ,ipu_ratio_table[Wsel].n,ipu_ratio_table[Hsel].m , ipu_ratio_table[Hsel].n);
  531.  
  532.     // јЖЛгКдіцНјРОіЯґзТФј°LUT
  533.     srcN = ipu_ratio_table[Wsel].n;
  534.     dstM = ipu_ratio_table[Wsel].m;
  535.     *outWp = resize_out_cal( img->in_width, rsize_w2, srcN, dstM, width_up, Wdiff);
  536.     resize_lut_cal(srcN, dstM, width_up, h_lut);
  537.  
  538.     srcN = ipu_ratio_table[Hsel].n;
  539.     dstM = ipu_ratio_table[Hsel].m;
  540.     *outHp = resize_out_cal( img->in_height, rsize_h2, srcN, dstM, height_up, Hdiff);
  541.     resize_lut_cal(srcN, dstM, height_up, v_lut);
  542.  
  543.     img->out_height = *outHp;
  544.     img->out_width = *outWp;
  545.  
  546.     caculate_h_lut(h_lut, hoft_table, hcoef_table, Width_lut_max);
  547.     caculate_v_lut(v_lut, voft_table, vcoef_table, Height_lut_max);
  548.     OUTREG32(IPU_RSZ_COEF_INDEX, ((vcoef_real_heiht- 1) << VE_IDX_H_BIT) | ((hcoef_real_heiht- 1)  << HE_IDX_W_BIT));
  549. //printf("%s,%d\n",__FUNCTION__,__LINE__);
  550.     // ЕдЦГLUTјДґжЖч
  551.     #if 1
  552.     SETREG32(IPU_VRSZ_LUT_BASE, 1 << V_CONF_BIT);
  553.     //printf("%s,%d\n",__FUNCTION__,__LINE__);
  554.     for (i = 0; i < vcoef_real_heiht; i++)
  555.     {
  556.     //printf("%s,%d\n",__FUNCTION__,__LINE__);
  557.         OUTREG32(IPU_VRSZ_LUT_BASE, ((vcoef_table[i+1]&W_COEF0_MSK)<< W_COEF0_BIT)
  558.             | ((voft_table[i+1]&V_OFT_MSK) << V_OFT_BIT));
  559.     }
  560. //printf("%s,%d\n",__FUNCTION__,__LINE__);
  561.     SETREG32(IPU_HRSZ_LUT_BASE, 1 << H_CONF_BIT);
  562.     //printf("%s,%d\n",__FUNCTION__,__LINE__);
  563.     for (i = 0; i < hcoef_real_heiht; i++)
  564.     {
  565.     printk("%s,%d\n",__FUNCTION__,__LINE__);
  566.         OUTREG32(IPU_HRSZ_LUT_BASE, ((hcoef_table[i+1]&W_COEF0_MSK)<< W_COEF0_BIT)
  567.             | ((hoft_table[i+1]&H_OFT_MSK) << H_OFT_BIT));
  568.     }
  569.     #else
  570.     for (i = 0; i < Height_lut_max; i++)
  571.     {
  572.         if ((height_up == 0) && ((i & 1) == 0))
  573.         {
  574.             if ((v_lut[i].out_n == 0) && (v_lut[i+1].out_n == 1))
  575.             {
  576.                 v_lut[i].out_n = 1;
  577.                 v_lut[i+1].out_n = 0;
  578.             }
  579.         }
  580.  
  581.         OUTREG32(IPU_VRSZ_LUT_BASE, (v_lut[i].coef << W_COEF0_BIT)
  582.             /*| (v_lut[i].in_n << IN_EN_BIT) | (v_lut[i].out_n  << OUT_EN_BIT)*/);
  583.     }
  584.  
  585.     SETREG32(IPU_HRSZ_LUT_BASE, 1 << H_CONF_BIT);
  586.     for (i = 0; i < Width_lut_max; i++)
  587.     {
  588.         OUTREG32(IPU_HRSZ_LUT_BASE, (h_lut[i].coef << W_COEF0_BIT)
  589.         /*| (h_lut[i].in_n << IN_EN_BIT) | (h_lut[i].out_n  << OUT_EN_BIT)*/);
  590.     }
  591.     #endif
  592.  
  593.     return (0);
  594. }
  595. /**************************************************
  596.  * ЙиЦГКдИлКдіцјДґжЖч
  597.  **************************************************/
  598. static int jz47_set_ipu_buf(void)
  599. {
  600.     int ret;
  601.     unsigned int py_buf;
  602.     unsigned int pu_buf;
  603.     unsigned int pv_buf;
  604.     unsigned int py_t_buf;
  605.     unsigned int pu_t_buf;
  606.     unsigned int pv_t_buf;
  607.     unsigned int out_buf;
  608.     // ¶ЁТеIPU_CONTROLКэѕЭЅб№№±дБї
  609.     PIPU_CTRL2 pipu_ctrl = (PIPU_CTRL2)(&img->ipu_ctrl);
  610.  
  611. #if 0
  612.     py_buf = PHYS((unsigned int)img->y_buf);
  613.     pu_buf = PHYS((unsigned int)img->u_buf);
  614.     pv_buf = PHYS((unsigned int)img->v_buf);
  615. #else
  616.     py_buf = ((unsigned int)img->y_buf);
  617.     pu_buf = ((unsigned int)img->u_buf);
  618.     pv_buf = ((unsigned int)img->v_buf);
  619. #endif
  620.     //printf("=====py__buf=[0x%x],pu__buf=[0x%x],pv__buf=[0x%x]\n",py_buf,pu_buf,pv_buf);
  621.  
  622.     if (pipu_ctrl->spage_map != 0) // Из№ыФКРнТіГжµШЦ·УіЙд
  623.     {
  624.         printk("spage map != 0 \n");
  625.         // КэѕЭУРР§РФЕР¶П
  626.         if ((py_t_buf == 0) || (pu_t_buf == 0) || (pv_t_buf == 0))
  627.         {
  628.             printk(" Can not found source map table, use no map now!\r\n");
  629.             pipu_ctrl->spage_map = 0;
  630.         }
  631.         else
  632.         {
  633.             py_t_buf = PHYS((unsigned int)img->y_t_addr);
  634.             pu_t_buf = PHYS((unsigned int)img->u_t_addr);
  635.             pv_t_buf = PHYS((unsigned int)img->v_t_addr);
  636.  
  637.             //printf("=====py_t_buf=[0x%x],pu_t_buf=[0x%x],pv_t_buf=[0x%x]\n",py_t_buf,pu_t_buf,pv_t_buf);
  638.  
  639.             py_buf = py_t_buf & 0xfff;
  640.             pu_buf = pu_t_buf & 0xfff;
  641.             pv_buf = pv_t_buf & 0xfff;
  642.  
  643.             // Input source TLB base address
  644.             OUTREG32(IPU_Y_PHY_T_ADDR, py_t_buf);
  645.             OUTREG32(IPU_Y_PHY_T_ADDR, pu_t_buf);
  646.             OUTREG32(IPU_Y_PHY_T_ADDR, pv_t_buf);
  647.  
  648.             //printf("=====IPU_SRC_TLB_ADDR=[0x%x]===\n",REG32(IPU_SRC_TLB_ADDR));
  649.         }
  650.     }
  651.     else
  652.     {
  653.         if ((py_buf == 0) || (pu_buf == 0) || (pv_buf == 0))
  654.         {
  655.             printk ("++ Can not found buffer(0x%x,0x%x,0x%x) physical addr since addr errors +++\n",
  656.                   (unsigned int)img->y_buf, (unsigned int)img->u_buf, (unsigned int)img->v_buf);
  657.             return (-1);
  658.         }
  659.     }
  660.  
  661.     // КдИлYРЕєЕКэѕЭµШЦ·јДґжЖч
  662.     OUTREG32(IPU_Y_ADDR, py_buf);
  663.     OUTREG32(IPU_U_ADDR, pu_buf);
  664.     OUTREG32(IPU_V_ADDR, pv_buf);
  665.  
  666.     // Из№ыФКРнµШЦ·УіЙд,ТФј°І»КЗЦ±НЁДЈКЅ
  667.     if ((pipu_ctrl->dpage_map != 0) && (pipu_ctrl->lcdc_sel == 0))
  668.     {
  669.         if (PHYS(img->out_t_addr) == 0)
  670.         {
  671.             //printf(" Can not found destination map table, use no map now!\r\n");
  672.             pipu_ctrl->dpage_map = 0;
  673.  
  674.             if (PHYS(img->out_buf) == 0)
  675.             {
  676.                 printk("Can not found the destination buf[%#x]\r\n",  img->out_buf);
  677.                 return (-1);
  678.             }
  679.             else
  680.             {
  681.                 OUTREG32(IPU_OUT_ADDR, PHYS(img->out_buf));
  682.             }
  683.         }
  684.         else
  685.         {
  686.             // ЕдЦГКэѕЭКдіцјДґжЖчЎўКдіцµШЦ·УіЙд±нјДґжЖч
  687.             OUTREG32(IPU_OUT_ADDR, PHYS(img->out_t_addr) & 0xfff);
  688.             OUTREG32(IPU_U_PHY_T_ADDR, PHYS(img->out_t_addr));
  689.         }
  690.     }
  691.     else
  692.     {
  693.         pipu_ctrl->dpage_map = 0;
  694.         if (pipu_ctrl->lcdc_sel == 0)
  695.         {
  696.             if (PHYS(img->out_buf) == 0)
  697.             {
  698.                 printk("Can not found the destination buf[%#x]\r\n",  img->out_buf);
  699.                 return (-1);
  700.             }
  701.             else
  702.             {
  703.                                out_buf = (unsigned int)img->out_buf + (img->out_y * lcd_get_width()+ img->out_x) * img->in_bpp / 8;//sxyzhang 2010-12-2
  704. //              out_buf = (unsigned int)img->out_buf + (img->out_y * fb_w+ img->out_x) * img->in_bpp / 8;
  705.                 OUTREG32(IPU_OUT_ADDR, PHYS(out_buf));
  706.                 //OUTREG32(IPU_OUT_ADDR, (out_buf));
  707.                 //printf("===")
  708.             }
  709.         }else{
  710.             printk("\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
  711.         }
  712.     }
  713.     return (0);
  714. }
  715.  
  716. #ifndef IPU_FUNC_EX
  717. /************************************************
  718.  *  јЖЛгКдіціЯґз
  719.  ************************************************/
  720. static int resize_out_cal(int insize, int outsize, int srcN, int dstM,
  721.                         int upScale, int *diff)
  722. {
  723.     unsigned int calsize, delta;
  724.     unsigned int tmp, tmp2;
  725.  
  726.     delta = IPU_RATIO_MUL;
  727.     insize *= IPU_RATIO_MUL;
  728.  
  729.     do
  730.     {
  731.         tmp = ((insize - delta) * dstM / srcN) & (~(IPU_RATIO_MUL - 1));
  732.         tmp2 = tmp  * srcN / dstM;
  733.         if (upScale)// Из№ыНјПс·Еґу
  734.         {
  735.             if (tmp2 == insize - delta)
  736.             {
  737.                 calsize = tmp / IPU_RATIO_MUL + 1;
  738.             }
  739.             else
  740.             {
  741.                 calsize = tmp / IPU_RATIO_MUL + 2;
  742.             }
  743.         }
  744.         else        // ЛхРЎ
  745.         {
  746.             if (tmp2 == insize - delta)
  747.             {
  748.                 calsize = tmp / IPU_RATIO_MUL;
  749.             }
  750.             else
  751.             {
  752.                 calsize = tmp / IPU_RATIO_MUL + 1;
  753.             }
  754.         }
  755.  
  756.         delta += IPU_RATIO_MUL;
  757.  
  758.     } while (calsize > outsize);
  759.  
  760.     *diff = delta / IPU_RATIO_MUL - 2;
  761.  
  762.     return (calsize);
  763. }
  764.  
  765. /************************************************
  766.  *  јЖЛгLUT
  767.  ************************************************/
  768. static int resize_lut_cal(int srcN, int dstM, int upScale, rsz_lut lut[])
  769. {
  770.     int i, t, x;
  771.     unsigned int w_coef, factor, factor2;
  772.  
  773.     if (upScale)
  774.     {
  775.         for (i = 0, t = 0; i < dstM; i++)
  776.         {
  777.             factor = (i * srcN * IPU_RATIO_MUL) / dstM;
  778.             factor2 = factor - factor / IPU_RATIO_MUL * IPU_RATIO_MUL;
  779.             w_coef = IPU_RATIO_MUL  - factor2;
  780.             lut[i].coef = (unsigned int)(512 * w_coef / IPU_RATIO_MUL) & W_COEF0_MSK;
  781.             // calculate in & out
  782.             lut[i].out_n = 1;
  783.             if (t <= factor)
  784.             {
  785.                 lut[i].in_n = 1;
  786.                 t += IPU_RATIO_MUL;
  787.             }
  788.             else
  789.             {
  790.                 lut[i].in_n = 0;
  791.             }
  792.         } // end for
  793.     }
  794.     else
  795.     {
  796.         for (i = 0, t = 0, x = 0; i < srcN; i++)
  797.         {
  798.             factor = (t * srcN + 1) * IPU_RATIO_MUL / dstM;
  799.             if (dstM == 1)
  800.             {
  801.                 // calculate in & out
  802.                 lut[i].coef = (i == 0) ? 256 : 0;
  803.                 lut[i].out_n = (i == 0) ? 1  : 0;
  804.             }
  805.             else
  806.             {
  807.                 if (((t * srcN + 1) / dstM - i) >= 1)
  808.                 {
  809.                     lut[i].coef = 0;
  810.                 }
  811.                 else
  812.                 {
  813.                     if (factor - i * IPU_RATIO_MUL == 0)
  814.                     {
  815.                         lut[i].coef = 512;
  816.                         t++;
  817.                     }
  818.                     else
  819.                     {
  820.                         factor2 = (t * srcN ) / dstM * IPU_RATIO_MUL;
  821.                         factor = factor - factor2;
  822.                         w_coef = IPU_RATIO_MUL  - factor;
  823.                         lut[i].coef = (unsigned int)(512 * w_coef / IPU_RATIO_MUL) & W_COEF0_MSK;
  824.                         t++;
  825.                     }
  826.                 }
  827.             }
  828.             // calculate in & out
  829.             lut[i].in_n = 1;
  830.             if (dstM != 1)
  831.             {
  832.                 if (((x * srcN + 1) / dstM - i) >= 1)
  833.                 {
  834.                     lut[i].out_n = 0;
  835.                 }
  836.                 else
  837.                 {
  838.                     lut[i].out_n = 1;
  839.                     x++;
  840.                 }
  841.             }
  842.  
  843.         }   // for end down Scale
  844.     }   // else upScale
  845.  
  846.     return (0);
  847. }
  848.  
  849. static void caculate_h_lut(rsz_lut *h_lut0, int * hoft_table, int* hcoef_table,  int H_MAX_LUT)
  850. {
  851.     int j ;
  852.     int i;
  853.     int in_oft_tmp = 0;
  854.     int coef_tmp = 0;
  855.     rsz_lut *h_lut;
  856.  
  857.     h_lut = h_lut0;
  858.  
  859.     j = 0 ;
  860.     for (i=0; i<H_MAX_LUT; i++)
  861.     {
  862.         if ( h_lut[i].out_n ) {
  863.             hoft_table[j] = (h_lut[i].in_n == 0)? 0: in_oft_tmp;
  864.             hcoef_table[j] = coef_tmp;
  865.             coef_tmp = h_lut[i].coef;
  866.             in_oft_tmp = h_lut[i].in_n==0? in_oft_tmp : h_lut[i].in_n ;
  867.             j++;
  868.         }
  869.         else
  870.             in_oft_tmp = h_lut[i].in_n + in_oft_tmp;
  871.     }
  872.     if ( h_lut[0].out_n ){
  873.         hoft_table[j] = (h_lut[0].in_n == 0)? 0: in_oft_tmp;
  874.         hcoef_table[j] = coef_tmp;
  875.     }
  876.  
  877.     hcoef_real_heiht = j;
  878. }
  879.  
  880. static void caculate_v_lut(rsz_lut *v_lut0, int * voft_table, int* vcoef_table, int V_MAX_LUT)
  881. {
  882.     int j;
  883.     int i;
  884.     int in_oft_tmp = 0;
  885.     int coef_tmp = 0;
  886.     rsz_lut *v_lut;
  887.  
  888.     v_lut = v_lut0;
  889.  
  890.  
  891.     j = 0 ;
  892.     for (i=0; i<V_MAX_LUT; i++)
  893.     {
  894.         if ( v_lut[i].out_n ){
  895.             voft_table[j] = (v_lut[i].in_n == 0)? 0: in_oft_tmp;
  896.             vcoef_table[j] = coef_tmp;
  897.             coef_tmp = v_lut[i].coef;
  898.             in_oft_tmp = v_lut[i].in_n==0? in_oft_tmp : v_lut[i].in_n ;
  899.             j++;
  900.         }
  901.         else
  902.             in_oft_tmp = v_lut[i].in_n + in_oft_tmp;
  903.     }
  904.     if ( v_lut[0].out_n ){
  905.         voft_table[j] = (v_lut[0].in_n == 0)? 0: in_oft_tmp;
  906.         vcoef_table[j] = coef_tmp;
  907.     }
  908.  
  909.     vcoef_real_heiht = j;
  910. }
  911. #endif
  912. /**********************************************************
  913.  *  IPUЦР¶Пґ¦АнєЇКэ----Г»УРК№УГ
  914.  *  Camera.cОДјюЦРК№УГµДІйСЇ
  915.  **********************************************************/
  916. static void ipu_interrupt_handler(void)
  917. {
  918.     //printf("_______[%s]_[%d]______\n",__FUNCTION__,__LINE__);
  919.     //  if (ipu_change_buf != 0)
  920.     {
  921.         if ((INREG32(IPU_STATUS) & OUT_END) == 0)
  922.         {
  923.             return;
  924.         }
  925.  
  926.         CLRREG32(IPU_STATUS, OUT_END);
  927.  
  928.         // jz47_set_ipu_buf();
  929.         OUTREG32(IPU_Y_ADDR, PHYS((unsigned int)img->y_buf));
  930.         OUTREG32(IPU_U_ADDR, PHYS((unsigned int)img->u_buf));
  931.         OUTREG32(IPU_V_ADDR, PHYS((unsigned int)img->v_buf));
  932.         // ipu_change_buf = 0;
  933.         OUTREG32(IPU_Y_STRIDE, *py_stride);
  934.         OUTREG32(IPU_UV_STRIDE, U_STRIDE(*pu_stride) | V_STRIDE(*pv_stride));
  935.  
  936.         SETREG32(IPU_CTRL, IPU_RUN);
  937.         // printf(" %s\n", __FUNCTION__);
  938.         IPU_INTC_DISABLE();
  939.     }
  940. }
  941. /************************************************
  942.  * ґтУЎКэѕЭІОКэ
  943.  ************************************************/
  944. int print_img(void)
  945. {
  946.     printk ("ipu_ctrl[%#x]\r\n" , img->ipu_ctrl);
  947.     printk ("ipu_d_fmt[%#x]\r\n" , img->ipu_d_fmt);
  948.     printk ("in_width[%#x]\r\n" , img->in_width);
  949.     printk ("in_height[%#x]\r\n" , img->in_height);
  950.     printk ("in_bpp[%#x]\r\n" , img->in_bpp);
  951.     printk ("out_width[%#x]\r\n" , img->out_width);
  952.     printk ("out_height[%#x]\r\n" , img->out_height);
  953.     printk ("y_buf[%#x]\r\n" , img->y_buf);
  954.     printk ("u_buf[%#x]\r\n" , img->u_buf);
  955.     printk ("v_buf[%#x]\r\n" , img->v_buf);
  956.     printk ("out_buf[%#x]\r\n" , img->out_buf);
  957.     printk ("y_t_addr[%#x]\r\n" , img->y_t_addr);
  958.     printk ("u_t_addr[%#x]\r\n" , img->u_t_addr);
  959.     printk ("v_t_addr[%#x]\r\n" , img->v_t_addr);
  960.     printk ("out_t_addr[%#x]\r\n" , img->out_t_addr);
  961. }
  962. /************************************************
  963.  * ґтУЎјДґжЖч
  964.  ************************************************/
  965. int print_reg(void)
  966. {
  967.     return 0;
  968.     printk("=1==IPU_CTRL=[0x%8x]===\n",REG32(IPU_CTRL));
  969.     printk("=2==IPU_STATUS=[0x%8x]===\n",REG32(IPU_STATUS));
  970.     printk("=3==IPU_D_FMT=[0x%8x]===\n",REG32(IPU_D_FMT));
  971.     printk("=4==IPU_Y_ADDR=[0x%8x]===\n",REG32(IPU_Y_ADDR));
  972.     printk("=5==IPU_U_ADDR=[0x%8x]===\n",REG32(IPU_U_ADDR));
  973.     printk("=6==IPU_V_ADDR=[0x%8x]===\n",REG32(IPU_V_ADDR));
  974.     printk("=7==IPU_IN_FM_GS=[0x%8x]===\n",REG32(IPU_IN_FM_GS));
  975.     printk("=8==IPU_Y_STRIDE=[0x%8x]===\n",REG32(IPU_Y_STRIDE));
  976.     printk("=9==IPU_UV_STRIDE=[0x%8x]===\n",REG32(IPU_UV_STRIDE));
  977.     printf("=10==IPU_OUT_ADDR=[0x%8x]===\n",REG32(IPU_OUT_ADDR));
  978.     printf("=11==IPU_OUT_GS=[0x%8x]===\n",REG32(IPU_OUT_GS));
  979.     printf("=12==IPU_OUT_STRIDE=[0x%8x]===\n",REG32(IPU_OUT_STRIDE));
  980.     printf("=13==IPU_RSZ_COEF_INDEX=[0x%8x]===\n",REG32(IPU_RSZ_COEF_INDEX));
  981.     printf("=14==IPU_CSC_C0_COEF=[0x%8x]===\n",REG32(IPU_CSC_C0_COEF));
  982.     printf("=15==IPU_CSC_C1_COEF=[0x%8x]===\n",REG32(IPU_CSC_C1_COEF));
  983.     printf("=16==IPU_CSC_C2_COEF=[0x%8x]===\n",REG32(IPU_CSC_C2_COEF));
  984.     printf("=17==IPU_CSC_C3_COEF=[0x%8x]===\n",REG32(IPU_CSC_C3_COEF));
  985.     printf("=18==IPU_CSC_C4_COEF=[0x%8x]===\n",REG32(IPU_CSC_C4_COEF));
  986.     printf("=19==IPU_HRSZ_LUT_BASE=[0x%8x]===\n",REG32(IPU_HRSZ_LUT_BASE));
  987.     printf("=20==IPU_VRSZ_LUT_BASE=[0x%8x]===\n",REG32(IPU_VRSZ_LUT_BASE));
  988.     printf("=21==IPU_CSC_OFSET_PARA=[0x%8x]===\n",REG32(IPU_CSC_OFSET_PARA));
  989.     printf("=22==IPU_SRC_TLB_ADDR=[0x%8x]===\n",REG32(IPU_Y_PHY_T_ADDR));
  990.     printf("=23==IPU_DEST_TLB_ADDR=[0x%8x]===\n",REG32(IPU_U_PHY_T_ADDR));
  991. #if 0
  992.     printf("=24==IPU_TLB_MONITOR=[0x%8x]===\n",REG32(IPU_TLB_MONITOR));
  993.     printf("=25==IPU_ADDR_CTRL=[0x%8x]===\n",REG32(IPU_ADDR_CTRL));
  994.     printf("=26==IPU_Y_ADDR_N=[0x%8x]===\n",REG32(IPU_Y_ADDR_N));
  995.     printf("=27==IPU_U_ADDR_N=[0x%8x]===\n",REG32(IPU_U_ADDR_N));
  996.     printf("=28==IPU_V_ADDR_N=[0x%8x]===\n",REG32(IPU_V_ADDR_N));
  997.     printf("=29==IPU_OUT_ADDR_N=[0x%8x]===\n",REG32(IPU_OUT_ADDR_N));
  998.     printf("=30==IPU_SRC_TLB_ADDR_N=[0x%8x]===\n",REG32(IPU_SRC_TLB_ADDR_N));
  999.     printf("=31==IPU_DEST_TLB_ADDR_N=[0x%8x]===\n",REG32(IPU_DEST_TLB_ADDR_N));
  1000.     printf("=32==IPU_TLB_CTRL=[0x%8x]===\n",REG32(IPU_TLB_CTRL));
  1001. #endif
  1002. }
  1003.  
  1004. /************************************************
  1005.  * IPUіхКј»ЇєЇКэ2
  1006.  ************************************************/
  1007. int ipu_init2(img_param_t *pimg)
  1008. {
  1009.     int ret = -1;
  1010.     int in_fmt;
  1011.     int out_fmt;
  1012.     int outW, outH, Wdiff, Hdiff;
  1013.  
  1014.     printf("Debug=== +++IPU init +++....\r\n");
  1015.  
  1016. #ifdef IPU_FUNC_EX // Г»УР¶ЁТе
  1017.     if (!pimg || !resize_lut_cal || !resize_out_cal)
  1018. #else
  1019.     if (!pimg)
  1020. #endif
  1021.     {
  1022.         printf("ipu_init: parameter error\r\n");
  1023.         return (ret);
  1024.     }
  1025.     //printf("%s,%d\n",__FUNCTION__,__LINE__);
  1026.     get_fbaddr_info();
  1027.     // printf("reg_ctrl=0x%x,reg_ctrl=0x%x\n",img->ipu_ctrl,INREG32(IPU_CTRL));
  1028.     //printf("%s,%d\n",__FUNCTION__,__LINE__);
  1029.     // °Сґ«µЭ№эАґµДКэѕЭёіёшИ«ѕЦ±дБї
  1030.     img = pimg;
  1031.     outW    = img->out_width;
  1032.     outH    = img->out_height;
  1033.     in_fmt  = img->ipu_d_fmt & IN_FMT_MASK;
  1034.     out_fmt = img->ipu_d_fmt & OUT_FMT_MASK;
  1035.  
  1036. //  ipu_ratio_table = img->ratio_table;  //sxyzhang 2010-12-2 close
  1037.     //printf("iputable=0x%x\n",ipu_ratio_table );
  1038.  
  1039.     py_stride   = &(img->stride->y);
  1040.     pu_stride   = &(img->stride->u);
  1041.     pv_stride   = &(img->stride->v);
  1042.     pout_stride = &(img->stride->out);
  1043.  
  1044.     //printf("img->in_widht=%d\n",img->in_width);
  1045.     //printf("img->in_height=%d\n",img->in_height);
  1046.     //printf("img->in_bpp=%d\n",img->in_bpp);
  1047.     printf("img->out_widht=%d\n",img->out_width);
  1048.     printf("img->out_height%d\n",img->out_height);
  1049.     //printf("img->out-y=%d\n",img->stride->y);
  1050.     //printf("img->out-u=%d\n",img->stride->u);
  1051.     //printf("img->out-v=%d\n",img->stride->v);
  1052.     //printf("img->out-out=%d\n",img->stride->out);
  1053.     // img->ipu_ctrl &= (LCDC_SEL | FM_IRQ_EN | ADDR_SEL);
  1054.     // Из№ыГ»УРЅшРРіхКј»Ї
  1055.     if (ipu_inited == 0)
  1056.     {
  1057.         /***wyang***/
  1058.         CLRREG32(CPM_CLKGR0, CLKGR0_IPU); // run ipu clock
  1059.         //К№УГІйСЇ·ЁЈ¬Г»УРК№УГЦР¶П
  1060.         //request_irq(IRQ_IPU, ipu_interrupt_handler, 0);
  1061.         IPU_INTC_DISABLE();
  1062.  
  1063.         CLRREG32(IPU_CTRL, IPU_RUN);
  1064.         SETREG32(IPU_CTRL, CHIP_EN);
  1065.         SETREG32(IPU_CTRL, IPU_RST);// reset controller
  1066.         CLRREG32(IPU_CTRL, IPU_RST);
  1067.         while ((INREG32(IPU_STATUS) & OUT_END) == 0){
  1068.             printk("time out!\n");; // wait the end flag
  1069.         }
  1070.     }
  1071.     else
  1072.     {
  1073.         while ((INREG32(IPU_CTRL) & IPU_RUN) && ((INREG32(IPU_STATUS) & OUT_END) == 0)); // wait the end flag
  1074.         SETREG32(IPU_CTRL, IPU_RST);                // reset controller
  1075.         CLRREG32(IPU_CTRL, IPU_RST);
  1076.         while ((INREG32(IPU_STATUS) & OUT_END) == 0); // wait the end flag
  1077.     }
  1078.     //printf("%s,%d\n",__FUNCTION__,__LINE__);
  1079.     // МхјюІ»ВъЧг(cameraПВ)
  1080.     if ((in_fmt == IN_FMT_YUV444) && (out_fmt != OUT_FMT_YUV422))
  1081.     {
  1082.         img->ipu_ctrl &= ~SPKG_SEL; //Separated Frame
  1083.     }
  1084.     //printf("%s,%d\n",__FUNCTION__,__LINE__);
  1085.  
  1086.     // јЖЛгЛх·ЕТтЧУІў·µ»Ш
  1087.     jz47_set_ipu_resize(&outW, &outH, &Wdiff, &Hdiff);
  1088.  
  1089.     printf("===outW=[%d],outH=[%d],Wdiff=[%d],Hdiff=[%d]===\n",outW,outH,Wdiff,Hdiff);
  1090.     // ЕдЦГјДґжЖч
  1091.     //printf("%s,%d\n",__FUNCTION__,__LINE__);
  1092.     ret = jz47_set_ipu_csc_cfg(outW, outH, Wdiff, Hdiff);
  1093.     if (ret != 0)  return (ret);
  1094.     //printf("%s,%d\n",__FUNCTION__,__LINE__);
  1095.  
  1096.     //printf("reg_ctrl=0x%x,reg_ctrl=0x%x\n",img->ipu_ctrl,INREG32(IPU_CTRL));
  1097.  
  1098.     // ЕдЦГКдИлКдіцјДґжЖч
  1099.     if (jz47_set_ipu_buf() < 0) // ХэіЈ·µ»Ш0
  1100.     {
  1101.         //printf("%s,%d\n",__FUNCTION__,__LINE__);
  1102.  
  1103.         ret = -1;
  1104.         return (ret);
  1105.     }
  1106.     //printf("%s,%d\n",__FUNCTION__,__LINE__);
  1107.  
  1108.     // set  stride
  1109.     if (img->stride == 0)
  1110.     {
  1111.     //printf("[%s][%d]\n",__FUNCTION__,__LINE__);
  1112.     if((img->ipu_ctrl) |SPKG_SEL)
  1113.     //  if (img->ipu_ctrl & SPKG_SEL)
  1114.         {
  1115.             OUTREG32(IPU_Y_STRIDE, img->in_width * 2);
  1116.         }
  1117.         else
  1118.         {
  1119.  
  1120.             OUTREG32(IPU_Y_STRIDE, img->in_width);
  1121.         }
  1122.  
  1123.         switch(((PIPU_DFMT2)&(img->ipu_d_fmt))->in_fmt)
  1124.         {
  1125.             case IN_FMT_YUV420:
  1126.             case IN_FMT_YUV422:
  1127.                 OUTREG32(IPU_UV_STRIDE, U_STRIDE(img->in_width / 2) | V_STRIDE(img->in_width / 2));
  1128.                 break;
  1129.  
  1130.             case IN_FMT_YUV444:
  1131.                 OUTREG32(IPU_UV_STRIDE, U_STRIDE(img->in_width) | V_STRIDE(img->in_width));
  1132.                 break;
  1133.  
  1134.             case IN_FMT_YUV411:
  1135.                 OUTREG32(IPU_UV_STRIDE, U_STRIDE(img->in_width / 4) | V_STRIDE(img->in_width / 4));
  1136.                 break;
  1137.  
  1138.             default:
  1139.                 printf("Error: Input data format isn't support\n");
  1140.                 return (-1);
  1141.                 break;
  1142.         }
  1143.     }
  1144.     else
  1145.     {
  1146.         printf("[%s][%d]\n",__FUNCTION__,__LINE__);
  1147. #if 1
  1148.         OUTREG32(IPU_Y_STRIDE, *py_stride);
  1149.         OUTREG32(IPU_UV_STRIDE, U_STRIDE(*pu_stride) | V_STRIDE(*pv_stride));
  1150. #else
  1151.         OUTREG32(IPU_Y_STRIDE, 640*2);
  1152.         OUTREG32(IPU_UV_STRIDE, U_STRIDE(320) | V_STRIDE(320));
  1153. #endif
  1154.         //printf("[%s][%d]\n",__FUNCTION__,__LINE__);
  1155.  
  1156.     }
  1157.     // IPUК№ДЬ
  1158.     OUTREG32(IPU_CTRL, img->ipu_ctrl | CHIP_EN);
  1159.     //printf("[%s][%d]\n",__FUNCTION__,__LINE__);
  1160.  
  1161.     ipu_inited = 1;
  1162.  
  1163.     //print_img();
  1164.     print_reg();
  1165.     return (0);
  1166. }
  1167. /*************************************************
  1168.  *
  1169.  *************************************************/
  1170. int ipu_deinit2(void)
  1171. {
  1172.     //free_irq(IRQ_IPU);
  1173.     CLRREG32(IPU_CTRL, CHIP_EN);
  1174.  
  1175.     /***wyang***/
  1176.     //cpm_stop_clock(CGM_IPU);
  1177.     SETREG32(CPM_CLKGR0, CLKGR0_IPU);
  1178.  
  1179.     ipu_inited = 0;
  1180.     return (0);
  1181. }
  1182.  
  1183. static int ipu_run;
  1184.  
  1185. void ipu_driver_set_src_stride(int src_w, int dst_w)
  1186. {
  1187.     img_param_t *img;
  1188.     img = ipu_def_img;
  1189.  
  1190.     img->stride = &def_stride;
  1191.     img->stride->out = dst_w*2;
  1192.     img->stride->y = src_w*2;
  1193.     img->stride->u = src_w/2;
  1194.     img->stride->v = src_w/2;
  1195. }
  1196.  
  1197. #if defined(CONFIG_JZ_CIM)
  1198.  
  1199. void ipu_driver_init_test(int src_w,int src_h,int dst_w,int dst_h)
  1200. {
  1201.     img_param_t *img;
  1202.     img = ipu_def_img;
  1203.     //img->output_mode = IPU_OUTPUT_TO_FRAMEBUFFER;
  1204.     img->in_width = src_w;
  1205.     img->in_height = src_h;
  1206.     img->in_bpp = 16;
  1207.     img->out_width = dst_w;
  1208.     img->out_height = dst_h;
  1209.     if (dst_w > 2*src_w)
  1210.     {
  1211.         img->out_x = (dst_w - 2*src_w)/2;
  1212.     }else
  1213.         img->out_x = 0;
  1214.  
  1215.     if (dst_h > 2*src_h)
  1216.     {
  1217.         img->out_y = (dst_h - 2*src_h)/2;
  1218.     }else
  1219.         img->out_y = 0;
  1220.  
  1221.     img->ipu_ctrl = ADDR_SEL | SPKG_SEL ;
  1222.     //img->ipu_ctrl = ADDR_SEL | LCDC_SEL;
  1223.     //img->ipu_ctrl =  SPKG_SEL;
  1224.     //img->zoom_mode = ZOOM_MODE_BILINEAR;
  1225.     //img->in_fmt  = IN_FMT_YUV422;
  1226.     //img->out_fmt = OUT_FMT_RGB565;
  1227.     img->ipu_d_fmt = IN_FMT_YUV422 | OUT_FMT_RGB565 | IPU_INDATA_PACKAGE_OFFSIZE;
  1228.     //img->ipu_d_fmt = IN_FMT_YUV422 | OUT_FMT_RGB565 ;
  1229.     //img->out_buf = (unsigned int)(lcd_frame0 + 480*272*2);
  1230.     img->out_buf = (unsigned int)(lcd_frame1);
  1231.     img->y_buf = (unsigned int)cim_read_dma();
  1232.     img->u_buf = (unsigned int)cim_read_dma();
  1233.     img->v_buf = (unsigned int)cim_read_dma();
  1234. #if 0
  1235.     img->stride = &def_stride;
  1236.     img->stride->out = dst_w*2;
  1237.     img->stride->y = src_w*2;
  1238.     img->stride->u = src_w/2;
  1239.     img->stride->v = src_w/2;
  1240. #else
  1241. #endif
  1242.     ipu_init2(img);
  1243. #if 0
  1244.         __lcd_clr_ena();
  1245.         __lcd_enable_f1();
  1246.         //__lcd_disable_f0();
  1247.         __lcd_fg1_use_ipu();
  1248.         REG32(IPU_V_BASE + REG_STATUS) &= ~OUT_END;
  1249.         REG32(IPU_V_BASE + REG_CTRL) |= IPU_RUN;
  1250.         __lcd_set_ena();
  1251. #endif
  1252.  
  1253. }
  1254. EXPORT_SYMBOL(ipu_driver_init_test);
  1255. #endif
  1256.  
  1257. void ipu_driver_start(void);
  1258. void ipu_driver_stop(void);
  1259. void ipu_driver_open_tv(int src_w,int src_h,int dst_w,int dst_h)
  1260. {
  1261.     img_param_t *img;
  1262.     img = ipu_def_img;
  1263.     //img->output_mode = IPU_OUTPUT_TO_FRAMEBUFFER;
  1264.     img->in_width = src_w;
  1265.     img->in_height = src_h;
  1266.     img->in_bpp = 16;
  1267.     img->out_width = dst_w;
  1268.     img->out_height = dst_h;
  1269.  
  1270.     if (dst_w > 2*src_w)
  1271.     {
  1272.         img->out_x = (dst_w - 2*src_w)/2;
  1273.     }else
  1274.         img->out_x = 0;
  1275.  
  1276.     if (dst_h > 2*src_h)
  1277.     {
  1278.         img->out_y = (dst_h - 2*src_h)/2;
  1279.     }else
  1280.         img->out_y = 0;
  1281.  
  1282.  
  1283.     img->ipu_ctrl = ADDR_SEL | SPKG_SEL;
  1284.     //img->ipu_ctrl = ADDR_SEL | LCDC_SEL;
  1285.     //img->ipu_ctrl =  SPKG_SEL;
  1286.     //img->zoom_mode = ZOOM_MODE_BILINEAR;
  1287.     //img->in_fmt  = IN_FMT_YUV422;
  1288.     //img->out_fmt = OUT_FMT_RGB565;
  1289.     img->ipu_d_fmt = IN_FMT_PKG_RGB565 | OUT_FMT_RGB565 | 0x1 ;
  1290.     //img->ipu_d_fmt = IN_FMT_YUV422 | OUT_FMT_RGB565 ;
  1291.     //img->out_buf = (unsigned int)(lcd_frame0 + 480*272*2);
  1292.     img->out_buf = (unsigned int)(lcd_frame01);
  1293.     img->y_buf = (unsigned int)PHYS(lcd_frame0);
  1294.     img->u_buf = (unsigned int)PHYS(lcd_frame0);
  1295.     img->v_buf = (unsigned int)PHYS(lcd_frame0);
  1296.     img->stride = &def_stride;
  1297.     img->stride->out = dst_w*2;
  1298.     img->stride->y = src_w*2;
  1299.     img->stride->u = src_w/2;
  1300.     img->stride->v = src_w/2;
  1301.     ipu_init2(img);
  1302.     //ipu_driver_start();
  1303.  
  1304. }
  1305.  
  1306. void ipu_driver_flush_tv(void)
  1307. {
  1308.     if (!ipu_inited)
  1309.         return;
  1310.     //printk("flush tv start\n");
  1311.     while(((REG32(IPU_V_BASE + REG_STATUS)) & OUT_END) == 0);
  1312.     REG32(IPU_V_BASE + REG_STATUS) &= ~OUT_END;
  1313.     if (!REG32(IPU_V_BASE + REG_ADDR_CTRL)){
  1314.  
  1315.         REG32(IPU_V_BASE + REG_Y_ADDR) = (unsigned int)PHYS(lcd_frame0);
  1316.         REG32(IPU_V_BASE + REG_ADDR_CTRL) = YUV_READY;
  1317.         REG32(IPU_V_BASE + REG_OUT_ADDR) = (unsigned int)ipu_def_img->out_buf;
  1318.         REG32(IPU_V_BASE + REG_STATUS) &= ~OUT_END;
  1319.         REG32(IPU_V_BASE + REG_CTRL) |= IPU_RUN;
  1320.     }
  1321.     //printk("flush tv end\n");
  1322.  
  1323. }
  1324.  
  1325. void ipu_driver_close_tv(void)
  1326. {
  1327.     ipu_driver_stop();
  1328. }
  1329.  
  1330. #if defined(CONFIG_JZ_CIM)
  1331. void ipu_driver_update_test(void)
  1332. {
  1333.  
  1334.     //printk("comming medive update cim data!\n");
  1335.     while(((REG32(IPU_V_BASE + REG_STATUS)) & OUT_END) == 0);
  1336.     REG32(IPU_V_BASE + REG_STATUS) &= ~OUT_END;
  1337.     if (!REG32(IPU_V_BASE + REG_ADDR_CTRL)){
  1338.  
  1339.         //REG32(IPU_V_BASE + REG_Y_ADDR) = virt_to_phys(vaddr_yuv);
  1340. #if 1
  1341.         REG32(IPU_V_BASE + REG_Y_ADDR) = (unsigned int)cim_read_dma();
  1342.         REG32(IPU_V_BASE + REG_ADDR_CTRL) = YUV_READY;
  1343.         REG32(IPU_V_BASE + REG_OUT_ADDR) = (unsigned int)ipu_def_img->out_buf;
  1344.         REG32(IPU_V_BASE + REG_STATUS) &= ~OUT_END;
  1345.         REG32(IPU_V_BASE + REG_CTRL) |= IPU_RUN;
  1346. #else
  1347.         REG32(IPU_V_BASE + REG_CTRL) |= IPU_RUN;
  1348. #endif
  1349.     }
  1350.     //printk("go out medive update cim data!\n");
  1351.  
  1352. }
  1353. EXPORT_SYMBOL(ipu_driver_update_test);
  1354. #endif
  1355.  
  1356. void ipu_driver_start(void)
  1357. {
  1358.         REG32(IPU_V_BASE + REG_STATUS) &= ~OUT_END;
  1359.         REG32(IPU_V_BASE + REG_CTRL) |= IPU_RUN;
  1360. }
  1361. void ipu_driver_stop(void)
  1362. {
  1363.     if (!ipu_inited)
  1364.         return;
  1365.     ipu_inited = 0;
  1366.     while(((REG32(IPU_V_BASE + REG_STATUS)) & OUT_END) == 0);
  1367.     REG32(IPU_V_BASE + REG_STATUS) &= ~OUT_END;
  1368.     REG32(IPU_V_BASE + REG_CTRL) &= ~IPU_RUN;
  1369.     memset((unsigned char *)ipu_def_img->out_buf,0,ipu_def_img->out_width*ipu_def_img->out_height*2);
  1370. }
  1371. void ipu_driver_stop_new(void)
  1372. {
  1373.     if (!ipu_inited)
  1374.         return;
  1375.     ipu_inited = 0;
  1376.     while(((REG32(IPU_V_BASE + REG_STATUS)) & OUT_END) == 0);
  1377.     REG32(IPU_V_BASE + REG_STATUS) &= ~OUT_END;
  1378.     REG32(IPU_V_BASE + REG_CTRL) &= ~IPU_RUN;
  1379.     //memset((unsigned char *)ipu_def_img->out_buf,0,ipu_def_img->out_width*ipu_def_img->out_height*2);
  1380. }
  1381.  
  1382.  
  1383. void ipu_driver_wait_end(void)
  1384. {
  1385.     while(((REG32(IPU_V_BASE + REG_STATUS)) & OUT_END) == 0);
  1386.     REG32(IPU_V_BASE + REG_STATUS) &= ~OUT_END;
  1387. }
  1388.  
  1389. int ipu_get_status(void)
  1390. {
  1391.     return ipu_inited;
  1392. }
  1393.  
  1394. EXPORT_SYMBOL(ipu_get_status);
  1395.  
  1396. EXPORT_SYMBOL(ipu_driver_wait_end);
  1397. EXPORT_SYMBOL(ipu_driver_stop);
  1398. EXPORT_SYMBOL(ipu_driver_stop_new);
  1399. EXPORT_SYMBOL(ipu_driver_open_tv);
  1400. EXPORT_SYMBOL(ipu_driver_close_tv);
  1401. EXPORT_SYMBOL(ipu_driver_flush_tv);
  1402. EXPORT_SYMBOL(ipu_driver_set_src_stride);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement