| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * BCM47XX NAND flash driver |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2012 Rafał Miłecki <zajec5@gmail.com> |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 8 | | - * published by the Free Software Foundation. |
|---|
| 9 | | - * |
|---|
| 10 | 6 | */ |
|---|
| 11 | 7 | |
|---|
| 12 | 8 | #include "bcm47xxnflash.h" |
|---|
| .. | .. |
|---|
| 170 | 166 | * NAND chip ops |
|---|
| 171 | 167 | **************************************************/ |
|---|
| 172 | 168 | |
|---|
| 173 | | -static void bcm47xxnflash_ops_bcm4706_cmd_ctrl(struct mtd_info *mtd, int cmd, |
|---|
| 174 | | - unsigned int ctrl) |
|---|
| 169 | +static void bcm47xxnflash_ops_bcm4706_cmd_ctrl(struct nand_chip *nand_chip, |
|---|
| 170 | + int cmd, unsigned int ctrl) |
|---|
| 175 | 171 | { |
|---|
| 176 | | - struct nand_chip *nand_chip = mtd_to_nand(mtd); |
|---|
| 177 | 172 | struct bcm47xxnflash *b47n = nand_get_controller_data(nand_chip); |
|---|
| 178 | 173 | u32 code = 0; |
|---|
| 179 | 174 | |
|---|
| .. | .. |
|---|
| 191 | 186 | } |
|---|
| 192 | 187 | |
|---|
| 193 | 188 | /* Default nand_select_chip calls cmd_ctrl, which is not used in BCM4706 */ |
|---|
| 194 | | -static void bcm47xxnflash_ops_bcm4706_select_chip(struct mtd_info *mtd, |
|---|
| 195 | | - int chip) |
|---|
| 189 | +static void bcm47xxnflash_ops_bcm4706_select_chip(struct nand_chip *chip, |
|---|
| 190 | + int cs) |
|---|
| 196 | 191 | { |
|---|
| 197 | 192 | return; |
|---|
| 198 | 193 | } |
|---|
| 199 | 194 | |
|---|
| 200 | | -static int bcm47xxnflash_ops_bcm4706_dev_ready(struct mtd_info *mtd) |
|---|
| 195 | +static int bcm47xxnflash_ops_bcm4706_dev_ready(struct nand_chip *nand_chip) |
|---|
| 201 | 196 | { |
|---|
| 202 | | - struct nand_chip *nand_chip = mtd_to_nand(mtd); |
|---|
| 203 | 197 | struct bcm47xxnflash *b47n = nand_get_controller_data(nand_chip); |
|---|
| 204 | 198 | |
|---|
| 205 | 199 | return !!(bcma_cc_read32(b47n->cc, BCMA_CC_NFLASH_CTL) & NCTL_READY); |
|---|
| .. | .. |
|---|
| 212 | 206 | * registers of ChipCommon core. Hacking cmd_ctrl to understand and convert |
|---|
| 213 | 207 | * standard commands would be much more complicated. |
|---|
| 214 | 208 | */ |
|---|
| 215 | | -static void bcm47xxnflash_ops_bcm4706_cmdfunc(struct mtd_info *mtd, |
|---|
| 209 | +static void bcm47xxnflash_ops_bcm4706_cmdfunc(struct nand_chip *nand_chip, |
|---|
| 216 | 210 | unsigned command, int column, |
|---|
| 217 | 211 | int page_addr) |
|---|
| 218 | 212 | { |
|---|
| 219 | | - struct nand_chip *nand_chip = mtd_to_nand(mtd); |
|---|
| 213 | + struct mtd_info *mtd = nand_to_mtd(nand_chip); |
|---|
| 220 | 214 | struct bcm47xxnflash *b47n = nand_get_controller_data(nand_chip); |
|---|
| 221 | 215 | struct bcma_drv_cc *cc = b47n->cc; |
|---|
| 222 | 216 | u32 ctlcode; |
|---|
| .. | .. |
|---|
| 229 | 223 | |
|---|
| 230 | 224 | switch (command) { |
|---|
| 231 | 225 | case NAND_CMD_RESET: |
|---|
| 232 | | - nand_chip->cmd_ctrl(mtd, command, NAND_CTRL_CLE); |
|---|
| 226 | + nand_chip->legacy.cmd_ctrl(nand_chip, command, NAND_CTRL_CLE); |
|---|
| 233 | 227 | |
|---|
| 234 | 228 | ndelay(100); |
|---|
| 235 | | - nand_wait_ready(mtd); |
|---|
| 229 | + nand_wait_ready(nand_chip); |
|---|
| 236 | 230 | break; |
|---|
| 237 | 231 | case NAND_CMD_READID: |
|---|
| 238 | 232 | ctlcode = NCTL_CSA | 0x01000000 | NCTL_CMD1W | NCTL_CMD0; |
|---|
| .. | .. |
|---|
| 310 | 304 | b47n->curr_command = command; |
|---|
| 311 | 305 | } |
|---|
| 312 | 306 | |
|---|
| 313 | | -static u8 bcm47xxnflash_ops_bcm4706_read_byte(struct mtd_info *mtd) |
|---|
| 307 | +static u8 bcm47xxnflash_ops_bcm4706_read_byte(struct nand_chip *nand_chip) |
|---|
| 314 | 308 | { |
|---|
| 315 | | - struct nand_chip *nand_chip = mtd_to_nand(mtd); |
|---|
| 309 | + struct mtd_info *mtd = nand_to_mtd(nand_chip); |
|---|
| 316 | 310 | struct bcm47xxnflash *b47n = nand_get_controller_data(nand_chip); |
|---|
| 317 | 311 | struct bcma_drv_cc *cc = b47n->cc; |
|---|
| 318 | 312 | u32 tmp = 0; |
|---|
| .. | .. |
|---|
| 338 | 332 | return 0; |
|---|
| 339 | 333 | } |
|---|
| 340 | 334 | |
|---|
| 341 | | -static void bcm47xxnflash_ops_bcm4706_read_buf(struct mtd_info *mtd, |
|---|
| 335 | +static void bcm47xxnflash_ops_bcm4706_read_buf(struct nand_chip *nand_chip, |
|---|
| 342 | 336 | uint8_t *buf, int len) |
|---|
| 343 | 337 | { |
|---|
| 344 | | - struct nand_chip *nand_chip = mtd_to_nand(mtd); |
|---|
| 345 | 338 | struct bcm47xxnflash *b47n = nand_get_controller_data(nand_chip); |
|---|
| 346 | 339 | |
|---|
| 347 | 340 | switch (b47n->curr_command) { |
|---|
| 348 | 341 | case NAND_CMD_READ0: |
|---|
| 349 | 342 | case NAND_CMD_READOOB: |
|---|
| 350 | | - bcm47xxnflash_ops_bcm4706_read(mtd, buf, len); |
|---|
| 343 | + bcm47xxnflash_ops_bcm4706_read(nand_to_mtd(nand_chip), buf, |
|---|
| 344 | + len); |
|---|
| 351 | 345 | return; |
|---|
| 352 | 346 | } |
|---|
| 353 | 347 | |
|---|
| 354 | 348 | pr_err("Invalid command for buf read: 0x%X\n", b47n->curr_command); |
|---|
| 355 | 349 | } |
|---|
| 356 | 350 | |
|---|
| 357 | | -static void bcm47xxnflash_ops_bcm4706_write_buf(struct mtd_info *mtd, |
|---|
| 351 | +static void bcm47xxnflash_ops_bcm4706_write_buf(struct nand_chip *nand_chip, |
|---|
| 358 | 352 | const uint8_t *buf, int len) |
|---|
| 359 | 353 | { |
|---|
| 360 | | - struct nand_chip *nand_chip = mtd_to_nand(mtd); |
|---|
| 361 | 354 | struct bcm47xxnflash *b47n = nand_get_controller_data(nand_chip); |
|---|
| 362 | 355 | |
|---|
| 363 | 356 | switch (b47n->curr_command) { |
|---|
| 364 | 357 | case NAND_CMD_SEQIN: |
|---|
| 365 | | - bcm47xxnflash_ops_bcm4706_write(mtd, buf, len); |
|---|
| 358 | + bcm47xxnflash_ops_bcm4706_write(nand_to_mtd(nand_chip), buf, |
|---|
| 359 | + len); |
|---|
| 366 | 360 | return; |
|---|
| 367 | 361 | } |
|---|
| 368 | 362 | |
|---|
| .. | .. |
|---|
| 385 | 379 | u8 tbits, col_bits, col_size, row_bits, row_bsize; |
|---|
| 386 | 380 | u32 val; |
|---|
| 387 | 381 | |
|---|
| 388 | | - b47n->nand_chip.select_chip = bcm47xxnflash_ops_bcm4706_select_chip; |
|---|
| 389 | | - nand_chip->cmd_ctrl = bcm47xxnflash_ops_bcm4706_cmd_ctrl; |
|---|
| 390 | | - nand_chip->dev_ready = bcm47xxnflash_ops_bcm4706_dev_ready; |
|---|
| 391 | | - b47n->nand_chip.cmdfunc = bcm47xxnflash_ops_bcm4706_cmdfunc; |
|---|
| 392 | | - b47n->nand_chip.read_byte = bcm47xxnflash_ops_bcm4706_read_byte; |
|---|
| 393 | | - b47n->nand_chip.read_buf = bcm47xxnflash_ops_bcm4706_read_buf; |
|---|
| 394 | | - b47n->nand_chip.write_buf = bcm47xxnflash_ops_bcm4706_write_buf; |
|---|
| 395 | | - b47n->nand_chip.set_features = nand_get_set_features_notsupp; |
|---|
| 396 | | - b47n->nand_chip.get_features = nand_get_set_features_notsupp; |
|---|
| 382 | + nand_chip->legacy.select_chip = bcm47xxnflash_ops_bcm4706_select_chip; |
|---|
| 383 | + nand_chip->legacy.cmd_ctrl = bcm47xxnflash_ops_bcm4706_cmd_ctrl; |
|---|
| 384 | + nand_chip->legacy.dev_ready = bcm47xxnflash_ops_bcm4706_dev_ready; |
|---|
| 385 | + b47n->nand_chip.legacy.cmdfunc = bcm47xxnflash_ops_bcm4706_cmdfunc; |
|---|
| 386 | + b47n->nand_chip.legacy.read_byte = bcm47xxnflash_ops_bcm4706_read_byte; |
|---|
| 387 | + b47n->nand_chip.legacy.read_buf = bcm47xxnflash_ops_bcm4706_read_buf; |
|---|
| 388 | + b47n->nand_chip.legacy.write_buf = bcm47xxnflash_ops_bcm4706_write_buf; |
|---|
| 389 | + b47n->nand_chip.legacy.set_features = nand_get_set_features_notsupp; |
|---|
| 390 | + b47n->nand_chip.legacy.get_features = nand_get_set_features_notsupp; |
|---|
| 397 | 391 | |
|---|
| 398 | | - nand_chip->chip_delay = 50; |
|---|
| 392 | + nand_chip->legacy.chip_delay = 50; |
|---|
| 399 | 393 | b47n->nand_chip.bbt_options = NAND_BBT_USE_FLASH; |
|---|
| 400 | | - b47n->nand_chip.ecc.mode = NAND_ECC_NONE; /* TODO: implement ECC */ |
|---|
| 394 | + /* TODO: implement ECC */ |
|---|
| 395 | + b47n->nand_chip.ecc.engine_type = NAND_ECC_ENGINE_TYPE_NONE; |
|---|
| 401 | 396 | |
|---|
| 402 | 397 | /* Enable NAND flash access */ |
|---|
| 403 | 398 | bcma_cc_set32(b47n->cc, BCMA_CC_4706_FLASHSCFG, |
|---|
| .. | .. |
|---|
| 430 | 425 | } |
|---|
| 431 | 426 | |
|---|
| 432 | 427 | /* Configure FLASH */ |
|---|
| 433 | | - chipsize = b47n->nand_chip.chipsize >> 20; |
|---|
| 428 | + chipsize = nanddev_target_size(&b47n->nand_chip.base) >> 20; |
|---|
| 434 | 429 | tbits = ffs(chipsize); /* find first bit set */ |
|---|
| 435 | 430 | if (!tbits || tbits != fls(chipsize)) { |
|---|
| 436 | 431 | pr_err("Invalid flash size: 0x%lX\n", chipsize); |
|---|