Lines Matching +full:cs +full:- +full:to +full:- +full:clk

1 // SPDX-License-Identifier: GPL-2.0
6 * Copyright (C) 2013 Jean-Jacques Hiblot <jjhiblot@traphandler.com>
10 #include <linux/clk.h>
13 #include <linux/mfd/syscon/atmel-matrix.h>
14 #include <linux/mfd/syscon/atmel-smc.h>
21 #include <soc/at91/atmel-sfr.h>
26 int cs; member
54 struct clk *clk; member
58 struct clk *clk; member
86 atmel_smc_cs_conf_get(ebid->ebi->smc.regmap, conf->cs, in at91sam9_ebi_get_config()
87 &conf->smcconf); in at91sam9_ebi_get_config()
93 atmel_hsmc_cs_conf_get(ebid->ebi->smc.regmap, ebid->ebi->smc.layout, in sama5_ebi_get_config()
94 conf->cs, &conf->smcconf); in sama5_ebi_get_config()
98 ATMEL_SMC_SETUP_XLATE("atmel,smc-ncs-rd-setup-ns",
100 ATMEL_SMC_SETUP_XLATE("atmel,smc-ncs-wr-setup-ns",
102 ATMEL_SMC_SETUP_XLATE("atmel,smc-nrd-setup-ns", ATMEL_SMC_NRD_SHIFT),
103 ATMEL_SMC_SETUP_XLATE("atmel,smc-nwe-setup-ns", ATMEL_SMC_NWE_SHIFT),
104 ATMEL_SMC_PULSE_XLATE("atmel,smc-ncs-rd-pulse-ns",
106 ATMEL_SMC_PULSE_XLATE("atmel,smc-ncs-wr-pulse-ns",
108 ATMEL_SMC_PULSE_XLATE("atmel,smc-nrd-pulse-ns", ATMEL_SMC_NRD_SHIFT),
109 ATMEL_SMC_PULSE_XLATE("atmel,smc-nwe-pulse-ns", ATMEL_SMC_NWE_SHIFT),
110 ATMEL_SMC_CYCLE_XLATE("atmel,smc-nrd-cycle-ns", ATMEL_SMC_NRD_SHIFT),
111 ATMEL_SMC_CYCLE_XLATE("atmel,smc-nwe-cycle-ns", ATMEL_SMC_NWE_SHIFT),
118 unsigned int clk_rate = clk_get_rate(ebid->ebi->clk); in atmel_ebi_xslate_smc_timings()
125 ret = of_property_read_u32(np, "atmel,smc-tdf-ns", &val); in atmel_ebi_xslate_smc_timings()
130 ret = -EINVAL; in atmel_ebi_xslate_smc_timings()
137 smcconf->mode |= ATMEL_SMC_MODE_TDF(ncycles); in atmel_ebi_xslate_smc_timings()
145 ret = of_property_read_u32(np, xlate->name, &val); in atmel_ebi_xslate_smc_timings()
154 ret = -EINVAL; in atmel_ebi_xslate_smc_timings()
159 ret = xlate->converter(smcconf, xlate->shift, ncycles); in atmel_ebi_xslate_smc_timings()
166 dev_err(ebid->ebi->dev, in atmel_ebi_xslate_smc_timings()
179 struct atmel_smc_cs_conf *smcconf = &conf->smcconf; in atmel_ebi_xslate_smc_config()
185 ret = of_property_read_u32(np, "atmel,smc-bus-width", &tmp); in atmel_ebi_xslate_smc_config()
189 smcconf->mode |= ATMEL_SMC_MODE_DBW_8; in atmel_ebi_xslate_smc_config()
193 smcconf->mode |= ATMEL_SMC_MODE_DBW_16; in atmel_ebi_xslate_smc_config()
197 smcconf->mode |= ATMEL_SMC_MODE_DBW_32; in atmel_ebi_xslate_smc_config()
201 return -EINVAL; in atmel_ebi_xslate_smc_config()
207 if (of_property_read_bool(np, "atmel,smc-tdf-optimized")) { in atmel_ebi_xslate_smc_config()
208 smcconf->mode |= ATMEL_SMC_MODE_TDFMODE_OPTIMIZED; in atmel_ebi_xslate_smc_config()
213 of_property_read_string(np, "atmel,smc-byte-access-type", &tmp_str); in atmel_ebi_xslate_smc_config()
215 smcconf->mode |= ATMEL_SMC_MODE_BAT_WRITE; in atmel_ebi_xslate_smc_config()
220 of_property_read_string(np, "atmel,smc-read-mode", &tmp_str); in atmel_ebi_xslate_smc_config()
222 smcconf->mode |= ATMEL_SMC_MODE_READMODE_NRD; in atmel_ebi_xslate_smc_config()
227 of_property_read_string(np, "atmel,smc-write-mode", &tmp_str); in atmel_ebi_xslate_smc_config()
229 smcconf->mode |= ATMEL_SMC_MODE_WRITEMODE_NWE; in atmel_ebi_xslate_smc_config()
234 of_property_read_string(np, "atmel,smc-exnw-mode", &tmp_str); in atmel_ebi_xslate_smc_config()
237 smcconf->mode |= ATMEL_SMC_MODE_EXNWMODE_FROZEN; in atmel_ebi_xslate_smc_config()
239 smcconf->mode |= ATMEL_SMC_MODE_EXNWMODE_READY; in atmel_ebi_xslate_smc_config()
241 return -EINVAL; in atmel_ebi_xslate_smc_config()
246 ret = of_property_read_u32(np, "atmel,smc-page-mode", &tmp); in atmel_ebi_xslate_smc_config()
250 smcconf->mode |= ATMEL_SMC_MODE_PS_4; in atmel_ebi_xslate_smc_config()
254 smcconf->mode |= ATMEL_SMC_MODE_PS_8; in atmel_ebi_xslate_smc_config()
258 smcconf->mode |= ATMEL_SMC_MODE_PS_16; in atmel_ebi_xslate_smc_config()
262 smcconf->mode |= ATMEL_SMC_MODE_PS_32; in atmel_ebi_xslate_smc_config()
266 return -EINVAL; in atmel_ebi_xslate_smc_config()
269 smcconf->mode |= ATMEL_SMC_MODE_PMEN; in atmel_ebi_xslate_smc_config()
273 ret = atmel_ebi_xslate_smc_timings(ebid, np, &conf->smcconf); in atmel_ebi_xslate_smc_config()
275 return -EINVAL; in atmel_ebi_xslate_smc_config()
278 dev_err(ebid->ebi->dev, "missing atmel,smc- properties in %pOF", in atmel_ebi_xslate_smc_config()
280 return -EINVAL; in atmel_ebi_xslate_smc_config()
289 atmel_smc_cs_conf_apply(ebid->ebi->smc.regmap, conf->cs, in at91sam9_ebi_apply_config()
290 &conf->smcconf); in at91sam9_ebi_apply_config()
296 atmel_hsmc_cs_conf_apply(ebid->ebi->smc.regmap, ebid->ebi->smc.layout, in sama5_ebi_apply_config()
297 conf->cs, &conf->smcconf); in sama5_ebi_apply_config()
303 const struct atmel_ebi_caps *caps = ebi->caps; in atmel_ebi_dev_setup()
305 struct device *dev = ebi->dev; in atmel_ebi_dev_setup()
310 u32 cs; in atmel_ebi_dev_setup() local
316 &cs); in atmel_ebi_dev_setup()
320 if (cs >= AT91_EBI_NUM_CS || in atmel_ebi_dev_setup()
321 !(ebi->caps->available_cs & BIT(cs))) { in atmel_ebi_dev_setup()
323 return -EINVAL; in atmel_ebi_dev_setup()
326 if (!test_and_set_bit(cs, &cslines)) in atmel_ebi_dev_setup()
332 return -EINVAL; in atmel_ebi_dev_setup()
335 ebid = devm_kzalloc(ebi->dev, struct_size(ebid, configs, numcs), in atmel_ebi_dev_setup()
338 return -ENOMEM; in atmel_ebi_dev_setup()
340 ebid->ebi = ebi; in atmel_ebi_dev_setup()
341 ebid->numcs = numcs; in atmel_ebi_dev_setup()
343 ret = caps->xlate_config(ebid, np, &conf); in atmel_ebi_dev_setup()
350 for_each_set_bit(cs, &cslines, AT91_EBI_NUM_CS) { in atmel_ebi_dev_setup()
351 ebid->configs[i].cs = cs; in atmel_ebi_dev_setup()
354 conf.cs = cs; in atmel_ebi_dev_setup()
355 caps->apply_config(ebid, &conf); in atmel_ebi_dev_setup()
358 caps->get_config(ebid, &ebid->configs[i]); in atmel_ebi_dev_setup()
361 * Attach the EBI device to the generic SMC logic if at least in atmel_ebi_dev_setup()
362 * one "atmel,smc-" property is present. in atmel_ebi_dev_setup()
364 if (ebi->caps->ebi_csa_offs && apply) in atmel_ebi_dev_setup()
365 regmap_update_bits(ebi->regmap, in atmel_ebi_dev_setup()
366 ebi->caps->ebi_csa_offs, in atmel_ebi_dev_setup()
367 BIT(cs), 0); in atmel_ebi_dev_setup()
372 list_add_tail(&ebid->node, &ebi->devs); in atmel_ebi_dev_setup()
458 .compatible = "atmel,at91sam9260-ebi",
462 .compatible = "atmel,at91sam9261-ebi",
466 .compatible = "atmel,at91sam9263-ebi0",
470 .compatible = "atmel,at91sam9263-ebi1",
474 .compatible = "atmel,at91sam9rl-ebi",
478 .compatible = "atmel,at91sam9g45-ebi",
482 .compatible = "atmel,at91sam9x5-ebi",
486 .compatible = "atmel,sama5d3-ebi",
490 .compatible = "microchip,sam9x60-ebi",
498 struct device *dev = ebi->dev; in atmel_ebi_dev_disable()
503 return -ENOMEM; in atmel_ebi_dev_disable()
505 newprop->name = devm_kstrdup(dev, "status", GFP_KERNEL); in atmel_ebi_dev_disable()
506 if (!newprop->name) in atmel_ebi_dev_disable()
507 return -ENOMEM; in atmel_ebi_dev_disable()
509 newprop->value = devm_kstrdup(dev, "disabled", GFP_KERNEL); in atmel_ebi_dev_disable()
510 if (!newprop->value) in atmel_ebi_dev_disable()
511 return -ENOMEM; in atmel_ebi_dev_disable()
513 newprop->length = sizeof("disabled"); in atmel_ebi_dev_disable()
520 struct device *dev = &pdev->dev; in atmel_ebi_probe()
521 struct device_node *np = dev->of_node; in atmel_ebi_probe()
524 struct clk *clk; in atmel_ebi_probe() local
529 return -ENOMEM; in atmel_ebi_probe()
533 INIT_LIST_HEAD(&ebi->devs); in atmel_ebi_probe()
534 ebi->caps = device_get_match_data(dev); in atmel_ebi_probe()
535 if (!ebi->caps) in atmel_ebi_probe()
536 return -EINVAL; in atmel_ebi_probe()
537 ebi->dev = dev; in atmel_ebi_probe()
539 clk = devm_clk_get(dev, NULL); in atmel_ebi_probe()
540 if (IS_ERR(clk)) in atmel_ebi_probe()
541 return PTR_ERR(clk); in atmel_ebi_probe()
543 ebi->clk = clk; in atmel_ebi_probe()
546 of_parse_phandle(dev->of_node, "atmel,smc", 0); in atmel_ebi_probe()
548 ebi->smc.regmap = syscon_node_to_regmap(smc_np); in atmel_ebi_probe()
549 if (IS_ERR(ebi->smc.regmap)) in atmel_ebi_probe()
550 return PTR_ERR(ebi->smc.regmap); in atmel_ebi_probe()
552 ebi->smc.layout = atmel_hsmc_get_reg_layout(smc_np); in atmel_ebi_probe()
553 if (IS_ERR(ebi->smc.layout)) in atmel_ebi_probe()
554 return PTR_ERR(ebi->smc.layout); in atmel_ebi_probe()
556 ebi->smc.clk = of_clk_get(smc_np, 0); in atmel_ebi_probe()
557 if (IS_ERR(ebi->smc.clk)) { in atmel_ebi_probe()
558 if (PTR_ERR(ebi->smc.clk) != -ENOENT) in atmel_ebi_probe()
559 return PTR_ERR(ebi->smc.clk); in atmel_ebi_probe()
561 ebi->smc.clk = NULL; in atmel_ebi_probe()
563 ret = clk_prepare_enable(ebi->smc.clk); in atmel_ebi_probe()
569 * to access it. in atmel_ebi_probe()
571 if (ebi->caps->ebi_csa_offs) { in atmel_ebi_probe()
572 ebi->regmap = in atmel_ebi_probe()
574 ebi->caps->regmap_name); in atmel_ebi_probe()
575 if (IS_ERR(ebi->regmap)) in atmel_ebi_probe()
576 return PTR_ERR(ebi->regmap); in atmel_ebi_probe()
579 ret = of_property_read_u32(np, "#address-cells", &val); in atmel_ebi_probe()
581 dev_err(dev, "missing #address-cells property\n"); in atmel_ebi_probe()
587 ret = of_property_read_u32(np, "#size-cells", &val); in atmel_ebi_probe()
589 dev_err(dev, "missing #address-cells property\n"); in atmel_ebi_probe()
601 dev_err(dev, "failed to configure EBI bus for %pOF, disabling the device", in atmel_ebi_probe()
618 list_for_each_entry(ebid, &ebi->devs, node) { in atmel_ebi_resume()
621 for (i = 0; i < ebid->numcs; i++) in atmel_ebi_resume()
622 ebid->ebi->caps->apply_config(ebid, &ebid->configs[i]); in atmel_ebi_resume()
632 .name = "atmel-ebi",