// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
* Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
* Copyright 2010 Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
*/
/*
* basic modesetting functions
*/
#include <linux/kernel.h>
#include <linux/via-core.h>
#include "via_modesetting.h"
#include "share.h"
#include "debug.h"
void via_set_primary_timing(const struct via_display_timing *timing)
{
struct via_display_timing raw;
raw.hor_total = timing->hor_total / 8 - 5 ;
raw.hor_addr = timing->hor_addr / 8 - 1 ;
raw.hor_blank_start = timing->hor_blank_start / 8 - 1 ;
raw.hor_blank_end = timing->hor_blank_end / 8 - 1 ;
raw.hor_sync_start = timing->hor_sync_start / 8 ;
raw.hor_sync_end = timing->hor_sync_end / 8 ;
raw.ver_total = timing->ver_total - 2 ;
raw.ver_addr = timing->ver_addr - 1 ;
raw.ver_blank_start = timing->ver_blank_start - 1 ;
raw.ver_blank_end = timing->ver_blank_end - 1 ;
raw.ver_sync_start = timing->ver_sync_start - 1 ;
raw.ver_sync_end = timing->ver_sync_end - 1 ;
/* unlock timing registers */
via_write_reg_mask(VIACR, 0 x11, 0 x00, 0 x80);
via_write_reg(VIACR, 0 x00, raw.hor_total & 0 xFF);
via_write_reg(VIACR, 0 x01, raw.hor_addr & 0 xFF);
via_write_reg(VIACR, 0 x02, raw.hor_blank_start & 0 xFF);
via_write_reg_mask(VIACR, 0 x03, raw.hor_blank_end & 0 x1F, 0 x1F);
via_write_reg(VIACR, 0 x04, raw.hor_sync_start & 0 xFF);
via_write_reg_mask(VIACR, 0 x05, (raw.hor_sync_end & 0 x1F)
| (raw.hor_blank_end << (7 - 5 ) & 0 x80), 0 x9F);
via_write_reg(VIACR, 0 x06, raw.ver_total & 0 xFF);
via_write_reg_mask(VIACR, 0 x07, (raw.ver_total >> 8 & 0 x01)
| (raw.ver_addr >> (8 - 1 ) & 0 x02)
| (raw.ver_sync_start >> (8 - 2 ) & 0 x04)
| (raw.ver_blank_start >> (8 - 3 ) & 0 x08)
| (raw.ver_total >> (9 - 5 ) & 0 x20)
| (raw.ver_addr >> (9 - 6 ) & 0 x40)
| (raw.ver_sync_start >> (9 - 7 ) & 0 x80), 0 xEF);
via_write_reg_mask(VIACR, 0 x09, raw.ver_blank_start >> (9 - 5 ) & 0 x20,
0 x20);
via_write_reg(VIACR, 0 x10, raw.ver_sync_start & 0 xFF);
via_write_reg_mask(VIACR, 0 x11, raw.ver_sync_end & 0 x0F, 0 x0F);
via_write_reg(VIACR, 0 x12, raw.ver_addr & 0 xFF);
via_write_reg(VIACR, 0 x15, raw.ver_blank_start & 0 xFF);
via_write_reg(VIACR, 0 x16, raw.ver_blank_end & 0 xFF);
via_write_reg_mask(VIACR, 0 x33, (raw.hor_sync_start >> (8 - 4 ) & 0 x10)
| (raw.hor_blank_end >> (6 - 5 ) & 0 x20), 0 x30);
via_write_reg_mask(VIACR, 0 x35, (raw.ver_total >> 10 & 0 x01)
| (raw.ver_sync_start >> (10 - 1 ) & 0 x02)
| (raw.ver_addr >> (10 - 2 ) & 0 x04)
| (raw.ver_blank_start >> (10 - 3 ) & 0 x08), 0 x0F);
via_write_reg_mask(VIACR, 0 x36, raw.hor_total >> (8 - 3 ) & 0 x08, 0 x08);
/* lock timing registers */
via_write_reg_mask(VIACR, 0 x11, 0 x80, 0 x80);
/* reset timing control */
via_write_reg_mask(VIACR, 0 x17, 0 x00, 0 x80);
via_write_reg_mask(VIACR, 0 x17, 0 x80, 0 x80);
}
void via_set_secondary_timing(const struct via_display_timing *timing)
{
struct via_display_timing raw;
raw.hor_total = timing->hor_total - 1 ;
raw.hor_addr = timing->hor_addr - 1 ;
raw.hor_blank_start = timing->hor_blank_start - 1 ;
raw.hor_blank_end = timing->hor_blank_end - 1 ;
raw.hor_sync_start = timing->hor_sync_start - 1 ;
raw.hor_sync_end = timing->hor_sync_end - 1 ;
raw.ver_total = timing->ver_total - 1 ;
raw.ver_addr = timing->ver_addr - 1 ;
raw.ver_blank_start = timing->ver_blank_start - 1 ;
raw.ver_blank_end = timing->ver_blank_end - 1 ;
raw.ver_sync_start = timing->ver_sync_start - 1 ;
raw.ver_sync_end = timing->ver_sync_end - 1 ;
via_write_reg(VIACR, 0 x50, raw.hor_total & 0 xFF);
via_write_reg(VIACR, 0 x51, raw.hor_addr & 0 xFF);
via_write_reg(VIACR, 0 x52, raw.hor_blank_start & 0 xFF);
via_write_reg(VIACR, 0 x53, raw.hor_blank_end & 0 xFF);
via_write_reg(VIACR, 0 x54, (raw.hor_blank_start >> 8 & 0 x07)
| (raw.hor_blank_end >> (8 - 3 ) & 0 x38)
| (raw.hor_sync_start >> (8 - 6 ) & 0 xC0));
via_write_reg_mask(VIACR, 0 x55, (raw.hor_total >> 8 & 0 x0F)
| (raw.hor_addr >> (8 - 4 ) & 0 x70), 0 x7F);
via_write_reg(VIACR, 0 x56, raw.hor_sync_start & 0 xFF);
via_write_reg(VIACR, 0 x57, raw.hor_sync_end & 0 xFF);
via_write_reg(VIACR, 0 x58, raw.ver_total & 0 xFF);
via_write_reg(VIACR, 0 x59, raw.ver_addr & 0 xFF);
via_write_reg(VIACR, 0 x5A, raw.ver_blank_start & 0 xFF);
via_write_reg(VIACR, 0 x5B, raw.ver_blank_end & 0 xFF);
via_write_reg(VIACR, 0 x5C, (raw.ver_blank_start >> 8 & 0 x07)
| (raw.ver_blank_end >> (8 - 3 ) & 0 x38)
| (raw.hor_sync_end >> (8 - 6 ) & 0 x40)
| (raw.hor_sync_start >> (10 - 7 ) & 0 x80));
via_write_reg(VIACR, 0 x5D, (raw.ver_total >> 8 & 0 x07)
| (raw.ver_addr >> (8 - 3 ) & 0 x38)
| (raw.hor_blank_end >> (11 - 6 ) & 0 x40)
| (raw.hor_sync_start >> (11 - 7 ) & 0 x80));
via_write_reg(VIACR, 0 x5E, raw.ver_sync_start & 0 xFF);
via_write_reg(VIACR, 0 x5F, (raw.ver_sync_end & 0 x1F)
| (raw.ver_sync_start >> (8 - 5 ) & 0 xE0));
}
void via_set_primary_address(u32 addr)
{
DEBUG_MSG(KERN_DEBUG "via_set_primary_address(0x%08X)\n" , addr);
via_write_reg(VIACR, 0 x0D, addr & 0 xFF);
via_write_reg(VIACR, 0 x0C, (addr >> 8 ) & 0 xFF);
via_write_reg(VIACR, 0 x34, (addr >> 16 ) & 0 xFF);
via_write_reg_mask(VIACR, 0 x48, (addr >> 24 ) & 0 x1F, 0 x1F);
}
void via_set_secondary_address(u32 addr)
{
DEBUG_MSG(KERN_DEBUG "via_set_secondary_address(0x%08X)\n" , addr);
/* secondary display supports only quadword aligned memory */
via_write_reg_mask(VIACR, 0 x62, (addr >> 2 ) & 0 xFE, 0 xFE);
via_write_reg(VIACR, 0 x63, (addr >> 10 ) & 0 xFF);
via_write_reg(VIACR, 0 x64, (addr >> 18 ) & 0 xFF);
via_write_reg_mask(VIACR, 0 xA3, (addr >> 26 ) & 0 x07, 0 x07);
}
void via_set_primary_pitch(u32 pitch)
{
DEBUG_MSG(KERN_DEBUG "via_set_primary_pitch(0x%08X)\n" , pitch);
/* spec does not say that first adapter skips 3 bits but old
* code did it and seems to be reasonable in analogy to 2nd adapter
*/
pitch = pitch >> 3 ;
via_write_reg(VIACR, 0 x13, pitch & 0 xFF);
via_write_reg_mask(VIACR, 0 x35, (pitch >> (8 - 5 )) & 0 xE0, 0 xE0);
}
void via_set_secondary_pitch(u32 pitch)
{
DEBUG_MSG(KERN_DEBUG "via_set_secondary_pitch(0x%08X)\n" , pitch);
pitch = pitch >> 3 ;
via_write_reg(VIACR, 0 x66, pitch & 0 xFF);
via_write_reg_mask(VIACR, 0 x67, (pitch >> 8 ) & 0 x03, 0 x03);
via_write_reg_mask(VIACR, 0 x71, (pitch >> (10 - 7 )) & 0 x80, 0 x80);
}
void via_set_primary_color_depth(u8 depth)
{
u8 value;
DEBUG_MSG(KERN_DEBUG "via_set_primary_color_depth(%d)\n" , depth);
switch (depth) {
case 8 :
value = 0 x00;
break ;
case 15 :
value = 0 x04;
break ;
case 16 :
value = 0 x14;
break ;
case 24 :
value = 0 x0C;
break ;
case 30 :
value = 0 x08;
break ;
default :
printk(KERN_WARNING "via_set_primary_color_depth: "
"Unsupported depth: %d\n" , depth);
return ;
}
via_write_reg_mask(VIASR, 0 x15, value, 0 x1C);
}
void via_set_secondary_color_depth(u8 depth)
{
u8 value;
DEBUG_MSG(KERN_DEBUG "via_set_secondary_color_depth(%d)\n" , depth);
switch (depth) {
case 8 :
value = 0 x00;
break ;
case 16 :
value = 0 x40;
break ;
case 24 :
value = 0 xC0;
break ;
case 30 :
value = 0 x80;
break ;
default :
printk(KERN_WARNING "via_set_secondary_color_depth: "
"Unsupported depth: %d\n" , depth);
return ;
}
via_write_reg_mask(VIACR, 0 x67, value, 0 xC0);
}
Messung V0.5 in Prozent C=96 H=94 G=94
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet am 2026-06-07)
¤
*© Formatika GbR, Deutschland