소스 검색

Merge branch 'CR_2288_VPU_515_samin.guo' into 'jh7110-devel'

Cr 2288 vpu 515 samin.guo

See merge request sdk/freelight-u-sdk!185
andy.hu 1 년 전
부모
커밋
4479476fa4
6개의 변경된 파일142개의 추가작업 그리고 57개의 파일을 삭제
  1. 0 2
      codaj12/build_for_riscv.sh
  2. 29 5
      codaj12/jdi/linux/driver/jpu.c
  3. 1 1
      wave420l/code/build.sh
  4. 40 24
      wave420l/code/vdi/linux/driver/venc.c
  5. 1 1
      wave511/code/build_for_vdec.sh
  6. 71 24
      wave511/code/vdi/linux/driver/vdec.c

+ 0 - 2
codaj12/build_for_riscv.sh

@@ -23,8 +23,6 @@ cp -rdvp ${jpu_path}/script/* ${obj_jpu}/
 cp -rdvp ${jpu_path}/cfg $obj_jpu
 cp -rdvp ${jpu_path}/yuv $obj_jpu
 cp -rdvp ${jpu_path}/stream $obj_jpu
-cp -dvp ${jpu_driver}/load.sh $obj_jpu_driver
-cp -dvp ${jpu_driver}/unload.sh $obj_jpu_driver
 
 #make linux driver
 cd $jpu_driver

+ 29 - 5
codaj12/jdi/linux/driver/jpu.c

@@ -166,8 +166,10 @@ static void jpu_pmu_disable(struct device *dev);
 
 static jpudrv_buffer_t s_instance_pool = {0};
 static jpu_drv_context_t s_jpu_drv_context;
+static dev_t s_jpu_devt;
 static int s_jpu_major;
 static struct cdev s_jpu_cdev;
+static struct class *s_jpu_class;
 static jpu_clk_t *s_jpu_clk;
 static int s_jpu_open_ref_count;
 #ifdef JPU_SUPPORT_ISR
@@ -845,6 +847,7 @@ static int jpu_probe(struct platform_device *pdev)
 {
     int err = 0;
     struct resource *res = NULL;
+    struct device *devices;
 #ifdef JPU_SUPPORT_RESERVED_VIDEO_MEMORY
 	struct resource res_cma;
 	struct device_node *node;
@@ -872,21 +875,35 @@ static int jpu_probe(struct platform_device *pdev)
         dev_info(jpu_dev,"init device.\n");
     }
     /* get the major number of the character device */
-    if ((alloc_chrdev_region(&s_jpu_major, 0, 1, JPU_DEV_NAME)) < 0) {
+    if ((alloc_chrdev_region(&s_jpu_devt, 0, 1, JPU_DEV_NAME)) < 0) {
         err = -EBUSY;
         printk(KERN_ERR "could not allocate major number\n");
         goto ERROR_PROVE_DEVICE;
     }
 
+    s_jpu_major = MAJOR(s_jpu_devt);
     /* initialize the device structure and register the device with the kernel */
     cdev_init(&s_jpu_cdev, &jpu_fops);
-    if ((cdev_add(&s_jpu_cdev, s_jpu_major, 1)) < 0) {
+    if ((cdev_add(&s_jpu_cdev, s_jpu_devt, 1)) < 0) {
         err = -EBUSY;
         printk(KERN_ERR "could not allocate chrdev\n");
 
         goto ERROR_PROVE_DEVICE;
     }
 
+    s_jpu_class = class_create(THIS_MODULE, JPU_DEV_NAME);
+    if (IS_ERR(s_jpu_class)) {
+	dev_err(jpu_dev, "class creat error.\n");
+	goto ERROR_CRART_CLASS;
+    }
+
+    devices = device_create(s_jpu_class, 0, MKDEV(s_jpu_major, 0),
+				NULL, JPU_DEV_NAME);
+    if (IS_ERR(devices)) {
+	dev_err(jpu_dev, "device creat error.\n");
+	goto ERROR_CREAT_DEVICE;
+    }
+
     if (pdev)
         s_jpu_clk = jpu_clk_get(pdev);
     else
@@ -955,7 +972,10 @@ static int jpu_probe(struct platform_device *pdev)
 
     return 0;
 
-
+ERROR_CREAT_DEVICE:
+	class_destroy(s_jpu_class);
+ERROR_CRART_CLASS:
+	cdev_del(&s_jpu_cdev);
 ERROR_PROVE_DEVICE:
 
     if (s_jpu_major)
@@ -985,8 +1005,10 @@ static int jpu_remove(struct platform_device *pdev)
 #endif
 
     if (s_jpu_major > 0) {
+        device_destroy(s_jpu_class, MKDEV(s_jpu_major, 0));
+        class_destroy(s_jpu_class);
         cdev_del(&s_jpu_cdev);
-        unregister_chrdev_region(s_jpu_major, 1);
+        unregister_chrdev_region(s_jpu_devt, 1);
         s_jpu_major = 0;
     }
 
@@ -1089,8 +1111,10 @@ static void __exit jpu_exit(void)
 #endif /* JPU_SUPPORT_RESERVED_VIDEO_MEMORY */
 
     if (s_jpu_major > 0) {
+        device_destroy(s_jpu_class, MKDEV(s_jpu_major, 0));
+        class_destroy(s_jpu_class);
         cdev_del(&s_jpu_cdev);
-        unregister_chrdev_region(s_jpu_major, 1);
+        unregister_chrdev_region(s_jpu_devt, 1);
         s_jpu_major = 0;
     }
 

+ 1 - 1
wave420l/code/build.sh

@@ -16,7 +16,7 @@ if [ ! -d $DRI_OPT ];then
 fi
 
 make -f  Wave420Driver.mak
-$CP $DRI_SRC/venc.ko $DRI_SRC/load.sh  $DRI_SRC/unload.sh $DRI_OPT
+$CP $DRI_SRC/venc.ko $DRI_OPT
 make -f  Wave420Driver.mak clean
 
 make -f  Wave420Enc.mak

+ 40 - 24
wave420l/code/vdi/linux/driver/venc.c

@@ -52,7 +52,7 @@
 
 /* definitions to be changed as customer  configuration */
 /* if you want to have clock gating scheme frame by frame */
-//#define VPU_SUPPORT_CLOCK_CONTROL
+#define VPU_SUPPORT_CLOCK_CONTROL
 
 /* if clktree is work,try this...*/
 #define STARFIVE_VPU_SUPPORT_CLOCK_CONTROL
@@ -174,13 +174,17 @@ static void vpu_clk_disable(vpu_clk_t *clk);
 static int vpu_clk_enable(vpu_clk_t *clk);
 static vpu_clk_t *vpu_clk_get(struct platform_device *pdev);
 static void vpu_clk_put(vpu_clk_t *clk);
+static int vpu_pmu_enable(struct device *dev);
+static void vpu_pmu_disable(struct device *dev);
 
 /* end customer definition */
 static vpudrv_buffer_t s_instance_pool = {0};
 static vpudrv_buffer_t s_common_memory = {0};
 static vpu_drv_context_t s_vpu_drv_context;
+static dev_t s_vpu_devt;
 static int s_vpu_major;
 static struct cdev s_vpu_cdev;
+static struct class *s_vpu_class;
 
 static struct vpu_clk_t *s_vpu_clk;
 static int s_vpu_open_ref_count;
@@ -465,6 +469,8 @@ static irqreturn_t vpu_irq_handler(int irq, void *dev_id)
 static int vpu_open(struct inode *inode, struct file *filp)
 {
 	DPRINTK("[VPUDRV][+] %s\n", __func__);
+	vpu_clk_enable(s_vpu_clk);
+	reset_control_deassert(s_vpu_clk->resets);
 	spin_lock(&s_vpu_lock);
 
 	s_vpu_drv_context.open_count++;
@@ -914,7 +920,9 @@ static int vpu_release(struct inode *inode, struct file *filp)
     }
     up(&s_vpu_sem);
 
-	vpu_hw_reset();
+	//vpu_hw_reset();
+	reset_control_assert(s_vpu_clk->resets);
+	vpu_clk_disable(s_vpu_clk);
 	
     return 0;
 }
@@ -1019,6 +1027,7 @@ static int vpu_probe(struct platform_device *pdev)
 {
 	int err = 0;
 	struct resource *res = NULL;
+	struct device *devices;
 
 	DPRINTK("[VPUDRV] vpu_probe\n");
 
@@ -1043,22 +1052,35 @@ static int vpu_probe(struct platform_device *pdev)
 	}
 
 	/* get the major number of the character device */
-	if ((alloc_chrdev_region(&s_vpu_major, 0, 1, VPU_DEV_NAME)) < 0) {
+	if ((alloc_chrdev_region(&s_vpu_devt, 0, 1, VPU_DEV_NAME)) < 0) {
 		err = -EBUSY;
 		printk(KERN_ERR "could not allocate major number\n");
 		goto ERROR_PROVE_DEVICE;
 	}
 	printk(KERN_INFO "SUCCESS alloc_chrdev_region\n");
-
+	s_vpu_major = MAJOR(s_vpu_devt);
 	/* initialize the device structure and register the device with the kernel */
 	cdev_init(&s_vpu_cdev, &vpu_fops);
-	if ((cdev_add(&s_vpu_cdev, s_vpu_major, 1)) < 0) {
+	if ((cdev_add(&s_vpu_cdev, s_vpu_devt, 1)) < 0) {
 		err = -EBUSY;
 		printk(KERN_ERR "could not allocate chrdev\n");
 
 		goto ERROR_PROVE_DEVICE;
 	}
 
+	s_vpu_class = class_create(THIS_MODULE, VPU_DEV_NAME);
+	if (IS_ERR(s_vpu_class)) {
+	    dev_err(vpu_dev, "class creat error.\n");
+	    goto ERROR_CRART_CLASS;
+	}
+
+	devices = device_create(s_vpu_class, 0, MKDEV(s_vpu_major, 0),
+				    NULL, VPU_DEV_NAME);
+	if (IS_ERR(devices)) {
+	    dev_err(vpu_dev, "device creat error.\n");
+	    goto ERROR_CREAT_DEVICE;
+	}
+
 	if (pdev)
 		s_vpu_clk = vpu_clk_get(pdev);
 	else
@@ -1069,10 +1091,7 @@ static int vpu_probe(struct platform_device *pdev)
 	else
 		DPRINTK("[VPUDRV] : get clock controller s_vpu_clk=%p\n", s_vpu_clk);
 
-#ifdef VPU_SUPPORT_CLOCK_CONTROL
-#else
-	vpu_clk_enable(s_vpu_clk);
-#endif
+	vpu_pmu_enable(s_vpu_clk->dev);
 
 #ifdef VPU_SUPPORT_ISR
 #ifdef VPU_SUPPORT_PLATFORM_DRIVER_REGISTER
@@ -1115,6 +1134,10 @@ static int vpu_probe(struct platform_device *pdev)
 
 	return 0;
 
+ERROR_CREAT_DEVICE:
+	class_destroy(s_vpu_class);
+ERROR_CRART_CLASS:
+	cdev_del(&s_vpu_cdev);
 ERROR_PROVE_DEVICE:
 
 	if (s_vpu_major)
@@ -1154,8 +1177,10 @@ static int vpu_remove(struct platform_device *pdev)
 #endif
 
 	if (s_vpu_major > 0) {
+		device_destroy(s_vpu_class, MKDEV(s_vpu_major, 0));
+		class_destroy(s_vpu_class);
 		cdev_del(&s_vpu_cdev);
-		unregister_chrdev_region(s_vpu_major, 1);
+		unregister_chrdev_region(s_vpu_devt, 1);
 		s_vpu_major = 0;
 	}
 
@@ -1167,8 +1192,8 @@ static int vpu_remove(struct platform_device *pdev)
 	if (s_vpu_register.virt_addr)
 		iounmap((void *)s_vpu_register.virt_addr);
 
-	vpu_clk_disable(s_vpu_clk);
 	vpu_clk_put(s_vpu_clk);
+	vpu_pmu_disable(&pdev->dev);
 
 #endif /*VPU_SUPPORT_PLATFORM_DRIVER_REGISTER*/
 
@@ -1501,8 +1526,10 @@ static void __exit vpu_exit(void)
 #endif
 
 	if (s_vpu_major > 0) {
+		device_destroy(s_vpu_class, MKDEV(s_vpu_major, 0));
+		class_destroy(s_vpu_class);
 		cdev_del(&s_vpu_cdev);
-		unregister_chrdev_region(s_vpu_major, 1);
+		unregister_chrdev_region(s_vpu_devt, 1);
 		s_vpu_major = 0;
 	}
 
@@ -1824,29 +1851,18 @@ static int vpu_clk_enable(vpu_clk_t *clk)
 {
 	int ret;
 
-	vpu_pmu_enable(clk->dev);
+
 	ret = clk_bulk_prepare_enable(clk->nr_clks, clk->clks);
 	if (ret)
 		dev_err(clk->dev, "enable clk error.\n");
 
-	ret = reset_control_deassert(clk->resets);
-	if (ret)
-		dev_err(clk->dev, "deassert vpu error.\n");
-
 	DPRINTK("[VPUDRV] vpu_clk_enable\n");
 	return ret;
 }
 
 static void vpu_clk_disable(vpu_clk_t *clk)
 {
-	int ret;
-
-	ret = reset_control_assert(clk->resets);
-	if (ret)
-		dev_err(clk->dev, "assert vpu error.\n");
-
 	clk_bulk_disable_unprepare(clk->nr_clks, clk->clks);
-	vpu_pmu_disable(clk->dev);
 }
 
 #endif /*STARFIVE_VPU_SUPPORT_CLOCK_CONTROL*/

+ 1 - 1
wave511/code/build_for_vdec.sh

@@ -20,7 +20,7 @@ $CP $DEC_FFMPEG_BIN $OUTPUT
 make -f WaveDecode-ffmpeg.mak clean
 
 make -f WaveDecDriver.mak
-$CP $DRI_SRC/vdec.ko $DRI_SRC/load.sh  $DRI_SRC/unload.sh $DRI_OPT
+$CP $DRI_SRC/vdec.ko $DRI_OPT
 make -f WaveDecDriver.mak clean
 
 make -f WaveDecode.mak

+ 71 - 24
wave511/code/vdi/linux/driver/vdec.c

@@ -3,6 +3,7 @@
 #include <linux/interrupt.h>
 #include <linux/ioport.h>
 #include <linux/module.h>
+#include <linux/mutex.h>
 #include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
 #include <linux/of.h>
@@ -168,8 +169,10 @@ static void vpu_pmu_disable(struct device *dev);
 static vpudrv_buffer_t s_instance_pool = {0};
 static vpudrv_buffer_t s_common_memory = {0};
 static vpu_drv_context_t s_vpu_drv_context;
+static dev_t s_vpu_devt;
 static int s_vpu_major;
 static struct cdev s_vpu_cdev;
+static struct class *s_vpu_class;
 
 static vpu_clk_t *s_vpu_clk;
 static int s_vpu_open_ref_count;
@@ -305,6 +308,8 @@ struct freq_ctrl {
 	const char *fixed_freq;
 	char re_cpu_gov[16];
 	char re_max_freq[16];
+	struct mutex mutex_lock;
+	int count;
 };
 
 static struct freq_ctrl *vpu_freq_ctrl;
@@ -337,6 +342,8 @@ static int vpu_freq_close(void)
 	if (!vpu_freq_ctrl)
 		return -ENODEV;
 
+	mutex_destroy(&vpu_freq_ctrl->mutex_lock);
+
 	if (vpu_freq_ctrl->governor && vpu_freq_ctrl->maxfreq
 		&& vpu_freq_ctrl->parameters_off) {
 		fput(vpu_freq_ctrl->governor);
@@ -357,18 +364,26 @@ static int vpu_freq_save_env(void)
 
 	if (!vpu_freq_ctrl)
 		return -ENODEV;
-	/*save env*/
-	kernel_read(vpu_freq_ctrl->governor, vpu_freq_ctrl->re_cpu_gov,
-			sizeof(vpu_freq_ctrl->re_cpu_gov), NULL);
-	kernel_read(vpu_freq_ctrl->maxfreq, vpu_freq_ctrl->re_max_freq,
-			sizeof(vpu_freq_ctrl->re_max_freq), NULL);
-
-	/*setenv*/
-	rv = kernel_write(vpu_freq_ctrl->maxfreq, fixed_freq,
-			strlen(fixed_freq), NULL);
-	rv = kernel_write(vpu_freq_ctrl->governor, governor_mode,
-			strlen(governor_mode), NULL);
-	rv = kernel_write(vpu_freq_ctrl->parameters_off, "1", 1, NULL);
+
+	mutex_lock(&vpu_freq_ctrl->mutex_lock);
+
+	if (vpu_freq_ctrl->count == 0) {
+		/*save env*/
+		kernel_read(vpu_freq_ctrl->governor, vpu_freq_ctrl->re_cpu_gov,
+				sizeof(vpu_freq_ctrl->re_cpu_gov), NULL);
+		kernel_read(vpu_freq_ctrl->maxfreq, vpu_freq_ctrl->re_max_freq,
+				sizeof(vpu_freq_ctrl->re_max_freq), NULL);
+
+		/*setenv*/
+		rv = kernel_write(vpu_freq_ctrl->maxfreq, fixed_freq,
+				strlen(fixed_freq), NULL);
+		rv = kernel_write(vpu_freq_ctrl->governor, governor_mode,
+				strlen(governor_mode), NULL);
+		rv = kernel_write(vpu_freq_ctrl->parameters_off, "1", 1, NULL);
+	}
+	vpu_freq_ctrl->count++;
+
+	mutex_unlock(&vpu_freq_ctrl->mutex_lock);
 
 	return 0;
 }
@@ -380,12 +395,19 @@ static int vpu_freq_put_env(void)
 	if (!vpu_freq_ctrl)
 		return -ENODEV;
 
-	rv = kernel_write(vpu_freq_ctrl->governor, vpu_freq_ctrl->re_cpu_gov,
-			strlen(vpu_freq_ctrl->re_cpu_gov), NULL);
-	rv = kernel_write(vpu_freq_ctrl->maxfreq, vpu_freq_ctrl->re_max_freq,
-			strlen(vpu_freq_ctrl->re_max_freq), NULL);
-	rv = kernel_write(vpu_freq_ctrl->parameters_off, "0", 1, NULL);
+	mutex_lock(&vpu_freq_ctrl->mutex_lock);
+
+	vpu_freq_ctrl->count--;
 
+	if (vpu_freq_ctrl->count == 0) {
+		rv = kernel_write(vpu_freq_ctrl->governor, vpu_freq_ctrl->re_cpu_gov,
+				strlen(vpu_freq_ctrl->re_cpu_gov), NULL);
+		rv = kernel_write(vpu_freq_ctrl->maxfreq, vpu_freq_ctrl->re_max_freq,
+				strlen(vpu_freq_ctrl->re_max_freq), NULL);
+		rv = kernel_write(vpu_freq_ctrl->parameters_off, "0", 1, NULL);
+	}
+
+	mutex_unlock(&vpu_freq_ctrl->mutex_lock);
 	return 0;
 }
 
@@ -415,6 +437,9 @@ static int vpu_freq_init(struct device *dev)
 	else
 		vpu_freq_ctrl->fixed_freq = "1250000";
 
+	vpu_freq_ctrl->count = 0;
+	mutex_init(&vpu_freq_ctrl->mutex_lock);
+
 	dev_dbg(dev, "fixed_freq:%s\n", vpu_freq_ctrl->fixed_freq);
 
 	return 0;
@@ -1489,11 +1514,11 @@ struct file_operations vpu_fops = {
     .mmap = vpu_mmap,
 };
 
-
 static int vpu_probe(struct platform_device *pdev)
 {
     int err = 0;
     struct resource *res = NULL;
+    struct device *devices;
 #ifdef VPU_SUPPORT_RESERVED_VIDEO_MEMORY
 	struct resource res_cma;
 	struct device_node *node;
@@ -1520,22 +1545,36 @@ static int vpu_probe(struct platform_device *pdev)
     }
 
     /* get the major number of the character device */
-    if ((alloc_chrdev_region(&s_vpu_major, 0, 1, VPU_DEV_NAME)) < 0) {
+    if ((alloc_chrdev_region(&s_vpu_devt, 0, 1, VPU_DEV_NAME)) < 0) {
         err = -EBUSY;
         printk(KERN_ERR "could not allocate major number\n");
         goto ERROR_PROVE_DEVICE;
     }
     printk(KERN_INFO "SUCCESS alloc_chrdev_region\n");
 
+    s_vpu_major = MAJOR(s_vpu_devt);
     /* initialize the device structure and register the device with the kernel */
     cdev_init(&s_vpu_cdev, &vpu_fops);
-    if ((cdev_add(&s_vpu_cdev, s_vpu_major, 1)) < 0) {
+    if ((cdev_add(&s_vpu_cdev, s_vpu_devt, 1)) < 0) {
         err = -EBUSY;
         printk(KERN_ERR "could not allocate chrdev\n");
 
         goto ERROR_PROVE_DEVICE;
     }
 
+    s_vpu_class = class_create(THIS_MODULE, VPU_DEV_NAME);
+    if (IS_ERR(s_vpu_class)) {
+	dev_err(vpu_dev, "class creat error.\n");
+	goto ERROR_CRART_CLASS;
+    }
+
+    devices = device_create(s_vpu_class, 0, MKDEV(s_vpu_major, 0),
+				NULL, VPU_DEV_NAME);
+    if (IS_ERR(devices)) {
+	dev_err(vpu_dev, "device creat error.\n");
+	goto ERROR_CREAT_DEVICE;
+    }
+
     if (pdev)
         s_vpu_clk = vpu_clk_get(pdev);
     else
@@ -1601,6 +1640,10 @@ static int vpu_probe(struct platform_device *pdev)
 
     return 0;
 
+ERROR_CREAT_DEVICE:
+	class_destroy(s_vpu_class);
+ERROR_CRART_CLASS:
+	cdev_del(&s_vpu_cdev);
 ERROR_PROVE_DEVICE:
 
     if (s_vpu_major)
@@ -1639,8 +1682,10 @@ static int vpu_remove(struct platform_device *pdev)
 #endif
 
     if (s_vpu_major > 0) {
+        device_destroy(s_vpu_class, MKDEV(s_vpu_major, 0));
+        class_destroy(s_vpu_class);
         cdev_del(&s_vpu_cdev);
-        unregister_chrdev_region(s_vpu_major, 1);
+        unregister_chrdev_region(s_vpu_devt, 1);
         s_vpu_major = 0;
     }
 
@@ -1977,9 +2022,11 @@ static void __exit vpu_exit(void)
 #endif
 
     if (s_vpu_major > 0) {
-        cdev_del(&s_vpu_cdev);
-        unregister_chrdev_region(s_vpu_major, 1);
-        s_vpu_major = 0;
+	device_destroy(s_vpu_class, MKDEV(s_vpu_major, 0));
+	class_destroy(s_vpu_class);
+	cdev_del(&s_vpu_cdev);
+	unregister_chrdev_region(s_vpu_devt, 1);
+	s_vpu_major = 0;
     }
 
 #ifdef VPU_SUPPORT_ISR