Linux Audio

Check our new training course

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