📄 matroxfb_g450.c
字号:
/* * * Hardware accelerated Matrox Millennium I, II, Mystique, G100, G200, G400 and G450. * * (c) 1998-2002 Petr Vandrovec <vandrove@vc.cvut.cz> * * Portions Copyright (c) 2001 Matrox Graphics Inc. * * Version: 1.64 2002/06/02 * * See matroxfb_base.c for contributors. * */#include "matroxfb_base.h"#include "matroxfb_misc.h"#include "matroxfb_DAC1064.h"#include "g450_pll.h"#include <linux/matroxfb.h>#include <asm/uaccess.h>#include <asm/div64.h>/* Definition of the various controls */struct mctl { struct matroxfb_queryctrl desc; size_t control;};#define BLMIN 0xF3#define WLMAX 0x3FFstatic const struct mctl g450_controls[] ={ { { MATROXFB_CID_BRIGHTNESS, "brightness", 0, WLMAX-BLMIN, 1, 370-BLMIN, MATROXFB_CTRL_TYPE_INTEGER, 0, 0, "picture" }, offsetof(struct matrox_fb_info, altout.tvo_params.brightness) }, { { MATROXFB_CID_CONTRAST, "contrast", 0, 1023, 1, 127, MATROXFB_CTRL_TYPE_INTEGER, 0, 0, "picture" }, offsetof(struct matrox_fb_info, altout.tvo_params.contrast) }, { { MATROXFB_CID_SATURATION, "saturation", 0, 255, 1, 165, MATROXFB_CTRL_TYPE_INTEGER, 0, 0, "picture" }, offsetof(struct matrox_fb_info, altout.tvo_params.saturation) }, { { MATROXFB_CID_HUE, "hue", 0, 255, 1, 0, MATROXFB_CTRL_TYPE_INTEGER, 0, 0, "picture" }, offsetof(struct matrox_fb_info, altout.tvo_params.hue) }, { { MATROXFB_CID_TESTOUT, "test output", 0, 1, 1, 0, MATROXFB_CTRL_TYPE_BOOLEAN, 0, 0, "picture" }, offsetof(struct matrox_fb_info, altout.tvo_params.testout) },};#define G450CTRLS (sizeof(g450_controls)/sizeof(g450_controls[0]))/* Return: positive number: id found -EINVAL: id not found, return failure -ENOENT: id not found, create fake disabled control */static int get_ctrl_id(__u32 v4l2_id) { int i; for (i = 0; i < G450CTRLS; i++) { if (v4l2_id < g450_controls[i].desc.id) { if (g450_controls[i].desc.id == 0x08000000) { return -EINVAL; } return -ENOENT; } if (v4l2_id == g450_controls[i].desc.id) { return i; } } return -EINVAL;}static inline int* get_ctrl_ptr(WPMINFO unsigned int idx) { return (int*)((char*)MINFO + g450_controls[idx].control);}static void tvo_fill_defaults(WPMINFO2) { unsigned int i; for (i = 0; i < G450CTRLS; i++) { *get_ctrl_ptr(PMINFO i) = g450_controls[i].desc.default_value; }}static int cve2_get_reg(WPMINFO int reg) { unsigned long flags; int val; matroxfb_DAC_lock_irqsave(flags); matroxfb_DAC_out(PMINFO 0x87, reg); val = matroxfb_DAC_in(PMINFO 0x88); matroxfb_DAC_unlock_irqrestore(flags); return val;}static void cve2_set_reg(WPMINFO int reg, int val) { unsigned long flags; matroxfb_DAC_lock_irqsave(flags); matroxfb_DAC_out(PMINFO 0x87, reg); matroxfb_DAC_out(PMINFO 0x88, val); matroxfb_DAC_unlock_irqrestore(flags);}static void cve2_set_reg10(WPMINFO int reg, int val) { unsigned long flags; matroxfb_DAC_lock_irqsave(flags); matroxfb_DAC_out(PMINFO 0x87, reg); matroxfb_DAC_out(PMINFO 0x88, val >> 2); matroxfb_DAC_out(PMINFO 0x87, reg + 1); matroxfb_DAC_out(PMINFO 0x88, val & 3); matroxfb_DAC_unlock_irqrestore(flags);}static void g450_compute_bwlevel(CPMINFO int *bl, int *wl) { const int b = ACCESS_FBINFO(altout.tvo_params.brightness) + BLMIN; const int c = ACCESS_FBINFO(altout.tvo_params.contrast); *bl = max(b - c, BLMIN); *wl = min(b + c, WLMAX);}static int g450_query_ctrl(void* md, struct matroxfb_queryctrl *p) { int i; i = get_ctrl_id(p->id); if (i >= 0) { *p = g450_controls[i].desc; return 0; } if (i == -ENOENT) { static const struct matroxfb_queryctrl disctrl = { 0, "", 0, 0, 0, 0, 0, 1, 1, "Disabled" }; i = p->id; *p = disctrl; p->id = i; sprintf(p->name, "Ctrl #%08X", i); return 0; } return -EINVAL;}static int g450_set_ctrl(void* md, struct matroxfb_control *p) { int i; MINFO_FROM(md); i = get_ctrl_id(p->id); if (i < 0) return -EINVAL; /* * Check if changed. */ if (p->value == *get_ctrl_ptr(PMINFO i)) return 0; /* * Check limits. */ if (p->value > g450_controls[i].desc.maximum) return -EINVAL; if (p->value < g450_controls[i].desc.minimum) return -EINVAL; /* * Store new value. */ *get_ctrl_ptr(PMINFO i) = p->value; switch (p->id) { case MATROXFB_CID_BRIGHTNESS: case MATROXFB_CID_CONTRAST: { int blacklevel, whitelevel; g450_compute_bwlevel(PMINFO &blacklevel, &whitelevel); cve2_set_reg10(PMINFO 0x0e, blacklevel); cve2_set_reg10(PMINFO 0x1e, whitelevel); } break; case MATROXFB_CID_SATURATION: cve2_set_reg(PMINFO 0x20, p->value); cve2_set_reg(PMINFO 0x22, p->value); break; case MATROXFB_CID_HUE: cve2_set_reg(PMINFO 0x25, p->value); break; case MATROXFB_CID_TESTOUT: { unsigned char val = cve2_get_reg (PMINFO 0x05); if (p->value) val |= 0x02; else val &= ~0x02; cve2_set_reg(PMINFO 0x05, val); } break; } return 0;}static int g450_get_ctrl(void* md, struct matroxfb_control *p) { int i; MINFO_FROM(md); i = get_ctrl_id(p->id); if (i < 0) return -EINVAL; p->value = *get_ctrl_ptr(PMINFO i); return 0;}struct output_desc { unsigned int h_vis; unsigned int h_f_porch; unsigned int h_sync; unsigned int h_b_porch; unsigned long long int chromasc; unsigned int burst; unsigned int v_total;};static void computeRegs(WPMINFO struct mavenregs* r, struct my_timming* mt, const struct output_desc* outd) { u_int32_t chromasc; u_int32_t hlen; u_int32_t hsl; u_int32_t hbp; u_int32_t hfp; u_int32_t hvis; unsigned int pixclock; unsigned long long piic; int mnp; int over; r->regs[0x80] = 0x03; /* | 0x40 for SCART */ hvis = ((mt->HDisplay << 1) + 3) & ~3; if (hvis >= 2048) { hvis = 2044; } piic = 1000000000ULL * hvis; do_div(piic, outd->h_vis); dprintk(KERN_DEBUG "Want %u kHz pixclock\n", (unsigned int)piic); mnp = matroxfb_g450_setclk(PMINFO piic, M_VIDEO_PLL); mt->mnp = mnp; mt->pixclock = g450_mnp2f(PMINFO mnp); dprintk(KERN_DEBUG "MNP=%08X\n", mnp); pixclock = 1000000000U / mt->pixclock; dprintk(KERN_DEBUG "Got %u ps pixclock\n", pixclock); piic = outd->chromasc; do_div(piic, mt->pixclock); chromasc = piic; dprintk(KERN_DEBUG "Chroma is %08X\n", chromasc); r->regs[0] = piic >> 24; r->regs[1] = piic >> 16; r->regs[2] = piic >> 8; r->regs[3] = piic >> 0; hbp = (((outd->h_b_porch + pixclock) / pixclock)) & ~1; hfp = (((outd->h_f_porch + pixclock) / pixclock)) & ~1; hsl = (((outd->h_sync + pixclock) / pixclock)) & ~1; hlen = hvis + hfp + hsl + hbp; over = hlen & 0x0F; dprintk(KERN_DEBUG "WL: vis=%u, hf=%u, hs=%u, hb=%u, total=%u\n", hvis, hfp, hsl, hbp, hlen); if (over) { hfp -= over; hlen -= over; if (over <= 2) { } else if (over < 10) { hfp += 4; hlen += 4; } else { hfp += 16; hlen += 16; } } /* maybe cve2 has requirement 800 < hlen < 1184 */ r->regs[0x08] = hsl; r->regs[0x09] = (outd->burst + pixclock - 1) / pixclock; /* burst length */ r->regs[0x0A] = hbp; r->regs[0x2C] = hfp; r->regs[0x31] = hvis / 8; r->regs[0x32] = hvis & 7; dprintk(KERN_DEBUG "PG: vis=%04X, hf=%02X, hs=%02X, hb=%02X, total=%04X\n", hvis, hfp, hsl, hbp, hlen); r->regs[0x84] = 1; /* x sync point */ r->regs[0x85] = 0; hvis = hvis >> 1; hlen = hlen >> 1; dprintk(KERN_DEBUG "hlen=%u hvis=%u\n", hlen, hvis); mt->interlaced = 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -