Lines Matching +full:nemc +full:- +full:tbp

1 // SPDX-License-Identifier: GPL-2.0-only
3 * JZ4780 NAND/external memory controller (NEMC)
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
62 * @dev: device to count banks for, must be a child of the NEMC.
64 * Return: The number of unique NEMC banks referred to by the specified NEMC
75 while ((prop = of_get_address(dev->of_node, i++, NULL, NULL))) { in jz4780_nemc_num_banks()
88 * jz4780_nemc_set_type() - set the type of device connected to a bank
89 * @dev: child device of the NEMC.
96 struct jz4780_nemc *nemc = dev_get_drvdata(dev->parent); in jz4780_nemc_set_type() local
99 nfcsr = readl(nemc->base + NEMC_NFCSR); 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
118 * @dev: child device of the NEMC.
122 * (De-)asserts the chip enable pin for the NAND device connected to the
127 struct jz4780_nemc *nemc = dev_get_drvdata(dev->parent); in jz4780_nemc_assert() local
130 nfcsr = readl(nemc->base + NEMC_NFCSR); in jz4780_nemc_assert()
137 writel(nfcsr, nemc->base + NEMC_NFCSR); in jz4780_nemc_assert()
141 static uint32_t jz4780_nemc_clk_period(struct jz4780_nemc *nemc) in jz4780_nemc_clk_period() argument
145 rate = clk_get_rate(nemc->clk); in jz4780_nemc_clk_period()
153 static uint32_t jz4780_nemc_ns_to_cycles(struct jz4780_nemc *nemc, uint32_t ns) in jz4780_nemc_ns_to_cycles() argument
155 return ((ns * 1000) + nemc->clk_period - 1) / nemc->clk_period; in jz4780_nemc_ns_to_cycles()
158 static bool jz4780_nemc_configure_bank(struct jz4780_nemc *nemc, in jz4780_nemc_configure_bank() argument
165 * Conversion of tBP and tAW cycle counts to values supported by the in jz4780_nemc_configure_bank()
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()
208 cycles = jz4780_nemc_ns_to_cycles(nemc, val); 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()
220 cycles = jz4780_nemc_ns_to_cycles(nemc, val); 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()
232 cycles = jz4780_nemc_ns_to_cycles(nemc, val); 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()
244 cycles = jz4780_nemc_ns_to_cycles(nemc, val); 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()
256 cycles = jz4780_nemc_ns_to_cycles(nemc, val); 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()
273 struct jz4780_nemc *nemc; in jz4780_nemc_probe() local
281 nemc = devm_kzalloc(dev, sizeof(*nemc), GFP_KERNEL); in jz4780_nemc_probe()
282 if (!nemc) in jz4780_nemc_probe()
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()
299 * NEMC registers, we only request the registers we will use for now; 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()
346 dev_err(nemc->dev, 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()
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()
382 platform_set_drvdata(pdev, nemc); in jz4780_nemc_probe()
383 dev_info(dev, "JZ4780 NEMC initialised\n"); in jz4780_nemc_probe()
389 struct jz4780_nemc *nemc = platform_get_drvdata(pdev); in jz4780_nemc_remove() local
391 clk_disable_unprepare(nemc->clk); in jz4780_nemc_remove()
404 { .compatible = "ingenic,jz4740-nemc", .data = &jz4740_soc_info, },
405 { .compatible = "ingenic,jz4780-nemc", .data = &jz4780_soc_info, },
413 .name = "jz4780-nemc",