2018-09-12 09:40:17 -04:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-04-14 11:33:31 -04:00
|
|
|
/*
|
|
|
|
* Marvell Armada AP806 System Controller
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 Marvell
|
|
|
|
*
|
|
|
|
* Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define pr_fmt(fmt) "ap806-system-controller: " fmt
|
|
|
|
|
2019-07-10 09:43:42 -04:00
|
|
|
#include "armada_ap_cp_helper.h"
|
2016-04-14 11:33:31 -04:00
|
|
|
#include <linux/clk-provider.h>
|
|
|
|
#include <linux/mfd/syscon.h>
|
2016-07-04 17:12:14 -04:00
|
|
|
#include <linux/init.h>
|
2016-04-14 11:33:31 -04:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/regmap.h>
|
|
|
|
|
|
|
|
#define AP806_SAR_REG 0x400
|
|
|
|
#define AP806_SAR_CLKFREQ_MODE_MASK 0x1f
|
|
|
|
|
2019-08-05 06:03:08 -04:00
|
|
|
#define AP806_CLK_NUM 6
|
2016-04-14 11:33:31 -04:00
|
|
|
|
|
|
|
static struct clk *ap806_clks[AP806_CLK_NUM];
|
|
|
|
|
|
|
|
static struct clk_onecell_data ap806_clk_data = {
|
|
|
|
.clks = ap806_clks,
|
|
|
|
.clk_num = AP806_CLK_NUM,
|
|
|
|
};
|
|
|
|
|
2019-08-05 06:03:09 -04:00
|
|
|
static int ap806_get_sar_clocks(unsigned int freq_mode,
|
|
|
|
unsigned int *cpuclk_freq,
|
|
|
|
unsigned int *dclk_freq)
|
2016-04-14 11:33:31 -04:00
|
|
|
{
|
|
|
|
switch (freq_mode) {
|
2016-12-22 07:08:14 -05:00
|
|
|
case 0x0:
|
2019-08-05 06:03:09 -04:00
|
|
|
*cpuclk_freq = 2000;
|
|
|
|
*dclk_freq = 600;
|
|
|
|
break;
|
2016-12-22 07:08:14 -05:00
|
|
|
case 0x1:
|
2019-08-05 06:03:09 -04:00
|
|
|
*cpuclk_freq = 2000;
|
|
|
|
*dclk_freq = 525;
|
2016-04-14 11:33:31 -04:00
|
|
|
break;
|
2016-12-22 07:08:14 -05:00
|
|
|
case 0x6:
|
2019-08-05 06:03:09 -04:00
|
|
|
*cpuclk_freq = 1800;
|
|
|
|
*dclk_freq = 600;
|
|
|
|
break;
|
2016-12-22 07:08:14 -05:00
|
|
|
case 0x7:
|
2019-08-05 06:03:09 -04:00
|
|
|
*cpuclk_freq = 1800;
|
|
|
|
*dclk_freq = 525;
|
2016-04-14 11:33:31 -04:00
|
|
|
break;
|
2016-12-22 07:08:14 -05:00
|
|
|
case 0x4:
|
2019-08-05 06:03:09 -04:00
|
|
|
*cpuclk_freq = 1600;
|
|
|
|
*dclk_freq = 400;
|
|
|
|
break;
|
2016-12-22 07:08:14 -05:00
|
|
|
case 0xB:
|
2019-08-05 06:03:09 -04:00
|
|
|
*cpuclk_freq = 1600;
|
|
|
|
*dclk_freq = 450;
|
|
|
|
break;
|
2016-12-22 07:08:14 -05:00
|
|
|
case 0xD:
|
2019-08-05 06:03:09 -04:00
|
|
|
*cpuclk_freq = 1600;
|
|
|
|
*dclk_freq = 525;
|
2016-04-14 11:33:31 -04:00
|
|
|
break;
|
2016-12-22 07:08:14 -05:00
|
|
|
case 0x1a:
|
2019-08-05 06:03:09 -04:00
|
|
|
*cpuclk_freq = 1400;
|
|
|
|
*dclk_freq = 400;
|
2016-04-14 11:33:31 -04:00
|
|
|
break;
|
2016-12-22 07:08:14 -05:00
|
|
|
case 0x14:
|
2019-08-05 06:03:09 -04:00
|
|
|
*cpuclk_freq = 1300;
|
|
|
|
*dclk_freq = 400;
|
|
|
|
break;
|
2016-12-22 07:08:14 -05:00
|
|
|
case 0x17:
|
2019-08-05 06:03:09 -04:00
|
|
|
*cpuclk_freq = 1300;
|
|
|
|
*dclk_freq = 325;
|
2016-04-14 11:33:31 -04:00
|
|
|
break;
|
2016-12-22 07:08:14 -05:00
|
|
|
case 0x19:
|
2019-08-05 06:03:09 -04:00
|
|
|
*cpuclk_freq = 1200;
|
|
|
|
*dclk_freq = 400;
|
2016-12-22 07:08:14 -05:00
|
|
|
break;
|
|
|
|
case 0x13:
|
2019-08-05 06:03:09 -04:00
|
|
|
*cpuclk_freq = 1000;
|
|
|
|
*dclk_freq = 325;
|
|
|
|
break;
|
2016-12-22 07:08:14 -05:00
|
|
|
case 0x1d:
|
2019-08-05 06:03:09 -04:00
|
|
|
*cpuclk_freq = 1000;
|
|
|
|
*dclk_freq = 400;
|
2016-12-22 07:08:14 -05:00
|
|
|
break;
|
|
|
|
case 0x1c:
|
2019-08-05 06:03:09 -04:00
|
|
|
*cpuclk_freq = 800;
|
|
|
|
*dclk_freq = 400;
|
2016-12-22 07:08:14 -05:00
|
|
|
break;
|
|
|
|
case 0x1b:
|
2019-08-05 06:03:09 -04:00
|
|
|
*cpuclk_freq = 600;
|
|
|
|
*dclk_freq = 400;
|
2016-12-22 07:08:14 -05:00
|
|
|
break;
|
2016-04-14 11:33:31 -04:00
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2019-08-05 06:03:09 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-08-05 06:03:10 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-08-05 06:03:09 -04:00
|
|
|
static int ap806_syscon_common_probe(struct platform_device *pdev,
|
|
|
|
struct device_node *syscon_node)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
struct regmap *regmap;
|
|
|
|
u32 reg;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
regmap = syscon_node_to_regmap(syscon_node);
|
|
|
|
if (IS_ERR(regmap)) {
|
|
|
|
dev_err(dev, "cannot get regmap\n");
|
|
|
|
return PTR_ERR(regmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = regmap_read(regmap, AP806_SAR_REG, ®);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "cannot read from regmap\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
freq_mode = reg & AP806_SAR_CLKFREQ_MODE_MASK;
|
|
|
|
|
|
|
|
if (of_device_is_compatible(pdev->dev.of_node,
|
|
|
|
"marvell,ap806-clock")) {
|
|
|
|
ret = ap806_get_sar_clocks(freq_mode, &cpuclk_freq, &dclk_freq);
|
2019-08-05 06:03:10 -04:00
|
|
|
} else if (of_device_is_compatible(pdev->dev.of_node,
|
|
|
|
"marvell,ap807-clock")) {
|
|
|
|
ret = ap807_get_sar_clocks(freq_mode, &cpuclk_freq, &dclk_freq);
|
2019-08-05 06:03:09 -04:00
|
|
|
} else {
|
|
|
|
dev_err(dev, "compatible not supported\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret) {
|
2019-08-05 06:03:08 -04:00
|
|
|
dev_err(dev, "invalid Sample at Reset value\n");
|
2019-08-05 06:03:09 -04:00
|
|
|
return ret;
|
2019-08-05 06:03:08 -04:00
|
|
|
}
|
|
|
|
|
2016-04-14 11:33:31 -04:00
|
|
|
/* Convert to hertz */
|
|
|
|
cpuclk_freq *= 1000 * 1000;
|
2019-08-05 06:03:08 -04:00
|
|
|
dclk_freq *= 1000 * 1000;
|
2016-04-14 11:33:31 -04:00
|
|
|
|
|
|
|
/* CPU clocks depend on the Sample At Reset configuration */
|
2019-07-10 09:43:44 -04:00
|
|
|
name = ap_cp_unique_name(dev, syscon_node, "pll-cluster-0");
|
2017-05-31 10:07:22 -04:00
|
|
|
ap806_clks[0] = clk_register_fixed_rate(dev, name, NULL,
|
2016-04-14 11:33:31 -04:00
|
|
|
0, cpuclk_freq);
|
|
|
|
if (IS_ERR(ap806_clks[0])) {
|
|
|
|
ret = PTR_ERR(ap806_clks[0]);
|
|
|
|
goto fail0;
|
|
|
|
}
|
|
|
|
|
2019-07-10 09:43:44 -04:00
|
|
|
name = ap_cp_unique_name(dev, syscon_node, "pll-cluster-1");
|
2017-05-31 10:07:22 -04:00
|
|
|
ap806_clks[1] = clk_register_fixed_rate(dev, name, NULL, 0,
|
2016-04-14 11:33:31 -04:00
|
|
|
cpuclk_freq);
|
|
|
|
if (IS_ERR(ap806_clks[1])) {
|
|
|
|
ret = PTR_ERR(ap806_clks[1]);
|
|
|
|
goto fail1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fixed clock is always 1200 Mhz */
|
2019-07-10 09:43:42 -04:00
|
|
|
fixedclk_name = ap_cp_unique_name(dev, syscon_node, "fixed");
|
2017-05-31 10:07:22 -04:00
|
|
|
ap806_clks[2] = clk_register_fixed_rate(dev, fixedclk_name, NULL,
|
2016-04-14 11:33:31 -04:00
|
|
|
0, 1200 * 1000 * 1000);
|
|
|
|
if (IS_ERR(ap806_clks[2])) {
|
|
|
|
ret = PTR_ERR(ap806_clks[2]);
|
|
|
|
goto fail2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* MSS Clock is fixed clock divided by 6 */
|
2019-07-10 09:43:42 -04:00
|
|
|
name = ap_cp_unique_name(dev, syscon_node, "mss");
|
2016-04-14 11:33:31 -04:00
|
|
|
ap806_clks[3] = clk_register_fixed_factor(NULL, name, fixedclk_name,
|
|
|
|
0, 1, 6);
|
|
|
|
if (IS_ERR(ap806_clks[3])) {
|
|
|
|
ret = PTR_ERR(ap806_clks[3]);
|
|
|
|
goto fail3;
|
|
|
|
}
|
|
|
|
|
2017-05-31 10:07:24 -04:00
|
|
|
/* SDIO(/eMMC) Clock is fixed clock divided by 3 */
|
2019-07-10 09:43:42 -04:00
|
|
|
name = ap_cp_unique_name(dev, syscon_node, "sdio");
|
2017-05-31 10:07:24 -04:00
|
|
|
ap806_clks[4] = clk_register_fixed_factor(NULL, name,
|
|
|
|
fixedclk_name,
|
|
|
|
0, 1, 3);
|
|
|
|
if (IS_ERR(ap806_clks[4])) {
|
|
|
|
ret = PTR_ERR(ap806_clks[4]);
|
|
|
|
goto fail4;
|
2017-03-30 11:22:53 -04:00
|
|
|
}
|
|
|
|
|
2019-08-05 06:03:08 -04:00
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
2016-04-14 11:33:31 -04:00
|
|
|
ret = of_clk_add_provider(np, of_clk_src_onecell_get, &ap806_clk_data);
|
|
|
|
if (ret)
|
|
|
|
goto fail_clk_add;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail_clk_add:
|
2019-08-05 06:03:08 -04:00
|
|
|
clk_unregister_fixed_factor(ap806_clks[5]);
|
|
|
|
fail5:
|
2017-03-30 11:22:53 -04:00
|
|
|
clk_unregister_fixed_factor(ap806_clks[4]);
|
|
|
|
fail4:
|
2016-04-14 11:33:31 -04:00
|
|
|
clk_unregister_fixed_factor(ap806_clks[3]);
|
|
|
|
fail3:
|
|
|
|
clk_unregister_fixed_rate(ap806_clks[2]);
|
|
|
|
fail2:
|
|
|
|
clk_unregister_fixed_rate(ap806_clks[1]);
|
|
|
|
fail1:
|
|
|
|
clk_unregister_fixed_rate(ap806_clks[0]);
|
|
|
|
fail0:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
clk: mvebu: ap806: introduce a new binding
As for cp110, the initial intent when the binding of the ap806 system
controller was to have one flat node. The idea being that what is
currently a clock-only driver in drivers would become a MFD driver,
exposing the clock, GPIO and pinctrl functionality. However, after taking
a step back, this would lead to a messy binding. Indeed, a single node
would be a GPIO controller, clock controller, pinmux controller, and
more.
This patch adopts a more classical solution of a top-level syscon node
with sub-nodes for the individual devices. The main benefit will be to
have each functional block associated to its own sub-node where we can
put its own properties.
The introduction of the Armada 7K/8K is still in the early stage so the
plan is to remove the old binding. However, we don't want to break the
device tree compatibility for the few devices already in the field. For
this we still keep the support of the legacy compatible string with a big
warning in the kernel about updating the device tree.
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
Signed-off-by: Michael Turquette <mturquette@baylibre.com>
Link: lkml.kernel.org/r/cc8c8c40fa4c4e71133033358992ec38e5aa2be5.1496239589.git-series.gregory.clement@free-electrons.com
2017-05-31 10:07:26 -04:00
|
|
|
static int ap806_syscon_legacy_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
dev_warn(&pdev->dev, FW_WARN "Using legacy device tree binding\n");
|
|
|
|
dev_warn(&pdev->dev, FW_WARN "Update your device tree:\n");
|
|
|
|
dev_warn(&pdev->dev, FW_WARN
|
|
|
|
"This binding won't be supported in future kernel\n");
|
|
|
|
|
|
|
|
return ap806_syscon_common_probe(pdev, pdev->dev.of_node);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ap806_clock_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
return ap806_syscon_common_probe(pdev, pdev->dev.of_node->parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct of_device_id ap806_syscon_legacy_of_match[] = {
|
2016-04-14 11:33:31 -04:00
|
|
|
{ .compatible = "marvell,ap806-system-controller", },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
clk: mvebu: ap806: introduce a new binding
As for cp110, the initial intent when the binding of the ap806 system
controller was to have one flat node. The idea being that what is
currently a clock-only driver in drivers would become a MFD driver,
exposing the clock, GPIO and pinctrl functionality. However, after taking
a step back, this would lead to a messy binding. Indeed, a single node
would be a GPIO controller, clock controller, pinmux controller, and
more.
This patch adopts a more classical solution of a top-level syscon node
with sub-nodes for the individual devices. The main benefit will be to
have each functional block associated to its own sub-node where we can
put its own properties.
The introduction of the Armada 7K/8K is still in the early stage so the
plan is to remove the old binding. However, we don't want to break the
device tree compatibility for the few devices already in the field. For
this we still keep the support of the legacy compatible string with a big
warning in the kernel about updating the device tree.
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
Signed-off-by: Michael Turquette <mturquette@baylibre.com>
Link: lkml.kernel.org/r/cc8c8c40fa4c4e71133033358992ec38e5aa2be5.1496239589.git-series.gregory.clement@free-electrons.com
2017-05-31 10:07:26 -04:00
|
|
|
static struct platform_driver ap806_syscon_legacy_driver = {
|
|
|
|
.probe = ap806_syscon_legacy_probe,
|
2016-04-14 11:33:31 -04:00
|
|
|
.driver = {
|
|
|
|
.name = "marvell-ap806-system-controller",
|
clk: mvebu: ap806: introduce a new binding
As for cp110, the initial intent when the binding of the ap806 system
controller was to have one flat node. The idea being that what is
currently a clock-only driver in drivers would become a MFD driver,
exposing the clock, GPIO and pinctrl functionality. However, after taking
a step back, this would lead to a messy binding. Indeed, a single node
would be a GPIO controller, clock controller, pinmux controller, and
more.
This patch adopts a more classical solution of a top-level syscon node
with sub-nodes for the individual devices. The main benefit will be to
have each functional block associated to its own sub-node where we can
put its own properties.
The introduction of the Armada 7K/8K is still in the early stage so the
plan is to remove the old binding. However, we don't want to break the
device tree compatibility for the few devices already in the field. For
this we still keep the support of the legacy compatible string with a big
warning in the kernel about updating the device tree.
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
Signed-off-by: Michael Turquette <mturquette@baylibre.com>
Link: lkml.kernel.org/r/cc8c8c40fa4c4e71133033358992ec38e5aa2be5.1496239589.git-series.gregory.clement@free-electrons.com
2017-05-31 10:07:26 -04:00
|
|
|
.of_match_table = ap806_syscon_legacy_of_match,
|
|
|
|
.suppress_bind_attrs = true,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
builtin_platform_driver(ap806_syscon_legacy_driver);
|
|
|
|
|
|
|
|
static const struct of_device_id ap806_clock_of_match[] = {
|
|
|
|
{ .compatible = "marvell,ap806-clock", },
|
2019-08-05 06:03:10 -04:00
|
|
|
{ .compatible = "marvell,ap807-clock", },
|
clk: mvebu: ap806: introduce a new binding
As for cp110, the initial intent when the binding of the ap806 system
controller was to have one flat node. The idea being that what is
currently a clock-only driver in drivers would become a MFD driver,
exposing the clock, GPIO and pinctrl functionality. However, after taking
a step back, this would lead to a messy binding. Indeed, a single node
would be a GPIO controller, clock controller, pinmux controller, and
more.
This patch adopts a more classical solution of a top-level syscon node
with sub-nodes for the individual devices. The main benefit will be to
have each functional block associated to its own sub-node where we can
put its own properties.
The introduction of the Armada 7K/8K is still in the early stage so the
plan is to remove the old binding. However, we don't want to break the
device tree compatibility for the few devices already in the field. For
this we still keep the support of the legacy compatible string with a big
warning in the kernel about updating the device tree.
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
Signed-off-by: Michael Turquette <mturquette@baylibre.com>
Link: lkml.kernel.org/r/cc8c8c40fa4c4e71133033358992ec38e5aa2be5.1496239589.git-series.gregory.clement@free-electrons.com
2017-05-31 10:07:26 -04:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct platform_driver ap806_clock_driver = {
|
|
|
|
.probe = ap806_clock_probe,
|
|
|
|
.driver = {
|
|
|
|
.name = "marvell-ap806-clock",
|
|
|
|
.of_match_table = ap806_clock_of_match,
|
2016-07-04 17:12:14 -04:00
|
|
|
.suppress_bind_attrs = true,
|
2016-04-14 11:33:31 -04:00
|
|
|
},
|
|
|
|
};
|
clk: mvebu: ap806: introduce a new binding
As for cp110, the initial intent when the binding of the ap806 system
controller was to have one flat node. The idea being that what is
currently a clock-only driver in drivers would become a MFD driver,
exposing the clock, GPIO and pinctrl functionality. However, after taking
a step back, this would lead to a messy binding. Indeed, a single node
would be a GPIO controller, clock controller, pinmux controller, and
more.
This patch adopts a more classical solution of a top-level syscon node
with sub-nodes for the individual devices. The main benefit will be to
have each functional block associated to its own sub-node where we can
put its own properties.
The introduction of the Armada 7K/8K is still in the early stage so the
plan is to remove the old binding. However, we don't want to break the
device tree compatibility for the few devices already in the field. For
this we still keep the support of the legacy compatible string with a big
warning in the kernel about updating the device tree.
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
Signed-off-by: Michael Turquette <mturquette@baylibre.com>
Link: lkml.kernel.org/r/cc8c8c40fa4c4e71133033358992ec38e5aa2be5.1496239589.git-series.gregory.clement@free-electrons.com
2017-05-31 10:07:26 -04:00
|
|
|
builtin_platform_driver(ap806_clock_driver);
|