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: rawnand: sunxi: rework pattern found registers

On H6/H616, the register ECC_PAT_FOUND is at its own address, and not
part of ECC status register.
So, introduce the pattern found register offset in sunxi_nfc_caps, along
with its mask.

Also, introduce a non compile-time field_get() because FIELD_GET() and
u32_get_bits() don't work with non compile-time constant.

No functional change.

Link: https://lore.kernel.org/all/cover.1761588465.git.geert+renesas@glider.be
Signed-off-by: Richard Genoud <richard.genoud@bootlin.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>

authored by

Richard Genoud and committed by
Miquel Raynal
6fc2619a f53c74d0

+31 -5
+31 -5
drivers/mtd/nand/raw/sunxi_nand.c
··· 29 29 #include <linux/iopoll.h> 30 30 #include <linux/reset.h> 31 31 32 + /* non compile-time field get */ 33 + #define field_get(_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) 34 + 32 35 #define NFC_REG_CTL 0x0000 33 36 #define NFC_REG_ST 0x0004 34 37 #define NFC_REG_INT 0x0008 ··· 153 150 /* define bit use in NFC_ECC_ST */ 154 151 #define NFC_ECC_ERR(x) BIT(x) 155 152 #define NFC_ECC_ERR_MSK GENMASK(15, 0) 156 - #define NFC_ECC_PAT_FOUND(x) BIT(x + 16) 153 + 154 + /* 155 + * define bit use in NFC_REG_PAT_FOUND 156 + * For A10/A23, NFC_REG_PAT_FOUND == NFC_ECC_ST register 157 + */ 158 + #define NFC_ECC_PAT_FOUND_MSK(nfc) (nfc->caps->pat_found_mask) 159 + 157 160 #define NFC_ECC_ERR_CNT(b, x) (((x) >> (((b) % 4) * 8)) & 0xff) 158 161 159 162 #define NFC_DEFAULT_TIMEOUT_MS 1000 ··· 236 227 * @reg_io_data: I/O data register 237 228 * @reg_ecc_err_cnt: ECC error counter register 238 229 * @reg_user_data: User data register 230 + * @reg_pat_found: Data Pattern Status Register 231 + * @pat_found_mask: ECC_PAT_FOUND mask in NFC_REG_PAT_FOUND register 239 232 * @dma_maxburst: DMA maxburst 240 233 * @ecc_strengths: Available ECC strengths array 241 234 * @nstrengths: Size of @ecc_strengths ··· 247 236 unsigned int reg_io_data; 248 237 unsigned int reg_ecc_err_cnt; 249 238 unsigned int reg_user_data; 239 + unsigned int reg_pat_found; 240 + unsigned int pat_found_mask; 250 241 unsigned int dma_maxburst; 251 242 const u8 *ecc_strengths; 252 243 unsigned int nstrengths; ··· 789 776 } 790 777 791 778 static int sunxi_nfc_hw_ecc_correct(struct nand_chip *nand, u8 *data, u8 *oob, 792 - int step, u32 status, bool *erased) 779 + int step, u32 status, u32 pattern_found, 780 + bool *erased) 793 781 { 794 782 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); 795 783 struct nand_ecc_ctrl *ecc = &nand->ecc; ··· 801 787 if (status & NFC_ECC_ERR(step)) 802 788 return -EBADMSG; 803 789 804 - if (status & NFC_ECC_PAT_FOUND(step)) { 790 + if (pattern_found & BIT(step)) { 805 791 u8 pattern; 806 792 807 793 if (unlikely(!(readl(nfc->regs + NFC_REG_PAT_ID) & 0x1))) { ··· 835 821 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); 836 822 struct nand_ecc_ctrl *ecc = &nand->ecc; 837 823 int raw_mode = 0; 824 + u32 pattern_found; 838 825 bool erased; 839 826 int ret; 840 827 ··· 863 848 864 849 *cur_off = oob_off + ecc->bytes + USER_DATA_SZ; 865 850 851 + pattern_found = readl(nfc->regs + nfc->caps->reg_pat_found); 852 + pattern_found = field_get(NFC_ECC_PAT_FOUND_MSK(nfc), pattern_found); 853 + 866 854 ret = sunxi_nfc_hw_ecc_correct(nand, data, oob_required ? oob : NULL, 0, 867 855 readl(nfc->regs + NFC_REG_ECC_ST), 856 + pattern_found, 868 857 &erased); 869 858 if (erased) 870 859 return 1; ··· 949 930 unsigned int max_bitflips = 0; 950 931 int ret, i, raw_mode = 0; 951 932 struct scatterlist sg; 952 - u32 status, wait; 933 + u32 status, pattern_found, wait; 953 934 954 935 ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); 955 936 if (ret) ··· 990 971 return ret; 991 972 992 973 status = readl(nfc->regs + NFC_REG_ECC_ST); 974 + pattern_found = readl(nfc->regs + nfc->caps->reg_pat_found); 975 + pattern_found = field_get(NFC_ECC_PAT_FOUND_MSK(nfc), pattern_found); 993 976 994 977 for (i = 0; i < nchunks; i++) { 995 978 int data_off = i * ecc->size; ··· 1002 981 1003 982 ret = sunxi_nfc_hw_ecc_correct(nand, randomized ? data : NULL, 1004 983 oob_required ? oob : NULL, 1005 - i, status, &erased); 984 + i, status, pattern_found, 985 + &erased); 1006 986 1007 987 /* ECC errors are handled in the second loop. */ 1008 988 if (ret < 0) ··· 2217 2195 .reg_io_data = NFC_REG_A10_IO_DATA, 2218 2196 .reg_ecc_err_cnt = NFC_REG_A10_ECC_ERR_CNT, 2219 2197 .reg_user_data = NFC_REG_A10_USER_DATA, 2198 + .reg_pat_found = NFC_REG_ECC_ST, 2199 + .pat_found_mask = GENMASK(31, 16), 2220 2200 .dma_maxburst = 4, 2221 2201 .ecc_strengths = sunxi_ecc_strengths_a10, 2222 2202 .nstrengths = ARRAY_SIZE(sunxi_ecc_strengths_a10), ··· 2229 2205 .reg_io_data = NFC_REG_A23_IO_DATA, 2230 2206 .reg_ecc_err_cnt = NFC_REG_A10_ECC_ERR_CNT, 2231 2207 .reg_user_data = NFC_REG_A10_USER_DATA, 2208 + .reg_pat_found = NFC_REG_ECC_ST, 2209 + .pat_found_mask = GENMASK(31, 16), 2232 2210 .dma_maxburst = 8, 2233 2211 .ecc_strengths = sunxi_ecc_strengths_a10, 2234 2212 .nstrengths = ARRAY_SIZE(sunxi_ecc_strengths_a10),