各位TI大牛:
Linux系统下 NandFlash GPMC资源是如何分配的呢?片选这个不说了,直接明了,起始地址?地址范围呢?
我查看了下源代码,没有找到明确的设置地方,跟踪了下内核启动信息,添加打印,看到了如下结果
gpmc ncs0 nand flash:startaddr 8000000 memory size 1000000
起始地址128M 大小16M
程序里面是怎么设定的呢?
am335x_nand_init (board_am335xevm.c)调用 board_nand_init()(board-flash.c)
void
161 __init board_nand_init(struct mtd_partition *nand_parts,
162 u8 nr_parts, u8 cs, int nand_type)
163 { 164 board_nand_data.cs = cs;
165 board_nand_data.parts = nand_parts;
166 board_nand_data.nr_parts = nr_parts;
167 board_nand_data.devsize = nand_type;
168169 board_nand_data.ecc_opt = OMAP_ECC_HAMMING_CODE_DEFAULT;
170 board_nand_data.gpmc_irq = OMAP_GPMC_IRQ_BASE + cs;
171172 if (cpu_is_am335x()) {
173 // board_nand_data.ecc_opt = OMAP_ECC_BCH8_CODE_HW;
174 board_nand_data.xfer_type = NAND_OMAP_PREFETCH_POLLED;
175 }
176177 gpmc_nand_init(&board_nand_data);
178 }
这里设置了片选,分区信息
board_nand_data.devsize = nand_type;//怎么理解,devsize设备大小?nandtype nand类型,看程序nand_type = 0x00,不解、、
再后面就是调用gpmc_nand_init进行底层初始化了。
int __init gpmc_nand_init(struct omap_nand_platform_data *gpmc_nand_data)
85 {
86 int err = 0;
87 struct device *dev = &gpmc_nand_device.dev;
88 89 gpmc_nand_device.dev.platform_data = gpmc_nand_data;
90 91 err = gpmc_cs_request(gpmc_nand_data->cs, NAND_IO_SIZE,
92 &gpmc_nand_data->phys_base);
93 if (err < 0) {
94 dev_err(dev, "Cannot request GPMC CS\n");
95 return err;
96 }
97 98 /* Set timings in GPMC */
99 err = omap2_nand_gpmc_retime(gpmc_nand_data);
100 if (err < 0) {
101 dev_err(dev, "Unable to set gpmc timings: %d\n", err);
102 return err;
103 }
104105 /* Enable RD PIN Monitoring Reg */
106 if (gpmc_nand_data->dev_ready) {
107 gpmc_cs_configure(gpmc_nand_data->cs, GPMC_CONFIG_RDY_BSY, 1);
108 }
109110 err = platform_device_register(&gpmc_nand_device);
111 if (err < 0) {
112 dev_err(dev, "Unable to register NAND device\n");
113 goto out_free_cs;
114 }
115116 return 0;
117118 out_free_cs:
119 gpmc_cs_free(gpmc_nand_data->cs);
120121 return err;
122 }
NAND_IO_SIZE 4
gpmc_cs_request(gpmc_nand_data->cs, NAND_IO_SIZE, &gpmc_nand_data->phys_base);
片选申请 这个NAND_IO_SIZE 又是什么含义?
int gpmc_cs_request(int cs, unsigned long size, unsigned long *base)
403 {
404 struct resource *res = &gpmc_cs_mem[cs];
405 int r = -1;
406407 if (cs > GPMC_CS_NUM)
408 return -ENODEV;
409410 size = gpmc_mem_align(size);
411 if (size > (1 << GPMC_SECTION_SHIFT))
412 return -ENOMEM;
413414 spin_lock(&gpmc_mem_lock);
415 if (gpmc_cs_reserved(cs)) {
416 r = -EBUSY;
417 goto out;
418 }
419 if (gpmc_cs_mem_enabled(cs))
420 r = adjust_resource(res, res->start & ~(size – 1), size);
421 if (r < 0)
422 r = allocate_resource(&gpmc_mem_root, res, size, 0, ~0,
423 size, NULL, NULL);
424 if (r < 0)
425 goto out;
426 427 gpmc_cs_enable_mem(cs, res->start, resource_size(res));
428 printk("gpmc ncs0 nand flash:startaddr %x memory size %x\n",res->start,resource_size(res));
429 *base = res->start;
430 gpmc_cs_set_reserved(cs, 1);
431 out:
432 spin_unlock(&gpmc_mem_lock);
433 return r;
434 }
gpmc_cs_request 又是如何得出 128M起始地址 16M大小的呢?
请高手指点?
my wu:
TI最近是否放假了?好些问题都没人解答。
楼主用的是哪个linux版本?
看样子应该是通过dts配置传过去的,如果还不知道何为dts,那得花两天熟悉一下。
Jian Zhou:
回复 my wu:
devsize是指GPMC的bus带宽为8bit或者16bit,NAND_IO_SIZE是需要申请的空间大小,具体还是要详细读下代码。
推荐参考:http://www.deyisupport.com/files/m/sitara_arm/11905.aspx