]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - drivers/mtd/nand/pxa3xx_nand.c
mtd: nand: Add page argument to write_page() etc.
[people/ms/u-boot.git] / drivers / mtd / nand / pxa3xx_nand.c
index 939274204e18bef80a9428ba6fcf7797a106ee91..d3ac5391f156e84fce4134fb22f8f01303206b90 100644 (file)
 
 #include "pxa3xx_nand.h"
 
-/* Some U-Boot compatibility macros */
-#define writesl(a, d, s)       __raw_writesl((unsigned long)a, d, s)
-#define readsl(a, d, s)                __raw_readsl((unsigned long)a, d, s)
-#define writesw(a, d, s)       __raw_writesw((unsigned long)a, d, s)
-#define readsw(a, d, s)                __raw_readsw((unsigned long)a, d, s)
-#define writesb(a, d, s)       __raw_writesb((unsigned long)a, d, s)
-#define readsb(a, d, s)                __raw_readsb((unsigned long)a, d, s)
-
 #define TIMEOUT_DRAIN_FIFO     5       /* in ms */
 #define        CHIP_DELAY_TIMEOUT      200
 #define NAND_STOP_DELAY                40
@@ -908,7 +900,8 @@ static int prepare_set_command(struct pxa3xx_nand_info *info, int command,
 static void nand_cmdfunc(struct mtd_info *mtd, unsigned command,
                         int column, int page_addr)
 {
-       struct pxa3xx_nand_host *host = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct pxa3xx_nand_host *host = nand_get_controller_data(chip);
        struct pxa3xx_nand_info *info = host->info_data;
        int exec_cmd;
 
@@ -968,7 +961,8 @@ static void nand_cmdfunc_extended(struct mtd_info *mtd,
                                  const unsigned command,
                                  int column, int page_addr)
 {
-       struct pxa3xx_nand_host *host = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct pxa3xx_nand_host *host = nand_get_controller_data(chip);
        struct pxa3xx_nand_info *info = host->info_data;
        int exec_cmd, ext_cmd_type;
 
@@ -1087,7 +1081,8 @@ static void nand_cmdfunc_extended(struct mtd_info *mtd,
 }
 
 static int pxa3xx_nand_write_page_hwecc(struct mtd_info *mtd,
-               struct nand_chip *chip, const uint8_t *buf, int oob_required)
+               struct nand_chip *chip, const uint8_t *buf, int oob_required,
+               int page)
 {
        chip->write_buf(mtd, buf, mtd->writesize);
        chip->write_buf(mtd, chip->oob_poi, mtd->oobsize);
@@ -1099,7 +1094,7 @@ static int pxa3xx_nand_read_page_hwecc(struct mtd_info *mtd,
                struct nand_chip *chip, uint8_t *buf, int oob_required,
                int page)
 {
-       struct pxa3xx_nand_host *host = mtd->priv;
+       struct pxa3xx_nand_host *host = nand_get_controller_data(chip);
        struct pxa3xx_nand_info *info = host->info_data;
 
        chip->read_buf(mtd, buf, mtd->writesize);
@@ -1125,7 +1120,8 @@ static int pxa3xx_nand_read_page_hwecc(struct mtd_info *mtd,
 
 static uint8_t pxa3xx_nand_read_byte(struct mtd_info *mtd)
 {
-       struct pxa3xx_nand_host *host = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct pxa3xx_nand_host *host = nand_get_controller_data(chip);
        struct pxa3xx_nand_info *info = host->info_data;
        char retval = 0xFF;
 
@@ -1138,7 +1134,8 @@ static uint8_t pxa3xx_nand_read_byte(struct mtd_info *mtd)
 
 static u16 pxa3xx_nand_read_word(struct mtd_info *mtd)
 {
-       struct pxa3xx_nand_host *host = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct pxa3xx_nand_host *host = nand_get_controller_data(chip);
        struct pxa3xx_nand_info *info = host->info_data;
        u16 retval = 0xFFFF;
 
@@ -1151,7 +1148,8 @@ static u16 pxa3xx_nand_read_word(struct mtd_info *mtd)
 
 static void pxa3xx_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 {
-       struct pxa3xx_nand_host *host = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct pxa3xx_nand_host *host = nand_get_controller_data(chip);
        struct pxa3xx_nand_info *info = host->info_data;
        int real_len = min_t(size_t, len, info->buf_count - info->buf_start);
 
@@ -1162,7 +1160,8 @@ static void pxa3xx_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 static void pxa3xx_nand_write_buf(struct mtd_info *mtd,
                const uint8_t *buf, int len)
 {
-       struct pxa3xx_nand_host *host = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct pxa3xx_nand_host *host = nand_get_controller_data(chip);
        struct pxa3xx_nand_info *info = host->info_data;
        int real_len = min_t(size_t, len, info->buf_count - info->buf_start);
 
@@ -1177,7 +1176,8 @@ static void pxa3xx_nand_select_chip(struct mtd_info *mtd, int chip)
 
 static int pxa3xx_nand_waitfunc(struct mtd_info *mtd, struct nand_chip *this)
 {
-       struct pxa3xx_nand_host *host = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct pxa3xx_nand_host *host = nand_get_controller_data(chip);
        struct pxa3xx_nand_info *info = host->info_data;
 
        if (info->need_wait) {
@@ -1218,7 +1218,7 @@ static int pxa3xx_nand_config_flash(struct pxa3xx_nand_info *info)
 {
        struct pxa3xx_nand_host *host = info->host[info->cs];
        struct mtd_info *mtd = host->mtd;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        info->reg_ndcr |= (host->col_addr_cycles == 2) ? NDCR_RA_START : 0;
        info->reg_ndcr |= (chip->page_shift == 6) ? NDCR_PG_PER_BLK : 0;
@@ -1270,7 +1270,7 @@ static int pxa3xx_nand_sensing(struct pxa3xx_nand_host *host)
        int ret;
 
        mtd = info->host[info->cs]->mtd;
-       chip = mtd->priv;
+       chip = mtd_to_nand(mtd);
 
        /* configure default flash values */
        info->reg_ndcr = 0x0; /* enable all interrupts */
@@ -1362,10 +1362,10 @@ static int pxa_ecc_init(struct pxa3xx_nand_info *info,
 
 static int pxa3xx_nand_scan(struct mtd_info *mtd)
 {
-       struct pxa3xx_nand_host *host = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct pxa3xx_nand_host *host = nand_get_controller_data(chip);
        struct pxa3xx_nand_info *info = host->info_data;
        struct pxa3xx_nand_platform_data *pdata = info->pdata;
-       struct nand_chip *chip = mtd->priv;
        int ret;
        uint16_t ecc_strength, ecc_step;
 
@@ -1485,16 +1485,15 @@ static int alloc_nand_resource(struct pxa3xx_nand_info *info)
 
        info->variant = pxa3xx_nand_get_variant();
        for (cs = 0; cs < pdata->num_cs; cs++) {
-               mtd = &nand_info[cs];
                chip = (struct nand_chip *)
                        ((u8 *)&info[1] + sizeof(*host) * cs);
+               mtd = nand_to_mtd(chip);
                host = (struct pxa3xx_nand_host *)chip;
                info->host[cs] = host;
                host->mtd = mtd;
                host->cs = cs;
                host->info_data = info;
                host->read_id_bytes = 4;
-               mtd->priv = host;
                mtd->owner = THIS_MODULE;
 
                chip->ecc.read_page     = pxa3xx_nand_read_page_hwecc;
@@ -1581,8 +1580,10 @@ static int pxa3xx_nand_probe(struct pxa3xx_nand_info *info)
                        continue;
                }
 
-               if (!ret)
-                       probe_success = 1;
+               if (nand_register(cs, mtd))
+                       continue;
+
+               probe_success = 1;
        }
 
        if (!probe_success)
@@ -1609,6 +1610,4 @@ void board_nand_init(void)
        ret = pxa3xx_nand_probe(info);
        if (ret)
                return;
-
-       nand_register(0);
 }