From a5969cabbb4660eab42b6ef0412cbbd1200cf14d Mon Sep 17 00:00:00 2001
From: hc <hc@nodka.com>
Date: Sat, 12 Oct 2024 07:10:09 +0000
Subject: [PATCH] 修改led为gpio
---
kernel/drivers/clk/mvebu/ap806-system-controller.c | 183 +++++++++++++++++++++++++++++++--------------
1 files changed, 127 insertions(+), 56 deletions(-)
diff --git a/kernel/drivers/clk/mvebu/ap806-system-controller.c b/kernel/drivers/clk/mvebu/ap806-system-controller.c
index fa2fbd2..948bd1e 100644
--- a/kernel/drivers/clk/mvebu/ap806-system-controller.c
+++ b/kernel/drivers/clk/mvebu/ap806-system-controller.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
/*
* Marvell Armada AP806 System Controller
*
@@ -5,25 +6,22 @@
*
* Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
*
- * This file is licensed under the terms of the GNU General Public
- * License version 2. This program is licensed "as is" without any
- * warranty of any kind, whether express or implied.
*/
#define pr_fmt(fmt) "ap806-system-controller: " fmt
+#include "armada_ap_cp_helper.h"
#include <linux/clk-provider.h>
#include <linux/mfd/syscon.h>
#include <linux/init.h>
#include <linux/of.h>
-#include <linux/of_address.h>
#include <linux/platform_device.h>
#include <linux/regmap.h>
#define AP806_SAR_REG 0x400
#define AP806_SAR_CLKFREQ_MODE_MASK 0x1f
-#define AP806_CLK_NUM 5
+#define AP806_CLK_NUM 6
static struct clk *ap806_clks[AP806_CLK_NUM];
@@ -32,22 +30,106 @@
.clk_num = AP806_CLK_NUM,
};
-static char *ap806_unique_name(struct device *dev, struct device_node *np,
- char *name)
+static int ap806_get_sar_clocks(unsigned int freq_mode,
+ unsigned int *cpuclk_freq,
+ unsigned int *dclk_freq)
{
- const __be32 *reg;
- u64 addr;
+ switch (freq_mode) {
+ case 0x0:
+ *cpuclk_freq = 2000;
+ *dclk_freq = 600;
+ break;
+ case 0x1:
+ *cpuclk_freq = 2000;
+ *dclk_freq = 525;
+ break;
+ case 0x6:
+ *cpuclk_freq = 1800;
+ *dclk_freq = 600;
+ break;
+ case 0x7:
+ *cpuclk_freq = 1800;
+ *dclk_freq = 525;
+ break;
+ case 0x4:
+ *cpuclk_freq = 1600;
+ *dclk_freq = 400;
+ break;
+ case 0xB:
+ *cpuclk_freq = 1600;
+ *dclk_freq = 450;
+ break;
+ case 0xD:
+ *cpuclk_freq = 1600;
+ *dclk_freq = 525;
+ break;
+ case 0x1a:
+ *cpuclk_freq = 1400;
+ *dclk_freq = 400;
+ break;
+ case 0x14:
+ *cpuclk_freq = 1300;
+ *dclk_freq = 400;
+ break;
+ case 0x17:
+ *cpuclk_freq = 1300;
+ *dclk_freq = 325;
+ break;
+ case 0x19:
+ *cpuclk_freq = 1200;
+ *dclk_freq = 400;
+ break;
+ case 0x13:
+ *cpuclk_freq = 1000;
+ *dclk_freq = 325;
+ break;
+ case 0x1d:
+ *cpuclk_freq = 1000;
+ *dclk_freq = 400;
+ break;
+ case 0x1c:
+ *cpuclk_freq = 800;
+ *dclk_freq = 400;
+ break;
+ case 0x1b:
+ *cpuclk_freq = 600;
+ *dclk_freq = 400;
+ break;
+ default:
+ return -EINVAL;
+ }
- reg = of_get_property(np, "reg", NULL);
- addr = of_translate_address(np, reg);
- return devm_kasprintf(dev, GFP_KERNEL, "%llx-%s",
- (unsigned long long)addr, name);
+ return 0;
+}
+
+static int ap807_get_sar_clocks(unsigned int freq_mode,
+ unsigned int *cpuclk_freq,
+ unsigned int *dclk_freq)
+{
+ switch (freq_mode) {
+ case 0x0:
+ *cpuclk_freq = 2000;
+ *dclk_freq = 1200;
+ break;
+ case 0x6:
+ *cpuclk_freq = 2200;
+ *dclk_freq = 1200;
+ break;
+ case 0xD:
+ *cpuclk_freq = 1600;
+ *dclk_freq = 1200;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return 0;
}
static int ap806_syscon_common_probe(struct platform_device *pdev,
struct device_node *syscon_node)
{
- unsigned int freq_mode, cpuclk_freq;
+ unsigned int freq_mode, cpuclk_freq, dclk_freq;
const char *name, *fixedclk_name;
struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node;
@@ -68,50 +150,29 @@
}
freq_mode = reg & AP806_SAR_CLKFREQ_MODE_MASK;
- switch (freq_mode) {
- case 0x0:
- case 0x1:
- cpuclk_freq = 2000;
- break;
- case 0x6:
- case 0x7:
- cpuclk_freq = 1800;
- break;
- case 0x4:
- case 0xB:
- case 0xD:
- cpuclk_freq = 1600;
- break;
- case 0x1a:
- cpuclk_freq = 1400;
- break;
- case 0x14:
- case 0x17:
- cpuclk_freq = 1300;
- break;
- case 0x19:
- cpuclk_freq = 1200;
- break;
- case 0x13:
- case 0x1d:
- cpuclk_freq = 1000;
- break;
- case 0x1c:
- cpuclk_freq = 800;
- break;
- case 0x1b:
- cpuclk_freq = 600;
- break;
- default:
- dev_err(dev, "invalid SAR value\n");
+
+ if (of_device_is_compatible(pdev->dev.of_node,
+ "marvell,ap806-clock")) {
+ ret = ap806_get_sar_clocks(freq_mode, &cpuclk_freq, &dclk_freq);
+ } else if (of_device_is_compatible(pdev->dev.of_node,
+ "marvell,ap807-clock")) {
+ ret = ap807_get_sar_clocks(freq_mode, &cpuclk_freq, &dclk_freq);
+ } else {
+ dev_err(dev, "compatible not supported\n");
return -EINVAL;
+ }
+
+ if (ret) {
+ dev_err(dev, "invalid Sample at Reset value\n");
+ return ret;
}
/* Convert to hertz */
cpuclk_freq *= 1000 * 1000;
+ dclk_freq *= 1000 * 1000;
/* CPU clocks depend on the Sample At Reset configuration */
- name = ap806_unique_name(dev, syscon_node, "cpu-cluster-0");
+ name = ap_cp_unique_name(dev, syscon_node, "pll-cluster-0");
ap806_clks[0] = clk_register_fixed_rate(dev, name, NULL,
0, cpuclk_freq);
if (IS_ERR(ap806_clks[0])) {
@@ -119,7 +180,7 @@
goto fail0;
}
- name = ap806_unique_name(dev, syscon_node, "cpu-cluster-1");
+ name = ap_cp_unique_name(dev, syscon_node, "pll-cluster-1");
ap806_clks[1] = clk_register_fixed_rate(dev, name, NULL, 0,
cpuclk_freq);
if (IS_ERR(ap806_clks[1])) {
@@ -128,7 +189,7 @@
}
/* Fixed clock is always 1200 Mhz */
- fixedclk_name = ap806_unique_name(dev, syscon_node, "fixed");
+ fixedclk_name = ap_cp_unique_name(dev, syscon_node, "fixed");
ap806_clks[2] = clk_register_fixed_rate(dev, fixedclk_name, NULL,
0, 1200 * 1000 * 1000);
if (IS_ERR(ap806_clks[2])) {
@@ -137,7 +198,7 @@
}
/* MSS Clock is fixed clock divided by 6 */
- name = ap806_unique_name(dev, syscon_node, "mss");
+ name = ap_cp_unique_name(dev, syscon_node, "mss");
ap806_clks[3] = clk_register_fixed_factor(NULL, name, fixedclk_name,
0, 1, 6);
if (IS_ERR(ap806_clks[3])) {
@@ -146,7 +207,7 @@
}
/* SDIO(/eMMC) Clock is fixed clock divided by 3 */
- name = ap806_unique_name(dev, syscon_node, "sdio");
+ name = ap_cp_unique_name(dev, syscon_node, "sdio");
ap806_clks[4] = clk_register_fixed_factor(NULL, name,
fixedclk_name,
0, 1, 3);
@@ -155,7 +216,14 @@
goto fail4;
}
- of_clk_add_provider(np, of_clk_src_onecell_get, &ap806_clk_data);
+ /* AP-DCLK(HCLK) Clock is DDR clock divided by 2 */
+ name = ap_cp_unique_name(dev, syscon_node, "ap-dclk");
+ ap806_clks[5] = clk_register_fixed_rate(dev, name, NULL, 0, dclk_freq);
+ if (IS_ERR(ap806_clks[5])) {
+ ret = PTR_ERR(ap806_clks[5]);
+ goto fail5;
+ }
+
ret = of_clk_add_provider(np, of_clk_src_onecell_get, &ap806_clk_data);
if (ret)
goto fail_clk_add;
@@ -163,6 +231,8 @@
return 0;
fail_clk_add:
+ clk_unregister_fixed_factor(ap806_clks[5]);
+fail5:
clk_unregister_fixed_factor(ap806_clks[4]);
fail4:
clk_unregister_fixed_factor(ap806_clks[3]);
@@ -209,6 +279,7 @@
static const struct of_device_id ap806_clock_of_match[] = {
{ .compatible = "marvell,ap806-clock", },
+ { .compatible = "marvell,ap807-clock", },
{ }
};
--
Gitblit v1.6.2