avionic design with actual uboot and tooling

submodule of avionic design uboot bootloader and with included tools to
get you started , read readme.md and readme-tk1-loader.md
This commit is contained in:
2026-03-03 21:46:32 +02:00
parent fe3ba02c96
commit 68d74d3181
11967 changed files with 2221897 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
#
# (C) Copyright 2000-2007
# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
#
# SPDX-License-Identifier: GPL-2.0+
#
obj-y += rk_edp.o rk_hdmi.o rk_vop.o rk_lvds.o

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,933 @@
/*
* Copyright (c) 2015 Google, Inc
* Copyright 2014 Rockchip Inc.
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
#include <clk.h>
#include <display.h>
#include <dm.h>
#include <edid.h>
#include <regmap.h>
#include <syscon.h>
#include <asm/gpio.h>
#include <asm/io.h>
#include <asm/arch/clock.h>
#include <asm/arch/grf_rk3288.h>
#include <asm/arch/hdmi_rk3288.h>
#include <power/regulator.h>
struct tmds_n_cts {
u32 tmds;
u32 cts;
u32 n;
};
struct rk_hdmi_priv {
struct rk3288_hdmi *regs;
struct rk3288_grf *grf;
};
static const struct tmds_n_cts n_cts_table[] = {
{
.tmds = 25175, .n = 6144, .cts = 25175,
}, {
.tmds = 25200, .n = 6144, .cts = 25200,
}, {
.tmds = 27000, .n = 6144, .cts = 27000,
}, {
.tmds = 27027, .n = 6144, .cts = 27027,
}, {
.tmds = 40000, .n = 6144, .cts = 40000,
}, {
.tmds = 54000, .n = 6144, .cts = 54000,
}, {
.tmds = 54054, .n = 6144, .cts = 54054,
}, {
.tmds = 65000, .n = 6144, .cts = 65000,
}, {
.tmds = 74176, .n = 11648, .cts = 140625,
}, {
.tmds = 74250, .n = 6144, .cts = 74250,
}, {
.tmds = 83500, .n = 6144, .cts = 83500,
}, {
.tmds = 106500, .n = 6144, .cts = 106500,
}, {
.tmds = 108000, .n = 6144, .cts = 108000,
}, {
.tmds = 148352, .n = 5824, .cts = 140625,
}, {
.tmds = 148500, .n = 6144, .cts = 148500,
}, {
.tmds = 297000, .n = 5120, .cts = 247500,
}
};
struct hdmi_mpll_config {
u64 mpixelclock;
/* Mode of Operation and PLL Dividers Control Register */
u32 cpce;
/* PLL Gmp Control Register */
u32 gmp;
/* PLL Current COntrol Register */
u32 curr;
};
struct hdmi_phy_config {
u64 mpixelclock;
u32 sym_ctr; /* clock symbol and transmitter control */
u32 term; /* transmission termination value */
u32 vlev_ctr; /* voltage level control */
};
static const struct hdmi_phy_config rockchip_phy_config[] = {
{
.mpixelclock = 74250,
.sym_ctr = 0x8009, .term = 0x0004, .vlev_ctr = 0x0272,
}, {
.mpixelclock = 148500,
.sym_ctr = 0x802b, .term = 0x0004, .vlev_ctr = 0x028d,
}, {
.mpixelclock = 297000,
.sym_ctr = 0x8039, .term = 0x0005, .vlev_ctr = 0x028d,
}, {
.mpixelclock = ~0ul,
.sym_ctr = 0x0000, .term = 0x0000, .vlev_ctr = 0x0000,
}
};
static const struct hdmi_mpll_config rockchip_mpll_cfg[] = {
{
.mpixelclock = 40000,
.cpce = 0x00b3, .gmp = 0x0000, .curr = 0x0018,
}, {
.mpixelclock = 65000,
.cpce = 0x0072, .gmp = 0x0001, .curr = 0x0028,
}, {
.mpixelclock = 66000,
.cpce = 0x013e, .gmp = 0x0003, .curr = 0x0038,
}, {
.mpixelclock = 83500,
.cpce = 0x0072, .gmp = 0x0001, .curr = 0x0028,
}, {
.mpixelclock = 146250,
.cpce = 0x0051, .gmp = 0x0002, .curr = 0x0038,
}, {
.mpixelclock = 148500,
.cpce = 0x0051, .gmp = 0x0003, .curr = 0x0000,
}, {
.mpixelclock = ~0ul,
.cpce = 0x0051, .gmp = 0x0003, .curr = 0x0000,
}
};
static const u32 csc_coeff_default[3][4] = {
{ 0x2000, 0x0000, 0x0000, 0x0000 },
{ 0x0000, 0x2000, 0x0000, 0x0000 },
{ 0x0000, 0x0000, 0x2000, 0x0000 }
};
static void hdmi_set_clock_regenerator(struct rk3288_hdmi *regs, u32 n, u32 cts)
{
u8 cts3;
u8 n3;
/* first set ncts_atomic_write (if present) */
n3 = HDMI_AUD_N3_NCTS_ATOMIC_WRITE;
writel(n3, &regs->aud_n3);
/* set cts_manual (if present) */
cts3 = HDMI_AUD_CTS3_CTS_MANUAL;
cts3 |= HDMI_AUD_CTS3_N_SHIFT_1 << HDMI_AUD_CTS3_N_SHIFT_OFFSET;
cts3 |= (cts >> 16) & HDMI_AUD_CTS3_AUDCTS19_16_MASK;
/* write cts values; cts3 must be written first */
writel(cts3, &regs->aud_cts3);
writel((cts >> 8) & 0xff, &regs->aud_cts2);
writel(cts & 0xff, &regs->aud_cts1);
/* write n values; n1 must be written last */
n3 |= (n >> 16) & HDMI_AUD_N3_AUDN19_16_MASK;
writel(n3, &regs->aud_n3);
writel((n >> 8) & 0xff, &regs->aud_n2);
writel(n & 0xff, &regs->aud_n1);
writel(HDMI_AUD_INPUTCLKFS_128, &regs->aud_inputclkfs);
}
static int hdmi_lookup_n_cts(u32 pixel_clk)
{
int i;
for (i = 0; i < ARRAY_SIZE(n_cts_table); i++)
if (pixel_clk <= n_cts_table[i].tmds)
break;
if (i >= ARRAY_SIZE(n_cts_table))
return -1;
return i;
}
static void hdmi_audio_set_samplerate(struct rk3288_hdmi *regs, u32 pixel_clk)
{
u32 clk_n, clk_cts;
int index;
index = hdmi_lookup_n_cts(pixel_clk);
if (index == -1) {
debug("audio not supported for pixel clk %d\n", pixel_clk);
return;
}
clk_n = n_cts_table[index].n;
clk_cts = n_cts_table[index].cts;
hdmi_set_clock_regenerator(regs, clk_n, clk_cts);
}
/*
* this submodule is responsible for the video data synchronization.
* for example, for rgb 4:4:4 input, the data map is defined as
* pin{47~40} <==> r[7:0]
* pin{31~24} <==> g[7:0]
* pin{15~8} <==> b[7:0]
*/
static void hdmi_video_sample(struct rk3288_hdmi *regs)
{
u32 color_format = 0x01;
u8 val;
val = HDMI_TX_INVID0_INTERNAL_DE_GENERATOR_DISABLE |
((color_format << HDMI_TX_INVID0_VIDEO_MAPPING_OFFSET) &
HDMI_TX_INVID0_VIDEO_MAPPING_MASK);
writel(val, &regs->tx_invid0);
/* enable tx stuffing: when de is inactive, fix the output data to 0 */
val = HDMI_TX_INSTUFFING_BDBDATA_STUFFING_ENABLE |
HDMI_TX_INSTUFFING_RCRDATA_STUFFING_ENABLE |
HDMI_TX_INSTUFFING_GYDATA_STUFFING_ENABLE;
writel(val, &regs->tx_instuffing);
writel(0x0, &regs->tx_gydata0);
writel(0x0, &regs->tx_gydata1);
writel(0x0, &regs->tx_rcrdata0);
writel(0x0, &regs->tx_rcrdata1);
writel(0x0, &regs->tx_bcbdata0);
writel(0x0, &regs->tx_bcbdata1);
}
static void hdmi_update_csc_coeffs(struct rk3288_hdmi *regs)
{
u32 i, j;
u32 csc_scale = 1;
/* the csc registers are sequential, alternating msb then lsb */
for (i = 0; i < ARRAY_SIZE(csc_coeff_default); i++) {
for (j = 0; j < ARRAY_SIZE(csc_coeff_default[0]); j++) {
u32 coeff = csc_coeff_default[i][j];
writel(coeff >> 8, &regs->csc_coef[i][j].msb);
writel(coeff && 0xff, &regs->csc_coef[i][j].lsb);
}
}
clrsetbits_le32(&regs->csc_scale, HDMI_CSC_SCALE_CSCSCALE_MASK,
csc_scale);
}
static void hdmi_video_csc(struct rk3288_hdmi *regs)
{
u32 color_depth = HDMI_CSC_SCALE_CSC_COLORDE_PTH_24BPP;
u32 interpolation = HDMI_CSC_CFG_INTMODE_DISABLE;
/* configure the csc registers */
writel(interpolation, &regs->csc_cfg);
clrsetbits_le32(&regs->csc_scale,
HDMI_CSC_SCALE_CSC_COLORDE_PTH_MASK, color_depth);
hdmi_update_csc_coeffs(regs);
}
static void hdmi_video_packetize(struct rk3288_hdmi *regs)
{
u32 output_select = HDMI_VP_CONF_OUTPUT_SELECTOR_BYPASS;
u32 remap_size = HDMI_VP_REMAP_YCC422_16BIT;
u32 color_depth = 0;
u8 val, vp_conf;
/* set the packetizer registers */
val = ((color_depth << HDMI_VP_PR_CD_COLOR_DEPTH_OFFSET) &
HDMI_VP_PR_CD_COLOR_DEPTH_MASK) |
((0 << HDMI_VP_PR_CD_DESIRED_PR_FACTOR_OFFSET) &
HDMI_VP_PR_CD_DESIRED_PR_FACTOR_MASK);
writel(val, &regs->vp_pr_cd);
clrsetbits_le32(&regs->vp_stuff, HDMI_VP_STUFF_PR_STUFFING_MASK,
HDMI_VP_STUFF_PR_STUFFING_STUFFING_MODE);
/* data from pixel repeater block */
vp_conf = HDMI_VP_CONF_PR_EN_DISABLE |
HDMI_VP_CONF_BYPASS_SELECT_VID_PACKETIZER;
clrsetbits_le32(&regs->vp_conf, HDMI_VP_CONF_PR_EN_MASK |
HDMI_VP_CONF_BYPASS_SELECT_MASK, vp_conf);
clrsetbits_le32(&regs->vp_stuff, HDMI_VP_STUFF_IDEFAULT_PHASE_MASK,
1 << HDMI_VP_STUFF_IDEFAULT_PHASE_OFFSET);
writel(remap_size, &regs->vp_remap);
vp_conf = HDMI_VP_CONF_BYPASS_EN_ENABLE |
HDMI_VP_CONF_PP_EN_DISABLE |
HDMI_VP_CONF_YCC422_EN_DISABLE;
clrsetbits_le32(&regs->vp_conf, HDMI_VP_CONF_BYPASS_EN_MASK |
HDMI_VP_CONF_PP_EN_ENMASK | HDMI_VP_CONF_YCC422_EN_MASK,
vp_conf);
clrsetbits_le32(&regs->vp_stuff, HDMI_VP_STUFF_PP_STUFFING_MASK |
HDMI_VP_STUFF_YCC422_STUFFING_MASK,
HDMI_VP_STUFF_PP_STUFFING_STUFFING_MODE |
HDMI_VP_STUFF_YCC422_STUFFING_STUFFING_MODE);
clrsetbits_le32(&regs->vp_conf, HDMI_VP_CONF_OUTPUT_SELECTOR_MASK,
output_select);
}
static inline void hdmi_phy_test_clear(struct rk3288_hdmi *regs, u8 bit)
{
clrsetbits_le32(&regs->phy_tst0, HDMI_PHY_TST0_TSTCLR_MASK,
bit << HDMI_PHY_TST0_TSTCLR_OFFSET);
}
static int hdmi_phy_wait_i2c_done(struct rk3288_hdmi *regs, u32 msec)
{
ulong start;
u32 val;
start = get_timer(0);
do {
val = readl(&regs->ih_i2cmphy_stat0);
if (val & 0x3) {
writel(val, &regs->ih_i2cmphy_stat0);
return 0;
}
udelay(100);
} while (get_timer(start) < msec);
return 1;
}
static void hdmi_phy_i2c_write(struct rk3288_hdmi *regs, uint data, uint addr)
{
writel(0xff, &regs->ih_i2cmphy_stat0);
writel(addr, &regs->phy_i2cm_address_addr);
writel((u8)(data >> 8), &regs->phy_i2cm_datao_1_addr);
writel((u8)(data >> 0), &regs->phy_i2cm_datao_0_addr);
writel(HDMI_PHY_I2CM_OPERATION_ADDR_WRITE,
&regs->phy_i2cm_operation_addr);
hdmi_phy_wait_i2c_done(regs, 1000);
}
static void hdmi_phy_enable_power(struct rk3288_hdmi *regs, uint enable)
{
clrsetbits_le32(&regs->phy_conf0, HDMI_PHY_CONF0_PDZ_MASK,
enable << HDMI_PHY_CONF0_PDZ_OFFSET);
}
static void hdmi_phy_enable_tmds(struct rk3288_hdmi *regs, uint enable)
{
clrsetbits_le32(&regs->phy_conf0, HDMI_PHY_CONF0_ENTMDS_MASK,
enable << HDMI_PHY_CONF0_ENTMDS_OFFSET);
}
static void hdmi_phy_enable_spare(struct rk3288_hdmi *regs, uint enable)
{
clrsetbits_le32(&regs->phy_conf0, HDMI_PHY_CONF0_SPARECTRL_MASK,
enable << HDMI_PHY_CONF0_SPARECTRL_OFFSET);
}
static void hdmi_phy_gen2_pddq(struct rk3288_hdmi *regs, uint enable)
{
clrsetbits_le32(&regs->phy_conf0, HDMI_PHY_CONF0_GEN2_PDDQ_MASK,
enable << HDMI_PHY_CONF0_GEN2_PDDQ_OFFSET);
}
static void hdmi_phy_gen2_txpwron(struct rk3288_hdmi *regs, uint enable)
{
clrsetbits_le32(&regs->phy_conf0,
HDMI_PHY_CONF0_GEN2_TXPWRON_MASK,
enable << HDMI_PHY_CONF0_GEN2_TXPWRON_OFFSET);
}
static void hdmi_phy_sel_data_en_pol(struct rk3288_hdmi *regs, uint enable)
{
clrsetbits_le32(&regs->phy_conf0,
HDMI_PHY_CONF0_SELDATAENPOL_MASK,
enable << HDMI_PHY_CONF0_SELDATAENPOL_OFFSET);
}
static void hdmi_phy_sel_interface_control(struct rk3288_hdmi *regs,
uint enable)
{
clrsetbits_le32(&regs->phy_conf0, HDMI_PHY_CONF0_SELDIPIF_MASK,
enable << HDMI_PHY_CONF0_SELDIPIF_OFFSET);
}
static int hdmi_phy_configure(struct rk3288_hdmi *regs, u32 mpixelclock)
{
ulong start;
u8 i, val;
writel(HDMI_MC_FLOWCTRL_FEED_THROUGH_OFF_CSC_BYPASS,
&regs->mc_flowctrl);
/* gen2 tx power off */
hdmi_phy_gen2_txpwron(regs, 0);
/* gen2 pddq */
hdmi_phy_gen2_pddq(regs, 1);
/* phy reset */
writel(HDMI_MC_PHYRSTZ_DEASSERT, &regs->mc_phyrstz);
writel(HDMI_MC_PHYRSTZ_ASSERT, &regs->mc_phyrstz);
writel(HDMI_MC_HEACPHY_RST_ASSERT, &regs->mc_heacphy_rst);
hdmi_phy_test_clear(regs, 1);
writel(HDMI_PHY_I2CM_SLAVE_ADDR_PHY_GEN2, &regs->phy_i2cm_slave_addr);
hdmi_phy_test_clear(regs, 0);
/* pll/mpll cfg - always match on final entry */
for (i = 0; rockchip_mpll_cfg[i].mpixelclock != (~0ul); i++)
if (mpixelclock <= rockchip_mpll_cfg[i].mpixelclock)
break;
hdmi_phy_i2c_write(regs, rockchip_mpll_cfg[i].cpce, PHY_OPMODE_PLLCFG);
hdmi_phy_i2c_write(regs, rockchip_mpll_cfg[i].gmp, PHY_PLLGMPCTRL);
hdmi_phy_i2c_write(regs, rockchip_mpll_cfg[i].curr, PHY_PLLCURRCTRL);
hdmi_phy_i2c_write(regs, 0x0000, PHY_PLLPHBYCTRL);
hdmi_phy_i2c_write(regs, 0x0006, PHY_PLLCLKBISTPHASE);
for (i = 0; rockchip_phy_config[i].mpixelclock != (~0ul); i++)
if (mpixelclock <= rockchip_phy_config[i].mpixelclock)
break;
/*
* resistance term 133ohm cfg
* preemp cgf 0.00
* tx/ck lvl 10
*/
hdmi_phy_i2c_write(regs, rockchip_phy_config[i].term, PHY_TXTERM);
hdmi_phy_i2c_write(regs, rockchip_phy_config[i].sym_ctr,
PHY_CKSYMTXCTRL);
hdmi_phy_i2c_write(regs, rockchip_phy_config[i].vlev_ctr, PHY_VLEVCTRL);
/* remove clk term */
hdmi_phy_i2c_write(regs, 0x8000, PHY_CKCALCTRL);
hdmi_phy_enable_power(regs, 1);
/* toggle tmds enable */
hdmi_phy_enable_tmds(regs, 0);
hdmi_phy_enable_tmds(regs, 1);
/* gen2 tx power on */
hdmi_phy_gen2_txpwron(regs, 1);
hdmi_phy_gen2_pddq(regs, 0);
hdmi_phy_enable_spare(regs, 1);
/* wait for phy pll lock */
start = get_timer(0);
do {
val = readl(&regs->phy_stat0);
if (!(val & HDMI_PHY_TX_PHY_LOCK))
return 0;
udelay(100);
} while (get_timer(start) < 5);
return -1;
}
static int hdmi_phy_init(struct rk3288_hdmi *regs, uint mpixelclock)
{
int i, ret;
/* hdmi phy spec says to do the phy initialization sequence twice */
for (i = 0; i < 2; i++) {
hdmi_phy_sel_data_en_pol(regs, 1);
hdmi_phy_sel_interface_control(regs, 0);
hdmi_phy_enable_tmds(regs, 0);
hdmi_phy_enable_power(regs, 0);
/* enable csc */
ret = hdmi_phy_configure(regs, mpixelclock);
if (ret) {
debug("hdmi phy config failure %d\n", ret);
return ret;
}
}
return 0;
}
static void hdmi_av_composer(struct rk3288_hdmi *regs,
const struct display_timing *edid)
{
u8 mdataenablepolarity = 1;
u8 inv_val;
uint hbl;
uint vbl;
hbl = edid->hback_porch.typ + edid->hfront_porch.typ +
edid->hsync_len.typ;
vbl = edid->vback_porch.typ + edid->vfront_porch.typ +
edid->vsync_len.typ;
/* set up hdmi_fc_invidconf */
inv_val = HDMI_FC_INVIDCONF_HDCP_KEEPOUT_INACTIVE;
inv_val |= (edid->flags & DISPLAY_FLAGS_HSYNC_HIGH ?
HDMI_FC_INVIDCONF_VSYNC_IN_POLARITY_ACTIVE_HIGH :
HDMI_FC_INVIDCONF_VSYNC_IN_POLARITY_ACTIVE_LOW);
inv_val |= (edid->flags & DISPLAY_FLAGS_VSYNC_HIGH ?
HDMI_FC_INVIDCONF_HSYNC_IN_POLARITY_ACTIVE_HIGH :
HDMI_FC_INVIDCONF_HSYNC_IN_POLARITY_ACTIVE_LOW);
inv_val |= (mdataenablepolarity ?
HDMI_FC_INVIDCONF_DE_IN_POLARITY_ACTIVE_HIGH :
HDMI_FC_INVIDCONF_DE_IN_POLARITY_ACTIVE_LOW);
/*
* TODO(sjg@chromium.org>: Need to check for HDMI / DVI
* inv_val |= (edid->hdmi_monitor_detected ?
* HDMI_FC_INVIDCONF_DVI_MODEZ_HDMI_MODE :
* HDMI_FC_INVIDCONF_DVI_MODEZ_DVI_MODE);
*/
inv_val |= HDMI_FC_INVIDCONF_DVI_MODEZ_HDMI_MODE;
inv_val |= HDMI_FC_INVIDCONF_R_V_BLANK_IN_OSC_ACTIVE_LOW;
inv_val |= HDMI_FC_INVIDCONF_IN_I_P_PROGRESSIVE;
writel(inv_val, &regs->fc_invidconf);
/* set up horizontal active pixel width */
writel(edid->hactive.typ >> 8, &regs->fc_inhactv1);
writel(edid->hactive.typ, &regs->fc_inhactv0);
/* set up vertical active lines */
writel(edid->vactive.typ >> 8, &regs->fc_invactv1);
writel(edid->vactive.typ, &regs->fc_invactv0);
/* set up horizontal blanking pixel region width */
writel(hbl >> 8, &regs->fc_inhblank1);
writel(hbl, &regs->fc_inhblank0);
/* set up vertical blanking pixel region width */
writel(vbl, &regs->fc_invblank);
/* set up hsync active edge delay width (in pixel clks) */
writel(edid->hfront_porch.typ >> 8, &regs->fc_hsyncindelay1);
writel(edid->hfront_porch.typ, &regs->fc_hsyncindelay0);
/* set up vsync active edge delay (in lines) */
writel(edid->vfront_porch.typ, &regs->fc_vsyncindelay);
/* set up hsync active pulse width (in pixel clks) */
writel(edid->hsync_len.typ >> 8, &regs->fc_hsyncinwidth1);
writel(edid->hsync_len.typ, &regs->fc_hsyncinwidth0);
/* set up vsync active edge delay (in lines) */
writel(edid->vsync_len.typ, &regs->fc_vsyncinwidth);
}
/* hdmi initialization step b.4 */
static void hdmi_enable_video_path(struct rk3288_hdmi *regs)
{
u8 clkdis;
/* control period minimum duration */
writel(12, &regs->fc_ctrldur);
writel(32, &regs->fc_exctrldur);
writel(1, &regs->fc_exctrlspac);
/* set to fill tmds data channels */
writel(0x0b, &regs->fc_ch0pream);
writel(0x16, &regs->fc_ch1pream);
writel(0x21, &regs->fc_ch2pream);
/* enable pixel clock and tmds data path */
clkdis = 0x7f;
clkdis &= ~HDMI_MC_CLKDIS_PIXELCLK_DISABLE;
writel(clkdis, &regs->mc_clkdis);
clkdis &= ~HDMI_MC_CLKDIS_TMDSCLK_DISABLE;
writel(clkdis, &regs->mc_clkdis);
clkdis &= ~HDMI_MC_CLKDIS_AUDCLK_DISABLE;
writel(clkdis, &regs->mc_clkdis);
}
/* workaround to clear the overflow condition */
static void hdmi_clear_overflow(struct rk3288_hdmi *regs)
{
u8 val, count;
/* tmds software reset */
writel((u8)~HDMI_MC_SWRSTZ_TMDSSWRST_REQ, &regs->mc_swrstz);
val = readl(&regs->fc_invidconf);
for (count = 0; count < 4; count++)
writel(val, &regs->fc_invidconf);
}
static void hdmi_audio_set_format(struct rk3288_hdmi *regs)
{
writel(HDMI_AUD_CONF0_I2S_SELECT | HDMI_AUD_CONF0_I2S_IN_EN_0,
&regs->aud_conf0);
writel(HDMI_AUD_CONF1_I2S_MODE_STANDARD_MODE |
HDMI_AUD_CONF1_I2S_WIDTH_16BIT, &regs->aud_conf1);
writel(0x00, &regs->aud_conf2);
}
static void hdmi_audio_fifo_reset(struct rk3288_hdmi *regs)
{
writel((u8)~HDMI_MC_SWRSTZ_II2SSWRST_REQ, &regs->mc_swrstz);
writel(HDMI_AUD_CONF0_SW_AUDIO_FIFO_RST, &regs->aud_conf0);
writel(0x00, &regs->aud_int);
writel(0x00, &regs->aud_int1);
}
static void hdmi_init_interrupt(struct rk3288_hdmi *regs)
{
u8 ih_mute;
/*
* boot up defaults are:
* hdmi_ih_mute = 0x03 (disabled)
* hdmi_ih_mute_* = 0x00 (enabled)
*
* disable top level interrupt bits in hdmi block
*/
ih_mute = readl(&regs->ih_mute) |
HDMI_IH_MUTE_MUTE_WAKEUP_INTERRUPT |
HDMI_IH_MUTE_MUTE_ALL_INTERRUPT;
writel(ih_mute, &regs->ih_mute);
/* enable i2c master done irq */
writel(~0x04, &regs->i2cm_int);
/* enable i2c client nack % arbitration error irq */
writel(~0x44, &regs->i2cm_ctlint);
/* enable phy i2cm done irq */
writel(HDMI_PHY_I2CM_INT_ADDR_DONE_POL, &regs->phy_i2cm_int_addr);
/* enable phy i2cm nack & arbitration error irq */
writel(HDMI_PHY_I2CM_CTLINT_ADDR_NAC_POL |
HDMI_PHY_I2CM_CTLINT_ADDR_ARBITRATION_POL,
&regs->phy_i2cm_ctlint_addr);
/* enable cable hot plug irq */
writel((u8)~HDMI_PHY_HPD, &regs->phy_mask0);
/* clear hotplug interrupts */
writel(HDMI_IH_PHY_STAT0_HPD, &regs->ih_phy_stat0);
}
static u8 hdmi_get_plug_in_status(struct rk3288_hdmi *regs)
{
u8 val = readl(&regs->phy_stat0) & HDMI_PHY_HPD;
return !!(val);
}
static int hdmi_wait_for_hpd(struct rk3288_hdmi *regs)
{
ulong start;
start = get_timer(0);
do {
if (hdmi_get_plug_in_status(regs))
return 0;
udelay(100);
} while (get_timer(start) < 300);
return -1;
}
static int hdmi_ddc_wait_i2c_done(struct rk3288_hdmi *regs, int msec)
{
u32 val;
ulong start;
start = get_timer(0);
do {
val = readl(&regs->ih_i2cm_stat0);
if (val & 0x2) {
writel(val, &regs->ih_i2cm_stat0);
return 0;
}
udelay(100);
} while (get_timer(start) < msec);
return 1;
}
static void hdmi_ddc_reset(struct rk3288_hdmi *regs)
{
clrbits_le32(&regs->i2cm_softrstz, HDMI_I2CM_SOFTRSTZ);
}
static int hdmi_read_edid(struct rk3288_hdmi *regs, int block, u8 *buff)
{
int shift = (block % 2) * 0x80;
int edid_read_err = 0;
u32 trytime = 5;
u32 n, j, val;
/* set ddc i2c clk which devided from ddc_clk to 100khz */
writel(0x7a, &regs->i2cm_ss_scl_hcnt_0_addr);
writel(0x8d, &regs->i2cm_ss_scl_lcnt_0_addr);
/*
* TODO(sjg@chromium.org): The above values don't work - these ones
* work better, but generate lots of errors in the data.
*/
writel(0x0d, &regs->i2cm_ss_scl_hcnt_0_addr);
writel(0x0d, &regs->i2cm_ss_scl_lcnt_0_addr);
clrsetbits_le32(&regs->i2cm_div, HDMI_I2CM_DIV_FAST_STD_MODE,
HDMI_I2CM_DIV_STD_MODE);
writel(HDMI_I2CM_SLAVE_DDC_ADDR, &regs->i2cm_slave);
writel(HDMI_I2CM_SEGADDR_DDC, &regs->i2cm_segaddr);
writel(block >> 1, &regs->i2cm_segptr);
while (trytime--) {
edid_read_err = 0;
for (n = 0; n < HDMI_EDID_BLOCK_SIZE / 8; n++) {
writel(shift + 8 * n, &regs->i2c_address);
if (block == 0)
clrsetbits_le32(&regs->i2cm_operation,
HDMI_I2CM_OPT_RD8,
HDMI_I2CM_OPT_RD8);
else
clrsetbits_le32(&regs->i2cm_operation,
HDMI_I2CM_OPT_RD8_EXT,
HDMI_I2CM_OPT_RD8_EXT);
if (hdmi_ddc_wait_i2c_done(regs, 10)) {
hdmi_ddc_reset(regs);
edid_read_err = 1;
break;
}
for (j = 0; j < 8; j++) {
val = readl(&regs->i2cm_buf0 + j);
buff[8 * n + j] = val;
}
}
if (!edid_read_err)
break;
}
return edid_read_err;
}
static u8 pre_buf[] = {
0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00,
0x04, 0x69, 0xfa, 0x23, 0xc8, 0x28, 0x01, 0x00,
0x10, 0x17, 0x01, 0x03, 0x80, 0x33, 0x1d, 0x78,
0x2a, 0xd9, 0x45, 0xa2, 0x55, 0x4d, 0xa0, 0x27,
0x12, 0x50, 0x54, 0xb7, 0xef, 0x00, 0x71, 0x4f,
0x81, 0x40, 0x81, 0x80, 0x95, 0x00, 0xb3, 0x00,
0xd1, 0xc0, 0x81, 0xc0, 0x81, 0x00, 0x02, 0x3a,
0x80, 0x18, 0x71, 0x38, 0x2d, 0x40, 0x58, 0x2c,
0x45, 0x00, 0xfd, 0x1e, 0x11, 0x00, 0x00, 0x1e,
0x00, 0x00, 0x00, 0xff, 0x00, 0x44, 0x34, 0x4c,
0x4d, 0x54, 0x46, 0x30, 0x37, 0x35, 0x39, 0x37,
0x36, 0x0a, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x32,
0x4b, 0x18, 0x53, 0x11, 0x00, 0x0a, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xfc,
0x00, 0x41, 0x53, 0x55, 0x53, 0x20, 0x56, 0x53,
0x32, 0x33, 0x38, 0x0a, 0x20, 0x20, 0x01, 0xb0,
0x02, 0x03, 0x22, 0x71, 0x4f, 0x01, 0x02, 0x03,
0x11, 0x12, 0x13, 0x04, 0x14, 0x05, 0x0e, 0x0f,
0x1d, 0x1e, 0x1f, 0x10, 0x23, 0x09, 0x17, 0x07,
0x83, 0x01, 0x00, 0x00, 0x65, 0x03, 0x0c, 0x00,
0x10, 0x00, 0x8c, 0x0a, 0xd0, 0x8a, 0x20, 0xe0,
0x2d, 0x10, 0x10, 0x3e, 0x96, 0x00, 0xfd, 0x1e,
0x11, 0x00, 0x00, 0x18, 0x01, 0x1d, 0x00, 0x72,
0x51, 0xd0, 0x1e, 0x20, 0x6e, 0x28, 0x55, 0x00,
0xfd, 0x1e, 0x11, 0x00, 0x00, 0x1e, 0x01, 0x1d,
0x00, 0xbc, 0x52, 0xd0, 0x1e, 0x20, 0xb8, 0x28,
0x55, 0x40, 0xfd, 0x1e, 0x11, 0x00, 0x00, 0x1e,
0x8c, 0x0a, 0xd0, 0x90, 0x20, 0x40, 0x31, 0x20,
0x0c, 0x40, 0x55, 0x00, 0xfd, 0x1e, 0x11, 0x00,
0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe9,
};
static int rk_hdmi_read_edid(struct udevice *dev, u8 *buf, int buf_size)
{
struct rk_hdmi_priv *priv = dev_get_priv(dev);
u32 edid_size = HDMI_EDID_BLOCK_SIZE;
int ret;
if (0) {
edid_size = sizeof(pre_buf);
memcpy(buf, pre_buf, edid_size);
} else {
ret = hdmi_read_edid(priv->regs, 0, buf);
if (ret) {
debug("failed to read edid.\n");
return -1;
}
if (buf[0x7e] != 0) {
hdmi_read_edid(priv->regs, 1,
buf + HDMI_EDID_BLOCK_SIZE);
edid_size += HDMI_EDID_BLOCK_SIZE;
}
}
return edid_size;
}
static int rk_hdmi_enable(struct udevice *dev, int panel_bpp,
const struct display_timing *edid)
{
struct rk_hdmi_priv *priv = dev_get_priv(dev);
struct rk3288_hdmi *regs = priv->regs;
int ret;
debug("hdmi, mode info : clock %d hdis %d vdis %d\n",
edid->pixelclock.typ, edid->hactive.typ, edid->vactive.typ);
hdmi_av_composer(regs, edid);
ret = hdmi_phy_init(regs, edid->pixelclock.typ);
if (ret)
return ret;
hdmi_enable_video_path(regs);
hdmi_audio_fifo_reset(regs);
hdmi_audio_set_format(regs);
hdmi_audio_set_samplerate(regs, edid->pixelclock.typ);
hdmi_video_packetize(regs);
hdmi_video_csc(regs);
hdmi_video_sample(regs);
hdmi_clear_overflow(regs);
return 0;
}
static int rk_hdmi_ofdata_to_platdata(struct udevice *dev)
{
struct rk_hdmi_priv *priv = dev_get_priv(dev);
priv->regs = (struct rk3288_hdmi *)dev_get_addr(dev);
priv->grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
return 0;
}
static int rk_hdmi_probe(struct udevice *dev)
{
struct display_plat *uc_plat = dev_get_uclass_platdata(dev);
struct rk_hdmi_priv *priv = dev_get_priv(dev);
struct udevice *reg;
struct clk clk;
int ret;
int vop_id = uc_plat->source_id;
ret = clk_get_by_index(dev, 0, &clk);
if (ret >= 0) {
ret = clk_set_rate(&clk, 0);
clk_free(&clk);
}
if (ret) {
debug("%s: Failed to set EDP clock: ret=%d\n", __func__, ret);
return ret;
}
/*
* Configure the maximum clock to permit whatever resolution the
* monitor wants
*/
ret = clk_get_by_index(uc_plat->src_dev, 0, &clk);
if (ret >= 0) {
ret = clk_set_rate(&clk, 384000000);
clk_free(&clk);
}
if (ret < 0) {
debug("%s: Failed to set clock in source device '%s': ret=%d\n",
__func__, uc_plat->src_dev->name, ret);
return ret;
}
ret = regulator_get_by_platname("vcc50_hdmi", &reg);
if (!ret)
ret = regulator_set_enable(reg, true);
if (ret)
debug("%s: Cannot set regulator vcc50_hdmi\n", __func__);
/* hdmi source select hdmi controller */
rk_setreg(&priv->grf->soc_con6, 1 << 15);
/* hdmi data from vop id */
rk_setreg(&priv->grf->soc_con6, (vop_id == 1) ? (1 << 4) : (1 << 4));
ret = hdmi_wait_for_hpd(priv->regs);
if (ret < 0) {
debug("hdmi can not get hpd signal\n");
return -1;
}
hdmi_init_interrupt(priv->regs);
return 0;
}
static const struct dm_display_ops rk_hdmi_ops = {
.read_edid = rk_hdmi_read_edid,
.enable = rk_hdmi_enable,
};
static const struct udevice_id rk_hdmi_ids[] = {
{ .compatible = "rockchip,rk3288-dw-hdmi" },
{ }
};
U_BOOT_DRIVER(hdmi_rockchip) = {
.name = "hdmi_rockchip",
.id = UCLASS_DISPLAY,
.of_match = rk_hdmi_ids,
.ops = &rk_hdmi_ops,
.ofdata_to_platdata = rk_hdmi_ofdata_to_platdata,
.probe = rk_hdmi_probe,
.priv_auto_alloc_size = sizeof(struct rk_hdmi_priv),
};

View File

@@ -0,0 +1,253 @@
/*
* Copyright 2016 Rockchip Inc.
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
#include <display.h>
#include <dm.h>
#include <edid.h>
#include <panel.h>
#include <regmap.h>
#include <syscon.h>
#include <asm/gpio.h>
#include <asm/io.h>
#include <asm/arch/clock.h>
#include <asm/arch/lvds_rk3288.h>
#include <asm/arch/grf_rk3288.h>
#include <dt-bindings/clock/rk3288-cru.h>
#include <dt-bindings/video/rk3288.h>
DECLARE_GLOBAL_DATA_PTR;
/**
* struct rk_lvds_priv - private rockchip lvds display driver info
*
* @reg: LVDS register address
* @grf: GRF register
* @panel: Panel device that is used in driver
*
* @output: Output mode, decided single or double channel,
* LVDS or LVTLL
* @format: Data format that RGB data will packing as
*/
struct rk_lvds_priv {
void __iomem *regs;
struct rk3288_grf *grf;
struct udevice *panel;
int output;
int format;
};
static inline void lvds_writel(struct rk_lvds_priv *lvds, u32 offset, u32 val)
{
writel(val, lvds->regs + offset);
writel(val, lvds->regs + offset + 0x100);
}
int rk_lvds_enable(struct udevice *dev, int panel_bpp,
const struct display_timing *edid)
{
struct rk_lvds_priv *priv = dev_get_priv(dev);
struct display_plat *uc_plat = dev_get_uclass_platdata(dev);
int ret = 0;
unsigned int val = 0;
ret = panel_enable_backlight(priv->panel);
if (ret) {
debug("%s: backlight error: %d\n", __func__, ret);
return ret;
}
/* Select the video source */
if (uc_plat->source_id)
val = RK3288_LVDS_SOC_CON6_SEL_VOP_LIT |
(RK3288_LVDS_SOC_CON6_SEL_VOP_LIT << 16);
else
val = RK3288_LVDS_SOC_CON6_SEL_VOP_LIT << 16;
rk_setreg(&priv->grf->soc_con6, val);
/* Select data transfer format */
val = priv->format;
if (priv->output == LVDS_OUTPUT_DUAL)
val |= LVDS_DUAL | LVDS_CH0_EN | LVDS_CH1_EN;
else if (priv->output == LVDS_OUTPUT_SINGLE)
val |= LVDS_CH0_EN;
else if (priv->output == LVDS_OUTPUT_RGB)
val |= LVDS_TTL_EN | LVDS_CH0_EN | LVDS_CH1_EN;
val |= (0xffff << 16);
rk_setreg(&priv->grf->soc_con7, val);
/* Enable LVDS PHY */
if (priv->output == LVDS_OUTPUT_RGB) {
lvds_writel(priv, RK3288_LVDS_CH0_REG0,
RK3288_LVDS_CH0_REG0_TTL_EN |
RK3288_LVDS_CH0_REG0_LANECK_EN |
RK3288_LVDS_CH0_REG0_LANE4_EN |
RK3288_LVDS_CH0_REG0_LANE3_EN |
RK3288_LVDS_CH0_REG0_LANE2_EN |
RK3288_LVDS_CH0_REG0_LANE1_EN |
RK3288_LVDS_CH0_REG0_LANE0_EN);
lvds_writel(priv, RK3288_LVDS_CH0_REG2,
RK3288_LVDS_PLL_FBDIV_REG2(0x46));
lvds_writel(priv, RK3288_LVDS_CH0_REG3,
RK3288_LVDS_PLL_FBDIV_REG3(0x46));
lvds_writel(priv, RK3288_LVDS_CH0_REG4,
RK3288_LVDS_CH0_REG4_LANECK_TTL_MODE |
RK3288_LVDS_CH0_REG4_LANE4_TTL_MODE |
RK3288_LVDS_CH0_REG4_LANE3_TTL_MODE |
RK3288_LVDS_CH0_REG4_LANE2_TTL_MODE |
RK3288_LVDS_CH0_REG4_LANE1_TTL_MODE |
RK3288_LVDS_CH0_REG4_LANE0_TTL_MODE);
lvds_writel(priv, RK3288_LVDS_CH0_REG5,
RK3288_LVDS_CH0_REG5_LANECK_TTL_DATA |
RK3288_LVDS_CH0_REG5_LANE4_TTL_DATA |
RK3288_LVDS_CH0_REG5_LANE3_TTL_DATA |
RK3288_LVDS_CH0_REG5_LANE2_TTL_DATA |
RK3288_LVDS_CH0_REG5_LANE1_TTL_DATA |
RK3288_LVDS_CH0_REG5_LANE0_TTL_DATA);
lvds_writel(priv, RK3288_LVDS_CH0_REGD,
RK3288_LVDS_PLL_PREDIV_REGD(0x0a));
lvds_writel(priv, RK3288_LVDS_CH0_REG20,
RK3288_LVDS_CH0_REG20_LSB);
} else {
lvds_writel(priv, RK3288_LVDS_CH0_REG0,
RK3288_LVDS_CH0_REG0_LVDS_EN |
RK3288_LVDS_CH0_REG0_LANECK_EN |
RK3288_LVDS_CH0_REG0_LANE4_EN |
RK3288_LVDS_CH0_REG0_LANE3_EN |
RK3288_LVDS_CH0_REG0_LANE2_EN |
RK3288_LVDS_CH0_REG0_LANE1_EN |
RK3288_LVDS_CH0_REG0_LANE0_EN);
lvds_writel(priv, RK3288_LVDS_CH0_REG1,
RK3288_LVDS_CH0_REG1_LANECK_BIAS |
RK3288_LVDS_CH0_REG1_LANE4_BIAS |
RK3288_LVDS_CH0_REG1_LANE3_BIAS |
RK3288_LVDS_CH0_REG1_LANE2_BIAS |
RK3288_LVDS_CH0_REG1_LANE1_BIAS |
RK3288_LVDS_CH0_REG1_LANE0_BIAS);
lvds_writel(priv, RK3288_LVDS_CH0_REG2,
RK3288_LVDS_CH0_REG2_RESERVE_ON |
RK3288_LVDS_CH0_REG2_LANECK_LVDS_MODE |
RK3288_LVDS_CH0_REG2_LANE4_LVDS_MODE |
RK3288_LVDS_CH0_REG2_LANE3_LVDS_MODE |
RK3288_LVDS_CH0_REG2_LANE2_LVDS_MODE |
RK3288_LVDS_CH0_REG2_LANE1_LVDS_MODE |
RK3288_LVDS_CH0_REG2_LANE0_LVDS_MODE |
RK3288_LVDS_PLL_FBDIV_REG2(0x46));
lvds_writel(priv, RK3288_LVDS_CH0_REG3,
RK3288_LVDS_PLL_FBDIV_REG3(0x46));
lvds_writel(priv, RK3288_LVDS_CH0_REG4, 0x00);
lvds_writel(priv, RK3288_LVDS_CH0_REG5, 0x00);
lvds_writel(priv, RK3288_LVDS_CH0_REGD,
RK3288_LVDS_PLL_PREDIV_REGD(0x0a));
lvds_writel(priv, RK3288_LVDS_CH0_REG20,
RK3288_LVDS_CH0_REG20_LSB);
}
/* Power on */
writel(RK3288_LVDS_CFG_REGC_PLL_ENABLE,
priv->regs + RK3288_LVDS_CFG_REGC);
writel(RK3288_LVDS_CFG_REG21_TX_ENABLE,
priv->regs + RK3288_LVDS_CFG_REG21);
return 0;
}
int rk_lvds_read_timing(struct udevice *dev, struct display_timing *timing)
{
if (fdtdec_decode_display_timing
(gd->fdt_blob, dev->of_offset, 0, timing)) {
debug("%s: Failed to decode display timing\n", __func__);
return -EINVAL;
}
return 0;
}
static int rk_lvds_ofdata_to_platdata(struct udevice *dev)
{
struct rk_lvds_priv *priv = dev_get_priv(dev);
const void *blob = gd->fdt_blob;
int node = dev->of_offset;
int ret;
priv->regs = (void *)dev_get_addr(dev);
priv->grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
ret = fdtdec_get_int(blob, node, "rockchip,output", -1);
if (ret != -1) {
priv->output = ret;
debug("LVDS output : %d\n", ret);
} else {
/* default set it as output rgb */
priv->output = LVDS_OUTPUT_RGB;
}
ret = fdtdec_get_int(blob, node, "rockchip,data-mapping", -1);
if (ret != -1) {
priv->format = ret;
debug("LVDS data-mapping : %d\n", ret);
} else {
/* default set it as format jeida */
priv->format = LVDS_FORMAT_JEIDA;
}
ret = fdtdec_get_int(blob, node, "rockchip,data-width", -1);
if (ret != -1) {
debug("LVDS data-width : %d\n", ret);
if (ret == 24) {
priv->format |= LVDS_24BIT;
} else if (ret == 18) {
priv->format |= LVDS_18BIT;
} else {
debug("rockchip-lvds unsupport data-width[%d]\n", ret);
ret = -EINVAL;
return ret;
}
} else {
priv->format |= LVDS_24BIT;
}
return 0;
}
int rk_lvds_probe(struct udevice *dev)
{
struct rk_lvds_priv *priv = dev_get_priv(dev);
int ret;
ret = uclass_get_device_by_phandle(UCLASS_PANEL, dev, "rockchip,panel",
&priv->panel);
if (ret) {
debug("%s: Cannot find panel for '%s' (ret=%d)\n", __func__,
dev->name, ret);
return ret;
}
return 0;
}
static const struct dm_display_ops lvds_rockchip_ops = {
.read_timing = rk_lvds_read_timing,
.enable = rk_lvds_enable,
};
static const struct udevice_id rockchip_lvds_ids[] = {
{.compatible = "rockchip,rk3288-lvds"},
{}
};
U_BOOT_DRIVER(lvds_rockchip) = {
.name = "lvds_rockchip",
.id = UCLASS_DISPLAY,
.of_match = rockchip_lvds_ids,
.ops = &lvds_rockchip_ops,
.ofdata_to_platdata = rk_lvds_ofdata_to_platdata,
.probe = rk_lvds_probe,
.priv_auto_alloc_size = sizeof(struct rk_lvds_priv),
};

View File

@@ -0,0 +1,362 @@
/*
* Copyright (c) 2015 Google, Inc
* Copyright 2014 Rockchip Inc.
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
#include <clk.h>
#include <display.h>
#include <dm.h>
#include <edid.h>
#include <regmap.h>
#include <syscon.h>
#include <video.h>
#include <asm/gpio.h>
#include <asm/hardware.h>
#include <asm/io.h>
#include <asm/arch/clock.h>
#include <asm/arch/cru_rk3288.h>
#include <asm/arch/grf_rk3288.h>
#include <asm/arch/edp_rk3288.h>
#include <asm/arch/hdmi_rk3288.h>
#include <asm/arch/vop_rk3288.h>
#include <dm/device-internal.h>
#include <dm/uclass-internal.h>
#include <dt-bindings/clock/rk3288-cru.h>
#include <power/regulator.h>
DECLARE_GLOBAL_DATA_PTR;
struct rk_vop_priv {
struct rk3288_vop *regs;
struct rk3288_grf *grf;
};
void rkvop_enable(struct rk3288_vop *regs, ulong fbbase,
int fb_bits_per_pixel, const struct display_timing *edid)
{
u32 lb_mode;
u32 rgb_mode;
u32 hactive = edid->hactive.typ;
u32 vactive = edid->vactive.typ;
writel(V_ACT_WIDTH(hactive - 1) | V_ACT_HEIGHT(vactive - 1),
&regs->win0_act_info);
writel(V_DSP_XST(edid->hsync_len.typ + edid->hback_porch.typ) |
V_DSP_YST(edid->vsync_len.typ + edid->vback_porch.typ),
&regs->win0_dsp_st);
writel(V_DSP_WIDTH(hactive - 1) |
V_DSP_HEIGHT(vactive - 1),
&regs->win0_dsp_info);
clrsetbits_le32(&regs->win0_color_key, M_WIN0_KEY_EN | M_WIN0_KEY_COLOR,
V_WIN0_KEY_EN(0) | V_WIN0_KEY_COLOR(0));
switch (fb_bits_per_pixel) {
case 16:
rgb_mode = RGB565;
writel(V_RGB565_VIRWIDTH(hactive), &regs->win0_vir);
break;
case 24:
rgb_mode = RGB888;
writel(V_RGB888_VIRWIDTH(hactive), &regs->win0_vir);
break;
case 32:
default:
rgb_mode = ARGB8888;
writel(V_ARGB888_VIRWIDTH(hactive), &regs->win0_vir);
break;
}
if (hactive > 2560)
lb_mode = LB_RGB_3840X2;
else if (hactive > 1920)
lb_mode = LB_RGB_2560X4;
else if (hactive > 1280)
lb_mode = LB_RGB_1920X5;
else
lb_mode = LB_RGB_1280X8;
clrsetbits_le32(&regs->win0_ctrl0,
M_WIN0_LB_MODE | M_WIN0_DATA_FMT | M_WIN0_EN,
V_WIN0_LB_MODE(lb_mode) | V_WIN0_DATA_FMT(rgb_mode) |
V_WIN0_EN(1));
writel(fbbase, &regs->win0_yrgb_mst);
writel(0x01, &regs->reg_cfg_done); /* enable reg config */
}
void rkvop_mode_set(struct rk3288_vop *regs,
const struct display_timing *edid, enum vop_modes mode)
{
u32 hactive = edid->hactive.typ;
u32 vactive = edid->vactive.typ;
u32 hsync_len = edid->hsync_len.typ;
u32 hback_porch = edid->hback_porch.typ;
u32 vsync_len = edid->vsync_len.typ;
u32 vback_porch = edid->vback_porch.typ;
u32 hfront_porch = edid->hfront_porch.typ;
u32 vfront_porch = edid->vfront_porch.typ;
uint flags;
int mode_flags;
switch (mode) {
case VOP_MODE_HDMI:
clrsetbits_le32(&regs->sys_ctrl, M_ALL_OUT_EN,
V_HDMI_OUT_EN(1));
break;
case VOP_MODE_EDP:
default:
clrsetbits_le32(&regs->sys_ctrl, M_ALL_OUT_EN,
V_EDP_OUT_EN(1));
break;
case VOP_MODE_LVDS:
clrsetbits_le32(&regs->sys_ctrl, M_ALL_OUT_EN,
V_RGB_OUT_EN(1));
break;
}
if (mode == VOP_MODE_HDMI || mode == VOP_MODE_EDP)
/* RGBaaa */
mode_flags = 15;
else
/* RGB888 */
mode_flags = 0;
flags = V_DSP_OUT_MODE(mode_flags) |
V_DSP_HSYNC_POL(!!(edid->flags & DISPLAY_FLAGS_HSYNC_HIGH)) |
V_DSP_VSYNC_POL(!!(edid->flags & DISPLAY_FLAGS_VSYNC_HIGH));
clrsetbits_le32(&regs->dsp_ctrl0,
M_DSP_OUT_MODE | M_DSP_VSYNC_POL | M_DSP_HSYNC_POL,
flags);
writel(V_HSYNC(hsync_len) |
V_HORPRD(hsync_len + hback_porch + hactive + hfront_porch),
&regs->dsp_htotal_hs_end);
writel(V_HEAP(hsync_len + hback_porch + hactive) |
V_HASP(hsync_len + hback_porch),
&regs->dsp_hact_st_end);
writel(V_VSYNC(vsync_len) |
V_VERPRD(vsync_len + vback_porch + vactive + vfront_porch),
&regs->dsp_vtotal_vs_end);
writel(V_VAEP(vsync_len + vback_porch + vactive)|
V_VASP(vsync_len + vback_porch),
&regs->dsp_vact_st_end);
writel(V_HEAP(hsync_len + hback_porch + hactive) |
V_HASP(hsync_len + hback_porch),
&regs->post_dsp_hact_info);
writel(V_VAEP(vsync_len + vback_porch + vactive)|
V_VASP(vsync_len + vback_porch),
&regs->post_dsp_vact_info);
writel(0x01, &regs->reg_cfg_done); /* enable reg config */
}
/**
* rk_display_init() - Try to enable the given display device
*
* This function performs many steps:
* - Finds the display device being referenced by @ep_node
* - Puts the VOP's ID into its uclass platform data
* - Probes the device to set it up
* - Reads the EDID timing information
* - Sets up the VOP clocks, etc. for the selected pixel clock and display mode
* - Enables the display (the display device handles this and will do different
* things depending on the display type)
* - Tells the uclass about the display resolution so that the console will
* appear correctly
*
* @dev: VOP device that we want to connect to the display
* @fbbase: Frame buffer address
* @l2bpp Log2 of bits-per-pixels for the display
* @ep_node: Device tree node to process - this is the offset of an endpoint
* node within the VOP's 'port' list.
* @return 0 if OK, -ve if something went wrong
*/
int rk_display_init(struct udevice *dev, ulong fbbase,
enum video_log2_bpp l2bpp, int ep_node)
{
struct video_priv *uc_priv = dev_get_uclass_priv(dev);
const void *blob = gd->fdt_blob;
struct rk_vop_priv *priv = dev_get_priv(dev);
int vop_id, remote_vop_id;
struct rk3288_vop *regs = priv->regs;
struct display_timing timing;
struct udevice *disp;
int ret, remote, i, offset;
struct display_plat *disp_uc_plat;
struct udevice *dev_clk;
struct clk clk;
vop_id = fdtdec_get_int(blob, ep_node, "reg", -1);
debug("vop_id=%d\n", vop_id);
remote = fdtdec_lookup_phandle(blob, ep_node, "remote-endpoint");
if (remote < 0)
return -EINVAL;
remote_vop_id = fdtdec_get_int(blob, remote, "reg", -1);
debug("remote vop_id=%d\n", remote_vop_id);
for (i = 0, offset = remote; i < 3 && offset > 0; i++)
offset = fdt_parent_offset(blob, offset);
if (offset < 0) {
debug("%s: Invalid remote-endpoint position\n", dev->name);
return -EINVAL;
}
ret = uclass_find_device_by_of_offset(UCLASS_DISPLAY, offset, &disp);
if (ret) {
debug("%s: device '%s' display not found (ret=%d)\n", __func__,
dev->name, ret);
return ret;
}
disp_uc_plat = dev_get_uclass_platdata(disp);
debug("Found device '%s', disp_uc_priv=%p\n", disp->name, disp_uc_plat);
disp_uc_plat->source_id = remote_vop_id;
disp_uc_plat->src_dev = dev;
ret = device_probe(disp);
if (ret) {
debug("%s: device '%s' display won't probe (ret=%d)\n",
__func__, dev->name, ret);
return ret;
}
ret = display_read_timing(disp, &timing);
if (ret) {
debug("%s: Failed to read timings\n", __func__);
return ret;
}
ret = uclass_get_device(UCLASS_CLK, 0, &dev_clk);
if (!ret) {
clk.id = DCLK_VOP0 + remote_vop_id;
ret = clk_request(dev_clk, &clk);
}
if (!ret)
ret = clk_set_rate(&clk, timing.pixelclock.typ);
if (ret) {
debug("%s: Failed to set pixel clock: ret=%d\n", __func__, ret);
return ret;
}
rkvop_mode_set(regs, &timing, vop_id);
rkvop_enable(regs, fbbase, 1 << l2bpp, &timing);
ret = display_enable(disp, 1 << l2bpp, &timing);
if (ret)
return ret;
uc_priv->xsize = timing.hactive.typ;
uc_priv->ysize = timing.vactive.typ;
uc_priv->bpix = l2bpp;
debug("fb=%lx, size=%d %d\n", fbbase, uc_priv->xsize, uc_priv->ysize);
return 0;
}
static int rk_vop_probe(struct udevice *dev)
{
struct video_uc_platdata *plat = dev_get_uclass_platdata(dev);
const void *blob = gd->fdt_blob;
struct rk_vop_priv *priv = dev_get_priv(dev);
struct udevice *reg;
int ret, port, node;
/* Before relocation we don't need to do anything */
if (!(gd->flags & GD_FLG_RELOC))
return 0;
priv->grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
priv->regs = (struct rk3288_vop *)dev_get_addr(dev);
/* lcdc(vop) iodomain select 1.8V */
rk_setreg(&priv->grf->io_vsel, 1 << 0);
/*
* Try some common regulators. We should really get these from the
* device tree somehow.
*/
ret = regulator_autoset_by_name("vcc18_lcd", &reg);
if (ret)
debug("%s: Cannot autoset regulator vcc18_lcd\n", __func__);
ret = regulator_autoset_by_name("VCC18_LCD", &reg);
if (ret)
debug("%s: Cannot autoset regulator VCC18_LCD\n", __func__);
ret = regulator_autoset_by_name("vdd10_lcd_pwren_h", &reg);
if (ret) {
debug("%s: Cannot autoset regulator vdd10_lcd_pwren_h\n",
__func__);
}
ret = regulator_autoset_by_name("vdd10_lcd", &reg);
if (ret) {
debug("%s: Cannot autoset regulator vdd10_lcd\n",
__func__);
}
ret = regulator_autoset_by_name("VDD10_LCD", &reg);
if (ret) {
debug("%s: Cannot autoset regulator VDD10_LCD\n",
__func__);
}
ret = regulator_autoset_by_name("vcc33_lcd", &reg);
if (ret)
debug("%s: Cannot autoset regulator vcc33_lcd\n", __func__);
/*
* Try all the ports until we find one that works. In practice this
* tries EDP first if available, then HDMI.
*/
port = fdt_subnode_offset(blob, dev->of_offset, "port");
if (port < 0)
return -EINVAL;
for (node = fdt_first_subnode(blob, port);
node > 0;
node = fdt_next_subnode(blob, node)) {
ret = rk_display_init(dev, plat->base, VIDEO_BPP16, node);
if (ret)
debug("Device failed: ret=%d\n", ret);
if (!ret)
break;
}
video_set_flush_dcache(dev, 1);
return ret;
}
static int rk_vop_bind(struct udevice *dev)
{
struct video_uc_platdata *plat = dev_get_uclass_platdata(dev);
plat->size = 1920 * 1080 * 2;
return 0;
}
static const struct video_ops rk_vop_ops = {
};
static const struct udevice_id rk_vop_ids[] = {
{ .compatible = "rockchip,rk3288-vop" },
{ }
};
U_BOOT_DRIVER(rk_vop) = {
.name = "rk_vop",
.id = UCLASS_VIDEO,
.of_match = rk_vop_ids,
.ops = &rk_vop_ops,
.bind = rk_vop_bind,
.probe = rk_vop_probe,
.priv_auto_alloc_size = sizeof(struct rk_vop_priv),
};