/drivers/video/wm8505fb.c
C | 422 lines | 315 code | 87 blank | 20 comment | 24 complexity | 22587ea01075a34255eaece9b10c189d MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
- /*
- * WonderMedia WM8505 Frame Buffer device driver
- *
- * Copyright (C) 2010 Ed Spiridonov <edo.rus@gmail.com>
- * Based on vt8500lcdfb.c
- *
- * This software is licensed under the terms of the GNU General Public
- * License version 2, as published by the Free Software Foundation, and
- * may be copied, distributed, and modified under those terms.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
- #include <linux/module.h>
- #include <linux/kernel.h>
- #include <linux/errno.h>
- #include <linux/string.h>
- #include <linux/mm.h>
- #include <linux/slab.h>
- #include <linux/delay.h>
- #include <linux/fb.h>
- #include <linux/init.h>
- #include <linux/interrupt.h>
- #include <linux/io.h>
- #include <linux/dma-mapping.h>
- #include <linux/platform_device.h>
- #include <linux/wait.h>
- #include <mach/vt8500fb.h>
- #include "wm8505fb_regs.h"
- #include "wmt_ge_rops.h"
- #define DRIVER_NAME "wm8505-fb"
- #define to_wm8505fb_info(__info) container_of(__info, \
- struct wm8505fb_info, fb)
- struct wm8505fb_info {
- struct fb_info fb;
- void __iomem *regbase;
- unsigned int contrast;
- };
- static int wm8505fb_init_hw(struct fb_info *info)
- {
- struct wm8505fb_info *fbi = to_wm8505fb_info(info);
- int i;
- /* I know the purpose only of few registers, so clear unknown */
- for (i = 0; i < 0x200; i += 4)
- writel(0, fbi->regbase + i);
- /* Set frame buffer address */
- writel(fbi->fb.fix.smem_start, fbi->regbase + WMT_GOVR_FBADDR);
- writel(fbi->fb.fix.smem_start, fbi->regbase + WMT_GOVR_FBADDR1);
- /* Set in-memory picture format to RGB 32bpp */
- writel(0x1c, fbi->regbase + WMT_GOVR_COLORSPACE);
- writel(1, fbi->regbase + WMT_GOVR_COLORSPACE1);
- /* Virtual buffer size */
- writel(info->var.xres, fbi->regbase + WMT_GOVR_XRES);
- writel(info->var.xres_virtual, fbi->regbase + WMT_GOVR_XRES_VIRTUAL);
- /* black magic ;) */
- writel(0xf, fbi->regbase + WMT_GOVR_FHI);
- writel(4, fbi->regbase + WMT_GOVR_DVO_SET);
- writel(1, fbi->regbase + WMT_GOVR_MIF_ENABLE);
- writel(1, fbi->regbase + WMT_GOVR_REG_UPDATE);
- return 0;
- }
- static int wm8505fb_set_timing(struct fb_info *info)
- {
- struct wm8505fb_info *fbi = to_wm8505fb_info(info);
- int h_start = info->var.left_margin;
- int h_end = h_start + info->var.xres;
- int h_all = h_end + info->var.right_margin;
- int h_sync = info->var.hsync_len;
- int v_start = info->var.upper_margin;
- int v_end = v_start + info->var.yres;
- int v_all = v_end + info->var.lower_margin;
- int v_sync = info->var.vsync_len;
- writel(0, fbi->regbase + WMT_GOVR_TG);
- writel(h_start, fbi->regbase + WMT_GOVR_TIMING_H_START);
- writel(h_end, fbi->regbase + WMT_GOVR_TIMING_H_END);
- writel(h_all, fbi->regbase + WMT_GOVR_TIMING_H_ALL);
- writel(h_sync, fbi->regbase + WMT_GOVR_TIMING_H_SYNC);
- writel(v_start, fbi->regbase + WMT_GOVR_TIMING_V_START);
- writel(v_end, fbi->regbase + WMT_GOVR_TIMING_V_END);
- writel(v_all, fbi->regbase + WMT_GOVR_TIMING_V_ALL);
- writel(v_sync, fbi->regbase + WMT_GOVR_TIMING_V_SYNC);
- writel(1, fbi->regbase + WMT_GOVR_TG);
- return 0;
- }
- static int wm8505fb_set_par(struct fb_info *info)
- {
- struct wm8505fb_info *fbi = to_wm8505fb_info(info);
- if (!fbi)
- return -EINVAL;
- if (info->var.bits_per_pixel == 32) {
- info->var.red.offset = 16;
- info->var.red.length = 8;
- info->var.red.msb_right = 0;
- info->var.green.offset = 8;
- info->var.green.length = 8;
- info->var.green.msb_right = 0;
- info->var.blue.offset = 0;
- info->var.blue.length = 8;
- info->var.blue.msb_right = 0;
- info->fix.visual = FB_VISUAL_TRUECOLOR;
- info->fix.line_length = info->var.xres_virtual << 2;
- }
- wm8505fb_set_timing(info);
- writel(fbi->contrast<<16 | fbi->contrast<<8 | fbi->contrast,
- fbi->regbase + WMT_GOVR_CONTRAST);
- return 0;
- }
- static ssize_t contrast_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct fb_info *info = dev_get_drvdata(dev);
- struct wm8505fb_info *fbi = to_wm8505fb_info(info);
- return sprintf(buf, "%d\n", fbi->contrast);
- }
- static ssize_t contrast_store(struct device *dev,
- struct device_attribute *attr,
- const char *buf, size_t count)
- {
- struct fb_info *info = dev_get_drvdata(dev);
- struct wm8505fb_info *fbi = to_wm8505fb_info(info);
- unsigned long tmp;
- if (strict_strtoul(buf, 10, &tmp) || (tmp > 0xff))
- return -EINVAL;
- fbi->contrast = tmp;
- wm8505fb_set_par(info);
- return count;
- }
- static DEVICE_ATTR(contrast, 0644, contrast_show, contrast_store);
- static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf)
- {
- chan &= 0xffff;
- chan >>= 16 - bf->length;
- return chan << bf->offset;
- }
- static int wm8505fb_setcolreg(unsigned regno, unsigned red, unsigned green,
- unsigned blue, unsigned transp,
- struct fb_info *info) {
- struct wm8505fb_info *fbi = to_wm8505fb_info(info);
- int ret = 1;
- unsigned int val;
- if (regno >= 256)
- return -EINVAL;
- if (info->var.grayscale)
- red = green = blue =
- (19595 * red + 38470 * green + 7471 * blue) >> 16;
- switch (fbi->fb.fix.visual) {
- case FB_VISUAL_TRUECOLOR:
- if (regno < 16) {
- u32 *pal = info->pseudo_palette;
- val = chan_to_field(red, &fbi->fb.var.red);
- val |= chan_to_field(green, &fbi->fb.var.green);
- val |= chan_to_field(blue, &fbi->fb.var.blue);
- pal[regno] = val;
- ret = 0;
- }
- break;
- }
- return ret;
- }
- static int wm8505fb_pan_display(struct fb_var_screeninfo *var,
- struct fb_info *info)
- {
- struct wm8505fb_info *fbi = to_wm8505fb_info(info);
- writel(var->xoffset, fbi->regbase + WMT_GOVR_XPAN);
- writel(var->yoffset, fbi->regbase + WMT_GOVR_YPAN);
- return 0;
- }
- static int wm8505fb_blank(int blank, struct fb_info *info)
- {
- struct wm8505fb_info *fbi = to_wm8505fb_info(info);
- switch (blank) {
- case FB_BLANK_UNBLANK:
- wm8505fb_set_timing(info);
- break;
- default:
- writel(0, fbi->regbase + WMT_GOVR_TIMING_V_SYNC);
- break;
- }
- return 0;
- }
- static struct fb_ops wm8505fb_ops = {
- .owner = THIS_MODULE,
- .fb_set_par = wm8505fb_set_par,
- .fb_setcolreg = wm8505fb_setcolreg,
- .fb_fillrect = wmt_ge_fillrect,
- .fb_copyarea = wmt_ge_copyarea,
- .fb_imageblit = sys_imageblit,
- .fb_sync = wmt_ge_sync,
- .fb_pan_display = wm8505fb_pan_display,
- .fb_blank = wm8505fb_blank,
- };
- static int __devinit wm8505fb_probe(struct platform_device *pdev)
- {
- struct wm8505fb_info *fbi;
- struct resource *res;
-