David Vrabel | fc4effc | 2006-03-27 01:17:23 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Geode GX display controller. |
| 3 | * |
| 4 | * Copyright (C) 2005 Arcom Control Systems Ltd. |
| 5 | * |
| 6 | * Portions from AMD's original 2.4 driver: |
| 7 | * Copyright (C) 2004 Advanced Micro Devices, Inc. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License as published by * the |
| 11 | * Free Software Foundation; either version 2 of the License, or * (at your |
| 12 | * option) any later version. |
| 13 | */ |
| 14 | #include <linux/spinlock.h> |
| 15 | #include <linux/fb.h> |
| 16 | #include <linux/delay.h> |
| 17 | #include <asm/io.h> |
| 18 | #include <asm/div64.h> |
| 19 | #include <asm/delay.h> |
| 20 | |
| 21 | #include "geodefb.h" |
| 22 | #include "display_gx.h" |
Andres Salomon | ab06aaf | 2008-04-28 02:14:58 -0700 | [diff] [blame^] | 23 | #include "gxfb.h" |
David Vrabel | fc4effc | 2006-03-27 01:17:23 -0800 | [diff] [blame] | 24 | |
Jordan Crouse | 4c1979c | 2006-12-08 02:40:52 -0800 | [diff] [blame] | 25 | unsigned int gx_frame_buffer_size(void) |
David Vrabel | fc4effc | 2006-03-27 01:17:23 -0800 | [diff] [blame] | 26 | { |
Jordan Crouse | 4c1979c | 2006-12-08 02:40:52 -0800 | [diff] [blame] | 27 | unsigned int val; |
| 28 | |
| 29 | /* FB size is reported by a virtual register */ |
| 30 | /* Virtual register class = 0x02 */ |
| 31 | /* VG_MEM_SIZE(512Kb units) = 0x00 */ |
| 32 | |
| 33 | outw(0xFC53, 0xAC1C); |
| 34 | outw(0x0200, 0xAC1C); |
| 35 | |
| 36 | val = (unsigned int)(inw(0xAC1E)) & 0xFFl; |
| 37 | return (val << 19); |
David Vrabel | fc4effc | 2006-03-27 01:17:23 -0800 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | int gx_line_delta(int xres, int bpp) |
| 41 | { |
| 42 | /* Must be a multiple of 8 bytes. */ |
| 43 | return (xres * (bpp >> 3) + 7) & ~0x7; |
| 44 | } |
| 45 | |
| 46 | static void gx_set_mode(struct fb_info *info) |
| 47 | { |
| 48 | struct geodefb_par *par = info->par; |
| 49 | u32 gcfg, dcfg; |
| 50 | int hactive, hblankstart, hsyncstart, hsyncend, hblankend, htotal; |
| 51 | int vactive, vblankstart, vsyncstart, vsyncend, vblankend, vtotal; |
| 52 | |
| 53 | /* Unlock the display controller registers. */ |
Andres Salomon | ab06aaf | 2008-04-28 02:14:58 -0700 | [diff] [blame^] | 54 | write_dc(par, DC_UNLOCK, DC_UNLOCK_CODE); |
David Vrabel | fc4effc | 2006-03-27 01:17:23 -0800 | [diff] [blame] | 55 | |
Andres Salomon | ab06aaf | 2008-04-28 02:14:58 -0700 | [diff] [blame^] | 56 | gcfg = read_dc(par, DC_GENERAL_CFG); |
| 57 | dcfg = read_dc(par, DC_DISPLAY_CFG); |
David Vrabel | fc4effc | 2006-03-27 01:17:23 -0800 | [diff] [blame] | 58 | |
| 59 | /* Disable the timing generator. */ |
| 60 | dcfg &= ~(DC_DCFG_TGEN); |
Andres Salomon | ab06aaf | 2008-04-28 02:14:58 -0700 | [diff] [blame^] | 61 | write_dc(par, DC_DISPLAY_CFG, dcfg); |
David Vrabel | fc4effc | 2006-03-27 01:17:23 -0800 | [diff] [blame] | 62 | |
| 63 | /* Wait for pending memory requests before disabling the FIFO load. */ |
| 64 | udelay(100); |
| 65 | |
| 66 | /* Disable FIFO load and compression. */ |
| 67 | gcfg &= ~(DC_GCFG_DFLE | DC_GCFG_CMPE | DC_GCFG_DECE); |
Andres Salomon | ab06aaf | 2008-04-28 02:14:58 -0700 | [diff] [blame^] | 68 | write_dc(par, DC_GENERAL_CFG, gcfg); |
David Vrabel | fc4effc | 2006-03-27 01:17:23 -0800 | [diff] [blame] | 69 | |
| 70 | /* Setup DCLK and its divisor. */ |
| 71 | par->vid_ops->set_dclk(info); |
| 72 | |
| 73 | /* |
| 74 | * Setup new mode. |
| 75 | */ |
| 76 | |
| 77 | /* Clear all unused feature bits. */ |
| 78 | gcfg &= DC_GCFG_YUVM | DC_GCFG_VDSE; |
| 79 | dcfg = 0; |
| 80 | |
| 81 | /* Set FIFO priority (default 6/5) and enable. */ |
| 82 | /* FIXME: increase fifo priority for 1280x1024 and higher modes? */ |
| 83 | gcfg |= (6 << DC_GCFG_DFHPEL_POS) | (5 << DC_GCFG_DFHPSL_POS) | DC_GCFG_DFLE; |
| 84 | |
| 85 | /* Framebuffer start offset. */ |
Andres Salomon | ab06aaf | 2008-04-28 02:14:58 -0700 | [diff] [blame^] | 86 | write_dc(par, DC_FB_ST_OFFSET, 0); |
David Vrabel | fc4effc | 2006-03-27 01:17:23 -0800 | [diff] [blame] | 87 | |
| 88 | /* Line delta and line buffer length. */ |
Andres Salomon | ab06aaf | 2008-04-28 02:14:58 -0700 | [diff] [blame^] | 89 | write_dc(par, DC_GFX_PITCH, info->fix.line_length >> 3); |
| 90 | write_dc(par, DC_LINE_SIZE, |
| 91 | ((info->var.xres * info->var.bits_per_pixel/8) >> 3) + 2); |
David Vrabel | fc4effc | 2006-03-27 01:17:23 -0800 | [diff] [blame] | 92 | |
Jordan Crouse | f378819 | 2006-12-08 02:40:53 -0800 | [diff] [blame] | 93 | |
David Vrabel | fc4effc | 2006-03-27 01:17:23 -0800 | [diff] [blame] | 94 | /* Enable graphics and video data and unmask address lines. */ |
| 95 | dcfg |= DC_DCFG_GDEN | DC_DCFG_VDEN | DC_DCFG_A20M | DC_DCFG_A18M; |
| 96 | |
| 97 | /* Set pixel format. */ |
| 98 | switch (info->var.bits_per_pixel) { |
| 99 | case 8: |
| 100 | dcfg |= DC_DCFG_DISP_MODE_8BPP; |
| 101 | break; |
| 102 | case 16: |
| 103 | dcfg |= DC_DCFG_DISP_MODE_16BPP; |
| 104 | dcfg |= DC_DCFG_16BPP_MODE_565; |
| 105 | break; |
| 106 | case 32: |
| 107 | dcfg |= DC_DCFG_DISP_MODE_24BPP; |
| 108 | dcfg |= DC_DCFG_PALB; |
| 109 | break; |
| 110 | } |
| 111 | |
| 112 | /* Enable timing generator. */ |
| 113 | dcfg |= DC_DCFG_TGEN; |
| 114 | |
| 115 | /* Horizontal and vertical timings. */ |
| 116 | hactive = info->var.xres; |
| 117 | hblankstart = hactive; |
| 118 | hsyncstart = hblankstart + info->var.right_margin; |
| 119 | hsyncend = hsyncstart + info->var.hsync_len; |
| 120 | hblankend = hsyncend + info->var.left_margin; |
| 121 | htotal = hblankend; |
| 122 | |
| 123 | vactive = info->var.yres; |
| 124 | vblankstart = vactive; |
| 125 | vsyncstart = vblankstart + info->var.lower_margin; |
| 126 | vsyncend = vsyncstart + info->var.vsync_len; |
| 127 | vblankend = vsyncend + info->var.upper_margin; |
| 128 | vtotal = vblankend; |
| 129 | |
Andres Salomon | ab06aaf | 2008-04-28 02:14:58 -0700 | [diff] [blame^] | 130 | write_dc(par, DC_H_ACTIVE_TIMING, (hactive - 1) | |
| 131 | ((htotal - 1) << 16)); |
| 132 | write_dc(par, DC_H_BLANK_TIMING, (hblankstart - 1) | |
| 133 | ((hblankend - 1) << 16)); |
| 134 | write_dc(par, DC_H_SYNC_TIMING, (hsyncstart - 1) | |
| 135 | ((hsyncend - 1) << 16)); |
David Vrabel | fc4effc | 2006-03-27 01:17:23 -0800 | [diff] [blame] | 136 | |
Andres Salomon | ab06aaf | 2008-04-28 02:14:58 -0700 | [diff] [blame^] | 137 | write_dc(par, DC_V_ACTIVE_TIMING, (vactive - 1) | |
| 138 | ((vtotal - 1) << 16)); |
| 139 | write_dc(par, DC_V_BLANK_TIMING, (vblankstart - 1) | |
| 140 | ((vblankend - 1) << 16)); |
| 141 | write_dc(par, DC_V_SYNC_TIMING, (vsyncstart - 1) | |
| 142 | ((vsyncend - 1) << 16)); |
David Vrabel | fc4effc | 2006-03-27 01:17:23 -0800 | [diff] [blame] | 143 | |
| 144 | /* Write final register values. */ |
Andres Salomon | ab06aaf | 2008-04-28 02:14:58 -0700 | [diff] [blame^] | 145 | write_dc(par, DC_DISPLAY_CFG, dcfg); |
| 146 | write_dc(par, DC_GENERAL_CFG, gcfg); |
David Vrabel | fc4effc | 2006-03-27 01:17:23 -0800 | [diff] [blame] | 147 | |
| 148 | par->vid_ops->configure_display(info); |
| 149 | |
| 150 | /* Relock display controller registers */ |
Andres Salomon | ab06aaf | 2008-04-28 02:14:58 -0700 | [diff] [blame^] | 151 | write_dc(par, DC_UNLOCK, 0); |
David Vrabel | fc4effc | 2006-03-27 01:17:23 -0800 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | static void gx_set_hw_palette_reg(struct fb_info *info, unsigned regno, |
| 155 | unsigned red, unsigned green, unsigned blue) |
| 156 | { |
| 157 | struct geodefb_par *par = info->par; |
| 158 | int val; |
| 159 | |
| 160 | /* Hardware palette is in RGB 8-8-8 format. */ |
| 161 | val = (red << 8) & 0xff0000; |
| 162 | val |= (green) & 0x00ff00; |
| 163 | val |= (blue >> 8) & 0x0000ff; |
| 164 | |
Andres Salomon | ab06aaf | 2008-04-28 02:14:58 -0700 | [diff] [blame^] | 165 | write_dc(par, DC_PAL_ADDRESS, regno); |
| 166 | write_dc(par, DC_PAL_DATA, val); |
David Vrabel | fc4effc | 2006-03-27 01:17:23 -0800 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | struct geode_dc_ops gx_dc_ops = { |
| 170 | .set_mode = gx_set_mode, |
| 171 | .set_palette_reg = gx_set_hw_palette_reg, |
| 172 | }; |