1
0
Fork 0
alistair23-linux/drivers/video/fbdev/omap2/omapfb/dss/video-pll.c

206 lines
4.3 KiB
C
Raw Normal View History

// SPDX-License-Identifier: GPL-2.0-only
omapfb: copy omapdss & displays for omapfb This patch makes a copy of the omapdss driver and the omap panel & encoder drivers for omapfb. The purpose is to separate omapdrm and omapfb drivers from each other. Note that this patch only does a direct copy of the files without any other modifications. The files are not yet used. The original files are in: drivers/video/fbdev/omap2/dss/ drivers/video/fbdev/omap2/displays-new/ Here's a more detailed explanation about this and the following patches, from the introduction mail of the patch series: A short background on the current status. We have the following entities: * omapdss, located in drivers/video/fbdev/omap2/dss/. This is a driver for the display subsystem IPs used on OMAP (and related) SoCs. It offers only a kernel internal API, and does not implement anything for fbdev or drm. * omapdss panels and encoders, located in drivers/video/fbdev/omap2/displays-new/. These are panel and external encoder drivers, which use APIs offered by omapdss driver. These also don't implement anything for fbdev or drm. * omapdrm, located in drivers/gpu/drm/omapdrm/. This is a drm driver, which uses omapdss and the panel/encoder drivers to operate the hardware. * omapfb, located in drivers/video/fbdev/omap2/omapfb/. This is an fbdev driver, which uses omapdss and the panel/encoder drivers to operate the hardware. * omap_vout, located in drivers/media/platform/omap/. This is a v4l2 driver, which uses omapdss and omapfb to implement a v4l2 API for the video overlays. So, on the top level, we have either omapdrm, or omapfb+omap_vout. Both of those use the same low level drivers. Without going to the historical details why the architecture is like that, I think it's finally time to change that. The situation with omapfb+omap_vout is that it still works, but no new features have been added for a long time, and I want to keep it working as it's still being used. At some point in the future I'd like to remove omapfb and omap_vout altogether. Omapdrm, on the other hand, is being actively developed. Sharing the low level parts with omapfb makes that development more difficult than it should be. It also "hides" half of the development, as everything happening in the low level parts resides under fbdev directory, not in the drm directory. I've been wanting to clean this up for a long time, but I haven't figured out a very good way to do it. I still haven't, but here's the best way I have come up with. This series makes a full copy of the low level parts, omapdss and panel/encoder drivers. Both omapfb+omap_vout and omapdrm will have their own versions. The copy omapfb+omap_vout get is a new copy, and the copy that omapdrm gets is just the current files moved. This way git will associate the omapdrm version with the old files. The omapfb+omap_vout versions won't be touched unless there are some big issues there. The omapdrm versions can be refactored and cleaned up, as the omapfb support code is no longer needed. We can perhaps also merge omapdss and omapdrm into the same kernel module. This series only does the copy, and the absolutely necessary parts. No further cleanups are done yet. Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com> Acked-by: Dave Airlie <airlied@gmail.com> Acked-by: Rob Clark <robdclark@gmail.com>
2015-12-09 09:28:28 -07:00
/*
* Copyright (C) 2014 Texas Instruments Ltd
*/
#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/err.h>
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/platform_device.h>
#include <linux/sched.h>
#include <video/omapfb_dss.h>
omapfb: copy omapdss & displays for omapfb This patch makes a copy of the omapdss driver and the omap panel & encoder drivers for omapfb. The purpose is to separate omapdrm and omapfb drivers from each other. Note that this patch only does a direct copy of the files without any other modifications. The files are not yet used. The original files are in: drivers/video/fbdev/omap2/dss/ drivers/video/fbdev/omap2/displays-new/ Here's a more detailed explanation about this and the following patches, from the introduction mail of the patch series: A short background on the current status. We have the following entities: * omapdss, located in drivers/video/fbdev/omap2/dss/. This is a driver for the display subsystem IPs used on OMAP (and related) SoCs. It offers only a kernel internal API, and does not implement anything for fbdev or drm. * omapdss panels and encoders, located in drivers/video/fbdev/omap2/displays-new/. These are panel and external encoder drivers, which use APIs offered by omapdss driver. These also don't implement anything for fbdev or drm. * omapdrm, located in drivers/gpu/drm/omapdrm/. This is a drm driver, which uses omapdss and the panel/encoder drivers to operate the hardware. * omapfb, located in drivers/video/fbdev/omap2/omapfb/. This is an fbdev driver, which uses omapdss and the panel/encoder drivers to operate the hardware. * omap_vout, located in drivers/media/platform/omap/. This is a v4l2 driver, which uses omapdss and omapfb to implement a v4l2 API for the video overlays. So, on the top level, we have either omapdrm, or omapfb+omap_vout. Both of those use the same low level drivers. Without going to the historical details why the architecture is like that, I think it's finally time to change that. The situation with omapfb+omap_vout is that it still works, but no new features have been added for a long time, and I want to keep it working as it's still being used. At some point in the future I'd like to remove omapfb and omap_vout altogether. Omapdrm, on the other hand, is being actively developed. Sharing the low level parts with omapfb makes that development more difficult than it should be. It also "hides" half of the development, as everything happening in the low level parts resides under fbdev directory, not in the drm directory. I've been wanting to clean this up for a long time, but I haven't figured out a very good way to do it. I still haven't, but here's the best way I have come up with. This series makes a full copy of the low level parts, omapdss and panel/encoder drivers. Both omapfb+omap_vout and omapdrm will have their own versions. The copy omapfb+omap_vout get is a new copy, and the copy that omapdrm gets is just the current files moved. This way git will associate the omapdrm version with the old files. The omapfb+omap_vout versions won't be touched unless there are some big issues there. The omapdrm versions can be refactored and cleaned up, as the omapfb support code is no longer needed. We can perhaps also merge omapdss and omapdrm into the same kernel module. This series only does the copy, and the absolutely necessary parts. No further cleanups are done yet. Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com> Acked-by: Dave Airlie <airlied@gmail.com> Acked-by: Rob Clark <robdclark@gmail.com>
2015-12-09 09:28:28 -07:00
#include "dss.h"
#include "dss_features.h"
struct dss_video_pll {
struct dss_pll pll;
struct device *dev;
void __iomem *clkctrl_base;
};
#define REG_MOD(reg, val, start, end) \
writel_relaxed(FLD_MOD(readl_relaxed(reg), val, start, end), reg)
static void dss_dpll_enable_scp_clk(struct dss_video_pll *vpll)
{
REG_MOD(vpll->clkctrl_base, 1, 14, 14); /* CIO_CLK_ICG */
}
static void dss_dpll_disable_scp_clk(struct dss_video_pll *vpll)
{
REG_MOD(vpll->clkctrl_base, 0, 14, 14); /* CIO_CLK_ICG */
}
static void dss_dpll_power_enable(struct dss_video_pll *vpll)
{
REG_MOD(vpll->clkctrl_base, 2, 31, 30); /* PLL_POWER_ON_ALL */
/*
* DRA7x PLL CTRL's PLL_PWR_STATUS seems to always return 0,
* so we have to use fixed delay here.
*/
msleep(1);
}
static void dss_dpll_power_disable(struct dss_video_pll *vpll)
{
REG_MOD(vpll->clkctrl_base, 0, 31, 30); /* PLL_POWER_OFF */
}
static int dss_video_pll_enable(struct dss_pll *pll)
{
struct dss_video_pll *vpll = container_of(pll, struct dss_video_pll, pll);
int r;
r = dss_runtime_get();
if (r)
return r;
dss_ctrl_pll_enable(pll->id, true);
dss_dpll_enable_scp_clk(vpll);
r = dss_pll_wait_reset_done(pll);
if (r)
goto err_reset;
dss_dpll_power_enable(vpll);
return 0;
err_reset:
dss_dpll_disable_scp_clk(vpll);
dss_ctrl_pll_enable(pll->id, false);
dss_runtime_put();
return r;
}
static void dss_video_pll_disable(struct dss_pll *pll)
{
struct dss_video_pll *vpll = container_of(pll, struct dss_video_pll, pll);
dss_dpll_power_disable(vpll);
dss_dpll_disable_scp_clk(vpll);
dss_ctrl_pll_enable(pll->id, false);
dss_runtime_put();
}
static const struct dss_pll_ops dss_pll_ops = {
.enable = dss_video_pll_enable,
.disable = dss_video_pll_disable,
.set_config = dss_pll_write_config_type_a,
};
static const struct dss_pll_hw dss_dra7_video_pll_hw = {
.n_max = (1 << 8) - 1,
.m_max = (1 << 12) - 1,
.mX_max = (1 << 5) - 1,
.fint_min = 500000,
.fint_max = 2500000,
.clkdco_max = 1800000000,
.n_msb = 8,
.n_lsb = 1,
.m_msb = 20,
.m_lsb = 9,
.mX_msb[0] = 25,
.mX_lsb[0] = 21,
.mX_msb[1] = 30,
.mX_lsb[1] = 26,
.has_refsel = true,
};
struct dss_pll *dss_video_pll_init(struct platform_device *pdev, int id,
struct regulator *regulator)
{
const char * const reg_name[] = { "pll1", "pll2" };
const char * const clkctrl_name[] = { "pll1_clkctrl", "pll2_clkctrl" };
const char * const clkin_name[] = { "video1_clk", "video2_clk" };
struct resource *res;
struct dss_video_pll *vpll;
void __iomem *pll_base, *clkctrl_base;
struct clk *clk;
struct dss_pll *pll;
int r;
/* PLL CONTROL */
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, reg_name[id]);
if (!res) {
dev_err(&pdev->dev,
"missing platform resource data for pll%d\n", id);
return ERR_PTR(-ENODEV);
}
pll_base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(pll_base)) {
dev_err(&pdev->dev, "failed to ioremap pll%d reg_name\n", id);
return ERR_CAST(pll_base);
}
/* CLOCK CONTROL */
res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
clkctrl_name[id]);
if (!res) {
dev_err(&pdev->dev,
"missing platform resource data for pll%d\n", id);
return ERR_PTR(-ENODEV);
}
clkctrl_base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(clkctrl_base)) {
dev_err(&pdev->dev, "failed to ioremap pll%d clkctrl\n", id);
return ERR_CAST(clkctrl_base);
}
/* CLKIN */
clk = devm_clk_get(&pdev->dev, clkin_name[id]);
if (IS_ERR(clk)) {
DSSERR("can't get video pll clkin\n");
return ERR_CAST(clk);
}
vpll = devm_kzalloc(&pdev->dev, sizeof(*vpll), GFP_KERNEL);
if (!vpll)
return ERR_PTR(-ENOMEM);
vpll->dev = &pdev->dev;
vpll->clkctrl_base = clkctrl_base;
pll = &vpll->pll;
pll->name = id == 0 ? "video0" : "video1";
pll->id = id == 0 ? DSS_PLL_VIDEO1 : DSS_PLL_VIDEO2;
pll->clkin = clk;
pll->regulator = regulator;
pll->base = pll_base;
pll->hw = &dss_dra7_video_pll_hw;
pll->ops = &dss_pll_ops;
r = dss_pll_register(pll);
if (r)
return ERR_PTR(r);
return pll;
}
void dss_video_pll_uninit(struct dss_pll *pll)
{
dss_pll_unregister(pll);
}