Skip to content

Commit 1db50b9

Browse files
Ansuelmiquelraynal
authored andcommitted
mtd: rawnand: qcom: finish converting register to FIELD_PREP
With some research in some obscure old QSDK, it was possible to find the MASK of the last register there were still set with raw shift and convert them to FIELD_PREP API. This is only a cleanup and modernize the code a bit and doesn't make any behaviour change. Signed-off-by: Christian Marangi <[email protected]> Signed-off-by: Miquel Raynal <[email protected]>
1 parent a3b219e commit 1db50b9

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

drivers/mtd/nand/raw/qcom_nandc.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ static void nandc_set_read_loc_first(struct nand_chip *chip,
165165
{
166166
struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip);
167167
__le32 locreg_val;
168-
u32 val = (((cw_offset) << READ_LOCATION_OFFSET) |
169-
((read_size) << READ_LOCATION_SIZE) |
170-
((is_last_read_loc) << READ_LOCATION_LAST));
168+
u32 val = FIELD_PREP(READ_LOCATION_OFFSET_MASK, cw_offset) |
169+
FIELD_PREP(READ_LOCATION_SIZE_MASK, read_size) |
170+
FIELD_PREP(READ_LOCATION_LAST_MASK, is_last_read_loc);
171171

172172
locreg_val = cpu_to_le32(val);
173173

@@ -197,9 +197,9 @@ static void nandc_set_read_loc_last(struct nand_chip *chip,
197197
{
198198
struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip);
199199
__le32 locreg_val;
200-
u32 val = (((cw_offset) << READ_LOCATION_OFFSET) |
201-
((read_size) << READ_LOCATION_SIZE) |
202-
((is_last_read_loc) << READ_LOCATION_LAST));
200+
u32 val = FIELD_PREP(READ_LOCATION_OFFSET_MASK, cw_offset) |
201+
FIELD_PREP(READ_LOCATION_SIZE_MASK, read_size) |
202+
FIELD_PREP(READ_LOCATION_LAST_MASK, is_last_read_loc);
203203

204204
locreg_val = cpu_to_le32(val);
205205

@@ -271,14 +271,14 @@ static void update_rw_regs(struct qcom_nand_host *host, int num_cw, bool read, i
271271
}
272272

273273
if (host->use_ecc) {
274-
cfg0 = cpu_to_le32((host->cfg0 & ~(7U << CW_PER_PAGE)) |
275-
(num_cw - 1) << CW_PER_PAGE);
274+
cfg0 = cpu_to_le32((host->cfg0 & ~CW_PER_PAGE_MASK) |
275+
FIELD_PREP(CW_PER_PAGE_MASK, (num_cw - 1)));
276276

277277
cfg1 = cpu_to_le32(host->cfg1);
278278
ecc_bch_cfg = cpu_to_le32(host->ecc_bch_cfg);
279279
} else {
280-
cfg0 = cpu_to_le32((host->cfg0_raw & ~(7U << CW_PER_PAGE)) |
281-
(num_cw - 1) << CW_PER_PAGE);
280+
cfg0 = cpu_to_le32((host->cfg0_raw & ~CW_PER_PAGE_MASK) |
281+
FIELD_PREP(CW_PER_PAGE_MASK, (num_cw - 1)));
282282

283283
cfg1 = cpu_to_le32(host->cfg1_raw);
284284
ecc_bch_cfg = cpu_to_le32(ECC_CFG_ECC_DISABLE);
@@ -882,12 +882,12 @@ static void qcom_nandc_codeword_fixup(struct qcom_nand_host *host, int page)
882882
host->bbm_size - host->cw_data;
883883

884884
host->cfg0 &= ~(SPARE_SIZE_BYTES_MASK | UD_SIZE_BYTES_MASK);
885-
host->cfg0 |= host->spare_bytes << SPARE_SIZE_BYTES |
886-
host->cw_data << UD_SIZE_BYTES;
885+
host->cfg0 |= FIELD_PREP(SPARE_SIZE_BYTES_MASK, host->spare_bytes) |
886+
FIELD_PREP(UD_SIZE_BYTES_MASK, host->cw_data);
887887

888888
host->ecc_bch_cfg &= ~ECC_NUM_DATA_BYTES_MASK;
889-
host->ecc_bch_cfg |= host->cw_data << ECC_NUM_DATA_BYTES;
890-
host->ecc_buf_cfg = (host->cw_data - 1) << NUM_STEPS;
889+
host->ecc_bch_cfg |= FIELD_PREP(ECC_NUM_DATA_BYTES_MASK, host->cw_data);
890+
host->ecc_buf_cfg = FIELD_PREP(NUM_STEPS_MASK, host->cw_data - 1);
891891
}
892892

893893
/* implements ecc->read_page() */
@@ -1531,7 +1531,7 @@ static int qcom_nand_attach_chip(struct nand_chip *chip)
15311531
FIELD_PREP(ECC_PARITY_SIZE_BYTES_BCH_MASK, host->ecc_bytes_hw);
15321532

15331533
if (!nandc->props->qpic_version2)
1534-
host->ecc_buf_cfg = 0x203 << NUM_STEPS;
1534+
host->ecc_buf_cfg = FIELD_PREP(NUM_STEPS_MASK, 0x203);
15351535

15361536
host->clrflashstatus = FS_READY_BSY_N;
15371537
host->clrreadstatus = 0xc0;
@@ -1817,7 +1817,7 @@ static int qcom_misc_cmd_type_exec(struct nand_chip *chip, const struct nand_sub
18171817
q_op.cmd_reg |= cpu_to_le32(PAGE_ACC | LAST_PAGE);
18181818
nandc->regs->addr0 = q_op.addr1_reg;
18191819
nandc->regs->addr1 = q_op.addr2_reg;
1820-
nandc->regs->cfg0 = cpu_to_le32(host->cfg0_raw & ~(7 << CW_PER_PAGE));
1820+
nandc->regs->cfg0 = cpu_to_le32(host->cfg0_raw & ~CW_PER_PAGE_MASK);
18211821
nandc->regs->cfg1 = cpu_to_le32(host->cfg1_raw);
18221822
instrs = 3;
18231823
} else if (q_op.cmd_reg != cpu_to_le32(OP_RESET_DEVICE)) {
@@ -1900,8 +1900,8 @@ static int qcom_param_page_type_exec(struct nand_chip *chip, const struct nand_
19001900
/* configure CMD1 and VLD for ONFI param probing in QPIC v1 */
19011901
if (!nandc->props->qpic_version2) {
19021902
nandc->regs->vld = cpu_to_le32((nandc->vld & ~READ_START_VLD));
1903-
nandc->regs->cmd1 = cpu_to_le32((nandc->cmd1 & ~(0xFF << READ_ADDR))
1904-
| NAND_CMD_PARAM << READ_ADDR);
1903+
nandc->regs->cmd1 = cpu_to_le32((nandc->cmd1 & ~READ_ADDR_MASK) |
1904+
FIELD_PREP(READ_ADDR_MASK, NAND_CMD_PARAM));
19051905
}
19061906

19071907
nandc->regs->exec = cpu_to_le32(1);

include/linux/mtd/nand-qpic-common.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
#define ECC_FORCE_CLK_OPEN BIT(30)
109109

110110
/* NAND_DEV_CMD1 bits */
111-
#define READ_ADDR 0
111+
#define READ_ADDR_MASK GENMASK(7, 0)
112112

113113
/* NAND_DEV_CMD_VLD bits */
114114
#define READ_START_VLD BIT(0)
@@ -119,6 +119,7 @@
119119

120120
/* NAND_EBI2_ECC_BUF_CFG bits */
121121
#define NUM_STEPS 0
122+
#define NUM_STEPS_MASK GENMASK(9, 0)
122123

123124
/* NAND_ERASED_CW_DETECT_CFG bits */
124125
#define ERASED_CW_ECC_MASK 1
@@ -139,8 +140,11 @@
139140

140141
/* NAND_READ_LOCATION_n bits */
141142
#define READ_LOCATION_OFFSET 0
143+
#define READ_LOCATION_OFFSET_MASK GENMASK(9, 0)
142144
#define READ_LOCATION_SIZE 16
145+
#define READ_LOCATION_SIZE_MASK GENMASK(25, 16)
143146
#define READ_LOCATION_LAST 31
147+
#define READ_LOCATION_LAST_MASK BIT(31)
144148

145149
/* Version Mask */
146150
#define NAND_VERSION_MAJOR_MASK 0xf0000000

0 commit comments

Comments
 (0)