@@ -113,6 +113,36 @@ static int cypress_nor_octal_dtr_dis(struct spi_nor *nor)
113113 return 0 ;
114114}
115115
116+ /**
117+ * cypress_nor_set_page_size() - Set page size which corresponds to the flash
118+ * configuration.
119+ * @nor: pointer to a 'struct spi_nor'
120+ *
121+ * The BFPT table advertises a 512B or 256B page size depending on part but the
122+ * page size is actually configurable (with the default being 256B). Read from
123+ * CFR3V[4] and set the correct size.
124+ *
125+ * Return: 0 on success, -errno otherwise.
126+ */
127+ static int cypress_nor_set_page_size (struct spi_nor * nor )
128+ {
129+ struct spi_mem_op op =
130+ CYPRESS_NOR_RD_ANY_REG_OP (3 , SPINOR_REG_CYPRESS_CFR3V ,
131+ nor -> bouncebuf );
132+ int ret ;
133+
134+ ret = spi_nor_read_any_reg (nor , & op , nor -> reg_proto );
135+ if (ret )
136+ return ret ;
137+
138+ if (nor -> bouncebuf [0 ] & SPINOR_REG_CYPRESS_CFR3V_PGSZ )
139+ nor -> params -> page_size = 512 ;
140+ else
141+ nor -> params -> page_size = 256 ;
142+
143+ return 0 ;
144+ }
145+
116146/**
117147 * cypress_nor_octal_dtr_enable() - Enable octal DTR on Cypress flashes.
118148 * @nor: pointer to a 'struct spi_nor'
@@ -167,28 +197,7 @@ static int s28hs512t_post_bfpt_fixup(struct spi_nor *nor,
167197 const struct sfdp_parameter_header * bfpt_header ,
168198 const struct sfdp_bfpt * bfpt )
169199{
170- /*
171- * The BFPT table advertises a 512B page size but the page size is
172- * actually configurable (with the default being 256B). Read from
173- * CFR3V[4] and set the correct size.
174- */
175- struct spi_mem_op op =
176- CYPRESS_NOR_RD_ANY_REG_OP (3 , SPINOR_REG_CYPRESS_CFR3V ,
177- nor -> bouncebuf );
178- int ret ;
179-
180- spi_nor_spimem_setup_op (nor , & op , nor -> reg_proto );
181-
182- ret = spi_mem_exec_op (nor -> spimem , & op );
183- if (ret )
184- return ret ;
185-
186- if (nor -> bouncebuf [0 ] & SPINOR_REG_CYPRESS_CFR3V_PGSZ )
187- nor -> params -> page_size = 512 ;
188- else
189- nor -> params -> page_size = 256 ;
190-
191- return 0 ;
200+ return cypress_nor_set_page_size (nor );
192201}
193202
194203static const struct spi_nor_fixups s28hs512t_fixups = {
0 commit comments