.. | .. |
---|
22 | 22 | #include <linux/platform_data/mtd-orion_nand.h> |
---|
23 | 23 | |
---|
24 | 24 | struct orion_nand_info { |
---|
| 25 | + struct nand_controller controller; |
---|
25 | 26 | struct nand_chip chip; |
---|
26 | 27 | struct clk *clk; |
---|
27 | 28 | }; |
---|
28 | 29 | |
---|
29 | | -static void orion_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) |
---|
| 30 | +static void orion_nand_cmd_ctrl(struct nand_chip *nc, int cmd, |
---|
| 31 | + unsigned int ctrl) |
---|
30 | 32 | { |
---|
31 | | - struct nand_chip *nc = mtd_to_nand(mtd); |
---|
32 | 33 | struct orion_nand_data *board = nand_get_controller_data(nc); |
---|
33 | 34 | u32 offs; |
---|
34 | 35 | |
---|
.. | .. |
---|
45 | 46 | if (nc->options & NAND_BUSWIDTH_16) |
---|
46 | 47 | offs <<= 1; |
---|
47 | 48 | |
---|
48 | | - writeb(cmd, nc->IO_ADDR_W + offs); |
---|
| 49 | + writeb(cmd, nc->legacy.IO_ADDR_W + offs); |
---|
49 | 50 | } |
---|
50 | 51 | |
---|
51 | | -static void orion_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) |
---|
| 52 | +static void orion_nand_read_buf(struct nand_chip *chip, uint8_t *buf, int len) |
---|
52 | 53 | { |
---|
53 | | - struct nand_chip *chip = mtd_to_nand(mtd); |
---|
54 | | - void __iomem *io_base = chip->IO_ADDR_R; |
---|
| 54 | + void __iomem *io_base = chip->legacy.IO_ADDR_R; |
---|
55 | 55 | #if defined(__LINUX_ARM_ARCH__) && __LINUX_ARM_ARCH__ >= 5 |
---|
56 | 56 | uint64_t *buf64; |
---|
57 | 57 | #endif |
---|
.. | .. |
---|
83 | 83 | buf[i++] = readb(io_base); |
---|
84 | 84 | } |
---|
85 | 85 | |
---|
| 86 | +static int orion_nand_attach_chip(struct nand_chip *chip) |
---|
| 87 | +{ |
---|
| 88 | + if (chip->ecc.engine_type == NAND_ECC_ENGINE_TYPE_SOFT && |
---|
| 89 | + chip->ecc.algo == NAND_ECC_ALGO_UNKNOWN) |
---|
| 90 | + chip->ecc.algo = NAND_ECC_ALGO_HAMMING; |
---|
| 91 | + |
---|
| 92 | + return 0; |
---|
| 93 | +} |
---|
| 94 | + |
---|
| 95 | +static const struct nand_controller_ops orion_nand_ops = { |
---|
| 96 | + .attach_chip = orion_nand_attach_chip, |
---|
| 97 | +}; |
---|
| 98 | + |
---|
86 | 99 | static int __init orion_nand_probe(struct platform_device *pdev) |
---|
87 | 100 | { |
---|
88 | 101 | struct orion_nand_info *info; |
---|
.. | .. |
---|
101 | 114 | return -ENOMEM; |
---|
102 | 115 | nc = &info->chip; |
---|
103 | 116 | mtd = nand_to_mtd(nc); |
---|
| 117 | + |
---|
| 118 | + nand_controller_init(&info->controller); |
---|
| 119 | + info->controller.ops = &orion_nand_ops; |
---|
| 120 | + nc->controller = &info->controller; |
---|
104 | 121 | |
---|
105 | 122 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
---|
106 | 123 | io_base = devm_ioremap_resource(&pdev->dev, res); |
---|
.. | .. |
---|
137 | 154 | |
---|
138 | 155 | nand_set_controller_data(nc, board); |
---|
139 | 156 | nand_set_flash_node(nc, pdev->dev.of_node); |
---|
140 | | - nc->IO_ADDR_R = nc->IO_ADDR_W = io_base; |
---|
141 | | - nc->cmd_ctrl = orion_nand_cmd_ctrl; |
---|
142 | | - nc->read_buf = orion_nand_read_buf; |
---|
143 | | - nc->ecc.mode = NAND_ECC_SOFT; |
---|
144 | | - nc->ecc.algo = NAND_ECC_HAMMING; |
---|
| 157 | + nc->legacy.IO_ADDR_R = nc->legacy.IO_ADDR_W = io_base; |
---|
| 158 | + nc->legacy.cmd_ctrl = orion_nand_cmd_ctrl; |
---|
| 159 | + nc->legacy.read_buf = orion_nand_read_buf; |
---|
145 | 160 | |
---|
146 | 161 | if (board->chip_delay) |
---|
147 | | - nc->chip_delay = board->chip_delay; |
---|
| 162 | + nc->legacy.chip_delay = board->chip_delay; |
---|
148 | 163 | |
---|
149 | 164 | WARN(board->width > 16, |
---|
150 | 165 | "%d bit bus width out of range", |
---|
.. | .. |
---|
174 | 189 | return ret; |
---|
175 | 190 | } |
---|
176 | 191 | |
---|
| 192 | + /* |
---|
| 193 | + * This driver assumes that the default ECC engine should be TYPE_SOFT. |
---|
| 194 | + * Set ->engine_type before registering the NAND devices in order to |
---|
| 195 | + * provide a driver specific default value. |
---|
| 196 | + */ |
---|
| 197 | + nc->ecc.engine_type = NAND_ECC_ENGINE_TYPE_SOFT; |
---|
| 198 | + |
---|
177 | 199 | ret = nand_scan(nc, 1); |
---|
178 | 200 | if (ret) |
---|
179 | 201 | goto no_dev; |
---|
.. | .. |
---|
196 | 218 | { |
---|
197 | 219 | struct orion_nand_info *info = platform_get_drvdata(pdev); |
---|
198 | 220 | struct nand_chip *chip = &info->chip; |
---|
| 221 | + int ret; |
---|
199 | 222 | |
---|
200 | | - nand_release(chip); |
---|
| 223 | + ret = mtd_device_unregister(nand_to_mtd(chip)); |
---|
| 224 | + WARN_ON(ret); |
---|
| 225 | + |
---|
| 226 | + nand_cleanup(chip); |
---|
201 | 227 | |
---|
202 | 228 | clk_disable_unprepare(info->clk); |
---|
203 | 229 | |
---|