]> git.sur5r.net Git - u-boot/blobdiff - drivers/mtd/nand/mxc_nand.c
Merge git://git.denx.de/u-boot-sunxi
[u-boot] / drivers / mtd / nand / mxc_nand.c
index f12b07e7adc720e9537be24e18d82bd22993b0cf..7221d0ba0d7da4fef7307ab3a8784578d2e2748d 100644 (file)
@@ -19,7 +19,6 @@
 #define DRIVER_NAME "mxc_nand"
 
 struct mxc_nand_host {
-       struct mtd_info                 mtd;
        struct nand_chip                *nand;
 
        struct mxc_nand_regs __iomem    *regs;
@@ -351,8 +350,8 @@ static int mxc_nand_dev_ready(struct mtd_info *mtd)
 
 static void _mxc_nand_enable_hwecc(struct mtd_info *mtd, int on)
 {
-       struct nand_chip *nand_chip = mtd->priv;
-       struct mxc_nand_host *host = nand_chip->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
+       struct mxc_nand_host *host = nand_get_controller_data(nand_chip);
 #if defined(MXC_NFC_V1) || defined(MXC_NFC_V2_1)
        uint16_t tmp = readnfc(&host->regs->config1);
 
@@ -386,7 +385,7 @@ static int mxc_nand_read_oob_syndrome(struct mtd_info *mtd,
                                      struct nand_chip *chip,
                                      int page)
 {
-       struct mxc_nand_host *host = chip->priv;
+       struct mxc_nand_host *host = nand_get_controller_data(chip);
        uint8_t *buf = chip->oob_poi;
        int length = mtd->oobsize;
        int eccpitch = chip->ecc.bytes + chip->ecc.prepad + chip->ecc.postpad;
@@ -441,7 +440,7 @@ static int mxc_nand_read_page_raw_syndrome(struct mtd_info *mtd,
                                           int oob_required,
                                           int page)
 {
-       struct mxc_nand_host *host = chip->priv;
+       struct mxc_nand_host *host = nand_get_controller_data(chip);
        int eccsize = chip->ecc.size;
        int eccbytes = chip->ecc.bytes;
        int eccpitch = eccbytes + chip->ecc.prepad + chip->ecc.postpad;
@@ -486,7 +485,7 @@ static int mxc_nand_read_page_syndrome(struct mtd_info *mtd,
                                       int oob_required,
                                       int page)
 {
-       struct mxc_nand_host *host = chip->priv;
+       struct mxc_nand_host *host = nand_get_controller_data(chip);
        int n, eccsize = chip->ecc.size;
        int eccbytes = chip->ecc.bytes;
        int eccpitch = eccbytes + chip->ecc.prepad + chip->ecc.postpad;
@@ -550,7 +549,7 @@ static int mxc_nand_read_page_syndrome(struct mtd_info *mtd,
 static int mxc_nand_write_oob_syndrome(struct mtd_info *mtd,
                                       struct nand_chip *chip, int page)
 {
-       struct mxc_nand_host *host = chip->priv;
+       struct mxc_nand_host *host = nand_get_controller_data(chip);
        int eccpitch = chip->ecc.bytes + chip->ecc.prepad + chip->ecc.postpad;
        int length = mtd->oobsize;
        int i, len, status, steps = chip->ecc.steps;
@@ -576,9 +575,9 @@ static int mxc_nand_write_oob_syndrome(struct mtd_info *mtd,
 static int mxc_nand_write_page_raw_syndrome(struct mtd_info *mtd,
                                             struct nand_chip *chip,
                                             const uint8_t *buf,
-                                            int oob_required)
+                                            int oob_required, int page)
 {
-       struct mxc_nand_host *host = chip->priv;
+       struct mxc_nand_host *host = nand_get_controller_data(chip);
        int eccsize = chip->ecc.size;
        int eccbytes = chip->ecc.bytes;
        int eccpitch = eccbytes + chip->ecc.prepad + chip->ecc.postpad;
@@ -616,9 +615,9 @@ static int mxc_nand_write_page_raw_syndrome(struct mtd_info *mtd,
 static int mxc_nand_write_page_syndrome(struct mtd_info *mtd,
                                         struct nand_chip *chip,
                                         const uint8_t *buf,
-                                        int oob_required)
+                                        int oob_required, int page)
 {
-       struct mxc_nand_host *host = chip->priv;
+       struct mxc_nand_host *host = nand_get_controller_data(chip);
        int i, n, eccsize = chip->ecc.size;
        int eccbytes = chip->ecc.bytes;
        int eccpitch = eccbytes + chip->ecc.prepad + chip->ecc.postpad;
@@ -661,8 +660,8 @@ static int mxc_nand_write_page_syndrome(struct mtd_info *mtd,
 static int mxc_nand_correct_data(struct mtd_info *mtd, u_char *dat,
                                 u_char *read_ecc, u_char *calc_ecc)
 {
-       struct nand_chip *nand_chip = mtd->priv;
-       struct mxc_nand_host *host = nand_chip->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
+       struct mxc_nand_host *host = nand_get_controller_data(nand_chip);
        uint32_t ecc_status = readl(&host->regs->ecc_status_result);
        int subpages = mtd->writesize / nand_chip->subpagesize;
        int pg2blk_shift = nand_chip->phys_erase_shift -
@@ -681,7 +680,7 @@ static int mxc_nand_correct_data(struct mtd_info *mtd, u_char *dat,
                                       mtd->writesize / nand_chip->subpagesize
                                            - subpages);
                        }
-                       return -1;
+                       return -EBADMSG;
                }
                ecc_status >>= 4;
                subpages--;
@@ -700,8 +699,8 @@ static int mxc_nand_correct_data(struct mtd_info *mtd, u_char *dat,
 static int mxc_nand_correct_data(struct mtd_info *mtd, u_char *dat,
                                 u_char *read_ecc, u_char *calc_ecc)
 {
-       struct nand_chip *nand_chip = mtd->priv;
-       struct mxc_nand_host *host = nand_chip->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
+       struct mxc_nand_host *host = nand_get_controller_data(nand_chip);
 
        /*
         * 1-Bit errors are automatically corrected in HW.  No need for
@@ -713,7 +712,7 @@ static int mxc_nand_correct_data(struct mtd_info *mtd, u_char *dat,
        if (((ecc_status & 0x3) == 2) || ((ecc_status >> 2) == 2)) {
                MTDDEBUG(MTD_DEBUG_LEVEL0,
                      "MXC_NAND: HWECC uncorrectable 2-bit ECC error\n");
-               return -1;
+               return -EBADMSG;
        }
 
        return 0;
@@ -729,8 +728,8 @@ static int mxc_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
 
 static u_char mxc_nand_read_byte(struct mtd_info *mtd)
 {
-       struct nand_chip *nand_chip = mtd->priv;
-       struct mxc_nand_host *host = nand_chip->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
+       struct mxc_nand_host *host = nand_get_controller_data(nand_chip);
        uint8_t ret = 0;
        uint16_t col;
        uint16_t __iomem *main_buf =
@@ -769,8 +768,8 @@ static u_char mxc_nand_read_byte(struct mtd_info *mtd)
 
 static uint16_t mxc_nand_read_word(struct mtd_info *mtd)
 {
-       struct nand_chip *nand_chip = mtd->priv;
-       struct mxc_nand_host *host = nand_chip->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
+       struct mxc_nand_host *host = nand_get_controller_data(nand_chip);
        uint16_t col, ret;
        uint16_t __iomem *p;
 
@@ -821,8 +820,8 @@ static uint16_t mxc_nand_read_word(struct mtd_info *mtd)
 static void mxc_nand_write_buf(struct mtd_info *mtd,
                                const u_char *buf, int len)
 {
-       struct nand_chip *nand_chip = mtd->priv;
-       struct mxc_nand_host *host = nand_chip->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
+       struct mxc_nand_host *host = nand_get_controller_data(nand_chip);
        int n, col, i = 0;
 
        MTDDEBUG(MTD_DEBUG_LEVEL3,
@@ -895,8 +894,8 @@ static void mxc_nand_write_buf(struct mtd_info *mtd,
  */
 static void mxc_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
 {
-       struct nand_chip *nand_chip = mtd->priv;
-       struct mxc_nand_host *host = nand_chip->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
+       struct mxc_nand_host *host = nand_get_controller_data(nand_chip);
        int n, col, i = 0;
 
        MTDDEBUG(MTD_DEBUG_LEVEL3,
@@ -955,8 +954,8 @@ static void mxc_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
  */
 static void mxc_nand_select_chip(struct mtd_info *mtd, int chip)
 {
-       struct nand_chip *nand_chip = mtd->priv;
-       struct mxc_nand_host *host = nand_chip->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
+       struct mxc_nand_host *host = nand_get_controller_data(nand_chip);
 
        switch (chip) {
        case -1:
@@ -982,8 +981,8 @@ static void mxc_nand_select_chip(struct mtd_info *mtd, int chip)
 void mxc_nand_command(struct mtd_info *mtd, unsigned command,
                                int column, int page_addr)
 {
-       struct nand_chip *nand_chip = mtd->priv;
-       struct mxc_nand_host *host = nand_chip->priv;
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
+       struct mxc_nand_host *host = nand_get_controller_data(nand_chip);
 
        MTDDEBUG(MTD_DEBUG_LEVEL3,
              "mxc_nand_command (cmd = 0x%x, col = 0x%x, page = 0x%x)\n",
@@ -1164,14 +1163,13 @@ int board_nand_init(struct nand_chip *this)
 #endif
 
        /* structures must be linked */
-       mtd = &host->mtd;
-       mtd->priv = this;
+       mtd = &this->mtd;
        host->nand = this;
 
        /* 5 us command delay time */
        this->chip_delay = 5;
 
-       this->priv = host;
+       nand_set_controller_data(this, host);
        this->dev_ready = mxc_nand_dev_ready;
        this->cmdfunc = mxc_nand_command;
        this->select_chip = mxc_nand_select_chip;