Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /* tcx.c: TCX frame buffer driver
0003  *
0004  * Copyright (C) 2003, 2006 David S. Miller (davem@davemloft.net)
0005  * Copyright (C) 1996,1998 Jakub Jelinek (jj@ultra.linux.cz)
0006  * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
0007  * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
0008  *
0009  * Driver layout based loosely on tgafb.c, see that file for credits.
0010  */
0011 
0012 #include <linux/module.h>
0013 #include <linux/kernel.h>
0014 #include <linux/errno.h>
0015 #include <linux/string.h>
0016 #include <linux/delay.h>
0017 #include <linux/init.h>
0018 #include <linux/fb.h>
0019 #include <linux/mm.h>
0020 #include <linux/of_device.h>
0021 
0022 #include <asm/io.h>
0023 #include <asm/fbio.h>
0024 
0025 #include "sbuslib.h"
0026 
0027 /*
0028  * Local functions.
0029  */
0030 
0031 static int tcx_setcolreg(unsigned, unsigned, unsigned, unsigned,
0032              unsigned, struct fb_info *);
0033 static int tcx_blank(int, struct fb_info *);
0034 
0035 static int tcx_mmap(struct fb_info *, struct vm_area_struct *);
0036 static int tcx_ioctl(struct fb_info *, unsigned int, unsigned long);
0037 static int tcx_pan_display(struct fb_var_screeninfo *, struct fb_info *);
0038 
0039 /*
0040  *  Frame buffer operations
0041  */
0042 
0043 static const struct fb_ops tcx_ops = {
0044     .owner          = THIS_MODULE,
0045     .fb_setcolreg       = tcx_setcolreg,
0046     .fb_blank       = tcx_blank,
0047     .fb_pan_display     = tcx_pan_display,
0048     .fb_fillrect        = cfb_fillrect,
0049     .fb_copyarea        = cfb_copyarea,
0050     .fb_imageblit       = cfb_imageblit,
0051     .fb_mmap        = tcx_mmap,
0052     .fb_ioctl       = tcx_ioctl,
0053 #ifdef CONFIG_COMPAT
0054     .fb_compat_ioctl    = sbusfb_compat_ioctl,
0055 #endif
0056 };
0057 
0058 /* THC definitions */
0059 #define TCX_THC_MISC_REV_SHIFT       16
0060 #define TCX_THC_MISC_REV_MASK        15
0061 #define TCX_THC_MISC_VSYNC_DIS       (1 << 25)
0062 #define TCX_THC_MISC_HSYNC_DIS       (1 << 24)
0063 #define TCX_THC_MISC_RESET           (1 << 12)
0064 #define TCX_THC_MISC_VIDEO           (1 << 10)
0065 #define TCX_THC_MISC_SYNC            (1 << 9)
0066 #define TCX_THC_MISC_VSYNC           (1 << 8)
0067 #define TCX_THC_MISC_SYNC_ENAB       (1 << 7)
0068 #define TCX_THC_MISC_CURS_RES        (1 << 6)
0069 #define TCX_THC_MISC_INT_ENAB        (1 << 5)
0070 #define TCX_THC_MISC_INT             (1 << 4)
0071 #define TCX_THC_MISC_INIT            0x9f
0072 #define TCX_THC_REV_REV_SHIFT        20
0073 #define TCX_THC_REV_REV_MASK         15
0074 #define TCX_THC_REV_MINREV_SHIFT     28
0075 #define TCX_THC_REV_MINREV_MASK      15
0076 
0077 /* The contents are unknown */
0078 struct tcx_tec {
0079     u32 tec_matrix;
0080     u32 tec_clip;
0081     u32 tec_vdc;
0082 };
0083 
0084 struct tcx_thc {
0085     u32 thc_rev;
0086     u32 thc_pad0[511];
0087     u32 thc_hs;     /* hsync timing */
0088     u32 thc_hsdvs;
0089     u32 thc_hd;
0090     u32 thc_vs;     /* vsync timing */
0091     u32 thc_vd;
0092     u32 thc_refresh;
0093     u32 thc_misc;
0094     u32 thc_pad1[56];
0095     u32 thc_cursxy; /* cursor x,y position (16 bits each) */
0096     u32 thc_cursmask[32];   /* cursor mask bits */
0097     u32 thc_cursbits[32];   /* what to show where mask enabled */
0098 };
0099 
0100 struct bt_regs {
0101     u32 addr;
0102     u32 color_map;
0103     u32 control;
0104     u32 cursor;
0105 };
0106 
0107 #define TCX_MMAP_ENTRIES 14
0108 
0109 struct tcx_par {
0110     spinlock_t      lock;
0111     struct bt_regs      __iomem *bt;
0112     struct tcx_thc      __iomem *thc;
0113     struct tcx_tec      __iomem *tec;
0114     u32         __iomem *cplane;
0115 
0116     u32         flags;
0117 #define TCX_FLAG_BLANKED    0x00000001
0118 
0119     unsigned long       which_io;
0120 
0121     struct sbus_mmap_map    mmap_map[TCX_MMAP_ENTRIES];
0122     int         lowdepth;
0123 };
0124 
0125 /* Reset control plane so that WID is 8-bit plane. */
0126 static void __tcx_set_control_plane(struct fb_info *info)
0127 {
0128     struct tcx_par *par = info->par;
0129     u32 __iomem *p, *pend;
0130 
0131     if (par->lowdepth)
0132         return;
0133 
0134     p = par->cplane;
0135     if (p == NULL)
0136         return;
0137     for (pend = p + info->fix.smem_len; p < pend; p++) {
0138         u32 tmp = sbus_readl(p);
0139 
0140         tmp &= 0xffffff;
0141         sbus_writel(tmp, p);
0142     }
0143 }
0144 
0145 static void tcx_reset(struct fb_info *info)
0146 {
0147     struct tcx_par *par = (struct tcx_par *) info->par;
0148     unsigned long flags;
0149 
0150     spin_lock_irqsave(&par->lock, flags);
0151     __tcx_set_control_plane(info);
0152     spin_unlock_irqrestore(&par->lock, flags);
0153 }
0154 
0155 static int tcx_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
0156 {
0157     tcx_reset(info);
0158     return 0;
0159 }
0160 
0161 /**
0162  *      tcx_setcolreg - Optional function. Sets a color register.
0163  *      @regno: boolean, 0 copy local, 1 get_user() function
0164  *      @red: frame buffer colormap structure
0165  *      @green: The green value which can be up to 16 bits wide
0166  *      @blue:  The blue value which can be up to 16 bits wide.
0167  *      @transp: If supported the alpha value which can be up to 16 bits wide.
0168  *      @info: frame buffer info structure
0169  */
0170 static int tcx_setcolreg(unsigned regno,
0171              unsigned red, unsigned green, unsigned blue,
0172              unsigned transp, struct fb_info *info)
0173 {
0174     struct tcx_par *par = (struct tcx_par *) info->par;
0175     struct bt_regs __iomem *bt = par->bt;
0176     unsigned long flags;
0177 
0178     if (regno >= 256)
0179         return 1;
0180 
0181     red >>= 8;
0182     green >>= 8;
0183     blue >>= 8;
0184 
0185     spin_lock_irqsave(&par->lock, flags);
0186 
0187     sbus_writel(regno << 24, &bt->addr);
0188     sbus_writel(red << 24, &bt->color_map);
0189     sbus_writel(green << 24, &bt->color_map);
0190     sbus_writel(blue << 24, &bt->color_map);
0191 
0192     spin_unlock_irqrestore(&par->lock, flags);
0193 
0194     return 0;
0195 }
0196 
0197 /**
0198  *      tcx_blank - Optional function.  Blanks the display.
0199  *      @blank: the blank mode we want.
0200  *      @info: frame buffer structure that represents a single frame buffer
0201  */
0202 static int
0203 tcx_blank(int blank, struct fb_info *info)
0204 {
0205     struct tcx_par *par = (struct tcx_par *) info->par;
0206     struct tcx_thc __iomem *thc = par->thc;
0207     unsigned long flags;
0208     u32 val;
0209 
0210     spin_lock_irqsave(&par->lock, flags);
0211 
0212     val = sbus_readl(&thc->thc_misc);
0213 
0214     switch (blank) {
0215     case FB_BLANK_UNBLANK: /* Unblanking */
0216         val &= ~(TCX_THC_MISC_VSYNC_DIS |
0217              TCX_THC_MISC_HSYNC_DIS);
0218         val |= TCX_THC_MISC_VIDEO;
0219         par->flags &= ~TCX_FLAG_BLANKED;
0220         break;
0221 
0222     case FB_BLANK_NORMAL: /* Normal blanking */
0223         val &= ~TCX_THC_MISC_VIDEO;
0224         par->flags |= TCX_FLAG_BLANKED;
0225         break;
0226 
0227     case FB_BLANK_VSYNC_SUSPEND: /* VESA blank (vsync off) */
0228         val |= TCX_THC_MISC_VSYNC_DIS;
0229         break;
0230     case FB_BLANK_HSYNC_SUSPEND: /* VESA blank (hsync off) */
0231         val |= TCX_THC_MISC_HSYNC_DIS;
0232         break;
0233 
0234     case FB_BLANK_POWERDOWN: /* Poweroff */
0235         break;
0236     }
0237 
0238     sbus_writel(val, &thc->thc_misc);
0239 
0240     spin_unlock_irqrestore(&par->lock, flags);
0241 
0242     return 0;
0243 }
0244 
0245 static struct sbus_mmap_map __tcx_mmap_map[TCX_MMAP_ENTRIES] = {
0246     {
0247         .voff   = TCX_RAM8BIT,
0248         .size   = SBUS_MMAP_FBSIZE(1)
0249     },
0250     {
0251         .voff   = TCX_RAM24BIT,
0252         .size   = SBUS_MMAP_FBSIZE(4)
0253     },
0254     {
0255         .voff   = TCX_UNK3,
0256         .size   = SBUS_MMAP_FBSIZE(8)
0257     },
0258     {
0259         .voff   = TCX_UNK4,
0260         .size   = SBUS_MMAP_FBSIZE(8)
0261     },
0262     {
0263         .voff   = TCX_CONTROLPLANE,
0264         .size   = SBUS_MMAP_FBSIZE(4)
0265     },
0266     {
0267         .voff   = TCX_UNK6,
0268         .size   = SBUS_MMAP_FBSIZE(8)
0269     },
0270     {
0271         .voff   = TCX_UNK7,
0272         .size   = SBUS_MMAP_FBSIZE(8)
0273     },
0274     {
0275         .voff   = TCX_TEC,
0276         .size   = PAGE_SIZE
0277     },
0278     {
0279         .voff   = TCX_BTREGS,
0280         .size   = PAGE_SIZE
0281     },
0282     {
0283         .voff   = TCX_THC,
0284         .size   = PAGE_SIZE
0285     },
0286     {
0287         .voff   = TCX_DHC,
0288         .size   = PAGE_SIZE
0289     },
0290     {
0291         .voff   = TCX_ALT,
0292         .size   = PAGE_SIZE
0293     },
0294     {
0295         .voff   = TCX_UNK2,
0296         .size   = 0x20000
0297     },
0298     { .size = 0 }
0299 };
0300 
0301 static int tcx_mmap(struct fb_info *info, struct vm_area_struct *vma)
0302 {
0303     struct tcx_par *par = (struct tcx_par *)info->par;
0304 
0305     return sbusfb_mmap_helper(par->mmap_map,
0306                   info->fix.smem_start, info->fix.smem_len,
0307                   par->which_io, vma);
0308 }
0309 
0310 static int tcx_ioctl(struct fb_info *info, unsigned int cmd,
0311              unsigned long arg)
0312 {
0313     struct tcx_par *par = (struct tcx_par *) info->par;
0314 
0315     return sbusfb_ioctl_helper(cmd, arg, info,
0316                    FBTYPE_TCXCOLOR,
0317                    (par->lowdepth ? 8 : 24),
0318                    info->fix.smem_len);
0319 }
0320 
0321 /*
0322  *  Initialisation
0323  */
0324 
0325 static void
0326 tcx_init_fix(struct fb_info *info, int linebytes)
0327 {
0328     struct tcx_par *par = (struct tcx_par *)info->par;
0329     const char *tcx_name;
0330 
0331     if (par->lowdepth)
0332         tcx_name = "TCX8";
0333     else
0334         tcx_name = "TCX24";
0335 
0336     strscpy(info->fix.id, tcx_name, sizeof(info->fix.id));
0337 
0338     info->fix.type = FB_TYPE_PACKED_PIXELS;
0339     info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
0340 
0341     info->fix.line_length = linebytes;
0342 
0343     info->fix.accel = FB_ACCEL_SUN_TCX;
0344 }
0345 
0346 static void tcx_unmap_regs(struct platform_device *op, struct fb_info *info,
0347                struct tcx_par *par)
0348 {
0349     if (par->tec)
0350         of_iounmap(&op->resource[7],
0351                par->tec, sizeof(struct tcx_tec));
0352     if (par->thc)
0353         of_iounmap(&op->resource[9],
0354                par->thc, sizeof(struct tcx_thc));
0355     if (par->bt)
0356         of_iounmap(&op->resource[8],
0357                par->bt, sizeof(struct bt_regs));
0358     if (par->cplane)
0359         of_iounmap(&op->resource[4],
0360                par->cplane, info->fix.smem_len * sizeof(u32));
0361     if (info->screen_base)
0362         of_iounmap(&op->resource[0],
0363                info->screen_base, info->fix.smem_len);
0364 }
0365 
0366 static int tcx_probe(struct platform_device *op)
0367 {
0368     struct device_node *dp = op->dev.of_node;
0369     struct fb_info *info;
0370     struct tcx_par *par;
0371     int linebytes, i, err;
0372 
0373     info = framebuffer_alloc(sizeof(struct tcx_par), &op->dev);
0374 
0375     err = -ENOMEM;
0376     if (!info)
0377         goto out_err;
0378     par = info->par;
0379 
0380     spin_lock_init(&par->lock);
0381 
0382     par->lowdepth =
0383         (of_find_property(dp, "tcx-8-bit", NULL) != NULL);
0384 
0385     sbusfb_fill_var(&info->var, dp, 8);
0386     info->var.red.length = 8;
0387     info->var.green.length = 8;
0388     info->var.blue.length = 8;
0389 
0390     linebytes = of_getintprop_default(dp, "linebytes",
0391                       info->var.xres);
0392     info->fix.smem_len = PAGE_ALIGN(linebytes * info->var.yres);
0393 
0394     par->tec = of_ioremap(&op->resource[7], 0,
0395                   sizeof(struct tcx_tec), "tcx tec");
0396     par->thc = of_ioremap(&op->resource[9], 0,
0397                   sizeof(struct tcx_thc), "tcx thc");
0398     par->bt = of_ioremap(&op->resource[8], 0,
0399                  sizeof(struct bt_regs), "tcx dac");
0400     info->screen_base = of_ioremap(&op->resource[0], 0,
0401                        info->fix.smem_len, "tcx ram");
0402     if (!par->tec || !par->thc ||
0403         !par->bt || !info->screen_base)
0404         goto out_unmap_regs;
0405 
0406     memcpy(&par->mmap_map, &__tcx_mmap_map, sizeof(par->mmap_map));
0407     if (!par->lowdepth) {
0408         par->cplane = of_ioremap(&op->resource[4], 0,
0409                          info->fix.smem_len * sizeof(u32),
0410                          "tcx cplane");
0411         if (!par->cplane)
0412             goto out_unmap_regs;
0413     } else {
0414         par->mmap_map[1].size = SBUS_MMAP_EMPTY;
0415         par->mmap_map[4].size = SBUS_MMAP_EMPTY;
0416         par->mmap_map[5].size = SBUS_MMAP_EMPTY;
0417         par->mmap_map[6].size = SBUS_MMAP_EMPTY;
0418     }
0419 
0420     info->fix.smem_start = op->resource[0].start;
0421     par->which_io = op->resource[0].flags & IORESOURCE_BITS;
0422 
0423     for (i = 0; i < TCX_MMAP_ENTRIES; i++) {
0424         int j;
0425 
0426         switch (i) {
0427         case 10:
0428             j = 12;
0429             break;
0430 
0431         case 11: case 12:
0432             j = i - 1;
0433             break;
0434 
0435         default:
0436             j = i;
0437             break;
0438         }
0439         par->mmap_map[i].poff = op->resource[j].start;
0440     }
0441 
0442     info->flags = FBINFO_DEFAULT;
0443     info->fbops = &tcx_ops;
0444 
0445     /* Initialize brooktree DAC. */
0446     sbus_writel(0x04 << 24, &par->bt->addr);         /* color planes */
0447     sbus_writel(0xff << 24, &par->bt->control);
0448     sbus_writel(0x05 << 24, &par->bt->addr);
0449     sbus_writel(0x00 << 24, &par->bt->control);
0450     sbus_writel(0x06 << 24, &par->bt->addr);         /* overlay plane */
0451     sbus_writel(0x73 << 24, &par->bt->control);
0452     sbus_writel(0x07 << 24, &par->bt->addr);
0453     sbus_writel(0x00 << 24, &par->bt->control);
0454 
0455     tcx_reset(info);
0456 
0457     tcx_blank(FB_BLANK_UNBLANK, info);
0458 
0459     if (fb_alloc_cmap(&info->cmap, 256, 0))
0460         goto out_unmap_regs;
0461 
0462     fb_set_cmap(&info->cmap, info);
0463     tcx_init_fix(info, linebytes);
0464 
0465     err = register_framebuffer(info);
0466     if (err < 0)
0467         goto out_dealloc_cmap;
0468 
0469     dev_set_drvdata(&op->dev, info);
0470 
0471     printk(KERN_INFO "%pOF: TCX at %lx:%lx, %s\n",
0472            dp,
0473            par->which_io,
0474            info->fix.smem_start,
0475            par->lowdepth ? "8-bit only" : "24-bit depth");
0476 
0477     return 0;
0478 
0479 out_dealloc_cmap:
0480     fb_dealloc_cmap(&info->cmap);
0481 
0482 out_unmap_regs:
0483     tcx_unmap_regs(op, info, par);
0484     framebuffer_release(info);
0485 
0486 out_err:
0487     return err;
0488 }
0489 
0490 static int tcx_remove(struct platform_device *op)
0491 {
0492     struct fb_info *info = dev_get_drvdata(&op->dev);
0493     struct tcx_par *par = info->par;
0494 
0495     unregister_framebuffer(info);
0496     fb_dealloc_cmap(&info->cmap);
0497 
0498     tcx_unmap_regs(op, info, par);
0499 
0500     framebuffer_release(info);
0501 
0502     return 0;
0503 }
0504 
0505 static const struct of_device_id tcx_match[] = {
0506     {
0507         .name = "SUNW,tcx",
0508     },
0509     {},
0510 };
0511 MODULE_DEVICE_TABLE(of, tcx_match);
0512 
0513 static struct platform_driver tcx_driver = {
0514     .driver = {
0515         .name = "tcx",
0516         .of_match_table = tcx_match,
0517     },
0518     .probe      = tcx_probe,
0519     .remove     = tcx_remove,
0520 };
0521 
0522 static int __init tcx_init(void)
0523 {
0524     if (fb_get_options("tcxfb", NULL))
0525         return -ENODEV;
0526 
0527     return platform_driver_register(&tcx_driver);
0528 }
0529 
0530 static void __exit tcx_exit(void)
0531 {
0532     platform_driver_unregister(&tcx_driver);
0533 }
0534 
0535 module_init(tcx_init);
0536 module_exit(tcx_exit);
0537 
0538 MODULE_DESCRIPTION("framebuffer driver for TCX chipsets");
0539 MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
0540 MODULE_VERSION("2.0");
0541 MODULE_LICENSE("GPL");