2019-05-29 22:17:56 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2010-11-09 07:42:39 +08:00
|
|
|
/*
|
|
|
|
* WonderMedia WM8505 Frame Buffer device driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Ed Spiridonov <edo.rus@gmail.com>
|
|
|
|
* Based on vt8500lcdfb.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/delay.h>
|
2013-04-03 02:20:38 +08:00
|
|
|
#include <linux/dma-mapping.h>
|
2010-11-09 07:42:39 +08:00
|
|
|
#include <linux/fb.h>
|
2013-04-03 02:20:38 +08:00
|
|
|
#include <linux/errno.h>
|
2013-04-08 18:04:00 +08:00
|
|
|
#include <linux/err.h>
|
2010-11-09 07:42:39 +08:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/io.h>
|
2013-04-03 02:20:38 +08:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/memblock.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/module.h>
|
2012-08-03 16:58:22 +08:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_fdt.h>
|
2013-04-03 02:20:38 +08:00
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/wait.h>
|
|
|
|
#include <video/of_display_timing.h>
|
2010-11-09 07:42:39 +08:00
|
|
|
|
|
|
|
#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);
|
|
|
|
|
2012-08-03 16:58:22 +08:00
|
|
|
/*
|
|
|
|
* Set in-memory picture format to RGB
|
|
|
|
* 0x31C sets the correct color mode (RGB565) for WM8650
|
|
|
|
* Bit 8+9 (0x300) are ignored on WM8505 as reserved
|
|
|
|
*/
|
|
|
|
writel(0x31c, fbi->regbase + WMT_GOVR_COLORSPACE);
|
2010-11-09 07:42:39 +08:00
|
|
|
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;
|
2010-12-20 21:09:57 +08:00
|
|
|
int v_sync = info->var.vsync_len;
|
2010-11-09 07:42:39 +08:00
|
|
|
|
|
|
|
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;
|
2012-08-03 16:58:22 +08:00
|
|
|
} else if (info->var.bits_per_pixel == 16) {
|
|
|
|
info->var.red.offset = 11;
|
|
|
|
info->var.red.length = 5;
|
|
|
|
info->var.red.msb_right = 0;
|
|
|
|
info->var.green.offset = 5;
|
|
|
|
info->var.green.length = 6;
|
|
|
|
info->var.green.msb_right = 0;
|
|
|
|
info->var.blue.offset = 0;
|
|
|
|
info->var.blue.length = 5;
|
|
|
|
info->var.blue.msb_right = 0;
|
|
|
|
info->fix.visual = FB_VISUAL_TRUECOLOR;
|
|
|
|
info->fix.line_length = info->var.xres_virtual << 1;
|
2010-11-09 07:42:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2014-04-29 20:21:54 +08:00
|
|
|
return sprintf(buf, "%u\n", fbi->contrast);
|
2010-11-09 07:42:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2013-06-01 15:31:21 +08:00
|
|
|
if (kstrtoul(buf, 10, &tmp) || (tmp > 0xff))
|
2010-11-09 07:42:39 +08:00
|
|
|
return -EINVAL;
|
|
|
|
fbi->contrast = tmp;
|
|
|
|
|
|
|
|
wm8505fb_set_par(info);
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
video: fbdev: wm8505fb use permission-specific DEVICE_ATTR variants
Use DEVICE_ATTR_RW for read-write attributes. This simplifies the
source code, improves readbility, and reduces the chance of
inconsistencies.
The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)
// <smpl>
@rw@
declarer name DEVICE_ATTR;
identifier x,x_show,x_store;
@@
DEVICE_ATTR(x, \(0644\|S_IRUGO|S_IWUSR\), x_show, x_store);
@script:ocaml@
x << rw.x;
x_show << rw.x_show;
x_store << rw.x_store;
@@
if not (x^"_show" = x_show && x^"_store" = x_store)
then Coccilib.include_match false
@@
declarer name DEVICE_ATTR_RW;
identifier rw.x,rw.x_show,rw.x_store;
@@
- DEVICE_ATTR(x, \(0644\|S_IRUGO|S_IWUSR\), x_show, x_store);
+ DEVICE_ATTR_RW(x);
// </smpl>
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
2017-01-12 00:09:51 +08:00
|
|
|
static DEVICE_ATTR_RW(contrast);
|
2010-11-09 07:42:39 +08:00
|
|
|
|
2019-07-31 20:43:47 +08:00
|
|
|
static struct attribute *wm8505fb_attrs[] = {
|
|
|
|
&dev_attr_contrast.attr,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
ATTRIBUTE_GROUPS(wm8505fb);
|
|
|
|
|
2010-11-09 07:42:39 +08:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2012-12-22 05:07:39 +08:00
|
|
|
static int wm8505fb_probe(struct platform_device *pdev)
|
2010-11-09 07:42:39 +08:00
|
|
|
{
|
|
|
|
struct wm8505fb_info *fbi;
|
2013-04-03 02:20:38 +08:00
|
|
|
struct resource *res;
|
|
|
|
struct display_timings *disp_timing;
|
2010-11-09 07:42:39 +08:00
|
|
|
void *addr;
|
|
|
|
int ret;
|
|
|
|
|
2013-04-03 02:20:38 +08:00
|
|
|
struct fb_videomode mode;
|
2012-08-03 16:58:22 +08:00
|
|
|
u32 bpp;
|
|
|
|
dma_addr_t fb_mem_phys;
|
|
|
|
unsigned long fb_mem_len;
|
|
|
|
void *fb_mem_virt;
|
2010-11-09 07:42:39 +08:00
|
|
|
|
2012-08-03 16:58:22 +08:00
|
|
|
fbi = devm_kzalloc(&pdev->dev, sizeof(struct wm8505fb_info) +
|
|
|
|
sizeof(u32) * 16, GFP_KERNEL);
|
2017-12-30 02:48:43 +08:00
|
|
|
if (!fbi)
|
drivers/video/wm8505fb.c: use devm_ functions
The various devm_ functions allocate memory that is released when a driver
detaches. This patch uses these functions for data that is allocated in
the probe function of a platform device and is only freed in the remove
function.
The patch makes some other cleanups. First, the original code used
devm_kzalloc, but kfree. This would lead to a double free. The problem
was found using the following semantic match (http://coccinelle.lip6.fr/):
// <smpl>
@@
expression x,e;
@@
x = devm_kzalloc(...)
... when != x = e
?-kfree(x,...);
// </smpl>
The error-handing code of devm_request_and_ioremap does not print any
warning message, because devm_request_and_ioremap does this.
The call to dma_alloc_coherent is converted to its devm equivalent,
dmam_alloc_coherent. This implicitly introduces a call to
dmam_free_coherent, which was completly missing in the original code.
A semicolon is removed at the end of the error-handling code for the call
to dma_alloc_coherent.
The block of code calling fb_alloc_cmap is moved below the block of code
calling wm8505fb_set_par, so that the error-handing code of the call to
wm8505fb_set_par can just return ret. This way there is only one block of
error-handling code that needs to call fb_dealloc_cmap, and so this is
moved up to the place where it is needed, eliminating the need for all
gotos and labels in the function. This was suggested by Tony Prisk.
The initializations of fbi and ret at the beginning of the function are not
necessary and are removed. The call platform_set_drvdata(pdev, NULL); at
the end of the function is also removed.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Tony Prisk <linux@prisktech.co.nz>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
2013-04-03 02:20:36 +08:00
|
|
|
return -ENOMEM;
|
2010-11-09 07:42:39 +08:00
|
|
|
|
|
|
|
strcpy(fbi->fb.fix.id, DRIVER_NAME);
|
|
|
|
|
|
|
|
fbi->fb.fix.type = FB_TYPE_PACKED_PIXELS;
|
|
|
|
fbi->fb.fix.xpanstep = 1;
|
|
|
|
fbi->fb.fix.ypanstep = 1;
|
|
|
|
fbi->fb.fix.ywrapstep = 0;
|
|
|
|
fbi->fb.fix.accel = FB_ACCEL_NONE;
|
|
|
|
|
|
|
|
fbi->fb.fbops = &wm8505fb_ops;
|
|
|
|
fbi->fb.flags = FBINFO_DEFAULT
|
|
|
|
| FBINFO_HWACCEL_COPYAREA
|
|
|
|
| FBINFO_HWACCEL_FILLRECT
|
|
|
|
| FBINFO_HWACCEL_XPAN
|
|
|
|
| FBINFO_HWACCEL_YPAN
|
|
|
|
| FBINFO_VIRTFB
|
|
|
|
| FBINFO_PARTIAL_PAN_OK;
|
|
|
|
fbi->fb.node = -1;
|
|
|
|
|
|
|
|
addr = fbi;
|
|
|
|
addr = addr + sizeof(struct wm8505fb_info);
|
|
|
|
fbi->fb.pseudo_palette = addr;
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
2013-04-08 18:04:00 +08:00
|
|
|
fbi->regbase = devm_ioremap_resource(&pdev->dev, res);
|
|
|
|
if (IS_ERR(fbi->regbase))
|
|
|
|
return PTR_ERR(fbi->regbase);
|
2010-11-09 07:42:39 +08:00
|
|
|
|
2013-04-03 02:20:38 +08:00
|
|
|
disp_timing = of_get_display_timings(pdev->dev.of_node);
|
|
|
|
if (!disp_timing)
|
drivers/video/wm8505fb.c: use devm_ functions
The various devm_ functions allocate memory that is released when a driver
detaches. This patch uses these functions for data that is allocated in
the probe function of a platform device and is only freed in the remove
function.
The patch makes some other cleanups. First, the original code used
devm_kzalloc, but kfree. This would lead to a double free. The problem
was found using the following semantic match (http://coccinelle.lip6.fr/):
// <smpl>
@@
expression x,e;
@@
x = devm_kzalloc(...)
... when != x = e
?-kfree(x,...);
// </smpl>
The error-handing code of devm_request_and_ioremap does not print any
warning message, because devm_request_and_ioremap does this.
The call to dma_alloc_coherent is converted to its devm equivalent,
dmam_alloc_coherent. This implicitly introduces a call to
dmam_free_coherent, which was completly missing in the original code.
A semicolon is removed at the end of the error-handling code for the call
to dma_alloc_coherent.
The block of code calling fb_alloc_cmap is moved below the block of code
calling wm8505fb_set_par, so that the error-handing code of the call to
wm8505fb_set_par can just return ret. This way there is only one block of
error-handling code that needs to call fb_dealloc_cmap, and so this is
moved up to the place where it is needed, eliminating the need for all
gotos and labels in the function. This was suggested by Tony Prisk.
The initializations of fbi and ret at the beginning of the function are not
necessary and are removed. The call platform_set_drvdata(pdev, NULL); at
the end of the function is also removed.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Tony Prisk <linux@prisktech.co.nz>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
2013-04-03 02:20:36 +08:00
|
|
|
return -EINVAL;
|
2012-08-03 16:58:22 +08:00
|
|
|
|
2013-04-03 02:20:38 +08:00
|
|
|
ret = of_get_fb_videomode(pdev->dev.of_node, &mode, OF_USE_NATIVE_MODE);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = of_property_read_u32(pdev->dev.of_node, "bits-per-pixel", &bpp);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2012-08-03 16:58:22 +08:00
|
|
|
|
2013-04-03 02:20:38 +08:00
|
|
|
fb_videomode_to_var(&fbi->fb.var, &mode);
|
2010-11-09 07:42:39 +08:00
|
|
|
|
|
|
|
fbi->fb.var.nonstd = 0;
|
|
|
|
fbi->fb.var.activate = FB_ACTIVATE_NOW;
|
|
|
|
|
|
|
|
fbi->fb.var.height = -1;
|
|
|
|
fbi->fb.var.width = -1;
|
|
|
|
|
2012-08-03 16:58:22 +08:00
|
|
|
/* try allocating the framebuffer */
|
2013-04-03 02:20:38 +08:00
|
|
|
fb_mem_len = mode.xres * mode.yres * 2 * (bpp / 8);
|
drivers/video/wm8505fb.c: use devm_ functions
The various devm_ functions allocate memory that is released when a driver
detaches. This patch uses these functions for data that is allocated in
the probe function of a platform device and is only freed in the remove
function.
The patch makes some other cleanups. First, the original code used
devm_kzalloc, but kfree. This would lead to a double free. The problem
was found using the following semantic match (http://coccinelle.lip6.fr/):
// <smpl>
@@
expression x,e;
@@
x = devm_kzalloc(...)
... when != x = e
?-kfree(x,...);
// </smpl>
The error-handing code of devm_request_and_ioremap does not print any
warning message, because devm_request_and_ioremap does this.
The call to dma_alloc_coherent is converted to its devm equivalent,
dmam_alloc_coherent. This implicitly introduces a call to
dmam_free_coherent, which was completly missing in the original code.
A semicolon is removed at the end of the error-handling code for the call
to dma_alloc_coherent.
The block of code calling fb_alloc_cmap is moved below the block of code
calling wm8505fb_set_par, so that the error-handing code of the call to
wm8505fb_set_par can just return ret. This way there is only one block of
error-handling code that needs to call fb_dealloc_cmap, and so this is
moved up to the place where it is needed, eliminating the need for all
gotos and labels in the function. This was suggested by Tony Prisk.
The initializations of fbi and ret at the beginning of the function are not
necessary and are removed. The call platform_set_drvdata(pdev, NULL); at
the end of the function is also removed.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Tony Prisk <linux@prisktech.co.nz>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
2013-04-03 02:20:36 +08:00
|
|
|
fb_mem_virt = dmam_alloc_coherent(&pdev->dev, fb_mem_len, &fb_mem_phys,
|
2012-08-03 16:58:22 +08:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (!fb_mem_virt) {
|
|
|
|
pr_err("%s: Failed to allocate framebuffer\n", __func__);
|
|
|
|
return -ENOMEM;
|
drivers/video/wm8505fb.c: use devm_ functions
The various devm_ functions allocate memory that is released when a driver
detaches. This patch uses these functions for data that is allocated in
the probe function of a platform device and is only freed in the remove
function.
The patch makes some other cleanups. First, the original code used
devm_kzalloc, but kfree. This would lead to a double free. The problem
was found using the following semantic match (http://coccinelle.lip6.fr/):
// <smpl>
@@
expression x,e;
@@
x = devm_kzalloc(...)
... when != x = e
?-kfree(x,...);
// </smpl>
The error-handing code of devm_request_and_ioremap does not print any
warning message, because devm_request_and_ioremap does this.
The call to dma_alloc_coherent is converted to its devm equivalent,
dmam_alloc_coherent. This implicitly introduces a call to
dmam_free_coherent, which was completly missing in the original code.
A semicolon is removed at the end of the error-handling code for the call
to dma_alloc_coherent.
The block of code calling fb_alloc_cmap is moved below the block of code
calling wm8505fb_set_par, so that the error-handing code of the call to
wm8505fb_set_par can just return ret. This way there is only one block of
error-handling code that needs to call fb_dealloc_cmap, and so this is
moved up to the place where it is needed, eliminating the need for all
gotos and labels in the function. This was suggested by Tony Prisk.
The initializations of fbi and ret at the beginning of the function are not
necessary and are removed. The call platform_set_drvdata(pdev, NULL); at
the end of the function is also removed.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Tony Prisk <linux@prisktech.co.nz>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
2013-04-03 02:20:36 +08:00
|
|
|
}
|
2012-08-03 16:58:22 +08:00
|
|
|
|
2013-04-03 02:20:38 +08:00
|
|
|
fbi->fb.var.xres_virtual = mode.xres;
|
|
|
|
fbi->fb.var.yres_virtual = mode.yres * 2;
|
2012-08-03 16:58:22 +08:00
|
|
|
fbi->fb.var.bits_per_pixel = bpp;
|
|
|
|
|
|
|
|
fbi->fb.fix.smem_start = fb_mem_phys;
|
|
|
|
fbi->fb.fix.smem_len = fb_mem_len;
|
|
|
|
fbi->fb.screen_base = fb_mem_virt;
|
|
|
|
fbi->fb.screen_size = fb_mem_len;
|
2010-11-09 07:42:39 +08:00
|
|
|
|
2013-04-03 02:20:37 +08:00
|
|
|
fbi->contrast = 0x10;
|
2010-11-09 07:42:39 +08:00
|
|
|
ret = wm8505fb_set_par(&fbi->fb);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "Failed to set parameters\n");
|
drivers/video/wm8505fb.c: use devm_ functions
The various devm_ functions allocate memory that is released when a driver
detaches. This patch uses these functions for data that is allocated in
the probe function of a platform device and is only freed in the remove
function.
The patch makes some other cleanups. First, the original code used
devm_kzalloc, but kfree. This would lead to a double free. The problem
was found using the following semantic match (http://coccinelle.lip6.fr/):
// <smpl>
@@
expression x,e;
@@
x = devm_kzalloc(...)
... when != x = e
?-kfree(x,...);
// </smpl>
The error-handing code of devm_request_and_ioremap does not print any
warning message, because devm_request_and_ioremap does this.
The call to dma_alloc_coherent is converted to its devm equivalent,
dmam_alloc_coherent. This implicitly introduces a call to
dmam_free_coherent, which was completly missing in the original code.
A semicolon is removed at the end of the error-handling code for the call
to dma_alloc_coherent.
The block of code calling fb_alloc_cmap is moved below the block of code
calling wm8505fb_set_par, so that the error-handing code of the call to
wm8505fb_set_par can just return ret. This way there is only one block of
error-handling code that needs to call fb_dealloc_cmap, and so this is
moved up to the place where it is needed, eliminating the need for all
gotos and labels in the function. This was suggested by Tony Prisk.
The initializations of fbi and ret at the beginning of the function are not
necessary and are removed. The call platform_set_drvdata(pdev, NULL); at
the end of the function is also removed.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Tony Prisk <linux@prisktech.co.nz>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
2013-04-03 02:20:36 +08:00
|
|
|
return ret;
|
2010-11-09 07:42:39 +08:00
|
|
|
}
|
|
|
|
|
drivers/video/wm8505fb.c: use devm_ functions
The various devm_ functions allocate memory that is released when a driver
detaches. This patch uses these functions for data that is allocated in
the probe function of a platform device and is only freed in the remove
function.
The patch makes some other cleanups. First, the original code used
devm_kzalloc, but kfree. This would lead to a double free. The problem
was found using the following semantic match (http://coccinelle.lip6.fr/):
// <smpl>
@@
expression x,e;
@@
x = devm_kzalloc(...)
... when != x = e
?-kfree(x,...);
// </smpl>
The error-handing code of devm_request_and_ioremap does not print any
warning message, because devm_request_and_ioremap does this.
The call to dma_alloc_coherent is converted to its devm equivalent,
dmam_alloc_coherent. This implicitly introduces a call to
dmam_free_coherent, which was completly missing in the original code.
A semicolon is removed at the end of the error-handling code for the call
to dma_alloc_coherent.
The block of code calling fb_alloc_cmap is moved below the block of code
calling wm8505fb_set_par, so that the error-handing code of the call to
wm8505fb_set_par can just return ret. This way there is only one block of
error-handling code that needs to call fb_dealloc_cmap, and so this is
moved up to the place where it is needed, eliminating the need for all
gotos and labels in the function. This was suggested by Tony Prisk.
The initializations of fbi and ret at the beginning of the function are not
necessary and are removed. The call platform_set_drvdata(pdev, NULL); at
the end of the function is also removed.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Tony Prisk <linux@prisktech.co.nz>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
2013-04-03 02:20:36 +08:00
|
|
|
if (fb_alloc_cmap(&fbi->fb.cmap, 256, 0) < 0) {
|
|
|
|
dev_err(&pdev->dev, "Failed to allocate color map\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
wm8505fb_init_hw(&fbi->fb);
|
|
|
|
|
2010-11-09 07:42:39 +08:00
|
|
|
platform_set_drvdata(pdev, fbi);
|
|
|
|
|
|
|
|
ret = register_framebuffer(&fbi->fb);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"Failed to register framebuffer device: %d\n", ret);
|
drivers/video/wm8505fb.c: use devm_ functions
The various devm_ functions allocate memory that is released when a driver
detaches. This patch uses these functions for data that is allocated in
the probe function of a platform device and is only freed in the remove
function.
The patch makes some other cleanups. First, the original code used
devm_kzalloc, but kfree. This would lead to a double free. The problem
was found using the following semantic match (http://coccinelle.lip6.fr/):
// <smpl>
@@
expression x,e;
@@
x = devm_kzalloc(...)
... when != x = e
?-kfree(x,...);
// </smpl>
The error-handing code of devm_request_and_ioremap does not print any
warning message, because devm_request_and_ioremap does this.
The call to dma_alloc_coherent is converted to its devm equivalent,
dmam_alloc_coherent. This implicitly introduces a call to
dmam_free_coherent, which was completly missing in the original code.
A semicolon is removed at the end of the error-handling code for the call
to dma_alloc_coherent.
The block of code calling fb_alloc_cmap is moved below the block of code
calling wm8505fb_set_par, so that the error-handing code of the call to
wm8505fb_set_par can just return ret. This way there is only one block of
error-handling code that needs to call fb_dealloc_cmap, and so this is
moved up to the place where it is needed, eliminating the need for all
gotos and labels in the function. This was suggested by Tony Prisk.
The initializations of fbi and ret at the beginning of the function are not
necessary and are removed. The call platform_set_drvdata(pdev, NULL); at
the end of the function is also removed.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Tony Prisk <linux@prisktech.co.nz>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
2013-04-03 02:20:36 +08:00
|
|
|
if (fbi->fb.cmap.len)
|
|
|
|
fb_dealloc_cmap(&fbi->fb.cmap);
|
|
|
|
return ret;
|
2010-11-09 07:42:39 +08:00
|
|
|
}
|
|
|
|
|
2013-09-20 09:35:55 +08:00
|
|
|
fb_info(&fbi->fb, "%s frame buffer at 0x%lx-0x%lx\n",
|
|
|
|
fbi->fb.fix.id, fbi->fb.fix.smem_start,
|
|
|
|
fbi->fb.fix.smem_start + fbi->fb.fix.smem_len - 1);
|
2010-11-09 07:42:39 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-22 05:07:39 +08:00
|
|
|
static int wm8505fb_remove(struct platform_device *pdev)
|
2010-11-09 07:42:39 +08:00
|
|
|
{
|
|
|
|
struct wm8505fb_info *fbi = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
unregister_framebuffer(&fbi->fb);
|
|
|
|
|
|
|
|
writel(0, fbi->regbase);
|
|
|
|
|
|
|
|
if (fbi->fb.cmap.len)
|
|
|
|
fb_dealloc_cmap(&fbi->fb.cmap);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-03 16:58:22 +08:00
|
|
|
static const struct of_device_id wmt_dt_ids[] = {
|
|
|
|
{ .compatible = "wm,wm8505-fb", },
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2010-11-09 07:42:39 +08:00
|
|
|
static struct platform_driver wm8505fb_driver = {
|
|
|
|
.probe = wm8505fb_probe,
|
2012-12-22 05:07:39 +08:00
|
|
|
.remove = wm8505fb_remove,
|
2010-11-09 07:42:39 +08:00
|
|
|
.driver = {
|
|
|
|
.name = DRIVER_NAME,
|
2013-09-30 16:45:32 +08:00
|
|
|
.of_match_table = wmt_dt_ids,
|
2019-07-31 20:43:47 +08:00
|
|
|
.dev_groups = wm8505fb_groups,
|
2010-11-09 07:42:39 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2011-11-26 10:25:54 +08:00
|
|
|
module_platform_driver(wm8505fb_driver);
|
2010-11-09 07:42:39 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Ed Spiridonov <edo.rus@gmail.com>");
|
|
|
|
MODULE_DESCRIPTION("Framebuffer driver for WMT WM8505");
|
2012-08-03 16:58:22 +08:00
|
|
|
MODULE_LICENSE("GPL v2");
|
|
|
|
MODULE_DEVICE_TABLE(of, wmt_dt_ids);
|