@@ -249,9 +249,11 @@ static const struct mtd_ooblayout_ops qcom_spi_ooblayout = {
249
249
static int qcom_spi_ecc_init_ctx_pipelined (struct nand_device * nand )
250
250
{
251
251
struct qcom_nand_controller * snandc = nand_to_qcom_snand (nand );
252
+ struct nand_ecc_props * reqs = & nand -> ecc .requirements ;
253
+ struct nand_ecc_props * user = & nand -> ecc .user_conf ;
252
254
struct nand_ecc_props * conf = & nand -> ecc .ctx .conf ;
253
255
struct mtd_info * mtd = nanddev_to_mtd (nand );
254
- int cwperpage , bad_block_byte ;
256
+ int cwperpage , bad_block_byte , ret ;
255
257
struct qpic_ecc * ecc_cfg ;
256
258
257
259
cwperpage = mtd -> writesize / NANDC_STEP_SIZE ;
@@ -260,11 +262,39 @@ static int qcom_spi_ecc_init_ctx_pipelined(struct nand_device *nand)
260
262
ecc_cfg = kzalloc (sizeof (* ecc_cfg ), GFP_KERNEL );
261
263
if (!ecc_cfg )
262
264
return - ENOMEM ;
265
+
266
+ if (user -> step_size && user -> strength ) {
267
+ ecc_cfg -> step_size = user -> step_size ;
268
+ ecc_cfg -> strength = user -> strength ;
269
+ } else if (reqs -> step_size && reqs -> strength ) {
270
+ ecc_cfg -> step_size = reqs -> step_size ;
271
+ ecc_cfg -> strength = reqs -> strength ;
272
+ } else {
273
+ /* use defaults */
274
+ ecc_cfg -> step_size = NANDC_STEP_SIZE ;
275
+ ecc_cfg -> strength = 4 ;
276
+ }
277
+
278
+ if (ecc_cfg -> step_size != NANDC_STEP_SIZE ) {
279
+ dev_err (snandc -> dev ,
280
+ "only %u bytes ECC step size is supported\n" ,
281
+ NANDC_STEP_SIZE );
282
+ ret = - EOPNOTSUPP ;
283
+ goto err_free_ecc_cfg ;
284
+ }
285
+
286
+ if (ecc_cfg -> strength != 4 ) {
287
+ dev_err (snandc -> dev ,
288
+ "only 4 bits ECC strength is supported\n" );
289
+ ret = - EOPNOTSUPP ;
290
+ goto err_free_ecc_cfg ;
291
+ }
292
+
263
293
snandc -> qspi -> oob_buf = kmalloc (mtd -> writesize + mtd -> oobsize ,
264
294
GFP_KERNEL );
265
295
if (!snandc -> qspi -> oob_buf ) {
266
- kfree ( ecc_cfg ) ;
267
- return - ENOMEM ;
296
+ ret = - ENOMEM ;
297
+ goto err_free_ecc_cfg ;
268
298
}
269
299
270
300
memset (snandc -> qspi -> oob_buf , 0xff , mtd -> writesize + mtd -> oobsize );
@@ -279,8 +309,6 @@ static int qcom_spi_ecc_init_ctx_pipelined(struct nand_device *nand)
279
309
ecc_cfg -> bytes = ecc_cfg -> ecc_bytes_hw + ecc_cfg -> spare_bytes + ecc_cfg -> bbm_size ;
280
310
281
311
ecc_cfg -> steps = 4 ;
282
- ecc_cfg -> strength = 4 ;
283
- ecc_cfg -> step_size = 512 ;
284
312
ecc_cfg -> cw_data = 516 ;
285
313
ecc_cfg -> cw_size = ecc_cfg -> cw_data + ecc_cfg -> bytes ;
286
314
bad_block_byte = mtd -> writesize - ecc_cfg -> cw_size * (cwperpage - 1 ) + 1 ;
@@ -338,6 +366,10 @@ static int qcom_spi_ecc_init_ctx_pipelined(struct nand_device *nand)
338
366
ecc_cfg -> strength , ecc_cfg -> step_size );
339
367
340
368
return 0 ;
369
+
370
+ err_free_ecc_cfg :
371
+ kfree (ecc_cfg );
372
+ return ret ;
341
373
}
342
374
343
375
static void qcom_spi_ecc_cleanup_ctx_pipelined (struct nand_device * nand )
0 commit comments