Lines Matching full:nemc

3  * JZ4780 NAND/external memory controller (NEMC)
20 #include <linux/jz4780-nemc.h>
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
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()
118 * @dev: child device of the NEMC.
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
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()
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()
285 nemc->soc_info = device_get_match_data(dev); in jz4780_nemc_probe()
286 if (!nemc->soc_info) in jz4780_nemc_probe()
289 spin_lock_init(&nemc->lock); in jz4780_nemc_probe()
290 nemc->dev = dev; in jz4780_nemc_probe()
299 * NEMC registers, we only request the registers we will use for now; 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()
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()
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",