diff options
author | André Fabian Silva Delgado <emulatorman@parabola.nu> | 2016-03-25 03:53:42 -0300 |
---|---|---|
committer | André Fabian Silva Delgado <emulatorman@parabola.nu> | 2016-03-25 03:53:42 -0300 |
commit | 03dd4cb26d967f9588437b0fc9cc0e8353322bb7 (patch) | |
tree | fa581f6dc1c0596391690d1f67eceef3af8246dc /drivers/mtd/nand/nandsim.c | |
parent | d4e493caf788ef44982e131ff9c786546904d934 (diff) |
Linux-libre 4.5-gnu
Diffstat (limited to 'drivers/mtd/nand/nandsim.c')
-rw-r--r-- | drivers/mtd/nand/nandsim.c | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c index b16d70aaf..1fd519503 100644 --- a/drivers/mtd/nand/nandsim.c +++ b/drivers/mtd/nand/nandsim.c @@ -666,8 +666,8 @@ static char *get_partition_name(int i) */ static int init_nandsim(struct mtd_info *mtd) { - struct nand_chip *chip = mtd->priv; - struct nandsim *ns = chip->priv; + struct nand_chip *chip = mtd_to_nand(mtd); + struct nandsim *ns = nand_get_controller_data(chip); int i, ret = 0; uint64_t remains; uint64_t next_offset; @@ -1908,7 +1908,8 @@ static void switch_state(struct nandsim *ns) static u_char ns_nand_read_byte(struct mtd_info *mtd) { - struct nandsim *ns = ((struct nand_chip *)mtd->priv)->priv; + struct nand_chip *chip = mtd_to_nand(mtd); + struct nandsim *ns = nand_get_controller_data(chip); u_char outb = 0x00; /* Sanity and correctness checks */ @@ -1969,7 +1970,8 @@ static u_char ns_nand_read_byte(struct mtd_info *mtd) static void ns_nand_write_byte(struct mtd_info *mtd, u_char byte) { - struct nandsim *ns = ((struct nand_chip *)mtd->priv)->priv; + struct nand_chip *chip = mtd_to_nand(mtd); + struct nandsim *ns = nand_get_controller_data(chip); /* Sanity and correctness checks */ if (!ns->lines.ce) { @@ -2123,7 +2125,8 @@ static void ns_nand_write_byte(struct mtd_info *mtd, u_char byte) static void ns_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int bitmask) { - struct nandsim *ns = ((struct nand_chip *)mtd->priv)->priv; + struct nand_chip *chip = mtd_to_nand(mtd); + struct nandsim *ns = nand_get_controller_data(chip); ns->lines.cle = bitmask & NAND_CLE ? 1 : 0; ns->lines.ale = bitmask & NAND_ALE ? 1 : 0; @@ -2141,7 +2144,7 @@ static int ns_device_ready(struct mtd_info *mtd) static uint16_t ns_nand_read_word(struct mtd_info *mtd) { - struct nand_chip *chip = (struct nand_chip *)mtd->priv; + struct nand_chip *chip = mtd_to_nand(mtd); NS_DBG("read_word\n"); @@ -2150,7 +2153,8 @@ static uint16_t ns_nand_read_word(struct mtd_info *mtd) static void ns_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len) { - struct nandsim *ns = ((struct nand_chip *)mtd->priv)->priv; + struct nand_chip *chip = mtd_to_nand(mtd); + struct nandsim *ns = nand_get_controller_data(chip); /* Check that chip is expecting data input */ if (!(ns->state & STATE_DATAIN_MASK)) { @@ -2177,7 +2181,8 @@ static void ns_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len) static void ns_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len) { - struct nandsim *ns = ((struct nand_chip *)mtd->priv)->priv; + struct nand_chip *chip = mtd_to_nand(mtd); + struct nandsim *ns = nand_get_controller_data(chip); /* Sanity and correctness checks */ if (!ns->lines.ce) { @@ -2198,7 +2203,7 @@ static void ns_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len) int i; for (i = 0; i < len; i++) - buf[i] = ((struct nand_chip *)mtd->priv)->read_byte(mtd); + buf[i] = mtd_to_nand(mtd)->read_byte(mtd); return; } @@ -2236,16 +2241,15 @@ static int __init ns_init_module(void) } /* Allocate and initialize mtd_info, nand_chip and nandsim structures */ - nsmtd = kzalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip) - + sizeof(struct nandsim), GFP_KERNEL); - if (!nsmtd) { + chip = kzalloc(sizeof(struct nand_chip) + sizeof(struct nandsim), + GFP_KERNEL); + if (!chip) { NS_ERR("unable to allocate core structures.\n"); return -ENOMEM; } - chip = (struct nand_chip *)(nsmtd + 1); - nsmtd->priv = (void *)chip; + nsmtd = nand_to_mtd(chip); nand = (struct nandsim *)(chip + 1); - chip->priv = (void *)nand; + nand_set_controller_data(chip, (void *)nand); /* * Register simulator's callbacks. @@ -2392,7 +2396,7 @@ err_exit: for (i = 0;i < ARRAY_SIZE(nand->partitions); ++i) kfree(nand->partitions[i].name); error: - kfree(nsmtd); + kfree(chip); free_lists(); return retval; @@ -2405,7 +2409,8 @@ module_init(ns_init_module); */ static void __exit ns_cleanup_module(void) { - struct nandsim *ns = ((struct nand_chip *)nsmtd->priv)->priv; + struct nand_chip *chip = mtd_to_nand(nsmtd); + struct nandsim *ns = nand_get_controller_data(chip); int i; nandsim_debugfs_remove(ns); @@ -2413,7 +2418,7 @@ static void __exit ns_cleanup_module(void) nand_release(nsmtd); /* Unregister driver */ for (i = 0;i < ARRAY_SIZE(ns->partitions); ++i) kfree(ns->partitions[i].name); - kfree(nsmtd); /* Free other structures */ + kfree(mtd_to_nand(nsmtd)); /* Free other structures */ free_lists(); } |