York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2007 Freescale Semiconductor, Inc. |
| 3 | * York Sun <yorksun@freescale.com> |
| 4 | * |
| 5 | * FSL DIU Framebuffer driver |
| 6 | * |
| 7 | * See file CREDITS for list of people who contributed to this |
| 8 | * project. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of |
| 13 | * the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 23 | * MA 02111-1307 USA |
| 24 | */ |
| 25 | |
| 26 | #include <common.h> |
| 27 | #include <command.h> |
| 28 | #include <asm/io.h> |
Anatolij Gustschin | 43ffc53 | 2010-09-24 01:06:37 +0200 | [diff] [blame^] | 29 | #include <fsl_diu_fb.h> |
York Sun | 59e7468 | 2007-10-31 14:59:04 -0500 | [diff] [blame] | 30 | |
York Sun | c496438 | 2008-05-05 10:19:59 -0500 | [diff] [blame] | 31 | void diu_set_pixel_clock(unsigned int pixclock) |
| 32 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 33 | volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
York Sun | c496438 | 2008-05-05 10:19:59 -0500 | [diff] [blame] | 34 | volatile ccsr_gur_t *gur = &immap->im_gur; |
| 35 | volatile unsigned int *guts_clkdvdr = &gur->clkdvdr; |
| 36 | unsigned long speed_ccb, temp, pixval; |
| 37 | |
| 38 | speed_ccb = get_bus_freq(0); |
| 39 | temp = 1000000000/pixclock; |
| 40 | temp *= 1000; |
| 41 | pixval = speed_ccb / temp; |
| 42 | debug("DIU pixval = %lu\n", pixval); |
| 43 | |
| 44 | /* Modify PXCLK in GUTS CLKDVDR */ |
| 45 | debug("DIU: Current value of CLKDVDR = 0x%08x\n", *guts_clkdvdr); |
| 46 | temp = *guts_clkdvdr & 0x2000FFFF; |
| 47 | *guts_clkdvdr = temp; /* turn off clock */ |
| 48 | *guts_clkdvdr = temp | 0x80000000 | ((pixval & 0x1F) << 16); |
| 49 | debug("DIU: Modified value of CLKDVDR = 0x%08x\n", *guts_clkdvdr); |
| 50 | } |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 51 | |
Anatolij Gustschin | 43ffc53 | 2010-09-24 01:06:37 +0200 | [diff] [blame^] | 52 | int platform_diu_init(unsigned int *xres, unsigned int *yres) |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 53 | { |
| 54 | char *monitor_port; |
York Sun | 59e7468 | 2007-10-31 14:59:04 -0500 | [diff] [blame] | 55 | int gamma_fix; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 56 | unsigned int pixel_format; |
| 57 | unsigned char tmp_val; |
York Sun | 59e7468 | 2007-10-31 14:59:04 -0500 | [diff] [blame] | 58 | unsigned char pixis_arch; |
Kumar Gala | 146c4b2 | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 59 | u8 *pixis_base = (u8 *)PIXIS_BASE; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 60 | |
Kumar Gala | 146c4b2 | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 61 | tmp_val = in_8(pixis_base + PIXIS_BRDCFG0); |
| 62 | pixis_arch = in_8(pixis_base + PIXIS_VER); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 63 | |
York Sun | 59e7468 | 2007-10-31 14:59:04 -0500 | [diff] [blame] | 64 | monitor_port = getenv("monitor"); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 65 | if (!strncmp(monitor_port, "0", 1)) { /* 0 - DVI */ |
Anatolij Gustschin | 43ffc53 | 2010-09-24 01:06:37 +0200 | [diff] [blame^] | 66 | *xres = 1280; |
| 67 | *yres = 1024; |
York Sun | 59e7468 | 2007-10-31 14:59:04 -0500 | [diff] [blame] | 68 | if (pixis_arch == 0x01) |
| 69 | pixel_format = 0x88882317; |
| 70 | else |
| 71 | pixel_format = 0x88883316; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 72 | gamma_fix = 0; |
Kumar Gala | 146c4b2 | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 73 | out_8(pixis_base + PIXIS_BRDCFG0, tmp_val | 0x08); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 74 | |
| 75 | } else if (!strncmp(monitor_port, "1", 1)) { /* 1 - Single link LVDS */ |
Anatolij Gustschin | 43ffc53 | 2010-09-24 01:06:37 +0200 | [diff] [blame^] | 76 | *xres = 1024; |
| 77 | *yres = 768; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 78 | pixel_format = 0x88883316; |
| 79 | gamma_fix = 0; |
Kumar Gala | 146c4b2 | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 80 | out_8(pixis_base + PIXIS_BRDCFG0, (tmp_val & 0xf7) | 0x10); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 81 | |
| 82 | } else if (!strncmp(monitor_port, "2", 1)) { /* 2 - Double link LVDS */ |
Anatolij Gustschin | 43ffc53 | 2010-09-24 01:06:37 +0200 | [diff] [blame^] | 83 | *xres = 1280; |
| 84 | *yres = 1024; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 85 | pixel_format = 0x88883316; |
| 86 | gamma_fix = 1; |
Kumar Gala | 146c4b2 | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 87 | out_8(pixis_base + PIXIS_BRDCFG0, tmp_val & 0xe7); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 88 | |
| 89 | } else { /* DVI */ |
Anatolij Gustschin | 43ffc53 | 2010-09-24 01:06:37 +0200 | [diff] [blame^] | 90 | *xres = 1280; |
| 91 | *yres = 1024; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 92 | pixel_format = 0x88882317; |
| 93 | gamma_fix = 0; |
Kumar Gala | 146c4b2 | 2009-07-22 10:12:39 -0500 | [diff] [blame] | 94 | out_8(pixis_base + PIXIS_BRDCFG0, tmp_val | 0x08); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 95 | } |
| 96 | |
Anatolij Gustschin | 43ffc53 | 2010-09-24 01:06:37 +0200 | [diff] [blame^] | 97 | return fsl_diu_init(*xres, pixel_format, gamma_fix); |
York Sun | 59e7468 | 2007-10-31 14:59:04 -0500 | [diff] [blame] | 98 | } |