blob: 12080b05e3e6030ec635632725700c6e30e418a1 [file] [log] [blame]
Alexandre Bellonie81b6ab2014-07-08 18:21:12 +02001/*
2 * Atmel (Multi-port DDR-)SDRAM Controller driver
3 *
Paul Gortmaker563b41c2016-06-16 20:37:43 -04004 * Author: Alexandre Belloni <alexandre.belloni@free-electrons.com>
5 *
Alexandre Bellonie81b6ab2014-07-08 18:21:12 +02006 * Copyright (C) 2014 Atmel
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#include <linux/clk.h>
23#include <linux/err.h>
24#include <linux/kernel.h>
Paul Gortmaker563b41c2016-06-16 20:37:43 -040025#include <linux/init.h>
Alexandre Bellonie81b6ab2014-07-08 18:21:12 +020026#include <linux/of_platform.h>
27#include <linux/platform_device.h>
28
29struct at91_ramc_caps {
30 bool has_ddrck;
31 bool has_mpddr_clk;
32};
33
34static const struct at91_ramc_caps at91rm9200_caps = { };
35
36static const struct at91_ramc_caps at91sam9g45_caps = {
37 .has_ddrck = 1,
38 .has_mpddr_clk = 0,
39};
40
41static const struct at91_ramc_caps sama5d3_caps = {
42 .has_ddrck = 1,
43 .has_mpddr_clk = 1,
44};
45
46static const struct of_device_id atmel_ramc_of_match[] = {
47 { .compatible = "atmel,at91rm9200-sdramc", .data = &at91rm9200_caps, },
48 { .compatible = "atmel,at91sam9260-sdramc", .data = &at91rm9200_caps, },
49 { .compatible = "atmel,at91sam9g45-ddramc", .data = &at91sam9g45_caps, },
50 { .compatible = "atmel,sama5d3-ddramc", .data = &sama5d3_caps, },
51 {},
52};
Alexandre Bellonie81b6ab2014-07-08 18:21:12 +020053
54static int atmel_ramc_probe(struct platform_device *pdev)
55{
Alexandre Bellonie81b6ab2014-07-08 18:21:12 +020056 const struct at91_ramc_caps *caps;
57 struct clk *clk;
58
LABBE Corentin79221182016-08-16 15:53:18 +020059 caps = of_device_get_match_data(&pdev->dev);
Alexandre Bellonie81b6ab2014-07-08 18:21:12 +020060
61 if (caps->has_ddrck) {
62 clk = devm_clk_get(&pdev->dev, "ddrck");
63 if (IS_ERR(clk))
64 return PTR_ERR(clk);
65 clk_prepare_enable(clk);
66 }
67
68 if (caps->has_mpddr_clk) {
69 clk = devm_clk_get(&pdev->dev, "mpddr");
70 if (IS_ERR(clk)) {
71 pr_err("AT91 RAMC: couldn't get mpddr clock\n");
72 return PTR_ERR(clk);
73 }
74 clk_prepare_enable(clk);
75 }
76
77 return 0;
78}
79
80static struct platform_driver atmel_ramc_driver = {
81 .probe = atmel_ramc_probe,
82 .driver = {
83 .name = "atmel-ramc",
Alexandre Bellonie81b6ab2014-07-08 18:21:12 +020084 .of_match_table = atmel_ramc_of_match,
85 },
86};
87
88static int __init atmel_ramc_init(void)
89{
90 return platform_driver_register(&atmel_ramc_driver);
91}
Paul Gortmaker563b41c2016-06-16 20:37:43 -040092device_initcall(atmel_ramc_init);