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>
9 #include <linux/clk.h>
12 #include <linux/mfd/syscon/atmel-matrix.h>
13 #include <linux/mfd/syscon/atmel-smc.h>
20 #include <soc/at91/atmel-sfr.h>
25 int cs; member
53 struct clk *clk; member
57 struct clk *clk; member
85 atmel_smc_cs_conf_get(ebid->ebi->smc.regmap, conf->cs, in at91sam9_ebi_get_config()
86 &conf->smcconf); in at91sam9_ebi_get_config()
92 atmel_hsmc_cs_conf_get(ebid->ebi->smc.regmap, ebid->ebi->smc.layout, in sama5_ebi_get_config()
93 conf->cs, &conf->smcconf); in sama5_ebi_get_config()
97 ATMEL_SMC_SETUP_XLATE("atmel,smc-ncs-rd-setup-ns",
99 ATMEL_SMC_SETUP_XLATE("atmel,smc-ncs-wr-setup-ns",
101 ATMEL_SMC_SETUP_XLATE("atmel,smc-nrd-setup-ns", ATMEL_SMC_NRD_SHIFT),
102 ATMEL_SMC_SETUP_XLATE("atmel,smc-nwe-setup-ns", ATMEL_SMC_NWE_SHIFT),
103 ATMEL_SMC_PULSE_XLATE("atmel,smc-ncs-rd-pulse-ns",
105 ATMEL_SMC_PULSE_XLATE("atmel,smc-ncs-wr-pulse-ns",
107 ATMEL_SMC_PULSE_XLATE("atmel,smc-nrd-pulse-ns", ATMEL_SMC_NRD_SHIFT),
108 ATMEL_SMC_PULSE_XLATE("atmel,smc-nwe-pulse-ns", ATMEL_SMC_NWE_SHIFT),
109 ATMEL_SMC_CYCLE_XLATE("atmel,smc-nrd-cycle-ns", ATMEL_SMC_NRD_SHIFT),
110 ATMEL_SMC_CYCLE_XLATE("atmel,smc-nwe-cycle-ns", ATMEL_SMC_NWE_SHIFT),
117 unsigned int clk_rate = clk_get_rate(ebid->ebi->clk); in atmel_ebi_xslate_smc_timings()
124 ret = of_property_read_u32(np, "atmel,smc-tdf-ns", &val); in atmel_ebi_xslate_smc_timings()
129 ret = -EINVAL; in atmel_ebi_xslate_smc_timings()
136 smcconf->mode |= ATMEL_SMC_MODE_TDF(ncycles); in atmel_ebi_xslate_smc_timings()
144 ret = of_property_read_u32(np, xlate->name, &val); in atmel_ebi_xslate_smc_timings()
153 ret = -EINVAL; in atmel_ebi_xslate_smc_timings()
158 ret = xlate->converter(smcconf, xlate->shift, ncycles); in atmel_ebi_xslate_smc_timings()
165 dev_err(ebid->ebi->dev, in atmel_ebi_xslate_smc_timings()
178 struct atmel_smc_cs_conf *smcconf = &conf->smcconf; in atmel_ebi_xslate_smc_config()
184 ret = of_property_read_u32(np, "atmel,smc-bus-width", &tmp); in atmel_ebi_xslate_smc_config()
188 smcconf->mode |= ATMEL_SMC_MODE_DBW_8; in atmel_ebi_xslate_smc_config()
192 smcconf->mode |= ATMEL_SMC_MODE_DBW_16; in atmel_ebi_xslate_smc_config()
196 smcconf->mode |= ATMEL_SMC_MODE_DBW_32; in atmel_ebi_xslate_smc_config()
200 return -EINVAL; in atmel_ebi_xslate_smc_config()
206 if (of_property_read_bool(np, "atmel,smc-tdf-optimized")) { in atmel_ebi_xslate_smc_config()
207 smcconf->mode |= ATMEL_SMC_MODE_TDFMODE_OPTIMIZED; in atmel_ebi_xslate_smc_config()
212 of_property_read_string(np, "atmel,smc-byte-access-type", &tmp_str); in atmel_ebi_xslate_smc_config()
214 smcconf->mode |= ATMEL_SMC_MODE_BAT_WRITE; in atmel_ebi_xslate_smc_config()
219 of_property_read_string(np, "atmel,smc-read-mode", &tmp_str); in atmel_ebi_xslate_smc_config()
221 smcconf->mode |= ATMEL_SMC_MODE_READMODE_NRD; in atmel_ebi_xslate_smc_config()
226 of_property_read_string(np, "atmel,smc-write-mode", &tmp_str); in atmel_ebi_xslate_smc_config()
228 smcconf->mode |= ATMEL_SMC_MODE_WRITEMODE_NWE; in atmel_ebi_xslate_smc_config()
233 of_property_read_string(np, "atmel,smc-exnw-mode", &tmp_str); in atmel_ebi_xslate_smc_config()
236 smcconf->mode |= ATMEL_SMC_MODE_EXNWMODE_FROZEN; in atmel_ebi_xslate_smc_config()
238 smcconf->mode |= ATMEL_SMC_MODE_EXNWMODE_READY; in atmel_ebi_xslate_smc_config()
240 return -EINVAL; in atmel_ebi_xslate_smc_config()
245 ret = of_property_read_u32(np, "atmel,smc-page-mode", &tmp); in atmel_ebi_xslate_smc_config()
249 smcconf->mode |= ATMEL_SMC_MODE_PS_4; in atmel_ebi_xslate_smc_config()
253 smcconf->mode |= ATMEL_SMC_MODE_PS_8; in atmel_ebi_xslate_smc_config()
257 smcconf->mode |= ATMEL_SMC_MODE_PS_16; in atmel_ebi_xslate_smc_config()
261 smcconf->mode |= ATMEL_SMC_MODE_PS_32; in atmel_ebi_xslate_smc_config()
265 return -EINVAL; in atmel_ebi_xslate_smc_config()
268 smcconf->mode |= ATMEL_SMC_MODE_PMEN; in atmel_ebi_xslate_smc_config()
272 ret = atmel_ebi_xslate_smc_timings(ebid, np, &conf->smcconf); in atmel_ebi_xslate_smc_config()
274 return -EINVAL; in atmel_ebi_xslate_smc_config()
277 dev_err(ebid->ebi->dev, "missing atmel,smc- properties in %pOF", in atmel_ebi_xslate_smc_config()
279 return -EINVAL; in atmel_ebi_xslate_smc_config()
288 atmel_smc_cs_conf_apply(ebid->ebi->smc.regmap, conf->cs, in at91sam9_ebi_apply_config()
289 &conf->smcconf); in at91sam9_ebi_apply_config()
295 atmel_hsmc_cs_conf_apply(ebid->ebi->smc.regmap, ebid->ebi->smc.layout, in sama5_ebi_apply_config()
296 conf->cs, &conf->smcconf); in sama5_ebi_apply_config()
302 const struct atmel_ebi_caps *caps = ebi->caps; in atmel_ebi_dev_setup()
304 struct device *dev = ebi->dev; in atmel_ebi_dev_setup()
309 u32 cs; in atmel_ebi_dev_setup() local
315 &cs); in atmel_ebi_dev_setup()
319 if (cs >= AT91_EBI_NUM_CS || in atmel_ebi_dev_setup()
320 !(ebi->caps->available_cs & BIT(cs))) { in atmel_ebi_dev_setup()
322 return -EINVAL; in atmel_ebi_dev_setup()
325 if (!test_and_set_bit(cs, &cslines)) in atmel_ebi_dev_setup()
331 return -EINVAL; in atmel_ebi_dev_setup()
334 ebid = devm_kzalloc(ebi->dev, struct_size(ebid, configs, numcs), in atmel_ebi_dev_setup()
337 return -ENOMEM; in atmel_ebi_dev_setup()
339 ebid->ebi = ebi; in atmel_ebi_dev_setup()
340 ebid->numcs = numcs; in atmel_ebi_dev_setup()
342 ret = caps->xlate_config(ebid, np, &conf); in atmel_ebi_dev_setup()
349 for_each_set_bit(cs, &cslines, AT91_EBI_NUM_CS) { in atmel_ebi_dev_setup()
350 ebid->configs[i].cs = cs; in atmel_ebi_dev_setup()
353 conf.cs = cs; in atmel_ebi_dev_setup()
354 caps->apply_config(ebid, &conf); in atmel_ebi_dev_setup()
357 caps->get_config(ebid, &ebid->configs[i]); in atmel_ebi_dev_setup()
360 * Attach the EBI device to the generic SMC logic if at least in atmel_ebi_dev_setup()
361 * one "atmel,smc-" property is present. in atmel_ebi_dev_setup()
363 if (ebi->caps->ebi_csa_offs && apply) in atmel_ebi_dev_setup()
364 regmap_update_bits(ebi->regmap, in atmel_ebi_dev_setup()
365 ebi->caps->ebi_csa_offs, in atmel_ebi_dev_setup()
366 BIT(cs), 0); in atmel_ebi_dev_setup()
371 list_add_tail(&ebid->node, &ebi->devs); in atmel_ebi_dev_setup()
457 .compatible = "atmel,at91sam9260-ebi",
461 .compatible = "atmel,at91sam9261-ebi",
465 .compatible = "atmel,at91sam9263-ebi0",
469 .compatible = "atmel,at91sam9263-ebi1",
473 .compatible = "atmel,at91sam9rl-ebi",
477 .compatible = "atmel,at91sam9g45-ebi",
481 .compatible = "atmel,at91sam9x5-ebi",
485 .compatible = "atmel,sama5d3-ebi",
489 .compatible = "microchip,sam9x60-ebi",
497 struct device *dev = ebi->dev; in atmel_ebi_dev_disable()
502 return -ENOMEM; in atmel_ebi_dev_disable()
504 newprop->name = devm_kstrdup(dev, "status", GFP_KERNEL); in atmel_ebi_dev_disable()
505 if (!newprop->name) in atmel_ebi_dev_disable()
506 return -ENOMEM; in atmel_ebi_dev_disable()
508 newprop->value = devm_kstrdup(dev, "disabled", GFP_KERNEL); in atmel_ebi_dev_disable()
509 if (!newprop->value) in atmel_ebi_dev_disable()
510 return -ENOMEM; in atmel_ebi_dev_disable()
512 newprop->length = sizeof("disabled"); in atmel_ebi_dev_disable()
519 struct device *dev = &pdev->dev; in atmel_ebi_probe()
520 struct device_node *child, *np = dev->of_node, *smc_np; in atmel_ebi_probe()
523 struct clk *clk; in atmel_ebi_probe() local
528 return -ENOMEM; in atmel_ebi_probe()
532 INIT_LIST_HEAD(&ebi->devs); in atmel_ebi_probe()
533 ebi->caps = device_get_match_data(dev); in atmel_ebi_probe()
534 if (!ebi->caps) in atmel_ebi_probe()
535 return -EINVAL; in atmel_ebi_probe()
536 ebi->dev = dev; in atmel_ebi_probe()
538 clk = devm_clk_get(dev, NULL); in atmel_ebi_probe()
539 if (IS_ERR(clk)) in atmel_ebi_probe()
540 return PTR_ERR(clk); in atmel_ebi_probe()
542 ebi->clk = clk; in atmel_ebi_probe()
544 smc_np = of_parse_phandle(dev->of_node, "atmel,smc", 0); in atmel_ebi_probe()
546 ebi->smc.regmap = syscon_node_to_regmap(smc_np); in atmel_ebi_probe()
547 if (IS_ERR(ebi->smc.regmap)) { in atmel_ebi_probe()
548 ret = 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 ret = PTR_ERR(ebi->smc.layout); in atmel_ebi_probe()
558 ebi->smc.clk = of_clk_get(smc_np, 0); in atmel_ebi_probe()
559 if (IS_ERR(ebi->smc.clk)) { in atmel_ebi_probe()
560 if (PTR_ERR(ebi->smc.clk) != -ENOENT) { in atmel_ebi_probe()
561 ret = PTR_ERR(ebi->smc.clk); in atmel_ebi_probe()
565 ebi->smc.clk = NULL; in atmel_ebi_probe()
568 ret = clk_prepare_enable(ebi->smc.clk); in atmel_ebi_probe()
574 * to access it. in atmel_ebi_probe()
576 if (ebi->caps->ebi_csa_offs) { in atmel_ebi_probe()
577 ebi->regmap = in atmel_ebi_probe()
579 ebi->caps->regmap_name); in atmel_ebi_probe()
580 if (IS_ERR(ebi->regmap)) in atmel_ebi_probe()
581 return PTR_ERR(ebi->regmap); in atmel_ebi_probe()
584 ret = of_property_read_u32(np, "#address-cells", &val); in atmel_ebi_probe()
586 dev_err(dev, "missing #address-cells property\n"); in atmel_ebi_probe()
592 ret = of_property_read_u32(np, "#size-cells", &val); in atmel_ebi_probe()
594 dev_err(dev, "missing #address-cells property\n"); in atmel_ebi_probe()
606 dev_err(dev, "failed to configure EBI bus for %pOF, disabling the device", in atmel_ebi_probe()
629 list_for_each_entry(ebid, &ebi->devs, node) { in atmel_ebi_resume()
632 for (i = 0; i < ebid->numcs; i++) in atmel_ebi_resume()
633 ebid->ebi->caps->apply_config(ebid, &ebid->configs[i]); in atmel_ebi_resume()
643 .name = "atmel-ebi",