blob: 1e82ecc367dd259cf78863a6a32a5df6b65985f7 [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>
Andres Salomon61a517a2008-04-28 02:15:30 -070020#include <asm/geode.h>
David Vrabelfc4effc2006-03-27 01:17:23 -080021
Andres Salomonab06aaf2008-04-28 02:14:58 -070022#include "gxfb.h"
David Vrabelfc4effc2006-03-27 01:17:23 -080023
Jordan Crouse4c1979c2006-12-08 02:40:52 -080024unsigned int gx_frame_buffer_size(void)
David Vrabelfc4effc2006-03-27 01:17:23 -080025{
Jordan Crouse4c1979c2006-12-08 02:40:52 -080026 unsigned int val;
27
28 /* FB size is reported by a virtual register */
29 /* Virtual register class = 0x02 */
30 /* VG_MEM_SIZE(512Kb units) = 0x00 */
31
Andres Salomon61a517a2008-04-28 02:15:30 -070032 outw(VSA_VR_UNLOCK, VSA_VRC_INDEX);
33 outw(VSA_VR_MEM_SIZE, VSA_VRC_INDEX);
Jordan Crouse4c1979c2006-12-08 02:40:52 -080034
Andres Salomon61a517a2008-04-28 02:15:30 -070035 val = (unsigned int)(inw(VSA_VRC_DATA)) & 0xFFl;
Jordan Crouse4c1979c2006-12-08 02:40:52 -080036 return (val << 19);
David Vrabelfc4effc2006-03-27 01:17:23 -080037}
38
39int gx_line_delta(int xres, int bpp)
40{
41 /* Must be a multiple of 8 bytes. */
42 return (xres * (bpp >> 3) + 7) & ~0x7;
43}
44
Andres Salomond1b4cc32008-04-28 02:15:01 -070045void gx_set_mode(struct fb_info *info)
David Vrabelfc4effc2006-03-27 01:17:23 -080046{
Andres Salomond1b4cc32008-04-28 02:15:01 -070047 struct gxfb_par *par = info->par;
David Vrabelfc4effc2006-03-27 01:17:23 -080048 u32 gcfg, dcfg;
49 int hactive, hblankstart, hsyncstart, hsyncend, hblankend, htotal;
50 int vactive, vblankstart, vsyncstart, vsyncend, vblankend, vtotal;
51
52 /* Unlock the display controller registers. */
Andres Salomond2551142008-04-28 02:14:59 -070053 write_dc(par, DC_UNLOCK, DC_UNLOCK_UNLOCK);
David Vrabelfc4effc2006-03-27 01:17:23 -080054
Andres Salomonab06aaf2008-04-28 02:14:58 -070055 gcfg = read_dc(par, DC_GENERAL_CFG);
56 dcfg = read_dc(par, DC_DISPLAY_CFG);
David Vrabelfc4effc2006-03-27 01:17:23 -080057
58 /* Disable the timing generator. */
Andres Salomond2551142008-04-28 02:14:59 -070059 dcfg &= ~DC_DISPLAY_CFG_TGEN;
Andres Salomonab06aaf2008-04-28 02:14:58 -070060 write_dc(par, DC_DISPLAY_CFG, dcfg);
David Vrabelfc4effc2006-03-27 01:17:23 -080061
62 /* Wait for pending memory requests before disabling the FIFO load. */
63 udelay(100);
64
65 /* Disable FIFO load and compression. */
Andres Salomond2551142008-04-28 02:14:59 -070066 gcfg &= ~(DC_GENERAL_CFG_DFLE | DC_GENERAL_CFG_CMPE |
67 DC_GENERAL_CFG_DECE);
Andres Salomonab06aaf2008-04-28 02:14:58 -070068 write_dc(par, DC_GENERAL_CFG, gcfg);
David Vrabelfc4effc2006-03-27 01:17:23 -080069
70 /* Setup DCLK and its divisor. */
Andres Salomond1b4cc32008-04-28 02:15:01 -070071 gx_set_dclk_frequency(info);
David Vrabelfc4effc2006-03-27 01:17:23 -080072
73 /*
74 * Setup new mode.
75 */
76
77 /* Clear all unused feature bits. */
Andres Salomond2551142008-04-28 02:14:59 -070078 gcfg &= DC_GENERAL_CFG_YUVM | DC_GENERAL_CFG_VDSE;
David Vrabelfc4effc2006-03-27 01:17:23 -080079 dcfg = 0;
80
81 /* Set FIFO priority (default 6/5) and enable. */
82 /* FIXME: increase fifo priority for 1280x1024 and higher modes? */
Andres Salomond2551142008-04-28 02:14:59 -070083 gcfg |= (6 << DC_GENERAL_CFG_DFHPEL_SHIFT) |
84 (5 << DC_GENERAL_CFG_DFHPSL_SHIFT) | DC_GENERAL_CFG_DFLE;
David Vrabelfc4effc2006-03-27 01:17:23 -080085
86 /* Framebuffer start offset. */
Andres Salomonab06aaf2008-04-28 02:14:58 -070087 write_dc(par, DC_FB_ST_OFFSET, 0);
David Vrabelfc4effc2006-03-27 01:17:23 -080088
89 /* Line delta and line buffer length. */
Andres Salomonab06aaf2008-04-28 02:14:58 -070090 write_dc(par, DC_GFX_PITCH, info->fix.line_length >> 3);
91 write_dc(par, DC_LINE_SIZE,
92 ((info->var.xres * info->var.bits_per_pixel/8) >> 3) + 2);
David Vrabelfc4effc2006-03-27 01:17:23 -080093
Jordan Crousef3788192006-12-08 02:40:53 -080094
David Vrabelfc4effc2006-03-27 01:17:23 -080095 /* Enable graphics and video data and unmask address lines. */
Andres Salomond2551142008-04-28 02:14:59 -070096 dcfg |= DC_DISPLAY_CFG_GDEN | DC_DISPLAY_CFG_VDEN |
97 DC_DISPLAY_CFG_A20M | DC_DISPLAY_CFG_A18M;
David Vrabelfc4effc2006-03-27 01:17:23 -080098
99 /* Set pixel format. */
100 switch (info->var.bits_per_pixel) {
101 case 8:
Andres Salomond2551142008-04-28 02:14:59 -0700102 dcfg |= DC_DISPLAY_CFG_DISP_MODE_8BPP;
David Vrabelfc4effc2006-03-27 01:17:23 -0800103 break;
104 case 16:
Andres Salomond2551142008-04-28 02:14:59 -0700105 dcfg |= DC_DISPLAY_CFG_DISP_MODE_16BPP;
David Vrabelfc4effc2006-03-27 01:17:23 -0800106 break;
107 case 32:
Andres Salomond2551142008-04-28 02:14:59 -0700108 dcfg |= DC_DISPLAY_CFG_DISP_MODE_24BPP;
109 dcfg |= DC_DISPLAY_CFG_PALB;
David Vrabelfc4effc2006-03-27 01:17:23 -0800110 break;
111 }
112
113 /* Enable timing generator. */
Andres Salomond2551142008-04-28 02:14:59 -0700114 dcfg |= DC_DISPLAY_CFG_TGEN;
David Vrabelfc4effc2006-03-27 01:17:23 -0800115
116 /* Horizontal and vertical timings. */
117 hactive = info->var.xres;
118 hblankstart = hactive;
119 hsyncstart = hblankstart + info->var.right_margin;
120 hsyncend = hsyncstart + info->var.hsync_len;
121 hblankend = hsyncend + info->var.left_margin;
122 htotal = hblankend;
123
124 vactive = info->var.yres;
125 vblankstart = vactive;
126 vsyncstart = vblankstart + info->var.lower_margin;
127 vsyncend = vsyncstart + info->var.vsync_len;
128 vblankend = vsyncend + info->var.upper_margin;
129 vtotal = vblankend;
130
Andres Salomonab06aaf2008-04-28 02:14:58 -0700131 write_dc(par, DC_H_ACTIVE_TIMING, (hactive - 1) |
132 ((htotal - 1) << 16));
133 write_dc(par, DC_H_BLANK_TIMING, (hblankstart - 1) |
134 ((hblankend - 1) << 16));
135 write_dc(par, DC_H_SYNC_TIMING, (hsyncstart - 1) |
136 ((hsyncend - 1) << 16));
David Vrabelfc4effc2006-03-27 01:17:23 -0800137
Andres Salomonab06aaf2008-04-28 02:14:58 -0700138 write_dc(par, DC_V_ACTIVE_TIMING, (vactive - 1) |
139 ((vtotal - 1) << 16));
140 write_dc(par, DC_V_BLANK_TIMING, (vblankstart - 1) |
141 ((vblankend - 1) << 16));
142 write_dc(par, DC_V_SYNC_TIMING, (vsyncstart - 1) |
143 ((vsyncend - 1) << 16));
David Vrabelfc4effc2006-03-27 01:17:23 -0800144
145 /* Write final register values. */
Andres Salomonab06aaf2008-04-28 02:14:58 -0700146 write_dc(par, DC_DISPLAY_CFG, dcfg);
147 write_dc(par, DC_GENERAL_CFG, gcfg);
David Vrabelfc4effc2006-03-27 01:17:23 -0800148
Andres Salomond1b4cc32008-04-28 02:15:01 -0700149 gx_configure_display(info);
David Vrabelfc4effc2006-03-27 01:17:23 -0800150
151 /* Relock display controller registers */
Andres Salomond2551142008-04-28 02:14:59 -0700152 write_dc(par, DC_UNLOCK, DC_UNLOCK_LOCK);
David Vrabelfc4effc2006-03-27 01:17:23 -0800153}
154
Andres Salomond1b4cc32008-04-28 02:15:01 -0700155void gx_set_hw_palette_reg(struct fb_info *info, unsigned regno,
156 unsigned red, unsigned green, unsigned blue)
David Vrabelfc4effc2006-03-27 01:17:23 -0800157{
Andres Salomond1b4cc32008-04-28 02:15:01 -0700158 struct gxfb_par *par = info->par;
David Vrabelfc4effc2006-03-27 01:17:23 -0800159 int val;
160
161 /* Hardware palette is in RGB 8-8-8 format. */
162 val = (red << 8) & 0xff0000;
163 val |= (green) & 0x00ff00;
164 val |= (blue >> 8) & 0x0000ff;
165
Andres Salomonab06aaf2008-04-28 02:14:58 -0700166 write_dc(par, DC_PAL_ADDRESS, regno);
167 write_dc(par, DC_PAL_DATA, val);
David Vrabelfc4effc2006-03-27 01:17:23 -0800168}