blob: 3743c8766a08b8c0df5a5962e49813d22bd7804a [file] [log] [blame]
David Vrabelfc4effc2006-03-27 01:17:23 -08001/*
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
Andres Salomonab06aaf2008-04-28 02:14:58 -070021#include "gxfb.h"
David Vrabelfc4effc2006-03-27 01:17:23 -080022
Jordan Crouse4c1979c2006-12-08 02:40:52 -080023unsigned int gx_frame_buffer_size(void)
David Vrabelfc4effc2006-03-27 01:17:23 -080024{
Jordan Crouse4c1979c2006-12-08 02:40:52 -080025 unsigned int val;
26
27 /* FB size is reported by a virtual register */
28 /* Virtual register class = 0x02 */
29 /* VG_MEM_SIZE(512Kb units) = 0x00 */
30
31 outw(0xFC53, 0xAC1C);
32 outw(0x0200, 0xAC1C);
33
34 val = (unsigned int)(inw(0xAC1E)) & 0xFFl;
35 return (val << 19);
David Vrabelfc4effc2006-03-27 01:17:23 -080036}
37
38int gx_line_delta(int xres, int bpp)
39{
40 /* Must be a multiple of 8 bytes. */
41 return (xres * (bpp >> 3) + 7) & ~0x7;
42}
43
Andres Salomond1b4cc32008-04-28 02:15:01 -070044void gx_set_mode(struct fb_info *info)
David Vrabelfc4effc2006-03-27 01:17:23 -080045{
Andres Salomond1b4cc32008-04-28 02:15:01 -070046 struct gxfb_par *par = info->par;
David Vrabelfc4effc2006-03-27 01:17:23 -080047 u32 gcfg, dcfg;
48 int hactive, hblankstart, hsyncstart, hsyncend, hblankend, htotal;
49 int vactive, vblankstart, vsyncstart, vsyncend, vblankend, vtotal;
50
51 /* Unlock the display controller registers. */
Andres Salomond2551142008-04-28 02:14:59 -070052 write_dc(par, DC_UNLOCK, DC_UNLOCK_UNLOCK);
David Vrabelfc4effc2006-03-27 01:17:23 -080053
Andres Salomonab06aaf2008-04-28 02:14:58 -070054 gcfg = read_dc(par, DC_GENERAL_CFG);
55 dcfg = read_dc(par, DC_DISPLAY_CFG);
David Vrabelfc4effc2006-03-27 01:17:23 -080056
57 /* Disable the timing generator. */
Andres Salomond2551142008-04-28 02:14:59 -070058 dcfg &= ~DC_DISPLAY_CFG_TGEN;
Andres Salomonab06aaf2008-04-28 02:14:58 -070059 write_dc(par, DC_DISPLAY_CFG, dcfg);
David Vrabelfc4effc2006-03-27 01:17:23 -080060
61 /* Wait for pending memory requests before disabling the FIFO load. */
62 udelay(100);
63
64 /* Disable FIFO load and compression. */
Andres Salomond2551142008-04-28 02:14:59 -070065 gcfg &= ~(DC_GENERAL_CFG_DFLE | DC_GENERAL_CFG_CMPE |
66 DC_GENERAL_CFG_DECE);
Andres Salomonab06aaf2008-04-28 02:14:58 -070067 write_dc(par, DC_GENERAL_CFG, gcfg);
David Vrabelfc4effc2006-03-27 01:17:23 -080068
69 /* Setup DCLK and its divisor. */
Andres Salomond1b4cc32008-04-28 02:15:01 -070070 gx_set_dclk_frequency(info);
David Vrabelfc4effc2006-03-27 01:17:23 -080071
72 /*
73 * Setup new mode.
74 */
75
76 /* Clear all unused feature bits. */
Andres Salomond2551142008-04-28 02:14:59 -070077 gcfg &= DC_GENERAL_CFG_YUVM | DC_GENERAL_CFG_VDSE;
David Vrabelfc4effc2006-03-27 01:17:23 -080078 dcfg = 0;
79
80 /* Set FIFO priority (default 6/5) and enable. */
81 /* FIXME: increase fifo priority for 1280x1024 and higher modes? */
Andres Salomond2551142008-04-28 02:14:59 -070082 gcfg |= (6 << DC_GENERAL_CFG_DFHPEL_SHIFT) |
83 (5 << DC_GENERAL_CFG_DFHPSL_SHIFT) | DC_GENERAL_CFG_DFLE;
David Vrabelfc4effc2006-03-27 01:17:23 -080084
85 /* Framebuffer start offset. */
Andres Salomonab06aaf2008-04-28 02:14:58 -070086 write_dc(par, DC_FB_ST_OFFSET, 0);
David Vrabelfc4effc2006-03-27 01:17:23 -080087
88 /* Line delta and line buffer length. */
Andres Salomonab06aaf2008-04-28 02:14:58 -070089 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 Vrabelfc4effc2006-03-27 01:17:23 -080092
Jordan Crousef3788192006-12-08 02:40:53 -080093
David Vrabelfc4effc2006-03-27 01:17:23 -080094 /* Enable graphics and video data and unmask address lines. */
Andres Salomond2551142008-04-28 02:14:59 -070095 dcfg |= DC_DISPLAY_CFG_GDEN | DC_DISPLAY_CFG_VDEN |
96 DC_DISPLAY_CFG_A20M | DC_DISPLAY_CFG_A18M;
David Vrabelfc4effc2006-03-27 01:17:23 -080097
98 /* Set pixel format. */
99 switch (info->var.bits_per_pixel) {
100 case 8:
Andres Salomond2551142008-04-28 02:14:59 -0700101 dcfg |= DC_DISPLAY_CFG_DISP_MODE_8BPP;
David Vrabelfc4effc2006-03-27 01:17:23 -0800102 break;
103 case 16:
Andres Salomond2551142008-04-28 02:14:59 -0700104 dcfg |= DC_DISPLAY_CFG_DISP_MODE_16BPP;
David Vrabelfc4effc2006-03-27 01:17:23 -0800105 break;
106 case 32:
Andres Salomond2551142008-04-28 02:14:59 -0700107 dcfg |= DC_DISPLAY_CFG_DISP_MODE_24BPP;
108 dcfg |= DC_DISPLAY_CFG_PALB;
David Vrabelfc4effc2006-03-27 01:17:23 -0800109 break;
110 }
111
112 /* Enable timing generator. */
Andres Salomond2551142008-04-28 02:14:59 -0700113 dcfg |= DC_DISPLAY_CFG_TGEN;
David Vrabelfc4effc2006-03-27 01:17:23 -0800114
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 Salomonab06aaf2008-04-28 02:14:58 -0700130 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 Vrabelfc4effc2006-03-27 01:17:23 -0800136
Andres Salomonab06aaf2008-04-28 02:14:58 -0700137 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 Vrabelfc4effc2006-03-27 01:17:23 -0800143
144 /* Write final register values. */
Andres Salomonab06aaf2008-04-28 02:14:58 -0700145 write_dc(par, DC_DISPLAY_CFG, dcfg);
146 write_dc(par, DC_GENERAL_CFG, gcfg);
David Vrabelfc4effc2006-03-27 01:17:23 -0800147
Andres Salomond1b4cc32008-04-28 02:15:01 -0700148 gx_configure_display(info);
David Vrabelfc4effc2006-03-27 01:17:23 -0800149
150 /* Relock display controller registers */
Andres Salomond2551142008-04-28 02:14:59 -0700151 write_dc(par, DC_UNLOCK, DC_UNLOCK_LOCK);
David Vrabelfc4effc2006-03-27 01:17:23 -0800152}
153
Andres Salomond1b4cc32008-04-28 02:15:01 -0700154void gx_set_hw_palette_reg(struct fb_info *info, unsigned regno,
155 unsigned red, unsigned green, unsigned blue)
David Vrabelfc4effc2006-03-27 01:17:23 -0800156{
Andres Salomond1b4cc32008-04-28 02:15:01 -0700157 struct gxfb_par *par = info->par;
David Vrabelfc4effc2006-03-27 01:17:23 -0800158 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 Salomonab06aaf2008-04-28 02:14:58 -0700165 write_dc(par, DC_PAL_ADDRESS, regno);
166 write_dc(par, DC_PAL_DATA, val);
David Vrabelfc4effc2006-03-27 01:17:23 -0800167}