diff options
author | Hauke Mehrtens <hauke@hauke-m.de> | 2016-06-20 17:32:12 -0400 |
---|---|---|
committer | Boris Brezillon <boris.brezillon@free-electrons.com> | 2016-07-11 02:40:16 -0400 |
commit | ddbed9c211ebddd1ad14903f276a51321d7b8fcd (patch) | |
tree | a91ee3b2f965e5cdbfc9cb185a1f6bcc0de0e2b6 | |
parent | e7e1f7be335458139e0a112bd0aae40d33dfe3a8 (diff) |
mtd: nand: xway: extract read and write function
Extract the functions to read and write to the register of the NAND
flash controller.
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
-rw-r--r-- | drivers/mtd/nand/xway_nand.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/drivers/mtd/nand/xway_nand.c b/drivers/mtd/nand/xway_nand.c index 08f796eaa624..4cdef245f52d 100644 --- a/drivers/mtd/nand/xway_nand.c +++ b/drivers/mtd/nand/xway_nand.c | |||
@@ -68,6 +68,22 @@ struct xway_nand_data { | |||
68 | unsigned long csflags; | 68 | unsigned long csflags; |
69 | }; | 69 | }; |
70 | 70 | ||
71 | static u8 xway_readb(struct mtd_info *mtd, int op) | ||
72 | { | ||
73 | struct nand_chip *chip = mtd_to_nand(mtd); | ||
74 | void __iomem *nandaddr = chip->IO_ADDR_R; | ||
75 | |||
76 | return readb(nandaddr + op); | ||
77 | } | ||
78 | |||
79 | static void xway_writeb(struct mtd_info *mtd, int op, u8 value) | ||
80 | { | ||
81 | struct nand_chip *chip = mtd_to_nand(mtd); | ||
82 | void __iomem *nandaddr = chip->IO_ADDR_W; | ||
83 | |||
84 | writeb(value, nandaddr + op); | ||
85 | } | ||
86 | |||
71 | static void xway_select_chip(struct mtd_info *mtd, int select) | 87 | static void xway_select_chip(struct mtd_info *mtd, int select) |
72 | { | 88 | { |
73 | struct nand_chip *chip = mtd_to_nand(mtd); | 89 | struct nand_chip *chip = mtd_to_nand(mtd); |
@@ -91,16 +107,13 @@ static void xway_select_chip(struct mtd_info *mtd, int select) | |||
91 | 107 | ||
92 | static void xway_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) | 108 | static void xway_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) |
93 | { | 109 | { |
94 | struct nand_chip *this = mtd_to_nand(mtd); | ||
95 | unsigned long nandaddr = (unsigned long) this->IO_ADDR_W; | ||
96 | |||
97 | if (cmd == NAND_CMD_NONE) | 110 | if (cmd == NAND_CMD_NONE) |
98 | return; | 111 | return; |
99 | 112 | ||
100 | if (ctrl & NAND_CLE) | 113 | if (ctrl & NAND_CLE) |
101 | writeb(cmd, (void __iomem *) (nandaddr | NAND_WRITE_CMD)); | 114 | xway_writeb(mtd, NAND_WRITE_CMD, cmd); |
102 | else if (ctrl & NAND_ALE) | 115 | else if (ctrl & NAND_ALE) |
103 | writeb(cmd, (void __iomem *) (nandaddr | NAND_WRITE_ADDR)); | 116 | xway_writeb(mtd, NAND_WRITE_ADDR, cmd); |
104 | 117 | ||
105 | while ((ltq_ebu_r32(EBU_NAND_WAIT) & NAND_WAIT_WR_C) == 0) | 118 | while ((ltq_ebu_r32(EBU_NAND_WAIT) & NAND_WAIT_WR_C) == 0) |
106 | ; | 119 | ; |
@@ -113,10 +126,7 @@ static int xway_dev_ready(struct mtd_info *mtd) | |||
113 | 126 | ||
114 | static unsigned char xway_read_byte(struct mtd_info *mtd) | 127 | static unsigned char xway_read_byte(struct mtd_info *mtd) |
115 | { | 128 | { |
116 | struct nand_chip *this = mtd_to_nand(mtd); | 129 | return xway_readb(mtd, NAND_READ_DATA); |
117 | unsigned long nandaddr = (unsigned long) this->IO_ADDR_R; | ||
118 | |||
119 | return ltq_r8((void __iomem *)(nandaddr + NAND_READ_DATA)); | ||
120 | } | 130 | } |
121 | 131 | ||
122 | /* | 132 | /* |