mirror of
https://github.com/torvalds/linux.git
synced 2026-06-08 06:25:52 +02:00
add rknand for debug
This commit is contained in:
parent
bd1ad1b0a6
commit
9a35477e37
|
|
@ -351,6 +351,12 @@ fb: fb{
|
|||
rockchip,disp-mode = <DUAL>;
|
||||
};
|
||||
|
||||
nandc: nandc {
|
||||
compatible = "rockchip,rk-nandc";
|
||||
reg = <0x10050000 0x4000>;
|
||||
interrupts = <GIC_SPI 27 IRQ_TYPE_LEVEL_HIGH>;
|
||||
};
|
||||
|
||||
lcdc0:lcdc@1010c000 {
|
||||
compatible = "rockchip,rk3188-lcdc";
|
||||
rockchip,prop = <PRMRY>;
|
||||
|
|
|
|||
2
drivers/mtd/Kconfig
Normal file → Executable file
2
drivers/mtd/Kconfig
Normal file → Executable file
|
|
@ -316,6 +316,8 @@ source "drivers/mtd/devices/Kconfig"
|
|||
|
||||
source "drivers/mtd/nand/Kconfig"
|
||||
|
||||
source "drivers/mtd/rknand/Kconfig"
|
||||
|
||||
source "drivers/mtd/onenand/Kconfig"
|
||||
|
||||
source "drivers/mtd/lpddr/Kconfig"
|
||||
|
|
|
|||
2
drivers/mtd/Makefile
Normal file → Executable file
2
drivers/mtd/Makefile
Normal file → Executable file
|
|
@ -30,6 +30,6 @@ obj-$(CONFIG_MTD_SWAP) += mtdswap.o
|
|||
nftl-objs := nftlcore.o nftlmount.o
|
||||
inftl-objs := inftlcore.o inftlmount.o
|
||||
|
||||
obj-y += chips/ lpddr/ maps/ devices/ nand/ onenand/ tests/
|
||||
obj-y += chips/ lpddr/ maps/ devices/ nand/ onenand/ tests/ rknand/
|
||||
|
||||
obj-$(CONFIG_MTD_UBI) += ubi/
|
||||
|
|
|
|||
|
|
@ -72,6 +72,9 @@ struct rknand_info {
|
|||
void (*nand_timing_config)(unsigned long AHBnKHz);
|
||||
void (*rknand_suspend)(void);
|
||||
void (*rknand_resume)(void);
|
||||
int (*rknand_re_init)(void);
|
||||
void (*rknand_dev_cache_flush)(void);
|
||||
int (*ftl_discard) (int Index, int nSec);
|
||||
int reserved[20];
|
||||
};
|
||||
|
||||
|
|
@ -83,5 +86,7 @@ extern void rknand_buffer_shutdown(void);
|
|||
extern int add_rknand_device(struct rknand_info * prknand_Info);
|
||||
extern int get_rknand_device(struct rknand_info ** prknand_Info);
|
||||
extern int rknand_buffer_sync(void);
|
||||
extern void rknand_cache_flush(void);
|
||||
extern void rknand_dev_cache_flush(void);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/version.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/sched.h>
|
||||
#include <linux/delay.h>
|
||||
|
|
@ -14,16 +14,26 @@
|
|||
#include <linux/slab.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/mtd/mtd.h>
|
||||
#include <linux/mtd/mtd.h>
|
||||
#include <linux/mtd/partitions.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/kthread.h>
|
||||
#include <linux/dma-mapping.h>
|
||||
#include <asm/dma.h>
|
||||
#include <asm/cacheflush.h>
|
||||
#include <linux/irq.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/reboot.h>
|
||||
#include <asm/io.h>
|
||||
#include <asm/mach/flash.h>
|
||||
//#include "api_flash.h"
|
||||
#include "rknand_base.h"
|
||||
#include "../mtdcore.h"
|
||||
#include <linux/clk.h>
|
||||
#include <linux/cpufreq.h>
|
||||
#ifdef CONFIG_OF
|
||||
#include <linux/of.h>
|
||||
#endif
|
||||
|
||||
#define DRIVER_NAME "rk29xxnand"
|
||||
|
||||
|
|
@ -117,9 +127,8 @@ static int rkNand_trac_read(char *page, char **start, off_t off, int count, int
|
|||
#define SPARE_LEN (32*8*2/4) //校验数据长度
|
||||
#define PAGE_LEN (DATA_LEN+SPARE_LEN) //每个数据单位的长度
|
||||
#define MAX_BUFFER_SIZE (long)(2048 * 8) //sector
|
||||
long grknand_buf[MAX_BUFFER_SIZE * 512/4] __attribute__((aligned(4096)));
|
||||
long grknand_dma_buf[PAGE_LEN*4*5] __attribute__((aligned(4096)));
|
||||
|
||||
//long grknand_buf[MAX_BUFFER_SIZE * 512/4] __attribute__((aligned(4096)));
|
||||
//long grknand_dma_buf[PAGE_LEN*4*5] __attribute__((aligned(4096)));
|
||||
static struct proc_dir_entry *my_proc_entry;
|
||||
extern int rkNand_proc_ftlread(char *page);
|
||||
extern int rkNand_proc_bufread(char *page);
|
||||
|
|
@ -144,6 +153,7 @@ static int rkNand_proc_read(char *page,
|
|||
return buf - page < count ? buf - page : count;
|
||||
}
|
||||
|
||||
#if 0// (LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0))
|
||||
static void rknand_create_procfs(void)
|
||||
{
|
||||
/* Install the proc_fs entry */
|
||||
|
|
@ -168,7 +178,21 @@ static void rknand_create_procfs(void)
|
|||
}
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
static const struct file_operations my_proc_fops = {
|
||||
.owner = THIS_MODULE,
|
||||
.read = rkNand_proc_read,
|
||||
.write = NULL,
|
||||
};
|
||||
|
||||
static void rknand_create_procfs(void)
|
||||
{
|
||||
/* Install the proc_fs entry */
|
||||
my_proc_entry = proc_create("rknand",
|
||||
S_IRUGO | S_IFREG,
|
||||
NANDPROC_ROOT,&my_proc_fops);
|
||||
}
|
||||
#endif
|
||||
void printk_write_log(long lba,int len, const u_char *pbuf)
|
||||
{
|
||||
char debug_buf[100];
|
||||
|
|
@ -189,15 +213,16 @@ static int rknand_read(struct mtd_info *mtd, loff_t from, size_t len,
|
|||
#ifdef RKNAND_TRAC_EN
|
||||
//trac_log(LBA,sector,0);
|
||||
#endif
|
||||
//printk("R %d %d \n",(int)LBA,sector);
|
||||
printk("R %d %d \n",(int)LBA,sector);
|
||||
//if(rknand_debug)
|
||||
// printk("rk28xxnand_read: from=%x,sector=%x,\n",(int)LBA,sector);
|
||||
if(sector && gpNandInfo->ftl_read)
|
||||
{
|
||||
ret = gpNandInfo->ftl_read(LBA, sector, buf);
|
||||
if(ret)
|
||||
*retlen = 0;
|
||||
}
|
||||
*retlen = len;
|
||||
return 0;//ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int rknand_write(struct mtd_info *mtd, loff_t from, size_t len,
|
||||
|
|
@ -209,7 +234,7 @@ static int rknand_write(struct mtd_info *mtd, loff_t from, size_t len,
|
|||
#ifdef RKNAND_TRAC_EN
|
||||
trac_log(LBA,sector,1);
|
||||
#endif
|
||||
//printk("W %d %d \n",(int)LBA,sector);
|
||||
printk("W %d %d \n",(int)LBA,sector);
|
||||
//return 0;
|
||||
//printk("*");
|
||||
//if(rknand_debug)
|
||||
|
|
@ -231,6 +256,19 @@ static int rknand_write(struct mtd_info *mtd, loff_t from, size_t len,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int rknand_diacard(struct mtd_info *mtd, loff_t from, size_t len)
|
||||
{
|
||||
int ret = 0;
|
||||
int sector = len>>9;
|
||||
int LBA = (int)(from>>9);
|
||||
//printk("rknand_diacard: from=%x,sector=%x,\n",(int)LBA,sector);
|
||||
if(sector && gpNandInfo->ftl_discard)
|
||||
{
|
||||
ret = gpNandInfo->ftl_discard(LBA, sector);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int rknand_erase(struct mtd_info *mtd, struct erase_info *instr)
|
||||
{
|
||||
int ret = 0;
|
||||
|
|
@ -271,29 +309,31 @@ int GetIdBlockSysData(char * buf, int Sector)
|
|||
return 0;
|
||||
}
|
||||
|
||||
char GetSNSectorInfo(char * pbuf)
|
||||
{
|
||||
if(gpNandInfo->GetSNSectorInfo)
|
||||
return( gpNandInfo->GetSNSectorInfo( pbuf));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
char GetSNSectorInfoBeforeNandInit(char * pbuf)
|
||||
{
|
||||
char * sn_addr = ioremap(0x10501600,0x200);
|
||||
memcpy(pbuf,sn_addr,0x200);
|
||||
iounmap(sn_addr);
|
||||
//print_hex_dump(KERN_WARNING, "sn:", DUMP_PREFIX_NONE, 16,1, sn_addr, 0x200, 0);
|
||||
//print_hex_dump(KERN_WARNING, "sn:", DUMP_PREFIX_NONE, 16,1, sn_addr, 16, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
char GetSNSectorInfo(char * pbuf)
|
||||
{
|
||||
if(gpNandInfo->GetSNSectorInfo)
|
||||
return( gpNandInfo->GetSNSectorInfo( pbuf));
|
||||
else
|
||||
return GetSNSectorInfoBeforeNandInit(pbuf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
char GetVendor0InfoBeforeNandInit(char * pbuf)
|
||||
{
|
||||
char * sn_addr = ioremap(0x10501400,0x200);
|
||||
memcpy(pbuf,sn_addr + 8,504);
|
||||
iounmap(sn_addr);
|
||||
//print_hex_dump(KERN_WARNING, "sn:", DUMP_PREFIX_NONE, 16,1, sn_addr, 0x200, 0);
|
||||
//print_hex_dump(KERN_WARNING, "sn:", DUMP_PREFIX_NONE, 16,1, sn_addr, 16, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -328,6 +368,12 @@ int GetflashDataByLba(int lba,char * pbuf , int len)
|
|||
return ret?-1:(sector<<9);
|
||||
}
|
||||
|
||||
void rknand_dev_cache_flush(void)
|
||||
{
|
||||
if(gpNandInfo->rknand_dev_cache_flush)
|
||||
gpNandInfo->rknand_dev_cache_flush();
|
||||
}
|
||||
|
||||
|
||||
static int rknand_block_isbad(struct mtd_info *mtd, loff_t ofs)
|
||||
{
|
||||
|
|
@ -379,22 +425,23 @@ static int rknand_info_init(struct rknand_info *nand_info)
|
|||
// Fill in remaining MTD driver data
|
||||
mtd->type = MTD_NANDFLASH;
|
||||
mtd->flags = (MTD_WRITEABLE|MTD_NO_ERASE);//
|
||||
mtd->erase = rknand_erase;
|
||||
mtd->point = NULL;
|
||||
mtd->unpoint = NULL;
|
||||
mtd->read = rknand_read;
|
||||
mtd->write = rknand_write;
|
||||
mtd->read_oob = NULL;
|
||||
mtd->write_oob = NULL;
|
||||
mtd->panic_write = rknand_panic_write;
|
||||
mtd->_erase = rknand_erase;
|
||||
mtd->_point = NULL;
|
||||
mtd->_unpoint = NULL;
|
||||
mtd->_read = rknand_read;
|
||||
mtd->_write = rknand_write;
|
||||
//mtd->discard = rknand_diacard;
|
||||
mtd->_read_oob = NULL;
|
||||
mtd->_write_oob = NULL;
|
||||
mtd->_panic_write = rknand_panic_write;
|
||||
|
||||
mtd->sync = rknand_sync;
|
||||
mtd->lock = NULL;
|
||||
mtd->unlock = NULL;
|
||||
mtd->suspend = NULL;
|
||||
mtd->resume = NULL;
|
||||
mtd->block_isbad = rknand_block_isbad;
|
||||
mtd->block_markbad = rknand_block_markbad;
|
||||
mtd->_sync = rknand_sync;
|
||||
mtd->_lock = NULL;
|
||||
mtd->_unlock = NULL;
|
||||
mtd->_suspend = NULL;
|
||||
mtd->_resume = NULL;
|
||||
mtd->_block_isbad = rknand_block_isbad;
|
||||
mtd->_block_markbad = rknand_block_markbad;
|
||||
mtd->owner = THIS_MODULE;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -418,6 +465,7 @@ static int rknand_add_partitions(struct rknand_info *nand_info)
|
|||
// 从命令行解析分区的信息
|
||||
num_partitions = parse_mtd_partitions(&(rknand_mtd), part_probes, &rknand_parts, 0);
|
||||
NAND_DEBUG(NAND_DEBUG_LEVEL0,"num_partitions = %d\n",num_partitions);
|
||||
printk("num_partitions = %d\n",num_partitions);
|
||||
if(num_partitions > 0) {
|
||||
int i;
|
||||
for (i = 0; i < num_partitions; i++)
|
||||
|
|
@ -428,11 +476,11 @@ static int rknand_add_partitions(struct rknand_info *nand_info)
|
|||
rknand_parts[num_partitions - 1].size = rknand_mtd.size - rknand_parts[num_partitions - 1].offset;
|
||||
|
||||
g_num_partitions = num_partitions;
|
||||
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
|
||||
return mtd_device_register(&rknand_mtd, rknand_parts, num_partitions);
|
||||
#else
|
||||
//#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
|
||||
// return mtd_device_register(&rknand_mtd, rknand_parts, num_partitions);
|
||||
//#else
|
||||
return add_mtd_partitions(&(rknand_mtd), rknand_parts, num_partitions);
|
||||
#endif
|
||||
//#endif
|
||||
}
|
||||
#endif
|
||||
g_num_partitions = 0;
|
||||
|
|
@ -444,7 +492,7 @@ int add_rknand_device(struct rknand_info * prknand_Info)
|
|||
struct mtd_partition *parts;
|
||||
int i;
|
||||
NAND_DEBUG(NAND_DEBUG_LEVEL0,"add_rknand_device: \n");
|
||||
|
||||
printk("gpNandInfo->nandCapacity = %lx\n",gpNandInfo->nandCapacity);
|
||||
rknand_mtd.size = (uint64_t)gpNandInfo->nandCapacity*0x200;
|
||||
|
||||
rknand_add_partitions(prknand_Info);
|
||||
|
|
@ -464,9 +512,9 @@ int add_rknand_device(struct rknand_info * prknand_Info)
|
|||
if(SysImageWriteEndAdd)
|
||||
gpNandInfo->SysImageWriteEndAdd = SysImageWriteEndAdd;
|
||||
|
||||
nandc_clk = clk_get(NULL, "nandc");
|
||||
clk_enable(nandc_clk);
|
||||
rknand_nand_timing_cfg();
|
||||
//nandc_clk = clk_get(NULL, "nandc");
|
||||
//clk_enable(nandc_clk);
|
||||
//rknand_nand_timing_cfg();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -479,6 +527,52 @@ int get_rknand_device(struct rknand_info ** prknand_Info)
|
|||
|
||||
EXPORT_SYMBOL(get_rknand_device);
|
||||
|
||||
int rknand_dma_map_single(unsigned long ptr,int size,int dir)
|
||||
{
|
||||
return dma_map_single(NULL, ptr,size, dir?DMA_TO_DEVICE:DMA_FROM_DEVICE);
|
||||
}
|
||||
EXPORT_SYMBOL(rknand_dma_map_single);
|
||||
|
||||
void rknand_dma_unmap_single(unsigned long ptr,int size,int dir)
|
||||
{
|
||||
dma_unmap_single(NULL, ptr,size, dir?DMA_TO_DEVICE:DMA_FROM_DEVICE);
|
||||
}
|
||||
EXPORT_SYMBOL(rknand_dma_unmap_single);
|
||||
|
||||
int rknand_flash_cs_init(void)
|
||||
{
|
||||
|
||||
}
|
||||
EXPORT_SYMBOL(rknand_flash_cs_init);
|
||||
|
||||
|
||||
int rknand_get_reg_addr(int *pNandc,int *pSDMMC0,int *pSDMMC1,int *pSDMMC2)
|
||||
{
|
||||
//*pNandc = ioremap(RK30_NANDC_PHYS,RK30_NANDC_SIZE);
|
||||
//*pSDMMC0 = ioremap(SDMMC0_BASE_ADDR, 0x4000);
|
||||
//*pSDMMC1 = ioremap(SDMMC1_BASE_ADDR, 0x4000);
|
||||
//*pSDMMC2 = ioremap(EMMC_BASE_ADDR, 0x4000);
|
||||
*pNandc = ioremap(0x10500000,0x4000);
|
||||
}
|
||||
EXPORT_SYMBOL(rknand_get_reg_addr);
|
||||
|
||||
static int g_nandc_irq = 27;
|
||||
int rknand_nandc_irq_init(int mode,void * pfun)
|
||||
{
|
||||
int ret = 0;
|
||||
if(mode) //init
|
||||
{
|
||||
ret = request_irq(g_nandc_irq, pfun, 0, "nandc", NULL);
|
||||
if(ret)
|
||||
printk("request IRQ_NANDC irq , ret=%x.........\n", ret);
|
||||
}
|
||||
else //deinit
|
||||
{
|
||||
free_irq(g_nandc_irq, NULL);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(rknand_nandc_irq_init);
|
||||
static int rknand_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct rknand_info *nand_info;
|
||||
|
|
@ -489,18 +583,25 @@ static int rknand_probe(struct platform_device *pdev)
|
|||
return -ENOMEM;
|
||||
|
||||
nand_info = gpNandInfo;
|
||||
printk("rknand_probe: \n");
|
||||
|
||||
g_nandc_irq = platform_get_irq(pdev, 0);
|
||||
if (g_nandc_irq < 0) {
|
||||
dev_err(&pdev->dev, "no irq resource?\n");
|
||||
return g_nandc_irq;
|
||||
}
|
||||
|
||||
memset(gpNandInfo,0,sizeof(struct rknand_info));
|
||||
|
||||
gpNandInfo->bufSize = MAX_BUFFER_SIZE * 512;
|
||||
gpNandInfo->pbuf = (char *)grknand_buf;
|
||||
gpNandInfo->pdmaBuf = (char *)grknand_dma_buf;
|
||||
gpNandInfo->pbuf = (char *)NULL;//grknand_buf;
|
||||
gpNandInfo->pdmaBuf = (char *)NULL;//grknand_dma_buf;
|
||||
//printk(" gpNandInfo->pdmaBuf=0x%x\n", gpNandInfo->pdmaBuf);
|
||||
#ifdef CONFIG_MTD_EMMC_CLK_POWER_SAVE
|
||||
gpNandInfo->emmc_clk_power_save_en = 1;
|
||||
#endif
|
||||
|
||||
rknand_mtd.name = dev_name(&pdev->dev);
|
||||
rknand_mtd.name = DRIVER_NAME;//dev_name(&pdev->dev);
|
||||
rknand_mtd.priv = &nand_info->rknand;
|
||||
rknand_mtd.owner = THIS_MODULE;
|
||||
|
||||
|
|
@ -549,6 +650,13 @@ void rknand_shutdown(struct platform_device *pdev)
|
|||
gpNandInfo->rknand_buffer_shutdown();
|
||||
}
|
||||
|
||||
#ifdef CONFIG_OF
|
||||
static const struct of_device_id of_rk_nandc_match[] = {
|
||||
{ .compatible = "rockchip,rk-nandc" },
|
||||
{ /* Sentinel */ }
|
||||
};
|
||||
#endif
|
||||
|
||||
static struct platform_driver rknand_driver = {
|
||||
.probe = rknand_probe,
|
||||
.suspend = rknand_suspend,
|
||||
|
|
@ -556,6 +664,9 @@ static struct platform_driver rknand_driver = {
|
|||
.shutdown = rknand_shutdown,
|
||||
.driver = {
|
||||
.name = DRIVER_NAME,
|
||||
#ifdef CONFIG_OF
|
||||
.of_match_table = of_rk_nandc_match,
|
||||
#endif
|
||||
.owner = THIS_MODULE,
|
||||
},
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user