uboot-d1: add bootloader for upcoming d1 target
[openwrt/staging/981213.git] / package / boot / uboot-d1 / patches / 0035-mtd-nand-sunxi-Pass-the-device-to-the-init-function.patch
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
5
6 This more closely matches the U-Boot driver to the Linux version.
7
8 Series-to: sunxi
9
10 Cover-letter:
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.
14
15 In addition to the immediate cleanup, this allows backporting more
16 patches (bugfixes, newer SoC support) from the Linux driver.
17 END
18
19 Signed-off-by: Samuel Holland <samuel@sholland.org>
20 ---
21 drivers/mtd/nand/raw/sunxi_nand.c | 39 ++++++++++++++++---------------
22 1 file changed, 20 insertions(+), 19 deletions(-)
23
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
27 return 0;
28 }
29
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)
33 {
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
37
38 nsels /= sizeof(u32);
39 if (!nsels || nsels > 8) {
40 - dev_err(nfc->dev, "invalid reg property size\n");
41 + dev_err(dev, "invalid reg property size\n");
42 return -EINVAL;
43 }
44
45 @@ -1628,7 +1629,7 @@ static int sunxi_nand_chip_init(ofnode n
46 (nsels * sizeof(struct sunxi_nand_chip_sel)),
47 GFP_KERNEL);
48 if (!chip) {
49 - dev_err(nfc->dev, "could not allocate chip\n");
50 + dev_err(dev, "could not allocate chip\n");
51 return -ENOMEM;
52 }
53
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);
57 if (ret) {
58 - dev_err(nfc->dev, "could not retrieve reg property: %d\n",
59 + dev_err(dev, "could not retrieve reg property: %d\n",
60 ret);
61 return ret;
62 }
63
64 if (tmp > NFC_MAX_CS) {
65 - dev_err(nfc->dev,
66 + dev_err(dev,
67 "invalid reg value: %u (max CS = 7)\n", tmp);
68 return -EINVAL;
69 }
70
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);
74 return -EINVAL;
75 }
76
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;
80 } else {
81 - ret = gpio_request_by_name_nodev(np, "rb-gpios", i,
82 - &chip->sels[i].rb.info.gpio,
83 - GPIOD_IS_IN);
84 + ret = gpio_request_by_name(dev, "rb-gpios", i,
85 + &chip->sels[i].rb.info.gpio,
86 + GPIOD_IS_IN);
87 if (ret)
88 chip->sels[i].rb.type = RB_GPIO;
89 else
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);
94 - dev_err(nfc->dev,
95 + dev_err(dev,
96 "could not retrieve timings for ONFI mode 0: %d\n",
97 ret);
98 return ret;
99 @@ -1682,7 +1683,7 @@ static int sunxi_nand_chip_init(ofnode n
100
101 ret = sunxi_nand_chip_set_timings(nfc, chip, timings);
102 if (ret) {
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);
105 return ret;
106 }
107
108 @@ -1717,25 +1718,25 @@ static int sunxi_nand_chip_init(ofnode n
109
110 ret = sunxi_nand_chip_init_timings(nfc, chip);
111 if (ret) {
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);
114 return ret;
115 }
116
117 ret = sunxi_nand_ecc_init(mtd, &nand->ecc);
118 if (ret) {
119 - dev_err(nfc->dev, "ECC init failed: %d\n", ret);
120 + dev_err(dev, "ECC init failed: %d\n", ret);
121 return ret;
122 }
123
124 ret = nand_scan_tail(mtd);
125 if (ret) {
126 - dev_err(nfc->dev, "nand_scan_tail failed: %d\n", ret);
127 + dev_err(dev, "nand_scan_tail failed: %d\n", ret);
128 return ret;
129 }
130
131 ret = nand_register(devnum, mtd);
132 if (ret) {
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);
135 return ret;
136 }
137
138 @@ -1744,13 +1745,13 @@ static int sunxi_nand_chip_init(ofnode n
139 return 0;
140 }
141
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)
144 {
145 ofnode nand_np;
146 int ret, i = 0;
147
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++);
152 if (ret)
153 return ret;
154 }
155 @@ -1802,7 +1803,7 @@ static int sunxi_nand_probe(struct udevi
156 if (ret)
157 return ret;
158
159 - ret = sunxi_nand_chips_init(dev_ofnode(dev), nfc);
160 + ret = sunxi_nand_chips_init(dev, nfc);
161 if (ret) {
162 dev_err(dev, "failed to init nand chips\n");
163 return ret;