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

Configure Feed

Select the types of activity you want to include in your feed.

mtd: spinand: Make use of the operation templates through SPINAND_OP()

Create a SPINAND_OP() macro to which we give the name of the operation
we want. This macro retrieves the correct operation template based on
the current bus interface (currently only single SDR, will soon be
extended to octal DTR) and fills it with the usual parameters.

This macro makes the transition from calling directly the low-level
macros into using the (bus interface dependent) templates very smooth.
Use it in all places that can be trivially converted. At this stage
there is no functional change expected, until octal DTR support gets
added.

Reviewed-by: Tudor Ambarus <tudor.ambarus@linaro.org>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>

+121 -27
+97 -13
drivers/mtd/nand/spi/core.c
··· 20 20 #include <linux/spi/spi.h> 21 21 #include <linux/spi/spi-mem.h> 22 22 23 + static struct spi_mem_op 24 + spinand_fill_reset_op(struct spinand_device *spinand) 25 + { 26 + return spinand->op_templates->reset; 27 + } 28 + 29 + static struct spi_mem_op 30 + spinand_fill_readid_op(struct spinand_device *spinand, 31 + u8 naddr, u8 ndummy, void *buf, unsigned int len) 32 + { 33 + struct spi_mem_op op = spinand->op_templates->readid; 34 + 35 + op.addr.nbytes = naddr; 36 + op.dummy.nbytes = ndummy; 37 + op.data.buf.in = buf; 38 + op.data.nbytes = len; 39 + 40 + return op; 41 + } 42 + 43 + struct spi_mem_op 44 + spinand_fill_wr_en_op(struct spinand_device *spinand) 45 + { 46 + return spinand->op_templates->wr_en; 47 + } 48 + 49 + static __maybe_unused struct spi_mem_op 50 + spinand_fill_wr_dis_op(struct spinand_device *spinand) 51 + { 52 + return spinand->op_templates->wr_dis; 53 + } 54 + 55 + struct spi_mem_op 56 + spinand_fill_set_feature_op(struct spinand_device *spinand, u64 reg, const void *valptr) 57 + { 58 + struct spi_mem_op op = spinand->op_templates->set_feature; 59 + 60 + op.addr.val = reg; 61 + op.data.buf.out = valptr; 62 + 63 + return op; 64 + } 65 + 66 + struct spi_mem_op 67 + spinand_fill_get_feature_op(struct spinand_device *spinand, u64 reg, void *valptr) 68 + { 69 + struct spi_mem_op op = spinand->op_templates->get_feature; 70 + 71 + op.addr.val = reg; 72 + op.data.buf.in = valptr; 73 + 74 + return op; 75 + } 76 + 77 + static struct spi_mem_op 78 + spinand_fill_blk_erase_op(struct spinand_device *spinand, u64 addr) 79 + { 80 + struct spi_mem_op op = spinand->op_templates->blk_erase; 81 + 82 + op.addr.val = addr; 83 + 84 + return op; 85 + } 86 + 87 + static struct spi_mem_op 88 + spinand_fill_page_read_op(struct spinand_device *spinand, u64 addr) 89 + { 90 + struct spi_mem_op op = spinand->op_templates->page_read; 91 + 92 + op.addr.val = addr; 93 + 94 + return op; 95 + } 96 + 97 + struct spi_mem_op 98 + spinand_fill_prog_exec_op(struct spinand_device *spinand, u64 addr) 99 + { 100 + struct spi_mem_op op = spinand->op_templates->prog_exec; 101 + 102 + op.addr.val = addr; 103 + 104 + return op; 105 + } 106 + 23 107 int spinand_read_reg_op(struct spinand_device *spinand, u8 reg, u8 *val) 24 108 { 25 - struct spi_mem_op op = SPINAND_GET_FEATURE_1S_1S_1S_OP(reg, 26 - spinand->scratchbuf); 109 + struct spi_mem_op op = SPINAND_OP(spinand, get_feature, 110 + reg, spinand->scratchbuf); 27 111 int ret; 28 112 29 113 ret = spi_mem_exec_op(spinand->spimem, &op); ··· 120 36 121 37 int spinand_write_reg_op(struct spinand_device *spinand, u8 reg, u8 val) 122 38 { 123 - struct spi_mem_op op = SPINAND_SET_FEATURE_1S_1S_1S_OP(reg, 124 - spinand->scratchbuf); 39 + struct spi_mem_op op = SPINAND_OP(spinand, set_feature, 40 + reg, spinand->scratchbuf); 125 41 126 42 *spinand->scratchbuf = val; 127 43 return spi_mem_exec_op(spinand->spimem, &op); ··· 446 362 447 363 int spinand_write_enable_op(struct spinand_device *spinand) 448 364 { 449 - struct spi_mem_op op = SPINAND_WR_EN_1S_0_0_OP; 365 + struct spi_mem_op op = SPINAND_OP(spinand, wr_en); 450 366 451 367 return spi_mem_exec_op(spinand->spimem, &op); 452 368 } ··· 456 372 { 457 373 struct nand_device *nand = spinand_to_nand(spinand); 458 374 unsigned int row = nanddev_pos_to_row(nand, &req->pos); 459 - struct spi_mem_op op = SPINAND_PAGE_READ_1S_1S_0_OP(row); 375 + struct spi_mem_op op = SPINAND_OP(spinand, page_read, row); 460 376 461 377 return spi_mem_exec_op(spinand->spimem, &op); 462 378 } ··· 611 527 { 612 528 struct nand_device *nand = spinand_to_nand(spinand); 613 529 unsigned int row = nanddev_pos_to_row(nand, &req->pos); 614 - struct spi_mem_op op = SPINAND_PROG_EXEC_1S_1S_0_OP(row); 530 + struct spi_mem_op op = SPINAND_OP(spinand, prog_exec, row); 615 531 616 532 return spi_mem_exec_op(spinand->spimem, &op); 617 533 } ··· 621 537 { 622 538 struct nand_device *nand = spinand_to_nand(spinand); 623 539 unsigned int row = nanddev_pos_to_row(nand, pos); 624 - struct spi_mem_op op = SPINAND_BLK_ERASE_1S_1S_0_OP(row); 540 + struct spi_mem_op op = SPINAND_OP(spinand, blk_erase, row); 625 541 626 542 return spi_mem_exec_op(spinand->spimem, &op); 627 543 } ··· 641 557 int spinand_wait(struct spinand_device *spinand, unsigned long initial_delay_us, 642 558 unsigned long poll_delay_us, u8 *s) 643 559 { 644 - struct spi_mem_op op = SPINAND_GET_FEATURE_1S_1S_1S_OP(REG_STATUS, 645 - spinand->scratchbuf); 560 + struct spi_mem_op op = SPINAND_OP(spinand, get_feature, 561 + REG_STATUS, spinand->scratchbuf); 646 562 u8 status; 647 563 int ret; 648 564 ··· 675 591 static int spinand_read_id_op(struct spinand_device *spinand, u8 naddr, 676 592 u8 ndummy, u8 *buf) 677 593 { 678 - struct spi_mem_op op = SPINAND_READID_1S_1S_1S_OP( 679 - naddr, ndummy, spinand->scratchbuf, SPINAND_MAX_ID_LEN); 594 + struct spi_mem_op op = SPINAND_OP(spinand, readid, 595 + naddr, ndummy, spinand->scratchbuf, SPINAND_MAX_ID_LEN); 680 596 int ret; 681 597 682 598 ret = spi_mem_exec_op(spinand->spimem, &op); ··· 688 604 689 605 static int spinand_reset_op(struct spinand_device *spinand) 690 606 { 691 - struct spi_mem_op op = SPINAND_RESET_1S_0_0_OP; 607 + struct spi_mem_op op = SPINAND_OP(spinand, reset); 692 608 int ret; 693 609 694 610 ret = spi_mem_exec_op(spinand->spimem, &op);
+2 -2
drivers/mtd/nand/spi/esmt.c
··· 138 138 static int f50l1g41lb_otp_lock(struct spinand_device *spinand, loff_t from, 139 139 size_t len) 140 140 { 141 - struct spi_mem_op write_op = SPINAND_WR_EN_1S_0_0_OP; 142 - struct spi_mem_op exec_op = SPINAND_PROG_EXEC_1S_1S_0_OP(0); 141 + struct spi_mem_op write_op = SPINAND_OP(spinand, wr_en); 142 + struct spi_mem_op exec_op = SPINAND_OP(spinand, prog_exec, 0); 143 143 u8 status; 144 144 int ret; 145 145
+4 -4
drivers/mtd/nand/spi/gigadevice.c
··· 266 266 u8 status) 267 267 { 268 268 u8 status2; 269 - struct spi_mem_op op = SPINAND_GET_FEATURE_1S_1S_1S_OP(GD5FXGQXXEXXG_REG_STATUS2, 270 - spinand->scratchbuf); 269 + struct spi_mem_op op = SPINAND_OP(spinand, get_feature, 270 + GD5FXGQXXEXXG_REG_STATUS2, spinand->scratchbuf); 271 271 int ret; 272 272 273 273 switch (status & STATUS_ECC_MASK) { ··· 309 309 u8 status) 310 310 { 311 311 u8 status2; 312 - struct spi_mem_op op = SPINAND_GET_FEATURE_1S_1S_1S_OP(GD5FXGQXXEXXG_REG_STATUS2, 313 - spinand->scratchbuf); 312 + struct spi_mem_op op = SPINAND_OP(spinand, get_feature, 313 + GD5FXGQXXEXXG_REG_STATUS2, spinand->scratchbuf); 314 314 int ret; 315 315 316 316 switch (status & STATUS_ECC_MASK) {
+2 -2
drivers/mtd/nand/spi/macronix.c
··· 148 148 static int macronix_set_read_retry(struct spinand_device *spinand, 149 149 unsigned int retry_mode) 150 150 { 151 - struct spi_mem_op op = SPINAND_SET_FEATURE_1S_1S_1S_OP(MACRONIX_FEATURE_ADDR_READ_RETRY, 152 - spinand->scratchbuf); 151 + struct spi_mem_op op = SPINAND_OP(spinand, set_feature, 152 + MACRONIX_FEATURE_ADDR_READ_RETRY, spinand->scratchbuf); 153 153 154 154 *spinand->scratchbuf = retry_mode; 155 155 return spi_mem_exec_op(spinand->spimem, &op);
+4 -4
drivers/mtd/nand/spi/micron.c
··· 137 137 static int micron_select_target(struct spinand_device *spinand, 138 138 unsigned int target) 139 139 { 140 - struct spi_mem_op op = SPINAND_SET_FEATURE_1S_1S_1S_OP(MICRON_DIE_SELECT_REG, 141 - spinand->scratchbuf); 140 + struct spi_mem_op op = SPINAND_OP(spinand, set_feature, 141 + MICRON_DIE_SELECT_REG, spinand->scratchbuf); 142 142 143 143 if (target > 1) 144 144 return -EINVAL; ··· 251 251 static int mt29f2g01abagd_otp_lock(struct spinand_device *spinand, loff_t from, 252 252 size_t len) 253 253 { 254 - struct spi_mem_op write_op = SPINAND_WR_EN_1S_0_0_OP; 255 - struct spi_mem_op exec_op = SPINAND_PROG_EXEC_1S_1S_0_OP(0); 254 + struct spi_mem_op write_op = SPINAND_OP(spinand, wr_en); 255 + struct spi_mem_op exec_op = SPINAND_OP(spinand, prog_exec, 0); 256 256 u8 status; 257 257 int ret; 258 258
+2 -1
drivers/mtd/nand/spi/toshiba.c
··· 73 73 { 74 74 struct nand_device *nand = spinand_to_nand(spinand); 75 75 u8 mbf = 0; 76 - struct spi_mem_op op = SPINAND_GET_FEATURE_1S_1S_1S_OP(0x30, spinand->scratchbuf); 76 + struct spi_mem_op op = SPINAND_OP(spinand, get_feature, 77 + 0x30, spinand->scratchbuf); 77 78 78 79 switch (status & STATUS_ECC_MASK) { 79 80 case STATUS_ECC_NO_BITFLIPS:
+2 -1
drivers/mtd/nand/spi/winbond.c
··· 251 251 { 252 252 struct nand_device *nand = spinand_to_nand(spinand); 253 253 u8 mbf = 0; 254 - struct spi_mem_op op = SPINAND_GET_FEATURE_1S_1S_1S_OP(0x30, spinand->scratchbuf); 254 + struct spi_mem_op op = SPINAND_OP(spinand, get_feature, 255 + 0x30, spinand->scratchbuf); 255 256 256 257 switch (status & STATUS_ECC_MASK) { 257 258 case STATUS_ECC_NO_BITFLIPS:
+8
include/linux/mtd/spinand.h
··· 703 703 unsigned int retry_mode); 704 704 }; 705 705 706 + struct spi_mem_op spinand_fill_wr_en_op(struct spinand_device *spinand); 707 + struct spi_mem_op spinand_fill_set_feature_op(struct spinand_device *spinand, u64 reg, const void *valptr); 708 + struct spi_mem_op spinand_fill_get_feature_op(struct spinand_device *spinand, u64 reg, void *valptr); 709 + struct spi_mem_op spinand_fill_prog_exec_op(struct spinand_device *spinand, u64 addr); 710 + 711 + #define SPINAND_OP(spinand, op_name, ...) \ 712 + spinand_fill_ ## op_name ## _op(spinand, ##__VA_ARGS__) 713 + 706 714 /** 707 715 * mtd_to_spinand() - Get the SPI NAND device attached to an MTD instance 708 716 * @mtd: MTD instance