tegra: Add NAND flash support
Subsystems (5)
v3 cover tegra: Add NAND flash support
This series adds NAND flash support to Tegra and enables it on Seaboard.
Included here is a proposed device tree binding with most of the properties private to "nvidia,". The binding includes information about the NAND controller as well as the connected NAND device. The Seaboard has a Hynix HY27UF4G2B.
The driver supports ECC-based access and uses DMA and NAND acceleration features of the Tegra SOC to provide access at reasonable speed.
Changes in v2:
- Add new patch to align default buffers in nand_base
- Added comment about the behaviour of the 'resp' register
- Call set_bus_width_page_size() at init to report errors earlier
- Change set_bus_width_page_size() to return an error when needed
- Change timing structure member to u32 to match device tree
- Check for supported bus width in board_nand_init()
- Fix tegra nand header file to remove BIT defines
- Implement a dummy nand_select_chip() instead of nand_hwcontro()
- Make nand_command() display an error on an unknown command
- Minor code tidy-ups in driver for style
- Move cache logic into a separate dma_prepare() function
- Remove CMD_TRANS_SIZE_BYTESx enum
- Remove space after casts
- Remove use of 'register' variables
- Rename struct nand_info to struct nand_drv to avoid nand_info_t confusion
- Support 4096 byte page devices, drop 1024 and 2048
- Tidy up nand_waitfor_cmd_completion() logic
- Update NAND binding to add "nvidia," prefix
- Use s32 for device tree integer values
Changes in v3:
- Add reg property for unit address (should be used for chip select)
- Change note in fdt binding about the need for a hardware-specific binding
- Fix up typos in fdt binding, and rename the file
- Update fdt binding to make everything Nvidia-specific
Jim Lin (1):
tegra: nand: Add Tegra NAND driver
Simon Glass (6):
nand: Try to align the default buffers
fdt: Add debugging to fdtdec_get_int/addr()
tegra: Add NAND support to funcmux
tegra: fdt: Add NAND controller binding and definitions
tegra: fdt: Add NAND definitions to fdt
tegra: Enable NAND on Seaboard
arch/arm/cpu/armv7/tegra2/funcmux.c | 7 + arch/arm/dts/tegra20.dtsi | 6 + arch/arm/include/asm/arch-tegra2/funcmux.h | 3 + arch/arm/include/asm/arch-tegra2/tegra2.h | 1 + board/nvidia/dts/tegra2-seaboard.dts | 16 + .../nand/nvidia,tegra20-nand.txt | 68 ++ drivers/mtd/nand/Makefile | 1 + drivers/mtd/nand/nand_base.c | 3 +- drivers/mtd/nand/tegra2_nand.c | 1095 ++++++++++++++++++++ drivers/mtd/nand/tegra2_nand.h | 257 +++++ include/configs/seaboard.h | 9 + include/fdtdec.h | 1 + include/linux/mtd/nand.h | 7 +- lib/fdtdec.c | 23 +- 14 files changed, 1487 insertions(+), 10 deletions(-) create mode 100644 doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt create mode 100644 drivers/mtd/nand/tegra2_nand.c create mode 100644 drivers/mtd/nand/tegra2_nand.h
Signature · 1 line
1.7.7.3
PATCH v3 1/7 nand: Try to align the default buffers
The NAND layer needs to use cache-aligned buffers by default. Towards this goal. align the default buffers and their members according to the minimum DMA alignment defined for the architecture.
---
Changes in v2:
- Add new patch to align default buffers in nand_base
drivers/mtd/nand/nand_base.c | 3 ++- include/linux/mtd/nand.h | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-)
drivers/mtd/nand/nand_base.c +2 -1
@@ -2935,7 +2935,8 @@ int nand_scan_tail(struct mtd_info *mtd)struct nand_chip *chip = mtd->priv;if (!(chip->options &NAND_OWN_BUFFERS )) - chip->buffers =kmalloc (sizeof (*chip->buffers),GFP_KERNEL ); + chip->buffers =memalign (ARCH_DMA_MINALIGN , +sizeof (*chip->buffers));if (!chip->buffers)return -ENOMEM ;
include/linux/mtd/nand.h +4 -3
@@ -391,9 +391,10 @@ struct nand_ecc_ctrl {* consecutive order. */ struct nand_buffers { -uint8_t ecccalc[NAND_MAX_OOBSIZE ]; -uint8_t ecccode[NAND_MAX_OOBSIZE ]; -uint8_t databuf[NAND_MAX_PAGESIZE +NAND_MAX_OOBSIZE ]; +uint8_t ecccalc[ALIGN (NAND_MAX_OOBSIZE ,ARCH_DMA_MINALIGN )]; +uint8_t ecccode[ALIGN (NAND_MAX_OOBSIZE ,ARCH_DMA_MINALIGN )]; +uint8_t databuf[ALIGN (NAND_MAX_PAGESIZE +NAND_MAX_OOBSIZE , +ARCH_DMA_MINALIGN )]; };/**
Signature · 1 line
1.7.7.3
PATCH v3 2/7 fdt: Add debugging to fdtdec_get_int/addr()
In reply to Simon GlassThe new debugging shows the value of integers and addresses read from the device tree.
---
lib/fdtdec.c | 22 ++++++++++++++++------ 1 files changed, 16 insertions(+), 6 deletions(-)
lib/fdtdec.c +16 -6
@@ -79,11 +79,16 @@ fdt_addr_t fdtdec_get_addr(const void *blob, int node,const fdt_addr_t *cell;int len; -debug ("get_addr: %s\n" , prop_name); +debug ("%s: %s\n" , __func__, prop_name); cell =fdt_getprop (blob, node, prop_name, &len);if (cell && (len ==sizeof (fdt_addr_t) || - len ==sizeof (fdt_addr_t) *2 )) -return fdt_addr_to_cpu (*cell); + len ==sizeof (fdt_addr_t) *2 )) { +fdt_addr_t addr =fdt_addr_to_cpu (*cell); + +debug ("%p\n" , (void *)addr); +return addr; + } +debug ("(not found)\n" );return FDT_ADDR_T_NONE ; }
@@ -93,10 +98,15 @@ s32 fdtdec_get_int(const void *blob, int node, const char *prop_name,const s32 *cell;int len; -debug ("get_size: %s\n" , prop_name); +debug ("%s: %s: " , __func__, prop_name); cell =fdt_getprop (blob, node, prop_name, &len); -if (cell && len >=sizeof (s32)) -return fdt32_to_cpu (cell[0 ]); +if (cell && len >=sizeof (s32)) { +s32 val =fdt32_to_cpu (cell[0 ]); + +debug ("%#x (%d)\n" , val, val); +return val; + } +debug ("(not found)\n" );return default_val; }
Signature · 1 line
1.7.7.3
PATCH v3 3/7 tegra: Add NAND support to funcmux
In reply to Simon GlassAdd selection of NAND flash pins to the funcmux.
---
arch/arm/cpu/armv7/tegra2/funcmux.c | 7 +++++++ arch/arm/include/asm/arch-tegra2/funcmux.h | 3 +++ 2 files changed, 10 insertions(+), 0 deletions(-)
arch/arm/cpu/armv7/tegra2/funcmux.c +7 -0
@@ -169,6 +169,13 @@ int funcmux_select(enum periph_id id, int config) }break ; +case PERIPH_ID_NDFLASH : +if (config ==FUNCMUX_NDFLASH_ATC ) { +pinmux_set_func (PINGRP_ATC ,PMUX_FUNC_NAND ); +pinmux_tristate_disable (PINGRP_ATC ); + } +break ; +default :debug ("%s: invalid periph_id %d" , __func__, id);return -1 ;
arch/arm/include/asm/arch-tegra2/funcmux.h +3 -0
@@ -47,6 +47,9 @@ enum {FUNCMUX_SDMMC4_ATC_ATD_8BIT =0 ,FUNCMUX_SDMMC4_ATB_GMA_4_BIT ,FUNCMUX_SDMMC4_ATB_GMA_GME_8_BIT , + +/* NAND flags */ + FUNCMUX_NDFLASH_ATC = 0, };/**
Signature · 1 line
1.7.7.3
PATCH v3 4/7 tegra: fdt: Add NAND controller binding and definitions
In reply to Simon GlassAdd a NAND controller along with a bindings file for review.
---
Changes in v2:
- Update NAND binding to add "nvidia," prefix
Changes in v3:
- Add reg property for unit address (should be used for chip select)
- Change note in fdt binding about the need for a hardware-specific binding
- Fix up typos in fdt binding, and rename the file
- Update fdt binding to make everything Nvidia-specific
arch/arm/dts/tegra20.dtsi | 6 ++ .../nand/nvidia,tegra20-nand.txt | 68 ++++++++++++++++++++ 2 files changed, 74 insertions(+), 0 deletions(-) create mode 100644 doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt
arch/arm/dts/tegra20.dtsi +6 -0
@@ -200,4 +200,10 @@ reg = <0x7000f400 0x200>; }; + nand: nand-controller@70008000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "nvidia,tegra20-nand"; + reg = <0x70008000 0x100>; + }; };
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt new file +68 -0
68 lines not on this page · raw message
Signature · 1 line
1.7.7.3
Re: [PATCH v3 4/7] tegra: fdt: Add NAND controller binding and definitions
Quoted 8 lines · Simon Glass
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt new file +2
-0@@ -0,0 +1,68 @@ +NAND Flash +----------
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt line 12
Quoted 10 lines
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt new file +10
-0+ +(there isn't yet a generic binding in Linux, so this describes what is in +U-Boot. There should not be Linux-specific or U-Boot specific binding, just +a binding that describes this hardware. But agreeing a binding in Linux in +the absence of a driver may be beyond my powers.) + +The device node for a NAND flash device is as follows: + +Required properties : + - compatible : Should be "manufacturer,device", "nand-flash"
Again, "nand-flash" is not an appropriate compatible. There is no generic nand-flash binding.
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt line 16
Quoted 4 lines
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt new file +4
-0+ - nvidia,page-data-bytes : Number of bytes in the data area + - nvidia,page-spare-bytes : Number of bytes in spare area + spare area = skipped-spare-bytes + data-ecc-bytes + tag-bytes + + tag-ecc-bytes
Do you really need this stuff to be in the device tree? You should be able to determine this information from the ID table.
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt line 18
Quoted 2 lines
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt new file +2
-0+ - nvidia,skipped-spare-bytes : Number of bytes to skip at start of spare area + (these are typically used for bad block maintenance)
So this binding can't deal with the bad block marker being somewhere other than the beginning of the spare area (e.g. 8-bit small page NAND)?
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt line 19
Quoted 1 line
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt new file +1
-0+ - nvidia,data-ecc-bytes : Number of ECC bytes for data area
Number of ECC bytes per page? Number of ECC bytes per ECC block? Number of data bytes per ECC block?
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt line 20
Quoted 1 line
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt new file +1
-0+ - nvidia,tag-bytes :Number of tag bytes in spare area
What are tag bytes?
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt line 34
Quoted 9 lines
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt new file +9
-0+Nvidia NAND Controller +---------------------- + +The device node for a NAND flash controller is as follows: + +Optional properties: + +nvidia,wp-gpios : GPIO of write-protect line, three cells in the format: + phandle, parameter, flags
Doesn't the number of cells depend on the GPIO controller binding?
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt line 39
Quoted 5 lines
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt new file +5
-0+nvidia,nand-width : bus width of the NAND device in bits + + - nvidia,nand-timing : Timing parameters for the NAND. Each is in ns. + Order is: MAX_TRP_TREA, TWB, Max(tCS, tCH, tALS, tALH), + TWHR, Max(tCS, tCH, tALS, tALH), TWH, TWP, TRH, TADL
Might want to point out that there's one cell per timing parameter.
-Scott
Re: [PATCH v3 4/7] tegra: fdt: Add NAND controller binding and definitions
+Jim, who wrote the driver originally
Hi Scott,
Quoted 14 lines · Scott Wood
Quoted 13 lines · Simon Glass
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt new file +7
-0@@ -0,0 +1,68 @@ +NAND Flash +---------- + +(there isn't yet a generic binding in Linux, so this describes what is in +U-Boot. There should not be Linux-specific or U-Boot specific binding, just +a binding that describes this hardware. But agreeing a binding in Linux in +the absence of a driver may be beyond my powers.)
Quoted 8 lines
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt line 12
Quoted 5 lines
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt new file +5
-0+ +The device node for a NAND flash device is as follows: + +Required properties : + - compatible : Should be "manufacturer,device", "nand-flash"Again, "nand-flash" is not an appropriate compatible. There is no generic nand-flash binding.
OK, so I should just drop this.
Quoted 8 lines
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt line 16
Quoted 5 lines
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt new file +4
-0+ - nvidia,page-data-bytes : Number of bytes in the data area + - nvidia,page-spare-bytes : Number of bytes in spare area + spare area = skipped-spare-bytes + data-ecc-bytes + tag-bytes + + tag-ecc-bytesDo you really need this stuff to be in the device tree? You should be able to determine this information from the ID table.
I suspect so - the driver originally had a lot of CONFIGs for this. Maybe someone who wants to take it further could do this as part of supporting ONFI?
I will see if Jim Lin can take another look.
Quoted 6 lines
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt line 18
Quoted 3 lines
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt new file +2
-0+ - nvidia,skipped-spare-bytes : Number of bytes to skip at start of spare area + (these are typically used for bad block maintenance)So this binding can't deal with the bad block marker being somewhere other than the beginning of the spare area (e.g. 8-bit small page NAND)?
I suppose it depends on what you want to put afterwards.
Quoted 9 lines
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt line 19
Quoted 2 lines
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt new file +1
-0+ - nvidia,data-ecc-bytes : Number of ECC bytes for data areaNumber of ECC bytes per page? Number of ECC bytes per ECC block? Number of data bytes per ECC block?
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt line 20
Quoted 1 line
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt new file +1
-0+ - nvidia,tag-bytes :Number of tag bytes in spare areaWhat are tag bytes?
I know that term from YAFFS, but other than that I am not sure.
Quoted 12 lines
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt line 34
Quoted 10 lines
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt new file +9
-0+Nvidia NAND Controller +---------------------- + +The device node for a NAND flash controller is as follows: + +Optional properties: + +nvidia,wp-gpios : GPIO of write-protect line, three cells in the format: + phandle, parameter, flagsDoesn't the number of cells depend on the GPIO controller binding?
Yes, but this is the binding Tegra uses.
Quoted 8 lines
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt line 39
Quoted 6 lines
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt new file +5
-0+nvidia,nand-width : bus width of the NAND device in bits + + - nvidia,nand-timing : Timing parameters for the NAND. Each is in ns. + Order is: MAX_TRP_TREA, TWB, Max(tCS, tCH, tALS, tALH), + TWHR, Max(tCS, tCH, tALS, tALH), TWH, TWP, TRH, TADLMight want to point out that there's one cell per timing parameter.
OK.
I'm going to wait and see if Jim can pick up this driver and make the device-tree change you requested.
Quoted 3 lines
-Scott
Regards,
Simon
Re: [PATCH v3 4/7] tegra: fdt: Add NAND controller binding and definitions
Quoted 10 lines · Simon Glass
+Jim, who wrote the driver originally
Hi Scott,
Quoted 5 lines · Scott Wood
Quoted 4 lines
+ - nvidia,page-data-bytes : Number of bytes in the data area
+ - nvidia,page-spare-bytes : Number of bytes in spare areadoc/device-tree-bindings/nand/nvidia,tegra20-nand.txt new file +2
-0+ spare area = skipped-spare-bytes + data-ecc-bytes + tag-bytes + + tag-ecc-bytes
Quoted 8 lines
Quoted 2 lines
Do you really need this stuff to be in the device tree? You should be able to determine this information from the ID table.
I suspect so - the driver originally had a lot of CONFIGs for this. Maybe someone who wants to take it further could do this as part of supporting ONFI?
I will see if Jim Lin can take another look.
You don't need ONFI to get the page/spare size out of the ID table.
The generic NAND code should already be doing this for you (fills in mtd->writesize and mtd->oobsize). If you need it during setup, we now have CONFIG_SYS_NAND_SELF_INIT that allows splitting up nand_scan_ident() from nand_scan_tail().
Quoted 12 lines
Quoted 11 lines
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt line 34
Quoted 9 lines
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt new file +9
-0+Nvidia NAND Controller +---------------------- + +The device node for a NAND flash controller is as follows: + +Optional properties: + +nvidia,wp-gpios : GPIO of write-protect line, three cells in the format: + phandle, parameter, flagsDoesn't the number of cells depend on the GPIO controller binding?
Quoted 1 line
Yes, but this is the binding Tegra uses.
Still, it doesn't belong in the NAND binding. Maybe a future chip wants to use this NAND binding but a different GPIO binding. If nothing else, people tend to copy-and-paste such descriptions. We've still got people adding bindings for Freescale devices saying interrupts are encoded as a pair of cells, even though the interrupt controller now uses four cells per interrupt.
-Scott
Re: [PATCH v3 4/7] tegra: fdt: Add NAND controller binding and definitions
Hi Scott,
Quoted 18 lines · Scott Wood
Quoted 17 lines · Simon Glass
+Jim, who wrote the driver originally
Hi Scott,
Quoted 7 lines · Scott Wood
Quoted 4 lines
+ - nvidia,page-data-bytes : Number of bytes in the data area
+ - nvidia,page-spare-bytes : Number of bytes in spare area
+ spare area = skipped-spare-bytes + data-ecc-bytes + tag-bytes
+ + tag-ecc-bytesDo you really need this stuff to be in the device tree? You should be able to determine this information from the ID table.
I suspect so - the driver originally had a lot of CONFIGs for this. Maybe someone who wants to take it further could do this as part of supporting ONFI?
Quoted 8 lines
Quoted 1 line
I will see if Jim Lin can take another look.
You don't need ONFI to get the page/spare size out of the ID table.
The generic NAND code should already be doing this for you (fills in
mtd->writesizeandmtd->oobsize). If you need it during setup, we now haveCONFIG_SYS_NAND_SELF_INITthat allows splitting upnand_scan_ident()fromnand_scan_tail().
OK, sounds good. It should just need to be changed over to calculate these values from the nand layer.
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt line 34
Quoted 10 lines
doc/device-tree-bindings/nand/nvidia,tegra20-nand.txt new file +9
-0+Nvidia NAND Controller +---------------------- + +The device node for a NAND flash controller is as follows: + +Optional properties: + +nvidia,wp-gpios : GPIO of write-protect line, three cells in the format: + phandle, parameter, flagsDoesn't the number of cells depend on the GPIO controller binding?
Quoted 8 lines
Quoted 1 line
Yes, but this is the binding Tegra uses.
Still, it doesn't belong in the NAND binding. Maybe a future chip wants to use this NAND binding but a different GPIO binding. If nothing else, people tend to copy-and-paste such descriptions. We've still got people adding bindings for Freescale devices saying interrupts are encoded as a pair of cells, even though the interrupt controller now uses four cells per interrupt.
OK I see - are you are saying that we should just say something like:
"nvidia,wp-gpios : GPIO of write-protect line, as defined by gpio bindings"
Quoted 3 lines
-Scott
Regards,
Simon
Re: [PATCH v3 4/7] tegra: fdt: Add NAND controller binding and definitions
Quoted 16 lines · Simon Glass
Hi Scott,
Quoted 4 lines · Scott Wood
Quoted 3 lines · Simon Glass
Quoted 1 line · Scott Wood
Doesn't the number of cells depend on the GPIO controller binding?
Quoted 8 lines
Quoted 1 line
Yes, but this is the binding Tegra uses.
Still, it doesn't belong in the NAND binding. Maybe a future chip wants to use this NAND binding but a different GPIO binding. If nothing else, people tend to copy-and-paste such descriptions. We've still got people adding bindings for Freescale devices saying interrupts are encoded as a pair of cells, even though the interrupt controller now uses four cells per interrupt.
Quoted 3 lines
OK I see - are you are saying that we should just say something like:
"nvidia,wp-gpios : GPIO of write-protect line, as defined by gpio bindings"
Yes. If there were more than one GPIO line, you'd specify which one is which, similar to reg and interrupts.
-Scott
A message that is not in the archive (sent off-list or not yet received): 1334688614-4977-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org
PATCH v3 5/7 tegra: fdt: Add NAND definitions to fdt
Add a flash node to handle the NAND, including memory timings and page / block size information.
---
Changes in v2:
- Update NAND binding to add "nvidia," prefix
Changes in v3:
- Add reg property for unit address (should be used for chip select)
- Update fdt binding to make everything Nvidia-specific
board/nvidia/dts/tegra2-seaboard.dts | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-)
board/nvidia/dts/tegra2-seaboard.dts +16 -0
@@ -126,4 +126,20 @@ 0x00000000 0x00000000 0x00000000 0x00000000 >; }; }; + + nand-controller@70008000 { + nvidia,wp-gpios = <&gpio 59 0>; /* PH3 */ + nvidia,width = <8>; + nvidia,timing = <26 100 20 80 20 10 12 10 70>; + nand@0 { + reg = <0>; + compatible = "hynix,hy27uf4g2b", "nand-flash"; + nvidia,page-data-bytes = <2048>; + nvidia,tag-ecc-bytes = <4>; + nvidia,tag-bytes = <20>; + nvidia,data-ecc-bytes = <36>; + nvidia,skipped-spare-bytes = <4>; + nvidia,page-spare-bytes = <64>; + }; + }; };
Signature · 1 line
1.7.7.3
PATCH v3 6/7 tegra: nand: Add Tegra NAND driver
In reply to Simon GlassFrom: Jim Lin <[email protected]>
A device tree is used to configure the NAND, including memory timings and block/pages sizes.
If this node is not present or is disabled, then NAND will not be initialized.
---
Changes in v2:
- Added comment about the behaviour of the 'resp' register
- Call set_bus_width_page_size() at init to report errors earlier
- Change set_bus_width_page_size() to return an error when needed
- Change timing structure member to u32 to match device tree
- Check for supported bus width in board_nand_init()
- Fix tegra nand header file to remove BIT defines
- Implement a dummy nand_select_chip() instead of nand_hwcontro()
- Make nand_command() display an error on an unknown command
- Minor code tidy-ups in driver for style
- Move cache logic into a separate dma_prepare() function
- Remove CMD_TRANS_SIZE_BYTESx enum
- Remove space after casts
- Remove use of 'register' variables
- Rename struct nand_info to struct nand_drv to avoid nand_info_t confusion
- Support 4096 byte page devices, drop 1024 and 2048
- Tidy up nand_waitfor_cmd_completion() logic
- Update NAND binding to add "nvidia," prefix
- Use s32 for device tree integer values
Changes in v3:
- Update fdt binding to make everything Nvidia-specific
arch/arm/include/asm/arch-tegra2/tegra2.h | 1 + drivers/mtd/nand/Makefile | 1 + drivers/mtd/nand/tegra2_nand.c | 1095 +++++++++++++++++++++++++++++ drivers/mtd/nand/tegra2_nand.h | 257 +++++++ include/fdtdec.h | 1 + lib/fdtdec.c | 1 + 6 files changed, 1356 insertions(+), 0 deletions(-) create mode 100644 drivers/mtd/nand/tegra2_nand.c create mode 100644 drivers/mtd/nand/tegra2_nand.h
arch/arm/include/asm/arch-tegra2/tegra2.h +1 -0
@@ -39,6 +39,7 @@#define NV_PA_APB_UARTC_BASE (NV_PA_APB_MISC_BASE + 0x6200)#define NV_PA_APB_UARTD_BASE (NV_PA_APB_MISC_BASE + 0x6300)#define NV_PA_APB_UARTE_BASE (NV_PA_APB_MISC_BASE + 0x6400) +#define TEGRA2_NAND_BASE (NV_PA_APB_MISC_BASE + 0x8000)#define TEGRA2_SPI_BASE (NV_PA_APB_MISC_BASE + 0xC380)#define TEGRA2_PMC_BASE (NV_PA_APB_MISC_BASE + 0xE400)#define TEGRA2_FUSE_BASE (NV_PA_APB_MISC_BASE + 0xF800)
drivers/mtd/nand/Makefile +1 -0
@@ -61,6 +61,7 @@ COBJS-$(CONFIG_NAND_NOMADIK) += nomadik.o COBJS-$(CONFIG_NAND_S3C2410) += s3c2410_nand.o COBJS-$(CONFIG_NAND_S3C64XX) += s3c64xx.o COBJS-$(CONFIG_NAND_SPEAR) += spr_nand.o +COBJS-$(CONFIG_TEGRA2_NAND) += tegra2_nand.o COBJS-$(CONFIG_NAND_OMAP_GPMC) += omap_gpmc.o COBJS-$(CONFIG_NAND_PLAT) += nand_plat.o endif
drivers/mtd/nand/tegra2_nand.c new file +1095 -0
1,095 lines not on this page · raw message
drivers/mtd/nand/tegra2_nand.h new file +257 -0
257 lines not on this page · raw message
include/fdtdec.h +1 -0
@@ -62,6 +62,7 @@ enum fdt_compat_id {COMPAT_NVIDIA_TEGRA20_DVC ,/* Tegra2 dvc (really just i2c) */ COMPAT_NVIDIA_TEGRA20_EMC ,/* Tegra2 memory controller */ COMPAT_NVIDIA_TEGRA20_EMC_TABLE ,/* Tegra2 memory timing table */ +COMPAT_NVIDIA_TEGRA20_NAND ,/* Tegra2 NAND controller */ COMPAT_COUNT, };
lib/fdtdec.c +1 -0
@@ -42,6 +42,7 @@ static const char * const compat_names[COMPAT_COUNT] = {COMPAT (NVIDIA_TEGRA20_DVC ,"nvidia,tegra20-i2c-dvc" ),COMPAT (NVIDIA_TEGRA20_EMC ,"nvidia,tegra20-emc" ),COMPAT (NVIDIA_TEGRA20_EMC_TABLE ,"nvidia,tegra20-emc-table" ), + COMPAT(NVIDIA_TEGRA20_NAND, "nvidia,tegra20-nand"), };const char *fdtdec_get_compatible (enum fdt_compat_id id)
Signature · 1 line
1.7.7.3
PATCH v3 6/7 tegra: nand: Add Tegra NAND driver
Quoted 1 line · Simon Glass
+#define DEBUG
Did you mean to leave this in?
Quoted 8 lines
+/**
+ * [DEFAULT] Read one byte from the chip
+ *
+ * @param mtd MTD device structure
+ * @return data byte
+ *
+ * Default read function for 8bit bus-width
+ */
This isn't the default read function, it's the tegra read function.
Quoted 6 lines
drivers/mtd/nand/tegra2_nand.c new file +6
-0+static uint8_t read_byte (struct mtd_info *mtd) +{ +struct nand_chip *chip = mtd->priv; +u32 dword_read; +struct nand_drv *info; +
drivers/mtd/nand/tegra2_nand.c line 200
Quoted 10 lines
drivers/mtd/nand/tegra2_nand.c new file +10
-0+ info = (struct nand_drv *)chip->priv; +if (info->pio_byte_index >3 ) +return 0 ; + +/* We can read this data multiple times and get the same word */ + dword_read =readl (&info->reg->resp); + dword_read = dword_read >> (8 * info->pio_byte_index); + info->pio_byte_index++; +return (uint8_t )dword_read; +}
So you only read up to 4 bytes via this method? If this is really all that's ever needed, please add a comment to that effect.
Quoted 9 lines
drivers/mtd/nand/tegra2_nand.c new file +9
-0+/** +* [DEFAULT] Write buffer to chip +* +* @param mtd MTD device structure +* @param buf data buffer +* @param len number of bytes to write +* +* Default write function for 8bit bus-width +*/
drivers/mtd/nand/tegra2_nand.c line 220
Quoted 10 lines
drivers/mtd/nand/tegra2_nand.c new file +10
-0+static void write_buf (struct mtd_info *mtd,const uint8_t *buf,int len) +{ +int i, j, l; +struct nand_chip *chip = mtd->priv; +struct nand_drv *info; + + info = (struct nand_drv *)chip->priv; + +for (i =0 ; i < len /4 ; i++) { + l = ((int *)buf)[i];
If you're assuming the buffer is 32-bit aligned, comment it. Ideally these assumptions should be stated in the interface itself...
Should also comment that there's an endian dependency here.
drivers/mtd/nand/tegra2_nand.c line 228
Quoted 8 lines
drivers/mtd/nand/tegra2_nand.c new file +8
-0+writel (l, &info->reg->resp); +writel (CMD_GO |CMD_PIO |CMD_TX | + ((4 -1 ) <<CMD_TRANS_SIZE_SHIFT ) + |CMD_A_VALID |CMD_CE0 , + &info->reg->command); + +if (!nand_waitfor_cmd_completion (info->reg)) +printf ("Command timeout during write_buf\n" );
You need to wait for completion every 4 bytes? Where is the DMA?
Quoted 3 lines
drivers/mtd/nand/tegra2_nand.c new file +3
-0+case NAND_CMD_RNDOUT : +printf ("%s: Unsupported RNDOUT command\n" , __func__); +return ;
[snip]
drivers/mtd/nand/tegra2_nand.c line 439
Quoted 4 lines
drivers/mtd/nand/tegra2_nand.c new file +4
-0+default : +printf ("%s: Unsupported command %d\n" , __func__, command); +return ; + }
Doesn't the print in the default case already handle RNDOUT?
Quoted 12 lines
drivers/mtd/nand/tegra2_nand.c new file +12
-0+if ((reg_val &DEC_STATUS_A_ECC_FAIL ) && databuf) { + reg_val =readl (®->bch_dec_status_buf); +/* +* If uncorrectable error occurs on data area, then see whether +* they are all FF. If all are FF, it's a blank page. +* Not error. +*/ +if ((reg_val &BCH_DEC_STATUS_FAIL_SEC_FLAG_MASK ) && + !blank_check (databuf, a_len)) + return_val |=ECC_DATA_ERROR ; + } +
drivers/mtd/nand/tegra2_nand.c line 509
Quoted 10 lines
drivers/mtd/nand/tegra2_nand.c new file +10
-0+if ((reg_val &DEC_STATUS_B_ECC_FAIL ) && oobbuf) { + reg_val =readl (®->bch_dec_status_buf); +/* +* If uncorrectable error occurs on tag area, then see whether +* they are all FF. If all are FF, it's a blank page. +* Not error. +*/ +if ((reg_val &BCH_DEC_STATUS_FAIL_TAG_MASK ) && + !blank_check (oobbuf, b_len)) + return_val |=ECC_TAG_ERROR ;
Please don't line up the continuation line with the if-body.
What is the difference between an "A" fail and a "B" fail? Do you really want to do the blank_check twice?
Quoted 7 lines
drivers/mtd/nand/tegra2_nand.c new file +6
-0+/* Need to be 4-byte aligned */ + tag_ptr = (char *)&tag_buf; + +stop_command (info->reg); + +writel ((1 << chip->page_shift) -1 , &info->reg->dma_cfg_a);
drivers/mtd/nand/tegra2_nand.c line 629
Quoted 10 lines
drivers/mtd/nand/tegra2_nand.c new file +10
-0+writel ((u32 )buf, &info->reg->data_block_ptr); + +if (with_ecc) { +writel ((u32 )tag_ptr, &info->reg->tag_ptr); +if (is_writing) +memcpy (tag_ptr, chip->oob_poi + free->offset, + config->tag_bytes + + config->tag_ecc_bytes); + }else +writel ((u32 )chip->oob_poi, &info->reg->tag_ptr);
Should use virt_to_phys(), even if it currently makes no difference on this platform.
Quoted 1 line
+int
fdt_decode_nand(const void *blob, int node, struct fdt_nand *config)
Make this static.
drivers/mtd/nand/tegra2_nand.c line 1036
Quoted 7 lines
drivers/mtd/nand/tegra2_nand.c new file +7
-0+/** +* Board-specific NAND initialization +* +* @param nand nand chip info structure +* @return 0, after initialized, -1 on error +*/ +int board_nand_init (struct nand_chip *nand)
Please consider using CONFIG_SYS_NAND_SELF_INIT.
Quoted 32 lines
drivers/mtd/nand/tegra2_nand.h new file +26
-0@@ -0,0 +1,257 @@ +/* +* (C) Copyright 2011 NVIDIA Corporation <www.nvidia.com> +* +* See file CREDITS for list of people who contributed to this +* project. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* 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. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, +* MA 02111-1307 USA +*/ + +/* register offset */ +#define COMMAND_0 0x00 +#define CMD_GO (1 << 31) +#define CMD_CLE (1 << 30)
drivers/mtd/nand/tegra2_nand.h line 36
Quoted 10 lines
drivers/mtd/nand/tegra2_nand.h new file +10
-0+#define CMD_ALE (1 << 29) +#define CMD_PIO (1 << 28) +#define CMD_TX (1 << 27) +#define CMD_RX (1 << 26) +#define CMD_SEC_CMD (1 << 25) +#define CMD_AFT_DAT_MASK (1 << 24) +#define CMD_AFT_DAT_DISABLE 0 +#define CMD_AFT_DAT_ENABLE (1 << 24) +#define CMD_TRANS_SIZE_SHIFT 20 +#define CMD_TRANS_SIZE_PAGE 8
Please use proper namespacing on symbols defined in headers.
-Scott
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v3 6/7 tegra: nand: Add Tegra NAND driver
Quoted 45 lines · Jim Lin
Quoted 32 lines
drivers/mtd/nand/tegra2_nand.h new file +26
-0@@ -0,0 +1,257 @@ +/* +* (C) Copyright 2011 NVIDIA Corporation <www.nvidia.com> +* +* See file CREDITS for list of people who contributed to this +* project. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* 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. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, +* MA 02111-1307 USA +*/ + +/* register offset */ +#define COMMAND_0 0x00 +#define CMD_GO (1 << 31) +#define CMD_CLE (1 << 30)drivers/mtd/nand/tegra2_nand.h line 36
Quoted 10 lines
drivers/mtd/nand/tegra2_nand.h new file +10
-0+#define CMD_ALE (1 << 29) +#define CMD_PIO (1 << 28) +#define CMD_TX (1 << 27) +#define CMD_RX (1 << 26) +#define CMD_SEC_CMD (1 << 25) +#define CMD_AFT_DAT_MASK (1 << 24) +#define CMD_AFT_DAT_DISABLE 0 +#define CMD_AFT_DAT_ENABLE (1 << 24) +#define CMD_TRANS_SIZE_SHIFT 20 +#define CMD_TRANS_SIZE_PAGE 8Please use proper namespacing on symbols defined in headers.
Quoted 3 lines
[Jim] Scott, I don't know what you meant. Could you give me an example?
Thanks.
The names likeAFT_DAT_MASK,TRANS_SIZE_SHIFT, andTRANS_SIZE_PAGEcome from field names of register in data sheet.
Names in your data sheet are presumably unique within that chip, but not within U-Boot as a whole. Names like CMD_CLE, CMD_TX, etc. are particularly likely to conflict (at least, if at least one other driver were similarly loose with its naming).
Prefix these with TEGRA_ or TEGRA_NAND_
-Scott
PATCH v3 6/7 tegra: nand: Add Tegra NAND driver
Hi Scott,
Quoted 51 lines · Scott Wood
Quoted 1 line · Jim Lin
Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/mtd/nand/tegra2_nand.hQuoted 45 lines
Quoted 31 lines
new file mode 100644
index 0000000..7e74be7drivers/mtd/nand/tegra2_nand.h new file +26
-0@@ -0,0 +1,257 @@ +/* +* (C) Copyright 2011 NVIDIA Corporation <www.nvidia.com> +* +* See file CREDITS for list of people who contributed to this +* project. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* 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. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, +* MA 02111-1307 USA +*/ + +/* register offset */ +#define COMMAND_0 0x00 +#define CMD_GO (1 << 31) +#define CMD_CLE (1 << 30)drivers/mtd/nand/tegra2_nand.h line 36
Quoted 10 lines
drivers/mtd/nand/tegra2_nand.h new file +10
-0+#define CMD_ALE (1 << 29) +#define CMD_PIO (1 << 28) +#define CMD_TX (1 << 27) +#define CMD_RX (1 << 26) +#define CMD_SEC_CMD (1 << 25) +#define CMD_AFT_DAT_MASK (1 << 24) +#define CMD_AFT_DAT_DISABLE 0 +#define CMD_AFT_DAT_ENABLE (1 << 24) +#define CMD_TRANS_SIZE_SHIFT 20 +#define CMD_TRANS_SIZE_PAGE 8Please use proper namespacing on symbols defined in headers.
Quoted 3 lines
[Jim] Scott, I don't know what you meant. Could you give me an example?
Thanks.
The names likeAFT_DAT_MASK,TRANS_SIZE_SHIFT, andTRANS_SIZE_PAGEcome
Quoted 9 lines
from field names of register in data sheet.
Names in your data sheet are presumably unique within that chip, but not within U-Boot as a whole. Names like
CMD_CLE,CMD_TX, etc. are particularly likely to conflict (at least, if at least one other driver were similarly loose with its naming).Prefix these with
TEGRA_orTEGRA_NAND_
I'm not thrilled with this idea. It adds a lot of needless boilerplate to the code IMO.
This header can only be included by the tegra NAND driver after all. Please can you reconsider this?
Quoted 4 lines
-Scott
Regards,
Simon
PATCH v3 6/7 tegra: nand: Add Tegra NAND driver
Quoted 65 lines · Simon Glass
Hi Scott,
On Mon, May 21, 2012 at 8:47 AM, Scott Wood <[email protected] <mailto:[email protected]>> wrote:
On 05/21/2012 05:07 AM, Jim Lin wrote:
>> diff --gita/drivers/mtd/nand/tegra2_nand.hb/drivers/mtd/nand/tegra2_nand.h
>> new file mode 100644
>> index 0000000..7e74be7
>> ---/dev/null
>> +++b/drivers/mtd/nand/tegra2_nand.h
>> @@ -0,0 +1,257 @@
>> +/*
>> + * (C) Copyright 2011 NVIDIA Corporation <www.nvidia.com
<http://www.nvidia.com>>
>> + *
>> + * See file CREDITS for list of people who contributed to this >> + * project.
>> + *
>> + * This program is free software; you can redistribute it and/or >> + * modify it under the terms of the GNU General Public License as >> + * published by the Free Software Foundation; either version 2 of >> + * the License, or (at your option) any later version. >> + *
>> + * 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.
>> + *
>> + * You should have received a copy of the GNU General Public License >> + * along with this program; if not, write to the Free Software >> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, >> + * MA 02111-1307 USA
>> + */
>> +
>> +/* register offset */
>> +#defineCOMMAND_00x00
>> +#defineCMD_GO(1 << 31)
>> +#defineCMD_CLE(1 << 30)
>> +#defineCMD_ALE(1 << 29)
>> +#defineCMD_PIO(1 << 28)
>> +#defineCMD_TX(1 << 27)
>> +#defineCMD_RX(1 << 26)
>> +#defineCMD_SEC_CMD(1 << 25)
>> +#defineCMD_AFT_DAT_MASK(1 << 24)
>> +#defineCMD_AFT_DAT_DISABLE0
>> +#defineCMD_AFT_DAT_ENABLE(1 << 24)
>> +#defineCMD_TRANS_SIZE_SHIFT20
>> +#defineCMD_TRANS_SIZE_PAGE8
>
> Please use proper namespacing on symbols defined in headers.>
> [Jim] Scott, I don't know what you meant. Could you give me an example?
> Thanks.
> The names likeAFT_DAT_MASK,TRANS_SIZE_SHIFT, andTRANS_SIZE_PAGEcome from field names of register in data sheet.Names in your data sheet are presumably unique within that chip, but not within U-Boot as a whole. Names like
CMD_CLE,CMD_TX, etc. are particularly likely to conflict (at least, if at least one other driver were similarly loose with its naming).
Quoted 8 lines
Prefix these with
TEGRA_orTEGRA_NAND_I'm not thrilled with this idea. It adds a lot of needless boilerplate to the code IMO.
This header can only be included by the tegra NAND driver after all. Please can you reconsider this?
If it can only be included in the NAND driver, why does it need to be in a header at all?
-Scott
PATCH v3 6/7 tegra: nand: Add Tegra NAND driver
Hi Scott,
Quoted 73 lines · Scott Wood
Quoted 18 lines · Simon Glass
Hi Scott,
On Mon, May 21, 2012 at 8:47 AM, Scott Wood <[email protected] <mailto:[email protected]>> wrote:
On 05/21/2012 05:07 AM, Jim Lin wrote: >> diff --git a/drivers/mtd/nand/tegra2_nand.h b/drivers/mtd/nand/tegra2_nand.h >> new file mode 100644 >> index 0000000..7e74be7 >> --- /dev/null >> +++ b/drivers/mtd/nand/tegra2_nand.h >> @@ -0,0 +1,257 @@ >> +/* >> + * (C) Copyright 2011 NVIDIA Corporation <www.nvidia.com <http://www.nvidia.com>> >> + * >> + * See file CREDITS for list of people who contributed to thisQuoted 8 lines
>> + * project. >> + * >> + * This program is free software; you can redistribute it and/or >> + * modify it under the terms of the GNU General Public License as >> + * published by the Free Software Foundation; either version 2 of >> + * the License, or (at your option) any later version. >> + * >> + * This program is distributed in the hope that it will beuseful,
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
+ * 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.
+ *
+ * You should have received a copy of the GNU General PublicLicense
Quoted 23 lines
Quoted 23 lines
Quoted 9 lines
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */drivers/mtd/nand/tegra2_nand.h new file +5
-0+ +/* register offset */ +#define COMMAND_0 0x00 +#define CMD_GO (1 << 31) +#define CMD_CLE (1 << 30)drivers/mtd/nand/tegra2_nand.h line 36
Quoted 10 lines
drivers/mtd/nand/tegra2_nand.h new file +10
-0+#define CMD_ALE (1 << 29) +#define CMD_PIO (1 << 28) +#define CMD_TX (1 << 27) +#define CMD_RX (1 << 26) +#define CMD_SEC_CMD (1 << 25) +#define CMD_AFT_DAT_MASK (1 << 24) +#define CMD_AFT_DAT_DISABLE 0 +#define CMD_AFT_DAT_ENABLE (1 << 24) +#define CMD_TRANS_SIZE_SHIFT 20 +#define CMD_TRANS_SIZE_PAGE 8Please use proper namespacing on symbols defined in headers.
Quoted 7 lines
Quoted 1 line
[Jim] Scott, I don't know what you meant. Could you give me an
example?
> Thanks.
> The names likeAFT_DAT_MASK,TRANS_SIZE_SHIFT, andTRANS_SIZE_PAGEcome from field names of register in data sheet.Names in your data sheet are presumably unique within that chip, but
not
Quoted 2 lines
within U-Boot as a whole. Names like
CMD_CLE,CMD_TX, etc. are particularly likely to conflict (at least, if at least one otherdriver
Quoted 5 lines
were similarly loose with its naming).
Prefix these with
TEGRA_orTEGRA_NAND_
Quoted 9 lines
Quoted 5 lines
I'm not thrilled with this idea. It adds a lot of needless boilerplate to the code IMO.
This header can only be included by the tegra NAND driver after all. Please can you reconsider this?
If it can only be included in the NAND driver, why does it need to be in a header at all?
It doesn't - it's just a convenient way to separate out the definitions from the rest of the code. Quite a lot of drivers in U-Boot have private .h files.
Quoted 4 lines
-Scott
Regards,
Simon
PATCH v3 6/7 tegra: nand: Add Tegra NAND driver
In reply to Scott WoodQuoted 69 lines · Scott Wood
Quoted 68 lines · Simon Glass
Hi Scott,
On Mon, May 21, 2012 at 8:47 AM, Scott Wood <[email protected] <mailto:[email protected]>> wrote:
On 05/21/2012 05:07 AM, Jim Lin wrote:
>> diff --gita/drivers/mtd/nand/tegra2_nand.hb/drivers/mtd/nand/tegra2_nand.h
>> new file mode 100644
>> index 0000000..7e74be7
>> ---/dev/null
>> +++b/drivers/mtd/nand/tegra2_nand.h
>> @@ -0,0 +1,257 @@
>> +/*
>> + * (C) Copyright 2011 NVIDIA Corporation <www.nvidia.com
<http://www.nvidia.com>>
>> + *
>> + * See file CREDITS for list of people who contributed to this >> + * project.
>> + *
>> + * This program is free software; you can redistribute it and/or >> + * modify it under the terms of the GNU General Public License as >> + * published by the Free Software Foundation; either version 2 of >> + * the License, or (at your option) any later version. >> + *
>> + * 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.
>> + *
>> + * You should have received a copy of the GNU General Public License >> + * along with this program; if not, write to the Free Software >> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, >> + * MA 02111-1307 USA
>> + */
>> +
>> +/* register offset */
>> +#defineCOMMAND_00x00
>> +#defineCMD_GO(1 << 31)
>> +#defineCMD_CLE(1 << 30)
>> +#defineCMD_ALE(1 << 29)
>> +#defineCMD_PIO(1 << 28)
>> +#defineCMD_TX(1 << 27)
>> +#defineCMD_RX(1 << 26)
>> +#defineCMD_SEC_CMD(1 << 25)
>> +#defineCMD_AFT_DAT_MASK(1 << 24)
>> +#defineCMD_AFT_DAT_DISABLE0
>> +#defineCMD_AFT_DAT_ENABLE(1 << 24)
>> +#defineCMD_TRANS_SIZE_SHIFT20
>> +#defineCMD_TRANS_SIZE_PAGE8
>
> Please use proper namespacing on symbols defined in headers.>
> [Jim] Scott, I don't know what you meant. Could you give me an example?
> Thanks.
> The names likeAFT_DAT_MASK,TRANS_SIZE_SHIFT, andTRANS_SIZE_PAGEcome from field names of register in data sheet.Names in your data sheet are presumably unique within that chip, but not within U-Boot as a whole. Names like
CMD_CLE,CMD_TX, etc. are particularly likely to conflict (at least, if at least one other driver were similarly loose with its naming).Prefix these with
TEGRA_orTEGRA_NAND_
Quoted 8 lines
Quoted 5 lines
I'm not thrilled with this idea. It adds a lot of needless boilerplate to the code IMO.
This header can only be included by the tegra NAND driver after all. Please can you reconsider this?
If it can only be included in the NAND driver, why does it need to be in a header at all?
That said, I see it's in drivers/mtd/nand/ and not include/, so if you really want to structure it that way, it's OK with me.
-Scott
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v3 6/7 tegra: nand: Add Tegra NAND driver
Quoted 21 lines · Jim Lin
Quoted 8 lines
-----Original Message-----
From: Scott Wood [mailto:scottwood at freescale.com]
Sent: Thursday, April 26, 2012 6:17 AM
To: Simon Glass
Cc: U-Boot Mailing List; Tom Warren; Stephen Warren; Jim Lin; Stephen Warren
Subject: Re: [PATCH v3 6/7] tegra: nand: Add Tegra NAND driverOn 04/17/2012 01:50 PM, Simon Glass wrote:
Quoted 13 lines
drivers/mtd/nand/tegra2_nand.c line 220
Quoted 10 lines
drivers/mtd/nand/tegra2_nand.c new file +10
-0+static void write_buf (struct mtd_info *mtd,const uint8_t *buf,int len) +{ +int i, j, l; +struct nand_chip *chip = mtd->priv; +struct nand_drv *info; + + info = (struct nand_drv *)chip->priv; + +for (i =0 ; i < len /4 ; i++) { + l = ((int *)buf)[i];If you're assuming the buffer is 32-bit aligned, comment it. Ideally these assumptions should be stated in the interface itself...
Quoted 2 lines
This doesn't mean that buf needs to be 32-bit aligned. It only says each write is 32-bit.
OK, didn't realize modern ARM could deal with unaligned accesses.
Quoted 2 lines
Quoted 1 line
Should also comment that there's an endian dependency here.
What do you mean? Could you explain more or have an example?
You load a value using host endianness, and store it using a little endian accessor. This would be fine if it represented a real 32-bit integer, but it's really a sequence of bytes that should not be swapped.
It's not a big deal if you don't see the driver ever being used with a big endian host, but a comment would be nice.
Quoted 10 lines
Quoted 9 lines
drivers/mtd/nand/tegra2_nand.c line 1036
Quoted 7 lines
drivers/mtd/nand/tegra2_nand.c new file +7
-0+/** +* Board-specific NAND initialization +* +* @param nand nand chip info structure +* @return 0, after initialized, -1 on error +*/ +int board_nand_init (struct nand_chip *nand)Please consider using
CONFIG_SYS_NAND_SELF_INIT.So far I don't see the demand.
I'd like to see the old way go away eventually.
Quoted 6 lines
-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
Please try to get rid of this. This is a public mailing list.
-Scott
PATCH v3 6/7 tegra: nand: Add Tegra NAND driver
Quoted 22 lines · Scott Wood
Quoted 21 lines · Jim Lin
Quoted 21 lines
-----Original Message-----
From: Scott Wood [mailto:scottwood at freescale.com]
Sent: Thursday, April 26, 2012 6:17 AM
To: Simon Glass
Cc: U-Boot Mailing List; Tom Warren; Stephen Warren; Jim Lin; Stephen Warren
Subject: Re: [PATCH v3 6/7] tegra: nand: Add Tegra NAND driverdrivers/mtd/nand/tegra2_nand.c line 220
Quoted 10 lines · Simon Glass
drivers/mtd/nand/tegra2_nand.c new file +10
-0+static void write_buf (struct mtd_info *mtd,const uint8_t *buf,int len) +{ +int i, j, l; +struct nand_chip *chip = mtd->priv; +struct nand_drv *info; + + info = (struct nand_drv *)chip->priv; + +for (i =0 ; i < len /4 ; i++) { + l = ((int *)buf)[i];If you're assuming the buffer is 32-bit aligned, comment it. Ideally these assumptions should be stated in the interface itself...
Quoted 4 lines
Quoted 2 lines
This doesn't mean that buf needs to be 32-bit aligned. It only says each write is 32-bit.
OK, didn't realize modern ARM could deal with unaligned accesses.
I'd like to see some more research here; I know that recent printk changes in the ARM kernel caused unaligned accesses which in turn caused significant problems (including on Tegra). This might only have been for 64-bit accesses, so perhaps 32-bit accesses don't have an issue, but if you could confirm this Jim, that'd be great.
PATCH v3 7/7 tegra: Enable NAND on Seaboard
In reply to Simon GlassThis enables NAND support for the Seaboard.
---
include/configs/seaboard.h | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)
include/configs/seaboard.h +9 -0
@@ -105,4 +105,13 @@#define CONFIG_USB_STORAGE #define CONFIG_CMD_USB +/* NAND support */ +#define CONFIG_CMD_NAND +#define CONFIG_TEGRA2_NAND + +/* Max number of NAND devices */ +#define CONFIG_SYS_MAX_NAND_DEVICE 1 + +/* Somewhat oddly, the NAND base address must be a config option */ +#define CONFIG_SYS_NAND_BASE TEGRA2_NAND_BASE#endif /* __CONFIG_H */
Signature · 1 line
1.7.7.3
v3 cover tegra: Add NAND flash support
In reply to Simon GlassQuoted 9 lines · Simon Glass
This series adds NAND flash support to Tegra and enables it on Seaboard.
Included here is a proposed device tree binding with most of the properties private to "nvidia,". The binding includes information about the NAND controller as well as the connected NAND device. The Seaboard has a Hynix HY27UF4G2B.
The driver supports ECC-based access and uses DMA and NAND acceleration features of the Tegra SOC to provide access at reasonable speed.
I've been working on getting a similar driver up and running in the Linux kernel. While I can successfully read data from the flash (my hardware has the same Hynix chip) I've run into a bit of a problem with the partition tables.
When I use nvflash with a given configuration file to write the BCT, the PT and U-Boot to the NAND, I noticed that the partitioning is not quite as it should be. For example I use this:
[device] type=nand instance=0 [partition] name=BCT id=2 type=boot_config_table allocation_policy=sequential filesystem_type=basic size=262144 file_system_attribute=0 partition_attribute=0 allocation_attribute=8 percent_reserved=0 [partition] name=PT id=3 type=partition_table allocation_policy=sequential filesystem_type=basic size=262144 file_system_attribute=0 partition_attribute=0 allocation_attribute=8 percent_reserved=0 [partition] name=EBT id=4 type=bootloader allocation_policy=sequential start_location=2097152 filesystem_type=basic size=524288 file_system_attribute=0 partition_attribute=0 allocation_attribute=8 percent_reserved=0 filename=u-boot.bin
That however doesn't produce the expected results. Looking at the UART output produced by the bootstrap fastboot.bin it looks like it's actually allocating more blocks than necessary.
On the Hynix chip, 256K is 2 blocks, but fastboot.bin seems to want to allocate more:
Erase Partition part-id=3: Start=6,End=11 Format partition BCT
Erase Partition part-id=2: Start=0,End=5 Format partition EBT
Erase Partition part-id=4: Start=12,End=19
On another board things are even worse. It has a bad block, which causes the bootstrap to skip that when allocating the partitions:
Erase Partition part-id=3: Start=6,End=12 Factory Bad block: Chip0 Block=8 Runtime Bad block: Chip0 Block=8,RTB=0xed Format partition BCT
Erase Partition part-id=2: Start=0,End=5 Format partition EBT
Erase Partition part-id=4: Start=13,End=20
Both of these issues lead to the problem that if I encode the same partition information in the DT, the kernel's representation will not match what the nvflash tool did.
There seems to be more output during bootstrap that indicates that nvflash does some remapping from logical blocks to physical blocks:
PartId 2: LB[0 2] PB[0 6] IL1 LS[0 128] Factory Bad block: Chip0 Block=8 Runtime Bad block: Chip0 Block=8,RTB=0xed Chip0 Block=8 bad PartId 3: LB[2 2] PB[6 7] IL1 LS[128 128] PartId 4: LB[4 4] PB[13 8] IL1 LS[256 256]
If we can get at this information (maybe it is stored within the partition table partition?), then it should be possible to use it to automatically build a correct partition table for both U-Boot and the kernel.
Anyway, I was wondering how you solved this problem. Or maybe you didn't have the same problem in the first place?
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120426/af5a781d/attachment.pgp>
v3 cover tegra: Add NAND flash support
Quoted 15 lines · Thierry Reding
Quoted 9 lines · Simon Glass
This series adds NAND flash support to Tegra and enables it on Seaboard.
Included here is a proposed device tree binding with most of the properties private to "nvidia,". The binding includes information about the NAND controller as well as the connected NAND device. The Seaboard has a Hynix HY27UF4G2B.
The driver supports ECC-based access and uses DMA and NAND acceleration features of the Tegra SOC to provide access at reasonable speed.
I've been working on getting a similar driver up and running in the Linux kernel. While I can successfully read data from the flash (my hardware has the same Hynix chip) I've run into a bit of a problem with the partition tables.
...
Quoted 3 lines
That however doesn't produce the expected results. Looking at the UART output produced by the bootstrap fastboot.bin it looks like it's actually allocating more blocks than necessary.
...
Quoted 3 lines
Both of these issues lead to the problem that if I encode the same partition information in the DT, the kernel's representation will not match what the nvflash tool did.
Yes, I'd recommend not putting information in DT that can be easily extracted from the partition table on the device itself.
Out of curiosity though, why do you even need the Tegra PT support; I'd assume in a situation like this, you'd just replace the whole flash with BCT, PT, EBT at once rather than attempting to update just parts of it (since the BCT must be updated when writing a new EBT content anyway), so the existing partition layout wouldn't matter, and the whole device could just be treated raw.
v3 cover tegra: Add NAND flash support
Quoted 2 lines · Stephen Warren
Yes, I'd recommend not putting information in DT that can be easily extracted from the partition table on the device itself.
The problem is that neither the format of the BCT nor that of the PT is documented anywhere. It seems like the BCT contains a reference to where in the flash the PT starts but I wasn't able to find out where.
Ideally I think we could probably create a separate partition parser, similar to ofpart, that takes the information directly from the PT. Or alternatively it could be extracted manually at probe time to create the partitions in Linux.
Quoted 6 lines
Out of curiosity though, why do you even need the Tegra PT support; I'd assume in a situation like this, you'd just replace the whole flash with BCT, PT, EBT at once rather than attempting to update just parts of it (since the BCT must be updated when writing a new EBT content anyway), so the existing partition layout wouldn't matter, and the whole device could just be treated raw.
Actually I'd need more than those three partitions. I need at least five, optimally six. In addition to BCT, PT and EBT I need one for the uImage and the root filesystem. Those can probably go onto the same partition with JFFS2 or YAFFS. But a fifth will be required to store some other data. If all else fails it could probably be done via the fourth partition as well, but that'd be suboptimal.
As I said before, the biggest problem with updating the whole content is that there's no documentation about either the BCT or the PT. There's cbootimage on gitorious that has some information about the BCT, but it's incomplete.
For production use it is also impractical to bootstrap using nvflash, boot the system to Linux and create all the partitions as well. If that turns out to be the only option, then better documentation is certainly required. In that case I think it may be possible to not use the PT because the partition layout will actually be deterministic and it can be encoded with DT.
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120426/0be6ba2a/attachment.pgp>
v3 cover tegra: Add NAND flash support
Quoted 7 lines · Thierry Reding
Quoted 2 lines · Stephen Warren
Yes, I'd recommend not putting information in DT that can be easily extracted from the partition table on the device itself.
The problem is that neither the format of the BCT nor that of the PT is documented anywhere. It seems like the BCT contains a reference to where in the flash the PT starts but I wasn't able to find out where.
I have filed an internal bug to request this information be added to the TRM. We will see what happens.
Quoted 3 lines
Actually I'd need more than those three partitions. I need at least five, optimally six. In addition to BCT, PT and EBT I need one for the uImage and the root filesystem.
Oh I see; you're mingling the boot flash and filesystem into a single memory device. It simpler (but I imagine more costly) not too:-)
Quoted 3 lines
As I said before, the biggest problem with updating the whole content is that there's no documentation about either the BCT or the PT. There's cbootimage on gitorious that has some information about the BCT, but it's incomplete.
Out of curiosity, what's missing from cbootimage?
v3 cover tegra: Add NAND flash support
Quoted 7 lines · Stephen Warren
Quoted 3 lines · Thierry Reding
The problem is that neither the format of the BCT nor that of the PT is documented anywhere. It seems like the BCT contains a reference to where in the flash the PT starts but I wasn't able to find out where.
I have filed an internal bug to request this information be added to the TRM. We will see what happens.
I have filed a similar bug (#976261 in the NVIDIA bug tracker) and Vincent has been informed, so that may help.
Quoted 6 lines
Quoted 3 lines
Actually I'd need more than those three partitions. I need at least five, optimally six. In addition to BCT, PT and EBT I need one for the uImage and the root filesystem.
Oh I see; you're mingling the boot flash and filesystem into a single memory device. It simpler (but I imagine more costly) not too:-)
Yes, it's all about the money. =) On a more serious note it makes a lot of sense. Firstly we want to use the MMC/SD slot for user storage on Plutux and therefore need to have the OS on internal storage (i.e. NAND). And secondly we build a very minimalistic distribution in-house it fits without a problem.
Quoted 5 lines
Quoted 3 lines
As I said before, the biggest problem with updating the whole content is that there's no documentation about either the BCT or the PT. There's cbootimage on gitorious that has some information about the BCT, but it's incomplete.
Out of curiosity, what's missing from cbootimage?
It's missing support for PT. That may not be necessary in a setup where we initialize the NAND from Linux user space, though, so maybe it would be enough.
One thing I just remembered which may be a little problem is that currently our boards need to use the L4T binaries for OpenGL ES support, which means they need to run a Chromium kernel and that sadly doesn't properly boot from a mainline U-Boot but requires a setup where we use quickboot as first stage and U-Boot as a second stage bootloader. I haven't had time to investigate this further, though. But having this kind of setup complicates the NAND setup from user space further.
The long term plan was to incrementally move to a mainline system by first replacing the QuickBoot/U-Boot combo that we use now with a mainline U-Boot. Most of the pieces for that are now in place. I'm not sure if the SMSC95xx is already supported by U-Boot (we need it to program the MAC address) during bootstrap. Subsequently we were planning to move to a mainline kernel, which is obviously even longer term because it requires the DRM driver to be merged along with an updated user space to take advantage of it.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120427/aae59824/attachment.pgp>
v3 cover tegra: Add NAND flash support
Quoted 5 lines · Thierry Reding
Quoted 4 lines · Stephen Warren
Quoted 3 lines · Thierry Reding
The problem is that neither the format of the BCT nor that of the PT is documented anywhere. It seems like the BCT contains a reference to where in the flash the PT starts but I wasn't able to find out where.
...
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
As I said before, the biggest problem with updating the whole content is that there's no documentation about either the BCT or the PT. There's cbootimage on gitorious that has some information about the BCT, but it's incomplete.
Out of curiosity, what's missing from cbootimage?
It's missing support for PT. That may not be necessary in a setup where we initialize the NAND from Linux user space, though, so maybe it would be enough.
I don't believe the Tegra boot process actually /requires/ the PT even exist. IIRC, the boot ROM searches for the BCT, and the BCT contains a pointer to the bootloader (e.g. U-Boot), so it's only at a later stage in the game that anything would care about the PT. As such, worrying about the PT (or even including it) may be pointless.
I believe that TrimSlice's firmware recovery SD card images are created solely using cbootimage, and hence most likely have no PT, although obviously no additional partitions/file-systems on the media.
Perhaps you could define some hard-coded "MTD" partitions (e.g. the first 1MB and the rest), where the first 1MB contains BCT + U-Boot and the rest contains a regular MBR or GPT partition table. I /think/ there may even be a kernel command-line option to define the MTD partition layout?
Or, you could probably even get away with using a GPT for the entire NAND by placing just the secondary GPT at the end of the NAND, putting the BCT+U-Boot right at the start, and defining a GPT partition to protect/cover BCT+U-Boot. I vaguely recall trying this on some Tegra device, but I may be wrong.
Note that while most/all of the suggestions above probably work fine in practice, you should probably run them by your support contacts at NVIDIA in order to determine if we'd actually provide support for any of them and/or whether they negatively interact with the boot ROM in any way.
v3 cover tegra: Add NAND flash support
Quoted 17 lines · Stephen Warren
Quoted 5 lines · Thierry Reding
Quoted 4 lines · Stephen Warren
Quoted 3 lines · Thierry Reding
The problem is that neither the format of the BCT nor that of the PT is documented anywhere. It seems like the BCT contains a reference to where in the flash the PT starts but I wasn't able to find out where.
...
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
As I said before, the biggest problem with updating the whole content is that there's no documentation about either the BCT or the PT. There's cbootimage on gitorious that has some information about the BCT, but it's incomplete.
Out of curiosity, what's missing from cbootimage?
It's missing support for PT. That may not be necessary in a setup where we initialize the NAND from Linux user space, though, so maybe it would be enough.
Quoted 5 lines
I don't believe the Tegra boot process actually /requires/ the PT even exist. IIRC, the boot ROM searches for the BCT, and the BCT contains a pointer to the bootloader (e.g. U-Boot), so it's only at a later stage in the game that anything would care about the PT. As such, worrying about the PT (or even including it) may be pointless.
After digging into this some more, I get the same impression. PT seems entirely optional. Information about the bootloader seems to be stored within the BCT.
Quoted 3 lines
I believe that TrimSlice's firmware recovery SD card images are created solely using cbootimage, and hence most likely have no PT, although obviously no additional partitions/file-systems on the media.
It looks like cbootimage does have support for generating the bootloader bits, so maybe I can get this to work.
Quoted 10 lines
Perhaps you could define some hard-coded "MTD" partitions (e.g. the first 1MB and the rest), where the first 1MB contains BCT + U-Boot and the rest contains a regular MBR or GPT partition table. I /think/ there may even be a kernel command-line option to define the MTD partition layout?
Or, you could probably even get away with using a GPT for the entire NAND by placing just the secondary GPT at the end of the NAND, putting the BCT+U-Boot right at the start, and defining a GPT partition to protect/cover BCT+U-Boot. I vaguely recall trying this on some Tegra device, but I may be wrong.
I didn't even know that you could put an MBR or GPT onto NAND. I was under the impression that the only way to partition flash was via MTD partitions. I'll have to see if I can make such a setup work.
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120428/861049b9/attachment.pgp>