mirror of https://github.com/OpenIPC/firmware.git
230 lines
7.6 KiB
Diff
230 lines
7.6 KiB
Diff
diff -drupN a/drivers/lzma/lzma_debug.c b/drivers/lzma/lzma_debug.c
|
|
--- a/drivers/lzma/lzma_debug.c 1970-01-01 03:00:00.000000000 +0300
|
|
+++ b/drivers/lzma/lzma_debug.c 2022-06-09 05:02:29.000000000 +0300
|
|
@@ -0,0 +1,225 @@
|
|
+#include <linux/init.h>
|
|
+#include <linux/kernel.h>
|
|
+#include <linux/module.h>
|
|
+#include <linux/miscdevice.h>
|
|
+#include <linux/fs.h>
|
|
+#include <linux/io.h>
|
|
+#include <linux/clk.h>
|
|
+#include <linux/ioport.h>
|
|
+#include <linux/platform_device.h>
|
|
+#include <linux/dma-mapping.h>
|
|
+#include <linux/slab.h>
|
|
+#include <linux/vmalloc.h>
|
|
+#include <soc/base.h>
|
|
+#include <linux/string.h>
|
|
+
|
|
+//#include <asm/arch/clk.h>
|
|
+#include <../drivers/media/platform/ingenic-jpeg/jpeg-regs.h>
|
|
+
|
|
+#define LZMA_CTRL 0x00
|
|
+#define LZMA_BS_BASE 0x04
|
|
+#define LZMA_BS_SIZE 0x08
|
|
+#define LZMA_DST_BASE 0x0C
|
|
+#define LZMA_ICRC 0x10
|
|
+#define LZMA_OCRC 0x14
|
|
+#define LZMA_TIMEOUT 0x18
|
|
+#define LZMA_FINAL 0x1c
|
|
+
|
|
+#define CPM_BASE_M (char *)0xb0000000
|
|
+#define CPM_CLKGR0 0x20
|
|
+#define CPM_BSCCDR 0xa0
|
|
+
|
|
+#define LZMA_BASE (char *)0xb3090000
|
|
+#define BSCALER_BASE (char *)0xb3090000
|
|
+#define REG32(x) *(volatile unsigned int *)(x)
|
|
+static void *clk_io_mem;
|
|
+static void *lzma_io_mem;
|
|
+/*void dump_lzma_reg(void)
|
|
+{
|
|
+ printk("\nDUMP CPM LZMA REG : \n");
|
|
+ printk("CPM_BSCCDR = 0x%x \n", REG32(CPM_BASE + CPM_BSCCDR));
|
|
+ printk("CPM_CLKGR0 = 0x%x \n", REG32(CPM_BASE + CPM_CLKGR0));
|
|
+
|
|
+ printk("DUMP LZMA REG : \n");
|
|
+ printk("LZMA_CTRL = 0x%x \n", REG32(LZMA_BASE + LZMA_CTRL));
|
|
+ printk("LZMA_BS_BASE = 0x%x \n", REG32(LZMA_BASE + LZMA_BS_BASE));
|
|
+ printk("LZMA_BS_SIZE = 0x%x \n", REG32(LZMA_BASE + LZMA_BS_SIZE));
|
|
+ printk("LZMA_DST_BASE = 0x%x \n", REG32(LZMA_BASE + LZMA_DST_BASE));
|
|
+ printk("LZMA_FINAL = 0x%x \n", REG32(LZMA_BASE + LZMA_FINAL));
|
|
+}*/
|
|
+void dump_lzma_reg(void)
|
|
+{
|
|
+ printk("\nDUMP CPM LZMA REG : \n");
|
|
+ printk("CPM_BSCCDR = 0x%x \n", readl( CPM_BASE_M + CPM_BSCCDR));
|
|
+ printk("CPM_CLKGR0 = 0x%x \n", readl( CPM_BASE_M + CPM_CLKGR0));
|
|
+
|
|
+ printk("DUMP LZMA REG : \n");
|
|
+ printk("LZMA_CTRL = 0x%x \n", readl( LZMA_BASE+ LZMA_CTRL));
|
|
+ printk("LZMA_BS_BASE = 0x%x \n", readl(LZMA_BASE + LZMA_BS_BASE));
|
|
+ printk("LZMA_BS_SIZE = 0x%x \n", readl(LZMA_BASE + LZMA_BS_SIZE));
|
|
+ printk("LZMA_DST_BASE = 0x%x \n", readl( LZMA_BASE + LZMA_DST_BASE));
|
|
+ printk("LZMA_FINAL = 0x%x \n", readl(LZMA_BASE + LZMA_FINAL));
|
|
+
|
|
+/* printk("\nDUMP CPM LZMA REG : \n");
|
|
+ printk("CPM_BSCCDR = 0x%x \n", readl( clk_io_mem + CPM_BSCCDR));
|
|
+ printk("CPM_CLKGR0 = 0x%x \n", readl( clk_io_mem + CPM_CLKGR0));
|
|
+
|
|
+ printk("DUMP LZMA REG : \n");
|
|
+ printk("LZMA_CTRL = 0x%x \n", readl( lzma_io_mem+ LZMA_CTRL));
|
|
+ printk("LZMA_BS_BASE = 0x%x \n", readl(lzma_io_mem + LZMA_BS_BASE));
|
|
+ printk("LZMA_BS_SIZE = 0x%x \n", readl( lzma_io_mem+ LZMA_BS_SIZE));
|
|
+ printk("LZMA_DST_BASE = 0x%x \n", readl( lzma_io_mem + LZMA_DST_BASE));
|
|
+ printk("LZMA_FINAL = 0x%x \n", readl(lzma_io_mem + LZMA_FINAL));*/
|
|
+
|
|
+
|
|
+}
|
|
+
|
|
+int jz_lzma_decompress(unsigned char *src, size_t size, unsigned char *dst)// char int*
|
|
+{
|
|
+ unsigned int value = 0, outlen = 0;
|
|
+ unsigned int clk_val = 0, clk_gate = 0;
|
|
+ unsigned long out_file ,in_file;
|
|
+ unsigned int out_reg = 0,in_reg=0;
|
|
+ //printk("THIS IS HARWARE_UNCOMPRESS!\n");
|
|
+
|
|
+ //printk("src addr=0x%x, dst addr=0x%x\n",*src,*dst);
|
|
+
|
|
+ /* config clk */
|
|
+ clk_val = readl(CPM_BASE_M + CPM_BSCCDR);
|
|
+ clk_val |= ((2 << 30) | (1 << 29) | (1 <<0));
|
|
+ writel(clk_val, CPM_BASE_M + CPM_BSCCDR);
|
|
+
|
|
+ clk_gate = readl(CPM_BASE_M + CPM_CLKGR0);
|
|
+ clk_gate &= ~(1 << 2);
|
|
+ writel(clk_gate, CPM_BASE_M + CPM_CLKGR0);
|
|
+/*if (!request_mem_region(CPM_BASE, 8, "clk_io_mem")){
|
|
+ return -EINVAL;
|
|
+}
|
|
+clk_io_mem = ioremap(CPM_BASE,8);
|
|
+clk_val = readl(clk_io_mem + CPM_BSCCDR);
|
|
+clk_val |= ((2 << 30) | (1 << 29) | (1 <<0));
|
|
+writel(clk_val, clk_io_mem + CPM_BSCCDR);
|
|
+printk("clk_val=0x%x\n",clk_val);
|
|
+printk("clk_io_mem + CPM_BSCCDR=0x%x\n",readl(clk_io_mem + CPM_BSCCDR));
|
|
+printk("000000000000\n");
|
|
+clk_gate = readl( clk_io_mem + CPM_CLKGR0);
|
|
+clk_gate &= ~(1 << 2);
|
|
+writel(clk_gate, clk_io_mem + CPM_CLKGR0);
|
|
+printk("clk_gate=0x%x\n",clk_gate);
|
|
+printk("clk_io_mem + CPM_CLKGR0=0x%x\n",readl(clk_io_mem + CPM_CLKGR0));*/
|
|
+
|
|
+ /* start set lzma */
|
|
+
|
|
+ value = readl(BSCALER_BASE + LZMA_CTRL);
|
|
+ value |= 1<<2;
|
|
+ writel(1 << 2, BSCALER_BASE + LZMA_CTRL);
|
|
+ value = readl(BSCALER_BASE + LZMA_CTRL);
|
|
+ while(value & 0x04) {
|
|
+ value = readl(BSCALER_BASE + LZMA_CTRL);
|
|
+ }
|
|
+/*printk("1\n");
|
|
+if (!request_mem_region(LZMA_BASE, 40, "lzma_io_mem")){
|
|
+ return -EINVAL;
|
|
+}
|
|
+lzma_io_mem = ioremap(LZMA_BASE,40);
|
|
+value = readl(lzma_io_mem + LZMA_CTRL);
|
|
+ value |= 1<<2;
|
|
+ writel(1 << 2, lzma_io_mem + LZMA_CTRL);
|
|
+ value = readl(lzma_io_mem + LZMA_CTRL);
|
|
+ while(value & 0x04) {
|
|
+ value = readl( lzma_io_mem + LZMA_CTRL);
|
|
+ }*/
|
|
+
|
|
+
|
|
+ /* set lzma mode */
|
|
+ value = readl(BSCALER_BASE + LZMA_CTRL);
|
|
+
|
|
+ while(!(value & (1 << 31))) {
|
|
+ value |= 1 << 31;
|
|
+ writel(value, BSCALER_BASE + LZMA_CTRL);
|
|
+ value = readl(BSCALER_BASE + LZMA_CTRL);
|
|
+ };
|
|
+/*printk("3\n");
|
|
+ value = readl(lzma_io_mem + LZMA_CTRL);
|
|
+
|
|
+ while(!(value & (1 << 31))) {
|
|
+ value |= 1 << 31;
|
|
+ writel(value, lzma_io_mem + LZMA_CTRL);
|
|
+ value = readl( lzma_io_mem+ LZMA_CTRL);
|
|
+ }*/
|
|
+
|
|
+ /* reset lzma */
|
|
+ writel(1 << 2, BSCALER_BASE + LZMA_CTRL);
|
|
+ while(readl(BSCALER_BASE + LZMA_CTRL) & (1 << 2));
|
|
+/*printk("5\n");
|
|
+ writel(1 << 2, lzma_io_mem + LZMA_CTRL);
|
|
+printk("6\n");
|
|
+ while(readl(lzma_io_mem + LZMA_CTRL) & (1 << 2));*/
|
|
+
|
|
+ /* init ram */
|
|
+ writel(1 << 1 ,BSCALER_BASE + LZMA_CTRL);
|
|
+ while(readl(BSCALER_BASE + LZMA_CTRL) & (1 << 1));
|
|
+/* writel(1 << 1 ,lzma_io_mem + LZMA_CTRL);
|
|
+printk("7\n");
|
|
+ while(readl( lzma_io_mem + LZMA_CTRL) & (1 << 1));*/
|
|
+
|
|
+ /* config */
|
|
+in_file = __get_free_pages(GFP_KERNEL, 11);//10 == 1024 == 4M ,if page_size=4096bytes,11==8M
|
|
+ if (in_file <= 0){
|
|
+ printk("input file space request failed!\n");
|
|
+ return -ENOMEM;
|
|
+ }
|
|
+ //lzma_debug("in size = 0x%x, virt_to_phys=0x%x\n", lzma_ope->in_file, virt_to_phys((void*)lzma_ope->in_file));
|
|
+ memset((void*)in_file, 0xff, 1024*1024*8);
|
|
+ out_file = __get_free_pages(GFP_KERNEL, 12); //10 == 1024 == 4M ,if page_size=4096bytes,12==16M
|
|
+ if (out_file <= 0){
|
|
+ printk("input file space request failed!\n");
|
|
+ return -ENOMEM;
|
|
+ }
|
|
+ memset((void*)out_file, 0xff, 1024*1024*16);
|
|
+ memmove((void *)in_file,(void* )src,size);
|
|
+ in_reg = virt_to_phys((void *)in_file );
|
|
+ out_reg = virt_to_phys((void*)out_file);
|
|
+ mm_segment_t fs;
|
|
+ fs = get_fs();
|
|
+ set_fs(KERNEL_DS);
|
|
+
|
|
+ printk("dma_cache_sync()...\n");
|
|
+ dma_cache_sync(NULL, (void *)in_file, 1*1024*1024, DMA_BIDIRECTIONAL);
|
|
+ printk("memmove...\n");
|
|
+ memmove((void *)in_file,(void *)src,size);
|
|
+ printk("dma_cache_sync()...\n");
|
|
+ dma_cache_sync(NULL, (void*)in_file, 1*1024*1024, DMA_BIDIRECTIONAL);
|
|
+ set_fs(fs);
|
|
+
|
|
+ writel(in_reg , BSCALER_BASE + LZMA_BS_BASE);
|
|
+ writel(size, BSCALER_BASE + LZMA_BS_SIZE);
|
|
+ writel(out_reg , BSCALER_BASE + LZMA_DST_BASE);
|
|
+/* writel(src- 0x80000000 , lzma_io_mem+ LZMA_BS_BASE);
|
|
+ writel(size, lzma_io_mem + LZMA_BS_SIZE);
|
|
+ writel(dst - 0x80000000,lzma_io_mem + LZMA_DST_BASE);*/
|
|
+
|
|
+ /* close intr and start lzma*/
|
|
+ writel((1 << 0) | (1 << 3), BSCALER_BASE + LZMA_CTRL);
|
|
+// writel((1 << 0) | (1 << 3), lzma_io_mem + LZMA_CTRL);
|
|
+
|
|
+ /* wait end */
|
|
+ printk(" LZMA_CTRL=0x%x\n",readl(BSCALER_BASE + LZMA_CTRL));
|
|
+ while(readl(BSCALER_BASE + LZMA_CTRL) & (1 << 0));
|
|
+ outlen = readl(BSCALER_BASE + LZMA_FINAL);
|
|
+// while(readl(lzma_io_mem + LZMA_CTRL) & (1 << 0));
|
|
+
|
|
+ memmove((void *)dst,(void *)out_file,outlen);
|
|
+ dump_lzma_reg();
|
|
+
|
|
+
|
|
+//release
|
|
+/* iounmap( clk_io_mem);
|
|
+ iounmap(lzma_io_mem);
|
|
+ release_mem_region(CPM_BASE,8);
|
|
+ release_mem_region( LZMA_BASE,40);*/
|
|
+ free_pages(in_file, 11);;
|
|
+ free_pages(out_file, 12);
|
|
+ return outlen;
|
|
+}
|
|
+EXPORT_SYMBOL(jz_lzma_decompress);
|