2013-10-08 14:25:26 +07:00
|
|
|
/*
|
|
|
|
* HDMI PLL
|
|
|
|
*
|
2017-12-06 03:29:31 +07:00
|
|
|
* Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
|
2013-10-08 14:25:26 +07:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2013-11-14 18:46:32 +07:00
|
|
|
#define DSS_SUBSYS_NAME "HDMIPLL"
|
|
|
|
|
2013-10-08 14:25:26 +07:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/platform_device.h>
|
2014-10-22 19:02:17 +07:00
|
|
|
#include <linux/clk.h>
|
2016-05-11 23:01:45 +07:00
|
|
|
#include <linux/seq_file.h>
|
2016-05-17 21:07:46 +07:00
|
|
|
#include <linux/pm_runtime.h>
|
2014-10-22 19:02:17 +07:00
|
|
|
|
2016-05-27 18:40:49 +07:00
|
|
|
#include "omapdss.h"
|
2013-10-08 14:25:26 +07:00
|
|
|
#include "dss.h"
|
2013-09-12 19:15:57 +07:00
|
|
|
#include "hdmi.h"
|
2013-10-08 14:25:26 +07:00
|
|
|
|
|
|
|
void hdmi_pll_dump(struct hdmi_pll_data *pll, struct seq_file *s)
|
|
|
|
{
|
|
|
|
#define DUMPPLL(r) seq_printf(s, "%-35s %08x\n", #r,\
|
|
|
|
hdmi_read_reg(pll->base, r))
|
|
|
|
|
|
|
|
DUMPPLL(PLLCTRL_PLL_CONTROL);
|
|
|
|
DUMPPLL(PLLCTRL_PLL_STATUS);
|
|
|
|
DUMPPLL(PLLCTRL_PLL_GO);
|
|
|
|
DUMPPLL(PLLCTRL_CFG1);
|
|
|
|
DUMPPLL(PLLCTRL_CFG2);
|
|
|
|
DUMPPLL(PLLCTRL_CFG3);
|
|
|
|
DUMPPLL(PLLCTRL_SSC_CFG1);
|
|
|
|
DUMPPLL(PLLCTRL_SSC_CFG2);
|
|
|
|
DUMPPLL(PLLCTRL_CFG4);
|
|
|
|
}
|
|
|
|
|
2014-10-22 19:02:17 +07:00
|
|
|
static int hdmi_pll_enable(struct dss_pll *dsspll)
|
2013-10-08 14:25:26 +07:00
|
|
|
{
|
2014-10-22 19:02:17 +07:00
|
|
|
struct hdmi_pll_data *pll = container_of(dsspll, struct hdmi_pll_data, pll);
|
2014-10-16 19:31:38 +07:00
|
|
|
struct hdmi_wp_data *wp = pll->wp;
|
2016-05-17 21:00:52 +07:00
|
|
|
int r;
|
2013-10-08 14:25:26 +07:00
|
|
|
|
2016-05-17 21:07:46 +07:00
|
|
|
r = pm_runtime_get_sync(&pll->pdev->dev);
|
|
|
|
WARN_ON(r < 0);
|
2013-10-08 14:25:26 +07:00
|
|
|
|
2018-02-13 19:00:22 +07:00
|
|
|
dss_ctrl_pll_enable(dsspll, true);
|
2014-12-31 16:26:18 +07:00
|
|
|
|
2013-10-08 14:25:26 +07:00
|
|
|
r = hdmi_wp_set_pll_pwr(wp, HDMI_PLLPWRCMD_BOTHON_ALLCLKS);
|
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-22 19:02:17 +07:00
|
|
|
static void hdmi_pll_disable(struct dss_pll *dsspll)
|
2013-10-08 14:25:26 +07:00
|
|
|
{
|
2014-10-22 19:02:17 +07:00
|
|
|
struct hdmi_pll_data *pll = container_of(dsspll, struct hdmi_pll_data, pll);
|
2014-10-16 19:31:38 +07:00
|
|
|
struct hdmi_wp_data *wp = pll->wp;
|
2016-05-17 21:07:46 +07:00
|
|
|
int r;
|
2014-10-16 19:31:38 +07:00
|
|
|
|
2013-10-08 14:25:26 +07:00
|
|
|
hdmi_wp_set_pll_pwr(wp, HDMI_PLLPWRCMD_ALLOFF);
|
2014-12-31 16:26:18 +07:00
|
|
|
|
2018-02-13 19:00:22 +07:00
|
|
|
dss_ctrl_pll_enable(dsspll, false);
|
2016-05-17 21:07:46 +07:00
|
|
|
|
|
|
|
r = pm_runtime_put_sync(&pll->pdev->dev);
|
|
|
|
WARN_ON(r < 0 && r != -ENOSYS);
|
2013-10-08 14:25:26 +07:00
|
|
|
}
|
|
|
|
|
2017-08-11 20:49:02 +07:00
|
|
|
static const struct dss_pll_ops hdmi_pll_ops = {
|
2014-10-22 19:02:17 +07:00
|
|
|
.enable = hdmi_pll_enable,
|
|
|
|
.disable = hdmi_pll_disable,
|
|
|
|
.set_config = dss_pll_write_config_type_b,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct dss_pll_hw dss_omap4_hdmi_pll_hw = {
|
2016-05-18 14:48:44 +07:00
|
|
|
.type = DSS_PLL_TYPE_B,
|
|
|
|
|
2014-10-22 19:02:17 +07:00
|
|
|
.n_max = 255,
|
|
|
|
.m_min = 20,
|
|
|
|
.m_max = 4095,
|
|
|
|
.mX_max = 127,
|
|
|
|
.fint_min = 500000,
|
|
|
|
.fint_max = 2500000,
|
|
|
|
|
|
|
|
.clkdco_min = 500000000,
|
|
|
|
.clkdco_low = 1000000000,
|
|
|
|
.clkdco_max = 2000000000,
|
|
|
|
|
|
|
|
.n_msb = 8,
|
|
|
|
.n_lsb = 1,
|
|
|
|
.m_msb = 20,
|
|
|
|
.m_lsb = 9,
|
|
|
|
|
|
|
|
.mX_msb[0] = 24,
|
|
|
|
.mX_lsb[0] = 18,
|
|
|
|
|
|
|
|
.has_selfreqdco = true,
|
2013-09-23 16:42:34 +07:00
|
|
|
};
|
|
|
|
|
2014-10-22 19:02:17 +07:00
|
|
|
static const struct dss_pll_hw dss_omap5_hdmi_pll_hw = {
|
2016-05-18 14:48:44 +07:00
|
|
|
.type = DSS_PLL_TYPE_B,
|
|
|
|
|
2014-10-22 19:02:17 +07:00
|
|
|
.n_max = 255,
|
|
|
|
.m_min = 20,
|
|
|
|
.m_max = 2045,
|
|
|
|
.mX_max = 127,
|
|
|
|
.fint_min = 620000,
|
|
|
|
.fint_max = 2500000,
|
|
|
|
|
|
|
|
.clkdco_min = 750000000,
|
|
|
|
.clkdco_low = 1500000000,
|
|
|
|
.clkdco_max = 2500000000UL,
|
|
|
|
|
|
|
|
.n_msb = 8,
|
|
|
|
.n_lsb = 1,
|
|
|
|
.m_msb = 20,
|
|
|
|
.m_lsb = 9,
|
|
|
|
|
|
|
|
.mX_msb[0] = 24,
|
|
|
|
.mX_lsb[0] = 18,
|
|
|
|
|
|
|
|
.has_selfreqdco = true,
|
|
|
|
.has_refsel = true,
|
2013-09-23 16:42:34 +07:00
|
|
|
};
|
|
|
|
|
2018-02-13 19:00:21 +07:00
|
|
|
static int hdmi_init_pll_data(struct dss_device *dss,
|
|
|
|
struct platform_device *pdev,
|
2017-08-11 20:49:02 +07:00
|
|
|
struct hdmi_pll_data *hpll)
|
2013-09-23 16:42:34 +07:00
|
|
|
{
|
2014-10-22 19:02:17 +07:00
|
|
|
struct dss_pll *pll = &hpll->pll;
|
|
|
|
struct clk *clk;
|
|
|
|
int r;
|
2013-09-23 16:42:34 +07:00
|
|
|
|
2014-10-22 19:02:17 +07:00
|
|
|
clk = devm_clk_get(&pdev->dev, "sys_clk");
|
|
|
|
if (IS_ERR(clk)) {
|
|
|
|
DSSERR("can't get sys_clk\n");
|
|
|
|
return PTR_ERR(clk);
|
2013-09-23 16:42:34 +07:00
|
|
|
}
|
|
|
|
|
2014-10-22 19:02:17 +07:00
|
|
|
pll->name = "hdmi";
|
2015-01-02 15:05:33 +07:00
|
|
|
pll->id = DSS_PLL_HDMI;
|
2014-10-22 19:02:17 +07:00
|
|
|
pll->base = hpll->base;
|
|
|
|
pll->clkin = clk;
|
|
|
|
|
2017-08-11 20:49:05 +07:00
|
|
|
if (hpll->wp->version == 4)
|
2014-10-22 19:02:17 +07:00
|
|
|
pll->hw = &dss_omap4_hdmi_pll_hw;
|
2017-08-11 20:49:05 +07:00
|
|
|
else
|
2014-10-22 19:02:17 +07:00
|
|
|
pll->hw = &dss_omap5_hdmi_pll_hw;
|
2013-09-23 16:42:34 +07:00
|
|
|
|
2017-08-11 20:49:02 +07:00
|
|
|
pll->ops = &hdmi_pll_ops;
|
2014-10-22 19:02:17 +07:00
|
|
|
|
2018-02-13 19:00:30 +07:00
|
|
|
r = dss_pll_register(dss, pll);
|
2014-10-22 19:02:17 +07:00
|
|
|
if (r)
|
|
|
|
return r;
|
2013-09-23 16:42:34 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-13 19:00:21 +07:00
|
|
|
int hdmi_pll_init(struct dss_device *dss, struct platform_device *pdev,
|
|
|
|
struct hdmi_pll_data *pll, struct hdmi_wp_data *wp)
|
2013-10-08 14:25:26 +07:00
|
|
|
{
|
2013-09-23 16:42:34 +07:00
|
|
|
int r;
|
2013-10-08 14:25:26 +07:00
|
|
|
struct resource *res;
|
|
|
|
|
2016-05-17 21:07:46 +07:00
|
|
|
pll->pdev = pdev;
|
2014-10-16 19:31:38 +07:00
|
|
|
pll->wp = wp;
|
|
|
|
|
2013-12-17 19:41:14 +07:00
|
|
|
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pll");
|
2014-04-28 20:11:01 +07:00
|
|
|
pll->base = devm_ioremap_resource(&pdev->dev, res);
|
2017-05-07 04:29:09 +07:00
|
|
|
if (IS_ERR(pll->base))
|
2014-05-23 18:50:09 +07:00
|
|
|
return PTR_ERR(pll->base);
|
2013-10-08 14:25:26 +07:00
|
|
|
|
2018-02-13 19:00:21 +07:00
|
|
|
r = hdmi_init_pll_data(dss, pdev, pll);
|
2014-10-22 19:02:17 +07:00
|
|
|
if (r) {
|
|
|
|
DSSERR("failed to init HDMI PLL\n");
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2013-10-08 14:25:26 +07:00
|
|
|
return 0;
|
|
|
|
}
|
2014-10-22 19:02:17 +07:00
|
|
|
|
|
|
|
void hdmi_pll_uninit(struct hdmi_pll_data *hpll)
|
|
|
|
{
|
|
|
|
struct dss_pll *pll = &hpll->pll;
|
|
|
|
|
|
|
|
dss_pll_unregister(pll);
|
|
|
|
}
|