2016-03-31 21:12:32 +00:00
|
|
|
/*
|
|
|
|
* Clock drivers for Qualcomm APQ8016
|
|
|
|
*
|
|
|
|
* (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
|
|
|
|
*
|
|
|
|
* Based on Little Kernel driver, simplified
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2016-06-17 15:44:00 +00:00
|
|
|
#include <clk-uclass.h>
|
2016-03-31 21:12:32 +00:00
|
|
|
#include <dm.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <linux/bitops.h>
|
2018-01-10 10:33:49 +00:00
|
|
|
#include "clock-snapdragon.h"
|
2016-03-31 21:12:32 +00:00
|
|
|
|
|
|
|
/* GPLL0 clock control registers */
|
|
|
|
#define GPLL0_STATUS_ACTIVE BIT(17)
|
|
|
|
#define APCS_GPLL_ENA_VOTE_GPLL0 BIT(0)
|
|
|
|
|
|
|
|
static const struct bcr_regs sdc_regs[] = {
|
|
|
|
{
|
|
|
|
.cfg_rcgr = SDCC_CFG_RCGR(1),
|
|
|
|
.cmd_rcgr = SDCC_CMD_RCGR(1),
|
|
|
|
.M = SDCC_M(1),
|
|
|
|
.N = SDCC_N(1),
|
|
|
|
.D = SDCC_D(1),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.cfg_rcgr = SDCC_CFG_RCGR(2),
|
|
|
|
.cmd_rcgr = SDCC_CMD_RCGR(2),
|
|
|
|
.M = SDCC_M(2),
|
|
|
|
.N = SDCC_N(2),
|
|
|
|
.D = SDCC_D(2),
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-01-10 10:33:49 +00:00
|
|
|
static struct gpll0_ctrl gpll0_ctrl = {
|
|
|
|
.status = GPLL0_STATUS,
|
|
|
|
.status_bit = GPLL0_STATUS_ACTIVE,
|
|
|
|
.ena_vote = APCS_GPLL_ENA_VOTE,
|
|
|
|
.vote_bit = APCS_GPLL_ENA_VOTE_GPLL0,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* SDHCI */
|
2016-03-31 21:12:32 +00:00
|
|
|
static int clk_init_sdc(struct msm_clk_priv *priv, int slot, uint rate)
|
|
|
|
{
|
|
|
|
int div = 8; /* 100MHz default */
|
|
|
|
|
|
|
|
if (rate == 200000000)
|
|
|
|
div = 4;
|
|
|
|
|
|
|
|
clk_enable_cbc(priv->base + SDCC_AHB_CBCR(slot));
|
|
|
|
/* 800Mhz/div, gpll0 */
|
|
|
|
clk_rcg_set_rate_mnd(priv->base, &sdc_regs[slot], div, 0, 0,
|
|
|
|
CFG_CLK_SRC_GPLL0);
|
2018-01-10 10:33:49 +00:00
|
|
|
clk_enable_gpll0(priv->base, &gpll0_ctrl);
|
2016-03-31 21:12:32 +00:00
|
|
|
clk_enable_cbc(priv->base + SDCC_APPS_CBCR(slot));
|
|
|
|
|
|
|
|
return rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct bcr_regs uart2_regs = {
|
|
|
|
.cfg_rcgr = BLSP1_UART2_APPS_CFG_RCGR,
|
|
|
|
.cmd_rcgr = BLSP1_UART2_APPS_CMD_RCGR,
|
|
|
|
.M = BLSP1_UART2_APPS_M,
|
|
|
|
.N = BLSP1_UART2_APPS_N,
|
|
|
|
.D = BLSP1_UART2_APPS_D,
|
|
|
|
};
|
|
|
|
|
2018-01-10 10:33:49 +00:00
|
|
|
/* UART: 115200 */
|
2016-03-31 21:12:32 +00:00
|
|
|
static int clk_init_uart(struct msm_clk_priv *priv)
|
|
|
|
{
|
|
|
|
/* Enable iface clk */
|
|
|
|
clk_enable_cbc(priv->base + BLSP1_AHB_CBCR);
|
|
|
|
/* 7372800 uart block clock @ GPLL0 */
|
|
|
|
clk_rcg_set_rate_mnd(priv->base, &uart2_regs, 1, 144, 15625,
|
|
|
|
CFG_CLK_SRC_GPLL0);
|
2018-01-10 10:33:49 +00:00
|
|
|
clk_enable_gpll0(priv->base, &gpll0_ctrl);
|
2016-03-31 21:12:32 +00:00
|
|
|
/* Enable core clk */
|
|
|
|
clk_enable_cbc(priv->base + BLSP1_UART2_APPS_CBCR);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-06-17 15:44:00 +00:00
|
|
|
ulong msm_set_rate(struct clk *clk, ulong rate)
|
2016-03-31 21:12:32 +00:00
|
|
|
{
|
2016-06-17 15:44:00 +00:00
|
|
|
struct msm_clk_priv *priv = dev_get_priv(clk->dev);
|
2016-03-31 21:12:32 +00:00
|
|
|
|
2016-06-17 15:44:00 +00:00
|
|
|
switch (clk->id) {
|
2016-03-31 21:12:32 +00:00
|
|
|
case 0: /* SDC1 */
|
|
|
|
return clk_init_sdc(priv, 0, rate);
|
|
|
|
break;
|
|
|
|
case 1: /* SDC2 */
|
|
|
|
return clk_init_sdc(priv, 1, rate);
|
|
|
|
break;
|
|
|
|
case 4: /* UART2 */
|
|
|
|
return clk_init_uart(priv);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|