Skip to content

Commit 6a3cec6

Browse files
committed
mtd: rawnand: qcom: convert driver to nand_scan()
Two helpers have been added to the core to do all kind of controller side configuration/initialization between the detection phase and the final NAND scan. Implement these hooks so that we can convert the driver to just use nand_scan() instead of the nand_scan_ident() + nand_scan_tail() pair. Signed-off-by: Miquel Raynal <[email protected]> Reviewed-by: Boris Brezillon <[email protected]>
1 parent fe13ae0 commit 6a3cec6

File tree

1 file changed

+24
-47
lines changed

1 file changed

+24
-47
lines changed

drivers/mtd/nand/raw/qcom_nandc.c

Lines changed: 24 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,10 +2475,10 @@ qcom_nandc_calc_ecc_bytes(int step_size, int strength)
24752475
NAND_ECC_CAPS_SINGLE(qcom_nandc_ecc_caps, qcom_nandc_calc_ecc_bytes,
24762476
NANDC_STEP_SIZE, 4, 8);
24772477

2478-
static int qcom_nand_host_setup(struct qcom_nand_host *host)
2478+
static int qcom_nand_attach_chip(struct nand_chip *chip)
24792479
{
2480-
struct nand_chip *chip = &host->chip;
24812480
struct mtd_info *mtd = nand_to_mtd(chip);
2481+
struct qcom_nand_host *host = to_qcom_nand_host(chip);
24822482
struct nand_ecc_ctrl *ecc = &chip->ecc;
24832483
struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip);
24842484
int cwperpage, bad_block_byte, ret;
@@ -2640,6 +2640,10 @@ static int qcom_nand_host_setup(struct qcom_nand_host *host)
26402640
return 0;
26412641
}
26422642

2643+
static const struct nand_controller_ops qcom_nandc_ops = {
2644+
.attach_chip = qcom_nand_attach_chip,
2645+
};
2646+
26432647
static int qcom_nandc_alloc(struct qcom_nand_controller *nandc)
26442648
{
26452649
int ret;
@@ -2729,6 +2733,7 @@ static int qcom_nandc_alloc(struct qcom_nand_controller *nandc)
27292733
INIT_LIST_HEAD(&nandc->host_list);
27302734

27312735
nand_controller_init(&nandc->controller);
2736+
nandc->controller.ops = &qcom_nandc_ops;
27322737

27332738
return 0;
27342739
}
@@ -2781,9 +2786,9 @@ static int qcom_nandc_setup(struct qcom_nand_controller *nandc)
27812786
return 0;
27822787
}
27832788

2784-
static int qcom_nand_host_init(struct qcom_nand_controller *nandc,
2785-
struct qcom_nand_host *host,
2786-
struct device_node *dn)
2789+
static int qcom_nand_host_init_and_register(struct qcom_nand_controller *nandc,
2790+
struct qcom_nand_host *host,
2791+
struct device_node *dn)
27872792
{
27882793
struct nand_chip *chip = &host->chip;
27892794
struct mtd_info *mtd = nand_to_mtd(chip);
@@ -2830,30 +2835,13 @@ static int qcom_nand_host_init(struct qcom_nand_controller *nandc,
28302835
/* set up initial status value */
28312836
host->status = NAND_STATUS_READY | NAND_STATUS_WP;
28322837

2833-
ret = nand_scan_ident(mtd, 1, NULL);
2834-
if (ret)
2835-
return ret;
2836-
2837-
ret = qcom_nand_host_setup(host);
2838-
2839-
return ret;
2840-
}
2841-
2842-
static int qcom_nand_mtd_register(struct qcom_nand_controller *nandc,
2843-
struct qcom_nand_host *host,
2844-
struct device_node *dn)
2845-
{
2846-
struct nand_chip *chip = &host->chip;
2847-
struct mtd_info *mtd = nand_to_mtd(chip);
2848-
int ret;
2849-
2850-
ret = nand_scan_tail(mtd);
2838+
ret = nand_scan(mtd, 1);
28512839
if (ret)
28522840
return ret;
28532841

28542842
ret = mtd_device_register(mtd, NULL, 0);
28552843
if (ret)
2856-
nand_cleanup(mtd_to_nand(mtd));
2844+
nand_cleanup(chip);
28572845

28582846
return ret;
28592847
}
@@ -2862,28 +2850,9 @@ static int qcom_probe_nand_devices(struct qcom_nand_controller *nandc)
28622850
{
28632851
struct device *dev = nandc->dev;
28642852
struct device_node *dn = dev->of_node, *child;
2865-
struct qcom_nand_host *host, *tmp;
2853+
struct qcom_nand_host *host;
28662854
int ret;
28672855

2868-
for_each_available_child_of_node(dn, child) {
2869-
host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL);
2870-
if (!host) {
2871-
of_node_put(child);
2872-
return -ENOMEM;
2873-
}
2874-
2875-
ret = qcom_nand_host_init(nandc, host, child);
2876-
if (ret) {
2877-
devm_kfree(dev, host);
2878-
continue;
2879-
}
2880-
2881-
list_add_tail(&host->node, &nandc->host_list);
2882-
}
2883-
2884-
if (list_empty(&nandc->host_list))
2885-
return -ENODEV;
2886-
28872856
if (nandc->props->is_bam) {
28882857
free_bam_transaction(nandc);
28892858
nandc->bam_txn = alloc_bam_transaction(nandc);
@@ -2894,12 +2863,20 @@ static int qcom_probe_nand_devices(struct qcom_nand_controller *nandc)
28942863
}
28952864
}
28962865

2897-
list_for_each_entry_safe(host, tmp, &nandc->host_list, node) {
2898-
ret = qcom_nand_mtd_register(nandc, host, child);
2866+
for_each_available_child_of_node(dn, child) {
2867+
host = devm_kzalloc(dev, sizeof(*host), GFP_KERNEL);
2868+
if (!host) {
2869+
of_node_put(child);
2870+
return -ENOMEM;
2871+
}
2872+
2873+
ret = qcom_nand_host_init_and_register(nandc, host, child);
28992874
if (ret) {
2900-
list_del(&host->node);
29012875
devm_kfree(dev, host);
2876+
continue;
29022877
}
2878+
2879+
list_add_tail(&host->node, &nandc->host_list);
29032880
}
29042881

29052882
if (list_empty(&nandc->host_list))

0 commit comments

Comments
 (0)