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