^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * linux/drivers/video/pmagb-b-fb.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * PMAGB-B TURBOchannel Smart Frame Buffer (SFB) card support,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * derived from:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * "HP300 Topcat framebuffer support (derived from macfb of all things)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Phil Blundell <philb@gnu.org> 1998", the original code can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * found in the file hpfb.c in the same directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * DECstation related code Copyright (C) 1999, 2000, 2001 by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Michael Engel <engel@unix-ag.org>,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Karsten Merker <merker@linuxtag.org> and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Harald Koerfgen.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Copyright (c) 2005, 2006 Maciej W. Rozycki
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * This file is subject to the terms and conditions of the GNU General
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * Public License. See the file COPYING in the main directory of this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * archive for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/fb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/tc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <video/pmagb-b-fb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct pmagbbfb_par {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) volatile void __iomem *mmio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) volatile void __iomem *smem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) volatile u32 __iomem *sfb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) volatile u32 __iomem *dac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) unsigned int osc0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) unsigned int osc1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) int slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static const struct fb_var_screeninfo pmagbbfb_defined = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) .bits_per_pixel = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) .red.length = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) .green.length = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) .blue.length = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) .activate = FB_ACTIVATE_NOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) .height = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) .width = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) .accel_flags = FB_ACCEL_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) .sync = FB_SYNC_ON_GREEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) .vmode = FB_VMODE_NONINTERLACED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static const struct fb_fix_screeninfo pmagbbfb_fix = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) .id = "PMAGB-BA",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) .smem_len = (2048 * 1024),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) .type = FB_TYPE_PACKED_PIXELS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) .visual = FB_VISUAL_PSEUDOCOLOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) .mmio_len = PMAGB_B_FBMEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static inline void sfb_write(struct pmagbbfb_par *par, unsigned int reg, u32 v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) writel(v, par->sfb + reg / 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static inline u32 sfb_read(struct pmagbbfb_par *par, unsigned int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return readl(par->sfb + reg / 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static inline void dac_write(struct pmagbbfb_par *par, unsigned int reg, u8 v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) writeb(v, par->dac + reg / 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) static inline u8 dac_read(struct pmagbbfb_par *par, unsigned int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) return readb(par->dac + reg / 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) static inline void gp0_write(struct pmagbbfb_par *par, u32 v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) writel(v, par->mmio + PMAGB_B_GP0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * Set the palette.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) static int pmagbbfb_setcolreg(unsigned int regno, unsigned int red,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) unsigned int green, unsigned int blue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) unsigned int transp, struct fb_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) struct pmagbbfb_par *par = info->par;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if (regno >= info->cmap.len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) red >>= 8; /* The cmap fields are 16 bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) green >>= 8; /* wide, but the hardware colormap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) blue >>= 8; /* registers are only 8 bits wide */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) dac_write(par, BT459_ADDR_LO, regno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) dac_write(par, BT459_ADDR_HI, 0x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) dac_write(par, BT459_CMAP, red);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) dac_write(par, BT459_CMAP, green);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) dac_write(par, BT459_CMAP, blue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static const struct fb_ops pmagbbfb_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) .fb_setcolreg = pmagbbfb_setcolreg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) .fb_fillrect = cfb_fillrect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) .fb_copyarea = cfb_copyarea,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) .fb_imageblit = cfb_imageblit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * Turn the hardware cursor off.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static void pmagbbfb_erase_cursor(struct fb_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct pmagbbfb_par *par = info->par;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) dac_write(par, BT459_ADDR_LO, 0x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) dac_write(par, BT459_ADDR_HI, 0x03);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) dac_write(par, BT459_DATA, 0x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * Set up screen parameters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static void pmagbbfb_screen_setup(struct fb_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct pmagbbfb_par *par = info->par;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) info->var.xres = ((sfb_read(par, SFB_REG_VID_HOR) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) SFB_VID_HOR_PIX_SHIFT) & SFB_VID_HOR_PIX_MASK) * 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) info->var.xres_virtual = info->var.xres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) info->var.yres = (sfb_read(par, SFB_REG_VID_VER) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) SFB_VID_VER_SL_SHIFT) & SFB_VID_VER_SL_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) info->var.yres_virtual = info->var.yres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) info->var.left_margin = ((sfb_read(par, SFB_REG_VID_HOR) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) SFB_VID_HOR_BP_SHIFT) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) SFB_VID_HOR_BP_MASK) * 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) info->var.right_margin = ((sfb_read(par, SFB_REG_VID_HOR) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) SFB_VID_HOR_FP_SHIFT) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) SFB_VID_HOR_FP_MASK) * 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) info->var.upper_margin = (sfb_read(par, SFB_REG_VID_VER) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) SFB_VID_VER_BP_SHIFT) & SFB_VID_VER_BP_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) info->var.lower_margin = (sfb_read(par, SFB_REG_VID_VER) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) SFB_VID_VER_FP_SHIFT) & SFB_VID_VER_FP_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) info->var.hsync_len = ((sfb_read(par, SFB_REG_VID_HOR) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) SFB_VID_HOR_SYN_SHIFT) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) SFB_VID_HOR_SYN_MASK) * 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) info->var.vsync_len = (sfb_read(par, SFB_REG_VID_VER) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) SFB_VID_VER_SYN_SHIFT) & SFB_VID_VER_SYN_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) info->fix.line_length = info->var.xres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * Determine oscillator configuration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) static void pmagbbfb_osc_setup(struct fb_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) static unsigned int pmagbbfb_freqs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 130808, 119843, 104000, 92980, 74370, 72800,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 69197, 66000, 65000, 50350, 36000, 32000, 25175
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct pmagbbfb_par *par = info->par;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) struct tc_bus *tbus = to_tc_dev(info->device)->bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) u32 count0 = 8, count1 = 8, counttc = 16 * 256 + 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) u32 freq0, freq1, freqtc = tc_get_speed(tbus) / 250;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) gp0_write(par, 0); /* select Osc0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) for (j = 0; j < 16; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) sfb_write(par, SFB_REG_TCCLK_COUNT, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) for (i = 0; i < 100; i++) { /* nominally max. 20.5us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (sfb_read(par, SFB_REG_TCCLK_COUNT) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) count0 += sfb_read(par, SFB_REG_VIDCLK_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) gp0_write(par, 1); /* select Osc1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) for (j = 0; j < 16; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) sfb_write(par, SFB_REG_TCCLK_COUNT, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) for (i = 0; i < 100; i++) { /* nominally max. 20.5us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (sfb_read(par, SFB_REG_TCCLK_COUNT) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) count1 += sfb_read(par, SFB_REG_VIDCLK_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) freq0 = (freqtc * count0 + counttc / 2) / counttc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) par->osc0 = freq0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) if (freq0 >= pmagbbfb_freqs[0] - (pmagbbfb_freqs[0] + 32) / 64 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) freq0 <= pmagbbfb_freqs[0] + (pmagbbfb_freqs[0] + 32) / 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) par->osc0 = pmagbbfb_freqs[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) freq1 = (par->osc0 * count1 + count0 / 2) / count0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) par->osc1 = freq1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) for (i = 0; i < ARRAY_SIZE(pmagbbfb_freqs); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (freq1 >= pmagbbfb_freqs[i] -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) (pmagbbfb_freqs[i] + 128) / 256 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) freq1 <= pmagbbfb_freqs[i] +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) (pmagbbfb_freqs[i] + 128) / 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) par->osc1 = pmagbbfb_freqs[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) if (par->osc0 - par->osc1 <= (par->osc0 + par->osc1 + 256) / 512 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) par->osc1 - par->osc0 <= (par->osc0 + par->osc1 + 256) / 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) par->osc1 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) gp0_write(par, par->osc1 != 0); /* reselect OscX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) info->var.pixclock = par->osc1 ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) (1000000000 + par->osc1 / 2) / par->osc1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) (1000000000 + par->osc0 / 2) / par->osc0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static int pmagbbfb_probe(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) struct tc_dev *tdev = to_tc_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) resource_size_t start, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) struct fb_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) struct pmagbbfb_par *par;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) char freq0[12], freq1[12];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) u32 vid_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) info = framebuffer_alloc(sizeof(struct pmagbbfb_par), dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) par = info->par;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) dev_set_drvdata(dev, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) printk(KERN_ERR "%s: Cannot allocate color map\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) dev_name(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) goto err_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) info->fbops = &pmagbbfb_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) info->fix = pmagbbfb_fix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) info->var = pmagbbfb_defined;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) info->flags = FBINFO_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) /* Request the I/O MEM resource. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) start = tdev->resource.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) len = tdev->resource.end - start + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) if (!request_mem_region(start, len, dev_name(dev))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) printk(KERN_ERR "%s: Cannot reserve FB region\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) dev_name(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) err = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) goto err_cmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) /* MMIO mapping setup. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) info->fix.mmio_start = start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) par->mmio = ioremap(info->fix.mmio_start, info->fix.mmio_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (!par->mmio) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) printk(KERN_ERR "%s: Cannot map MMIO\n", dev_name(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) goto err_resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) par->sfb = par->mmio + PMAGB_B_SFB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) par->dac = par->mmio + PMAGB_B_BT459;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) /* Frame buffer mapping setup. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) info->fix.smem_start = start + PMAGB_B_FBMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) par->smem = ioremap(info->fix.smem_start, info->fix.smem_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) if (!par->smem) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) printk(KERN_ERR "%s: Cannot map FB\n", dev_name(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) goto err_mmio_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) vid_base = sfb_read(par, SFB_REG_VID_BASE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) info->screen_base = (void __iomem *)par->smem + vid_base * 0x1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) info->screen_size = info->fix.smem_len - 2 * vid_base * 0x1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) pmagbbfb_erase_cursor(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) pmagbbfb_screen_setup(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) pmagbbfb_osc_setup(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) err = register_framebuffer(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) printk(KERN_ERR "%s: Cannot register framebuffer\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) dev_name(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) goto err_smem_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) get_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) snprintf(freq0, sizeof(freq0), "%u.%03uMHz",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) par->osc0 / 1000, par->osc0 % 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) snprintf(freq1, sizeof(freq1), "%u.%03uMHz",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) par->osc1 / 1000, par->osc1 % 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) fb_info(info, "%s frame buffer device at %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) info->fix.id, dev_name(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) fb_info(info, "Osc0: %s, Osc1: %s, Osc%u selected\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) freq0, par->osc1 ? freq1 : "disabled", par->osc1 != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) err_smem_map:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) iounmap(par->smem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) err_mmio_map:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) iounmap(par->mmio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) err_resource:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) release_mem_region(start, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) err_cmap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) fb_dealloc_cmap(&info->cmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) err_alloc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) framebuffer_release(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) static int pmagbbfb_remove(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) struct tc_dev *tdev = to_tc_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) struct fb_info *info = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) struct pmagbbfb_par *par = info->par;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) resource_size_t start, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) unregister_framebuffer(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) iounmap(par->smem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) iounmap(par->mmio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) start = tdev->resource.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) len = tdev->resource.end - start + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) release_mem_region(start, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) fb_dealloc_cmap(&info->cmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) framebuffer_release(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) * Initialize the framebuffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) static const struct tc_device_id pmagbbfb_tc_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) { "DEC ", "PMAGB-BA" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) MODULE_DEVICE_TABLE(tc, pmagbbfb_tc_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) static struct tc_driver pmagbbfb_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) .id_table = pmagbbfb_tc_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) .name = "pmagbbfb",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) .bus = &tc_bus_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) .probe = pmagbbfb_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) .remove = pmagbbfb_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) static int __init pmagbbfb_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) #ifndef MODULE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) if (fb_get_options("pmagbbfb", NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) return tc_register_driver(&pmagbbfb_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) static void __exit pmagbbfb_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) tc_unregister_driver(&pmagbbfb_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) module_init(pmagbbfb_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) module_exit(pmagbbfb_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) MODULE_LICENSE("GPL");