Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 2 | /* |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 3 | * Copyright 2007-2011 Freescale Semiconductor, Inc. |
| 4 | * Authors: York Sun <yorksun@freescale.com> |
| 5 | * Timur Tabi <timur@freescale.com> |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 6 | * |
| 7 | * FSL DIU Framebuffer driver |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <command.h> |
| 12 | #include <asm/io.h> |
Anatolij Gustschin | 43ffc53 | 2010-09-24 01:06:37 +0200 | [diff] [blame] | 13 | #include <fsl_diu_fb.h> |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 14 | #include "../common/pixis.h" |
| 15 | |
| 16 | #define PX_BRDCFG0_DLINK 0x10 |
| 17 | #define PX_BRDCFG0_DVISEL 0x08 |
York Sun | 59e7468 | 2007-10-31 14:59:04 -0500 | [diff] [blame] | 18 | |
York Sun | c496438 | 2008-05-05 10:19:59 -0500 | [diff] [blame] | 19 | void diu_set_pixel_clock(unsigned int pixclock) |
| 20 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 21 | volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
York Sun | c496438 | 2008-05-05 10:19:59 -0500 | [diff] [blame] | 22 | volatile ccsr_gur_t *gur = &immap->im_gur; |
| 23 | volatile unsigned int *guts_clkdvdr = &gur->clkdvdr; |
| 24 | unsigned long speed_ccb, temp, pixval; |
| 25 | |
| 26 | speed_ccb = get_bus_freq(0); |
| 27 | temp = 1000000000/pixclock; |
| 28 | temp *= 1000; |
| 29 | pixval = speed_ccb / temp; |
| 30 | debug("DIU pixval = %lu\n", pixval); |
| 31 | |
| 32 | /* Modify PXCLK in GUTS CLKDVDR */ |
| 33 | debug("DIU: Current value of CLKDVDR = 0x%08x\n", *guts_clkdvdr); |
| 34 | temp = *guts_clkdvdr & 0x2000FFFF; |
| 35 | *guts_clkdvdr = temp; /* turn off clock */ |
| 36 | *guts_clkdvdr = temp | 0x80000000 | ((pixval & 0x1F) << 16); |
| 37 | debug("DIU: Modified value of CLKDVDR = 0x%08x\n", *guts_clkdvdr); |
| 38 | } |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 39 | |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 40 | int platform_diu_init(unsigned int xres, unsigned int yres, const char *port) |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 41 | { |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 42 | const char *name; |
| 43 | int gamma_fix = 0; |
| 44 | u32 pixel_format = 0x88883316; |
| 45 | u8 temp; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 46 | |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 47 | temp = in_8(&pixis->brdcfg0); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 48 | |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 49 | if (strncmp(port, "dlvds", 5) == 0) { |
| 50 | /* Dual link LVDS */ |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 51 | gamma_fix = 1; |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 52 | temp &= ~(PX_BRDCFG0_DLINK | PX_BRDCFG0_DVISEL); |
| 53 | name = "Dual-Link LVDS"; |
| 54 | } else if (strncmp(port, "lvds", 4) == 0) { |
| 55 | /* Single link LVDS */ |
| 56 | temp = (temp & ~PX_BRDCFG0_DVISEL) | PX_BRDCFG0_DLINK; |
| 57 | name = "Single-Link LVDS"; |
| 58 | } else { |
| 59 | /* DVI */ |
| 60 | if (in_8(&pixis->ver) == 1) /* Board version */ |
| 61 | pixel_format = 0x88882317; |
| 62 | temp |= PX_BRDCFG0_DVISEL; |
| 63 | name = "DVI"; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 64 | } |
| 65 | |
Timur Tabi | 32f709e | 2011-04-11 14:18:22 -0500 | [diff] [blame] | 66 | printf("DIU: Switching to %s monitor @ %ux%u\n", name, xres, yres); |
| 67 | out_8(&pixis->brdcfg0, temp); |
| 68 | |
Timur Tabi | 6d99ce2 | 2011-05-26 09:02:17 -0500 | [diff] [blame] | 69 | return fsl_diu_init(xres, yres, pixel_format, gamma_fix); |
York Sun | 59e7468 | 2007-10-31 14:59:04 -0500 | [diff] [blame] | 70 | } |