1 From 61b63cbb3526e19a0e299f95a3435a237c7c4b4b Mon Sep 17 00:00:00 2001
2 From: Samuel Holland <samuel@sholland.org>
3 Date: Sun, 15 May 2022 21:54:25 -0500
4 Subject: [PATCH 30/90] mtd: nand: sunxi: Convert from fdtdec to ofnode
6 As a first step toward converting this driver to the driver model, use
7 the ofnode abstraction to replace direct references to the FDT blob.
9 Using ofnode_read_u32_index removes an extra pair of loops and makes the
10 allwinner,rb property optional, matching the devicetree binding.
12 Signed-off-by: Samuel Holland <samuel@sholland.org>
14 drivers/mtd/nand/raw/sunxi_nand.c | 73 +++++++++++--------------------
15 include/fdtdec.h | 1 -
17 3 files changed, 26 insertions(+), 49 deletions(-)
19 --- a/drivers/mtd/nand/raw/sunxi_nand.c
20 +++ b/drivers/mtd/nand/raw/sunxi_nand.c
30 -#include <asm/global_data.h>
31 #include <dm/device_compat.h>
32 #include <dm/devres.h>
33 #include <linux/bitops.h>
36 #include <asm/arch/clock.h>
38 -DECLARE_GLOBAL_DATA_PTR;
40 #define NFC_REG_CTL 0x0000
41 #define NFC_REG_ST 0x0004
42 #define NFC_REG_INT 0x0008
43 @@ -1605,19 +1602,18 @@ static int sunxi_nand_ecc_init(struct mt
47 -static int sunxi_nand_chip_init(int node, struct sunxi_nfc *nfc, int devnum)
48 +static int sunxi_nand_chip_init(ofnode np, struct sunxi_nfc *nfc, int devnum)
50 const struct nand_sdr_timings *timings;
51 - const void *blob = gd->fdt_blob;
52 struct sunxi_nand_chip *chip;
54 struct nand_chip *nand;
61 - if (!fdt_getprop(blob, node, "reg", &nsels))
62 + if (!ofnode_get_property(np, "reg", &nsels))
66 @@ -1638,25 +1634,12 @@ static int sunxi_nand_chip_init(int node
69 for (i = 0; i < nsels; i++) {
74 - ret = fdtdec_get_int_array(gd->fdt_blob, node, "reg", cs, nsels);
76 - dev_err(nfc->dev, "could not retrieve reg property: %d\n", ret);
80 - ret = fdtdec_get_int_array(gd->fdt_blob, node, "allwinner,rb", rb,
83 - dev_err(nfc->dev, "could not retrieve reg property: %d\n", ret);
87 - for (i = 0; i < nsels; i++) {
89 + ret = ofnode_read_u32_index(np, "reg", i, &tmp);
91 + dev_err(nfc->dev, "could not retrieve reg property: %d\n",
96 if (tmp > NFC_MAX_CS) {
98 @@ -1671,15 +1654,14 @@ static int sunxi_nand_chip_init(int node
100 chip->sels[i].cs = tmp;
103 - if (tmp >= 0 && tmp < 2) {
104 + if (!ofnode_read_u32_index(np, "allwinner,rb", i, &tmp) &&
106 chip->sels[i].rb.type = RB_NATIVE;
107 chip->sels[i].rb.info.nativeid = tmp;
109 - ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
111 - &chip->sels[i].rb.info.gpio,
113 + ret = gpio_request_by_name_nodev(np, "rb-gpios", i,
114 + &chip->sels[i].rb.info.gpio,
117 chip->sels[i].rb.type = RB_GPIO;
119 @@ -1711,7 +1693,7 @@ static int sunxi_nand_chip_init(int node
122 nand->ecc.mode = NAND_ECC_HW;
123 - nand->flash_node = offset_to_ofnode(node);
124 + nand->flash_node = np;
125 nand->select_chip = sunxi_nfc_select_chip;
126 nand->cmd_ctrl = sunxi_nfc_cmd_ctrl;
127 nand->read_buf = sunxi_nfc_read_buf;
128 @@ -1760,15 +1742,13 @@ static int sunxi_nand_chip_init(int node
132 -static int sunxi_nand_chips_init(int node, struct sunxi_nfc *nfc)
133 +static int sunxi_nand_chips_init(ofnode node, struct sunxi_nfc *nfc)
135 - const void *blob = gd->fdt_blob;
140 - for (nand_node = fdt_first_subnode(blob, node); nand_node >= 0;
141 - nand_node = fdt_next_subnode(blob, nand_node)) {
142 - ret = sunxi_nand_chip_init(nand_node, nfc, i++);
143 + ofnode_for_each_subnode(nand_np, node) {
144 + ret = sunxi_nand_chip_init(nand_np, nfc, i++);
148 @@ -1794,10 +1774,9 @@ static void sunxi_nand_chips_cleanup(str
150 void sunxi_nand_init(void)
152 - const void *blob = gd->fdt_blob;
153 struct sunxi_nfc *nfc;
160 nfc = kzalloc(sizeof(*nfc), GFP_KERNEL);
161 @@ -1808,18 +1787,18 @@ void sunxi_nand_init(void)
162 init_waitqueue_head(&nfc->controller.wq);
163 INIT_LIST_HEAD(&nfc->chips);
165 - node = fdtdec_next_compatible(blob, 0, COMPAT_SUNXI_NAND);
167 + node = ofnode_by_compatible(ofnode_null(), "allwinner,sun4i-a10-nand");
168 + if (!ofnode_valid(node)) {
169 pr_err("unable to find nfc node in device tree\n");
173 - if (!fdtdec_get_is_enabled(blob, node)) {
174 + if (!ofnode_is_enabled(node)) {
175 pr_err("nfc disabled in device tree\n");
179 - regs = fdtdec_get_addr(blob, node, "reg");
180 + regs = ofnode_get_addr(node);
181 if (regs == FDT_ADDR_T_NONE) {
182 pr_err("unable to find nfc address in device tree\n");
184 --- a/include/fdtdec.h
185 +++ b/include/fdtdec.h
186 @@ -187,7 +187,6 @@ enum fdt_compat_id {
187 COMPAT_INTEL_BAYTRAIL_FSP, /* Intel Bay Trail FSP */
188 COMPAT_INTEL_BAYTRAIL_FSP_MDP, /* Intel FSP memory-down params */
189 COMPAT_INTEL_IVYBRIDGE_FSP, /* Intel Ivy Bridge FSP */
190 - COMPAT_SUNXI_NAND, /* SUNXI NAND controller */
191 COMPAT_ALTERA_SOCFPGA_CLK, /* SoCFPGA Clock initialization */
192 COMPAT_ALTERA_SOCFPGA_PINCTRL_SINGLE, /* SoCFPGA pinctrl-single */
193 COMPAT_ALTERA_SOCFPGA_H2F_BRG, /* SoCFPGA hps2fpga bridge */
196 @@ -64,7 +64,6 @@ static const char * const compat_names[C
197 COMPAT(INTEL_BAYTRAIL_FSP, "intel,baytrail-fsp"),
198 COMPAT(INTEL_BAYTRAIL_FSP_MDP, "intel,baytrail-fsp-mdp"),
199 COMPAT(INTEL_IVYBRIDGE_FSP, "intel,ivybridge-fsp"),
200 - COMPAT(COMPAT_SUNXI_NAND, "allwinner,sun4i-a10-nand"),
201 COMPAT(ALTERA_SOCFPGA_CLK, "altr,clk-mgr"),
202 COMPAT(ALTERA_SOCFPGA_PINCTRL_SINGLE, "pinctrl-single"),
203 COMPAT(ALTERA_SOCFPGA_H2F_BRG, "altr,socfpga-hps2fpga-bridge"),