Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  *  valkyriefb.c -- frame buffer device for the PowerMac 'valkyrie' display
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  Created 8 August 1998 by 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Martin Costabel <costabel@wanadoo.fr> and Kevin Schoedel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  Vmode-switching changes and vmode 15/17 modifications created 29 August
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  1998 by Barry K. Nathan <barryn@pobox.com>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *  Ported to m68k Macintosh by David Huggins-Daines <dhd@debian.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *  Derived directly from:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *   controlfb.c -- frame buffer device for the PowerMac 'control' display
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *   Copyright (C) 1998 Dan Jacobowitz <dan@debian.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *   pmc-valkyrie.c -- Console support for PowerMac "valkyrie" display adaptor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *   Copyright (C) 1997 Paul Mackerras.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *  and indirectly:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *  Frame buffer structure from:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  *    drivers/video/chipsfb.c -- frame buffer device for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  *    Chips & Technologies 65550 chip.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  *    Copyright (C) 1998 Paul Mackerras
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *    This file is derived from the Powermac "chips" driver:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  *    Copyright (C) 1997 Fabio Riccardi.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  *    And from the frame buffer device for Open Firmware-initialized devices:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  *    Copyright (C) 1997 Geert Uytterhoeven.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  *  Hardware information from:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  *    control.c: Console support for PowerMac "control" display adaptor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  *    Copyright (C) 1996 Paul Mackerras
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  *  This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  *  License. See the file COPYING in the main directory of this archive for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  *  more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #include <linux/fb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #include <linux/selection.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #include <linux/nvram.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #include <linux/adb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #include <linux/cuda.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) #ifdef CONFIG_MAC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #include <asm/macintosh.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) #include <asm/prom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) #include "macmodes.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) #include "valkyriefb.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) static int default_vmode = VMODE_NVRAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) static int default_cmode = CMODE_NVRAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) struct fb_par_valkyrie {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	int	vmode, cmode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	int	xres, yres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	int	vxres, vyres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	struct valkyrie_regvals *init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) struct fb_info_valkyrie {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct fb_info		info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	struct fb_par_valkyrie	par;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	struct cmap_regs	__iomem *cmap_regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	unsigned long		cmap_regs_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	struct valkyrie_regs	__iomem *valkyrie_regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	unsigned long		valkyrie_regs_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	__u8			__iomem *frame_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	unsigned long		frame_buffer_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	int			sense;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	unsigned long		total_vram;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	u32			pseudo_palette[16];
^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)  * Exported functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) int valkyriefb_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) int valkyriefb_setup(char*);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static int valkyriefb_check_var(struct fb_var_screeninfo *var,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 				struct fb_info *info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static int valkyriefb_set_par(struct fb_info *info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static int valkyriefb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			     u_int transp, struct fb_info *info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static int valkyriefb_blank(int blank_mode, struct fb_info *info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static int read_valkyrie_sense(struct fb_info_valkyrie *p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static void set_valkyrie_clock(unsigned char *params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static int valkyrie_var_to_par(struct fb_var_screeninfo *var,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	struct fb_par_valkyrie *par, const struct fb_info *fb_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static int valkyrie_init_info(struct fb_info *info, struct fb_info_valkyrie *p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static void valkyrie_par_to_fix(struct fb_par_valkyrie *par, struct fb_fix_screeninfo *fix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static void valkyrie_init_fix(struct fb_fix_screeninfo *fix, struct fb_info_valkyrie *p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static const struct fb_ops valkyriefb_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	.owner =	THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	.fb_check_var =	valkyriefb_check_var,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	.fb_set_par =	valkyriefb_set_par,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	.fb_setcolreg =	valkyriefb_setcolreg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	.fb_blank =	valkyriefb_blank,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	.fb_fillrect	= cfb_fillrect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	.fb_copyarea	= cfb_copyarea,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	.fb_imageblit	= cfb_imageblit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /* Sets the video mode according to info->var */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static int valkyriefb_set_par(struct fb_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	struct fb_info_valkyrie *p =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		container_of(info, struct fb_info_valkyrie, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	volatile struct valkyrie_regs __iomem *valkyrie_regs = p->valkyrie_regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	struct fb_par_valkyrie *par = info->par;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	struct valkyrie_regvals	*init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	if ((err = valkyrie_var_to_par(&info->var, par, info)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	valkyrie_par_to_fix(par, &info->fix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	/* Reset the valkyrie */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	out_8(&valkyrie_regs->status.r, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	udelay(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	/* Initialize display timing registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	init = par->init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	out_8(&valkyrie_regs->mode.r, init->mode | 0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	out_8(&valkyrie_regs->depth.r, par->cmode + 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	set_valkyrie_clock(init->clock_params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	udelay(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	/* Turn on display */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	out_8(&valkyrie_regs->mode.r, init->mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static inline int valkyrie_par_to_var(struct fb_par_valkyrie *par,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 				      struct fb_var_screeninfo *var)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	return mac_vmode_to_var(par->vmode, par->cmode, var);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) valkyriefb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	struct fb_par_valkyrie par;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	if ((err = valkyrie_var_to_par(var, &par, info)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	valkyrie_par_to_var(&par, var);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)  *  Blank the screen if blank_mode != 0, else unblank. If blank_mode == NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)  *  then the caller blanks by setting the CLUT (Color Look Up Table) to all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  *  black. Return 0 if blanking succeeded, != 0 if un-/blanking failed due
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  *  to e.g. a video mode which doesn't support it. Implements VESA suspend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  *  and powerdown modes on hardware that supports disabling hsync/vsync:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  *    blank_mode == 2: suspend vsync
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  *    blank_mode == 3: suspend hsync
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)  *    blank_mode == 4: powerdown
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static int valkyriefb_blank(int blank_mode, struct fb_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	struct fb_info_valkyrie *p =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		container_of(info, struct fb_info_valkyrie, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	struct fb_par_valkyrie *par = info->par;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	struct valkyrie_regvals	*init = par->init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	if (init == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	switch (blank_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	case FB_BLANK_UNBLANK:			/* unblank */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		out_8(&p->valkyrie_regs->mode.r, init->mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	case FB_BLANK_NORMAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		return 1;	/* get caller to set CLUT to all black */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	case FB_BLANK_VSYNC_SUSPEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	case FB_BLANK_HSYNC_SUSPEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		 * [kps] Value extracted from MacOS. I don't know
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		 * whether this bit disables hsync or vsync, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		 * whether the hardware can do the other as well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		out_8(&p->valkyrie_regs->mode.r, init->mode | 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	case FB_BLANK_POWERDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		out_8(&p->valkyrie_regs->mode.r, 0x66);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) static int valkyriefb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 			     u_int transp, struct fb_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	struct fb_info_valkyrie *p =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		container_of(info, struct fb_info_valkyrie, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	volatile struct cmap_regs __iomem *cmap_regs = p->cmap_regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	struct fb_par_valkyrie *par = info->par;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	if (regno > 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	red >>= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	green >>= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	blue >>= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	/* tell clut which address to fill */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	out_8(&p->cmap_regs->addr, regno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	/* send one color channel at a time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	out_8(&cmap_regs->lut, red);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	out_8(&cmap_regs->lut, green);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	out_8(&cmap_regs->lut, blue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	if (regno < 16 && par->cmode == CMODE_16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		((u32 *)info->pseudo_palette)[regno] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 			(regno << 10) | (regno << 5) | regno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	return 0;
^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) static inline int valkyrie_vram_reqd(int video_mode, int color_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	int pitch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	struct valkyrie_regvals *init = valkyrie_reg_init[video_mode-1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	if ((pitch = init->pitch[color_mode]) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		pitch = 2 * init->pitch[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	return init->vres * pitch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static void set_valkyrie_clock(unsigned char *params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) #ifdef CONFIG_ADB_CUDA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	struct adb_request req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	for (i = 0; i < 3; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			     0x50, i + 1, params[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		while (!req.complete)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			cuda_poll();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) #endif
^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) static void __init valkyrie_choose_mode(struct fb_info_valkyrie *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	p->sense = read_valkyrie_sense(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	printk(KERN_INFO "Monitor sense value = 0x%x\n", p->sense);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	/* Try to pick a video mode out of NVRAM if we have one. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) #ifdef CONFIG_PPC_PMAC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	if (IS_REACHABLE(CONFIG_NVRAM) && default_vmode == VMODE_NVRAM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		default_vmode = nvram_read_byte(NV_VMODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	if (default_vmode <= 0 || default_vmode > VMODE_MAX ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	    !valkyrie_reg_init[default_vmode - 1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		default_vmode = mac_map_monitor_sense(p->sense);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		if (!valkyrie_reg_init[default_vmode - 1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 			default_vmode = VMODE_640_480_67;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) #ifdef CONFIG_PPC_PMAC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	if (IS_REACHABLE(CONFIG_NVRAM) && default_cmode == CMODE_NVRAM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		default_cmode = nvram_read_byte(NV_CMODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	 * Reduce the pixel size if we don't have enough VRAM or bandwidth.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	if (default_cmode < CMODE_8 || default_cmode > CMODE_16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	    || valkyrie_reg_init[default_vmode-1]->pitch[default_cmode] == 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	    || valkyrie_vram_reqd(default_vmode, default_cmode) > p->total_vram)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		default_cmode = CMODE_8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	printk(KERN_INFO "using video mode %d and color mode %d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	       default_vmode, default_cmode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) int __init valkyriefb_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	struct fb_info_valkyrie	*p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	unsigned long frame_buffer_phys, cmap_regs_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	char *option = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	if (fb_get_options("valkyriefb", &option))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	valkyriefb_setup(option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) #ifdef CONFIG_MAC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	if (!MACH_IS_MAC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	if (!(mac_bi_data.id == MAC_MODEL_Q630
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	      /* I'm not sure about this one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	    || mac_bi_data.id == MAC_MODEL_P588))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	/* Hardcoded addresses... welcome to 68k Macintosh country :-) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	frame_buffer_phys = 0xf9000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	cmap_regs_phys = 0x50f24000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) #else /* ppc (!CONFIG_MAC) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		struct device_node *dp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		struct resource r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		dp = of_find_node_by_name(NULL, "valkyrie");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		if (!dp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		if (of_address_to_resource(dp, 0, &r)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 			printk(KERN_ERR "can't find address for valkyrie\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		frame_buffer_phys = r.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		cmap_regs_phys = r.start + 0x304000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) #endif /* ppc (!CONFIG_MAC) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	p = kzalloc(sizeof(*p), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	/* Map in frame buffer and registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	if (!request_mem_region(frame_buffer_phys, 0x100000, "valkyriefb")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		kfree(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	p->total_vram = 0x100000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	p->frame_buffer_phys = frame_buffer_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) #ifdef CONFIG_MAC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	p->frame_buffer = ioremap(frame_buffer_phys, p->total_vram);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	p->frame_buffer = ioremap_wt(frame_buffer_phys, p->total_vram);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	p->cmap_regs_phys = cmap_regs_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	p->cmap_regs = ioremap(p->cmap_regs_phys, 0x1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	p->valkyrie_regs_phys = cmap_regs_phys+0x6000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	p->valkyrie_regs = ioremap(p->valkyrie_regs_phys, 0x1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	if (p->frame_buffer == NULL || p->cmap_regs == NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	    || p->valkyrie_regs == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		printk(KERN_ERR "valkyriefb: couldn't map resources\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		goto out_free;
^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) 	valkyrie_choose_mode(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	mac_vmode_to_var(default_vmode, default_cmode, &p->info.var);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	err = valkyrie_init_info(&p->info, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	valkyrie_init_fix(&p->info.fix, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	if (valkyriefb_set_par(&p->info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		/* "can't happen" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		printk(KERN_ERR "valkyriefb: can't set default video mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	if ((err = register_framebuffer(&p->info)) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		goto out_cmap_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	fb_info(&p->info, "valkyrie frame buffer device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)  out_cmap_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	fb_dealloc_cmap(&p->info.cmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)  out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	if (p->frame_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		iounmap(p->frame_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	if (p->cmap_regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		iounmap(p->cmap_regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	if (p->valkyrie_regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		iounmap(p->valkyrie_regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	kfree(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)  * Get the monitor sense value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) static int read_valkyrie_sense(struct fb_info_valkyrie *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	int sense, in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	out_8(&p->valkyrie_regs->msense.r, 0);   /* release all lines */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	__delay(20000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	sense = ((in = in_8(&p->valkyrie_regs->msense.r)) & 0x70) << 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	/* drive each sense line low in turn and collect the other 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	out_8(&p->valkyrie_regs->msense.r, 4);   /* drive A low */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	__delay(20000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	sense |= ((in = in_8(&p->valkyrie_regs->msense.r)) & 0x30);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	out_8(&p->valkyrie_regs->msense.r, 2);   /* drive B low */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	__delay(20000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	sense |= ((in = in_8(&p->valkyrie_regs->msense.r)) & 0x40) >> 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	sense |= (in & 0x10) >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	out_8(&p->valkyrie_regs->msense.r, 1);   /* drive C low */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	__delay(20000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	sense |= ((in = in_8(&p->valkyrie_regs->msense.r)) & 0x60) >> 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	out_8(&p->valkyrie_regs->msense.r, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	return sense;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)  * This routine takes a user-supplied var,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)  * and picks the best vmode/cmode from it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) /* [bkn] I did a major overhaul of this function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)  * Much of the old code was "swiped by jonh from atyfb.c". Because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)  * macmodes has mac_var_to_vmode, I felt that it would be better to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)  * rework this function to use that, instead of reinventing the wheel to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)  * add support for vmode 17. This was reinforced by the fact that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)  * the previously swiped atyfb.c code is no longer there.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)  * So, I swiped and adapted platinum_var_to_par (from platinumfb.c), replacing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)  * most, but not all, of the old code in the process. One side benefit of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)  * swiping the platinumfb code is that we now have more comprehensible error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)  * messages when a vmode/cmode switch fails. (Most of the error messages are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)  * platinumfb.c, but I added two of my own, and I also changed some commas
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)  * into colons to make the messages more consistent with other Linux error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)  * messages.) In addition, I think the new code *might* fix some vmode-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)  * switching oddities, but I'm not sure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)  * There may be some more opportunities for cleanup in here, but this is a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)  * good start...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) static int valkyrie_var_to_par(struct fb_var_screeninfo *var,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	struct fb_par_valkyrie *par, const struct fb_info *fb_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	int vmode, cmode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	struct valkyrie_regvals *init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	struct fb_info_valkyrie *p =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		container_of(fb_info, struct fb_info_valkyrie, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	if (mac_var_to_vmode(var, &vmode, &cmode) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 		printk(KERN_ERR "valkyriefb: can't do %dx%dx%d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		       var->xres, var->yres, var->bits_per_pixel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	/* Check if we know about the wanted video mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	if (vmode < 1 || vmode > VMODE_MAX || !valkyrie_reg_init[vmode-1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 		printk(KERN_ERR "valkyriefb: vmode %d not valid.\n", vmode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	if (cmode != CMODE_8 && cmode != CMODE_16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		printk(KERN_ERR "valkyriefb: cmode %d not valid.\n", cmode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	if (var->xres_virtual > var->xres || var->yres_virtual > var->yres
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	    || var->xoffset != 0 || var->yoffset != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	init = valkyrie_reg_init[vmode-1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	if (init->pitch[cmode] == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 		printk(KERN_ERR "valkyriefb: vmode %d does not support "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		       "cmode %d.\n", vmode, cmode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	if (valkyrie_vram_reqd(vmode, cmode) > p->total_vram) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 		printk(KERN_ERR "valkyriefb: not enough ram for vmode %d, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		       "cmode %d.\n", vmode, cmode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	par->vmode = vmode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	par->cmode = cmode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	par->init = init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	par->xres = var->xres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	par->yres = var->yres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	par->vxres = par->xres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	par->vyres = par->yres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) static void valkyrie_init_fix(struct fb_fix_screeninfo *fix, struct fb_info_valkyrie *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	memset(fix, 0, sizeof(*fix));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	strcpy(fix->id, "valkyrie");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	fix->mmio_start = p->valkyrie_regs_phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	fix->mmio_len = sizeof(struct valkyrie_regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	fix->type = FB_TYPE_PACKED_PIXELS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	fix->smem_start = p->frame_buffer_phys + 0x1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	fix->smem_len = p->total_vram;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	fix->type_aux = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	fix->ywrapstep = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	fix->ypanstep = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	fix->xpanstep = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) /* Fix must already be inited above */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) static void valkyrie_par_to_fix(struct fb_par_valkyrie *par,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	struct fb_fix_screeninfo *fix)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	fix->smem_len = valkyrie_vram_reqd(par->vmode, par->cmode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	fix->visual = (par->cmode == CMODE_8) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 		FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	fix->line_length = par->vxres << par->cmode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 		/* ywrapstep, xpanstep, ypanstep */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) static int __init valkyrie_init_info(struct fb_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 		struct fb_info_valkyrie *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	info->fbops = &valkyriefb_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	info->screen_base = p->frame_buffer + 0x1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	info->flags = FBINFO_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	info->pseudo_palette = p->pseudo_palette;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	info->par = &p->par;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	return fb_alloc_cmap(&info->cmap, 256, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)  * Parse user specified options (`video=valkyriefb:')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) int __init valkyriefb_setup(char *options)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	char *this_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	if (!options || !*options)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	while ((this_opt = strsep(&options, ",")) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 		if (!strncmp(this_opt, "vmode:", 6)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	    		int vmode = simple_strtoul(this_opt+6, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 			if (vmode > 0 && vmode <= VMODE_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 				default_vmode = vmode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 		else if (!strncmp(this_opt, "cmode:", 6)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 			int depth = simple_strtoul(this_opt+6, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 			switch (depth) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 			case 8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 				default_cmode = CMODE_8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 			case 15:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 			case 16:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 				default_cmode = CMODE_16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) module_init(valkyriefb_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) MODULE_LICENSE("GPL");