2008-07-24 12:31:24 +08:00
|
|
|
/*
|
|
|
|
* SuperH Mobile LCDC Framebuffer
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008 Magnus Damm
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
|
|
* License. See the file "COPYING" in the main directory of this archive
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/clk.h>
|
2009-08-14 18:49:08 +08:00
|
|
|
#include <linux/pm_runtime.h>
|
2008-07-24 12:31:24 +08:00
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
2008-12-19 14:34:41 +08:00
|
|
|
#include <linux/interrupt.h>
|
2011-12-13 21:02:28 +08:00
|
|
|
#include <linux/videodev2.h>
|
2009-07-01 14:50:31 +08:00
|
|
|
#include <linux/vmalloc.h>
|
2010-02-15 21:57:49 +08:00
|
|
|
#include <linux/ioctl.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2010-09-14 22:48:54 +08:00
|
|
|
#include <linux/console.h>
|
2011-02-16 11:49:01 +08:00
|
|
|
#include <linux/backlight.h>
|
|
|
|
#include <linux/gpio.h>
|
2011-07-04 04:17:28 +08:00
|
|
|
#include <linux/module.h>
|
2008-10-01 15:24:32 +08:00
|
|
|
#include <video/sh_mobile_lcdc.h>
|
2011-07-13 18:13:47 +08:00
|
|
|
#include <video/sh_mobile_meram.h>
|
2011-07-27 07:09:06 +08:00
|
|
|
#include <linux/atomic.h>
|
2008-07-24 12:31:24 +08:00
|
|
|
|
2010-09-03 15:20:23 +08:00
|
|
|
#include "sh_mobile_lcdcfb.h"
|
|
|
|
|
2009-09-15 20:00:30 +08:00
|
|
|
#define SIDE_B_OFFSET 0x1000
|
|
|
|
#define MIRROR_OFFSET 0x2000
|
2008-07-24 12:31:24 +08:00
|
|
|
|
2010-11-04 19:06:06 +08:00
|
|
|
#define MAX_XRES 1920
|
|
|
|
#define MAX_YRES 1080
|
2008-07-24 12:31:24 +08:00
|
|
|
|
2009-08-14 18:49:08 +08:00
|
|
|
static unsigned long lcdc_offs_mainlcd[NR_CH_REGS] = {
|
2008-07-24 12:31:24 +08:00
|
|
|
[LDDCKPAT1R] = 0x400,
|
|
|
|
[LDDCKPAT2R] = 0x404,
|
|
|
|
[LDMT1R] = 0x418,
|
|
|
|
[LDMT2R] = 0x41c,
|
|
|
|
[LDMT3R] = 0x420,
|
|
|
|
[LDDFR] = 0x424,
|
|
|
|
[LDSM1R] = 0x428,
|
2008-12-19 14:34:41 +08:00
|
|
|
[LDSM2R] = 0x42c,
|
2008-07-24 12:31:24 +08:00
|
|
|
[LDSA1R] = 0x430,
|
2011-02-24 13:47:13 +08:00
|
|
|
[LDSA2R] = 0x434,
|
2008-07-24 12:31:24 +08:00
|
|
|
[LDMLSR] = 0x438,
|
|
|
|
[LDHCNR] = 0x448,
|
|
|
|
[LDHSYNR] = 0x44c,
|
|
|
|
[LDVLNR] = 0x450,
|
|
|
|
[LDVSYNR] = 0x454,
|
|
|
|
[LDPMR] = 0x460,
|
2010-07-21 18:13:21 +08:00
|
|
|
[LDHAJR] = 0x4a0,
|
2008-07-24 12:31:24 +08:00
|
|
|
};
|
|
|
|
|
2009-08-14 18:49:08 +08:00
|
|
|
static unsigned long lcdc_offs_sublcd[NR_CH_REGS] = {
|
2008-07-24 12:31:24 +08:00
|
|
|
[LDDCKPAT1R] = 0x408,
|
|
|
|
[LDDCKPAT2R] = 0x40c,
|
|
|
|
[LDMT1R] = 0x600,
|
|
|
|
[LDMT2R] = 0x604,
|
|
|
|
[LDMT3R] = 0x608,
|
|
|
|
[LDDFR] = 0x60c,
|
|
|
|
[LDSM1R] = 0x610,
|
2008-12-19 14:34:41 +08:00
|
|
|
[LDSM2R] = 0x614,
|
2008-07-24 12:31:24 +08:00
|
|
|
[LDSA1R] = 0x618,
|
|
|
|
[LDMLSR] = 0x620,
|
|
|
|
[LDHCNR] = 0x624,
|
|
|
|
[LDHSYNR] = 0x628,
|
|
|
|
[LDVLNR] = 0x62c,
|
|
|
|
[LDVSYNR] = 0x630,
|
|
|
|
[LDPMR] = 0x63c,
|
|
|
|
};
|
|
|
|
|
2010-10-15 15:53:52 +08:00
|
|
|
static const struct fb_videomode default_720p = {
|
|
|
|
.name = "HDMI 720p",
|
|
|
|
.xres = 1280,
|
|
|
|
.yres = 720,
|
|
|
|
|
2010-11-04 19:06:01 +08:00
|
|
|
.left_margin = 220,
|
|
|
|
.right_margin = 110,
|
|
|
|
.hsync_len = 40,
|
2010-10-15 15:53:52 +08:00
|
|
|
|
|
|
|
.upper_margin = 20,
|
|
|
|
.lower_margin = 5,
|
|
|
|
.vsync_len = 5,
|
|
|
|
|
|
|
|
.pixclock = 13468,
|
2010-11-04 19:06:01 +08:00
|
|
|
.refresh = 60,
|
2010-10-15 15:53:52 +08:00
|
|
|
.sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT,
|
2009-08-14 18:49:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct sh_mobile_lcdc_priv {
|
|
|
|
void __iomem *base;
|
|
|
|
int irq;
|
|
|
|
atomic_t hw_usecnt;
|
|
|
|
struct device *dev;
|
|
|
|
struct clk *dot_clk;
|
|
|
|
unsigned long lddckr;
|
|
|
|
struct sh_mobile_lcdc_chan ch[2];
|
2010-07-21 18:13:21 +08:00
|
|
|
struct notifier_block notifier;
|
2009-08-14 18:49:08 +08:00
|
|
|
int started;
|
2011-12-13 21:02:28 +08:00
|
|
|
int forced_fourcc; /* 2 channel LCDC must share fourcc setting */
|
2011-05-18 19:10:07 +08:00
|
|
|
struct sh_mobile_meram_info *meram_dev;
|
2009-08-14 18:49:08 +08:00
|
|
|
};
|
|
|
|
|
2009-09-15 20:00:30 +08:00
|
|
|
static bool banked(int reg_nr)
|
|
|
|
{
|
|
|
|
switch (reg_nr) {
|
|
|
|
case LDMT1R:
|
|
|
|
case LDMT2R:
|
|
|
|
case LDMT3R:
|
|
|
|
case LDDFR:
|
|
|
|
case LDSM1R:
|
|
|
|
case LDSA1R:
|
2011-02-24 13:47:13 +08:00
|
|
|
case LDSA2R:
|
2009-09-15 20:00:30 +08:00
|
|
|
case LDMLSR:
|
|
|
|
case LDHCNR:
|
|
|
|
case LDHSYNR:
|
|
|
|
case LDVLNR:
|
|
|
|
case LDVSYNR:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-07-24 12:31:24 +08:00
|
|
|
static void lcdc_write_chan(struct sh_mobile_lcdc_chan *chan,
|
|
|
|
int reg_nr, unsigned long data)
|
|
|
|
{
|
|
|
|
iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr]);
|
2009-09-15 20:00:30 +08:00
|
|
|
if (banked(reg_nr))
|
|
|
|
iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr] +
|
|
|
|
SIDE_B_OFFSET);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lcdc_write_chan_mirror(struct sh_mobile_lcdc_chan *chan,
|
|
|
|
int reg_nr, unsigned long data)
|
|
|
|
{
|
|
|
|
iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr] +
|
|
|
|
MIRROR_OFFSET);
|
2008-07-24 12:31:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long lcdc_read_chan(struct sh_mobile_lcdc_chan *chan,
|
|
|
|
int reg_nr)
|
|
|
|
{
|
|
|
|
return ioread32(chan->lcdc->base + chan->reg_offs[reg_nr]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lcdc_write(struct sh_mobile_lcdc_priv *priv,
|
|
|
|
unsigned long reg_offs, unsigned long data)
|
|
|
|
{
|
|
|
|
iowrite32(data, priv->base + reg_offs);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long lcdc_read(struct sh_mobile_lcdc_priv *priv,
|
|
|
|
unsigned long reg_offs)
|
|
|
|
{
|
|
|
|
return ioread32(priv->base + reg_offs);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lcdc_wait_bit(struct sh_mobile_lcdc_priv *priv,
|
|
|
|
unsigned long reg_offs,
|
|
|
|
unsigned long mask, unsigned long until)
|
|
|
|
{
|
|
|
|
while ((lcdc_read(priv, reg_offs) & mask) != until)
|
|
|
|
cpu_relax();
|
|
|
|
}
|
|
|
|
|
|
|
|
static int lcdc_chan_is_sublcd(struct sh_mobile_lcdc_chan *chan)
|
|
|
|
{
|
|
|
|
return chan->cfg.chan == LCDC_CHAN_SUBLCD;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lcdc_sys_write_index(void *handle, unsigned long data)
|
|
|
|
{
|
|
|
|
struct sh_mobile_lcdc_chan *ch = handle;
|
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
lcdc_write(ch->lcdc, _LDDWD0R, data | LDDWDxR_WDACT);
|
|
|
|
lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
|
|
|
|
lcdc_write(ch->lcdc, _LDDWAR, LDDWAR_WA |
|
|
|
|
(lcdc_chan_is_sublcd(ch) ? 2 : 0));
|
|
|
|
lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
|
2008-07-24 12:31:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void lcdc_sys_write_data(void *handle, unsigned long data)
|
|
|
|
{
|
|
|
|
struct sh_mobile_lcdc_chan *ch = handle;
|
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
lcdc_write(ch->lcdc, _LDDWD0R, data | LDDWDxR_WDACT | LDDWDxR_RSW);
|
|
|
|
lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
|
|
|
|
lcdc_write(ch->lcdc, _LDDWAR, LDDWAR_WA |
|
|
|
|
(lcdc_chan_is_sublcd(ch) ? 2 : 0));
|
|
|
|
lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
|
2008-07-24 12:31:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long lcdc_sys_read_data(void *handle)
|
|
|
|
{
|
|
|
|
struct sh_mobile_lcdc_chan *ch = handle;
|
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
lcdc_write(ch->lcdc, _LDDRDR, LDDRDR_RSR);
|
|
|
|
lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
|
|
|
|
lcdc_write(ch->lcdc, _LDDRAR, LDDRAR_RA |
|
|
|
|
(lcdc_chan_is_sublcd(ch) ? 2 : 0));
|
2008-07-24 12:31:24 +08:00
|
|
|
udelay(1);
|
2011-07-13 18:13:47 +08:00
|
|
|
lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
|
2008-07-24 12:31:24 +08:00
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
return lcdc_read(ch->lcdc, _LDDRDR) & LDDRDR_DRD_MASK;
|
2008-07-24 12:31:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
|
|
|
|
lcdc_sys_write_index,
|
|
|
|
lcdc_sys_write_data,
|
|
|
|
lcdc_sys_read_data,
|
|
|
|
};
|
|
|
|
|
2011-12-13 21:02:28 +08:00
|
|
|
static int sh_mobile_format_fourcc(const struct fb_var_screeninfo *var)
|
|
|
|
{
|
|
|
|
if (var->grayscale > 1)
|
|
|
|
return var->grayscale;
|
|
|
|
|
|
|
|
switch (var->bits_per_pixel) {
|
|
|
|
case 16:
|
|
|
|
return V4L2_PIX_FMT_RGB565;
|
|
|
|
case 24:
|
|
|
|
return V4L2_PIX_FMT_BGR24;
|
|
|
|
case 32:
|
|
|
|
return V4L2_PIX_FMT_BGR32;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sh_mobile_format_is_fourcc(const struct fb_var_screeninfo *var)
|
|
|
|
{
|
|
|
|
return var->grayscale > 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool sh_mobile_format_is_yuv(const struct fb_var_screeninfo *var)
|
|
|
|
{
|
|
|
|
if (var->grayscale <= 1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
switch (var->grayscale) {
|
|
|
|
case V4L2_PIX_FMT_NV12:
|
|
|
|
case V4L2_PIX_FMT_NV21:
|
|
|
|
case V4L2_PIX_FMT_NV16:
|
|
|
|
case V4L2_PIX_FMT_NV61:
|
|
|
|
case V4L2_PIX_FMT_NV24:
|
|
|
|
case V4L2_PIX_FMT_NV42:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-19 14:34:41 +08:00
|
|
|
static void sh_mobile_lcdc_clk_on(struct sh_mobile_lcdc_priv *priv)
|
|
|
|
{
|
2009-08-14 18:49:08 +08:00
|
|
|
if (atomic_inc_and_test(&priv->hw_usecnt)) {
|
2008-12-19 14:34:41 +08:00
|
|
|
if (priv->dot_clk)
|
|
|
|
clk_enable(priv->dot_clk);
|
2011-07-11 17:05:49 +08:00
|
|
|
pm_runtime_get_sync(priv->dev);
|
2011-07-04 14:06:47 +08:00
|
|
|
if (priv->meram_dev && priv->meram_dev->pdev)
|
|
|
|
pm_runtime_get_sync(&priv->meram_dev->pdev->dev);
|
2008-12-19 14:34:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sh_mobile_lcdc_clk_off(struct sh_mobile_lcdc_priv *priv)
|
|
|
|
{
|
2009-08-14 18:49:08 +08:00
|
|
|
if (atomic_sub_return(1, &priv->hw_usecnt) == -1) {
|
2011-07-04 14:06:47 +08:00
|
|
|
if (priv->meram_dev && priv->meram_dev->pdev)
|
|
|
|
pm_runtime_put_sync(&priv->meram_dev->pdev->dev);
|
2009-08-14 18:49:08 +08:00
|
|
|
pm_runtime_put(priv->dev);
|
2011-07-11 17:05:49 +08:00
|
|
|
if (priv->dot_clk)
|
|
|
|
clk_disable(priv->dot_clk);
|
2008-12-19 14:34:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-01 14:50:31 +08:00
|
|
|
static int sh_mobile_lcdc_sginit(struct fb_info *info,
|
|
|
|
struct list_head *pagelist)
|
|
|
|
{
|
|
|
|
struct sh_mobile_lcdc_chan *ch = info->par;
|
|
|
|
unsigned int nr_pages_max = info->fix.smem_len >> PAGE_SHIFT;
|
|
|
|
struct page *page;
|
|
|
|
int nr_pages = 0;
|
|
|
|
|
|
|
|
sg_init_table(ch->sglist, nr_pages_max);
|
|
|
|
|
|
|
|
list_for_each_entry(page, pagelist, lru)
|
|
|
|
sg_set_page(&ch->sglist[nr_pages++], page, PAGE_SIZE, 0);
|
|
|
|
|
|
|
|
return nr_pages;
|
|
|
|
}
|
|
|
|
|
2008-12-19 14:34:41 +08:00
|
|
|
static void sh_mobile_lcdc_deferred_io(struct fb_info *info,
|
|
|
|
struct list_head *pagelist)
|
|
|
|
{
|
|
|
|
struct sh_mobile_lcdc_chan *ch = info->par;
|
2009-12-07 22:20:06 +08:00
|
|
|
struct sh_mobile_lcdc_board_cfg *bcfg = &ch->cfg.board_cfg;
|
2008-12-19 14:34:41 +08:00
|
|
|
|
|
|
|
/* enable clocks before accessing hardware */
|
|
|
|
sh_mobile_lcdc_clk_on(ch->lcdc);
|
|
|
|
|
2009-11-04 14:59:04 +08:00
|
|
|
/*
|
|
|
|
* It's possible to get here without anything on the pagelist via
|
|
|
|
* sh_mobile_lcdc_deferred_io_touch() or via a userspace fsync()
|
|
|
|
* invocation. In the former case, the acceleration routines are
|
|
|
|
* stepped in to when using the framebuffer console causing the
|
|
|
|
* workqueue to be scheduled without any dirty pages on the list.
|
|
|
|
*
|
|
|
|
* Despite this, a panel update is still needed given that the
|
|
|
|
* acceleration routines have their own methods for writing in
|
|
|
|
* that still need to be updated.
|
|
|
|
*
|
|
|
|
* The fsync() and empty pagelist case could be optimized for,
|
|
|
|
* but we don't bother, as any application exhibiting such
|
|
|
|
* behaviour is fundamentally broken anyways.
|
|
|
|
*/
|
|
|
|
if (!list_empty(pagelist)) {
|
|
|
|
unsigned int nr_pages = sh_mobile_lcdc_sginit(info, pagelist);
|
|
|
|
|
|
|
|
/* trigger panel update */
|
|
|
|
dma_map_sg(info->dev, ch->sglist, nr_pages, DMA_TO_DEVICE);
|
2009-12-07 22:20:06 +08:00
|
|
|
if (bcfg->start_transfer)
|
|
|
|
bcfg->start_transfer(bcfg->board_data, ch,
|
|
|
|
&sh_mobile_lcdc_sys_bus_ops);
|
2011-07-13 18:13:47 +08:00
|
|
|
lcdc_write_chan(ch, LDSM2R, LDSM2R_OSTRG);
|
2009-11-04 14:59:04 +08:00
|
|
|
dma_unmap_sg(info->dev, ch->sglist, nr_pages, DMA_TO_DEVICE);
|
2009-12-07 22:20:06 +08:00
|
|
|
} else {
|
|
|
|
if (bcfg->start_transfer)
|
|
|
|
bcfg->start_transfer(bcfg->board_data, ch,
|
|
|
|
&sh_mobile_lcdc_sys_bus_ops);
|
2011-07-13 18:13:47 +08:00
|
|
|
lcdc_write_chan(ch, LDSM2R, LDSM2R_OSTRG);
|
2009-12-07 22:20:06 +08:00
|
|
|
}
|
2008-12-19 14:34:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sh_mobile_lcdc_deferred_io_touch(struct fb_info *info)
|
|
|
|
{
|
|
|
|
struct fb_deferred_io *fbdefio = info->fbdefio;
|
|
|
|
|
|
|
|
if (fbdefio)
|
|
|
|
schedule_delayed_work(&info->deferred_work, fbdefio->delay);
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t sh_mobile_lcdc_irq(int irq, void *data)
|
|
|
|
{
|
|
|
|
struct sh_mobile_lcdc_priv *priv = data;
|
2009-03-13 23:36:55 +08:00
|
|
|
struct sh_mobile_lcdc_chan *ch;
|
2009-09-15 20:00:18 +08:00
|
|
|
unsigned long ldintr;
|
2009-03-13 23:36:55 +08:00
|
|
|
int is_sub;
|
|
|
|
int k;
|
2008-12-19 14:34:41 +08:00
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
/* Acknowledge interrupts and disable further VSYNC End IRQs. */
|
|
|
|
ldintr = lcdc_read(priv, _LDINTR);
|
|
|
|
lcdc_write(priv, _LDINTR, (ldintr ^ LDINTR_STATUS_MASK) & ~LDINTR_VEE);
|
2008-12-19 14:34:41 +08:00
|
|
|
|
2009-03-13 23:36:55 +08:00
|
|
|
/* figure out if this interrupt is for main or sub lcd */
|
2011-07-13 18:13:47 +08:00
|
|
|
is_sub = (lcdc_read(priv, _LDSR) & LDSR_MSS) ? 1 : 0;
|
2009-03-13 23:36:55 +08:00
|
|
|
|
2009-09-15 20:00:18 +08:00
|
|
|
/* wake up channel and disable clocks */
|
2009-03-13 23:36:55 +08:00
|
|
|
for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
|
|
|
|
ch = &priv->ch[k];
|
|
|
|
|
|
|
|
if (!ch->enabled)
|
|
|
|
continue;
|
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
/* Frame End */
|
2009-09-15 20:00:18 +08:00
|
|
|
if (ldintr & LDINTR_FS) {
|
|
|
|
if (is_sub == lcdc_chan_is_sublcd(ch)) {
|
|
|
|
ch->frame_end = 1;
|
|
|
|
wake_up(&ch->frame_end_wait);
|
2009-03-13 23:36:55 +08:00
|
|
|
|
2009-09-15 20:00:18 +08:00
|
|
|
sh_mobile_lcdc_clk_off(priv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* VSYNC End */
|
2010-02-15 21:57:49 +08:00
|
|
|
if (ldintr & LDINTR_VES)
|
|
|
|
complete(&ch->vsync_completion);
|
2009-03-13 23:36:55 +08:00
|
|
|
}
|
|
|
|
|
2008-12-19 14:34:41 +08:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2008-07-24 12:31:24 +08:00
|
|
|
static void sh_mobile_lcdc_start_stop(struct sh_mobile_lcdc_priv *priv,
|
|
|
|
int start)
|
|
|
|
{
|
|
|
|
unsigned long tmp = lcdc_read(priv, _LDCNT2R);
|
|
|
|
int k;
|
|
|
|
|
|
|
|
/* start or stop the lcdc */
|
|
|
|
if (start)
|
2011-07-13 18:13:47 +08:00
|
|
|
lcdc_write(priv, _LDCNT2R, tmp | LDCNT2R_DO);
|
2008-07-24 12:31:24 +08:00
|
|
|
else
|
2011-07-13 18:13:47 +08:00
|
|
|
lcdc_write(priv, _LDCNT2R, tmp & ~LDCNT2R_DO);
|
2008-07-24 12:31:24 +08:00
|
|
|
|
|
|
|
/* wait until power is applied/stopped on all channels */
|
|
|
|
for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
|
|
|
|
if (lcdc_read(priv, _LDCNT2R) & priv->ch[k].enabled)
|
|
|
|
while (1) {
|
2011-07-13 18:13:47 +08:00
|
|
|
tmp = lcdc_read_chan(&priv->ch[k], LDPMR)
|
|
|
|
& LDPMR_LPS;
|
|
|
|
if (start && tmp == LDPMR_LPS)
|
2008-07-24 12:31:24 +08:00
|
|
|
break;
|
|
|
|
if (!start && tmp == 0)
|
|
|
|
break;
|
|
|
|
cpu_relax();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!start)
|
|
|
|
lcdc_write(priv, _LDDCKSTPR, 1); /* stop dotclock */
|
|
|
|
}
|
|
|
|
|
2010-07-21 18:13:21 +08:00
|
|
|
static void sh_mobile_lcdc_geometry(struct sh_mobile_lcdc_chan *ch)
|
|
|
|
{
|
2010-09-03 15:20:27 +08:00
|
|
|
struct fb_var_screeninfo *var = &ch->info->var, *display_var = &ch->display_var;
|
|
|
|
unsigned long h_total, hsync_pos, display_h_total;
|
2010-07-21 18:13:21 +08:00
|
|
|
u32 tmp;
|
|
|
|
|
|
|
|
tmp = ch->ldmt1r_value;
|
2011-07-13 18:13:47 +08:00
|
|
|
tmp |= (var->sync & FB_SYNC_VERT_HIGH_ACT) ? 0 : LDMT1R_VPOL;
|
|
|
|
tmp |= (var->sync & FB_SYNC_HOR_HIGH_ACT) ? 0 : LDMT1R_HPOL;
|
|
|
|
tmp |= (ch->cfg.flags & LCDC_FLAGS_DWPOL) ? LDMT1R_DWPOL : 0;
|
|
|
|
tmp |= (ch->cfg.flags & LCDC_FLAGS_DIPOL) ? LDMT1R_DIPOL : 0;
|
|
|
|
tmp |= (ch->cfg.flags & LCDC_FLAGS_DAPOL) ? LDMT1R_DAPOL : 0;
|
|
|
|
tmp |= (ch->cfg.flags & LCDC_FLAGS_HSCNT) ? LDMT1R_HSCNT : 0;
|
|
|
|
tmp |= (ch->cfg.flags & LCDC_FLAGS_DWCNT) ? LDMT1R_DWCNT : 0;
|
2010-07-21 18:13:21 +08:00
|
|
|
lcdc_write_chan(ch, LDMT1R, tmp);
|
|
|
|
|
|
|
|
/* setup SYS bus */
|
|
|
|
lcdc_write_chan(ch, LDMT2R, ch->cfg.sys_bus_cfg.ldmt2r);
|
|
|
|
lcdc_write_chan(ch, LDMT3R, ch->cfg.sys_bus_cfg.ldmt3r);
|
|
|
|
|
|
|
|
/* horizontal configuration */
|
2010-09-03 15:20:27 +08:00
|
|
|
h_total = display_var->xres + display_var->hsync_len +
|
|
|
|
display_var->left_margin + display_var->right_margin;
|
2010-07-21 18:13:21 +08:00
|
|
|
tmp = h_total / 8; /* HTCN */
|
2010-09-03 15:20:27 +08:00
|
|
|
tmp |= (min(display_var->xres, var->xres) / 8) << 16; /* HDCN */
|
2010-07-21 18:13:21 +08:00
|
|
|
lcdc_write_chan(ch, LDHCNR, tmp);
|
|
|
|
|
2010-09-03 15:20:27 +08:00
|
|
|
hsync_pos = display_var->xres + display_var->right_margin;
|
2010-07-21 18:13:21 +08:00
|
|
|
tmp = hsync_pos / 8; /* HSYNP */
|
2010-09-03 15:20:27 +08:00
|
|
|
tmp |= (display_var->hsync_len / 8) << 16; /* HSYNW */
|
2010-07-21 18:13:21 +08:00
|
|
|
lcdc_write_chan(ch, LDHSYNR, tmp);
|
|
|
|
|
|
|
|
/* vertical configuration */
|
2010-09-03 15:20:27 +08:00
|
|
|
tmp = display_var->yres + display_var->vsync_len +
|
|
|
|
display_var->upper_margin + display_var->lower_margin; /* VTLN */
|
|
|
|
tmp |= min(display_var->yres, var->yres) << 16; /* VDLN */
|
2010-07-21 18:13:21 +08:00
|
|
|
lcdc_write_chan(ch, LDVLNR, tmp);
|
|
|
|
|
2010-09-03 15:20:27 +08:00
|
|
|
tmp = display_var->yres + display_var->lower_margin; /* VSYNP */
|
|
|
|
tmp |= display_var->vsync_len << 16; /* VSYNW */
|
2010-07-21 18:13:21 +08:00
|
|
|
lcdc_write_chan(ch, LDVSYNR, tmp);
|
|
|
|
|
|
|
|
/* Adjust horizontal synchronisation for HDMI */
|
2010-09-03 15:20:27 +08:00
|
|
|
display_h_total = display_var->xres + display_var->hsync_len +
|
|
|
|
display_var->left_margin + display_var->right_margin;
|
|
|
|
tmp = ((display_var->xres & 7) << 24) |
|
|
|
|
((display_h_total & 7) << 16) |
|
|
|
|
((display_var->hsync_len & 7) << 8) |
|
2011-11-09 12:33:29 +08:00
|
|
|
(hsync_pos & 7);
|
2010-07-21 18:13:21 +08:00
|
|
|
lcdc_write_chan(ch, LDHAJR, tmp);
|
|
|
|
}
|
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
/*
|
|
|
|
* __sh_mobile_lcdc_start - Configure and tart the LCDC
|
|
|
|
* @priv: LCDC device
|
|
|
|
*
|
|
|
|
* Configure all enabled channels and start the LCDC device. All external
|
|
|
|
* devices (clocks, MERAM, panels, ...) are not touched by this function.
|
|
|
|
*/
|
|
|
|
static void __sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv)
|
2008-07-24 12:31:24 +08:00
|
|
|
{
|
|
|
|
struct sh_mobile_lcdc_chan *ch;
|
|
|
|
unsigned long tmp;
|
2011-07-13 18:13:47 +08:00
|
|
|
int k, m;
|
2008-12-19 14:34:41 +08:00
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
/* Enable LCDC channels. Read data from external memory, avoid using the
|
|
|
|
* BEU for now.
|
|
|
|
*/
|
|
|
|
lcdc_write(priv, _LDCNT2R, priv->ch[0].enabled | priv->ch[1].enabled);
|
2008-07-24 12:31:24 +08:00
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
/* Stop the LCDC first and disable all interrupts. */
|
2008-07-24 12:31:24 +08:00
|
|
|
sh_mobile_lcdc_start_stop(priv, 0);
|
2011-07-13 18:13:47 +08:00
|
|
|
lcdc_write(priv, _LDINTR, 0);
|
2008-07-24 12:31:24 +08:00
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
/* Configure power supply, dot clocks and start them. */
|
2008-07-24 12:31:24 +08:00
|
|
|
tmp = priv->lddckr;
|
|
|
|
for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
|
|
|
|
ch = &priv->ch[k];
|
2011-07-13 18:13:47 +08:00
|
|
|
if (!ch->enabled)
|
2008-07-24 12:31:24 +08:00
|
|
|
continue;
|
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
/* Power supply */
|
|
|
|
lcdc_write_chan(ch, LDPMR, 0);
|
|
|
|
|
2008-07-24 12:31:24 +08:00
|
|
|
m = ch->cfg.clock_divider;
|
|
|
|
if (!m)
|
|
|
|
continue;
|
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
/* FIXME: sh7724 can only use 42, 48, 54 and 60 for the divider
|
|
|
|
* denominator.
|
|
|
|
*/
|
|
|
|
lcdc_write_chan(ch, LDDCKPAT1R, 0);
|
|
|
|
lcdc_write_chan(ch, LDDCKPAT2R, (1 << (m/2)) - 1);
|
|
|
|
|
2008-07-24 12:31:24 +08:00
|
|
|
if (m == 1)
|
2011-07-13 18:13:47 +08:00
|
|
|
m = LDDCKR_MOSEL;
|
2008-07-24 12:31:24 +08:00
|
|
|
tmp |= m << (lcdc_chan_is_sublcd(ch) ? 8 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
lcdc_write(priv, _LDDCKR, tmp);
|
|
|
|
lcdc_write(priv, _LDDCKSTPR, 0);
|
|
|
|
lcdc_wait_bit(priv, _LDDCKSTPR, ~0, 0);
|
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
/* Setup geometry, format, frame buffer memory and operation mode. */
|
2008-07-24 12:31:24 +08:00
|
|
|
for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
|
|
|
|
ch = &priv->ch[k];
|
|
|
|
if (!ch->enabled)
|
|
|
|
continue;
|
|
|
|
|
2010-07-21 18:13:21 +08:00
|
|
|
sh_mobile_lcdc_geometry(ch);
|
2008-07-24 12:31:24 +08:00
|
|
|
|
2011-12-13 21:02:28 +08:00
|
|
|
switch (sh_mobile_format_fourcc(&ch->info->var)) {
|
|
|
|
case V4L2_PIX_FMT_RGB565:
|
|
|
|
tmp = LDDFR_PKF_RGB16;
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_BGR24:
|
|
|
|
tmp = LDDFR_PKF_RGB24;
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_BGR32:
|
|
|
|
tmp = LDDFR_PKF_ARGB32;
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_NV12:
|
|
|
|
case V4L2_PIX_FMT_NV21:
|
|
|
|
tmp = LDDFR_CC | LDDFR_YF_420;
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_NV16:
|
|
|
|
case V4L2_PIX_FMT_NV61:
|
|
|
|
tmp = LDDFR_CC | LDDFR_YF_422;
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_NV24:
|
|
|
|
case V4L2_PIX_FMT_NV42:
|
|
|
|
tmp = LDDFR_CC | LDDFR_YF_444;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sh_mobile_format_is_yuv(&ch->info->var)) {
|
|
|
|
switch (ch->info->var.colorspace) {
|
|
|
|
case V4L2_COLORSPACE_REC709:
|
|
|
|
tmp |= LDDFR_CF1;
|
2011-02-24 13:47:13 +08:00
|
|
|
break;
|
2011-12-13 21:02:28 +08:00
|
|
|
case V4L2_COLORSPACE_JPEG:
|
|
|
|
tmp |= LDDFR_CF0;
|
2011-02-24 13:47:13 +08:00
|
|
|
break;
|
|
|
|
}
|
2011-01-05 18:21:00 +08:00
|
|
|
}
|
2011-05-18 19:10:07 +08:00
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
lcdc_write_chan(ch, LDDFR, tmp);
|
|
|
|
lcdc_write_chan(ch, LDMLSR, ch->pitch);
|
|
|
|
lcdc_write_chan(ch, LDSA1R, ch->base_addr_y);
|
2011-12-13 21:02:28 +08:00
|
|
|
if (sh_mobile_format_is_yuv(&ch->info->var))
|
2011-07-13 18:13:47 +08:00
|
|
|
lcdc_write_chan(ch, LDSA2R, ch->base_addr_c);
|
2011-05-18 19:10:07 +08:00
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
/* When using deferred I/O mode, configure the LCDC for one-shot
|
|
|
|
* operation and enable the frame end interrupt. Otherwise use
|
|
|
|
* continuous read mode.
|
|
|
|
*/
|
|
|
|
if (ch->ldmt1r_value & LDMT1R_IFM &&
|
|
|
|
ch->cfg.sys_bus_cfg.deferred_io_msec) {
|
|
|
|
lcdc_write_chan(ch, LDSM1R, LDSM1R_OS);
|
|
|
|
lcdc_write(priv, _LDINTR, LDINTR_FE);
|
|
|
|
} else {
|
|
|
|
lcdc_write_chan(ch, LDSM1R, 0);
|
|
|
|
}
|
|
|
|
}
|
2011-05-18 19:10:07 +08:00
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
/* Word and long word swap. */
|
2011-12-13 21:02:28 +08:00
|
|
|
switch (sh_mobile_format_fourcc(&priv->ch[0].info->var)) {
|
|
|
|
case V4L2_PIX_FMT_RGB565:
|
|
|
|
case V4L2_PIX_FMT_NV21:
|
|
|
|
case V4L2_PIX_FMT_NV61:
|
|
|
|
case V4L2_PIX_FMT_NV42:
|
|
|
|
tmp = LDDDSR_LS | LDDDSR_WS;
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_BGR24:
|
|
|
|
case V4L2_PIX_FMT_NV12:
|
|
|
|
case V4L2_PIX_FMT_NV16:
|
|
|
|
case V4L2_PIX_FMT_NV24:
|
2011-07-13 18:13:47 +08:00
|
|
|
tmp = LDDDSR_LS | LDDDSR_WS | LDDDSR_BS;
|
2011-12-13 21:02:28 +08:00
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_BGR32:
|
|
|
|
default:
|
|
|
|
tmp = LDDDSR_LS;
|
|
|
|
break;
|
2011-07-13 18:13:47 +08:00
|
|
|
}
|
|
|
|
lcdc_write(priv, _LDDDSR, tmp);
|
2011-05-18 19:10:07 +08:00
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
/* Enable the display output. */
|
|
|
|
lcdc_write(priv, _LDCNT1R, LDCNT1R_DE);
|
|
|
|
sh_mobile_lcdc_start_stop(priv, 1);
|
|
|
|
priv->started = 1;
|
|
|
|
}
|
2008-07-24 12:31:24 +08:00
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv)
|
|
|
|
{
|
|
|
|
struct sh_mobile_meram_info *mdev = priv->meram_dev;
|
|
|
|
struct sh_mobile_lcdc_board_cfg *board_cfg;
|
|
|
|
struct sh_mobile_lcdc_chan *ch;
|
|
|
|
unsigned long tmp;
|
|
|
|
int ret;
|
|
|
|
int k;
|
2008-07-24 12:31:24 +08:00
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
/* enable clocks before accessing the hardware */
|
|
|
|
for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
|
|
|
|
if (priv->ch[k].enabled)
|
|
|
|
sh_mobile_lcdc_clk_on(priv);
|
|
|
|
}
|
2008-12-19 14:34:41 +08:00
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
/* reset */
|
|
|
|
lcdc_write(priv, _LDCNT2R, lcdc_read(priv, _LDCNT2R) | LDCNT2R_BR);
|
|
|
|
lcdc_wait_bit(priv, _LDCNT2R, LDCNT2R_BR, 0);
|
2008-12-19 14:34:41 +08:00
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
|
|
|
|
ch = &priv->ch[k];
|
2008-12-19 14:34:41 +08:00
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
if (!ch->enabled)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
board_cfg = &ch->cfg.board_cfg;
|
|
|
|
if (board_cfg->setup_sys) {
|
|
|
|
ret = board_cfg->setup_sys(board_cfg->board_data, ch,
|
|
|
|
&sh_mobile_lcdc_sys_bus_ops);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2008-12-19 14:34:41 +08:00
|
|
|
}
|
2008-07-24 12:31:24 +08:00
|
|
|
}
|
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
/* Compute frame buffer base address and pitch for each channel. */
|
|
|
|
for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
|
|
|
|
struct sh_mobile_meram_cfg *cfg;
|
|
|
|
int pixelformat;
|
2008-07-24 12:31:24 +08:00
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
ch = &priv->ch[k];
|
|
|
|
if (!ch->enabled)
|
|
|
|
continue;
|
2008-07-24 12:31:24 +08:00
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
ch->base_addr_y = ch->info->fix.smem_start;
|
|
|
|
ch->base_addr_c = ch->base_addr_y
|
|
|
|
+ ch->info->var.xres
|
|
|
|
* ch->info->var.yres_virtual;
|
|
|
|
ch->pitch = ch->info->fix.line_length;
|
|
|
|
|
|
|
|
/* Enable MERAM if possible. */
|
|
|
|
cfg = ch->cfg.meram_cfg;
|
|
|
|
if (mdev == NULL || mdev->ops == NULL || cfg == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* we need to de-init configured ICBs before we can
|
|
|
|
* re-initialize them.
|
|
|
|
*/
|
|
|
|
if (ch->meram_enabled) {
|
|
|
|
mdev->ops->meram_unregister(mdev, cfg);
|
|
|
|
ch->meram_enabled = 0;
|
|
|
|
}
|
|
|
|
|
2011-12-13 21:02:28 +08:00
|
|
|
switch (sh_mobile_format_fourcc(&ch->info->var)) {
|
|
|
|
case V4L2_PIX_FMT_NV12:
|
|
|
|
case V4L2_PIX_FMT_NV21:
|
|
|
|
case V4L2_PIX_FMT_NV16:
|
|
|
|
case V4L2_PIX_FMT_NV61:
|
2011-07-13 18:13:47 +08:00
|
|
|
pixelformat = SH_MOBILE_MERAM_PF_NV;
|
2011-12-13 21:02:28 +08:00
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_NV24:
|
|
|
|
case V4L2_PIX_FMT_NV42:
|
|
|
|
pixelformat = SH_MOBILE_MERAM_PF_NV24;
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_RGB565:
|
|
|
|
case V4L2_PIX_FMT_BGR24:
|
|
|
|
case V4L2_PIX_FMT_BGR32:
|
|
|
|
default:
|
|
|
|
pixelformat = SH_MOBILE_MERAM_PF_RGB;
|
|
|
|
break;
|
|
|
|
}
|
2011-07-13 18:13:47 +08:00
|
|
|
|
|
|
|
ret = mdev->ops->meram_register(mdev, cfg, ch->pitch,
|
|
|
|
ch->info->var.yres, pixelformat,
|
|
|
|
ch->base_addr_y, ch->base_addr_c,
|
|
|
|
&ch->base_addr_y, &ch->base_addr_c,
|
|
|
|
&ch->pitch);
|
|
|
|
if (!ret)
|
|
|
|
ch->meram_enabled = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Start the LCDC. */
|
|
|
|
__sh_mobile_lcdc_start(priv);
|
|
|
|
|
|
|
|
/* Setup deferred I/O, tell the board code to enable the panels, and
|
|
|
|
* turn backlight on.
|
|
|
|
*/
|
2008-07-24 12:31:24 +08:00
|
|
|
for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
|
|
|
|
ch = &priv->ch[k];
|
2009-08-15 10:53:16 +08:00
|
|
|
if (!ch->enabled)
|
|
|
|
continue;
|
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
tmp = ch->cfg.sys_bus_cfg.deferred_io_msec;
|
|
|
|
if (ch->ldmt1r_value & LDMT1R_IFM && tmp) {
|
|
|
|
ch->defio.deferred_io = sh_mobile_lcdc_deferred_io;
|
|
|
|
ch->defio.delay = msecs_to_jiffies(tmp);
|
|
|
|
ch->info->fbdefio = &ch->defio;
|
|
|
|
fb_deferred_io_init(ch->info);
|
|
|
|
}
|
|
|
|
|
2008-07-24 12:31:24 +08:00
|
|
|
board_cfg = &ch->cfg.board_cfg;
|
2011-02-23 16:41:50 +08:00
|
|
|
if (board_cfg->display_on && try_module_get(board_cfg->owner)) {
|
2010-07-21 18:13:17 +08:00
|
|
|
board_cfg->display_on(board_cfg->board_data, ch->info);
|
2010-09-03 15:20:23 +08:00
|
|
|
module_put(board_cfg->owner);
|
|
|
|
}
|
2011-02-16 11:49:01 +08:00
|
|
|
|
|
|
|
if (ch->bl) {
|
|
|
|
ch->bl->props.power = FB_BLANK_UNBLANK;
|
|
|
|
backlight_update_status(ch->bl);
|
|
|
|
}
|
2008-07-24 12:31:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sh_mobile_lcdc_stop(struct sh_mobile_lcdc_priv *priv)
|
|
|
|
{
|
|
|
|
struct sh_mobile_lcdc_chan *ch;
|
|
|
|
struct sh_mobile_lcdc_board_cfg *board_cfg;
|
|
|
|
int k;
|
|
|
|
|
2009-03-13 23:36:55 +08:00
|
|
|
/* clean up deferred io and ask board code to disable panel */
|
2008-07-24 12:31:24 +08:00
|
|
|
for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
|
|
|
|
ch = &priv->ch[k];
|
2009-08-15 10:53:16 +08:00
|
|
|
if (!ch->enabled)
|
|
|
|
continue;
|
2008-12-19 14:34:41 +08:00
|
|
|
|
2009-03-13 23:36:55 +08:00
|
|
|
/* deferred io mode:
|
|
|
|
* flush frame, and wait for frame end interrupt
|
|
|
|
* clean up deferred io and enable clock
|
|
|
|
*/
|
2010-09-03 15:19:57 +08:00
|
|
|
if (ch->info && ch->info->fbdefio) {
|
2009-03-13 23:36:55 +08:00
|
|
|
ch->frame_end = 0;
|
2009-07-07 10:24:32 +08:00
|
|
|
schedule_delayed_work(&ch->info->deferred_work, 0);
|
2009-03-13 23:36:55 +08:00
|
|
|
wait_event(ch->frame_end_wait, ch->frame_end);
|
2009-07-07 10:24:32 +08:00
|
|
|
fb_deferred_io_cleanup(ch->info);
|
|
|
|
ch->info->fbdefio = NULL;
|
2009-03-13 23:36:55 +08:00
|
|
|
sh_mobile_lcdc_clk_on(priv);
|
2008-12-19 14:34:41 +08:00
|
|
|
}
|
2009-03-13 23:36:55 +08:00
|
|
|
|
2011-02-16 11:49:01 +08:00
|
|
|
if (ch->bl) {
|
|
|
|
ch->bl->props.power = FB_BLANK_POWERDOWN;
|
|
|
|
backlight_update_status(ch->bl);
|
|
|
|
}
|
|
|
|
|
2009-03-13 23:36:55 +08:00
|
|
|
board_cfg = &ch->cfg.board_cfg;
|
2011-02-23 16:41:50 +08:00
|
|
|
if (board_cfg->display_off && try_module_get(board_cfg->owner)) {
|
2009-03-13 23:36:55 +08:00
|
|
|
board_cfg->display_off(board_cfg->board_data);
|
2010-09-03 15:20:23 +08:00
|
|
|
module_put(board_cfg->owner);
|
|
|
|
}
|
2011-05-18 19:10:07 +08:00
|
|
|
|
|
|
|
/* disable the meram */
|
|
|
|
if (ch->meram_enabled) {
|
|
|
|
struct sh_mobile_meram_cfg *cfg;
|
|
|
|
struct sh_mobile_meram_info *mdev;
|
|
|
|
cfg = ch->cfg.meram_cfg;
|
|
|
|
mdev = priv->meram_dev;
|
|
|
|
mdev->ops->meram_unregister(mdev, cfg);
|
|
|
|
ch->meram_enabled = 0;
|
|
|
|
}
|
|
|
|
|
2008-07-24 12:31:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* stop the lcdc */
|
2009-05-20 22:34:43 +08:00
|
|
|
if (priv->started) {
|
|
|
|
sh_mobile_lcdc_start_stop(priv, 0);
|
|
|
|
priv->started = 0;
|
|
|
|
}
|
2008-10-31 19:23:26 +08:00
|
|
|
|
2008-12-19 14:34:41 +08:00
|
|
|
/* stop clocks */
|
|
|
|
for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
|
|
|
|
if (priv->ch[k].enabled)
|
|
|
|
sh_mobile_lcdc_clk_off(priv);
|
2008-07-24 12:31:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int sh_mobile_lcdc_check_interface(struct sh_mobile_lcdc_chan *ch)
|
|
|
|
{
|
2011-07-13 18:13:47 +08:00
|
|
|
int interface_type = ch->cfg.interface_type;
|
|
|
|
|
|
|
|
switch (interface_type) {
|
|
|
|
case RGB8:
|
|
|
|
case RGB9:
|
|
|
|
case RGB12A:
|
|
|
|
case RGB12B:
|
|
|
|
case RGB16:
|
|
|
|
case RGB18:
|
|
|
|
case RGB24:
|
|
|
|
case SYS8A:
|
|
|
|
case SYS8B:
|
|
|
|
case SYS8C:
|
|
|
|
case SYS8D:
|
|
|
|
case SYS9:
|
|
|
|
case SYS12:
|
|
|
|
case SYS16A:
|
|
|
|
case SYS16B:
|
|
|
|
case SYS16C:
|
|
|
|
case SYS18:
|
|
|
|
case SYS24:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
2008-07-24 12:31:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* SUBLCD only supports SYS interface */
|
|
|
|
if (lcdc_chan_is_sublcd(ch)) {
|
2011-07-13 18:13:47 +08:00
|
|
|
if (!(interface_type & LDMT1R_IFM))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
interface_type &= ~LDMT1R_IFM;
|
2008-07-24 12:31:24 +08:00
|
|
|
}
|
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
ch->ldmt1r_value = interface_type;
|
2008-07-24 12:31:24 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-10-31 19:23:26 +08:00
|
|
|
static int sh_mobile_lcdc_setup_clocks(struct platform_device *pdev,
|
|
|
|
int clock_source,
|
2008-07-24 12:31:24 +08:00
|
|
|
struct sh_mobile_lcdc_priv *priv)
|
|
|
|
{
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
switch (clock_source) {
|
2011-07-13 18:13:47 +08:00
|
|
|
case LCDC_CLK_BUS:
|
|
|
|
str = "bus_clk";
|
|
|
|
priv->lddckr = LDDCKR_ICKSEL_BUS;
|
|
|
|
break;
|
|
|
|
case LCDC_CLK_PERIPHERAL:
|
|
|
|
str = "peripheral_clk";
|
|
|
|
priv->lddckr = LDDCKR_ICKSEL_MIPI;
|
|
|
|
break;
|
|
|
|
case LCDC_CLK_EXTERNAL:
|
|
|
|
str = NULL;
|
|
|
|
priv->lddckr = LDDCKR_ICKSEL_HDMI;
|
|
|
|
break;
|
2008-07-24 12:31:24 +08:00
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (str) {
|
2008-10-31 19:23:26 +08:00
|
|
|
priv->dot_clk = clk_get(&pdev->dev, str);
|
|
|
|
if (IS_ERR(priv->dot_clk)) {
|
|
|
|
dev_err(&pdev->dev, "cannot get dot clock %s\n", str);
|
|
|
|
return PTR_ERR(priv->dot_clk);
|
2008-07-24 12:31:24 +08:00
|
|
|
}
|
|
|
|
}
|
2009-08-14 18:49:08 +08:00
|
|
|
|
|
|
|
/* Runtime PM support involves two step for this driver:
|
|
|
|
* 1) Enable Runtime PM
|
|
|
|
* 2) Force Runtime PM Resume since hardware is accessed from probe()
|
|
|
|
*/
|
2010-05-01 00:07:00 +08:00
|
|
|
priv->dev = &pdev->dev;
|
2009-08-14 18:49:08 +08:00
|
|
|
pm_runtime_enable(priv->dev);
|
|
|
|
pm_runtime_resume(priv->dev);
|
2008-07-24 12:31:24 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sh_mobile_lcdc_setcolreg(u_int regno,
|
|
|
|
u_int red, u_int green, u_int blue,
|
|
|
|
u_int transp, struct fb_info *info)
|
|
|
|
{
|
|
|
|
u32 *palette = info->pseudo_palette;
|
|
|
|
|
|
|
|
if (regno >= PALETTE_NR)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* only FB_VISUAL_TRUECOLOR supported */
|
|
|
|
|
|
|
|
red >>= 16 - info->var.red.length;
|
|
|
|
green >>= 16 - info->var.green.length;
|
|
|
|
blue >>= 16 - info->var.blue.length;
|
|
|
|
transp >>= 16 - info->var.transp.length;
|
|
|
|
|
|
|
|
palette[regno] = (red << info->var.red.offset) |
|
|
|
|
(green << info->var.green.offset) |
|
|
|
|
(blue << info->var.blue.offset) |
|
|
|
|
(transp << info->var.transp.offset);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct fb_fix_screeninfo sh_mobile_lcdc_fix = {
|
|
|
|
.id = "SH Mobile LCDC",
|
|
|
|
.type = FB_TYPE_PACKED_PIXELS,
|
|
|
|
.visual = FB_VISUAL_TRUECOLOR,
|
|
|
|
.accel = FB_ACCEL_NONE,
|
2009-09-15 20:00:18 +08:00
|
|
|
.xpanstep = 0,
|
|
|
|
.ypanstep = 1,
|
|
|
|
.ywrapstep = 0,
|
2011-12-13 21:02:28 +08:00
|
|
|
.capabilities = FB_CAP_FOURCC,
|
2008-07-24 12:31:24 +08:00
|
|
|
};
|
|
|
|
|
2008-12-19 14:34:41 +08:00
|
|
|
static void sh_mobile_lcdc_fillrect(struct fb_info *info,
|
|
|
|
const struct fb_fillrect *rect)
|
|
|
|
{
|
|
|
|
sys_fillrect(info, rect);
|
|
|
|
sh_mobile_lcdc_deferred_io_touch(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sh_mobile_lcdc_copyarea(struct fb_info *info,
|
|
|
|
const struct fb_copyarea *area)
|
|
|
|
{
|
|
|
|
sys_copyarea(info, area);
|
|
|
|
sh_mobile_lcdc_deferred_io_touch(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sh_mobile_lcdc_imageblit(struct fb_info *info,
|
|
|
|
const struct fb_image *image)
|
|
|
|
{
|
|
|
|
sys_imageblit(info, image);
|
|
|
|
sh_mobile_lcdc_deferred_io_touch(info);
|
|
|
|
}
|
|
|
|
|
2009-09-15 20:00:18 +08:00
|
|
|
static int sh_mobile_fb_pan_display(struct fb_var_screeninfo *var,
|
|
|
|
struct fb_info *info)
|
|
|
|
{
|
|
|
|
struct sh_mobile_lcdc_chan *ch = info->par;
|
2010-02-11 18:24:25 +08:00
|
|
|
struct sh_mobile_lcdc_priv *priv = ch->lcdc;
|
|
|
|
unsigned long ldrcntr;
|
|
|
|
unsigned long new_pan_offset;
|
2011-02-24 13:47:13 +08:00
|
|
|
unsigned long base_addr_y, base_addr_c;
|
|
|
|
unsigned long c_offset;
|
2011-12-13 21:02:28 +08:00
|
|
|
bool yuv = sh_mobile_format_is_yuv(&info->var);
|
2010-02-11 18:24:25 +08:00
|
|
|
|
2011-12-13 21:02:28 +08:00
|
|
|
if (!yuv)
|
2011-08-31 19:00:55 +08:00
|
|
|
new_pan_offset = var->yoffset * info->fix.line_length
|
|
|
|
+ var->xoffset * (info->var.bits_per_pixel / 8);
|
2011-02-24 13:47:13 +08:00
|
|
|
else
|
2011-08-31 19:00:55 +08:00
|
|
|
new_pan_offset = var->yoffset * info->fix.line_length
|
|
|
|
+ var->xoffset;
|
2009-09-15 20:00:18 +08:00
|
|
|
|
2010-02-11 18:24:25 +08:00
|
|
|
if (new_pan_offset == ch->pan_offset)
|
2009-09-15 20:00:18 +08:00
|
|
|
return 0; /* No change, do nothing */
|
|
|
|
|
2010-02-11 18:24:25 +08:00
|
|
|
ldrcntr = lcdc_read(priv, _LDRCNTR);
|
2009-09-15 20:00:18 +08:00
|
|
|
|
2010-02-11 18:24:25 +08:00
|
|
|
/* Set the source address for the next refresh */
|
2011-02-24 13:47:13 +08:00
|
|
|
base_addr_y = ch->dma_handle + new_pan_offset;
|
2011-12-13 21:02:28 +08:00
|
|
|
if (yuv) {
|
2011-02-24 13:47:13 +08:00
|
|
|
/* Set y offset */
|
2011-08-31 19:00:55 +08:00
|
|
|
c_offset = var->yoffset * info->fix.line_length
|
|
|
|
* (info->var.bits_per_pixel - 8) / 8;
|
|
|
|
base_addr_c = ch->dma_handle
|
|
|
|
+ info->var.xres * info->var.yres_virtual
|
|
|
|
+ c_offset;
|
2011-02-24 13:47:13 +08:00
|
|
|
/* Set x offset */
|
2011-12-13 21:02:28 +08:00
|
|
|
if (sh_mobile_format_fourcc(&info->var) == V4L2_PIX_FMT_NV24)
|
2011-02-24 13:47:13 +08:00
|
|
|
base_addr_c += 2 * var->xoffset;
|
|
|
|
else
|
|
|
|
base_addr_c += var->xoffset;
|
2011-07-13 18:13:47 +08:00
|
|
|
}
|
2011-02-24 13:47:13 +08:00
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
if (ch->meram_enabled) {
|
2011-05-18 19:10:07 +08:00
|
|
|
struct sh_mobile_meram_cfg *cfg;
|
|
|
|
struct sh_mobile_meram_info *mdev;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
cfg = ch->cfg.meram_cfg;
|
|
|
|
mdev = priv->meram_dev;
|
|
|
|
ret = mdev->ops->meram_update(mdev, cfg,
|
|
|
|
base_addr_y, base_addr_c,
|
2011-07-13 18:13:47 +08:00
|
|
|
&base_addr_y, &base_addr_c);
|
2011-05-18 19:10:07 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2011-07-13 18:13:47 +08:00
|
|
|
}
|
2011-05-18 19:10:07 +08:00
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
ch->base_addr_y = base_addr_y;
|
|
|
|
ch->base_addr_c = base_addr_c;
|
2011-05-18 19:10:07 +08:00
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
lcdc_write_chan_mirror(ch, LDSA1R, base_addr_y);
|
2011-12-13 21:02:28 +08:00
|
|
|
if (yuv)
|
2011-07-13 18:13:47 +08:00
|
|
|
lcdc_write_chan_mirror(ch, LDSA2R, base_addr_c);
|
2011-02-24 13:47:13 +08:00
|
|
|
|
2010-02-11 18:24:25 +08:00
|
|
|
if (lcdc_chan_is_sublcd(ch))
|
|
|
|
lcdc_write(ch->lcdc, _LDRCNTR, ldrcntr ^ LDRCNTR_SRS);
|
|
|
|
else
|
|
|
|
lcdc_write(ch->lcdc, _LDRCNTR, ldrcntr ^ LDRCNTR_MRS);
|
|
|
|
|
|
|
|
ch->pan_offset = new_pan_offset;
|
|
|
|
|
|
|
|
sh_mobile_lcdc_deferred_io_touch(info);
|
2009-09-15 20:00:18 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-15 21:57:49 +08:00
|
|
|
static int sh_mobile_wait_for_vsync(struct fb_info *info)
|
|
|
|
{
|
|
|
|
struct sh_mobile_lcdc_chan *ch = info->par;
|
|
|
|
unsigned long ldintr;
|
|
|
|
int ret;
|
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
/* Enable VSync End interrupt and be careful not to acknowledge any
|
|
|
|
* pending interrupt.
|
|
|
|
*/
|
2010-02-15 21:57:49 +08:00
|
|
|
ldintr = lcdc_read(ch->lcdc, _LDINTR);
|
2011-07-13 18:13:47 +08:00
|
|
|
ldintr |= LDINTR_VEE | LDINTR_STATUS_MASK;
|
2010-02-15 21:57:49 +08:00
|
|
|
lcdc_write(ch->lcdc, _LDINTR, ldintr);
|
|
|
|
|
|
|
|
ret = wait_for_completion_interruptible_timeout(&ch->vsync_completion,
|
|
|
|
msecs_to_jiffies(100));
|
|
|
|
if (!ret)
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sh_mobile_ioctl(struct fb_info *info, unsigned int cmd,
|
|
|
|
unsigned long arg)
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case FBIO_WAITFORVSYNC:
|
|
|
|
retval = sh_mobile_wait_for_vsync(info);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
retval = -ENOIOCTLCMD;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2010-09-14 22:48:54 +08:00
|
|
|
static void sh_mobile_fb_reconfig(struct fb_info *info)
|
|
|
|
{
|
|
|
|
struct sh_mobile_lcdc_chan *ch = info->par;
|
|
|
|
struct fb_videomode mode1, mode2;
|
|
|
|
struct fb_event event;
|
|
|
|
int evnt = FB_EVENT_MODE_CHANGE_ALL;
|
|
|
|
|
|
|
|
if (ch->use_count > 1 || (ch->use_count == 1 && !info->fbcon_par))
|
|
|
|
/* More framebuffer users are active */
|
|
|
|
return;
|
|
|
|
|
|
|
|
fb_var_to_videomode(&mode1, &ch->display_var);
|
|
|
|
fb_var_to_videomode(&mode2, &info->var);
|
|
|
|
|
|
|
|
if (fb_mode_is_equal(&mode1, &mode2))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Display has been re-plugged, framebuffer is free now, reconfigure */
|
|
|
|
if (fb_set_var(info, &ch->display_var) < 0)
|
|
|
|
/* Couldn't reconfigure, hopefully, can continue as before */
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* fb_set_var() calls the notifier change internally, only if
|
|
|
|
* FBINFO_MISC_USEREVENT flag is set. Since we do not want to fake a
|
|
|
|
* user event, we have to call the chain ourselves.
|
|
|
|
*/
|
|
|
|
event.info = info;
|
2010-11-16 05:43:22 +08:00
|
|
|
event.data = &mode1;
|
2010-09-14 22:48:54 +08:00
|
|
|
fb_notifier_call_chain(evnt, &event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Locking: both .fb_release() and .fb_open() are called with info->lock held if
|
|
|
|
* user == 1, or with console sem held, if user == 0.
|
|
|
|
*/
|
|
|
|
static int sh_mobile_release(struct fb_info *info, int user)
|
|
|
|
{
|
|
|
|
struct sh_mobile_lcdc_chan *ch = info->par;
|
|
|
|
|
|
|
|
mutex_lock(&ch->open_lock);
|
|
|
|
dev_dbg(info->dev, "%s(): %d users\n", __func__, ch->use_count);
|
|
|
|
|
|
|
|
ch->use_count--;
|
|
|
|
|
|
|
|
/* Nothing to reconfigure, when called from fbcon */
|
|
|
|
if (user) {
|
2011-01-26 07:07:35 +08:00
|
|
|
console_lock();
|
2010-09-14 22:48:54 +08:00
|
|
|
sh_mobile_fb_reconfig(info);
|
2011-01-26 07:07:35 +08:00
|
|
|
console_unlock();
|
2010-09-14 22:48:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&ch->open_lock);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sh_mobile_open(struct fb_info *info, int user)
|
|
|
|
{
|
|
|
|
struct sh_mobile_lcdc_chan *ch = info->par;
|
|
|
|
|
|
|
|
mutex_lock(&ch->open_lock);
|
|
|
|
ch->use_count++;
|
|
|
|
|
|
|
|
dev_dbg(info->dev, "%s(): %d users\n", __func__, ch->use_count);
|
|
|
|
mutex_unlock(&ch->open_lock);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sh_mobile_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
|
|
|
|
{
|
|
|
|
struct sh_mobile_lcdc_chan *ch = info->par;
|
2011-01-05 18:21:00 +08:00
|
|
|
struct sh_mobile_lcdc_priv *p = ch->lcdc;
|
2011-08-31 19:00:53 +08:00
|
|
|
unsigned int best_dist = (unsigned int)-1;
|
|
|
|
unsigned int best_xres = 0;
|
|
|
|
unsigned int best_yres = 0;
|
|
|
|
unsigned int i;
|
2010-09-14 22:48:54 +08:00
|
|
|
|
2011-08-31 19:00:53 +08:00
|
|
|
if (var->xres > MAX_XRES || var->yres > MAX_YRES)
|
2010-09-14 22:48:54 +08:00
|
|
|
return -EINVAL;
|
2011-08-31 19:00:53 +08:00
|
|
|
|
|
|
|
/* If board code provides us with a list of available modes, make sure
|
|
|
|
* we use one of them. Find the mode closest to the requested one. The
|
|
|
|
* distance between two modes is defined as the size of the
|
|
|
|
* non-overlapping parts of the two rectangles.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < ch->cfg.num_cfg; ++i) {
|
|
|
|
const struct fb_videomode *mode = &ch->cfg.lcd_cfg[i];
|
|
|
|
unsigned int dist;
|
|
|
|
|
|
|
|
/* We can only round up. */
|
|
|
|
if (var->xres > mode->xres || var->yres > mode->yres)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
dist = var->xres * var->yres + mode->xres * mode->yres
|
|
|
|
- 2 * min(var->xres, mode->xres)
|
|
|
|
* min(var->yres, mode->yres);
|
|
|
|
|
|
|
|
if (dist < best_dist) {
|
|
|
|
best_xres = mode->xres;
|
|
|
|
best_yres = mode->yres;
|
|
|
|
best_dist = dist;
|
|
|
|
}
|
2010-09-14 22:48:54 +08:00
|
|
|
}
|
2011-01-05 18:21:00 +08:00
|
|
|
|
2011-08-31 19:00:53 +08:00
|
|
|
/* If no available mode can be used, return an error. */
|
|
|
|
if (ch->cfg.num_cfg != 0) {
|
|
|
|
if (best_dist == (unsigned int)-1)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
var->xres = best_xres;
|
|
|
|
var->yres = best_yres;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure the virtual resolution is at least as big as the visible
|
|
|
|
* resolution.
|
|
|
|
*/
|
|
|
|
if (var->xres_virtual < var->xres)
|
|
|
|
var->xres_virtual = var->xres;
|
|
|
|
if (var->yres_virtual < var->yres)
|
|
|
|
var->yres_virtual = var->yres;
|
|
|
|
|
2011-12-13 21:02:28 +08:00
|
|
|
if (sh_mobile_format_is_fourcc(var)) {
|
|
|
|
switch (var->grayscale) {
|
|
|
|
case V4L2_PIX_FMT_NV12:
|
|
|
|
case V4L2_PIX_FMT_NV21:
|
|
|
|
var->bits_per_pixel = 12;
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_RGB565:
|
|
|
|
case V4L2_PIX_FMT_NV16:
|
|
|
|
case V4L2_PIX_FMT_NV61:
|
|
|
|
var->bits_per_pixel = 16;
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_BGR24:
|
|
|
|
case V4L2_PIX_FMT_NV24:
|
|
|
|
case V4L2_PIX_FMT_NV42:
|
|
|
|
var->bits_per_pixel = 24;
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_BGR32:
|
|
|
|
var->bits_per_pixel = 32;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Default to RGB and JPEG color-spaces for RGB and YUV formats
|
|
|
|
* respectively.
|
|
|
|
*/
|
|
|
|
if (!sh_mobile_format_is_yuv(var))
|
|
|
|
var->colorspace = V4L2_COLORSPACE_SRGB;
|
|
|
|
else if (var->colorspace != V4L2_COLORSPACE_REC709)
|
|
|
|
var->colorspace = V4L2_COLORSPACE_JPEG;
|
|
|
|
} else {
|
|
|
|
if (var->bits_per_pixel <= 16) { /* RGB 565 */
|
|
|
|
var->bits_per_pixel = 16;
|
|
|
|
var->red.offset = 11;
|
|
|
|
var->red.length = 5;
|
|
|
|
var->green.offset = 5;
|
|
|
|
var->green.length = 6;
|
|
|
|
var->blue.offset = 0;
|
|
|
|
var->blue.length = 5;
|
|
|
|
var->transp.offset = 0;
|
|
|
|
var->transp.length = 0;
|
|
|
|
} else if (var->bits_per_pixel <= 24) { /* RGB 888 */
|
|
|
|
var->bits_per_pixel = 24;
|
|
|
|
var->red.offset = 16;
|
|
|
|
var->red.length = 8;
|
|
|
|
var->green.offset = 8;
|
|
|
|
var->green.length = 8;
|
|
|
|
var->blue.offset = 0;
|
|
|
|
var->blue.length = 8;
|
|
|
|
var->transp.offset = 0;
|
|
|
|
var->transp.length = 0;
|
|
|
|
} else if (var->bits_per_pixel <= 32) { /* RGBA 888 */
|
|
|
|
var->bits_per_pixel = 32;
|
|
|
|
var->red.offset = 16;
|
|
|
|
var->red.length = 8;
|
|
|
|
var->green.offset = 8;
|
|
|
|
var->green.length = 8;
|
|
|
|
var->blue.offset = 0;
|
|
|
|
var->blue.length = 8;
|
|
|
|
var->transp.offset = 24;
|
|
|
|
var->transp.length = 8;
|
|
|
|
} else
|
|
|
|
return -EINVAL;
|
2011-01-05 18:21:00 +08:00
|
|
|
|
2011-12-13 21:02:28 +08:00
|
|
|
var->red.msb_right = 0;
|
|
|
|
var->green.msb_right = 0;
|
|
|
|
var->blue.msb_right = 0;
|
|
|
|
var->transp.msb_right = 0;
|
|
|
|
}
|
2011-08-31 19:00:53 +08:00
|
|
|
|
|
|
|
/* Make sure we don't exceed our allocated memory. */
|
|
|
|
if (var->xres_virtual * var->yres_virtual * var->bits_per_pixel / 8 >
|
|
|
|
info->fix.smem_len)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2011-12-13 21:02:28 +08:00
|
|
|
/* only accept the forced_fourcc for dual channel configurations */
|
|
|
|
if (p->forced_fourcc &&
|
|
|
|
p->forced_fourcc != sh_mobile_format_fourcc(var))
|
2011-01-05 18:21:00 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2010-09-14 22:48:54 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2010-02-15 21:57:49 +08:00
|
|
|
|
2011-08-31 19:00:54 +08:00
|
|
|
static int sh_mobile_set_par(struct fb_info *info)
|
|
|
|
{
|
|
|
|
struct sh_mobile_lcdc_chan *ch = info->par;
|
2011-08-31 19:00:56 +08:00
|
|
|
u32 line_length = info->fix.line_length;
|
2011-08-31 19:00:54 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
sh_mobile_lcdc_stop(ch->lcdc);
|
2011-08-31 19:00:56 +08:00
|
|
|
|
2011-12-13 21:02:28 +08:00
|
|
|
if (sh_mobile_format_is_yuv(&info->var))
|
2011-08-31 19:00:56 +08:00
|
|
|
info->fix.line_length = info->var.xres;
|
|
|
|
else
|
|
|
|
info->fix.line_length = info->var.xres
|
|
|
|
* info->var.bits_per_pixel / 8;
|
|
|
|
|
2011-08-31 19:00:54 +08:00
|
|
|
ret = sh_mobile_lcdc_start(ch->lcdc);
|
2011-08-31 19:00:56 +08:00
|
|
|
if (ret < 0) {
|
2011-08-31 19:00:54 +08:00
|
|
|
dev_err(info->dev, "%s: unable to restart LCDC\n", __func__);
|
2011-08-31 19:00:56 +08:00
|
|
|
info->fix.line_length = line_length;
|
|
|
|
}
|
2011-08-31 19:00:54 +08:00
|
|
|
|
2011-12-13 21:02:28 +08:00
|
|
|
if (sh_mobile_format_is_fourcc(&info->var)) {
|
|
|
|
info->fix.type = FB_TYPE_FOURCC;
|
|
|
|
info->fix.visual = FB_VISUAL_FOURCC;
|
|
|
|
} else {
|
|
|
|
info->fix.type = FB_TYPE_PACKED_PIXELS;
|
|
|
|
info->fix.visual = FB_VISUAL_TRUECOLOR;
|
|
|
|
}
|
|
|
|
|
2011-08-31 19:00:54 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-02-23 16:36:30 +08:00
|
|
|
/*
|
|
|
|
* Screen blanking. Behavior is as follows:
|
|
|
|
* FB_BLANK_UNBLANK: screen unblanked, clocks enabled
|
|
|
|
* FB_BLANK_NORMAL: screen blanked, clocks enabled
|
|
|
|
* FB_BLANK_VSYNC,
|
|
|
|
* FB_BLANK_HSYNC,
|
|
|
|
* FB_BLANK_POWEROFF: screen blanked, clocks disabled
|
|
|
|
*/
|
|
|
|
static int sh_mobile_lcdc_blank(int blank, struct fb_info *info)
|
|
|
|
{
|
|
|
|
struct sh_mobile_lcdc_chan *ch = info->par;
|
|
|
|
struct sh_mobile_lcdc_priv *p = ch->lcdc;
|
|
|
|
|
|
|
|
/* blank the screen? */
|
|
|
|
if (blank > FB_BLANK_UNBLANK && ch->blank_status == FB_BLANK_UNBLANK) {
|
|
|
|
struct fb_fillrect rect = {
|
|
|
|
.width = info->var.xres,
|
|
|
|
.height = info->var.yres,
|
|
|
|
};
|
|
|
|
sh_mobile_lcdc_fillrect(info, &rect);
|
|
|
|
}
|
|
|
|
/* turn clocks on? */
|
|
|
|
if (blank <= FB_BLANK_NORMAL && ch->blank_status > FB_BLANK_NORMAL) {
|
|
|
|
sh_mobile_lcdc_clk_on(p);
|
|
|
|
}
|
|
|
|
/* turn clocks off? */
|
|
|
|
if (blank > FB_BLANK_NORMAL && ch->blank_status <= FB_BLANK_NORMAL) {
|
|
|
|
/* make sure the screen is updated with the black fill before
|
|
|
|
* switching the clocks off. one vsync is not enough since
|
|
|
|
* blanking may occur in the middle of a refresh. deferred io
|
|
|
|
* mode will reenable the clocks and update the screen in time,
|
|
|
|
* so it does not need this. */
|
|
|
|
if (!info->fbdefio) {
|
|
|
|
sh_mobile_wait_for_vsync(info);
|
|
|
|
sh_mobile_wait_for_vsync(info);
|
|
|
|
}
|
|
|
|
sh_mobile_lcdc_clk_off(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
ch->blank_status = blank;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-24 12:31:24 +08:00
|
|
|
static struct fb_ops sh_mobile_lcdc_ops = {
|
2009-09-15 20:00:18 +08:00
|
|
|
.owner = THIS_MODULE,
|
2008-07-24 12:31:24 +08:00
|
|
|
.fb_setcolreg = sh_mobile_lcdc_setcolreg,
|
2008-12-17 16:29:49 +08:00
|
|
|
.fb_read = fb_sys_read,
|
|
|
|
.fb_write = fb_sys_write,
|
2008-12-19 14:34:41 +08:00
|
|
|
.fb_fillrect = sh_mobile_lcdc_fillrect,
|
|
|
|
.fb_copyarea = sh_mobile_lcdc_copyarea,
|
|
|
|
.fb_imageblit = sh_mobile_lcdc_imageblit,
|
2011-02-23 16:36:30 +08:00
|
|
|
.fb_blank = sh_mobile_lcdc_blank,
|
2009-09-15 20:00:18 +08:00
|
|
|
.fb_pan_display = sh_mobile_fb_pan_display,
|
2010-02-15 21:57:49 +08:00
|
|
|
.fb_ioctl = sh_mobile_ioctl,
|
2010-09-14 22:48:54 +08:00
|
|
|
.fb_open = sh_mobile_open,
|
|
|
|
.fb_release = sh_mobile_release,
|
|
|
|
.fb_check_var = sh_mobile_check_var,
|
2011-08-31 19:00:54 +08:00
|
|
|
.fb_set_par = sh_mobile_set_par,
|
2008-07-24 12:31:24 +08:00
|
|
|
};
|
|
|
|
|
2011-02-16 11:49:01 +08:00
|
|
|
static int sh_mobile_lcdc_update_bl(struct backlight_device *bdev)
|
|
|
|
{
|
|
|
|
struct sh_mobile_lcdc_chan *ch = bl_get_data(bdev);
|
|
|
|
struct sh_mobile_lcdc_board_cfg *cfg = &ch->cfg.board_cfg;
|
|
|
|
int brightness = bdev->props.brightness;
|
|
|
|
|
|
|
|
if (bdev->props.power != FB_BLANK_UNBLANK ||
|
|
|
|
bdev->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK))
|
|
|
|
brightness = 0;
|
|
|
|
|
|
|
|
return cfg->set_brightness(cfg->board_data, brightness);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sh_mobile_lcdc_get_brightness(struct backlight_device *bdev)
|
|
|
|
{
|
|
|
|
struct sh_mobile_lcdc_chan *ch = bl_get_data(bdev);
|
|
|
|
struct sh_mobile_lcdc_board_cfg *cfg = &ch->cfg.board_cfg;
|
|
|
|
|
|
|
|
return cfg->get_brightness(cfg->board_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sh_mobile_lcdc_check_fb(struct backlight_device *bdev,
|
|
|
|
struct fb_info *info)
|
|
|
|
{
|
|
|
|
return (info->bl_dev == bdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct backlight_ops sh_mobile_lcdc_bl_ops = {
|
|
|
|
.options = BL_CORE_SUSPENDRESUME,
|
|
|
|
.update_status = sh_mobile_lcdc_update_bl,
|
|
|
|
.get_brightness = sh_mobile_lcdc_get_brightness,
|
|
|
|
.check_fb = sh_mobile_lcdc_check_fb,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct backlight_device *sh_mobile_lcdc_bl_probe(struct device *parent,
|
|
|
|
struct sh_mobile_lcdc_chan *ch)
|
|
|
|
{
|
|
|
|
struct backlight_device *bl;
|
|
|
|
|
|
|
|
bl = backlight_device_register(ch->cfg.bl_info.name, parent, ch,
|
|
|
|
&sh_mobile_lcdc_bl_ops, NULL);
|
2011-03-21 23:03:13 +08:00
|
|
|
if (IS_ERR(bl)) {
|
|
|
|
dev_err(parent, "unable to register backlight device: %ld\n",
|
|
|
|
PTR_ERR(bl));
|
2011-02-16 11:49:01 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bl->props.max_brightness = ch->cfg.bl_info.max_brightness;
|
|
|
|
bl->props.brightness = bl->props.max_brightness;
|
|
|
|
backlight_update_status(bl);
|
|
|
|
|
|
|
|
return bl;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sh_mobile_lcdc_bl_remove(struct backlight_device *bdev)
|
|
|
|
{
|
|
|
|
backlight_device_unregister(bdev);
|
|
|
|
}
|
|
|
|
|
2009-03-13 23:36:55 +08:00
|
|
|
static int sh_mobile_lcdc_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
|
|
|
|
|
|
sh_mobile_lcdc_stop(platform_get_drvdata(pdev));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sh_mobile_lcdc_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
|
|
|
|
|
|
return sh_mobile_lcdc_start(platform_get_drvdata(pdev));
|
|
|
|
}
|
|
|
|
|
2009-08-14 18:49:08 +08:00
|
|
|
static int sh_mobile_lcdc_runtime_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
2011-07-13 18:13:47 +08:00
|
|
|
struct sh_mobile_lcdc_priv *priv = platform_get_drvdata(pdev);
|
2009-08-14 18:49:08 +08:00
|
|
|
|
|
|
|
/* turn off LCDC hardware */
|
2011-07-13 18:13:47 +08:00
|
|
|
lcdc_write(priv, _LDCNT1R, 0);
|
|
|
|
|
2009-08-14 18:49:08 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sh_mobile_lcdc_runtime_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
2011-07-13 18:13:47 +08:00
|
|
|
struct sh_mobile_lcdc_priv *priv = platform_get_drvdata(pdev);
|
2009-08-14 18:49:08 +08:00
|
|
|
|
2011-07-13 18:13:47 +08:00
|
|
|
__sh_mobile_lcdc_start(priv);
|
2009-08-14 18:49:08 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-15 10:00:08 +08:00
|
|
|
static const struct dev_pm_ops sh_mobile_lcdc_dev_pm_ops = {
|
2009-03-13 23:36:55 +08:00
|
|
|
.suspend = sh_mobile_lcdc_suspend,
|
|
|
|
.resume = sh_mobile_lcdc_resume,
|
2009-08-14 18:49:08 +08:00
|
|
|
.runtime_suspend = sh_mobile_lcdc_runtime_suspend,
|
|
|
|
.runtime_resume = sh_mobile_lcdc_runtime_resume,
|
2009-03-13 23:36:55 +08:00
|
|
|
};
|
|
|
|
|
2010-09-03 15:20:23 +08:00
|
|
|
/* locking: called with info->lock held */
|
2010-07-21 18:13:21 +08:00
|
|
|
static int sh_mobile_lcdc_notify(struct notifier_block *nb,
|
|
|
|
unsigned long action, void *data)
|
|
|
|
{
|
|
|
|
struct fb_event *event = data;
|
|
|
|
struct fb_info *info = event->info;
|
|
|
|
struct sh_mobile_lcdc_chan *ch = info->par;
|
|
|
|
struct sh_mobile_lcdc_board_cfg *board_cfg = &ch->cfg.board_cfg;
|
|
|
|
|
|
|
|
if (&ch->lcdc->notifier != nb)
|
2010-09-03 15:20:08 +08:00
|
|
|
return NOTIFY_DONE;
|
2010-07-21 18:13:21 +08:00
|
|
|
|
|
|
|
dev_dbg(info->dev, "%s(): action = %lu, data = %p\n",
|
|
|
|
__func__, action, event->data);
|
|
|
|
|
|
|
|
switch(action) {
|
|
|
|
case FB_EVENT_SUSPEND:
|
2011-02-23 16:41:50 +08:00
|
|
|
if (board_cfg->display_off && try_module_get(board_cfg->owner)) {
|
2010-07-21 18:13:21 +08:00
|
|
|
board_cfg->display_off(board_cfg->board_data);
|
2010-09-03 15:20:23 +08:00
|
|
|
module_put(board_cfg->owner);
|
|
|
|
}
|
2010-09-03 15:20:39 +08:00
|
|
|
sh_mobile_lcdc_stop(ch->lcdc);
|
2010-07-21 18:13:21 +08:00
|
|
|
break;
|
|
|
|
case FB_EVENT_RESUME:
|
2010-09-14 22:48:54 +08:00
|
|
|
mutex_lock(&ch->open_lock);
|
|
|
|
sh_mobile_fb_reconfig(info);
|
|
|
|
mutex_unlock(&ch->open_lock);
|
2010-07-21 18:13:21 +08:00
|
|
|
|
|
|
|
/* HDMI must be enabled before LCDC configuration */
|
2011-02-23 16:41:50 +08:00
|
|
|
if (board_cfg->display_on && try_module_get(board_cfg->owner)) {
|
2010-09-14 22:48:54 +08:00
|
|
|
board_cfg->display_on(board_cfg->board_data, info);
|
2010-09-03 15:20:23 +08:00
|
|
|
module_put(board_cfg->owner);
|
2010-07-21 18:13:21 +08:00
|
|
|
}
|
|
|
|
|
2011-05-06 00:33:40 +08:00
|
|
|
sh_mobile_lcdc_start(ch->lcdc);
|
2010-07-21 18:13:21 +08:00
|
|
|
}
|
|
|
|
|
2010-09-03 15:20:08 +08:00
|
|
|
return NOTIFY_OK;
|
2010-07-21 18:13:21 +08:00
|
|
|
}
|
|
|
|
|
2011-08-31 19:00:57 +08:00
|
|
|
static int sh_mobile_lcdc_remove(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct sh_mobile_lcdc_priv *priv = platform_get_drvdata(pdev);
|
|
|
|
struct fb_info *info;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
fb_unregister_client(&priv->notifier);
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(priv->ch); i++)
|
|
|
|
if (priv->ch[i].info && priv->ch[i].info->dev)
|
|
|
|
unregister_framebuffer(priv->ch[i].info);
|
|
|
|
|
|
|
|
sh_mobile_lcdc_stop(priv);
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(priv->ch); i++) {
|
|
|
|
info = priv->ch[i].info;
|
|
|
|
|
|
|
|
if (!info || !info->device)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (priv->ch[i].sglist)
|
|
|
|
vfree(priv->ch[i].sglist);
|
|
|
|
|
|
|
|
if (info->screen_base)
|
|
|
|
dma_free_coherent(&pdev->dev, info->fix.smem_len,
|
|
|
|
info->screen_base,
|
|
|
|
priv->ch[i].dma_handle);
|
|
|
|
fb_dealloc_cmap(&info->cmap);
|
|
|
|
framebuffer_release(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(priv->ch); i++) {
|
|
|
|
if (priv->ch[i].bl)
|
|
|
|
sh_mobile_lcdc_bl_remove(priv->ch[i].bl);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->dot_clk)
|
|
|
|
clk_put(priv->dot_clk);
|
|
|
|
|
|
|
|
if (priv->dev)
|
|
|
|
pm_runtime_disable(priv->dev);
|
|
|
|
|
|
|
|
if (priv->base)
|
|
|
|
iounmap(priv->base);
|
|
|
|
|
|
|
|
if (priv->irq)
|
|
|
|
free_irq(priv->irq, priv);
|
|
|
|
kfree(priv);
|
|
|
|
return 0;
|
|
|
|
}
|
2008-07-24 12:31:24 +08:00
|
|
|
|
2011-08-31 19:00:58 +08:00
|
|
|
static int __devinit sh_mobile_lcdc_channel_init(struct sh_mobile_lcdc_chan *ch,
|
|
|
|
struct device *dev)
|
2008-07-24 12:31:24 +08:00
|
|
|
{
|
2011-08-31 19:00:58 +08:00
|
|
|
struct sh_mobile_lcdc_chan_cfg *cfg = &ch->cfg;
|
|
|
|
const struct fb_videomode *max_mode;
|
|
|
|
const struct fb_videomode *mode;
|
|
|
|
struct fb_var_screeninfo *var;
|
2008-07-24 12:31:24 +08:00
|
|
|
struct fb_info *info;
|
2011-08-31 19:00:58 +08:00
|
|
|
unsigned int max_size;
|
|
|
|
int num_cfg;
|
|
|
|
void *buf;
|
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
|
2011-08-31 19:00:59 +08:00
|
|
|
mutex_init(&ch->open_lock);
|
|
|
|
|
|
|
|
/* Allocate the frame buffer device. */
|
2011-08-31 19:00:58 +08:00
|
|
|
ch->info = framebuffer_alloc(0, dev);
|
|
|
|
if (!ch->info) {
|
|
|
|
dev_err(dev, "unable to allocate fb_info\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
info = ch->info;
|
|
|
|
info->fbops = &sh_mobile_lcdc_ops;
|
|
|
|
info->par = ch;
|
2011-08-31 19:00:59 +08:00
|
|
|
info->pseudo_palette = &ch->pseudo_palette;
|
|
|
|
info->flags = FBINFO_FLAG_DEFAULT;
|
2011-08-31 19:00:58 +08:00
|
|
|
|
|
|
|
/* Iterate through the modes to validate them and find the highest
|
|
|
|
* resolution.
|
|
|
|
*/
|
|
|
|
max_mode = NULL;
|
|
|
|
max_size = 0;
|
|
|
|
|
|
|
|
for (i = 0, mode = cfg->lcd_cfg; i < cfg->num_cfg; i++, mode++) {
|
|
|
|
unsigned int size = mode->yres * mode->xres;
|
|
|
|
|
2011-12-13 21:02:28 +08:00
|
|
|
/* NV12/NV21 buffers must have even number of lines */
|
|
|
|
if ((cfg->fourcc == V4L2_PIX_FMT_NV12 ||
|
|
|
|
cfg->fourcc == V4L2_PIX_FMT_NV21) && (mode->yres & 0x1)) {
|
2011-08-31 19:00:58 +08:00
|
|
|
dev_err(dev, "yres must be multiple of 2 for YCbCr420 "
|
|
|
|
"mode.\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size > max_size) {
|
|
|
|
max_mode = mode;
|
|
|
|
max_size = size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!max_size)
|
|
|
|
max_size = MAX_XRES * MAX_YRES;
|
|
|
|
else
|
|
|
|
dev_dbg(dev, "Found largest videomode %ux%u\n",
|
|
|
|
max_mode->xres, max_mode->yres);
|
|
|
|
|
2011-08-31 19:00:59 +08:00
|
|
|
/* Create the mode list. */
|
2011-08-31 19:00:58 +08:00
|
|
|
if (cfg->lcd_cfg == NULL) {
|
|
|
|
mode = &default_720p;
|
|
|
|
num_cfg = 1;
|
|
|
|
} else {
|
|
|
|
mode = cfg->lcd_cfg;
|
|
|
|
num_cfg = cfg->num_cfg;
|
|
|
|
}
|
|
|
|
|
|
|
|
fb_videomode_to_modelist(mode, num_cfg, &info->modelist);
|
|
|
|
|
2011-08-31 19:00:59 +08:00
|
|
|
/* Initialize variable screen information using the first mode as
|
|
|
|
* default. The default Y virtual resolution is twice the panel size to
|
|
|
|
* allow for double-buffering.
|
|
|
|
*/
|
|
|
|
var = &info->var;
|
2011-08-31 19:00:58 +08:00
|
|
|
fb_videomode_to_var(var, mode);
|
|
|
|
var->width = cfg->lcd_size_cfg.width;
|
|
|
|
var->height = cfg->lcd_size_cfg.height;
|
|
|
|
var->yres_virtual = var->yres * 2;
|
|
|
|
var->activate = FB_ACTIVATE_NOW;
|
|
|
|
|
2011-12-13 21:02:28 +08:00
|
|
|
switch (cfg->fourcc) {
|
|
|
|
case V4L2_PIX_FMT_RGB565:
|
|
|
|
var->bits_per_pixel = 16;
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_BGR24:
|
|
|
|
var->bits_per_pixel = 24;
|
|
|
|
break;
|
|
|
|
case V4L2_PIX_FMT_BGR32:
|
|
|
|
var->bits_per_pixel = 32;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
var->grayscale = cfg->fourcc;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure the memory size check won't fail. smem_len is initialized
|
|
|
|
* later based on var.
|
|
|
|
*/
|
|
|
|
info->fix.smem_len = UINT_MAX;
|
2011-08-31 19:00:59 +08:00
|
|
|
ret = sh_mobile_check_var(var, info);
|
2011-08-31 19:00:58 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2011-12-13 21:02:28 +08:00
|
|
|
max_size = max_size * var->bits_per_pixel / 8 * 2;
|
|
|
|
|
2011-08-31 19:00:59 +08:00
|
|
|
/* Allocate frame buffer memory and color map. */
|
2011-12-13 21:02:28 +08:00
|
|
|
buf = dma_alloc_coherent(dev, max_size, &ch->dma_handle, GFP_KERNEL);
|
2011-08-31 19:00:58 +08:00
|
|
|
if (!buf) {
|
|
|
|
dev_err(dev, "unable to allocate buffer\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = fb_alloc_cmap(&info->cmap, PALETTE_NR, 0);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(dev, "unable to allocate cmap\n");
|
2011-12-13 21:02:28 +08:00
|
|
|
dma_free_coherent(dev, max_size, buf, ch->dma_handle);
|
2011-08-31 19:00:58 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-12-13 21:02:28 +08:00
|
|
|
/* Initialize fixed screen information. Restrict pan to 2 lines steps
|
|
|
|
* for NV12 and NV21.
|
|
|
|
*/
|
|
|
|
info->fix = sh_mobile_lcdc_fix;
|
2011-08-31 19:00:58 +08:00
|
|
|
info->fix.smem_start = ch->dma_handle;
|
2011-12-13 21:02:28 +08:00
|
|
|
info->fix.smem_len = max_size;
|
|
|
|
if (cfg->fourcc == V4L2_PIX_FMT_NV12 ||
|
|
|
|
cfg->fourcc == V4L2_PIX_FMT_NV21)
|
|
|
|
info->fix.ypanstep = 2;
|
|
|
|
|
|
|
|
if (sh_mobile_format_is_yuv(var)) {
|
2011-08-31 19:00:58 +08:00
|
|
|
info->fix.line_length = var->xres;
|
2011-12-13 21:02:28 +08:00
|
|
|
info->fix.visual = FB_VISUAL_FOURCC;
|
|
|
|
} else {
|
|
|
|
info->fix.line_length = var->xres * var->bits_per_pixel / 8;
|
|
|
|
info->fix.visual = FB_VISUAL_TRUECOLOR;
|
|
|
|
}
|
2011-08-31 19:00:58 +08:00
|
|
|
|
|
|
|
info->screen_base = buf;
|
|
|
|
info->device = dev;
|
|
|
|
ch->display_var = *var;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
|
|
|
|
{
|
2010-09-03 15:20:00 +08:00
|
|
|
struct sh_mobile_lcdc_info *pdata = pdev->dev.platform_data;
|
2011-08-31 19:00:58 +08:00
|
|
|
struct sh_mobile_lcdc_priv *priv;
|
2008-07-24 12:31:24 +08:00
|
|
|
struct resource *res;
|
2011-08-31 19:00:58 +08:00
|
|
|
int num_channels;
|
2008-07-24 12:31:24 +08:00
|
|
|
int error;
|
2011-08-31 19:00:58 +08:00
|
|
|
int i;
|
2008-07-24 12:31:24 +08:00
|
|
|
|
2010-09-03 15:20:00 +08:00
|
|
|
if (!pdata) {
|
2008-07-24 12:31:24 +08:00
|
|
|
dev_err(&pdev->dev, "no platform data defined\n");
|
2010-05-01 00:07:00 +08:00
|
|
|
return -EINVAL;
|
2008-07-24 12:31:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
2008-12-19 14:34:41 +08:00
|
|
|
i = platform_get_irq(pdev, 0);
|
|
|
|
if (!res || i < 0) {
|
|
|
|
dev_err(&pdev->dev, "cannot get platform resources\n");
|
2010-05-01 00:07:00 +08:00
|
|
|
return -ENOENT;
|
2008-07-24 12:31:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
|
|
|
|
if (!priv) {
|
|
|
|
dev_err(&pdev->dev, "cannot allocate device data\n");
|
2010-05-01 00:07:00 +08:00
|
|
|
return -ENOMEM;
|
2008-07-24 12:31:24 +08:00
|
|
|
}
|
|
|
|
|
2010-05-01 00:07:00 +08:00
|
|
|
platform_set_drvdata(pdev, priv);
|
|
|
|
|
2011-09-22 16:59:16 +08:00
|
|
|
error = request_irq(i, sh_mobile_lcdc_irq, 0,
|
2009-03-25 07:38:21 +08:00
|
|
|
dev_name(&pdev->dev), priv);
|
2008-12-19 14:34:41 +08:00
|
|
|
if (error) {
|
|
|
|
dev_err(&pdev->dev, "unable to request irq\n");
|
|
|
|
goto err1;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->irq = i;
|
2010-09-03 15:19:57 +08:00
|
|
|
atomic_set(&priv->hw_usecnt, -1);
|
2008-07-24 12:31:24 +08:00
|
|
|
|
2011-08-31 19:00:58 +08:00
|
|
|
for (i = 0, num_channels = 0; i < ARRAY_SIZE(pdata->ch); i++) {
|
|
|
|
struct sh_mobile_lcdc_chan *ch = priv->ch + num_channels;
|
2008-07-24 12:31:24 +08:00
|
|
|
|
2010-09-03 15:20:00 +08:00
|
|
|
ch->lcdc = priv;
|
|
|
|
memcpy(&ch->cfg, &pdata->ch[i], sizeof(pdata->ch[i]));
|
2008-07-24 12:31:24 +08:00
|
|
|
|
2010-09-03 15:20:00 +08:00
|
|
|
error = sh_mobile_lcdc_check_interface(ch);
|
2008-07-24 12:31:24 +08:00
|
|
|
if (error) {
|
|
|
|
dev_err(&pdev->dev, "unsupported interface type\n");
|
|
|
|
goto err1;
|
|
|
|
}
|
2010-09-03 15:20:00 +08:00
|
|
|
init_waitqueue_head(&ch->frame_end_wait);
|
|
|
|
init_completion(&ch->vsync_completion);
|
|
|
|
ch->pan_offset = 0;
|
2008-07-24 12:31:24 +08:00
|
|
|
|
2011-02-16 11:49:01 +08:00
|
|
|
/* probe the backlight is there is one defined */
|
|
|
|
if (ch->cfg.bl_info.max_brightness)
|
|
|
|
ch->bl = sh_mobile_lcdc_bl_probe(&pdev->dev, ch);
|
|
|
|
|
2008-07-24 12:31:24 +08:00
|
|
|
switch (pdata->ch[i].chan) {
|
|
|
|
case LCDC_CHAN_MAINLCD:
|
2011-07-13 18:13:47 +08:00
|
|
|
ch->enabled = LDCNT2R_ME;
|
2010-09-03 15:20:00 +08:00
|
|
|
ch->reg_offs = lcdc_offs_mainlcd;
|
2011-08-31 19:00:58 +08:00
|
|
|
num_channels++;
|
2008-07-24 12:31:24 +08:00
|
|
|
break;
|
|
|
|
case LCDC_CHAN_SUBLCD:
|
2011-07-13 18:13:47 +08:00
|
|
|
ch->enabled = LDCNT2R_SE;
|
2010-09-03 15:20:00 +08:00
|
|
|
ch->reg_offs = lcdc_offs_sublcd;
|
2011-08-31 19:00:58 +08:00
|
|
|
num_channels++;
|
2008-07-24 12:31:24 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-31 19:00:58 +08:00
|
|
|
if (!num_channels) {
|
2008-07-24 12:31:24 +08:00
|
|
|
dev_err(&pdev->dev, "no channels defined\n");
|
|
|
|
error = -EINVAL;
|
|
|
|
goto err1;
|
|
|
|
}
|
|
|
|
|
2011-12-13 21:02:28 +08:00
|
|
|
/* for dual channel LCDC (MAIN + SUB) force shared format setting */
|
2011-08-31 19:00:58 +08:00
|
|
|
if (num_channels == 2)
|
2011-12-13 21:02:28 +08:00
|
|
|
priv->forced_fourcc = pdata->ch[0].fourcc;
|
2011-01-05 18:21:00 +08:00
|
|
|
|
2010-06-30 17:26:35 +08:00
|
|
|
priv->base = ioremap_nocache(res->start, resource_size(res));
|
|
|
|
if (!priv->base)
|
|
|
|
goto err1;
|
|
|
|
|
2008-10-31 19:23:26 +08:00
|
|
|
error = sh_mobile_lcdc_setup_clocks(pdev, pdata->clock_source, priv);
|
2008-07-24 12:31:24 +08:00
|
|
|
if (error) {
|
|
|
|
dev_err(&pdev->dev, "unable to setup clocks\n");
|
|
|
|
goto err1;
|
|
|
|
}
|
|
|
|
|
2011-05-18 19:10:07 +08:00
|
|
|
priv->meram_dev = pdata->meram_dev;
|
|
|
|
|
2011-08-31 19:00:58 +08:00
|
|
|
for (i = 0; i < num_channels; i++) {
|
2010-09-03 15:20:00 +08:00
|
|
|
struct sh_mobile_lcdc_chan *ch = priv->ch + i;
|
2010-10-15 15:53:52 +08:00
|
|
|
|
2011-08-31 19:00:58 +08:00
|
|
|
error = sh_mobile_lcdc_channel_init(ch, &pdev->dev);
|
2008-07-24 12:31:24 +08:00
|
|
|
if (error)
|
2011-08-31 19:00:58 +08:00
|
|
|
goto err1;
|
2008-07-24 12:31:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
error = sh_mobile_lcdc_start(priv);
|
|
|
|
if (error) {
|
|
|
|
dev_err(&pdev->dev, "unable to start hardware\n");
|
|
|
|
goto err1;
|
|
|
|
}
|
|
|
|
|
2011-08-31 19:00:58 +08:00
|
|
|
for (i = 0; i < num_channels; i++) {
|
2009-07-01 14:50:31 +08:00
|
|
|
struct sh_mobile_lcdc_chan *ch = priv->ch + i;
|
2011-08-31 19:00:58 +08:00
|
|
|
struct fb_info *info = ch->info;
|
2009-07-01 14:50:31 +08:00
|
|
|
|
|
|
|
if (info->fbdefio) {
|
2010-05-01 00:07:00 +08:00
|
|
|
ch->sglist = vmalloc(sizeof(struct scatterlist) *
|
2009-07-01 14:50:31 +08:00
|
|
|
info->fix.smem_len >> PAGE_SHIFT);
|
2010-05-01 00:07:00 +08:00
|
|
|
if (!ch->sglist) {
|
2009-07-01 14:50:31 +08:00
|
|
|
dev_err(&pdev->dev, "cannot allocate sglist\n");
|
|
|
|
goto err1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-16 11:49:01 +08:00
|
|
|
info->bl_dev = ch->bl;
|
|
|
|
|
2009-07-01 14:50:31 +08:00
|
|
|
error = register_framebuffer(info);
|
2008-07-24 12:31:24 +08:00
|
|
|
if (error < 0)
|
|
|
|
goto err1;
|
|
|
|
|
2011-12-13 21:02:28 +08:00
|
|
|
dev_info(info->dev, "registered %s/%s as %dx%d %dbpp.\n",
|
|
|
|
pdev->name, (ch->cfg.chan == LCDC_CHAN_MAINLCD) ?
|
|
|
|
"mainlcd" : "sublcd", info->var.xres, info->var.yres,
|
|
|
|
info->var.bits_per_pixel);
|
2008-12-19 14:34:41 +08:00
|
|
|
|
|
|
|
/* deferred io mode: disable clock to save power */
|
2010-07-21 18:13:21 +08:00
|
|
|
if (info->fbdefio || info->state == FBINFO_STATE_SUSPENDED)
|
2008-12-19 14:34:41 +08:00
|
|
|
sh_mobile_lcdc_clk_off(priv);
|
2008-07-24 12:31:24 +08:00
|
|
|
}
|
|
|
|
|
2010-07-21 18:13:21 +08:00
|
|
|
/* Failure ignored */
|
|
|
|
priv->notifier.notifier_call = sh_mobile_lcdc_notify;
|
|
|
|
fb_register_client(&priv->notifier);
|
|
|
|
|
2008-07-24 12:31:24 +08:00
|
|
|
return 0;
|
2010-05-01 00:07:00 +08:00
|
|
|
err1:
|
2008-07-24 12:31:24 +08:00
|
|
|
sh_mobile_lcdc_remove(pdev);
|
2010-05-01 00:07:00 +08:00
|
|
|
|
2008-07-24 12:31:24 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver sh_mobile_lcdc_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "sh_mobile_lcdc_fb",
|
|
|
|
.owner = THIS_MODULE,
|
2009-03-13 23:36:55 +08:00
|
|
|
.pm = &sh_mobile_lcdc_dev_pm_ops,
|
2008-07-24 12:31:24 +08:00
|
|
|
},
|
|
|
|
.probe = sh_mobile_lcdc_probe,
|
|
|
|
.remove = sh_mobile_lcdc_remove,
|
|
|
|
};
|
|
|
|
|
2011-11-26 10:25:54 +08:00
|
|
|
module_platform_driver(sh_mobile_lcdc_driver);
|
2008-07-24 12:31:24 +08:00
|
|
|
|
|
|
|
MODULE_DESCRIPTION("SuperH Mobile LCDC Framebuffer driver");
|
|
|
|
MODULE_AUTHOR("Magnus Damm <damm@opensource.se>");
|
|
|
|
MODULE_LICENSE("GPL v2");
|