2011-02-26 06:49:01 +08:00
|
|
|
/*
|
|
|
|
* OMAP4-specific DPLL control functions
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Texas Instruments, Inc.
|
|
|
|
* Rajendra Nayak
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/bitops.h>
|
2015-03-02 17:07:35 +08:00
|
|
|
#include <linux/clk/ti.h>
|
2011-02-26 06:49:01 +08:00
|
|
|
|
|
|
|
#include "clock.h"
|
|
|
|
|
2012-12-15 16:35:46 +08:00
|
|
|
/*
|
|
|
|
* Maximum DPLL input frequency (FINT) and output frequency (FOUT) that
|
|
|
|
* can supported when using the DPLL low-power mode. Frequencies are
|
|
|
|
* defined in OMAP4430/60 Public TRM section 3.6.3.3.2 "Enable Control,
|
|
|
|
* Status, and Low-Power Operation Mode".
|
|
|
|
*/
|
|
|
|
#define OMAP4_DPLL_LP_FINT_MAX 1000000
|
|
|
|
#define OMAP4_DPLL_LP_FOUT_MAX 100000000
|
|
|
|
|
2014-07-02 16:47:38 +08:00
|
|
|
/*
|
|
|
|
* Bitfield declarations
|
|
|
|
*/
|
2015-03-02 17:07:35 +08:00
|
|
|
#define OMAP4430_DPLL_CLKOUT_GATE_CTRL_MASK BIT(8)
|
|
|
|
#define OMAP4430_DPLL_CLKOUTX2_GATE_CTRL_MASK BIT(10)
|
|
|
|
#define OMAP4430_DPLL_REGM4XEN_MASK BIT(11)
|
2014-07-02 16:47:38 +08:00
|
|
|
|
|
|
|
/* Static rate multiplier for OMAP4 REGM4XEN clocks */
|
|
|
|
#define OMAP4430_REGM4XEN_MULT 4
|
|
|
|
|
2015-03-02 17:07:35 +08:00
|
|
|
static void omap4_dpllmx_allow_gatectrl(struct clk_hw_omap *clk)
|
2011-02-26 06:49:01 +08:00
|
|
|
{
|
|
|
|
u32 v;
|
|
|
|
u32 mask;
|
|
|
|
|
2017-02-09 17:24:37 +08:00
|
|
|
if (!clk)
|
2011-02-26 06:49:01 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
mask = clk->flags & CLOCK_CLKOUTX2 ?
|
|
|
|
OMAP4430_DPLL_CLKOUTX2_GATE_CTRL_MASK :
|
|
|
|
OMAP4430_DPLL_CLKOUT_GATE_CTRL_MASK;
|
|
|
|
|
2017-02-09 17:24:37 +08:00
|
|
|
v = ti_clk_ll_ops->clk_readl(&clk->clksel_reg);
|
2011-02-26 06:49:01 +08:00
|
|
|
/* Clear the bit to allow gatectrl */
|
|
|
|
v &= ~mask;
|
2017-02-09 17:24:37 +08:00
|
|
|
ti_clk_ll_ops->clk_writel(v, &clk->clksel_reg);
|
2011-02-26 06:49:01 +08:00
|
|
|
}
|
|
|
|
|
2015-03-02 17:07:35 +08:00
|
|
|
static void omap4_dpllmx_deny_gatectrl(struct clk_hw_omap *clk)
|
2011-02-26 06:49:01 +08:00
|
|
|
{
|
|
|
|
u32 v;
|
|
|
|
u32 mask;
|
|
|
|
|
2017-02-09 17:24:37 +08:00
|
|
|
if (!clk)
|
2011-02-26 06:49:01 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
mask = clk->flags & CLOCK_CLKOUTX2 ?
|
|
|
|
OMAP4430_DPLL_CLKOUTX2_GATE_CTRL_MASK :
|
|
|
|
OMAP4430_DPLL_CLKOUT_GATE_CTRL_MASK;
|
|
|
|
|
2017-02-09 17:24:37 +08:00
|
|
|
v = ti_clk_ll_ops->clk_readl(&clk->clksel_reg);
|
2011-02-26 06:49:01 +08:00
|
|
|
/* Set the bit to deny gatectrl */
|
|
|
|
v |= mask;
|
2017-02-09 17:24:37 +08:00
|
|
|
ti_clk_ll_ops->clk_writel(v, &clk->clksel_reg);
|
2011-02-26 06:49:01 +08:00
|
|
|
}
|
2011-02-26 06:49:02 +08:00
|
|
|
|
2012-11-11 07:58:41 +08:00
|
|
|
const struct clk_hw_omap_ops clkhwops_omap4_dpllmx = {
|
|
|
|
.allow_idle = omap4_dpllmx_allow_gatectrl,
|
|
|
|
.deny_idle = omap4_dpllmx_deny_gatectrl,
|
|
|
|
};
|
2011-02-26 06:49:02 +08:00
|
|
|
|
2012-12-15 16:35:46 +08:00
|
|
|
/**
|
|
|
|
* omap4_dpll_lpmode_recalc - compute DPLL low-power setting
|
|
|
|
* @dd: pointer to the dpll data structure
|
|
|
|
*
|
|
|
|
* Calculates if low-power mode can be enabled based upon the last
|
|
|
|
* multiplier and divider values calculated. If low-power mode can be
|
|
|
|
* enabled, then the bit to enable low-power mode is stored in the
|
|
|
|
* last_rounded_lpmode variable. This implementation is based upon the
|
|
|
|
* criteria for enabling low-power mode as described in the OMAP4430/60
|
|
|
|
* Public TRM section 3.6.3.3.2 "Enable Control, Status, and Low-Power
|
|
|
|
* Operation Mode".
|
|
|
|
*/
|
|
|
|
static void omap4_dpll_lpmode_recalc(struct dpll_data *dd)
|
|
|
|
{
|
|
|
|
long fint, fout;
|
|
|
|
|
2016-02-20 19:24:26 +08:00
|
|
|
fint = clk_hw_get_rate(dd->clk_ref) / (dd->last_rounded_n + 1);
|
2012-12-15 16:35:46 +08:00
|
|
|
fout = fint * dd->last_rounded_m;
|
|
|
|
|
|
|
|
if ((fint < OMAP4_DPLL_LP_FINT_MAX) && (fout < OMAP4_DPLL_LP_FOUT_MAX))
|
|
|
|
dd->last_rounded_lpmode = 1;
|
|
|
|
else
|
|
|
|
dd->last_rounded_lpmode = 0;
|
|
|
|
}
|
|
|
|
|
2011-10-07 14:52:58 +08:00
|
|
|
/**
|
|
|
|
* omap4_dpll_regm4xen_recalc - compute DPLL rate, considering REGM4XEN bit
|
|
|
|
* @clk: struct clk * of the DPLL to compute the rate for
|
|
|
|
*
|
|
|
|
* Compute the output rate for the OMAP4 DPLL represented by @clk.
|
|
|
|
* Takes the REGM4XEN bit into consideration, which is needed for the
|
|
|
|
* OMAP4 ABE DPLL. Returns the DPLL's output rate (before M-dividers)
|
|
|
|
* upon success, or 0 upon error.
|
|
|
|
*/
|
2012-11-11 07:58:41 +08:00
|
|
|
unsigned long omap4_dpll_regm4xen_recalc(struct clk_hw *hw,
|
2015-03-02 17:07:35 +08:00
|
|
|
unsigned long parent_rate)
|
2012-11-11 07:58:41 +08:00
|
|
|
{
|
|
|
|
struct clk_hw_omap *clk = to_clk_hw_omap(hw);
|
2011-10-07 14:52:58 +08:00
|
|
|
u32 v;
|
|
|
|
unsigned long rate;
|
|
|
|
struct dpll_data *dd;
|
|
|
|
|
|
|
|
if (!clk || !clk->dpll_data)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
dd = clk->dpll_data;
|
|
|
|
|
|
|
|
rate = omap2_get_dpll_rate(clk);
|
|
|
|
|
|
|
|
/* regm4xen adds a multiplier of 4 to DPLL calculations */
|
2017-02-09 17:24:37 +08:00
|
|
|
v = ti_clk_ll_ops->clk_readl(&dd->control_reg);
|
2011-10-07 14:52:58 +08:00
|
|
|
if (v & OMAP4430_DPLL_REGM4XEN_MASK)
|
|
|
|
rate *= OMAP4430_REGM4XEN_MULT;
|
|
|
|
|
|
|
|
return rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* omap4_dpll_regm4xen_round_rate - round DPLL rate, considering REGM4XEN bit
|
|
|
|
* @clk: struct clk * of the DPLL to round a rate for
|
|
|
|
* @target_rate: the desired rate of the DPLL
|
|
|
|
*
|
|
|
|
* Compute the rate that would be programmed into the DPLL hardware
|
|
|
|
* for @clk if set_rate() were to be provided with the rate
|
|
|
|
* @target_rate. Takes the REGM4XEN bit into consideration, which is
|
|
|
|
* needed for the OMAP4 ABE DPLL. Returns the rounded rate (before
|
|
|
|
* M-dividers) upon success, -EINVAL if @clk is null or not a DPLL, or
|
|
|
|
* ~0 if an error occurred in omap2_dpll_round_rate().
|
|
|
|
*/
|
2012-11-11 07:58:41 +08:00
|
|
|
long omap4_dpll_regm4xen_round_rate(struct clk_hw *hw,
|
|
|
|
unsigned long target_rate,
|
|
|
|
unsigned long *parent_rate)
|
|
|
|
{
|
|
|
|
struct clk_hw_omap *clk = to_clk_hw_omap(hw);
|
2011-10-07 14:52:58 +08:00
|
|
|
struct dpll_data *dd;
|
|
|
|
long r;
|
|
|
|
|
|
|
|
if (!clk || !clk->dpll_data)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
dd = clk->dpll_data;
|
|
|
|
|
2012-12-15 16:35:46 +08:00
|
|
|
dd->last_rounded_m4xen = 0;
|
2011-10-07 14:52:58 +08:00
|
|
|
|
2012-12-15 16:35:46 +08:00
|
|
|
/*
|
|
|
|
* First try to compute the DPLL configuration for
|
|
|
|
* target rate without using the 4X multiplier.
|
|
|
|
*/
|
2012-11-11 07:58:41 +08:00
|
|
|
r = omap2_dpll_round_rate(hw, target_rate, NULL);
|
2012-12-15 16:35:46 +08:00
|
|
|
if (r != ~0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we did not find a valid DPLL configuration, try again, but
|
|
|
|
* this time see if using the 4X multiplier can help. Enabling the
|
|
|
|
* 4X multiplier is equivalent to dividing the target rate by 4.
|
|
|
|
*/
|
|
|
|
r = omap2_dpll_round_rate(hw, target_rate / OMAP4430_REGM4XEN_MULT,
|
|
|
|
NULL);
|
2011-10-07 14:52:58 +08:00
|
|
|
if (r == ~0)
|
|
|
|
return r;
|
|
|
|
|
2012-12-15 16:35:46 +08:00
|
|
|
dd->last_rounded_rate *= OMAP4430_REGM4XEN_MULT;
|
|
|
|
dd->last_rounded_m4xen = 1;
|
|
|
|
|
|
|
|
out:
|
|
|
|
omap4_dpll_lpmode_recalc(dd);
|
2011-10-07 14:52:58 +08:00
|
|
|
|
2012-12-15 16:35:46 +08:00
|
|
|
return dd->last_rounded_rate;
|
2011-10-07 14:52:58 +08:00
|
|
|
}
|
2014-10-03 21:57:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* omap4_dpll_regm4xen_determine_rate - determine rate for a DPLL
|
|
|
|
* @hw: pointer to the clock to determine rate for
|
2015-07-08 02:48:08 +08:00
|
|
|
* @req: target rate request
|
2014-10-03 21:57:12 +08:00
|
|
|
*
|
|
|
|
* Determines which DPLL mode to use for reaching a desired rate.
|
|
|
|
* Checks whether the DPLL shall be in bypass or locked mode, and if
|
|
|
|
* locked, calculates the M,N values for the DPLL via round-rate.
|
2015-07-08 02:48:08 +08:00
|
|
|
* Returns 0 on success and a negative error value otherwise.
|
2014-10-03 21:57:12 +08:00
|
|
|
*/
|
2015-07-08 02:48:08 +08:00
|
|
|
int omap4_dpll_regm4xen_determine_rate(struct clk_hw *hw,
|
|
|
|
struct clk_rate_request *req)
|
2014-10-03 21:57:12 +08:00
|
|
|
{
|
|
|
|
struct clk_hw_omap *clk = to_clk_hw_omap(hw);
|
|
|
|
struct dpll_data *dd;
|
|
|
|
|
2015-07-08 02:48:08 +08:00
|
|
|
if (!req->rate)
|
2014-10-03 21:57:12 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
dd = clk->dpll_data;
|
|
|
|
if (!dd)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2016-02-20 19:24:26 +08:00
|
|
|
if (clk_hw_get_rate(dd->clk_bypass) == req->rate &&
|
2014-10-03 21:57:12 +08:00
|
|
|
(dd->modes & (1 << DPLL_LOW_POWER_BYPASS))) {
|
2016-02-20 19:24:26 +08:00
|
|
|
req->best_parent_hw = dd->clk_bypass;
|
2014-10-03 21:57:12 +08:00
|
|
|
} else {
|
2015-07-08 02:48:08 +08:00
|
|
|
req->rate = omap4_dpll_regm4xen_round_rate(hw, req->rate,
|
|
|
|
&req->best_parent_rate);
|
2016-02-20 19:24:26 +08:00
|
|
|
req->best_parent_hw = dd->clk_ref;
|
2014-10-03 21:57:12 +08:00
|
|
|
}
|
|
|
|
|
2015-07-08 02:48:08 +08:00
|
|
|
req->best_parent_rate = req->rate;
|
2014-10-03 21:57:12 +08:00
|
|
|
|
2015-07-08 02:48:08 +08:00
|
|
|
return 0;
|
2014-10-03 21:57:12 +08:00
|
|
|
}
|