PM / devfreq: rockchip_dmc: add support for rk3128 dmc

This adds the necessary data for handling dmcfreq on the rk3128.

Change-Id: I6aeae7103c1eaed0b4515d8d11863c4b190b6918
Signed-off-by: Liang Chen <cl@rock-chips.com>
This commit is contained in:
Liang Chen 2017-09-05 15:37:14 +08:00 committed by Huang, Tao
parent 0d5567697f
commit 400617b950
4 changed files with 226 additions and 4 deletions

View File

@ -2,6 +2,7 @@
Required properties:
- compatible: Should be one of the following.
- "rockchip,rk3128-dmc" - for RK3128 SoCs.
- "rockchip,rk3288-dmc" - for RK3288 SoCs.
- "rockchip,rk3368-dmc" - for RK3368 SoCs.
- "rockchip,rk3399-dmc" - for RK3399 SoCs.

View File

@ -217,10 +217,10 @@ static struct rockchip_clk_branch common_clk_branches[] __initdata = {
RK2928_CLKGATE_CON(0), 2, GFLAGS),
GATE(0, "gpll_div2_ddr", "gpll_div2", CLK_IGNORE_UNUSED,
RK2928_CLKGATE_CON(0), 2, GFLAGS),
COMPOSITE_NOGATE(0, "ddrphy2x", mux_ddrphy_p, CLK_IGNORE_UNUSED,
RK2928_CLKSEL_CON(26), 8, 2, MFLAGS, 0, 2, DFLAGS | CLK_DIVIDER_POWER_OF_TWO),
FACTOR(SCLK_DDRC, "clk_ddrc", "ddrphy2x", 0, 1, 2),
FACTOR(0, "clk_ddrphy", "ddrphy2x", 0, 1, 2),
COMPOSITE_DDRCLK(SCLK_DDRC, "clk_ddrc", mux_ddrphy_p, 0,
RK2928_CLKSEL_CON(26), 8, 2, 0, 2,
ROCKCHIP_DDRCLK_SIP_V2),
FACTOR(0, "clk_ddrphy", "clk_ddrc", 0, 1, 2),
/* PD_CORE */
GATE(0, "apll_core", "apll", CLK_IGNORE_UNUSED,

View File

@ -89,6 +89,53 @@ struct share_params {
static struct share_params *ddr_psci_param;
static const char *rk3128_dts_timing[] = {
"ddr3_speed_bin",
"pd_idle",
"sr_idle",
"auto_pd_dis_freq",
"auto_sr_dis_freq",
"ddr3_dll_dis_freq",
"lpddr2_dll_dis_freq",
"phy_dll_dis_freq",
"ddr3_odt_dis_freq",
"phy_ddr3_odt_disb_freq",
"ddr3_drv",
"ddr3_odt",
"phy_ddr3_clk_drv",
"phy_ddr3_cmd_drv",
"phy_ddr3_dqs_drv",
"phy_ddr3_odt",
"lpddr2_drv",
"phy_lpddr2_clk_drv",
"phy_lpddr2_cmd_drv",
"phy_lpddr2_dqs_drv"
};
struct rk3128_ddr_dts_config_timing {
u32 ddr3_speed_bin;
u32 pd_idle;
u32 sr_idle;
u32 auto_pd_dis_freq;
u32 auto_sr_dis_freq;
u32 ddr3_dll_dis_freq;
u32 lpddr2_dll_dis_freq;
u32 phy_dll_dis_freq;
u32 ddr3_odt_dis_freq;
u32 phy_ddr3_odt_disb_freq;
u32 ddr3_drv;
u32 ddr3_odt;
u32 phy_ddr3_clk_drv;
u32 phy_ddr3_cmd_drv;
u32 phy_ddr3_dqs_drv;
u32 phy_ddr3_odt;
u32 lpddr2_drv;
u32 phy_lpddr2_clk_drv;
u32 phy_lpddr2_cmd_drv;
u32 phy_lpddr2_dqs_drv;
u32 available;
};
char *rk3288_dts_timing[] = {
"ddr3_speed_bin",
"pd_idle",
@ -493,6 +540,46 @@ static int rockchip_dmcfreq_init_freq_table(struct device *dev,
return 0;
}
static void of_get_rk3128_timings(struct device *dev,
struct device_node *np, uint32_t *timing)
{
struct device_node *np_tim;
u32 *p;
struct rk3128_ddr_dts_config_timing *dts_timing;
struct share_params *init_timing;
int ret = 0;
u32 i;
init_timing = (struct share_params *)timing;
if (of_property_read_u32(np, "vop-dclk-mode",
&init_timing->vop_dclk_mode))
init_timing->vop_dclk_mode = 0;
p = timing + DTS_PAR_OFFSET / 4;
np_tim = of_parse_phandle(np, "rockchip,ddr_timing", 0);
if (!np_tim) {
ret = -EINVAL;
goto end;
}
for (i = 0; i < ARRAY_SIZE(rk3128_dts_timing); i++) {
ret |= of_property_read_u32(np_tim, rk3128_dts_timing[i],
p + i);
}
end:
dts_timing =
(struct rk3128_ddr_dts_config_timing *)(timing +
DTS_PAR_OFFSET / 4);
if (!ret) {
dts_timing->available = 1;
} else {
dts_timing->available = 0;
dev_err(dev, "of_get_ddr_timings: fail\n");
}
of_node_put(np_tim);
}
static void of_get_rk3288_timings(struct device *dev,
struct device_node *np, uint32_t *timing)
{
@ -652,6 +739,44 @@ static int rockchip_ddr_set_auto_self_refresh(uint32_t en)
return res.a0;
}
static int rk3128_dmc_init(struct platform_device *pdev,
struct rockchip_dmcfreq *dmcfreq)
{
struct arm_smccc_res res;
struct drm_device *drm = drm_device_get_by_name("rockchip");
if (!drm) {
dev_err(&pdev->dev, "Get drm_device fail\n");
return -EPROBE_DEFER;
}
res = sip_smc_request_share_mem(DIV_ROUND_UP(sizeof(
struct rk3128_ddr_dts_config_timing),
4096) + 1, SHARE_PAGE_TYPE_DDR);
if (res.a0) {
dev_err(&pdev->dev, "no ATF memory for init\n");
return -ENOMEM;
}
ddr_psci_param = (struct share_params *)res.a1;
of_get_rk3128_timings(&pdev->dev, pdev->dev.of_node,
(uint32_t *)ddr_psci_param);
ddr_psci_param->hz = 0;
ddr_psci_param->lcdc_type = rk_drm_get_lcdc_type();
res = sip_smc_dram(SHARE_PAGE_TYPE_DDR, 0,
ROCKCHIP_SIP_CONFIG_DRAM_INIT);
if (res.a0) {
dev_err(&pdev->dev, "rockchip_sip_config_dram_init error:%lx\n",
res.a0);
return -ENOMEM;
}
dmcfreq->set_auto_self_refresh = rockchip_ddr_set_auto_self_refresh;
return 0;
}
static int rk3288_dmc_init(struct platform_device *pdev,
struct rockchip_dmcfreq *dmcfreq)
{
@ -951,6 +1076,7 @@ static int rk3399_dmc_init(struct platform_device *pdev)
}
static const struct of_device_id rockchip_dmcfreq_of_match[] = {
{ .compatible = "rockchip,rk3128-dmc", .data = rk3128_dmc_init },
{ .compatible = "rockchip,rk3288-dmc", .data = rk3288_dmc_init },
{ .compatible = "rockchip,rk3368-dmc", .data = rk3368_dmc_init },
{ .compatible = "rockchip,rk3399-dmc", .data = rk3399_dmc_init },

View File

@ -0,0 +1,95 @@
/*
* Copyright (c) 2017 Fuzhou Rockchip Electronics Co., Ltd
*
* This file is dual-licensed: you can use it either under the terms
* of the GPL or the X11 license, at your option. Note that this dual
* licensing only applies to this file, and not this project as a
* whole.
*
* a) This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Or, alternatively,
*
* b) Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef _DT_BINDINGS_DRAM_ROCKCHIP_RK3128_H
#define _DT_BINDINGS_DRAM_ROCKCHIP_RK3128_H
#define BIT(nr) (1UL << (nr))
#define DDR3_DS_34ohm BIT(1)
#define DDR3_DS_40ohm (0x0)
#define LP2_DS_34ohm (0x1)
#define LP2_DS_40ohm (0x2)
#define LP2_DS_48ohm (0x3)
#define LP2_DS_60ohm (0x4)
#define LP2_DS_68_6ohm (0x5) /* optional */
#define LP2_DS_80ohm (0x6)
#define LP2_DS_120ohm (0x7) /* optional */
#define DDR3_ODT_DIS (0)
#define DDR3_ODT_40ohm (BIT(2) | BIT(6))
#define DDR3_ODT_60ohm BIT(2)
#define DDR3_ODT_120ohm BIT(6)
#define PHY_RON_DISABLE (0)
#define PHY_RON_309ohm (1)
#define PHY_RON_155ohm (2)
#define PHY_RON_103ohm (3)
#define PHY_RON_77ohm (4)
#define PHY_RON_63ohm (5)
#define PHY_RON_52ohm (6)
#define PHY_RON_45ohm (7)
#define PHY_RON_62ohm (9)
#define PHY_RON_44ohm (11)
#define PHY_RON_39ohm (12)
#define PHY_RON_34ohm (13)
#define PHY_RON_31ohm (14)
#define PHY_RON_28ohm (15)
#define PHY_RTT_DISABLE (0)
#define PHY_RTT_816ohm (1)
#define PHY_RTT_431ohm (2)
#define PHY_RTT_287ohm (3)
#define PHY_RTT_216ohm (4)
#define PHY_RTT_172ohm (5)
#define PHY_RTT_145ohm (6)
#define PHY_RTT_124ohm (7)
#define PHY_RTT_215ohm (8)
#define PHY_RTT_144ohm (10)
#define PHY_RTT_123ohm (11)
#define PHY_RTT_108ohm (12)
#define PHY_RTT_96ohm (13)
#define PHY_RTT_86ohm (14)
#define PHY_RTT_78ohm (15)
#endif /* _DT_BINDINGS_DRAM_ROCKCHIP_RK3128_H */