Camera module video4linux driver port to 2.6
Signed-off-by: Daniel Ribeiro <drwyrm@gmail.com>
Index: linux-2.6.16/drivers/media/video/camera.h
===================================================================
--- linux-2.6.16.orig/drivers/media/video/camera.h	2007-03-17 18:00:37.000000000 -0300
+++ linux-2.6.16/drivers/media/video/camera.h	2007-03-17 18:01:58.000000000 -0300
@@ -1,32 +1,36 @@
-/*================================================================================
-                                                                               
-                     Module Name:  camera.h
-
-General Description: Camera module adcm2700  head file
-
-==================================================================================
-                      Motorola Confidential Proprietary
-                  Advanced Technology and Software Operations
-                (c) Copyright Motorola 1999, All Rights Reserved
-  
-Revision History:
-                            Modification     Tracking
-Author                 Date          Number     Description of Changes
-----------------   ------------    ----------   -------------------------
-Wangfei(w20239)     12/19/2003      LIBdd35749    Created
-wangfei(w20239)     02/26/2004      LIBdd81055    Update algorithm for DMA transfer
-
-Portability: Indicate ifthis module is portable to other compilers or 
-platforms. If not, indicate specific reasons why is it not portable.
-
-==================================================================================
-                                 INCLUDE FILES
-================================================================================*/
+/*
+ * linux/drivers/media/video/camera.h
+ *
+ * Camera module head file
+ *
+ * Copyright (C) 2003-2004 Motorola
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Dec 19,2003 - (Motorola) Created
+ * Feb 26,2004 - (Motorola) Update algorithm for DMA transfer
+ * Mar 17,2007 - (Daniel Ribeiro) Ported to linux 2.6
+ *
+ */
+
 #ifndef CAMERA_H_
 #define CAMERA_H_
 
 #include <linux/pxa_camera.h>
 #include <linux/videodev.h>
+#include <linux/interrupt.h>
 
 #define DEBUG   1
  
@@ -321,7 +325,7 @@
 //debug
 void ci_dump(void);
 // IRQ
-irqreturn_t pxa_camera_irq(int irq, void *dev_id, struct pt_regs *regs);
+static irqreturn_t pxa_camera_irq(int irq, void *dev_id, struct pt_regs *regs);
 
 #ifdef DEBUG
 
Index: linux-2.6.16/drivers/media/video/pxa_camera.c
===================================================================
--- linux-2.6.16.orig/drivers/media/video/pxa_camera.c	2007-03-17 18:00:37.000000000 -0300
+++ linux-2.6.16/drivers/media/video/pxa_camera.c	2007-03-17 20:07:31.000000000 -0300
@@ -1,51 +1,47 @@
-/*================================================================================
-                                                                               
-                     Module Name:  pxa-camera.c
-
-General Description: Camera module e680 camera  source file
-
-==================================================================================
-                      Motorola Confidential Proprietary
-                  Advanced Technology and Software Operations
-                (c) Copyright Motorola 1999, All Rights Reserved
-  
-Revision History:
-                            Modification     Tracking
-Author                 Date          Number     Description of Changes
-----------------   ------------    ----------   -------------------------
-Wangfei(w20239)     12/19/2003      LIBdd35749   Created
-
-WangWenxin(w20158)  1/1/2004        LIBdd35749   Modified
-
-wangfei(w20239)     02/05/2004      LIBdd74309   Set frame rate in video mode
-
-wangfei(w20239)     02/26/2004      LIBdd81055   New chip id support
-                                                 Update algorithm for DMA transfer
-                                                 Update strategy for memory management
-                                                 Fix still picture capture failed sometime
-                                                 New Agilent sensor chip ID support
-                                                 Make output height in an even multiple of 8
-                                                 Dynamic power management feature 
-                                                 
-wangfei(w20239)     03/08/2004      LIBdd84578   Photo effects setting
-                                                 Fix segmentation fault in rmmod
-                                                 Adjust default image buffer size  
-
-wangfei(w20239)     04/26/2004      LIBdd97716   Power Management added
-                                                 Photo effects setting bug fix
-                                                                                   
-wangfei(w20239)     05/28/2004      LIBee13628   add two new interface.
-                                                 1 get ready frames
-                                                 2 set frame buffer count
-                    
-                    06/10/2004                   add mt9v111 support                                                                                
-
-Portability: Indicate ifthis module is portable to other compilers or 
-platforms. If not, indicate specific reasons why is it not portable.
+/*
+ *  linux/drivers/media/video/pxa_camera.c
+ *
+ *  Bulverde Processor Camera Interface driver.
+ *
+ *  Copyright (C) 2003-2004 Motorola
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Dec 19,2003 - (Motorola) Created
+ * Jan 1,2004  - (Motorola) Modified
+ * Feb 5,2004  - (Motorola) Set frame rate in video mode
+ * Feb 26,2004 - (Motorola) New chip id support
+ *                          Update algorithm for DMA transfer
+ *                          Update strategy for memory management
+ *                          Fix still picture capture failed sometime
+ *                          New Agilent sensor chip ID support
+ *                          Make output height in an even multiple of 8
+ *                          Dynamic power management feature
+ * Mar 8,2004  - (Motorola) Photo effects setting
+ *                          Fix segmentation fault in rmmod
+ *                          Adjust default image buffer size
+ * Apr 26,2004 - (Motorola) Power Management added
+ *                          Photo effects setting bug fix
+ * May 28,2004 - (Motorola) Add two new interface:
+ *                                                 1 get ready frames
+ *                                                 2 set frame buffer count
+ * Jun 10,2004 - (Motorola) Add mt9v111 support
+ * Mar 17,2007 - (Daniel Ribeiro) Port to linux 2.6
+ *
+ */
 
-==================================================================================
-                                 INCLUDE FILES
-================================================================================*/  
 #include <linux/config.h>
 #include <linux/module.h>
 #include <linux/version.h>
@@ -94,10 +90,10 @@
 #define DRCMR70		__REG(0x40001118)  /* Request to Channel Map Register for Camera FIFO 2 Request */
 
 static camera_context_t  *g_camera_context;
-#ifdef  CONFIG_ARCH_EZX_E680
+#ifdef  CONFIG_PXA_EZX_E680
 extern camera_function_t  e680_camera_func;
 #endif
-#ifdef CONFIG_ARCH_EZX_A780
+#ifdef CONFIG_PXA_EZX_A780
   #ifdef CONFIG_CAMERA_MT9M111
   extern camera_function_t  mt9m111_func;
   #endif
@@ -191,7 +187,7 @@
 
 static struct video_device vd = {
 	.owner		= THIS_MODULE,
-	.name 		= "E680 camera",
+	.name 		= "pxa camera",
 	.type		= VID_TYPE_CAPTURE,
 	.hardware	= VID_HARDWARE_PXA_CAMERA,      /* FIXME */
 	.fops		= &vd_fops,
@@ -277,9 +273,8 @@
 		set_page_count(page, 1);
 		SetPageReserved(page);
 	}
-	camera_context->buffer_virtual = remap_page_array(camera_context->page_array, 
-                                                      pages,
- 	                                                  GFP_KERNEL);
+	camera_context->buffer_virtual = vmap(camera_context->page_array,
+						pages, VM_MAP, PAGE_KERNEL);
 	if(camera_context->buffer_virtual == NULL)
 	{
 		goto error;
@@ -334,7 +329,7 @@
                 fifox_descriptors_virtual, fifox_descriptors_physical              
                 fifox_num_descriptors 
 */
-//#ifdef  CONFIG_ARCH_EZX_E680
+//#ifdef  CONFIG_PXA_EZX_E680
 static int generate_fifo2_dma_chain(p_camera_context_t camera_context, pxa_dma_desc ** cur_vir, pxa_dma_desc ** cur_phy)
 {
     pxa_dma_desc *cur_des_virtual, *cur_des_physical, *last_des_virtual = NULL;
@@ -370,7 +365,7 @@
                 cur_des_virtual->ddadr = (unsigned)cur_des_physical + sizeof(pxa_dma_desc);
                 cur_des_virtual->dsadr = CIBR2_PHY;      // FIFO2 physical address
                 cur_des_virtual->dtadr =
-                page_to_bus(camera_context->page_array[target_page_num]);
+                virt_to_bus(camera_context->page_array[target_page_num]);
                 cur_des_virtual->dcmd = des_transfer_size | DCMD_FLOWSRC | DCMD_INCTRGADDR | DCMD_BURST32;
 
                 // advance pointers
@@ -400,12 +395,12 @@
                 if (!(j % 2))
                 {
                     cur_des_virtual->dtadr =
-                    page_to_bus(camera_context->page_array[target_page_num]);
+                    virt_to_bus(camera_context->page_array[target_page_num]);
                 }
                 else 
                 {
                     cur_des_virtual->dtadr =
-                    page_to_bus(camera_context->page_array[target_page_num]) + (PAGE_SIZE/2);
+                    virt_to_bus(camera_context->page_array[target_page_num]) + (PAGE_SIZE/2);
                 }
 
                 cur_des_virtual->dcmd = des_transfer_size | DCMD_FLOWSRC | DCMD_INCTRGADDR | DCMD_BURST32;
@@ -414,7 +409,7 @@
                             cur_des_virtual->ddadr,
                             cur_des_virtual->dtadr,
                             cur_des_virtual->dcmd,
-                            page_to_bus(camera_context->page_array[target_page_num]) );
+                            virt_to_bus(camera_context->page_array[target_page_num]) );
     
                 // advance pointers
                 remain_size -= des_transfer_size;
@@ -468,7 +463,7 @@
                 cur_des_virtual->ddadr = (unsigned)cur_des_physical + sizeof(pxa_dma_desc);
                 cur_des_virtual->dsadr = CIBR1_PHY;      // FIFO1 physical address
                 cur_des_virtual->dtadr =
-                page_to_bus(camera_context->page_array[target_page_num]);
+                virt_to_bus(camera_context->page_array[target_page_num]);
                 cur_des_virtual->dcmd = des_transfer_size | DCMD_FLOWSRC | DCMD_INCTRGADDR | DCMD_BURST32;
 
                 // advance pointers
@@ -501,12 +496,12 @@
                 if(!(j % 2))
                 {
                     cur_des_virtual->dtadr =
-                    page_to_bus(camera_context->page_array[target_page_num]);
+                    virt_to_bus(camera_context->page_array[target_page_num]);
                 }
                 else 
                 {
                     cur_des_virtual->dtadr =
-                    page_to_bus(camera_context->page_array[target_page_num]) + (PAGE_SIZE/2);
+                    virt_to_bus(camera_context->page_array[target_page_num]) + (PAGE_SIZE/2);
                 }
 
                 cur_des_virtual->dcmd = des_transfer_size | DCMD_FLOWSRC | DCMD_INCTRGADDR | DCMD_BURST32;
@@ -515,7 +510,7 @@
                         cur_des_virtual->ddadr,
                         cur_des_virtual->dtadr,
                         cur_des_virtual->dcmd,
-                        page_to_bus(camera_context->page_array[target_page_num]));
+                        virt_to_bus(camera_context->page_array[target_page_num]));
 
                 // advance pointers
                 remain_size -= des_transfer_size;
@@ -569,7 +564,7 @@
                 cur_des_virtual->ddadr = (unsigned)cur_des_physical + sizeof(pxa_dma_desc);
                 cur_des_virtual->dsadr = CIBR0_PHY;       // FIFO0 physical address
                 cur_des_virtual->dtadr =
-                page_to_bus(camera_context->page_array[target_page_num]);
+                virt_to_bus(camera_context->page_array[target_page_num]);
                 cur_des_virtual->dcmd = des_transfer_size | DCMD_FLOWSRC | DCMD_INCTRGADDR | DCMD_BURST32;
 
                 // advance pointers
@@ -599,11 +594,11 @@
                 cur_des_virtual->dsadr = CIBR0_PHY;       // FIFO0 physical address
                 if(!(j % 2))
                 {
-                    cur_des_virtual->dtadr = page_to_bus(camera_context->page_array[target_page_num]);
+                    cur_des_virtual->dtadr = virt_to_bus(camera_context->page_array[target_page_num]);
                 }
                 else 
                 {
-                    cur_des_virtual->dtadr = page_to_bus(camera_context->page_array[target_page_num]) + (PAGE_SIZE / 2);
+                    cur_des_virtual->dtadr = virt_to_bus(camera_context->page_array[target_page_num]) + (PAGE_SIZE / 2);
                 }
 
                 cur_des_virtual->dcmd = des_transfer_size | DCMD_FLOWSRC | DCMD_INCTRGADDR | DCMD_BURST32;
@@ -612,7 +607,7 @@
                             cur_des_virtual->ddadr,
                             cur_des_virtual->dtadr,
                             cur_des_virtual->dcmd,
-                            page_to_bus(camera_context->page_array[target_page_num]),
+                            virt_to_bus(camera_context->page_array[target_page_num]),
                             target_page_num);
                 // advance pointers
                 remain_size -= des_transfer_size;
@@ -751,7 +746,7 @@
                     
 		        cur_des_virtual->ddadr = (unsigned)cur_des_physical + sizeof(pxa_dma_desc);
         		cur_des_virtual->dsadr = CIBR0_PHY;       // FIFO0 physical address
-        		cur_des_virtual->dtadr = page_to_bus(camera_context->page_array[target_page_num]);
+        		cur_des_virtual->dtadr = virt_to_bus(camera_context->page_array[target_page_num]);
         		cur_des_virtual->dcmd = des_transfer_size | DCMD_FLOWSRC | DCMD_INCTRGADDR | DCMD_BURST32;
 
 		        // advance pointers
@@ -792,7 +787,7 @@
                             
         	        cur_des_virtual->ddadr = (unsigned)cur_des_physical + sizeof(pxa_dma_desc);
         	        cur_des_virtual->dsadr = CIBR1_PHY;      // FIFO1 physical address
-        	        cur_des_virtual->dtadr = page_to_bus(camera_context->page_array[target_page_num]);
+        	        cur_des_virtual->dtadr = virt_to_bus(camera_context->page_array[target_page_num]);
         	        cur_des_virtual->dcmd  = des_transfer_size | DCMD_FLOWSRC | DCMD_INCTRGADDR | DCMD_BURST32;
        		     // advance pointers
        		     
@@ -833,7 +828,7 @@
               		des_transfer_size = remain_size;
               	cur_des_virtual->ddadr = (unsigned)cur_des_physical + sizeof(pxa_dma_desc);
               	cur_des_virtual->dsadr = CIBR2_PHY;      // FIFO2 physical address
-              	cur_des_virtual->dtadr = page_to_bus(camera_context->page_array[target_page_num]);
+              	cur_des_virtual->dtadr = virt_to_bus(camera_context->page_array[target_page_num]);
               	cur_des_virtual->dcmd = des_transfer_size | DCMD_FLOWSRC | DCMD_INCTRGADDR | DCMD_BURST32;
               	// advance pointers
               	remain_size -= des_transfer_size;
@@ -947,14 +942,14 @@
     /*init sensor */
     if(detected_sensor_type == 0) {
     /* test sensor type */
-#ifdef  CONFIG_ARCH_EZX_E680
+#ifdef  CONFIG_PXA_EZX_E680
     camera_context->camera_functions = &e680_camera_func;
     if((ret = camera_context->camera_functions->init(camera_context)) ==0)
     {
 	    goto test_success;
     }
 #endif
-#ifdef CONFIG_ARCH_EZX_A780
+#ifdef CONFIG_PXA_EZX_A780
 
   #ifdef CONFIG_CAMERA_MT9M111
     camera_context->camera_functions = &mt9m111_func;
@@ -1000,7 +995,7 @@
     else 
     {
         switch (detected_sensor_type) {
-#ifdef  CONFIG_ARCH_EZX_E680
+#ifdef  CONFIG_PXA_EZX_E680
                 case CAMERA_TYPE_ADCM_2700:
                     camera_context->camera_functions = &e680_camera_func;
                 break;
@@ -1008,7 +1003,7 @@
                     camera_context->camera_functions = &e680_camera_func;
                 break;
 #endif
-#ifdef CONFIG_ARCH_EZX_A780
+#ifdef CONFIG_PXA_EZX_A780
     #ifdef CONFIG_CAMERA_OV9640
                 case CAMERA_TYPE_OMNIVISION_9640:
                     camera_context->camera_functions = &ov9640_func;
@@ -1545,7 +1540,7 @@
     */
     if(camera_init(cam_ctx))
     {
-       dbg_print("camera_init faile!");
+       dbg_print("camera_init failed!");
 	    camera_free_dma_irq();
        pxa_camera_mem_deinit();
        return -1;
@@ -1556,12 +1551,14 @@
        init function of each sensor should set proper value for cam_ctx->buf_size 
     */
    	cam_ctx->dma_started = 0;
-    cam_ctx->dma_descriptors_virtual = consistent_alloc(GFP_KERNEL, 
-                                                        (cam_ctx->dma_descriptors_size) * sizeof(pxa_dma_desc),
-                                                        (void *)&(cam_ctx->dma_descriptors_physical));
+    	cam_ctx->dma_descriptors_virtual = dma_alloc_coherent(NULL,
+		cam_ctx->dma_descriptors_size * sizeof(pxa_dma_desc),
+		&cam_ctx->dma_descriptors_physical,
+		GFP_KERNEL | GFP_DMA);
+
     if(cam_ctx->dma_descriptors_virtual == NULL)
     {
-       dbg_print("consistent alloc memory for dma_descriptors_virtual fail!");
+       dbg_print("coherent alloc memory for dma_descriptors_virtual fail!");
 	    camera_free_dma_irq();
        pxa_camera_mem_deinit();
        return -1;
@@ -2097,10 +2094,13 @@
     {
         if(g_camera_context->dma_descriptors_virtual != NULL) 
         {
-         consistent_free(g_camera_context->dma_descriptors_virtual, 
-                         g_camera_context->dma_descriptors_size * sizeof(pxa_dma_desc),  
-                         (int)g_camera_context->dma_descriptors_physical);
-		      
+	    dma_free_coherent(NULL,
+		    g_camera_context->dma_descriptors_size *
+		    				sizeof(pxa_dma_desc),
+		    g_camera_context->dma_descriptors_virtual,
+		    g_camera_context->dma_descriptors_physical);
+//            kfree(g_camera_context->dma_descriptors_virtual);
+
           g_camera_context->dma_descriptors_virtual = NULL;
 
         }
@@ -2155,7 +2155,7 @@
 	dbg_print("PXA_CAMERA: video_register_device failed\n");
 	return -EIO;
     }
-#ifdef CONFIG_ARCH_EZX_A780
+#ifdef CONFIG_PXA_EZX_A780
     PGSR1 |= GPIO_bit(50);
     PGSR0 |= GPIO_bit(19);
 #endif
@@ -2761,7 +2761,7 @@
 	cnt_block = (cam_ctx->block_header + 1) % cam_ctx->block_number;
     
     // FIFO0
-	(pxa_dma_desc *)cnt_head = (pxa_dma_desc *)cam_ctx->fifo0_descriptors_virtual + 
+	cnt_head = (pxa_dma_desc *)cam_ctx->fifo0_descriptors_virtual +
                                 cnt_block * cam_ctx->fifo0_num_descriptors;
                                 
 	cnt_tail = cnt_head + cam_ctx->fifo0_num_descriptors - 1;
