1 // SPDX-License-Identifier: GPL-2.0-only
2 /* p9100.c: P9100 frame buffer driver
4 * Copyright (C) 2003, 2006 David S. Miller (davem@davemloft.net)
5 * Copyright 1999 Derrick J Brashear (shadow@dementia.org)
7 * Driver layout based loosely on tgafb.c, see that file for credits.
10 #include <linux/module.h>
11 #include <linux/kernel.h>
12 #include <linux/errno.h>
13 #include <linux/string.h>
14 #include <linux/delay.h>
15 #include <linux/init.h>
18 #include <linux/of_device.h>
29 static int p9100_setcolreg(unsigned, unsigned, unsigned, unsigned,
30 unsigned, struct fb_info
*);
31 static int p9100_blank(int, struct fb_info
*);
33 static int p9100_mmap(struct fb_info
*, struct vm_area_struct
*);
34 static int p9100_ioctl(struct fb_info
*, unsigned int, unsigned long);
37 * Frame buffer operations
40 static const struct fb_ops p9100_ops
= {
42 .fb_setcolreg
= p9100_setcolreg
,
43 .fb_blank
= p9100_blank
,
44 .fb_fillrect
= cfb_fillrect
,
45 .fb_copyarea
= cfb_copyarea
,
46 .fb_imageblit
= cfb_imageblit
,
47 .fb_mmap
= p9100_mmap
,
48 .fb_ioctl
= p9100_ioctl
,
50 .fb_compat_ioctl
= sbusfb_compat_ioctl
,
54 /* P9100 control registers */
55 #define P9100_SYSCTL_OFF 0x0UL
56 #define P9100_VIDEOCTL_OFF 0x100UL
57 #define P9100_VRAMCTL_OFF 0x180UL
58 #define P9100_RAMDAC_OFF 0x200UL
59 #define P9100_VIDEOCOPROC_OFF 0x400UL
61 /* P9100 command registers */
62 #define P9100_CMD_OFF 0x0UL
64 /* P9100 framebuffer memory */
65 #define P9100_FB_OFF 0x0UL
67 /* 3 bits: 2=8bpp 3=16bpp 5=32bpp 7=24bpp */
68 #define SYS_CONFIG_PIXELSIZE_SHIFT 26
70 #define SCREENPAINT_TIMECTL1_ENABLE_VIDEO 0x20 /* 0 = off, 1 = on */
73 /* Registers for the system control */
82 /* Registers for the video control */
96 u32 vid_screenpaint_addr
;
97 u32 vid_screenpaint_timectl1
;
98 u32 vid_screenpaint_qsfcnt
;
99 u32 vid_screenpaint_timectl2
;
102 /* Registers for the video control */
106 u32 vram_refresh_cnt
;
112 /* Registers for IBM RGB528 Palette */
113 u32 ramdac_cmap_wridx
;
114 u32 ramdac_palette_data
;
115 u32 ramdac_pixel_mask
;
116 u32 ramdac_palette_rdaddr
;
121 u32 ramdac_xxx
[1784];
124 struct p9100_cmd_parameng
{
127 u32 parameng_quadcmd
;
132 struct p9100_regs __iomem
*regs
;
135 #define P9100_FLAG_BLANKED 0x00000001
137 unsigned long which_io
;
141 * p9100_setcolreg - Optional function. Sets a color register.
142 * @regno: boolean, 0 copy local, 1 get_user() function
143 * @red: frame buffer colormap structure
144 * @green: The green value which can be up to 16 bits wide
145 * @blue: The blue value which can be up to 16 bits wide.
146 * @transp: If supported the alpha value which can be up to 16 bits wide.
147 * @info: frame buffer info structure
149 static int p9100_setcolreg(unsigned regno
,
150 unsigned red
, unsigned green
, unsigned blue
,
151 unsigned transp
, struct fb_info
*info
)
153 struct p9100_par
*par
= (struct p9100_par
*) info
->par
;
154 struct p9100_regs __iomem
*regs
= par
->regs
;
164 spin_lock_irqsave(&par
->lock
, flags
);
166 sbus_writel((regno
<< 16), ®s
->ramdac_cmap_wridx
);
167 sbus_writel((red
<< 16), ®s
->ramdac_palette_data
);
168 sbus_writel((green
<< 16), ®s
->ramdac_palette_data
);
169 sbus_writel((blue
<< 16), ®s
->ramdac_palette_data
);
171 spin_unlock_irqrestore(&par
->lock
, flags
);
177 * p9100_blank - Optional function. Blanks the display.
178 * @blank_mode: the blank mode we want.
179 * @info: frame buffer structure that represents a single frame buffer
182 p9100_blank(int blank
, struct fb_info
*info
)
184 struct p9100_par
*par
= (struct p9100_par
*) info
->par
;
185 struct p9100_regs __iomem
*regs
= par
->regs
;
189 spin_lock_irqsave(&par
->lock
, flags
);
192 case FB_BLANK_UNBLANK
: /* Unblanking */
193 val
= sbus_readl(®s
->vid_screenpaint_timectl1
);
194 val
|= SCREENPAINT_TIMECTL1_ENABLE_VIDEO
;
195 sbus_writel(val
, ®s
->vid_screenpaint_timectl1
);
196 par
->flags
&= ~P9100_FLAG_BLANKED
;
199 case FB_BLANK_NORMAL
: /* Normal blanking */
200 case FB_BLANK_VSYNC_SUSPEND
: /* VESA blank (vsync off) */
201 case FB_BLANK_HSYNC_SUSPEND
: /* VESA blank (hsync off) */
202 case FB_BLANK_POWERDOWN
: /* Poweroff */
203 val
= sbus_readl(®s
->vid_screenpaint_timectl1
);
204 val
&= ~SCREENPAINT_TIMECTL1_ENABLE_VIDEO
;
205 sbus_writel(val
, ®s
->vid_screenpaint_timectl1
);
206 par
->flags
|= P9100_FLAG_BLANKED
;
210 spin_unlock_irqrestore(&par
->lock
, flags
);
215 static struct sbus_mmap_map p9100_mmap_map
[] = {
216 { CG3_MMAP_OFFSET
, 0, SBUS_MMAP_FBSIZE(1) },
220 static int p9100_mmap(struct fb_info
*info
, struct vm_area_struct
*vma
)
222 struct p9100_par
*par
= (struct p9100_par
*)info
->par
;
224 return sbusfb_mmap_helper(p9100_mmap_map
,
225 info
->fix
.smem_start
, info
->fix
.smem_len
,
229 static int p9100_ioctl(struct fb_info
*info
, unsigned int cmd
,
232 /* Make it look like a cg3. */
233 return sbusfb_ioctl_helper(cmd
, arg
, info
,
234 FBTYPE_SUN3COLOR
, 8, info
->fix
.smem_len
);
241 static void p9100_init_fix(struct fb_info
*info
, int linebytes
, struct device_node
*dp
)
243 snprintf(info
->fix
.id
, sizeof(info
->fix
.id
), "%pOFn", dp
);
245 info
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
246 info
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
248 info
->fix
.line_length
= linebytes
;
250 info
->fix
.accel
= FB_ACCEL_SUN_CGTHREE
;
253 static int p9100_probe(struct platform_device
*op
)
255 struct device_node
*dp
= op
->dev
.of_node
;
256 struct fb_info
*info
;
257 struct p9100_par
*par
;
260 info
= framebuffer_alloc(sizeof(struct p9100_par
), &op
->dev
);
267 spin_lock_init(&par
->lock
);
269 /* This is the framebuffer and the only resource apps can mmap. */
270 info
->fix
.smem_start
= op
->resource
[2].start
;
271 par
->which_io
= op
->resource
[2].flags
& IORESOURCE_BITS
;
273 sbusfb_fill_var(&info
->var
, dp
, 8);
274 info
->var
.red
.length
= 8;
275 info
->var
.green
.length
= 8;
276 info
->var
.blue
.length
= 8;
278 linebytes
= of_getintprop_default(dp
, "linebytes", info
->var
.xres
);
279 info
->fix
.smem_len
= PAGE_ALIGN(linebytes
* info
->var
.yres
);
281 par
->regs
= of_ioremap(&op
->resource
[0], 0,
282 sizeof(struct p9100_regs
), "p9100 regs");
286 info
->flags
= FBINFO_DEFAULT
;
287 info
->fbops
= &p9100_ops
;
288 info
->screen_base
= of_ioremap(&op
->resource
[2], 0,
289 info
->fix
.smem_len
, "p9100 ram");
290 if (!info
->screen_base
)
293 p9100_blank(FB_BLANK_UNBLANK
, info
);
295 if (fb_alloc_cmap(&info
->cmap
, 256, 0))
296 goto out_unmap_screen
;
298 p9100_init_fix(info
, linebytes
, dp
);
300 err
= register_framebuffer(info
);
302 goto out_dealloc_cmap
;
304 fb_set_cmap(&info
->cmap
, info
);
306 dev_set_drvdata(&op
->dev
, info
);
308 printk(KERN_INFO
"%pOF: p9100 at %lx:%lx\n",
310 par
->which_io
, info
->fix
.smem_start
);
315 fb_dealloc_cmap(&info
->cmap
);
318 of_iounmap(&op
->resource
[2], info
->screen_base
, info
->fix
.smem_len
);
321 of_iounmap(&op
->resource
[0], par
->regs
, sizeof(struct p9100_regs
));
324 framebuffer_release(info
);
330 static int p9100_remove(struct platform_device
*op
)
332 struct fb_info
*info
= dev_get_drvdata(&op
->dev
);
333 struct p9100_par
*par
= info
->par
;
335 unregister_framebuffer(info
);
336 fb_dealloc_cmap(&info
->cmap
);
338 of_iounmap(&op
->resource
[0], par
->regs
, sizeof(struct p9100_regs
));
339 of_iounmap(&op
->resource
[2], info
->screen_base
, info
->fix
.smem_len
);
341 framebuffer_release(info
);
346 static const struct of_device_id p9100_match
[] = {
352 MODULE_DEVICE_TABLE(of
, p9100_match
);
354 static struct platform_driver p9100_driver
= {
357 .of_match_table
= p9100_match
,
359 .probe
= p9100_probe
,
360 .remove
= p9100_remove
,
363 static int __init
p9100_init(void)
365 if (fb_get_options("p9100fb", NULL
))
368 return platform_driver_register(&p9100_driver
);
371 static void __exit
p9100_exit(void)
373 platform_driver_unregister(&p9100_driver
);
376 module_init(p9100_init
);
377 module_exit(p9100_exit
);
379 MODULE_DESCRIPTION("framebuffer driver for P9100 chipsets");
380 MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
381 MODULE_VERSION("2.0");
382 MODULE_LICENSE("GPL");