Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mtd: rawnand: qcom: Remove legacy interface

Remove legacy interface implementation

Co-developed-by: Sricharan Ramabadhran <quic_srichara@quicinc.com>
Signed-off-by: Sricharan Ramabadhran <quic_srichara@quicinc.com>
Signed-off-by: Md Sadre Alam <quic_mdalam@quicinc.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20230710054440.23297-2-quic_mdalam@quicinc.com

authored by

Md Sadre Alam and committed by
Miquel Raynal
2e7f735b 89550beb

-359
-359
drivers/mtd/nand/raw/qcom_nandc.c
··· 1303 1303 write_reg_dma(nandc, NAND_READ_STATUS, 1, NAND_BAM_NEXT_SGL); 1304 1304 } 1305 1305 1306 - /* 1307 - * the following functions are used within chip->legacy.cmdfunc() to 1308 - * perform different NAND_CMD_* commands 1309 - */ 1310 - 1311 - /* sets up descriptors for NAND_CMD_PARAM */ 1312 - static int nandc_param(struct qcom_nand_host *host) 1313 - { 1314 - struct nand_chip *chip = &host->chip; 1315 - struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip); 1316 - 1317 - /* 1318 - * NAND_CMD_PARAM is called before we know much about the FLASH chip 1319 - * in use. we configure the controller to perform a raw read of 512 1320 - * bytes to read onfi params 1321 - */ 1322 - if (nandc->props->qpic_v2) 1323 - nandc_set_reg(chip, NAND_FLASH_CMD, OP_PAGE_READ_ONFI_READ | 1324 - PAGE_ACC | LAST_PAGE); 1325 - else 1326 - nandc_set_reg(chip, NAND_FLASH_CMD, OP_PAGE_READ | 1327 - PAGE_ACC | LAST_PAGE); 1328 - 1329 - nandc_set_reg(chip, NAND_ADDR0, 0); 1330 - nandc_set_reg(chip, NAND_ADDR1, 0); 1331 - nandc_set_reg(chip, NAND_DEV0_CFG0, 0 << CW_PER_PAGE 1332 - | 512 << UD_SIZE_BYTES 1333 - | 5 << NUM_ADDR_CYCLES 1334 - | 0 << SPARE_SIZE_BYTES); 1335 - nandc_set_reg(chip, NAND_DEV0_CFG1, 7 << NAND_RECOVERY_CYCLES 1336 - | 0 << CS_ACTIVE_BSY 1337 - | 17 << BAD_BLOCK_BYTE_NUM 1338 - | 1 << BAD_BLOCK_IN_SPARE_AREA 1339 - | 2 << WR_RD_BSY_GAP 1340 - | 0 << WIDE_FLASH 1341 - | 1 << DEV0_CFG1_ECC_DISABLE); 1342 - if (!nandc->props->qpic_v2) 1343 - nandc_set_reg(chip, NAND_EBI2_ECC_BUF_CFG, 1 << ECC_CFG_ECC_DISABLE); 1344 - 1345 - /* configure CMD1 and VLD for ONFI param probing in QPIC v1 */ 1346 - if (!nandc->props->qpic_v2) { 1347 - nandc_set_reg(chip, NAND_DEV_CMD_VLD, 1348 - (nandc->vld & ~READ_START_VLD)); 1349 - nandc_set_reg(chip, NAND_DEV_CMD1, 1350 - (nandc->cmd1 & ~(0xFF << READ_ADDR)) 1351 - | NAND_CMD_PARAM << READ_ADDR); 1352 - } 1353 - 1354 - nandc_set_reg(chip, NAND_EXEC_CMD, 1); 1355 - 1356 - if (!nandc->props->qpic_v2) { 1357 - nandc_set_reg(chip, NAND_DEV_CMD1_RESTORE, nandc->cmd1); 1358 - nandc_set_reg(chip, NAND_DEV_CMD_VLD_RESTORE, nandc->vld); 1359 - } 1360 - 1361 - nandc_set_read_loc(chip, 0, 0, 0, 512, 1); 1362 - 1363 - if (!nandc->props->qpic_v2) { 1364 - write_reg_dma(nandc, NAND_DEV_CMD_VLD, 1, 0); 1365 - write_reg_dma(nandc, NAND_DEV_CMD1, 1, NAND_BAM_NEXT_SGL); 1366 - } 1367 - 1368 - nandc->buf_count = 512; 1369 - memset(nandc->data_buffer, 0xff, nandc->buf_count); 1370 - 1371 - config_nand_single_cw_page_read(chip, false, 0); 1372 - 1373 - read_data_dma(nandc, FLASH_BUF_ACC, nandc->data_buffer, 1374 - nandc->buf_count, 0); 1375 - 1376 - /* restore CMD1 and VLD regs */ 1377 - if (!nandc->props->qpic_v2) { 1378 - write_reg_dma(nandc, NAND_DEV_CMD1_RESTORE, 1, 0); 1379 - write_reg_dma(nandc, NAND_DEV_CMD_VLD_RESTORE, 1, NAND_BAM_NEXT_SGL); 1380 - } 1381 - 1382 - return 0; 1383 - } 1384 - 1385 - /* sets up descriptors for NAND_CMD_ERASE1 */ 1386 - static int erase_block(struct qcom_nand_host *host, int page_addr) 1387 - { 1388 - struct nand_chip *chip = &host->chip; 1389 - struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip); 1390 - 1391 - nandc_set_reg(chip, NAND_FLASH_CMD, 1392 - OP_BLOCK_ERASE | PAGE_ACC | LAST_PAGE); 1393 - nandc_set_reg(chip, NAND_ADDR0, page_addr); 1394 - nandc_set_reg(chip, NAND_ADDR1, 0); 1395 - nandc_set_reg(chip, NAND_DEV0_CFG0, 1396 - host->cfg0_raw & ~(7 << CW_PER_PAGE)); 1397 - nandc_set_reg(chip, NAND_DEV0_CFG1, host->cfg1_raw); 1398 - nandc_set_reg(chip, NAND_EXEC_CMD, 1); 1399 - nandc_set_reg(chip, NAND_FLASH_STATUS, host->clrflashstatus); 1400 - nandc_set_reg(chip, NAND_READ_STATUS, host->clrreadstatus); 1401 - 1402 - write_reg_dma(nandc, NAND_FLASH_CMD, 3, NAND_BAM_NEXT_SGL); 1403 - write_reg_dma(nandc, NAND_DEV0_CFG0, 2, NAND_BAM_NEXT_SGL); 1404 - write_reg_dma(nandc, NAND_EXEC_CMD, 1, NAND_BAM_NEXT_SGL); 1405 - 1406 - read_reg_dma(nandc, NAND_FLASH_STATUS, 1, NAND_BAM_NEXT_SGL); 1407 - 1408 - write_reg_dma(nandc, NAND_FLASH_STATUS, 1, 0); 1409 - write_reg_dma(nandc, NAND_READ_STATUS, 1, NAND_BAM_NEXT_SGL); 1410 - 1411 - return 0; 1412 - } 1413 - 1414 - /* sets up descriptors for NAND_CMD_READID */ 1415 - static int read_id(struct qcom_nand_host *host, int column) 1416 - { 1417 - struct nand_chip *chip = &host->chip; 1418 - struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip); 1419 - 1420 - if (column == -1) 1421 - return 0; 1422 - 1423 - nandc_set_reg(chip, NAND_FLASH_CMD, OP_FETCH_ID); 1424 - nandc_set_reg(chip, NAND_ADDR0, column); 1425 - nandc_set_reg(chip, NAND_ADDR1, 0); 1426 - nandc_set_reg(chip, NAND_FLASH_CHIP_SELECT, 1427 - nandc->props->is_bam ? 0 : DM_EN); 1428 - nandc_set_reg(chip, NAND_EXEC_CMD, 1); 1429 - 1430 - write_reg_dma(nandc, NAND_FLASH_CMD, 4, NAND_BAM_NEXT_SGL); 1431 - write_reg_dma(nandc, NAND_EXEC_CMD, 1, NAND_BAM_NEXT_SGL); 1432 - 1433 - read_reg_dma(nandc, NAND_READ_ID, 1, NAND_BAM_NEXT_SGL); 1434 - 1435 - return 0; 1436 - } 1437 - 1438 - /* sets up descriptors for NAND_CMD_RESET */ 1439 - static int reset(struct qcom_nand_host *host) 1440 - { 1441 - struct nand_chip *chip = &host->chip; 1442 - struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip); 1443 - 1444 - nandc_set_reg(chip, NAND_FLASH_CMD, OP_RESET_DEVICE); 1445 - nandc_set_reg(chip, NAND_EXEC_CMD, 1); 1446 - 1447 - write_reg_dma(nandc, NAND_FLASH_CMD, 1, NAND_BAM_NEXT_SGL); 1448 - write_reg_dma(nandc, NAND_EXEC_CMD, 1, NAND_BAM_NEXT_SGL); 1449 - 1450 - read_reg_dma(nandc, NAND_FLASH_STATUS, 1, NAND_BAM_NEXT_SGL); 1451 - 1452 - return 0; 1453 - } 1454 - 1455 1306 /* helpers to submit/free our list of dma descriptors */ 1456 1307 static int submit_descs(struct qcom_nand_controller *nandc) 1457 1308 { ··· 1383 1532 { 1384 1533 nandc->reg_read_pos = 0; 1385 1534 nandc_read_buffer_sync(nandc, false); 1386 - } 1387 - 1388 - static void pre_command(struct qcom_nand_host *host, int command) 1389 - { 1390 - struct nand_chip *chip = &host->chip; 1391 - struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip); 1392 - 1393 - nandc->buf_count = 0; 1394 - nandc->buf_start = 0; 1395 - host->use_ecc = false; 1396 - host->last_command = command; 1397 - 1398 - clear_read_regs(nandc); 1399 - 1400 - clear_bam_transaction(nandc); 1401 - } 1402 - 1403 - /* 1404 - * this is called after NAND_CMD_PAGEPROG and NAND_CMD_ERASE1 to set our 1405 - * privately maintained status byte, this status byte can be read after 1406 - * NAND_CMD_STATUS is called 1407 - */ 1408 - static void parse_erase_write_errors(struct qcom_nand_host *host, int command) 1409 - { 1410 - struct nand_chip *chip = &host->chip; 1411 - struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip); 1412 - struct nand_ecc_ctrl *ecc = &chip->ecc; 1413 - int num_cw; 1414 - int i; 1415 - 1416 - num_cw = command == NAND_CMD_PAGEPROG ? ecc->steps : 1; 1417 - nandc_read_buffer_sync(nandc, true); 1418 - 1419 - for (i = 0; i < num_cw; i++) { 1420 - u32 flash_status = le32_to_cpu(nandc->reg_read_buf[i]); 1421 - 1422 - if (flash_status & FS_MPU_ERR) 1423 - host->status &= ~NAND_STATUS_WP; 1424 - 1425 - if (flash_status & FS_OP_ERR || (i == (num_cw - 1) && 1426 - (flash_status & 1427 - FS_DEVICE_STS_ERR))) 1428 - host->status |= NAND_STATUS_FAIL; 1429 - } 1430 - } 1431 - 1432 - static void post_command(struct qcom_nand_host *host, int command) 1433 - { 1434 - struct nand_chip *chip = &host->chip; 1435 - struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip); 1436 - 1437 - switch (command) { 1438 - case NAND_CMD_READID: 1439 - nandc_read_buffer_sync(nandc, true); 1440 - memcpy(nandc->data_buffer, nandc->reg_read_buf, 1441 - nandc->buf_count); 1442 - break; 1443 - case NAND_CMD_PAGEPROG: 1444 - case NAND_CMD_ERASE1: 1445 - parse_erase_write_errors(host, command); 1446 - break; 1447 - default: 1448 - break; 1449 - } 1450 - } 1451 - 1452 - /* 1453 - * Implements chip->legacy.cmdfunc. It's only used for a limited set of 1454 - * commands. The rest of the commands wouldn't be called by upper layers. 1455 - * For example, NAND_CMD_READOOB would never be called because we have our own 1456 - * versions of read_oob ops for nand_ecc_ctrl. 1457 - */ 1458 - static void qcom_nandc_command(struct nand_chip *chip, unsigned int command, 1459 - int column, int page_addr) 1460 - { 1461 - struct qcom_nand_host *host = to_qcom_nand_host(chip); 1462 - struct nand_ecc_ctrl *ecc = &chip->ecc; 1463 - struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip); 1464 - bool wait = false; 1465 - int ret = 0; 1466 - 1467 - pre_command(host, command); 1468 - 1469 - switch (command) { 1470 - case NAND_CMD_RESET: 1471 - ret = reset(host); 1472 - wait = true; 1473 - break; 1474 - 1475 - case NAND_CMD_READID: 1476 - nandc->buf_count = 4; 1477 - ret = read_id(host, column); 1478 - wait = true; 1479 - break; 1480 - 1481 - case NAND_CMD_PARAM: 1482 - ret = nandc_param(host); 1483 - wait = true; 1484 - break; 1485 - 1486 - case NAND_CMD_ERASE1: 1487 - ret = erase_block(host, page_addr); 1488 - wait = true; 1489 - break; 1490 - 1491 - case NAND_CMD_READ0: 1492 - /* we read the entire page for now */ 1493 - WARN_ON(column != 0); 1494 - 1495 - host->use_ecc = true; 1496 - set_address(host, 0, page_addr); 1497 - update_rw_regs(host, ecc->steps, true, 0); 1498 - break; 1499 - 1500 - case NAND_CMD_SEQIN: 1501 - WARN_ON(column != 0); 1502 - set_address(host, 0, page_addr); 1503 - break; 1504 - 1505 - case NAND_CMD_PAGEPROG: 1506 - case NAND_CMD_STATUS: 1507 - case NAND_CMD_NONE: 1508 - default: 1509 - break; 1510 - } 1511 - 1512 - if (ret) { 1513 - dev_err(nandc->dev, "failure executing command %d\n", 1514 - command); 1515 - free_descs(nandc); 1516 - return; 1517 - } 1518 - 1519 - if (wait) { 1520 - ret = submit_descs(nandc); 1521 - if (ret) 1522 - dev_err(nandc->dev, 1523 - "failure submitting descs for command %d\n", 1524 - command); 1525 - } 1526 - 1527 - free_descs(nandc); 1528 - 1529 - post_command(host, command); 1530 1535 } 1531 1536 1532 1537 /* ··· 2238 2531 } 2239 2532 2240 2533 return nand_prog_page_end_op(chip); 2241 - } 2242 - 2243 - /* 2244 - * the three functions below implement chip->legacy.read_byte(), 2245 - * chip->legacy.read_buf() and chip->legacy.write_buf() respectively. these 2246 - * aren't used for reading/writing page data, they are used for smaller data 2247 - * like reading id, status etc 2248 - */ 2249 - static uint8_t qcom_nandc_read_byte(struct nand_chip *chip) 2250 - { 2251 - struct qcom_nand_host *host = to_qcom_nand_host(chip); 2252 - struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip); 2253 - u8 *buf = nandc->data_buffer; 2254 - u8 ret = 0x0; 2255 - 2256 - if (host->last_command == NAND_CMD_STATUS) { 2257 - ret = host->status; 2258 - 2259 - host->status = NAND_STATUS_READY | NAND_STATUS_WP; 2260 - 2261 - return ret; 2262 - } 2263 - 2264 - if (nandc->buf_start < nandc->buf_count) 2265 - ret = buf[nandc->buf_start++]; 2266 - 2267 - return ret; 2268 - } 2269 - 2270 - static void qcom_nandc_read_buf(struct nand_chip *chip, uint8_t *buf, int len) 2271 - { 2272 - struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip); 2273 - int real_len = min_t(size_t, len, nandc->buf_count - nandc->buf_start); 2274 - 2275 - memcpy(buf, nandc->data_buffer + nandc->buf_start, real_len); 2276 - nandc->buf_start += real_len; 2277 - } 2278 - 2279 - static void qcom_nandc_write_buf(struct nand_chip *chip, const uint8_t *buf, 2280 - int len) 2281 - { 2282 - struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip); 2283 - int real_len = min_t(size_t, len, nandc->buf_count - nandc->buf_start); 2284 - 2285 - memcpy(nandc->data_buffer + nandc->buf_start, buf, real_len); 2286 - 2287 - nandc->buf_start += real_len; 2288 - } 2289 - 2290 - /* we support only one external chip for now */ 2291 - static void qcom_nandc_select_chip(struct nand_chip *chip, int chipnr) 2292 - { 2293 - struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip); 2294 - 2295 - if (chipnr <= 0) 2296 - return; 2297 - 2298 - dev_warn(nandc->dev, "invalid chip select\n"); 2299 2534 } 2300 2535 2301 2536 /* ··· 3311 3662 3312 3663 mtd->owner = THIS_MODULE; 3313 3664 mtd->dev.parent = dev; 3314 - 3315 - chip->legacy.cmdfunc = qcom_nandc_command; 3316 - chip->legacy.select_chip = qcom_nandc_select_chip; 3317 - chip->legacy.read_byte = qcom_nandc_read_byte; 3318 - chip->legacy.read_buf = qcom_nandc_read_buf; 3319 - chip->legacy.write_buf = qcom_nandc_write_buf; 3320 - chip->legacy.set_features = nand_get_set_features_notsupp; 3321 - chip->legacy.get_features = nand_get_set_features_notsupp; 3322 3665 3323 3666 /* 3324 3667 * the bad block marker is readable only when we read the last codeword