blob: acf20bf2d26c3b8f1257a8efdc817276fd57e84c [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
21#include "geodefb.h"
22#include "display_gx.h"
Andres Salomonab06aaf2008-04-28 02:14:58 -070023#include "gxfb.h"
David Vrabelfc4effc2006-03-27 01:17:23 -080024
Jordan Crouse4c1979c2006-12-08 02:40:52 -080025unsigned int gx_frame_buffer_size(void)
David Vrabelfc4effc2006-03-27 01:17:23 -080026{
Jordan Crouse4c1979c2006-12-08 02:40:52 -080027 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 Vrabelfc4effc2006-03-27 01:17:23 -080038}
39
40int 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
46static 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 Salomond2551142008-04-28 02:14:59 -070054 write_dc(par, DC_UNLOCK, DC_UNLOCK_UNLOCK);
David Vrabelfc4effc2006-03-27 01:17:23 -080055
Andres Salomonab06aaf2008-04-28 02:14:58 -070056 gcfg = read_dc(par, DC_GENERAL_CFG);
57 dcfg = read_dc(par, DC_DISPLAY_CFG);
David Vrabelfc4effc2006-03-27 01:17:23 -080058
59 /* Disable the timing generator. */
Andres Salomond2551142008-04-28 02:14:59 -070060 dcfg &= ~DC_DISPLAY_CFG_TGEN;
Andres Salomonab06aaf2008-04-28 02:14:58 -070061 write_dc(par, DC_DISPLAY_CFG, dcfg);
David Vrabelfc4effc2006-03-27 01:17:23 -080062
63 /* Wait for pending memory requests before disabling the FIFO load. */
64 udelay(100);
65
66 /* Disable FIFO load and compression. */
Andres Salomond2551142008-04-28 02:14:59 -070067 gcfg &= ~(DC_GENERAL_CFG_DFLE | DC_GENERAL_CFG_CMPE |
68 DC_GENERAL_CFG_DECE);
Andres Salomonab06aaf2008-04-28 02:14:58 -070069 write_dc(par, DC_GENERAL_CFG, gcfg);
David Vrabelfc4effc2006-03-27 01:17:23 -080070
71 /* Setup DCLK and its divisor. */
72 par->vid_ops->set_dclk(info);
73
74 /*
75 * Setup new mode.
76 */
77
78 /* Clear all unused feature bits. */
Andres Salomond2551142008-04-28 02:14:59 -070079 gcfg &= DC_GENERAL_CFG_YUVM | DC_GENERAL_CFG_VDSE;
David Vrabelfc4effc2006-03-27 01:17:23 -080080 dcfg = 0;
81
82 /* Set FIFO priority (default 6/5) and enable. */
83 /* FIXME: increase fifo priority for 1280x1024 and higher modes? */
Andres Salomond2551142008-04-28 02:14:59 -070084 gcfg |= (6 << DC_GENERAL_CFG_DFHPEL_SHIFT) |
85 (5 << DC_GENERAL_CFG_DFHPSL_SHIFT) | DC_GENERAL_CFG_DFLE;
David Vrabelfc4effc2006-03-27 01:17:23 -080086
87 /* Framebuffer start offset. */
Andres Salomonab06aaf2008-04-28 02:14:58 -070088 write_dc(par, DC_FB_ST_OFFSET, 0);
David Vrabelfc4effc2006-03-27 01:17:23 -080089
90 /* Line delta and line buffer length. */
Andres Salomonab06aaf2008-04-28 02:14:58 -070091 write_dc(par, DC_GFX_PITCH, info->fix.line_length >> 3);
92 write_dc(par, DC_LINE_SIZE,
93 ((info->var.xres * info->var.bits_per_pixel/8) >> 3) + 2);
David Vrabelfc4effc2006-03-27 01:17:23 -080094
Jordan Crousef3788192006-12-08 02:40:53 -080095
David Vrabelfc4effc2006-03-27 01:17:23 -080096 /* Enable graphics and video data and unmask address lines. */
Andres Salomond2551142008-04-28 02:14:59 -070097 dcfg |= DC_DISPLAY_CFG_GDEN | DC_DISPLAY_CFG_VDEN |
98 DC_DISPLAY_CFG_A20M | DC_DISPLAY_CFG_A18M;
David Vrabelfc4effc2006-03-27 01:17:23 -080099
100 /* Set pixel format. */
101 switch (info->var.bits_per_pixel) {
102 case 8:
Andres Salomond2551142008-04-28 02:14:59 -0700103 dcfg |= DC_DISPLAY_CFG_DISP_MODE_8BPP;
David Vrabelfc4effc2006-03-27 01:17:23 -0800104 break;
105 case 16:
Andres Salomond2551142008-04-28 02:14:59 -0700106 dcfg |= DC_DISPLAY_CFG_DISP_MODE_16BPP;
David Vrabelfc4effc2006-03-27 01:17:23 -0800107 break;
108 case 32:
Andres Salomond2551142008-04-28 02:14:59 -0700109 dcfg |= DC_DISPLAY_CFG_DISP_MODE_24BPP;
110 dcfg |= DC_DISPLAY_CFG_PALB;
David Vrabelfc4effc2006-03-27 01:17:23 -0800111 break;
112 }
113
114 /* Enable timing generator. */
Andres Salomond2551142008-04-28 02:14:59 -0700115 dcfg |= DC_DISPLAY_CFG_TGEN;
David Vrabelfc4effc2006-03-27 01:17:23 -0800116
117 /* Horizontal and vertical timings. */
118 hactive = info->var.xres;
119 hblankstart = hactive;
120 hsyncstart = hblankstart + info->var.right_margin;
121 hsyncend = hsyncstart + info->var.hsync_len;
122 hblankend = hsyncend + info->var.left_margin;
123 htotal = hblankend;
124
125 vactive = info->var.yres;
126 vblankstart = vactive;
127 vsyncstart = vblankstart + info->var.lower_margin;
128 vsyncend = vsyncstart + info->var.vsync_len;
129 vblankend = vsyncend + info->var.upper_margin;
130 vtotal = vblankend;
131
Andres Salomonab06aaf2008-04-28 02:14:58 -0700132 write_dc(par, DC_H_ACTIVE_TIMING, (hactive - 1) |
133 ((htotal - 1) << 16));
134 write_dc(par, DC_H_BLANK_TIMING, (hblankstart - 1) |
135 ((hblankend - 1) << 16));
136 write_dc(par, DC_H_SYNC_TIMING, (hsyncstart - 1) |
137 ((hsyncend - 1) << 16));
David Vrabelfc4effc2006-03-27 01:17:23 -0800138
Andres Salomonab06aaf2008-04-28 02:14:58 -0700139 write_dc(par, DC_V_ACTIVE_TIMING, (vactive - 1) |
140 ((vtotal - 1) << 16));
141 write_dc(par, DC_V_BLANK_TIMING, (vblankstart - 1) |
142 ((vblankend - 1) << 16));
143 write_dc(par, DC_V_SYNC_TIMING, (vsyncstart - 1) |
144 ((vsyncend - 1) << 16));
David Vrabelfc4effc2006-03-27 01:17:23 -0800145
146 /* Write final register values. */
Andres Salomonab06aaf2008-04-28 02:14:58 -0700147 write_dc(par, DC_DISPLAY_CFG, dcfg);
148 write_dc(par, DC_GENERAL_CFG, gcfg);
David Vrabelfc4effc2006-03-27 01:17:23 -0800149
150 par->vid_ops->configure_display(info);
151
152 /* Relock display controller registers */
Andres Salomond2551142008-04-28 02:14:59 -0700153 write_dc(par, DC_UNLOCK, DC_UNLOCK_LOCK);
David Vrabelfc4effc2006-03-27 01:17:23 -0800154}
155
156static void gx_set_hw_palette_reg(struct fb_info *info, unsigned regno,
157 unsigned red, unsigned green, unsigned blue)
158{
159 struct geodefb_par *par = info->par;
160 int val;
161
162 /* Hardware palette is in RGB 8-8-8 format. */
163 val = (red << 8) & 0xff0000;
164 val |= (green) & 0x00ff00;
165 val |= (blue >> 8) & 0x0000ff;
166
Andres Salomonab06aaf2008-04-28 02:14:58 -0700167 write_dc(par, DC_PAL_ADDRESS, regno);
168 write_dc(par, DC_PAL_DATA, val);
David Vrabelfc4effc2006-03-27 01:17:23 -0800169}
170
171struct geode_dc_ops gx_dc_ops = {
172 .set_mode = gx_set_mode,
173 .set_palette_reg = gx_set_hw_palette_reg,
174};