1 From 4bc5cec5361dd6a2ae3bd044c79a4b5227bb9627 Mon Sep 17 00:00:00 2001
2 From: Samuel Holland <samuel@sholland.org>
3 Date: Mon, 16 May 2022 00:47:32 -0500
4 Subject: [PATCH 35/90] mtd: nand: sunxi: Pass the device to the init function
6 This more closely matches the U-Boot driver to the Linux version.
11 mtd: nand: sunxi: Convert to devicetree and the driver model
12 This series converts the sunxi NAND driver to get its resources (clocks,
13 resets, pins) from the devicetree, and probe using the driver model.
15 In addition to the immediate cleanup, this allows backporting more
16 patches (bugfixes, newer SoC support) from the Linux driver.
19 Signed-off-by: Samuel Holland <samuel@sholland.org>
21 drivers/mtd/nand/raw/sunxi_nand.c | 39 ++++++++++++++++---------------
22 1 file changed, 20 insertions(+), 19 deletions(-)
24 --- a/drivers/mtd/nand/raw/sunxi_nand.c
25 +++ b/drivers/mtd/nand/raw/sunxi_nand.c
26 @@ -1604,7 +1604,8 @@ static int sunxi_nand_ecc_init(struct mt
30 -static int sunxi_nand_chip_init(ofnode np, struct sunxi_nfc *nfc, int devnum)
31 +static int sunxi_nand_chip_init(struct udevice *dev, struct sunxi_nfc *nfc,
32 + ofnode np, int devnum)
34 const struct nand_sdr_timings *timings;
35 struct sunxi_nand_chip *chip;
36 @@ -1620,7 +1621,7 @@ static int sunxi_nand_chip_init(ofnode n
39 if (!nsels || nsels > 8) {
40 - dev_err(nfc->dev, "invalid reg property size\n");
41 + dev_err(dev, "invalid reg property size\n");
45 @@ -1628,7 +1629,7 @@ static int sunxi_nand_chip_init(ofnode n
46 (nsels * sizeof(struct sunxi_nand_chip_sel)),
49 - dev_err(nfc->dev, "could not allocate chip\n");
50 + dev_err(dev, "could not allocate chip\n");
54 @@ -1638,19 +1639,19 @@ static int sunxi_nand_chip_init(ofnode n
55 for (i = 0; i < nsels; i++) {
56 ret = ofnode_read_u32_index(np, "reg", i, &tmp);
58 - dev_err(nfc->dev, "could not retrieve reg property: %d\n",
59 + dev_err(dev, "could not retrieve reg property: %d\n",
64 if (tmp > NFC_MAX_CS) {
67 "invalid reg value: %u (max CS = 7)\n", tmp);
71 if (test_and_set_bit(tmp, &nfc->assigned_cs)) {
72 - dev_err(nfc->dev, "CS %d already assigned\n", tmp);
73 + dev_err(dev, "CS %d already assigned\n", tmp);
77 @@ -1661,9 +1662,9 @@ static int sunxi_nand_chip_init(ofnode n
78 chip->sels[i].rb.type = RB_NATIVE;
79 chip->sels[i].rb.info.nativeid = tmp;
81 - ret = gpio_request_by_name_nodev(np, "rb-gpios", i,
82 - &chip->sels[i].rb.info.gpio,
84 + ret = gpio_request_by_name(dev, "rb-gpios", i,
85 + &chip->sels[i].rb.info.gpio,
88 chip->sels[i].rb.type = RB_GPIO;
90 @@ -1674,7 +1675,7 @@ static int sunxi_nand_chip_init(ofnode n
91 timings = onfi_async_timing_mode_to_sdr_timings(0);
92 if (IS_ERR(timings)) {
93 ret = PTR_ERR(timings);
96 "could not retrieve timings for ONFI mode 0: %d\n",
99 @@ -1682,7 +1683,7 @@ static int sunxi_nand_chip_init(ofnode n
101 ret = sunxi_nand_chip_set_timings(nfc, chip, timings);
103 - dev_err(nfc->dev, "could not configure chip timings: %d\n", ret);
104 + dev_err(dev, "could not configure chip timings: %d\n", ret);
108 @@ -1717,25 +1718,25 @@ static int sunxi_nand_chip_init(ofnode n
110 ret = sunxi_nand_chip_init_timings(nfc, chip);
112 - dev_err(nfc->dev, "could not configure chip timings: %d\n", ret);
113 + dev_err(dev, "could not configure chip timings: %d\n", ret);
117 ret = sunxi_nand_ecc_init(mtd, &nand->ecc);
119 - dev_err(nfc->dev, "ECC init failed: %d\n", ret);
120 + dev_err(dev, "ECC init failed: %d\n", ret);
124 ret = nand_scan_tail(mtd);
126 - dev_err(nfc->dev, "nand_scan_tail failed: %d\n", ret);
127 + dev_err(dev, "nand_scan_tail failed: %d\n", ret);
131 ret = nand_register(devnum, mtd);
133 - dev_err(nfc->dev, "failed to register mtd device: %d\n", ret);
134 + dev_err(dev, "failed to register mtd device: %d\n", ret);
138 @@ -1744,13 +1745,13 @@ static int sunxi_nand_chip_init(ofnode n
142 -static int sunxi_nand_chips_init(ofnode node, struct sunxi_nfc *nfc)
143 +static int sunxi_nand_chips_init(struct udevice *dev, struct sunxi_nfc *nfc)
148 - ofnode_for_each_subnode(nand_np, node) {
149 - ret = sunxi_nand_chip_init(nand_np, nfc, i++);
150 + dev_for_each_subnode(nand_np, dev) {
151 + ret = sunxi_nand_chip_init(dev, nfc, nand_np, i++);
155 @@ -1802,7 +1803,7 @@ static int sunxi_nand_probe(struct udevi
159 - ret = sunxi_nand_chips_init(dev_ofnode(dev), nfc);
160 + ret = sunxi_nand_chips_init(dev, nfc);
162 dev_err(dev, "failed to init nand chips\n");