hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/drivers/memory/atmel-ebi.c
....@@ -1,12 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * EBI driver for Atmel chips
34 * inspired by the fsl weim bus driver
45 *
56 * Copyright (C) 2013 Jean-Jacques Hiblot <jjhiblot@traphandler.com>
6
- *
7
- * This file is licensed under the terms of the GNU General Public
8
- * License version 2. This program is licensed "as is" without any
9
- * warranty of any kind, whether express or implied.
107 */
118
129 #include <linux/clk.h>
....@@ -17,6 +14,9 @@
1714 #include <linux/init.h>
1815 #include <linux/of_device.h>
1916 #include <linux/regmap.h>
17
+#include <soc/at91/atmel-sfr.h>
18
+
19
+#define AT91_EBI_NUM_CS 8
2020
2121 struct atmel_ebi_dev_config {
2222 int cs;
....@@ -36,6 +36,7 @@
3636 struct atmel_ebi_caps {
3737 unsigned int available_cs;
3838 unsigned int ebi_csa_offs;
39
+ const char *regmap_name;
3940 void (*get_config)(struct atmel_ebi_dev *ebid,
4041 struct atmel_ebi_dev_config *conf);
4142 int (*xlate_config)(struct atmel_ebi_dev *ebid,
....@@ -47,7 +48,7 @@
4748
4849 struct atmel_ebi {
4950 struct clk *clk;
50
- struct regmap *matrix;
51
+ struct regmap *regmap;
5152 struct {
5253 struct regmap *regmap;
5354 struct clk *clk;
....@@ -312,7 +313,7 @@
312313 if (ret)
313314 return ret;
314315
315
- if (cs >= AT91_MATRIX_EBI_NUM_CS ||
316
+ if (cs >= AT91_EBI_NUM_CS ||
316317 !(ebi->caps->available_cs & BIT(cs))) {
317318 dev_err(dev, "invalid reg property in %pOF\n", np);
318319 return -EINVAL;
....@@ -327,8 +328,7 @@
327328 return -EINVAL;
328329 }
329330
330
- ebid = devm_kzalloc(ebi->dev,
331
- sizeof(*ebid) + (numcs * sizeof(*ebid->configs)),
331
+ ebid = devm_kzalloc(ebi->dev, struct_size(ebid, configs, numcs),
332332 GFP_KERNEL);
333333 if (!ebid)
334334 return -ENOMEM;
....@@ -343,7 +343,7 @@
343343 apply = true;
344344
345345 i = 0;
346
- for_each_set_bit(cs, &cslines, AT91_MATRIX_EBI_NUM_CS) {
346
+ for_each_set_bit(cs, &cslines, AT91_EBI_NUM_CS) {
347347 ebid->configs[i].cs = cs;
348348
349349 if (apply) {
....@@ -358,7 +358,7 @@
358358 * one "atmel,smc-" property is present.
359359 */
360360 if (ebi->caps->ebi_csa_offs && apply)
361
- regmap_update_bits(ebi->matrix,
361
+ regmap_update_bits(ebi->regmap,
362362 ebi->caps->ebi_csa_offs,
363363 BIT(cs), 0);
364364
....@@ -373,6 +373,7 @@
373373 static const struct atmel_ebi_caps at91sam9260_ebi_caps = {
374374 .available_cs = 0xff,
375375 .ebi_csa_offs = AT91SAM9260_MATRIX_EBICSA,
376
+ .regmap_name = "atmel,matrix",
376377 .get_config = at91sam9_ebi_get_config,
377378 .xlate_config = atmel_ebi_xslate_smc_config,
378379 .apply_config = at91sam9_ebi_apply_config,
....@@ -381,6 +382,7 @@
381382 static const struct atmel_ebi_caps at91sam9261_ebi_caps = {
382383 .available_cs = 0xff,
383384 .ebi_csa_offs = AT91SAM9261_MATRIX_EBICSA,
385
+ .regmap_name = "atmel,matrix",
384386 .get_config = at91sam9_ebi_get_config,
385387 .xlate_config = atmel_ebi_xslate_smc_config,
386388 .apply_config = at91sam9_ebi_apply_config,
....@@ -389,6 +391,7 @@
389391 static const struct atmel_ebi_caps at91sam9263_ebi0_caps = {
390392 .available_cs = 0x3f,
391393 .ebi_csa_offs = AT91SAM9263_MATRIX_EBI0CSA,
394
+ .regmap_name = "atmel,matrix",
392395 .get_config = at91sam9_ebi_get_config,
393396 .xlate_config = atmel_ebi_xslate_smc_config,
394397 .apply_config = at91sam9_ebi_apply_config,
....@@ -397,6 +400,7 @@
397400 static const struct atmel_ebi_caps at91sam9263_ebi1_caps = {
398401 .available_cs = 0x7,
399402 .ebi_csa_offs = AT91SAM9263_MATRIX_EBI1CSA,
403
+ .regmap_name = "atmel,matrix",
400404 .get_config = at91sam9_ebi_get_config,
401405 .xlate_config = atmel_ebi_xslate_smc_config,
402406 .apply_config = at91sam9_ebi_apply_config,
....@@ -405,6 +409,7 @@
405409 static const struct atmel_ebi_caps at91sam9rl_ebi_caps = {
406410 .available_cs = 0x3f,
407411 .ebi_csa_offs = AT91SAM9RL_MATRIX_EBICSA,
412
+ .regmap_name = "atmel,matrix",
408413 .get_config = at91sam9_ebi_get_config,
409414 .xlate_config = atmel_ebi_xslate_smc_config,
410415 .apply_config = at91sam9_ebi_apply_config,
....@@ -413,6 +418,7 @@
413418 static const struct atmel_ebi_caps at91sam9g45_ebi_caps = {
414419 .available_cs = 0x3f,
415420 .ebi_csa_offs = AT91SAM9G45_MATRIX_EBICSA,
421
+ .regmap_name = "atmel,matrix",
416422 .get_config = at91sam9_ebi_get_config,
417423 .xlate_config = atmel_ebi_xslate_smc_config,
418424 .apply_config = at91sam9_ebi_apply_config,
....@@ -421,6 +427,7 @@
421427 static const struct atmel_ebi_caps at91sam9x5_ebi_caps = {
422428 .available_cs = 0x3f,
423429 .ebi_csa_offs = AT91SAM9X5_MATRIX_EBICSA,
430
+ .regmap_name = "atmel,matrix",
424431 .get_config = at91sam9_ebi_get_config,
425432 .xlate_config = atmel_ebi_xslate_smc_config,
426433 .apply_config = at91sam9_ebi_apply_config,
....@@ -431,6 +438,15 @@
431438 .get_config = sama5_ebi_get_config,
432439 .xlate_config = atmel_ebi_xslate_smc_config,
433440 .apply_config = sama5_ebi_apply_config,
441
+};
442
+
443
+static const struct atmel_ebi_caps sam9x60_ebi_caps = {
444
+ .available_cs = 0x3f,
445
+ .ebi_csa_offs = AT91_SFR_CCFG_EBICSA,
446
+ .regmap_name = "microchip,sfr",
447
+ .get_config = at91sam9_ebi_get_config,
448
+ .xlate_config = atmel_ebi_xslate_smc_config,
449
+ .apply_config = at91sam9_ebi_apply_config,
434450 };
435451
436452 static const struct of_device_id atmel_ebi_id_table[] = {
....@@ -465,6 +481,10 @@
465481 {
466482 .compatible = "atmel,sama5d3-ebi",
467483 .data = &sama5d3_ebi_caps,
484
+ },
485
+ {
486
+ .compatible = "microchip,sam9x60-ebi",
487
+ .data = &sam9x60_ebi_caps,
468488 },
469489 { /* sentinel */ }
470490 };
....@@ -524,33 +544,41 @@
524544 smc_np = of_parse_phandle(dev->of_node, "atmel,smc", 0);
525545
526546 ebi->smc.regmap = syscon_node_to_regmap(smc_np);
527
- if (IS_ERR(ebi->smc.regmap))
528
- return PTR_ERR(ebi->smc.regmap);
547
+ if (IS_ERR(ebi->smc.regmap)) {
548
+ ret = PTR_ERR(ebi->smc.regmap);
549
+ goto put_node;
550
+ }
529551
530552 ebi->smc.layout = atmel_hsmc_get_reg_layout(smc_np);
531
- if (IS_ERR(ebi->smc.layout))
532
- return PTR_ERR(ebi->smc.layout);
553
+ if (IS_ERR(ebi->smc.layout)) {
554
+ ret = PTR_ERR(ebi->smc.layout);
555
+ goto put_node;
556
+ }
533557
534558 ebi->smc.clk = of_clk_get(smc_np, 0);
535559 if (IS_ERR(ebi->smc.clk)) {
536
- if (PTR_ERR(ebi->smc.clk) != -ENOENT)
537
- return PTR_ERR(ebi->smc.clk);
560
+ if (PTR_ERR(ebi->smc.clk) != -ENOENT) {
561
+ ret = PTR_ERR(ebi->smc.clk);
562
+ goto put_node;
563
+ }
538564
539565 ebi->smc.clk = NULL;
540566 }
567
+ of_node_put(smc_np);
541568 ret = clk_prepare_enable(ebi->smc.clk);
542569 if (ret)
543570 return ret;
544571
545572 /*
546573 * The sama5d3 does not provide an EBICSA register and thus does need
547
- * to access the matrix registers.
574
+ * to access it.
548575 */
549576 if (ebi->caps->ebi_csa_offs) {
550
- ebi->matrix =
551
- syscon_regmap_lookup_by_phandle(np, "atmel,matrix");
552
- if (IS_ERR(ebi->matrix))
553
- return PTR_ERR(ebi->matrix);
577
+ ebi->regmap =
578
+ syscon_regmap_lookup_by_phandle(np,
579
+ ebi->caps->regmap_name);
580
+ if (IS_ERR(ebi->regmap))
581
+ return PTR_ERR(ebi->regmap);
554582 }
555583
556584 ret = of_property_read_u32(np, "#address-cells", &val);
....@@ -587,6 +615,10 @@
587615 }
588616
589617 return of_platform_populate(np, NULL, NULL, dev);
618
+
619
+put_node:
620
+ of_node_put(smc_np);
621
+ return ret;
590622 }
591623
592624 static __maybe_unused int atmel_ebi_resume(struct device *dev)