PageRenderTime 55ms CodeModel.GetById 10ms app.highlight 36ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/video/q40fb.c

https://bitbucket.org/abioy/linux
C | 157 lines | 115 code | 25 blank | 17 comment | 9 complexity | e0b4fb0de624be2d282da4a21bf341f1 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, GPL-2.0, LGPL-2.0, AGPL-1.0
  1/*
  2 * linux/drivers/video/q40fb.c -- Q40 frame buffer device
  3 *
  4 * Copyright (C) 2001
  5 *
  6 *      Richard Zidlicky <rz@linux-m68k.org>
  7 *
  8 *  This file is subject to the terms and conditions of the GNU General Public
  9 *  License. See the file COPYING in the main directory of this archive for
 10 *  more details.
 11 */
 12
 13#include <linux/kernel.h>
 14#include <linux/errno.h>
 15#include <linux/string.h>
 16#include <linux/mm.h>
 17#include <linux/delay.h>
 18#include <linux/interrupt.h>
 19#include <linux/platform_device.h>
 20
 21#include <asm/uaccess.h>
 22#include <asm/setup.h>
 23#include <asm/system.h>
 24#include <asm/q40_master.h>
 25#include <linux/fb.h>
 26#include <linux/module.h>
 27#include <asm/pgtable.h>
 28
 29#define Q40_PHYS_SCREEN_ADDR 0xFE800000
 30
 31static struct fb_fix_screeninfo q40fb_fix __initdata = {
 32	.id		= "Q40",
 33	.smem_len	= 1024*1024,
 34	.type		= FB_TYPE_PACKED_PIXELS,
 35	.visual		= FB_VISUAL_TRUECOLOR,
 36	.line_length	= 1024*2,
 37	.accel		= FB_ACCEL_NONE,
 38};
 39
 40static struct fb_var_screeninfo q40fb_var __initdata = {
 41	.xres		= 1024,
 42	.yres		= 512,
 43	.xres_virtual	= 1024,
 44	.yres_virtual	= 512,
 45	.bits_per_pixel	= 16,
 46    	.red		= {6, 5, 0},
 47	.green		= {11, 5, 0},
 48	.blue		= {0, 6, 0},
 49	.activate	= FB_ACTIVATE_NOW,
 50	.height		= 230,
 51	.width		= 300,
 52	.vmode		= FB_VMODE_NONINTERLACED,
 53};
 54
 55static int q40fb_setcolreg(unsigned regno, unsigned red, unsigned green,
 56			   unsigned blue, unsigned transp,
 57			   struct fb_info *info)
 58{
 59    /*
 60     *  Set a single color register. The values supplied have a 16 bit
 61     *  magnitude.
 62     *  Return != 0 for invalid regno.
 63     */
 64
 65    if (regno > 255)
 66	    return 1;
 67    red>>=11;
 68    green>>=11;
 69    blue>>=10;
 70
 71    if (regno < 16) {
 72	((u32 *)info->pseudo_palette)[regno] = ((red & 31) <<6) |
 73					       ((green & 31) << 11) |
 74					       (blue & 63);
 75    }
 76    return 0;
 77}
 78
 79static struct fb_ops q40fb_ops = {
 80	.owner		= THIS_MODULE,
 81	.fb_setcolreg	= q40fb_setcolreg,
 82	.fb_fillrect	= cfb_fillrect,
 83	.fb_copyarea	= cfb_copyarea,
 84	.fb_imageblit	= cfb_imageblit,
 85};
 86
 87static int __devinit q40fb_probe(struct platform_device *dev)
 88{
 89	struct fb_info *info;
 90
 91	if (!MACH_IS_Q40)
 92		return -ENXIO;
 93
 94	/* mapped in q40/config.c */
 95	q40fb_fix.smem_start = Q40_PHYS_SCREEN_ADDR;
 96
 97	info = framebuffer_alloc(sizeof(u32) * 16, &dev->dev);
 98	if (!info)
 99		return -ENOMEM;
100
101	info->var = q40fb_var;
102	info->fix = q40fb_fix;
103	info->fbops = &q40fb_ops;
104	info->flags = FBINFO_DEFAULT;  /* not as module for now */
105	info->pseudo_palette = info->par;
106	info->par = NULL;
107	info->screen_base = (char *) q40fb_fix.smem_start;
108
109	if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
110		framebuffer_release(info);
111		return -ENOMEM;
112	}
113
114	master_outb(3, DISPLAY_CONTROL_REG);
115
116	if (register_framebuffer(info) < 0) {
117		printk(KERN_ERR "Unable to register Q40 frame buffer\n");
118		fb_dealloc_cmap(&info->cmap);
119		framebuffer_release(info);
120		return -EINVAL;
121	}
122
123        printk(KERN_INFO "fb%d: Q40 frame buffer alive and kicking !\n",
124	       info->node);
125	return 0;
126}
127
128static struct platform_driver q40fb_driver = {
129	.probe	= q40fb_probe,
130	.driver	= {
131		.name	= "q40fb",
132	},
133};
134
135static struct platform_device q40fb_device = {
136	.name	= "q40fb",
137};
138
139int __init q40fb_init(void)
140{
141	int ret = 0;
142
143	if (fb_get_options("q40fb", NULL))
144		return -ENODEV;
145
146	ret = platform_driver_register(&q40fb_driver);
147
148	if (!ret) {
149		ret = platform_device_register(&q40fb_device);
150		if (ret)
151			platform_driver_unregister(&q40fb_driver);
152	}
153	return ret;
154}
155
156module_init(q40fb_init);
157MODULE_LICENSE("GPL");