Under Linux Nand Flash driver instructions

 Registration driver_register

Nand Flash driver registered in s3c2410_nand_init () by driver_register () registered; by module_init (s3c2410_nand_init).

s3c2410_nand_driver driver, as follows:

static struct device_driver s3c2410_nand_driver = {

.name          = "s3c2410-nand",

.bus = & platform_bus_type, / * defined in drivers / base / platform.c in * /

.probe         = s3c2410_nand_probe,

.remove        = s3c2410_nand_remove,

};

 

Detection equipment probe

In Nand Flash driver registered in, probe method s3c2410_nand_probe (). S3c2410_nand_probe () and then call s3c24xx_nand_probe (). In this function, the * info private data structure as Nand Flash drive, and through dev_set_drvdata (dev, info) * info saved in the * device * driver_data the field. then (, "nand" dev) get Nand Flash clock resources clk_get, clk_use (info-> clk) clock count increased use of resources, clk_enable (info-> clk ) open field to fill in other resources * info, including:

  1. By request_mem_region () to register area Nand Flash application I / O memory address space region and through ioremap () maps it to the virtual address space.
    1. Call s3c2410_nand_inithw () to initialize Nand Flash controller. 3. storage space allocation device information mtd device.

4. Current mtd equipment, call s3c2410_nand_init_chip () to initialize.

The current mtd equipment, call nand_scan () detecting Nand Flash chip, nand_scan () function is defined in drivers / mtd / nand / nand_base.c the role of this function is to initialize the struct nand_chip methods, and from the Nand Flash read the chip ID, and the method struct mtd_info initialization.

6. mtd current device, which partition information is added.

7. If there are more mtd equipment, to 4 execution.

 

  Initialization Nand Flash Controller

s3c2410_nand_inithw () function initializes the Nand Flash controller, by providing the Nand Flash Control Register (S3C2410_NFCONF) to

Completed, where the most important is calculated tacls, twrph0 and twrph1 value in accordance with the S3C2410 PCLK.

 

Remove Device

s3c2410_nand_remove () when the device is removed, the device driver calls the core of its main work is as follows:

  1. * Device * driver_data of the field blank.

2. Release mtd device information. 3. Release clk resources.

4.) enantiomer canceled address space iounmap (. 5. Application of the release of I / O memory resources.

6. Release device private data * info space.

 

    Nand Flash chip initialization

. S3c2410_nand_init_chip () initializes a number of key fields in the struct nand_chip and a method wherein the methods include:

  1. s3c2410_nand_hwcontrol (); hardware control

2. s3c2410_nand_devready (); device is ready

  1. s3c2410_nand_write_buf (); write a buffer to nand flash
  2. s3c2410_nand_read_buf (); read buffer to a nand flash 5. s3c2410_nand_select_chip (); chip selecting operation

If the hardware supports the ECC check, a method is also provided:

 

  1. s3c2410_nand_correct_data (); correction data by the ECC code
  2. s3c2410_nand_enable_hwecc (); open hardware ECC check
  3. s3c2410_nand_calculate_ecc (); calculates the ECC code

 

Read Nand F. L A SH

When the device of the nand flash files (nand flash corresponding to the / dev file) system call read (), or read in a file system of the device. Struct mtd_info read method will be called in, they the default function is call nand_read (), the call nand_do_read_ecc drivers / mtd / nand / nand_base.c defined .nand_read () (), performing a read operation nand_do_read_ecc () function, performs the following several tasks:

  1. Select_chip method calls the overload struct nand_chip nand flash drive, i.e. s3c2410_nand_select_chip () to operate the chip select MTD.
  2. It will be called struct nand_chip the default method cmdfunc sends a read command to the nand flash.
  3. Struct nand_chip calls read_buf of overloading the nand flash drive (), i.e. s3c2410_nand_read_buf () read from the data register Nand Flash controller.
  4. If necessary, it will call in nand flash drive for struct nand_chip overloaded enable_hwecc, correct_data and calculate_ecc method for data ECC check.

 

 Write Nand Flash

When the device file for the nand flash (corresponding nand flash in the / dev file) system call write (), or read in a file system of the device will be called struct mtd_info the write method, they lack Province call the function (), these two functions is defined as nand_write in drivers / mtd / nand / nand_base.c in. nand_write () call nand_write_ecc (), write operation is performed. in nand_do_write_ecc () function, mainly to complete several tasks as follows :

    1. Select_chip method calls the overload struct nand_chip nand flash drive, i.e. s3c2410_nand_select_chip () to operate the chip select MTD.
    2. Call nand_write_page () to write a page.
    3. In nand_write_page (), the calls in the struct nand_chip the default method cmdfunc sends the write command to nand flash.
    4. In nand_write_page (), the call will write_buf (), i.e. s3c2410_nand_write_buf () to override the struct nand_chip nand flash drive to write data from the data register of Nand Flash controller.
    5. In nand_write_page (), the calls of the nand flash drive struct nand_chip overloaded waitfunc method calls the default function nand_wait (), the method obtaining an operating state, and waits for nand flash operation is completed. Wait until the operation is dev_ready nand flash drive method calls for the struct nand_chip overloaded, i.e. s3c2410_nand_devready () function.

Guess you like

Origin www.cnblogs.com/fanweisheng/p/11106264.html