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>
17 #include <soc/at91/atmel-sfr.h>
22 int cs; member
50 struct clk *clk; member
54 struct clk *clk; member
82 atmel_smc_cs_conf_get(ebid->ebi->smc.regmap, conf->cs, in at91sam9_ebi_get_config()
83 &conf->smcconf); in at91sam9_ebi_get_config()
89 atmel_hsmc_cs_conf_get(ebid->ebi->smc.regmap, ebid->ebi->smc.layout, in sama5_ebi_get_config()
90 conf->cs, &conf->smcconf); in sama5_ebi_get_config()
94 ATMEL_SMC_SETUP_XLATE("atmel,smc-ncs-rd-setup-ns",
96 ATMEL_SMC_SETUP_XLATE("atmel,smc-ncs-wr-setup-ns",
98 ATMEL_SMC_SETUP_XLATE("atmel,smc-nrd-setup-ns", ATMEL_SMC_NRD_SHIFT),
99 ATMEL_SMC_SETUP_XLATE("atmel,smc-nwe-setup-ns", ATMEL_SMC_NWE_SHIFT),
100 ATMEL_SMC_PULSE_XLATE("atmel,smc-ncs-rd-pulse-ns",
102 ATMEL_SMC_PULSE_XLATE("atmel,smc-ncs-wr-pulse-ns",
104 ATMEL_SMC_PULSE_XLATE("atmel,smc-nrd-pulse-ns", ATMEL_SMC_NRD_SHIFT),
105 ATMEL_SMC_PULSE_XLATE("atmel,smc-nwe-pulse-ns", ATMEL_SMC_NWE_SHIFT),
106 ATMEL_SMC_CYCLE_XLATE("atmel,smc-nrd-cycle-ns", ATMEL_SMC_NRD_SHIFT),
107 ATMEL_SMC_CYCLE_XLATE("atmel,smc-nwe-cycle-ns", ATMEL_SMC_NWE_SHIFT),
114 unsigned int clk_rate = clk_get_rate(ebid->ebi->clk); in atmel_ebi_xslate_smc_timings()
121 ret = of_property_read_u32(np, "atmel,smc-tdf-ns", &val); in atmel_ebi_xslate_smc_timings()
126 ret = -EINVAL; in atmel_ebi_xslate_smc_timings()
133 smcconf->mode |= ATMEL_SMC_MODE_TDF(ncycles); in atmel_ebi_xslate_smc_timings()
141 ret = of_property_read_u32(np, xlate->name, &val); in atmel_ebi_xslate_smc_timings()
150 ret = -EINVAL; in atmel_ebi_xslate_smc_timings()
155 ret = xlate->converter(smcconf, xlate->shift, ncycles); in atmel_ebi_xslate_smc_timings()
162 dev_err(ebid->ebi->dev, in atmel_ebi_xslate_smc_timings()
175 struct atmel_smc_cs_conf *smcconf = &conf->smcconf; in atmel_ebi_xslate_smc_config()
181 ret = of_property_read_u32(np, "atmel,smc-bus-width", &tmp); in atmel_ebi_xslate_smc_config()
185 smcconf->mode |= ATMEL_SMC_MODE_DBW_8; in atmel_ebi_xslate_smc_config()
189 smcconf->mode |= ATMEL_SMC_MODE_DBW_16; in atmel_ebi_xslate_smc_config()
193 smcconf->mode |= ATMEL_SMC_MODE_DBW_32; in atmel_ebi_xslate_smc_config()
197 return -EINVAL; in atmel_ebi_xslate_smc_config()
203 if (of_property_read_bool(np, "atmel,smc-tdf-optimized")) { in atmel_ebi_xslate_smc_config()
204 smcconf->mode |= ATMEL_SMC_MODE_TDFMODE_OPTIMIZED; in atmel_ebi_xslate_smc_config()
209 of_property_read_string(np, "atmel,smc-byte-access-type", &tmp_str); in atmel_ebi_xslate_smc_config()
211 smcconf->mode |= ATMEL_SMC_MODE_BAT_WRITE; in atmel_ebi_xslate_smc_config()
216 of_property_read_string(np, "atmel,smc-read-mode", &tmp_str); in atmel_ebi_xslate_smc_config()
218 smcconf->mode |= ATMEL_SMC_MODE_READMODE_NRD; in atmel_ebi_xslate_smc_config()
223 of_property_read_string(np, "atmel,smc-write-mode", &tmp_str); in atmel_ebi_xslate_smc_config()
225 smcconf->mode |= ATMEL_SMC_MODE_WRITEMODE_NWE; in atmel_ebi_xslate_smc_config()
230 of_property_read_string(np, "atmel,smc-exnw-mode", &tmp_str); in atmel_ebi_xslate_smc_config()
233 smcconf->mode |= ATMEL_SMC_MODE_EXNWMODE_FROZEN; in atmel_ebi_xslate_smc_config()
235 smcconf->mode |= ATMEL_SMC_MODE_EXNWMODE_READY; in atmel_ebi_xslate_smc_config()
237 return -EINVAL; in atmel_ebi_xslate_smc_config()
242 ret = of_property_read_u32(np, "atmel,smc-page-mode", &tmp); in atmel_ebi_xslate_smc_config()
246 smcconf->mode |= ATMEL_SMC_MODE_PS_4; in atmel_ebi_xslate_smc_config()
250 smcconf->mode |= ATMEL_SMC_MODE_PS_8; in atmel_ebi_xslate_smc_config()
254 smcconf->mode |= ATMEL_SMC_MODE_PS_16; in atmel_ebi_xslate_smc_config()
258 smcconf->mode |= ATMEL_SMC_MODE_PS_32; in atmel_ebi_xslate_smc_config()
262 return -EINVAL; in atmel_ebi_xslate_smc_config()
265 smcconf->mode |= ATMEL_SMC_MODE_PMEN; in atmel_ebi_xslate_smc_config()
269 ret = atmel_ebi_xslate_smc_timings(ebid, np, &conf->smcconf); in atmel_ebi_xslate_smc_config()
271 return -EINVAL; in atmel_ebi_xslate_smc_config()
274 dev_err(ebid->ebi->dev, "missing atmel,smc- properties in %pOF", in atmel_ebi_xslate_smc_config()
276 return -EINVAL; in atmel_ebi_xslate_smc_config()
285 atmel_smc_cs_conf_apply(ebid->ebi->smc.regmap, conf->cs, in at91sam9_ebi_apply_config()
286 &conf->smcconf); in at91sam9_ebi_apply_config()
292 atmel_hsmc_cs_conf_apply(ebid->ebi->smc.regmap, ebid->ebi->smc.layout, in sama5_ebi_apply_config()
293 conf->cs, &conf->smcconf); in sama5_ebi_apply_config()
299 const struct atmel_ebi_caps *caps = ebi->caps; in atmel_ebi_dev_setup()
301 struct device *dev = ebi->dev; in atmel_ebi_dev_setup()
306 u32 cs; in atmel_ebi_dev_setup() local
312 &cs); in atmel_ebi_dev_setup()
316 if (cs >= AT91_EBI_NUM_CS || in atmel_ebi_dev_setup()
317 !(ebi->caps->available_cs & BIT(cs))) { in atmel_ebi_dev_setup()
319 return -EINVAL; in atmel_ebi_dev_setup()
322 if (!test_and_set_bit(cs, &cslines)) in atmel_ebi_dev_setup()
328 return -EINVAL; in atmel_ebi_dev_setup()
331 ebid = devm_kzalloc(ebi->dev, struct_size(ebid, configs, numcs), in atmel_ebi_dev_setup()
334 return -ENOMEM; in atmel_ebi_dev_setup()
336 ebid->ebi = ebi; in atmel_ebi_dev_setup()
337 ebid->numcs = numcs; in atmel_ebi_dev_setup()
339 ret = caps->xlate_config(ebid, np, &conf); in atmel_ebi_dev_setup()
346 for_each_set_bit(cs, &cslines, AT91_EBI_NUM_CS) { in atmel_ebi_dev_setup()
347 ebid->configs[i].cs = cs; in atmel_ebi_dev_setup()
350 conf.cs = cs; in atmel_ebi_dev_setup()
351 caps->apply_config(ebid, &conf); in atmel_ebi_dev_setup()
354 caps->get_config(ebid, &ebid->configs[i]); in atmel_ebi_dev_setup()
357 * Attach the EBI device to the generic SMC logic if at least in atmel_ebi_dev_setup()
358 * one "atmel,smc-" property is present. in atmel_ebi_dev_setup()
360 if (ebi->caps->ebi_csa_offs && apply) in atmel_ebi_dev_setup()
361 regmap_update_bits(ebi->regmap, in atmel_ebi_dev_setup()
362 ebi->caps->ebi_csa_offs, in atmel_ebi_dev_setup()
363 BIT(cs), 0); in atmel_ebi_dev_setup()
368 list_add_tail(&ebid->node, &ebi->devs); in atmel_ebi_dev_setup()
454 .compatible = "atmel,at91sam9260-ebi",
458 .compatible = "atmel,at91sam9261-ebi",
462 .compatible = "atmel,at91sam9263-ebi0",
466 .compatible = "atmel,at91sam9263-ebi1",
470 .compatible = "atmel,at91sam9rl-ebi",
474 .compatible = "atmel,at91sam9g45-ebi",
478 .compatible = "atmel,at91sam9x5-ebi",
482 .compatible = "atmel,sama5d3-ebi",
486 .compatible = "microchip,sam9x60-ebi",
494 struct device *dev = ebi->dev; in atmel_ebi_dev_disable()
499 return -ENOMEM; in atmel_ebi_dev_disable()
501 newprop->name = devm_kstrdup(dev, "status", GFP_KERNEL); in atmel_ebi_dev_disable()
502 if (!newprop->name) in atmel_ebi_dev_disable()
503 return -ENOMEM; in atmel_ebi_dev_disable()
505 newprop->value = devm_kstrdup(dev, "disabled", GFP_KERNEL); in atmel_ebi_dev_disable()
506 if (!newprop->value) in atmel_ebi_dev_disable()
507 return -ENOMEM; in atmel_ebi_dev_disable()
509 newprop->length = sizeof("disabled"); in atmel_ebi_dev_disable()
516 struct device *dev = &pdev->dev; in atmel_ebi_probe()
517 struct device_node *child, *np = dev->of_node, *smc_np; in atmel_ebi_probe()
521 struct clk *clk; in atmel_ebi_probe() local
525 if (!match || !match->data) in atmel_ebi_probe()
526 return -EINVAL; in atmel_ebi_probe()
530 return -ENOMEM; in atmel_ebi_probe()
534 INIT_LIST_HEAD(&ebi->devs); in atmel_ebi_probe()
535 ebi->caps = match->data; 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",