#include <linux/rockchip/grf.h>
#include "rk32_lvds.h"
-//#define TTL_TO_LVDS 1
+
+#define grf_readl(offset) readl_relaxed(RK_GRF_VIRT + offset)
+#define grf_writel(v,offset) do{ writel_relaxed(v, RK_GRF_VIRT + offset);dsb();} while (0)
+
static struct rk32_lvds *rk32_lvds;
+
+static int rk32_lvds_clk_enable(struct rk32_lvds *lvds)
+{
+ if (!lvds->clk_on) {
+ clk_prepare_enable(lvds->pd);
+ clk_prepare_enable(lvds->pclk);
+ lvds->clk_on = true;
+ }
+
+ return 0;
+}
+
+static int rk32_lvds_clk_disable(struct rk32_lvds *lvds)
+{
+ if (lvds->clk_on) {
+ clk_disable_unprepare(lvds->pclk);
+ clk_disable_unprepare(lvds->pd);
+ lvds->clk_on = false;
+ }
+
+ return 0;
+}
+
static int rk32_lvds_disable(void)
{
struct rk32_lvds *lvds = rk32_lvds;
- writel_relaxed(0xffff8000, RK_GRF_VIRT + RK3288_GRF_SOC_CON7);
+ grf_writel(0xffff8000, RK3288_GRF_SOC_CON7);
writel_relaxed(0x00, lvds->regs + LVDS_CFG_REG_21); /*disable tx*/
writel_relaxed(0xff, lvds->regs + LVDS_CFG_REG_c); /*disable pll*/
- clk_disable_unprepare(lvds->clk);
- clk_disable_unprepare(lvds->pd);
+ rk32_lvds_clk_disable(lvds);
return 0;
}
{
struct rk32_lvds *lvds = rk32_lvds;
struct rk_screen *screen = &lvds->screen;
- u32 h_bp = screen->mode.hsync_len + screen->mode.left_margin;
- u32 i,j, val ;
-
- clk_prepare_enable(lvds->clk);
- clk_prepare_enable(lvds->pd);
- screen->type = SCREEN_RGB;
-
- screen->lcdc_id = 1;
+ u32 h_bp = 0;
+ u32 val = 0;
+
+ rk_fb_get_prmry_screen(screen);
+
+ /* enable clk */
+ rk32_lvds_clk_enable(lvds);
+
+ /* select lcdc source */
if (screen->lcdc_id == 1) /*lcdc1 = vop little,lcdc0 = vop big*/
val = LVDS_SEL_VOP_LIT | (LVDS_SEL_VOP_LIT << 16);
else
val = LVDS_SEL_VOP_LIT << 16;
- writel_relaxed(val, RK_GRF_VIRT + RK3288_GRF_SOC_CON6);
+ grf_writel(val, RK3288_GRF_SOC_CON6);
+ /* set lvds format */
val = screen->lvds_format;
if (screen->type == SCREEN_DUAL_LVDS)
val |= LVDS_DUAL | LVDS_CH0_EN | LVDS_CH1_EN;
else if(screen->type == SCREEN_LVDS)
val |= LVDS_CH0_EN;
-
- //val |= LVDS_MSB;
else if (screen->type == SCREEN_RGB)
val |= LVDS_TTL_EN | LVDS_CH0_EN | LVDS_CH1_EN;
+ h_bp = screen->mode.hsync_len + screen->mode.left_margin;
if (h_bp & 0x01)
val |= LVDS_START_PHASE_RST_1;
val |= (screen->pin_dclk << 8) | (screen->pin_hsync << 9) |
(screen->pin_den << 10);
- val |= 0xffff << 16;
- //val = 0x08010801;
- writel_relaxed(val, RK_GRF_VIRT + RK3288_GRF_SOC_CON7);
+ val |= (val << 16);
+ grf_writel(val, RK3288_GRF_SOC_CON7);
- if (screen->type == SCREEN_LVDS)
- val = 0xbf;
- else
- val = 0x7f;
-#if 0
- for(i=0;i<0x200;){
- val = readl_relaxed(lvds->regs + i);
- printk("0x%08x:0x%08x ",i,val);
- i += 4;
- if(i % 16 == 0)
- printk("\n");
- }
-#endif
- #ifdef TTL_TO_LVDS // 0 ttl 1 lvds
- val = 0x007f007f;//0x1<<6 |0x1 <<4;
- writel_relaxed(val, RK_GRF_VIRT + 0xc);
-
-
- lvds_writel(lvds, LVDS_CH0_REG_0, 0x7f);
- lvds_writel(lvds, LVDS_CH0_REG_1, 0x40);
- lvds_writel(lvds, LVDS_CH0_REG_2, 0x00);
-
- if (screen->type == SCREEN_RGB)
- val = 0x1f;
- else
- val = 0x00;
- lvds_writel(lvds, LVDS_CH0_REG_4, 0x3f);
- lvds_writel(lvds, LVDS_CH0_REG_5, 0x3f);
- lvds_writel(lvds, LVDS_CH0_REG_3, 0x46);
- lvds_writel(lvds, LVDS_CH0_REG_d, 0x0a);
- lvds_writel(lvds, LVDS_CH0_REG_20,0x44);/* 44:LSB 45:MSB*/
- writel_relaxed(0x00, lvds->regs + LVDS_CFG_REG_c); /*eanble pll*/
- writel_relaxed(0x92, lvds->regs + LVDS_CFG_REG_21); /*enable tx*/
-
- lvds_writel(lvds, 0x100, 0x7f);
- lvds_writel(lvds, 0x104, 0x40);
- lvds_writel(lvds, 0x108, 0x00);
- lvds_writel(lvds, 0x10c, 0x46);
- lvds_writel(lvds, 0x110, 0x3f);
- lvds_writel(lvds, 0x114, 0x3f);
- lvds_writel(lvds, 0x134, 0x0a);
- #else
- val = readl_relaxed(lvds->regs + 0x88);
- printk("0x88:0x%x\n",val);
-
- lvds_writel(lvds, LVDS_CH0_REG_0, 0xbf);
- lvds_writel(lvds, LVDS_CH0_REG_1, 0x3f);// 3f
- lvds_writel(lvds, LVDS_CH0_REG_2, 0xfe);
- lvds_writel(lvds, LVDS_CH0_REG_3, 0x46);//0x46
- lvds_writel(lvds, LVDS_CH0_REG_4, 0x00);
- //lvds_writel(lvds, LVDS_CH0_REG_9, 0x20);
- //lvds_writel(lvds, LVDS_CH0_REG_d, 0x4b);
- //lvds_writel(lvds, LVDS_CH0_REG_f, 0x0d);
- lvds_writel(lvds, LVDS_CH0_REG_d, 0x0a);//0a
- lvds_writel(lvds, LVDS_CH0_REG_20,0x44);/* 44:LSB 45:MSB*/
- //lvds_writel(lvds, 0x24,0x20);
- //writel_relaxed(0x23, lvds->regs + 0x88);
- writel_relaxed(0x00, lvds->regs + LVDS_CFG_REG_c); /*eanble pll*/
- writel_relaxed(0x92, lvds->regs + LVDS_CFG_REG_21); /*enable tx*/
-
-
- //lvds_writel(lvds, 0x100, 0xbf);
- //lvds_writel(lvds, 0x104, 0x3f);
- //lvds_writel(lvds, 0x108, 0xfe);
- //lvds_writel(lvds, 0x10c, 0x46); //0x46
- //lvds_writel(lvds, 0x110, 0x00);
- //lvds_writel(lvds, 0x114, 0x00);
- //lvds_writel(lvds, 0x134, 0x0a);
-
- #endif
-#if 0
- for(i=0;i<100;i++){
- mdelay(1000);
- mdelay(1000);
- mdelay(1000);
- mdelay(1000);
- mdelay(1000);
- printk("write LVDS_CH0_REG_20 :0x40\n");
- //writel_relaxed(0x10, lvds->regs + LVDS_CFG_REG_c);
- lvds_writel(lvds, LVDS_CH0_REG_20,0x40);/* 44:LSB 45:MSB*/
- val = readl_relaxed(lvds->regs + LVDS_CH0_REG_20);
- printk("read back LVDS_CH0_REG_20:0x%x\n",val);
- mdelay(1000);
- mdelay(1000);
- mdelay(1000);
- mdelay(1000);
- mdelay(1000);
- printk("write LVDS_CH0_REG_20 :0x44\n");
+ if (screen->type == SCREEN_RGB) {
+ val = 0x007f007f;//0x1<<6 |0x1 <<4;
+ grf_writel(val, RK3288_GRF_GPIO1D_IOMUX);
+
+ lvds_writel(lvds, LVDS_CH0_REG_0, 0x7f);
+ lvds_writel(lvds, LVDS_CH0_REG_1, 0x40);
+ lvds_writel(lvds, LVDS_CH0_REG_2, 0x00);
+
+ lvds_writel(lvds, LVDS_CH0_REG_4, 0x3f);
+ lvds_writel(lvds, LVDS_CH0_REG_5, 0x3f);
+ lvds_writel(lvds, LVDS_CH0_REG_3, 0x46);
+ lvds_writel(lvds, LVDS_CH0_REG_d, 0x0a);
lvds_writel(lvds, LVDS_CH0_REG_20,0x44);/* 44:LSB 45:MSB*/
- val = readl_relaxed(lvds->regs + LVDS_CH0_REG_20);
- printk("read back LVDS_CH0_REG_20:0x%x\n",val);
- }
-#endif
- //while(1)
-#if 0
- {
- val = readl_relaxed(RK_GRF_VIRT + RK3288_GRF_SOC_CON6);
- printk("RK3288_GRF_SOC_CON6:0x%x\n",val);
- val = readl_relaxed(RK_GRF_VIRT + RK3288_GRF_SOC_CON7);
- printk("RK3288_GRF_SOC_CON7:0x%x\n",val);
- val = readl_relaxed(RK_GRF_VIRT + RK3288_GRF_SOC_CON15);
- printk("RK3288_GRF_SOC_CON15:0x%x\n",val);
-
-
- val = readl_relaxed(lvds->regs + LVDS_CH0_REG_0);
- printk("LVDS_CH0_REG_0:0x%x\n",val);
-
- val = readl_relaxed(lvds->regs + LVDS_CH0_REG_1);
- printk("LVDS_CH0_REG_1:0x%x\n",val);
-
- val = readl_relaxed(lvds->regs + LVDS_CH0_REG_2);
- printk("LVDS_CH0_REG_2:0x%x\n",val);
-
- val = readl_relaxed(lvds->regs + LVDS_CH0_REG_3);
- printk("LVDS_CH0_REG_3:0x%x\n",val);
-
- val = readl_relaxed(lvds->regs + LVDS_CH0_REG_4);
- printk("LVDS_CH0_REG_4:0x%x\n",val);
-
- val = readl_relaxed(lvds->regs + LVDS_CH0_REG_5);
- printk("LVDS_CH0_REG_5:0x%x\n",val);
-
- val = readl_relaxed(lvds->regs + LVDS_CH0_REG_d);
- printk("LVDS_CH0_REG_d:0x%x\n",val);
-
- val = readl_relaxed(lvds->regs + LVDS_CH0_REG_f);
- printk("LVDS_CH0_REG_f:0x%x\n",val);
-
-
- val = readl_relaxed(lvds->regs + LVDS_CFG_REG_c);
- printk("LVDS_CFG_REG_c:0x%x\n",val);
-
- val = readl_relaxed(lvds->regs + LVDS_CFG_REG_21);
- printk("LVDS_CFG_REG_21:0x%x\n",val);
- val = readl_relaxed(lvds->regs + 0x100);
- printk("0x100:0x%x\n",val);
-
- val = readl_relaxed(lvds->regs + 0x104);
- printk("0x104:0x%x\n",val);
- val = readl_relaxed(lvds->regs + 0x108);
- printk("0x108:0x%x\n",val);
-
- val = readl_relaxed(lvds->regs + 0x10c);
- printk("0x10c:0x%x\n",val);
-
- val = readl_relaxed(lvds->regs + 0x110);
- printk("0x110:0x%x\n",val);
-
- val = readl_relaxed(lvds->regs + 0x114);
- printk("0x114:0x%x\n",val);
- val = readl_relaxed(lvds->regs + 0x118);
- printk("0x118:0x%x\n",val);
-
- val = readl_relaxed(lvds->regs + 0x11c);
- printk("0x11c:0x%x\n",val);
- mdelay(1000);
- }
-
- for(i=0;i<0x200;){
- val = readl_relaxed(lvds->regs + i);
- printk("0x%08x:0x%08x ",i,val);
- i += 4;
- if(i % 16 == 0)
- printk("\n");
+ writel_relaxed(0x00, lvds->regs + LVDS_CFG_REG_c); /*eanble pll*/
+ writel_relaxed(0x92, lvds->regs + LVDS_CFG_REG_21); /*enable tx*/
+
+ lvds_writel(lvds, 0x100, 0x7f);
+ lvds_writel(lvds, 0x104, 0x40);
+ lvds_writel(lvds, 0x108, 0x00);
+ lvds_writel(lvds, 0x10c, 0x46);
+ lvds_writel(lvds, 0x110, 0x3f);
+ lvds_writel(lvds, 0x114, 0x3f);
+ lvds_writel(lvds, 0x134, 0x0a);
+ } else {
+ lvds_writel(lvds, LVDS_CH0_REG_0, 0xbf);
+ lvds_writel(lvds, LVDS_CH0_REG_1, 0x3f);
+ lvds_writel(lvds, LVDS_CH0_REG_2, 0xfe);
+ lvds_writel(lvds, LVDS_CH0_REG_3, 0x46);
+ lvds_writel(lvds, LVDS_CH0_REG_4, 0x00);
+ lvds_writel(lvds, LVDS_CH0_REG_d, 0x0a);
+ lvds_writel(lvds, LVDS_CH0_REG_20,0x44);/* 44:LSB 45:MSB*/
+ writel_relaxed(0x00, lvds->regs + LVDS_CFG_REG_c); /*eanble pll*/
+ writel_relaxed(0x92, lvds->regs + LVDS_CFG_REG_21); /*enable tx*/
}
-#endif
+
return 0;
}
-
static struct rk_fb_trsm_ops trsm_lvds_ops = {
.enable = rk32_lvds_en,
.disable = rk32_lvds_disable,
dev_err(&pdev->dev, "ioremap reg failed\n");
return PTR_ERR(lvds->regs);
}
- lvds->clk = devm_clk_get(&pdev->dev,"pclk_lvds");
- if (IS_ERR(lvds->clk)) {
+ lvds->pclk = devm_clk_get(&pdev->dev,"pclk_lvds");
+ if (IS_ERR(lvds->pclk)) {
dev_err(&pdev->dev, "get clk failed\n");
- return PTR_ERR(lvds->clk);
+ return PTR_ERR(lvds->pclk);
}
lvds->pd = devm_clk_get(&pdev->dev,"pd_lvds");
if (IS_ERR(lvds->pd)) {
return PTR_ERR(lvds->pd);
}
if (support_uboot_display()) {
- clk_prepare_enable(lvds->clk);
- clk_prepare_enable(lvds->pd);
+ rk32_lvds_clk_enable(lvds);
}
rk32_lvds = lvds;