Lines Matching +full:bank +full:- +full:number

1 // SPDX-License-Identifier: GPL-2.0-only
6 * Author: Alex Smith <alex@alex-smith.me.uk>
20 #include <linux/jz4780-nemc.h>
22 #define NEMC_SMCRn(n) (0x14 + (((n) - 1) * 4))
42 #define NEMC_NFCSR_NFEn(n) BIT(((n) - 1) << 1)
43 #define NEMC_NFCSR_NFCEn(n) BIT((((n) - 1) << 1) + 1)
44 #define NEMC_NFCSR_TNFEn(n) BIT(16 + (n) - 1)
61 * jz4780_nemc_num_banks() - count the number of banks referenced by a device
64 * Return: The number of unique NEMC banks referred to by the specified NEMC
65 * child device. Unique here means that a device that references the same bank
71 unsigned int bank, count = 0; in jz4780_nemc_num_banks() local
75 while ((prop = of_get_address(dev->of_node, i++, NULL, NULL))) { in jz4780_nemc_num_banks()
76 bank = of_read_number(prop, 1); in jz4780_nemc_num_banks()
77 if (!(referenced & BIT(bank))) { in jz4780_nemc_num_banks()
78 referenced |= BIT(bank); in jz4780_nemc_num_banks()
88 * jz4780_nemc_set_type() - set the type of device connected to a bank
90 * @bank: bank number to configure.
91 * @type: type of device connected to the bank.
93 void jz4780_nemc_set_type(struct device *dev, unsigned int bank, in jz4780_nemc_set_type() argument
96 struct jz4780_nemc *nemc = dev_get_drvdata(dev->parent); in jz4780_nemc_set_type()
99 nfcsr = readl(nemc->base + NEMC_NFCSR); in jz4780_nemc_set_type()
104 nfcsr &= ~(NEMC_NFCSR_TNFEn(bank) | NEMC_NFCSR_NFEn(bank)); in jz4780_nemc_set_type()
107 nfcsr &= ~NEMC_NFCSR_TNFEn(bank); in jz4780_nemc_set_type()
108 nfcsr |= NEMC_NFCSR_NFEn(bank); in jz4780_nemc_set_type()
112 writel(nfcsr, nemc->base + NEMC_NFCSR); in jz4780_nemc_set_type()
117 * jz4780_nemc_assert() - (de-)assert a NAND device's chip enable pin
119 * @bank: bank number of device.
122 * (De-)asserts the chip enable pin for the NAND device connected to the
123 * specified bank.
125 void jz4780_nemc_assert(struct device *dev, unsigned int bank, bool assert) in jz4780_nemc_assert() argument
127 struct jz4780_nemc *nemc = dev_get_drvdata(dev->parent); in jz4780_nemc_assert()
130 nfcsr = readl(nemc->base + NEMC_NFCSR); in jz4780_nemc_assert()
133 nfcsr |= NEMC_NFCSR_NFCEn(bank); in jz4780_nemc_assert()
135 nfcsr &= ~NEMC_NFCSR_NFCEn(bank); in jz4780_nemc_assert()
137 writel(nfcsr, nemc->base + NEMC_NFCSR); in jz4780_nemc_assert()
145 rate = clk_get_rate(nemc->clk); in jz4780_nemc_clk_period()
155 return ((ns * 1000) + nemc->clk_period - 1) / nemc->clk_period; in jz4780_nemc_ns_to_cycles()
159 unsigned int bank, in jz4780_nemc_configure_bank() argument
171 /* 11 - 12 -> 12 cycles */ in jz4780_nemc_configure_bank()
174 /* 13 - 15 -> 15 cycles */ in jz4780_nemc_configure_bank()
177 /* 16 - 20 -> 20 cycles */ in jz4780_nemc_configure_bank()
180 /* 21 - 25 -> 25 cycles */ in jz4780_nemc_configure_bank()
183 /* 26 - 31 -> 31 cycles */ in jz4780_nemc_configure_bank()
187 smcr = readl(nemc->base + NEMC_SMCRn(bank)); in jz4780_nemc_configure_bank()
190 if (!of_property_read_u32(node, "ingenic,nemc-bus-width", &val)) { in jz4780_nemc_configure_bank()
201 dev_err(nemc->dev, "unsupported bus width: %u\n", val); in jz4780_nemc_configure_bank()
206 if (of_property_read_u32(node, "ingenic,nemc-tAS", &val) == 0) { in jz4780_nemc_configure_bank()
209 if (cycles > nemc->soc_info->tas_tah_cycles_max) { in jz4780_nemc_configure_bank()
210 dev_err(nemc->dev, "tAS %u is too high (%u cycles)\n", in jz4780_nemc_configure_bank()
218 if (of_property_read_u32(node, "ingenic,nemc-tAH", &val) == 0) { in jz4780_nemc_configure_bank()
221 if (cycles > nemc->soc_info->tas_tah_cycles_max) { in jz4780_nemc_configure_bank()
222 dev_err(nemc->dev, "tAH %u is too high (%u cycles)\n", in jz4780_nemc_configure_bank()
230 if (of_property_read_u32(node, "ingenic,nemc-tBP", &val) == 0) { in jz4780_nemc_configure_bank()
234 dev_err(nemc->dev, "tBP %u is too high (%u cycles)\n", in jz4780_nemc_configure_bank()
242 if (of_property_read_u32(node, "ingenic,nemc-tAW", &val) == 0) { in jz4780_nemc_configure_bank()
246 dev_err(nemc->dev, "tAW %u is too high (%u cycles)\n", in jz4780_nemc_configure_bank()
254 if (of_property_read_u32(node, "ingenic,nemc-tSTRV", &val) == 0) { in jz4780_nemc_configure_bank()
258 dev_err(nemc->dev, "tSTRV %u is too high (%u cycles)\n", in jz4780_nemc_configure_bank()
266 writel(smcr, nemc->base + NEMC_SMCRn(bank)); in jz4780_nemc_configure_bank()
272 struct device *dev = &pdev->dev; in jz4780_nemc_probe()
277 unsigned int bank; in jz4780_nemc_probe() local
283 return -ENOMEM; in jz4780_nemc_probe()
285 nemc->soc_info = device_get_match_data(dev); in jz4780_nemc_probe()
286 if (!nemc->soc_info) in jz4780_nemc_probe()
287 return -EINVAL; in jz4780_nemc_probe()
289 spin_lock_init(&nemc->lock); in jz4780_nemc_probe()
290 nemc->dev = dev; in jz4780_nemc_probe()
294 return -EINVAL; in jz4780_nemc_probe()
302 if (!devm_request_mem_region(dev, res->start, NEMC_REG_LEN, dev_name(dev))) { in jz4780_nemc_probe()
304 return -EBUSY; in jz4780_nemc_probe()
307 nemc->base = devm_ioremap(dev, res->start, NEMC_REG_LEN); in jz4780_nemc_probe()
308 if (!nemc->base) { in jz4780_nemc_probe()
310 return -ENOMEM; in jz4780_nemc_probe()
313 writel(0, nemc->base + NEMC_NFCSR); in jz4780_nemc_probe()
315 nemc->clk = devm_clk_get(dev, NULL); in jz4780_nemc_probe()
316 if (IS_ERR(nemc->clk)) { in jz4780_nemc_probe()
318 return PTR_ERR(nemc->clk); in jz4780_nemc_probe()
321 ret = clk_prepare_enable(nemc->clk); in jz4780_nemc_probe()
327 nemc->clk_period = jz4780_nemc_clk_period(nemc); in jz4780_nemc_probe()
328 if (!nemc->clk_period) { in jz4780_nemc_probe()
330 clk_disable_unprepare(nemc->clk); in jz4780_nemc_probe()
331 return -EINVAL; in jz4780_nemc_probe()
340 for_each_child_of_node(nemc->dev->of_node, child) { in jz4780_nemc_probe()
344 bank = of_read_number(prop, 1); in jz4780_nemc_probe()
345 if (bank < 1 || bank >= JZ4780_NEMC_NUM_BANKS) { in jz4780_nemc_probe()
346 dev_err(nemc->dev, in jz4780_nemc_probe()
347 "%pOF requests invalid bank %u\n", in jz4780_nemc_probe()
348 child, bank); in jz4780_nemc_probe()
355 referenced |= BIT(bank); in jz4780_nemc_probe()
359 dev_err(nemc->dev, "%pOF has no addresses\n", in jz4780_nemc_probe()
362 } else if (nemc->banks_present & referenced) { in jz4780_nemc_probe()
363 dev_err(nemc->dev, "%pOF conflicts with another node\n", in jz4780_nemc_probe()
368 /* Configure bank parameters. */ in jz4780_nemc_probe()
369 for_each_set_bit(bank, &referenced, JZ4780_NEMC_NUM_BANKS) { in jz4780_nemc_probe()
370 if (!jz4780_nemc_configure_bank(nemc, bank, child)) { in jz4780_nemc_probe()
377 if (of_platform_device_create(child, NULL, nemc->dev)) in jz4780_nemc_probe()
378 nemc->banks_present |= referenced; in jz4780_nemc_probe()
391 clk_disable_unprepare(nemc->clk); in jz4780_nemc_remove()
403 { .compatible = "ingenic,jz4740-nemc", .data = &jz4740_soc_info, },
404 { .compatible = "ingenic,jz4780-nemc", .data = &jz4780_soc_info, },
412 .name = "jz4780-nemc",