Thomas Gleixner | 2b72c9e | 2019-05-29 16:57:54 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Alexandre Belloni | e81b6ab | 2014-07-08 18:21:12 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Atmel (Multi-port DDR-)SDRAM Controller driver |
| 4 | * |
Paul Gortmaker | 563b41c | 2016-06-16 20:37:43 -0400 | [diff] [blame] | 5 | * Author: Alexandre Belloni <alexandre.belloni@free-electrons.com> |
| 6 | * |
Alexandre Belloni | e81b6ab | 2014-07-08 18:21:12 +0200 | [diff] [blame] | 7 | * Copyright (C) 2014 Atmel |
Alexandre Belloni | e81b6ab | 2014-07-08 18:21:12 +0200 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/clk.h> |
| 11 | #include <linux/err.h> |
| 12 | #include <linux/kernel.h> |
Paul Gortmaker | 563b41c | 2016-06-16 20:37:43 -0400 | [diff] [blame] | 13 | #include <linux/init.h> |
Alexandre Belloni | e81b6ab | 2014-07-08 18:21:12 +0200 | [diff] [blame] | 14 | #include <linux/of_platform.h> |
| 15 | #include <linux/platform_device.h> |
| 16 | |
| 17 | struct at91_ramc_caps { |
| 18 | bool has_ddrck; |
| 19 | bool has_mpddr_clk; |
| 20 | }; |
| 21 | |
| 22 | static const struct at91_ramc_caps at91rm9200_caps = { }; |
| 23 | |
| 24 | static const struct at91_ramc_caps at91sam9g45_caps = { |
| 25 | .has_ddrck = 1, |
| 26 | .has_mpddr_clk = 0, |
| 27 | }; |
| 28 | |
| 29 | static const struct at91_ramc_caps sama5d3_caps = { |
| 30 | .has_ddrck = 1, |
| 31 | .has_mpddr_clk = 1, |
| 32 | }; |
| 33 | |
| 34 | static 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 | }; |
Alexandre Belloni | e81b6ab | 2014-07-08 18:21:12 +0200 | [diff] [blame] | 41 | |
| 42 | static int atmel_ramc_probe(struct platform_device *pdev) |
| 43 | { |
Alexandre Belloni | e81b6ab | 2014-07-08 18:21:12 +0200 | [diff] [blame] | 44 | const struct at91_ramc_caps *caps; |
| 45 | struct clk *clk; |
| 46 | |
LABBE Corentin | 7922118 | 2016-08-16 15:53:18 +0200 | [diff] [blame] | 47 | caps = of_device_get_match_data(&pdev->dev); |
Alexandre Belloni | e81b6ab | 2014-07-08 18:21:12 +0200 | [diff] [blame] | 48 | |
| 49 | if (caps->has_ddrck) { |
| 50 | clk = devm_clk_get(&pdev->dev, "ddrck"); |
| 51 | if (IS_ERR(clk)) |
| 52 | return PTR_ERR(clk); |
| 53 | clk_prepare_enable(clk); |
| 54 | } |
| 55 | |
| 56 | if (caps->has_mpddr_clk) { |
| 57 | clk = devm_clk_get(&pdev->dev, "mpddr"); |
| 58 | if (IS_ERR(clk)) { |
| 59 | pr_err("AT91 RAMC: couldn't get mpddr clock\n"); |
| 60 | return PTR_ERR(clk); |
| 61 | } |
| 62 | clk_prepare_enable(clk); |
| 63 | } |
| 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | static struct platform_driver atmel_ramc_driver = { |
| 69 | .probe = atmel_ramc_probe, |
| 70 | .driver = { |
| 71 | .name = "atmel-ramc", |
Alexandre Belloni | e81b6ab | 2014-07-08 18:21:12 +0200 | [diff] [blame] | 72 | .of_match_table = atmel_ramc_of_match, |
| 73 | }, |
| 74 | }; |
| 75 | |
Wei Yongjun | af69240 | 2016-09-16 13:05:10 +0000 | [diff] [blame] | 76 | builtin_platform_driver(atmel_ramc_driver); |