X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=drivers%2Fvideo%2Frockchip%2Frga%2Frga_drv.c;h=171b09ad7f1b7095cac1543972688b071e91dbf2;hb=c57691331e5e1bb6dc9a9863c3daf9901990098c;hp=d081f0ca8c8ee35110c1ec7298cc95052ddaa8df;hpb=4b74168e11d2ea004971f9b372e892293880a40c;p=firefly-linux-kernel-4.4.55.git diff --git a/drivers/video/rockchip/rga/rga_drv.c b/drivers/video/rockchip/rga/rga_drv.c index d081f0ca8c8e..171b09ad7f1b 100755 --- a/drivers/video/rockchip/rga/rga_drv.c +++ b/drivers/video/rockchip/rga/rga_drv.c @@ -1,322 +1,323 @@ -/* - * Copyright (C) 2012 ROCKCHIP, Inc. - * - * This software is licensed under the terms of the GNU General Public - * License version 2, as published by the Free Software Foundation, and - * may be copied, distributed, and modified under those terms. - * - * 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. - * - */ - -#define pr_fmt(fmt) "rga: " fmt -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -//#include -//#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined(CONFIG_ION_ROCKCHIP) -#include -#endif - - -#include "rga.h" -#include "rga_reg_info.h" -#include "rga_mmu_info.h" -#include "RGA_API.h" - -#define RGA_TEST_CASE 0 - -#define RGA_TEST 0 -#define RGA_TEST_TIME 0 -#define RGA_TEST_FLUSH_TIME 0 -#define RGA_INFO_BUS_ERROR 1 - -#define PRE_SCALE_BUF_SIZE 2048*1024*4 - -#define RGA_POWER_OFF_DELAY 4*HZ /* 4s */ -#define RGA_TIMEOUT_DELAY 2*HZ /* 2s */ - -#define RGA_MAJOR 255 - -#if defined(CONFIG_ARCH_RK2928) || defined(CONFIG_ARCH_RK3026) -#define RK30_RGA_PHYS RK2928_RGA_PHYS -#define RK30_RGA_SIZE RK2928_RGA_SIZE -#endif -#define RGA_RESET_TIMEOUT 1000 - -/* Driver information */ -#define DRIVER_DESC "RGA Device Driver" -#define DRIVER_NAME "rga" - -#define RGA_VERSION "1.003" - -ktime_t rga_start; -ktime_t rga_end; - -rga_session rga_session_global; - -long (*rga_ioctl_kernel_p)(struct rga_req *); - - -struct rga_drvdata { - struct miscdevice miscdev; - struct device dev; - void *rga_base; - int irq; - - struct delayed_work power_off_work; - void (*rga_irq_callback)(int rga_retval); //callback function used by aync call - struct wake_lock wake_lock; - - struct clk *pd_rga; - struct clk *aclk_rga; - struct clk *hclk_rga; - - //#if defined(CONFIG_ION_ROCKCHIP) - struct ion_client * ion_client; - //#endif -}; - -static struct rga_drvdata *drvdata; -rga_service_info rga_service; -struct rga_mmu_buf_t rga_mmu_buf; - - -#if defined(CONFIG_ION_ROCKCHIP) -extern struct ion_client *rockchip_ion_client_create(const char * name); -#endif - -static int rga_blit_async(rga_session *session, struct rga_req *req); -static void rga_del_running_list(void); -static void rga_del_running_list_timeout(void); -static void rga_try_set_reg(void); - - -/* Logging */ -#define RGA_DEBUG 1 -#if RGA_DEBUG -#define DBG(format, args...) printk(KERN_DEBUG "%s: " format, DRIVER_NAME, ## args) -#define ERR(format, args...) printk(KERN_ERR "%s: " format, DRIVER_NAME, ## args) -#define WARNING(format, args...) printk(KERN_WARN "%s: " format, DRIVER_NAME, ## args) -#define INFO(format, args...) printk(KERN_INFO "%s: " format, DRIVER_NAME, ## args) -#else -#define DBG(format, args...) -#define ERR(format, args...) -#define WARNING(format, args...) -#define INFO(format, args...) -#endif - -#if RGA_TEST -static void print_info(struct rga_req *req) -{ - printk("src : yrgb_addr = %.8x, src.uv_addr = %.8x, src.v_addr = %.8x, format = %d\n", - req->src.yrgb_addr, req->src.uv_addr, req->src.v_addr, req->src.format); - printk("src : act_w = %d, act_h = %d, vir_w = %d, vir_h = %d\n", - req->src.act_w, req->src.act_h, req->src.vir_w, req->src.vir_h); - printk("src : x_off = %.8x y_off = %.8x\n", req->src.x_offset, req->src.y_offset); - - printk("dst : yrgb_addr = %.8x, dst.uv_addr = %.8x, dst.v_addr = %.8x, format = %d\n", - req->dst.yrgb_addr, req->dst.uv_addr, req->dst.v_addr, req->dst.format); - printk("dst : x_off = %.8x y_off = %.8x\n", req->dst.x_offset, req->dst.y_offset); - printk("dst : act_w = %d, act_h = %d, vir_w = %d, vir_h = %d\n", - req->dst.act_w, req->dst.act_h, req->dst.vir_w, req->dst.vir_h); - - printk("clip.xmin = %d, clip.xmax = %d. clip.ymin = %d, clip.ymax = %d\n", - req->clip.xmin, req->clip.xmax, req->clip.ymin, req->clip.ymax); - - printk("mmu_flag = %.8x\n", req->mmu_info.mmu_flag); - - //printk("alpha_rop_flag = %.8x\n", req->alpha_rop_flag); - //printk("alpha_rop_mode = %.8x\n", req->alpha_rop_mode); - //printk("PD_mode = %.8x\n", req->PD_mode); -} -#endif - - -static inline void rga_write(u32 b, u32 r) -{ - __raw_writel(b, drvdata->rga_base + r); -} - -static inline u32 rga_read(u32 r) -{ - return __raw_readl(drvdata->rga_base + r); -} - -static void rga_soft_reset(void) -{ - u32 i; - u32 reg; - - rga_write(1, RGA_SYS_CTRL); //RGA_SYS_CTRL - - for(i = 0; i < RGA_RESET_TIMEOUT; i++) - { - reg = rga_read(RGA_SYS_CTRL) & 1; //RGA_SYS_CTRL - - if(reg == 0) - break; - - udelay(1); - } - - if(i == RGA_RESET_TIMEOUT) - ERR("soft reset timeout.\n"); -} - -static void rga_dump(void) -{ - int running; - struct rga_reg *reg, *reg_tmp; - rga_session *session, *session_tmp; - - running = atomic_read(&rga_service.total_running); - printk("rga total_running %d\n", running); - - #if 0 - - /* Dump waiting list info */ - if (!list_empty(&rga_service.waiting)) - { - list_head *next; - - next = &rga_service.waiting; - - printk("rga_service dump waiting list\n"); - - do - { - reg = list_entry(next->next, struct rga_reg, status_link); - running = atomic_read(®->session->task_running); - num_done = atomic_read(®->session->num_done); - printk("rga session pid %d, done %d, running %d\n", reg->session->pid, num_done, running); - next = next->next; - } - while(!list_empty(next)); - } - - /* Dump running list info */ - if (!list_empty(&rga_service.running)) - { - printk("rga_service dump running list\n"); - - list_head *next; - - next = &rga_service.running; - do - { - reg = list_entry(next->next, struct rga_reg, status_link); - running = atomic_read(®->session->task_running); - num_done = atomic_read(®->session->num_done); - printk("rga session pid %d, done %d, running %d:\n", reg->session->pid, num_done, running); - next = next->next; - } - while(!list_empty(next)); - } - #endif - - list_for_each_entry_safe(session, session_tmp, &rga_service.session, list_session) - { - printk("session pid %d:\n", session->pid); - running = atomic_read(&session->task_running); - printk("task_running %d\n", running); - list_for_each_entry_safe(reg, reg_tmp, &session->waiting, session_link) - { - printk("waiting register set 0x%.8x\n", (unsigned int)reg); - } - list_for_each_entry_safe(reg, reg_tmp, &session->running, session_link) - { - printk("running register set 0x%.8x\n", (unsigned int)reg); - } - } -} - -static inline void rga_queue_power_off_work(void) -{ - queue_delayed_work(system_nrt_wq, &drvdata->power_off_work, RGA_POWER_OFF_DELAY); -} - -/* Caller must hold rga_service.lock */ -static void rga_power_on(void) -{ - static ktime_t last; - ktime_t now = ktime_get(); +/* + * Copyright (C) 2012 ROCKCHIP, Inc. + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * 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. + * + */ + +#define pr_fmt(fmt) "rga: " fmt +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#include +//#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(CONFIG_ION_ROCKCHIP) +#include +#endif + + +#include "rga.h" +#include "rga_reg_info.h" +#include "rga_mmu_info.h" +#include "RGA_API.h" + +#define RGA_TEST_CASE 0 + +#define RGA_TEST 0 +#define RGA_TEST_TIME 0 +#define RGA_TEST_FLUSH_TIME 0 +#define RGA_INFO_BUS_ERROR 1 + +#define PRE_SCALE_BUF_SIZE 2048*1024*4 + +#define RGA_POWER_OFF_DELAY 4*HZ /* 4s */ +#define RGA_TIMEOUT_DELAY 2*HZ /* 2s */ + +#define RGA_MAJOR 255 + +#if defined(CONFIG_ARCH_RK2928) || defined(CONFIG_ARCH_RK3026) +#define RK30_RGA_PHYS RK2928_RGA_PHYS +#define RK30_RGA_SIZE RK2928_RGA_SIZE +#endif +#define RGA_RESET_TIMEOUT 1000 + +/* Driver information */ +#define DRIVER_DESC "RGA Device Driver" +#define DRIVER_NAME "rga" + +#define RGA_VERSION "1.003" + +ktime_t rga_start; +ktime_t rga_end; + +rga_session rga_session_global; + +long (*rga_ioctl_kernel_p)(struct rga_req *); + + +struct rga_drvdata { + struct miscdevice miscdev; + struct device dev; + void *rga_base; + int irq; + + struct delayed_work power_off_work; + void (*rga_irq_callback)(int rga_retval); //callback function used by aync call + struct wake_lock wake_lock; + + struct clk *pd_rga; + struct clk *aclk_rga; + struct clk *hclk_rga; + + //#if defined(CONFIG_ION_ROCKCHIP) + struct ion_client * ion_client; + //#endif +}; + +static struct rga_drvdata *drvdata; +rga_service_info rga_service; +struct rga_mmu_buf_t rga_mmu_buf; + + +#if defined(CONFIG_ION_ROCKCHIP) +extern struct ion_client *rockchip_ion_client_create(const char * name); +#endif + +static int rga_blit_async(rga_session *session, struct rga_req *req); +static void rga_del_running_list(void); +static void rga_del_running_list_timeout(void); +static void rga_try_set_reg(void); + + +/* Logging */ +#define RGA_DEBUG 1 +#if RGA_DEBUG +#define DBG(format, args...) printk(KERN_DEBUG "%s: " format, DRIVER_NAME, ## args) +#define ERR(format, args...) printk(KERN_ERR "%s: " format, DRIVER_NAME, ## args) +#define WARNING(format, args...) printk(KERN_WARN "%s: " format, DRIVER_NAME, ## args) +#define INFO(format, args...) printk(KERN_INFO "%s: " format, DRIVER_NAME, ## args) +#else +#define DBG(format, args...) +#define ERR(format, args...) +#define WARNING(format, args...) +#define INFO(format, args...) +#endif + +#if RGA_TEST +static void print_info(struct rga_req *req) +{ + printk("src : yrgb_addr = %.8x, src.uv_addr = %.8x, src.v_addr = %.8x, format = %d\n", + req->src.yrgb_addr, req->src.uv_addr, req->src.v_addr, req->src.format); + printk("src : act_w = %d, act_h = %d, vir_w = %d, vir_h = %d\n", + req->src.act_w, req->src.act_h, req->src.vir_w, req->src.vir_h); + printk("src : x_off = %.8x y_off = %.8x\n", req->src.x_offset, req->src.y_offset); + + printk("dst : yrgb_addr = %.8x, dst.uv_addr = %.8x, dst.v_addr = %.8x, format = %d\n", + req->dst.yrgb_addr, req->dst.uv_addr, req->dst.v_addr, req->dst.format); + printk("dst : x_off = %.8x y_off = %.8x\n", req->dst.x_offset, req->dst.y_offset); + printk("dst : act_w = %d, act_h = %d, vir_w = %d, vir_h = %d\n", + req->dst.act_w, req->dst.act_h, req->dst.vir_w, req->dst.vir_h); + + printk("clip.xmin = %d, clip.xmax = %d. clip.ymin = %d, clip.ymax = %d\n", + req->clip.xmin, req->clip.xmax, req->clip.ymin, req->clip.ymax); + + printk("mmu_flag = %.8x\n", req->mmu_info.mmu_flag); + + //printk("alpha_rop_flag = %.8x\n", req->alpha_rop_flag); + //printk("alpha_rop_mode = %.8x\n", req->alpha_rop_mode); + //printk("PD_mode = %.8x\n", req->PD_mode); +} +#endif + + +static inline void rga_write(u32 b, u32 r) +{ + __raw_writel(b, drvdata->rga_base + r); +} + +static inline u32 rga_read(u32 r) +{ + return __raw_readl(drvdata->rga_base + r); +} + +static void rga_soft_reset(void) +{ + u32 i; + u32 reg; + + rga_write(1, RGA_SYS_CTRL); //RGA_SYS_CTRL + + for(i = 0; i < RGA_RESET_TIMEOUT; i++) + { + reg = rga_read(RGA_SYS_CTRL) & 1; //RGA_SYS_CTRL + + if(reg == 0) + break; + + udelay(1); + } + + if(i == RGA_RESET_TIMEOUT) + ERR("soft reset timeout.\n"); +} + +static void rga_dump(void) +{ + int running; + struct rga_reg *reg, *reg_tmp; + rga_session *session, *session_tmp; + + running = atomic_read(&rga_service.total_running); + printk("rga total_running %d\n", running); + + #if 0 + + /* Dump waiting list info */ + if (!list_empty(&rga_service.waiting)) + { + list_head *next; + + next = &rga_service.waiting; + + printk("rga_service dump waiting list\n"); + + do + { + reg = list_entry(next->next, struct rga_reg, status_link); + running = atomic_read(®->session->task_running); + num_done = atomic_read(®->session->num_done); + printk("rga session pid %d, done %d, running %d\n", reg->session->pid, num_done, running); + next = next->next; + } + while(!list_empty(next)); + } + + /* Dump running list info */ + if (!list_empty(&rga_service.running)) + { + printk("rga_service dump running list\n"); + + list_head *next; + + next = &rga_service.running; + do + { + reg = list_entry(next->next, struct rga_reg, status_link); + running = atomic_read(®->session->task_running); + num_done = atomic_read(®->session->num_done); + printk("rga session pid %d, done %d, running %d:\n", reg->session->pid, num_done, running); + next = next->next; + } + while(!list_empty(next)); + } + #endif + + list_for_each_entry_safe(session, session_tmp, &rga_service.session, list_session) + { + printk("session pid %d:\n", session->pid); + running = atomic_read(&session->task_running); + printk("task_running %d\n", running); + list_for_each_entry_safe(reg, reg_tmp, &session->waiting, session_link) + { + printk("waiting register set 0x%.lu\n", (unsigned long)reg); + } + list_for_each_entry_safe(reg, reg_tmp, &session->running, session_link) + { + printk("running register set 0x%.lu\n", (unsigned long)reg); + } + } +} + +static inline void rga_queue_power_off_work(void) +{ + queue_delayed_work(system_wq, &drvdata->power_off_work, RGA_POWER_OFF_DELAY); +} + +/* Caller must hold rga_service.lock */ +static void rga_power_on(void) +{ + static ktime_t last; + ktime_t now = ktime_get(); + + if (ktime_to_ns(ktime_sub(now, last)) > NSEC_PER_SEC) { + cancel_delayed_work_sync(&drvdata->power_off_work); + rga_queue_power_off_work(); + last = now; + } + if (rga_service.enable) + return; + + clk_prepare_enable(drvdata->aclk_rga); + clk_prepare_enable(drvdata->hclk_rga); + //clk_prepare_enable(drvdata->pd_rga); + wake_lock(&drvdata->wake_lock); + rga_service.enable = true; +} + +/* Caller must hold rga_service.lock */ +static void rga_power_off(void) +{ + int total_running; + + if (!rga_service.enable) { + return; + } + + total_running = atomic_read(&rga_service.total_running); + if (total_running) { + pr_err("power off when %d task running!!\n", total_running); + mdelay(50); + pr_err("delay 50 ms for running task\n"); + rga_dump(); + } + + //clk_disable_unprepare(drvdata->pd_rga); + clk_disable_unprepare(drvdata->aclk_rga); + clk_disable_unprepare(drvdata->hclk_rga); + wake_unlock(&drvdata->wake_lock); + rga_service.enable = false; +} + +static void rga_power_off_work(struct work_struct *work) +{ + if (mutex_trylock(&rga_service.lock)) { + rga_power_off(); + mutex_unlock(&rga_service.lock); + } else { + /* Come back later if the device is busy... */ - if (ktime_to_ns(ktime_sub(now, last)) > NSEC_PER_SEC) { - cancel_delayed_work_sync(&drvdata->power_off_work); - rga_queue_power_off_work(); - last = now; - } - if (rga_service.enable) - return; - - clk_prepare_enable(drvdata->aclk_rga); - clk_prepare_enable(drvdata->hclk_rga); - //clk_prepare_enable(drvdata->pd_rga); - wake_lock(&drvdata->wake_lock); - rga_service.enable = true; -} - -/* Caller must hold rga_service.lock */ -static void rga_power_off(void) -{ - int total_running; - - if (!rga_service.enable) { - return; - } - - total_running = atomic_read(&rga_service.total_running); - if (total_running) { - pr_err("power off when %d task running!!\n", total_running); - mdelay(50); - pr_err("delay 50 ms for running task\n"); - rga_dump(); - } - - //clk_disable_unprepare(drvdata->pd_rga); - clk_disable_unprepare(drvdata->aclk_rga); - clk_disable_unprepare(drvdata->hclk_rga); - wake_unlock(&drvdata->wake_lock); - rga_service.enable = false; -} - -static void rga_power_off_work(struct work_struct *work) -{ - if (mutex_trylock(&rga_service.lock)) { - rga_power_off(); - mutex_unlock(&rga_service.lock); - } else { - /* Come back later if the device is busy... */ rga_queue_power_off_work(); } } @@ -449,12 +450,9 @@ static void rga_copy_reg(struct rga_reg *reg, uint32_t offset) cmd_buf = (uint32_t *)rga_service.cmd_buff + offset*32; reg_p = (uint32_t *)reg->cmd_reg; - for(i=0; i<32; i++) - { + for(i=0; i<32; i++) cmd_buf[i] = reg_p[i]; - } - - dsb(); + } @@ -635,13 +633,15 @@ static void rga_try_set_reg(void) rga_copy_reg(reg, 0); rga_reg_from_wait_to_run(reg); + + #ifdef CONFIG_ARM + dmac_flush_range(&rga_service.cmd_buff[0], &rga_service.cmd_buff[32]); + outer_flush_range(virt_to_phys(&rga_service.cmd_buff[0]),virt_to_phys(&rga_service.cmd_buff[32])); + #elif defined(CONFIG_ARM64) + __dma_flush_range(&rga_service.cmd_buff[0], &rga_service.cmd_buff[32]); + #endif - dmac_flush_range(&rga_service.cmd_buff[0], &rga_service.cmd_buff[28]); - outer_flush_range(virt_to_phys(&rga_service.cmd_buff[0]),virt_to_phys(&rga_service.cmd_buff[28])); - - #if 1 rga_soft_reset(); - #endif rga_write(0x0, RGA_SYS_CTRL); rga_write(0, RGA_MMU_CTRL); @@ -731,10 +731,13 @@ static void rga_del_running_list_timeout(void) while(!list_empty(&rga_service.running)) { reg = list_entry(rga_service.running.next, struct rga_reg, status_link); - - if(reg->MMU_base != NULL) + + if(reg->MMU_len != 0) { - kfree(reg->MMU_base); + if (rga_mmu_buf.back + reg->MMU_len > 2*rga_mmu_buf.size) + rga_mmu_buf.back = reg->MMU_len + rga_mmu_buf.size; + else + rga_mmu_buf.back += reg->MMU_len; } atomic_sub(1, ®->session->task_running); @@ -816,7 +819,7 @@ static int rga_convert_dma_buf(struct rga_req *req) req->sg_src = NULL; req->sg_dst = NULL; - + src_offset = req->line_draw_info.flag; dst_offset = req->line_draw_info.line_width; @@ -1282,317 +1285,327 @@ static int rga_drv_probe(struct platform_device *pdev) } else { dev_info(&pdev->dev, "rga ion client create success!\n"); } - #endif - - ret = misc_register(&rga_dev); - if(ret) - { - ERR("cannot register miscdev (%d)\n", ret); - goto err_misc_register; - } - - pr_info("Driver loaded succesfully\n"); - - return 0; - -err_misc_register: - free_irq(data->irq, pdev); -err_irq: - iounmap(data->rga_base); -err_ioremap: - wake_lock_destroy(&data->wake_lock); - //kfree(data); - - return ret; -} - -static int rga_drv_remove(struct platform_device *pdev) -{ - struct rga_drvdata *data = platform_get_drvdata(pdev); - DBG("%s [%d]\n",__FUNCTION__,__LINE__); - - wake_lock_destroy(&data->wake_lock); - misc_deregister(&(data->miscdev)); - free_irq(data->irq, &data->miscdev); - iounmap((void __iomem *)(data->rga_base)); - - //clk_put(data->pd_rga); - devm_clk_put(&pdev->dev, data->aclk_rga); - devm_clk_put(&pdev->dev, data->hclk_rga); - - //kfree(data); - return 0; -} - -static struct platform_driver rga_driver = { - .probe = rga_drv_probe, - .remove = rga_drv_remove, - .driver = { - .owner = THIS_MODULE, - .name = "rga", - .of_match_table = of_match_ptr(rockchip_rga_dt_ids), - }, -}; - - -void rga_test_0(void); -void rga_test_1(void); - - -static int __init rga_init(void) -{ - int ret; - uint32_t *mmu_buf; - uint32_t i; - uint32_t *buf_p; - - /* malloc pre scale mid buf mmu table */ - mmu_buf = kzalloc(1024*8, GFP_KERNEL); - if(mmu_buf == NULL) { - printk(KERN_ERR "RGA get Pre Scale buff failed. \n"); - return -1; - } - - /* malloc 4 M buf */ - for(i=0; i<1024; i++) { - buf_p = (uint32_t *)__get_free_page(GFP_KERNEL|__GFP_ZERO); - if(buf_p == NULL) { - printk(KERN_ERR "RGA init pre scale buf falied\n"); - return -ENOMEM; - } - mmu_buf[i] = virt_to_phys((void *)((uint32_t)buf_p)); - } - - rga_service.pre_scale_buf = (uint32_t *)mmu_buf; - - buf_p = kmalloc(1024*256, GFP_KERNEL); - rga_mmu_buf.buf_virtual = buf_p; - rga_mmu_buf.buf = (uint32_t *)virt_to_phys((void *)((uint32_t)buf_p)); - rga_mmu_buf.front = 0; - rga_mmu_buf.back = 64*1024; - rga_mmu_buf.size = 64*1024; - - rga_mmu_buf.pages = kmalloc((32768)* sizeof(struct page *), GFP_KERNEL); - - if ((ret = platform_driver_register(&rga_driver)) != 0) - { - printk(KERN_ERR "Platform device register failed (%d).\n", ret); - return ret; - } - - { - rga_session_global.pid = 0x0000ffff; - INIT_LIST_HEAD(&rga_session_global.waiting); - INIT_LIST_HEAD(&rga_session_global.running); - INIT_LIST_HEAD(&rga_session_global.list_session); - - INIT_LIST_HEAD(&rga_service.waiting); - INIT_LIST_HEAD(&rga_service.running); - INIT_LIST_HEAD(&rga_service.done); - INIT_LIST_HEAD(&rga_service.session); - - init_waitqueue_head(&rga_session_global.wait); - //mutex_lock(&rga_service.lock); - list_add_tail(&rga_session_global.list_session, &rga_service.session); - //mutex_unlock(&rga_service.lock); - atomic_set(&rga_session_global.task_running, 0); - atomic_set(&rga_session_global.num_done, 0); - } - - - - #if RGA_TEST_CASE - rga_test_0(); - #endif - - INFO("Module initialized.\n"); - - return 0; -} - -static void __exit rga_exit(void) -{ - uint32_t i; - - rga_power_off(); - - for(i=0; i<1024; i++) - { - if((uint32_t *)rga_service.pre_scale_buf[i] != NULL) - { - __free_page((void *)rga_service.pre_scale_buf[i]); - } - } - - if(rga_service.pre_scale_buf != NULL) { - kfree((uint8_t *)rga_service.pre_scale_buf); - } - - if (rga_mmu_buf.buf_virtual) - kfree(rga_mmu_buf.buf_virtual); - - if (rga_mmu_buf.pages) - kfree(rga_mmu_buf.pages); - - platform_driver_unregister(&rga_driver); -} - - -#if RGA_TEST_CASE - -extern struct fb_info * rk_get_fb(int fb_id); -EXPORT_SYMBOL(rk_get_fb); - -extern void rk_direct_fb_show(struct fb_info * fbi); -EXPORT_SYMBOL(rk_direct_fb_show); - -unsigned int src_buf[1920*1080]; -unsigned int dst_buf[1920*1080]; -//unsigned int tmp_buf[1920*1080 * 2]; - -void rga_test_0(void) -{ - struct rga_req req; - rga_session session; - unsigned int *src, *dst; - uint32_t i, j; - uint8_t *p; - uint8_t t; - uint32_t *dst0, *dst1, *dst2; - - struct fb_info *fb; - - session.pid = current->pid; - INIT_LIST_HEAD(&session.waiting); - INIT_LIST_HEAD(&session.running); - INIT_LIST_HEAD(&session.list_session); - init_waitqueue_head(&session.wait); - /* no need to protect */ - list_add_tail(&session.list_session, &rga_service.session); - atomic_set(&session.task_running, 0); - atomic_set(&session.num_done, 0); - //file->private_data = (void *)session; - - fb = rk_get_fb(0); - - memset(&req, 0, sizeof(struct rga_req)); - src = src_buf; - dst = dst_buf; - - memset(src_buf, 0x80, 1024*600*4); - - dmac_flush_range(&src_buf[0], &src_buf[1024*600]); - outer_flush_range(virt_to_phys(&src_buf[0]),virt_to_phys(&src_buf[1024*600])); - - - #if 0 - memset(src_buf, 0x80, 800*480*4); - memset(dst_buf, 0xcc, 800*480*4); - - dmac_flush_range(&dst_buf[0], &dst_buf[800*480]); - outer_flush_range(virt_to_phys(&dst_buf[0]),virt_to_phys(&dst_buf[800*480])); - #endif - - dst0 = &dst_buf[0]; - //dst1 = &dst_buf[1280*800*4]; - //dst2 = &dst_buf[1280*800*4*2]; - - i = j = 0; - - printk("\n********************************\n"); - printk("************ RGA_TEST ************\n"); - printk("********************************\n\n"); - - req.src.act_w = 1024; - req.src.act_h = 600; - - req.src.vir_w = 1024; - req.src.vir_h = 600; - req.src.yrgb_addr = (uint32_t)virt_to_phys(src); - req.src.uv_addr = (uint32_t)(req.src.yrgb_addr + 1080*1920); - req.src.v_addr = (uint32_t)virt_to_phys(src); - req.src.format = RK_FORMAT_RGBA_8888; - - req.dst.act_w = 600; - req.dst.act_h = 352; - - req.dst.vir_w = 1280; - req.dst.vir_h = 800; - req.dst.x_offset = 600; - req.dst.y_offset = 0; - - dst = dst0; - - req.dst.yrgb_addr = ((uint32_t)virt_to_phys(dst)); - - //req.dst.format = RK_FORMAT_RGB_565; - - req.clip.xmin = 0; - req.clip.xmax = 1279; - req.clip.ymin = 0; - req.clip.ymax = 799; - - //req.render_mode = color_fill_mode; - //req.fg_color = 0x80ffffff; - - req.rotate_mode = 1; - //req.scale_mode = 2; - - //req.alpha_rop_flag = 0; - //req.alpha_rop_mode = 0x19; - //req.PD_mode = 3; - - req.sina = 65536; - req.cosa = 0; - - //req.mmu_info.mmu_flag = 0x21; - //req.mmu_info.mmu_en = 1; - - //printk("src = %.8x\n", req.src.yrgb_addr); - //printk("src = %.8x\n", req.src.uv_addr); - //printk("dst = %.8x\n", req.dst.yrgb_addr); - - - rga_blit_sync(&session, &req); - - #if 1 - fb->var.bits_per_pixel = 32; - - fb->var.xres = 1280; - fb->var.yres = 800; - - fb->var.red.length = 8; - fb->var.red.offset = 0; - fb->var.red.msb_right = 0; - - fb->var.green.length = 8; - fb->var.green.offset = 8; - fb->var.green.msb_right = 0; - - fb->var.blue.length = 8; - - fb->var.blue.offset = 16; - fb->var.blue.msb_right = 0; - - fb->var.transp.length = 8; - fb->var.transp.offset = 24; - fb->var.transp.msb_right = 0; - - fb->var.nonstd &= (~0xff); - fb->var.nonstd |= 1; - - fb->fix.smem_start = virt_to_phys(dst); - - rk_direct_fb_show(fb); - #endif - -} - + #endif + + ret = misc_register(&rga_dev); + if(ret) + { + ERR("cannot register miscdev (%d)\n", ret); + goto err_misc_register; + } + + pr_info("Driver loaded succesfully\n"); + + return 0; + +err_misc_register: + free_irq(data->irq, pdev); +err_irq: + iounmap(data->rga_base); +err_ioremap: + wake_lock_destroy(&data->wake_lock); + //kfree(data); + + return ret; +} + +static int rga_drv_remove(struct platform_device *pdev) +{ + struct rga_drvdata *data = platform_get_drvdata(pdev); + DBG("%s [%d]\n",__FUNCTION__,__LINE__); + + wake_lock_destroy(&data->wake_lock); + misc_deregister(&(data->miscdev)); + free_irq(data->irq, &data->miscdev); + iounmap((void __iomem *)(data->rga_base)); + + //clk_put(data->pd_rga); + devm_clk_put(&pdev->dev, data->aclk_rga); + devm_clk_put(&pdev->dev, data->hclk_rga); + + //kfree(data); + return 0; +} + +static struct platform_driver rga_driver = { + .probe = rga_drv_probe, + .remove = rga_drv_remove, + .driver = { + .owner = THIS_MODULE, + .name = "rga", + .of_match_table = of_match_ptr(rockchip_rga_dt_ids), + }, +}; + + +void rga_test_0(void); +void rga_test_1(void); + + +static int __init rga_init(void) +{ + int ret; + uint32_t *mmu_buf; + unsigned long *mmu_buf_virtual; + uint32_t i; + uint32_t *buf_p; + uint32_t *buf; + + /* malloc pre scale mid buf mmu table */ + mmu_buf = kzalloc(1024*8, GFP_KERNEL); + mmu_buf_virtual = kzalloc(1024*2*sizeof(unsigned long), GFP_KERNEL); + if(mmu_buf == NULL) { + printk(KERN_ERR "RGA get Pre Scale buff failed. \n"); + return -1; + } + + /* malloc 4 M buf */ + for(i=0; i<1024; i++) { + buf_p = (uint32_t *)__get_free_page(GFP_KERNEL|__GFP_ZERO); + if(buf_p == NULL) { + printk(KERN_ERR "RGA init pre scale buf falied\n"); + return -ENOMEM; + } + mmu_buf[i] = virt_to_phys((void *)((unsigned long)buf_p)); + mmu_buf_virtual[i] = (unsigned long)buf_p; + } + + rga_service.pre_scale_buf = (uint32_t *)mmu_buf; + rga_service.pre_scale_buf_virtual = (unsigned long *)mmu_buf_virtual; + + buf_p = kmalloc(1024*256, GFP_KERNEL); + rga_mmu_buf.buf_virtual = buf_p; +#if (defined(CONFIG_ARM) && defined(CONFIG_ARM_LPAE)) + buf = (uint32_t *)(uint32_t)virt_to_phys((void *)((unsigned long)buf_p)); +#else + buf = (uint32_t *)virt_to_phys((void *)((unsigned long)buf_p)); #endif -module_init(rga_init); -module_exit(rga_exit); - -/* Module information */ -MODULE_AUTHOR("zsq@rock-chips.com"); -MODULE_DESCRIPTION("Driver for rga device"); -MODULE_LICENSE("GPL"); + rga_mmu_buf.buf = buf; + rga_mmu_buf.front = 0; + rga_mmu_buf.back = 64*1024; + rga_mmu_buf.size = 64*1024; + + rga_mmu_buf.pages = kmalloc((32768)* sizeof(struct page *), GFP_KERNEL); + + if ((ret = platform_driver_register(&rga_driver)) != 0) + { + printk(KERN_ERR "Platform device register failed (%d).\n", ret); + return ret; + } + + { + rga_session_global.pid = 0x0000ffff; + INIT_LIST_HEAD(&rga_session_global.waiting); + INIT_LIST_HEAD(&rga_session_global.running); + INIT_LIST_HEAD(&rga_session_global.list_session); + + INIT_LIST_HEAD(&rga_service.waiting); + INIT_LIST_HEAD(&rga_service.running); + INIT_LIST_HEAD(&rga_service.done); + INIT_LIST_HEAD(&rga_service.session); + + init_waitqueue_head(&rga_session_global.wait); + //mutex_lock(&rga_service.lock); + list_add_tail(&rga_session_global.list_session, &rga_service.session); + //mutex_unlock(&rga_service.lock); + atomic_set(&rga_session_global.task_running, 0); + atomic_set(&rga_session_global.num_done, 0); + } + + + + #if RGA_TEST_CASE + rga_test_0(); + #endif + + INFO("Module initialized.\n"); + + return 0; +} + +static void __exit rga_exit(void) +{ + uint32_t i; + + rga_power_off(); + + for(i=0; i<1024; i++) + { + if((unsigned long)rga_service.pre_scale_buf_virtual[i]) + { + __free_page((void *)rga_service.pre_scale_buf_virtual[i]); + } + } + + if(rga_service.pre_scale_buf != NULL) { + kfree((uint8_t *)rga_service.pre_scale_buf); + } + + if (rga_mmu_buf.buf_virtual) + kfree(rga_mmu_buf.buf_virtual); + + if (rga_mmu_buf.pages) + kfree(rga_mmu_buf.pages); + + platform_driver_unregister(&rga_driver); +} + + +#if RGA_TEST_CASE + +extern struct fb_info * rk_get_fb(int fb_id); +EXPORT_SYMBOL(rk_get_fb); + +extern void rk_direct_fb_show(struct fb_info * fbi); +EXPORT_SYMBOL(rk_direct_fb_show); + +unsigned int src_buf[1920*1080]; +unsigned int dst_buf[1920*1080]; +//unsigned int tmp_buf[1920*1080 * 2]; + +void rga_test_0(void) +{ + struct rga_req req; + rga_session session; + unsigned int *src, *dst; + uint32_t i, j; + uint8_t *p; + uint8_t t; + uint32_t *dst0, *dst1, *dst2; + + struct fb_info *fb; + + session.pid = current->pid; + INIT_LIST_HEAD(&session.waiting); + INIT_LIST_HEAD(&session.running); + INIT_LIST_HEAD(&session.list_session); + init_waitqueue_head(&session.wait); + /* no need to protect */ + list_add_tail(&session.list_session, &rga_service.session); + atomic_set(&session.task_running, 0); + atomic_set(&session.num_done, 0); + //file->private_data = (void *)session; + + fb = rk_get_fb(0); + + memset(&req, 0, sizeof(struct rga_req)); + src = src_buf; + dst = dst_buf; + + memset(src_buf, 0x80, 1024*600*4); + + dmac_flush_range(&src_buf[0], &src_buf[1024*600]); + outer_flush_range(virt_to_phys(&src_buf[0]),virt_to_phys(&src_buf[1024*600])); + + + #if 0 + memset(src_buf, 0x80, 800*480*4); + memset(dst_buf, 0xcc, 800*480*4); + + dmac_flush_range(&dst_buf[0], &dst_buf[800*480]); + outer_flush_range(virt_to_phys(&dst_buf[0]),virt_to_phys(&dst_buf[800*480])); + #endif + + dst0 = &dst_buf[0]; + //dst1 = &dst_buf[1280*800*4]; + //dst2 = &dst_buf[1280*800*4*2]; + + i = j = 0; + + printk("\n********************************\n"); + printk("************ RGA_TEST ************\n"); + printk("********************************\n\n"); + + req.src.act_w = 1024; + req.src.act_h = 600; + + req.src.vir_w = 1024; + req.src.vir_h = 600; + req.src.yrgb_addr = (uint32_t)virt_to_phys(src); + req.src.uv_addr = (uint32_t)(req.src.yrgb_addr + 1080*1920); + req.src.v_addr = (uint32_t)virt_to_phys(src); + req.src.format = RK_FORMAT_RGBA_8888; + + req.dst.act_w = 600; + req.dst.act_h = 352; + + req.dst.vir_w = 1280; + req.dst.vir_h = 800; + req.dst.x_offset = 600; + req.dst.y_offset = 0; + + dst = dst0; + + req.dst.yrgb_addr = ((uint32_t)virt_to_phys(dst)); + + //req.dst.format = RK_FORMAT_RGB_565; + + req.clip.xmin = 0; + req.clip.xmax = 1279; + req.clip.ymin = 0; + req.clip.ymax = 799; + + //req.render_mode = color_fill_mode; + //req.fg_color = 0x80ffffff; + + req.rotate_mode = 1; + //req.scale_mode = 2; + + //req.alpha_rop_flag = 0; + //req.alpha_rop_mode = 0x19; + //req.PD_mode = 3; + + req.sina = 65536; + req.cosa = 0; + + //req.mmu_info.mmu_flag = 0x21; + //req.mmu_info.mmu_en = 1; + + //printk("src = %.8x\n", req.src.yrgb_addr); + //printk("src = %.8x\n", req.src.uv_addr); + //printk("dst = %.8x\n", req.dst.yrgb_addr); + + + rga_blit_sync(&session, &req); + + #if 1 + fb->var.bits_per_pixel = 32; + + fb->var.xres = 1280; + fb->var.yres = 800; + + fb->var.red.length = 8; + fb->var.red.offset = 0; + fb->var.red.msb_right = 0; + + fb->var.green.length = 8; + fb->var.green.offset = 8; + fb->var.green.msb_right = 0; + + fb->var.blue.length = 8; + + fb->var.blue.offset = 16; + fb->var.blue.msb_right = 0; + + fb->var.transp.length = 8; + fb->var.transp.offset = 24; + fb->var.transp.msb_right = 0; + + fb->var.nonstd &= (~0xff); + fb->var.nonstd |= 1; + + fb->fix.smem_start = virt_to_phys(dst); + + rk_direct_fb_show(fb); + #endif + +} + +#endif +fs_initcall(rga_init); +module_exit(rga_exit); + +/* Module information */ +MODULE_AUTHOR("zsq@rock-chips.com"); +MODULE_DESCRIPTION("Driver for rga device"); +MODULE_LICENSE("GPL");