Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * SuperH Mobile LCDC Framebuffer |
| 3 | * |
| 4 | * Copyright (c) 2008 Magnus Damm |
| 5 | * |
| 6 | * This file is subject to the terms and conditions of the GNU General Public |
| 7 | * License. See the file "COPYING" in the main directory of this archive |
| 8 | * for more details. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/delay.h> |
| 14 | #include <linux/mm.h> |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 15 | #include <linux/clk.h> |
Magnus Damm | 0246c47 | 2009-08-14 10:49:08 +0000 | [diff] [blame] | 16 | #include <linux/pm_runtime.h> |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/dma-mapping.h> |
Magnus Damm | 8564557 | 2008-12-19 15:34:41 +0900 | [diff] [blame] | 19 | #include <linux/interrupt.h> |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 20 | #include <linux/videodev2.h> |
Paul Mundt | 1c6a307 | 2009-07-01 06:50:31 +0000 | [diff] [blame] | 21 | #include <linux/vmalloc.h> |
Phil Edworthy | 40331b2 | 2010-02-15 13:57:49 +0000 | [diff] [blame] | 22 | #include <linux/ioctl.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/slab.h> |
Guennadi Liakhovetski | dd21050 | 2010-09-14 14:48:54 +0000 | [diff] [blame] | 24 | #include <linux/console.h> |
Alexandre Courbot | 3b0fd9d | 2011-02-16 03:49:01 +0000 | [diff] [blame] | 25 | #include <linux/backlight.h> |
| 26 | #include <linux/gpio.h> |
Paul Gortmaker | 355b200 | 2011-07-03 16:17:28 -0400 | [diff] [blame] | 27 | #include <linux/module.h> |
Paul Mundt | 225c9a8 | 2008-10-01 16:24:32 +0900 | [diff] [blame] | 28 | #include <video/sh_mobile_lcdc.h> |
Laurent Pinchart | 8a20974 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 29 | #include <video/sh_mobile_meram.h> |
Arun Sharma | 6006349 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 30 | #include <linux/atomic.h> |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 31 | |
Guennadi Liakhovetski | 6de9edd | 2010-09-03 07:20:23 +0000 | [diff] [blame] | 32 | #include "sh_mobile_lcdcfb.h" |
| 33 | |
Phil Edworthy | a6f15ad | 2009-09-15 12:00:30 +0000 | [diff] [blame] | 34 | #define SIDE_B_OFFSET 0x1000 |
| 35 | #define MIRROR_OFFSET 0x2000 |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 36 | |
Guennadi Liakhovetski | d2ecbab | 2010-11-04 11:06:06 +0000 | [diff] [blame] | 37 | #define MAX_XRES 1920 |
| 38 | #define MAX_YRES 1080 |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 39 | |
Magnus Damm | 0246c47 | 2009-08-14 10:49:08 +0000 | [diff] [blame] | 40 | static unsigned long lcdc_offs_mainlcd[NR_CH_REGS] = { |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 41 | [LDDCKPAT1R] = 0x400, |
| 42 | [LDDCKPAT2R] = 0x404, |
| 43 | [LDMT1R] = 0x418, |
| 44 | [LDMT2R] = 0x41c, |
| 45 | [LDMT3R] = 0x420, |
| 46 | [LDDFR] = 0x424, |
| 47 | [LDSM1R] = 0x428, |
Magnus Damm | 8564557 | 2008-12-19 15:34:41 +0900 | [diff] [blame] | 48 | [LDSM2R] = 0x42c, |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 49 | [LDSA1R] = 0x430, |
Damian Hobson-Garcia | 53b5031 | 2011-02-24 05:47:13 +0000 | [diff] [blame] | 50 | [LDSA2R] = 0x434, |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 51 | [LDMLSR] = 0x438, |
| 52 | [LDHCNR] = 0x448, |
| 53 | [LDHSYNR] = 0x44c, |
| 54 | [LDVLNR] = 0x450, |
| 55 | [LDVSYNR] = 0x454, |
| 56 | [LDPMR] = 0x460, |
Guennadi Liakhovetski | 6011bde | 2010-07-21 10:13:21 +0000 | [diff] [blame] | 57 | [LDHAJR] = 0x4a0, |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
Magnus Damm | 0246c47 | 2009-08-14 10:49:08 +0000 | [diff] [blame] | 60 | static unsigned long lcdc_offs_sublcd[NR_CH_REGS] = { |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 61 | [LDDCKPAT1R] = 0x408, |
| 62 | [LDDCKPAT2R] = 0x40c, |
| 63 | [LDMT1R] = 0x600, |
| 64 | [LDMT2R] = 0x604, |
| 65 | [LDMT3R] = 0x608, |
| 66 | [LDDFR] = 0x60c, |
| 67 | [LDSM1R] = 0x610, |
Magnus Damm | 8564557 | 2008-12-19 15:34:41 +0900 | [diff] [blame] | 68 | [LDSM2R] = 0x614, |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 69 | [LDSA1R] = 0x618, |
| 70 | [LDMLSR] = 0x620, |
| 71 | [LDHCNR] = 0x624, |
| 72 | [LDHSYNR] = 0x628, |
| 73 | [LDVLNR] = 0x62c, |
| 74 | [LDVSYNR] = 0x630, |
| 75 | [LDPMR] = 0x63c, |
| 76 | }; |
| 77 | |
Guennadi Liakhovetski | c44f9f7 | 2010-10-15 07:53:52 +0000 | [diff] [blame] | 78 | static const struct fb_videomode default_720p = { |
| 79 | .name = "HDMI 720p", |
| 80 | .xres = 1280, |
| 81 | .yres = 720, |
| 82 | |
Guennadi Liakhovetski | 5ae0cf8 | 2010-11-04 11:06:01 +0000 | [diff] [blame] | 83 | .left_margin = 220, |
| 84 | .right_margin = 110, |
| 85 | .hsync_len = 40, |
Guennadi Liakhovetski | c44f9f7 | 2010-10-15 07:53:52 +0000 | [diff] [blame] | 86 | |
| 87 | .upper_margin = 20, |
| 88 | .lower_margin = 5, |
| 89 | .vsync_len = 5, |
| 90 | |
| 91 | .pixclock = 13468, |
Guennadi Liakhovetski | 5ae0cf8 | 2010-11-04 11:06:01 +0000 | [diff] [blame] | 92 | .refresh = 60, |
Guennadi Liakhovetski | c44f9f7 | 2010-10-15 07:53:52 +0000 | [diff] [blame] | 93 | .sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT, |
Magnus Damm | 0246c47 | 2009-08-14 10:49:08 +0000 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | struct sh_mobile_lcdc_priv { |
| 97 | void __iomem *base; |
| 98 | int irq; |
| 99 | atomic_t hw_usecnt; |
| 100 | struct device *dev; |
| 101 | struct clk *dot_clk; |
| 102 | unsigned long lddckr; |
| 103 | struct sh_mobile_lcdc_chan ch[2]; |
Guennadi Liakhovetski | 6011bde | 2010-07-21 10:13:21 +0000 | [diff] [blame] | 104 | struct notifier_block notifier; |
Magnus Damm | 0246c47 | 2009-08-14 10:49:08 +0000 | [diff] [blame] | 105 | int started; |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 106 | int forced_fourcc; /* 2 channel LCDC must share fourcc setting */ |
Damian | 7caa434 | 2011-05-18 11:10:07 +0000 | [diff] [blame] | 107 | struct sh_mobile_meram_info *meram_dev; |
Magnus Damm | 0246c47 | 2009-08-14 10:49:08 +0000 | [diff] [blame] | 108 | }; |
| 109 | |
Phil Edworthy | a6f15ad | 2009-09-15 12:00:30 +0000 | [diff] [blame] | 110 | static bool banked(int reg_nr) |
| 111 | { |
| 112 | switch (reg_nr) { |
| 113 | case LDMT1R: |
| 114 | case LDMT2R: |
| 115 | case LDMT3R: |
| 116 | case LDDFR: |
| 117 | case LDSM1R: |
| 118 | case LDSA1R: |
Damian Hobson-Garcia | 53b5031 | 2011-02-24 05:47:13 +0000 | [diff] [blame] | 119 | case LDSA2R: |
Phil Edworthy | a6f15ad | 2009-09-15 12:00:30 +0000 | [diff] [blame] | 120 | case LDMLSR: |
| 121 | case LDHCNR: |
| 122 | case LDHSYNR: |
| 123 | case LDVLNR: |
| 124 | case LDVSYNR: |
| 125 | return true; |
| 126 | } |
| 127 | return false; |
| 128 | } |
| 129 | |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 130 | static void lcdc_write_chan(struct sh_mobile_lcdc_chan *chan, |
| 131 | int reg_nr, unsigned long data) |
| 132 | { |
| 133 | iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr]); |
Phil Edworthy | a6f15ad | 2009-09-15 12:00:30 +0000 | [diff] [blame] | 134 | if (banked(reg_nr)) |
| 135 | iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr] + |
| 136 | SIDE_B_OFFSET); |
| 137 | } |
| 138 | |
| 139 | static void lcdc_write_chan_mirror(struct sh_mobile_lcdc_chan *chan, |
| 140 | int reg_nr, unsigned long data) |
| 141 | { |
| 142 | iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr] + |
| 143 | MIRROR_OFFSET); |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | static unsigned long lcdc_read_chan(struct sh_mobile_lcdc_chan *chan, |
| 147 | int reg_nr) |
| 148 | { |
| 149 | return ioread32(chan->lcdc->base + chan->reg_offs[reg_nr]); |
| 150 | } |
| 151 | |
| 152 | static void lcdc_write(struct sh_mobile_lcdc_priv *priv, |
| 153 | unsigned long reg_offs, unsigned long data) |
| 154 | { |
| 155 | iowrite32(data, priv->base + reg_offs); |
| 156 | } |
| 157 | |
| 158 | static unsigned long lcdc_read(struct sh_mobile_lcdc_priv *priv, |
| 159 | unsigned long reg_offs) |
| 160 | { |
| 161 | return ioread32(priv->base + reg_offs); |
| 162 | } |
| 163 | |
| 164 | static void lcdc_wait_bit(struct sh_mobile_lcdc_priv *priv, |
| 165 | unsigned long reg_offs, |
| 166 | unsigned long mask, unsigned long until) |
| 167 | { |
| 168 | while ((lcdc_read(priv, reg_offs) & mask) != until) |
| 169 | cpu_relax(); |
| 170 | } |
| 171 | |
| 172 | static int lcdc_chan_is_sublcd(struct sh_mobile_lcdc_chan *chan) |
| 173 | { |
| 174 | return chan->cfg.chan == LCDC_CHAN_SUBLCD; |
| 175 | } |
| 176 | |
| 177 | static void lcdc_sys_write_index(void *handle, unsigned long data) |
| 178 | { |
| 179 | struct sh_mobile_lcdc_chan *ch = handle; |
| 180 | |
Laurent Pinchart | ce1c0b0 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 181 | lcdc_write(ch->lcdc, _LDDWD0R, data | LDDWDxR_WDACT); |
| 182 | lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0); |
| 183 | lcdc_write(ch->lcdc, _LDDWAR, LDDWAR_WA | |
| 184 | (lcdc_chan_is_sublcd(ch) ? 2 : 0)); |
| 185 | lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0); |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | static void lcdc_sys_write_data(void *handle, unsigned long data) |
| 189 | { |
| 190 | struct sh_mobile_lcdc_chan *ch = handle; |
| 191 | |
Laurent Pinchart | ce1c0b0 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 192 | lcdc_write(ch->lcdc, _LDDWD0R, data | LDDWDxR_WDACT | LDDWDxR_RSW); |
| 193 | lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0); |
| 194 | lcdc_write(ch->lcdc, _LDDWAR, LDDWAR_WA | |
| 195 | (lcdc_chan_is_sublcd(ch) ? 2 : 0)); |
| 196 | lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0); |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | static unsigned long lcdc_sys_read_data(void *handle) |
| 200 | { |
| 201 | struct sh_mobile_lcdc_chan *ch = handle; |
| 202 | |
Laurent Pinchart | ce1c0b0 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 203 | lcdc_write(ch->lcdc, _LDDRDR, LDDRDR_RSR); |
| 204 | lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0); |
| 205 | lcdc_write(ch->lcdc, _LDDRAR, LDDRAR_RA | |
| 206 | (lcdc_chan_is_sublcd(ch) ? 2 : 0)); |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 207 | udelay(1); |
Laurent Pinchart | ce1c0b0 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 208 | lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0); |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 209 | |
Laurent Pinchart | ce1c0b0 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 210 | return lcdc_read(ch->lcdc, _LDDRDR) & LDDRDR_DRD_MASK; |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = { |
| 214 | lcdc_sys_write_index, |
| 215 | lcdc_sys_write_data, |
| 216 | lcdc_sys_read_data, |
| 217 | }; |
| 218 | |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 219 | static int sh_mobile_format_fourcc(const struct fb_var_screeninfo *var) |
| 220 | { |
| 221 | if (var->grayscale > 1) |
| 222 | return var->grayscale; |
| 223 | |
| 224 | switch (var->bits_per_pixel) { |
| 225 | case 16: |
| 226 | return V4L2_PIX_FMT_RGB565; |
| 227 | case 24: |
| 228 | return V4L2_PIX_FMT_BGR24; |
| 229 | case 32: |
| 230 | return V4L2_PIX_FMT_BGR32; |
| 231 | default: |
| 232 | return 0; |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | static int sh_mobile_format_is_fourcc(const struct fb_var_screeninfo *var) |
| 237 | { |
| 238 | return var->grayscale > 1; |
| 239 | } |
| 240 | |
| 241 | static bool sh_mobile_format_is_yuv(const struct fb_var_screeninfo *var) |
| 242 | { |
| 243 | if (var->grayscale <= 1) |
| 244 | return false; |
| 245 | |
| 246 | switch (var->grayscale) { |
| 247 | case V4L2_PIX_FMT_NV12: |
| 248 | case V4L2_PIX_FMT_NV21: |
| 249 | case V4L2_PIX_FMT_NV16: |
| 250 | case V4L2_PIX_FMT_NV61: |
| 251 | case V4L2_PIX_FMT_NV24: |
| 252 | case V4L2_PIX_FMT_NV42: |
| 253 | return true; |
| 254 | |
| 255 | default: |
| 256 | return false; |
| 257 | } |
| 258 | } |
| 259 | |
Magnus Damm | 8564557 | 2008-12-19 15:34:41 +0900 | [diff] [blame] | 260 | static void sh_mobile_lcdc_clk_on(struct sh_mobile_lcdc_priv *priv) |
| 261 | { |
Magnus Damm | 0246c47 | 2009-08-14 10:49:08 +0000 | [diff] [blame] | 262 | if (atomic_inc_and_test(&priv->hw_usecnt)) { |
Magnus Damm | 8564557 | 2008-12-19 15:34:41 +0900 | [diff] [blame] | 263 | if (priv->dot_clk) |
| 264 | clk_enable(priv->dot_clk); |
Laurent Pinchart | f1ad90d | 2011-07-11 11:05:49 +0200 | [diff] [blame] | 265 | pm_runtime_get_sync(priv->dev); |
Damian Hobson-Garcia | ec19b9e | 2011-07-04 08:06:47 +0200 | [diff] [blame] | 266 | if (priv->meram_dev && priv->meram_dev->pdev) |
| 267 | pm_runtime_get_sync(&priv->meram_dev->pdev->dev); |
Magnus Damm | 8564557 | 2008-12-19 15:34:41 +0900 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | |
| 271 | static void sh_mobile_lcdc_clk_off(struct sh_mobile_lcdc_priv *priv) |
| 272 | { |
Magnus Damm | 0246c47 | 2009-08-14 10:49:08 +0000 | [diff] [blame] | 273 | if (atomic_sub_return(1, &priv->hw_usecnt) == -1) { |
Damian Hobson-Garcia | ec19b9e | 2011-07-04 08:06:47 +0200 | [diff] [blame] | 274 | if (priv->meram_dev && priv->meram_dev->pdev) |
| 275 | pm_runtime_put_sync(&priv->meram_dev->pdev->dev); |
Magnus Damm | 0246c47 | 2009-08-14 10:49:08 +0000 | [diff] [blame] | 276 | pm_runtime_put(priv->dev); |
Laurent Pinchart | f1ad90d | 2011-07-11 11:05:49 +0200 | [diff] [blame] | 277 | if (priv->dot_clk) |
| 278 | clk_disable(priv->dot_clk); |
Magnus Damm | 8564557 | 2008-12-19 15:34:41 +0900 | [diff] [blame] | 279 | } |
| 280 | } |
Magnus Damm | 8564557 | 2008-12-19 15:34:41 +0900 | [diff] [blame] | 281 | |
Paul Mundt | 1c6a307 | 2009-07-01 06:50:31 +0000 | [diff] [blame] | 282 | static int sh_mobile_lcdc_sginit(struct fb_info *info, |
| 283 | struct list_head *pagelist) |
| 284 | { |
| 285 | struct sh_mobile_lcdc_chan *ch = info->par; |
| 286 | unsigned int nr_pages_max = info->fix.smem_len >> PAGE_SHIFT; |
| 287 | struct page *page; |
| 288 | int nr_pages = 0; |
| 289 | |
| 290 | sg_init_table(ch->sglist, nr_pages_max); |
| 291 | |
| 292 | list_for_each_entry(page, pagelist, lru) |
| 293 | sg_set_page(&ch->sglist[nr_pages++], page, PAGE_SIZE, 0); |
| 294 | |
| 295 | return nr_pages; |
| 296 | } |
| 297 | |
Magnus Damm | 8564557 | 2008-12-19 15:34:41 +0900 | [diff] [blame] | 298 | static void sh_mobile_lcdc_deferred_io(struct fb_info *info, |
| 299 | struct list_head *pagelist) |
| 300 | { |
| 301 | struct sh_mobile_lcdc_chan *ch = info->par; |
Magnus Damm | ef61aae | 2009-12-07 14:20:06 +0000 | [diff] [blame] | 302 | struct sh_mobile_lcdc_board_cfg *bcfg = &ch->cfg.board_cfg; |
Magnus Damm | 8564557 | 2008-12-19 15:34:41 +0900 | [diff] [blame] | 303 | |
| 304 | /* enable clocks before accessing hardware */ |
| 305 | sh_mobile_lcdc_clk_on(ch->lcdc); |
| 306 | |
Paul Mundt | 5c1a56b | 2009-11-04 15:59:04 +0900 | [diff] [blame] | 307 | /* |
| 308 | * It's possible to get here without anything on the pagelist via |
| 309 | * sh_mobile_lcdc_deferred_io_touch() or via a userspace fsync() |
| 310 | * invocation. In the former case, the acceleration routines are |
| 311 | * stepped in to when using the framebuffer console causing the |
| 312 | * workqueue to be scheduled without any dirty pages on the list. |
| 313 | * |
| 314 | * Despite this, a panel update is still needed given that the |
| 315 | * acceleration routines have their own methods for writing in |
| 316 | * that still need to be updated. |
| 317 | * |
| 318 | * The fsync() and empty pagelist case could be optimized for, |
| 319 | * but we don't bother, as any application exhibiting such |
| 320 | * behaviour is fundamentally broken anyways. |
| 321 | */ |
| 322 | if (!list_empty(pagelist)) { |
| 323 | unsigned int nr_pages = sh_mobile_lcdc_sginit(info, pagelist); |
Paul Mundt | 1c6a307 | 2009-07-01 06:50:31 +0000 | [diff] [blame] | 324 | |
Paul Mundt | 5c1a56b | 2009-11-04 15:59:04 +0900 | [diff] [blame] | 325 | /* trigger panel update */ |
| 326 | dma_map_sg(info->dev, ch->sglist, nr_pages, DMA_TO_DEVICE); |
Magnus Damm | ef61aae | 2009-12-07 14:20:06 +0000 | [diff] [blame] | 327 | if (bcfg->start_transfer) |
| 328 | bcfg->start_transfer(bcfg->board_data, ch, |
| 329 | &sh_mobile_lcdc_sys_bus_ops); |
Laurent Pinchart | ce1c0b0 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 330 | lcdc_write_chan(ch, LDSM2R, LDSM2R_OSTRG); |
Paul Mundt | 5c1a56b | 2009-11-04 15:59:04 +0900 | [diff] [blame] | 331 | dma_unmap_sg(info->dev, ch->sglist, nr_pages, DMA_TO_DEVICE); |
Magnus Damm | ef61aae | 2009-12-07 14:20:06 +0000 | [diff] [blame] | 332 | } else { |
| 333 | if (bcfg->start_transfer) |
| 334 | bcfg->start_transfer(bcfg->board_data, ch, |
| 335 | &sh_mobile_lcdc_sys_bus_ops); |
Laurent Pinchart | ce1c0b0 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 336 | lcdc_write_chan(ch, LDSM2R, LDSM2R_OSTRG); |
Magnus Damm | ef61aae | 2009-12-07 14:20:06 +0000 | [diff] [blame] | 337 | } |
Magnus Damm | 8564557 | 2008-12-19 15:34:41 +0900 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | static void sh_mobile_lcdc_deferred_io_touch(struct fb_info *info) |
| 341 | { |
| 342 | struct fb_deferred_io *fbdefio = info->fbdefio; |
| 343 | |
| 344 | if (fbdefio) |
| 345 | schedule_delayed_work(&info->deferred_work, fbdefio->delay); |
| 346 | } |
| 347 | |
| 348 | static irqreturn_t sh_mobile_lcdc_irq(int irq, void *data) |
| 349 | { |
| 350 | struct sh_mobile_lcdc_priv *priv = data; |
Magnus Damm | 2feb075 | 2009-03-13 15:36:55 +0000 | [diff] [blame] | 351 | struct sh_mobile_lcdc_chan *ch; |
Phil Edworthy | 9dd3881 | 2009-09-15 12:00:18 +0000 | [diff] [blame] | 352 | unsigned long ldintr; |
Magnus Damm | 2feb075 | 2009-03-13 15:36:55 +0000 | [diff] [blame] | 353 | int is_sub; |
| 354 | int k; |
Magnus Damm | 8564557 | 2008-12-19 15:34:41 +0900 | [diff] [blame] | 355 | |
Laurent Pinchart | dc48665 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 356 | /* Acknowledge interrupts and disable further VSYNC End IRQs. */ |
| 357 | ldintr = lcdc_read(priv, _LDINTR); |
| 358 | lcdc_write(priv, _LDINTR, (ldintr ^ LDINTR_STATUS_MASK) & ~LDINTR_VEE); |
Magnus Damm | 8564557 | 2008-12-19 15:34:41 +0900 | [diff] [blame] | 359 | |
Magnus Damm | 2feb075 | 2009-03-13 15:36:55 +0000 | [diff] [blame] | 360 | /* figure out if this interrupt is for main or sub lcd */ |
Laurent Pinchart | ce1c0b0 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 361 | is_sub = (lcdc_read(priv, _LDSR) & LDSR_MSS) ? 1 : 0; |
Magnus Damm | 2feb075 | 2009-03-13 15:36:55 +0000 | [diff] [blame] | 362 | |
Phil Edworthy | 9dd3881 | 2009-09-15 12:00:18 +0000 | [diff] [blame] | 363 | /* wake up channel and disable clocks */ |
Magnus Damm | 2feb075 | 2009-03-13 15:36:55 +0000 | [diff] [blame] | 364 | for (k = 0; k < ARRAY_SIZE(priv->ch); k++) { |
| 365 | ch = &priv->ch[k]; |
| 366 | |
| 367 | if (!ch->enabled) |
| 368 | continue; |
| 369 | |
Laurent Pinchart | dc48665 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 370 | /* Frame End */ |
Phil Edworthy | 9dd3881 | 2009-09-15 12:00:18 +0000 | [diff] [blame] | 371 | if (ldintr & LDINTR_FS) { |
| 372 | if (is_sub == lcdc_chan_is_sublcd(ch)) { |
| 373 | ch->frame_end = 1; |
| 374 | wake_up(&ch->frame_end_wait); |
Magnus Damm | 2feb075 | 2009-03-13 15:36:55 +0000 | [diff] [blame] | 375 | |
Phil Edworthy | 9dd3881 | 2009-09-15 12:00:18 +0000 | [diff] [blame] | 376 | sh_mobile_lcdc_clk_off(priv); |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | /* VSYNC End */ |
Phil Edworthy | 40331b2 | 2010-02-15 13:57:49 +0000 | [diff] [blame] | 381 | if (ldintr & LDINTR_VES) |
| 382 | complete(&ch->vsync_completion); |
Magnus Damm | 2feb075 | 2009-03-13 15:36:55 +0000 | [diff] [blame] | 383 | } |
| 384 | |
Magnus Damm | 8564557 | 2008-12-19 15:34:41 +0900 | [diff] [blame] | 385 | return IRQ_HANDLED; |
| 386 | } |
| 387 | |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 388 | static void sh_mobile_lcdc_start_stop(struct sh_mobile_lcdc_priv *priv, |
| 389 | int start) |
| 390 | { |
| 391 | unsigned long tmp = lcdc_read(priv, _LDCNT2R); |
| 392 | int k; |
| 393 | |
| 394 | /* start or stop the lcdc */ |
| 395 | if (start) |
Laurent Pinchart | ce1c0b0 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 396 | lcdc_write(priv, _LDCNT2R, tmp | LDCNT2R_DO); |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 397 | else |
Laurent Pinchart | ce1c0b0 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 398 | lcdc_write(priv, _LDCNT2R, tmp & ~LDCNT2R_DO); |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 399 | |
| 400 | /* wait until power is applied/stopped on all channels */ |
| 401 | for (k = 0; k < ARRAY_SIZE(priv->ch); k++) |
| 402 | if (lcdc_read(priv, _LDCNT2R) & priv->ch[k].enabled) |
| 403 | while (1) { |
Laurent Pinchart | ce1c0b0 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 404 | tmp = lcdc_read_chan(&priv->ch[k], LDPMR) |
| 405 | & LDPMR_LPS; |
| 406 | if (start && tmp == LDPMR_LPS) |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 407 | break; |
| 408 | if (!start && tmp == 0) |
| 409 | break; |
| 410 | cpu_relax(); |
| 411 | } |
| 412 | |
| 413 | if (!start) |
| 414 | lcdc_write(priv, _LDDCKSTPR, 1); /* stop dotclock */ |
| 415 | } |
| 416 | |
Guennadi Liakhovetski | 6011bde | 2010-07-21 10:13:21 +0000 | [diff] [blame] | 417 | static void sh_mobile_lcdc_geometry(struct sh_mobile_lcdc_chan *ch) |
| 418 | { |
Guennadi Liakhovetski | 1c120de | 2010-09-03 07:20:27 +0000 | [diff] [blame] | 419 | struct fb_var_screeninfo *var = &ch->info->var, *display_var = &ch->display_var; |
| 420 | unsigned long h_total, hsync_pos, display_h_total; |
Guennadi Liakhovetski | 6011bde | 2010-07-21 10:13:21 +0000 | [diff] [blame] | 421 | u32 tmp; |
| 422 | |
| 423 | tmp = ch->ldmt1r_value; |
Laurent Pinchart | ce1c0b0 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 424 | tmp |= (var->sync & FB_SYNC_VERT_HIGH_ACT) ? 0 : LDMT1R_VPOL; |
| 425 | tmp |= (var->sync & FB_SYNC_HOR_HIGH_ACT) ? 0 : LDMT1R_HPOL; |
| 426 | tmp |= (ch->cfg.flags & LCDC_FLAGS_DWPOL) ? LDMT1R_DWPOL : 0; |
| 427 | tmp |= (ch->cfg.flags & LCDC_FLAGS_DIPOL) ? LDMT1R_DIPOL : 0; |
| 428 | tmp |= (ch->cfg.flags & LCDC_FLAGS_DAPOL) ? LDMT1R_DAPOL : 0; |
| 429 | tmp |= (ch->cfg.flags & LCDC_FLAGS_HSCNT) ? LDMT1R_HSCNT : 0; |
| 430 | tmp |= (ch->cfg.flags & LCDC_FLAGS_DWCNT) ? LDMT1R_DWCNT : 0; |
Guennadi Liakhovetski | 6011bde | 2010-07-21 10:13:21 +0000 | [diff] [blame] | 431 | lcdc_write_chan(ch, LDMT1R, tmp); |
| 432 | |
| 433 | /* setup SYS bus */ |
| 434 | lcdc_write_chan(ch, LDMT2R, ch->cfg.sys_bus_cfg.ldmt2r); |
| 435 | lcdc_write_chan(ch, LDMT3R, ch->cfg.sys_bus_cfg.ldmt3r); |
| 436 | |
| 437 | /* horizontal configuration */ |
Guennadi Liakhovetski | 1c120de | 2010-09-03 07:20:27 +0000 | [diff] [blame] | 438 | h_total = display_var->xres + display_var->hsync_len + |
| 439 | display_var->left_margin + display_var->right_margin; |
Guennadi Liakhovetski | 6011bde | 2010-07-21 10:13:21 +0000 | [diff] [blame] | 440 | tmp = h_total / 8; /* HTCN */ |
Guennadi Liakhovetski | 1c120de | 2010-09-03 07:20:27 +0000 | [diff] [blame] | 441 | tmp |= (min(display_var->xres, var->xres) / 8) << 16; /* HDCN */ |
Guennadi Liakhovetski | 6011bde | 2010-07-21 10:13:21 +0000 | [diff] [blame] | 442 | lcdc_write_chan(ch, LDHCNR, tmp); |
| 443 | |
Guennadi Liakhovetski | 1c120de | 2010-09-03 07:20:27 +0000 | [diff] [blame] | 444 | hsync_pos = display_var->xres + display_var->right_margin; |
Guennadi Liakhovetski | 6011bde | 2010-07-21 10:13:21 +0000 | [diff] [blame] | 445 | tmp = hsync_pos / 8; /* HSYNP */ |
Guennadi Liakhovetski | 1c120de | 2010-09-03 07:20:27 +0000 | [diff] [blame] | 446 | tmp |= (display_var->hsync_len / 8) << 16; /* HSYNW */ |
Guennadi Liakhovetski | 6011bde | 2010-07-21 10:13:21 +0000 | [diff] [blame] | 447 | lcdc_write_chan(ch, LDHSYNR, tmp); |
| 448 | |
| 449 | /* vertical configuration */ |
Guennadi Liakhovetski | 1c120de | 2010-09-03 07:20:27 +0000 | [diff] [blame] | 450 | tmp = display_var->yres + display_var->vsync_len + |
| 451 | display_var->upper_margin + display_var->lower_margin; /* VTLN */ |
| 452 | tmp |= min(display_var->yres, var->yres) << 16; /* VDLN */ |
Guennadi Liakhovetski | 6011bde | 2010-07-21 10:13:21 +0000 | [diff] [blame] | 453 | lcdc_write_chan(ch, LDVLNR, tmp); |
| 454 | |
Guennadi Liakhovetski | 1c120de | 2010-09-03 07:20:27 +0000 | [diff] [blame] | 455 | tmp = display_var->yres + display_var->lower_margin; /* VSYNP */ |
| 456 | tmp |= display_var->vsync_len << 16; /* VSYNW */ |
Guennadi Liakhovetski | 6011bde | 2010-07-21 10:13:21 +0000 | [diff] [blame] | 457 | lcdc_write_chan(ch, LDVSYNR, tmp); |
| 458 | |
| 459 | /* Adjust horizontal synchronisation for HDMI */ |
Guennadi Liakhovetski | 1c120de | 2010-09-03 07:20:27 +0000 | [diff] [blame] | 460 | display_h_total = display_var->xres + display_var->hsync_len + |
| 461 | display_var->left_margin + display_var->right_margin; |
| 462 | tmp = ((display_var->xres & 7) << 24) | |
| 463 | ((display_h_total & 7) << 16) | |
| 464 | ((display_var->hsync_len & 7) << 8) | |
Kuninori Morimoto | 41e583c | 2011-11-08 20:33:29 -0800 | [diff] [blame] | 465 | (hsync_pos & 7); |
Guennadi Liakhovetski | 6011bde | 2010-07-21 10:13:21 +0000 | [diff] [blame] | 466 | lcdc_write_chan(ch, LDHAJR, tmp); |
| 467 | } |
| 468 | |
Laurent Pinchart | 9a217e3 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 469 | /* |
| 470 | * __sh_mobile_lcdc_start - Configure and tart the LCDC |
| 471 | * @priv: LCDC device |
| 472 | * |
| 473 | * Configure all enabled channels and start the LCDC device. All external |
| 474 | * devices (clocks, MERAM, panels, ...) are not touched by this function. |
| 475 | */ |
| 476 | static void __sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv) |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 477 | { |
| 478 | struct sh_mobile_lcdc_chan *ch; |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 479 | unsigned long tmp; |
Laurent Pinchart | 9a217e3 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 480 | int k, m; |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 481 | |
Laurent Pinchart | 9a217e3 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 482 | /* Enable LCDC channels. Read data from external memory, avoid using the |
| 483 | * BEU for now. |
| 484 | */ |
| 485 | lcdc_write(priv, _LDCNT2R, priv->ch[0].enabled | priv->ch[1].enabled); |
Magnus Damm | 8564557 | 2008-12-19 15:34:41 +0900 | [diff] [blame] | 486 | |
Laurent Pinchart | 9a217e3 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 487 | /* Stop the LCDC first and disable all interrupts. */ |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 488 | sh_mobile_lcdc_start_stop(priv, 0); |
Laurent Pinchart | 9a217e3 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 489 | lcdc_write(priv, _LDINTR, 0); |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 490 | |
Laurent Pinchart | 9a217e3 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 491 | /* Configure power supply, dot clocks and start them. */ |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 492 | tmp = priv->lddckr; |
| 493 | for (k = 0; k < ARRAY_SIZE(priv->ch); k++) { |
| 494 | ch = &priv->ch[k]; |
Laurent Pinchart | 9a217e3 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 495 | if (!ch->enabled) |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 496 | continue; |
| 497 | |
Laurent Pinchart | 9a217e3 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 498 | /* Power supply */ |
| 499 | lcdc_write_chan(ch, LDPMR, 0); |
| 500 | |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 501 | m = ch->cfg.clock_divider; |
| 502 | if (!m) |
| 503 | continue; |
| 504 | |
Laurent Pinchart | 505c7de5 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 505 | /* FIXME: sh7724 can only use 42, 48, 54 and 60 for the divider |
| 506 | * denominator. |
| 507 | */ |
| 508 | lcdc_write_chan(ch, LDDCKPAT1R, 0); |
| 509 | lcdc_write_chan(ch, LDDCKPAT2R, (1 << (m/2)) - 1); |
| 510 | |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 511 | if (m == 1) |
Laurent Pinchart | ce1c0b0 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 512 | m = LDDCKR_MOSEL; |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 513 | tmp |= m << (lcdc_chan_is_sublcd(ch) ? 8 : 0); |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | lcdc_write(priv, _LDDCKR, tmp); |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 517 | lcdc_write(priv, _LDDCKSTPR, 0); |
| 518 | lcdc_wait_bit(priv, _LDDCKSTPR, ~0, 0); |
| 519 | |
Laurent Pinchart | 9a217e3 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 520 | /* Setup geometry, format, frame buffer memory and operation mode. */ |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 521 | for (k = 0; k < ARRAY_SIZE(priv->ch); k++) { |
| 522 | ch = &priv->ch[k]; |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 523 | if (!ch->enabled) |
| 524 | continue; |
| 525 | |
Guennadi Liakhovetski | 6011bde | 2010-07-21 10:13:21 +0000 | [diff] [blame] | 526 | sh_mobile_lcdc_geometry(ch); |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 527 | |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 528 | switch (sh_mobile_format_fourcc(&ch->info->var)) { |
| 529 | case V4L2_PIX_FMT_RGB565: |
| 530 | tmp = LDDFR_PKF_RGB16; |
| 531 | break; |
| 532 | case V4L2_PIX_FMT_BGR24: |
| 533 | tmp = LDDFR_PKF_RGB24; |
| 534 | break; |
| 535 | case V4L2_PIX_FMT_BGR32: |
| 536 | tmp = LDDFR_PKF_ARGB32; |
| 537 | break; |
| 538 | case V4L2_PIX_FMT_NV12: |
| 539 | case V4L2_PIX_FMT_NV21: |
| 540 | tmp = LDDFR_CC | LDDFR_YF_420; |
| 541 | break; |
| 542 | case V4L2_PIX_FMT_NV16: |
| 543 | case V4L2_PIX_FMT_NV61: |
| 544 | tmp = LDDFR_CC | LDDFR_YF_422; |
| 545 | break; |
| 546 | case V4L2_PIX_FMT_NV24: |
| 547 | case V4L2_PIX_FMT_NV42: |
| 548 | tmp = LDDFR_CC | LDDFR_YF_444; |
| 549 | break; |
| 550 | } |
| 551 | |
| 552 | if (sh_mobile_format_is_yuv(&ch->info->var)) { |
| 553 | switch (ch->info->var.colorspace) { |
| 554 | case V4L2_COLORSPACE_REC709: |
| 555 | tmp |= LDDFR_CF1; |
Damian Hobson-Garcia | 53b5031 | 2011-02-24 05:47:13 +0000 | [diff] [blame] | 556 | break; |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 557 | case V4L2_COLORSPACE_JPEG: |
| 558 | tmp |= LDDFR_CF0; |
Damian Hobson-Garcia | 53b5031 | 2011-02-24 05:47:13 +0000 | [diff] [blame] | 559 | break; |
| 560 | } |
Magnus Damm | 417d482 | 2011-01-05 10:21:00 +0000 | [diff] [blame] | 561 | } |
Laurent Pinchart | 9a217e3 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 562 | |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 563 | lcdc_write_chan(ch, LDDFR, tmp); |
Laurent Pinchart | 9a217e3 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 564 | lcdc_write_chan(ch, LDMLSR, ch->pitch); |
| 565 | lcdc_write_chan(ch, LDSA1R, ch->base_addr_y); |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 566 | if (sh_mobile_format_is_yuv(&ch->info->var)) |
Laurent Pinchart | 9a217e3 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 567 | lcdc_write_chan(ch, LDSA2R, ch->base_addr_c); |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 568 | |
Laurent Pinchart | 9a217e3 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 569 | /* When using deferred I/O mode, configure the LCDC for one-shot |
| 570 | * operation and enable the frame end interrupt. Otherwise use |
| 571 | * continuous read mode. |
| 572 | */ |
| 573 | if (ch->ldmt1r_value & LDMT1R_IFM && |
| 574 | ch->cfg.sys_bus_cfg.deferred_io_msec) { |
| 575 | lcdc_write_chan(ch, LDSM1R, LDSM1R_OS); |
| 576 | lcdc_write(priv, _LDINTR, LDINTR_FE); |
| 577 | } else { |
| 578 | lcdc_write_chan(ch, LDSM1R, 0); |
| 579 | } |
| 580 | } |
Damian | 7caa434 | 2011-05-18 11:10:07 +0000 | [diff] [blame] | 581 | |
Laurent Pinchart | 9a217e3 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 582 | /* Word and long word swap. */ |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 583 | switch (sh_mobile_format_fourcc(&priv->ch[0].info->var)) { |
| 584 | case V4L2_PIX_FMT_RGB565: |
| 585 | case V4L2_PIX_FMT_NV21: |
| 586 | case V4L2_PIX_FMT_NV61: |
| 587 | case V4L2_PIX_FMT_NV42: |
| 588 | tmp = LDDDSR_LS | LDDDSR_WS; |
| 589 | break; |
| 590 | case V4L2_PIX_FMT_BGR24: |
| 591 | case V4L2_PIX_FMT_NV12: |
| 592 | case V4L2_PIX_FMT_NV16: |
| 593 | case V4L2_PIX_FMT_NV24: |
Laurent Pinchart | 9a217e3 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 594 | tmp = LDDDSR_LS | LDDDSR_WS | LDDDSR_BS; |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 595 | break; |
| 596 | case V4L2_PIX_FMT_BGR32: |
| 597 | default: |
| 598 | tmp = LDDDSR_LS; |
| 599 | break; |
Laurent Pinchart | 9a217e3 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 600 | } |
| 601 | lcdc_write(priv, _LDDDSR, tmp); |
Damian | 7caa434 | 2011-05-18 11:10:07 +0000 | [diff] [blame] | 602 | |
Laurent Pinchart | 9a217e3 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 603 | /* Enable the display output. */ |
| 604 | lcdc_write(priv, _LDCNT1R, LDCNT1R_DE); |
| 605 | sh_mobile_lcdc_start_stop(priv, 1); |
| 606 | priv->started = 1; |
| 607 | } |
Damian | 7caa434 | 2011-05-18 11:10:07 +0000 | [diff] [blame] | 608 | |
Laurent Pinchart | 9a217e3 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 609 | static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv) |
| 610 | { |
| 611 | struct sh_mobile_meram_info *mdev = priv->meram_dev; |
| 612 | struct sh_mobile_lcdc_board_cfg *board_cfg; |
| 613 | struct sh_mobile_lcdc_chan *ch; |
| 614 | unsigned long tmp; |
| 615 | int ret; |
| 616 | int k; |
| 617 | |
| 618 | /* enable clocks before accessing the hardware */ |
| 619 | for (k = 0; k < ARRAY_SIZE(priv->ch); k++) { |
| 620 | if (priv->ch[k].enabled) |
| 621 | sh_mobile_lcdc_clk_on(priv); |
| 622 | } |
| 623 | |
| 624 | /* reset */ |
| 625 | lcdc_write(priv, _LDCNT2R, lcdc_read(priv, _LDCNT2R) | LDCNT2R_BR); |
| 626 | lcdc_wait_bit(priv, _LDCNT2R, LDCNT2R_BR, 0); |
| 627 | |
| 628 | for (k = 0; k < ARRAY_SIZE(priv->ch); k++) { |
| 629 | ch = &priv->ch[k]; |
| 630 | |
| 631 | if (!ch->enabled) |
| 632 | continue; |
| 633 | |
| 634 | board_cfg = &ch->cfg.board_cfg; |
| 635 | if (board_cfg->setup_sys) { |
| 636 | ret = board_cfg->setup_sys(board_cfg->board_data, ch, |
| 637 | &sh_mobile_lcdc_sys_bus_ops); |
| 638 | if (ret) |
| 639 | return ret; |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | /* Compute frame buffer base address and pitch for each channel. */ |
| 644 | for (k = 0; k < ARRAY_SIZE(priv->ch); k++) { |
| 645 | struct sh_mobile_meram_cfg *cfg; |
| 646 | int pixelformat; |
| 647 | |
| 648 | ch = &priv->ch[k]; |
| 649 | if (!ch->enabled) |
| 650 | continue; |
| 651 | |
| 652 | ch->base_addr_y = ch->info->fix.smem_start; |
| 653 | ch->base_addr_c = ch->base_addr_y |
| 654 | + ch->info->var.xres |
| 655 | * ch->info->var.yres_virtual; |
| 656 | ch->pitch = ch->info->fix.line_length; |
| 657 | |
| 658 | /* Enable MERAM if possible. */ |
| 659 | cfg = ch->cfg.meram_cfg; |
| 660 | if (mdev == NULL || mdev->ops == NULL || cfg == NULL) |
| 661 | continue; |
| 662 | |
| 663 | /* we need to de-init configured ICBs before we can |
| 664 | * re-initialize them. |
| 665 | */ |
| 666 | if (ch->meram_enabled) { |
| 667 | mdev->ops->meram_unregister(mdev, cfg); |
Damian | 7caa434 | 2011-05-18 11:10:07 +0000 | [diff] [blame] | 668 | ch->meram_enabled = 0; |
Damian | 7caa434 | 2011-05-18 11:10:07 +0000 | [diff] [blame] | 669 | } |
| 670 | |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 671 | switch (sh_mobile_format_fourcc(&ch->info->var)) { |
| 672 | case V4L2_PIX_FMT_NV12: |
| 673 | case V4L2_PIX_FMT_NV21: |
| 674 | case V4L2_PIX_FMT_NV16: |
| 675 | case V4L2_PIX_FMT_NV61: |
Laurent Pinchart | 9a217e3 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 676 | pixelformat = SH_MOBILE_MERAM_PF_NV; |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 677 | break; |
| 678 | case V4L2_PIX_FMT_NV24: |
| 679 | case V4L2_PIX_FMT_NV42: |
| 680 | pixelformat = SH_MOBILE_MERAM_PF_NV24; |
| 681 | break; |
| 682 | case V4L2_PIX_FMT_RGB565: |
| 683 | case V4L2_PIX_FMT_BGR24: |
| 684 | case V4L2_PIX_FMT_BGR32: |
| 685 | default: |
| 686 | pixelformat = SH_MOBILE_MERAM_PF_RGB; |
| 687 | break; |
| 688 | } |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 689 | |
Laurent Pinchart | 9a217e3 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 690 | ret = mdev->ops->meram_register(mdev, cfg, ch->pitch, |
| 691 | ch->info->var.yres, pixelformat, |
| 692 | ch->base_addr_y, ch->base_addr_c, |
| 693 | &ch->base_addr_y, &ch->base_addr_c, |
| 694 | &ch->pitch); |
| 695 | if (!ret) |
| 696 | ch->meram_enabled = 1; |
| 697 | } |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 698 | |
Laurent Pinchart | 9a217e3 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 699 | /* Start the LCDC. */ |
| 700 | __sh_mobile_lcdc_start(priv); |
| 701 | |
| 702 | /* Setup deferred I/O, tell the board code to enable the panels, and |
| 703 | * turn backlight on. |
| 704 | */ |
| 705 | for (k = 0; k < ARRAY_SIZE(priv->ch); k++) { |
| 706 | ch = &priv->ch[k]; |
| 707 | if (!ch->enabled) |
| 708 | continue; |
| 709 | |
Magnus Damm | 8564557 | 2008-12-19 15:34:41 +0900 | [diff] [blame] | 710 | tmp = ch->cfg.sys_bus_cfg.deferred_io_msec; |
Laurent Pinchart | ce1c0b0 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 711 | if (ch->ldmt1r_value & LDMT1R_IFM && tmp) { |
Magnus Damm | 8564557 | 2008-12-19 15:34:41 +0900 | [diff] [blame] | 712 | ch->defio.deferred_io = sh_mobile_lcdc_deferred_io; |
| 713 | ch->defio.delay = msecs_to_jiffies(tmp); |
Paul Mundt | e33afdd | 2009-07-07 11:24:32 +0900 | [diff] [blame] | 714 | ch->info->fbdefio = &ch->defio; |
| 715 | fb_deferred_io_init(ch->info); |
Magnus Damm | 8564557 | 2008-12-19 15:34:41 +0900 | [diff] [blame] | 716 | } |
Magnus Damm | 21bc1f0 | 2009-08-15 02:53:16 +0000 | [diff] [blame] | 717 | |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 718 | board_cfg = &ch->cfg.board_cfg; |
Alexandre Courbot | 247f993 | 2011-02-23 08:41:50 +0000 | [diff] [blame] | 719 | if (board_cfg->display_on && try_module_get(board_cfg->owner)) { |
Guennadi Liakhovetski | c243939 | 2010-07-21 10:13:17 +0000 | [diff] [blame] | 720 | board_cfg->display_on(board_cfg->board_data, ch->info); |
Guennadi Liakhovetski | 6de9edd | 2010-09-03 07:20:23 +0000 | [diff] [blame] | 721 | module_put(board_cfg->owner); |
| 722 | } |
Alexandre Courbot | 3b0fd9d | 2011-02-16 03:49:01 +0000 | [diff] [blame] | 723 | |
| 724 | if (ch->bl) { |
| 725 | ch->bl->props.power = FB_BLANK_UNBLANK; |
| 726 | backlight_update_status(ch->bl); |
| 727 | } |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | return 0; |
| 731 | } |
| 732 | |
| 733 | static void sh_mobile_lcdc_stop(struct sh_mobile_lcdc_priv *priv) |
| 734 | { |
| 735 | struct sh_mobile_lcdc_chan *ch; |
| 736 | struct sh_mobile_lcdc_board_cfg *board_cfg; |
| 737 | int k; |
| 738 | |
Magnus Damm | 2feb075 | 2009-03-13 15:36:55 +0000 | [diff] [blame] | 739 | /* clean up deferred io and ask board code to disable panel */ |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 740 | for (k = 0; k < ARRAY_SIZE(priv->ch); k++) { |
| 741 | ch = &priv->ch[k]; |
Magnus Damm | 21bc1f0 | 2009-08-15 02:53:16 +0000 | [diff] [blame] | 742 | if (!ch->enabled) |
| 743 | continue; |
Magnus Damm | 2feb075 | 2009-03-13 15:36:55 +0000 | [diff] [blame] | 744 | |
| 745 | /* deferred io mode: |
| 746 | * flush frame, and wait for frame end interrupt |
| 747 | * clean up deferred io and enable clock |
| 748 | */ |
Guennadi Liakhovetski | 5ef6b50 | 2010-09-03 07:19:57 +0000 | [diff] [blame] | 749 | if (ch->info && ch->info->fbdefio) { |
Magnus Damm | 2feb075 | 2009-03-13 15:36:55 +0000 | [diff] [blame] | 750 | ch->frame_end = 0; |
Paul Mundt | e33afdd | 2009-07-07 11:24:32 +0900 | [diff] [blame] | 751 | schedule_delayed_work(&ch->info->deferred_work, 0); |
Magnus Damm | 2feb075 | 2009-03-13 15:36:55 +0000 | [diff] [blame] | 752 | wait_event(ch->frame_end_wait, ch->frame_end); |
Paul Mundt | e33afdd | 2009-07-07 11:24:32 +0900 | [diff] [blame] | 753 | fb_deferred_io_cleanup(ch->info); |
| 754 | ch->info->fbdefio = NULL; |
Magnus Damm | 2feb075 | 2009-03-13 15:36:55 +0000 | [diff] [blame] | 755 | sh_mobile_lcdc_clk_on(priv); |
| 756 | } |
| 757 | |
Alexandre Courbot | 3b0fd9d | 2011-02-16 03:49:01 +0000 | [diff] [blame] | 758 | if (ch->bl) { |
| 759 | ch->bl->props.power = FB_BLANK_POWERDOWN; |
| 760 | backlight_update_status(ch->bl); |
| 761 | } |
| 762 | |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 763 | board_cfg = &ch->cfg.board_cfg; |
Alexandre Courbot | 247f993 | 2011-02-23 08:41:50 +0000 | [diff] [blame] | 764 | if (board_cfg->display_off && try_module_get(board_cfg->owner)) { |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 765 | board_cfg->display_off(board_cfg->board_data); |
Guennadi Liakhovetski | 6de9edd | 2010-09-03 07:20:23 +0000 | [diff] [blame] | 766 | module_put(board_cfg->owner); |
| 767 | } |
Damian | 7caa434 | 2011-05-18 11:10:07 +0000 | [diff] [blame] | 768 | |
| 769 | /* disable the meram */ |
| 770 | if (ch->meram_enabled) { |
| 771 | struct sh_mobile_meram_cfg *cfg; |
| 772 | struct sh_mobile_meram_info *mdev; |
| 773 | cfg = ch->cfg.meram_cfg; |
| 774 | mdev = priv->meram_dev; |
| 775 | mdev->ops->meram_unregister(mdev, cfg); |
| 776 | ch->meram_enabled = 0; |
| 777 | } |
| 778 | |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | /* stop the lcdc */ |
Magnus Damm | 8e9bb19 | 2009-05-20 14:34:43 +0000 | [diff] [blame] | 782 | if (priv->started) { |
| 783 | sh_mobile_lcdc_start_stop(priv, 0); |
| 784 | priv->started = 0; |
| 785 | } |
Magnus Damm | b51339f | 2008-10-31 20:23:26 +0900 | [diff] [blame] | 786 | |
Magnus Damm | 8564557 | 2008-12-19 15:34:41 +0900 | [diff] [blame] | 787 | /* stop clocks */ |
| 788 | for (k = 0; k < ARRAY_SIZE(priv->ch); k++) |
| 789 | if (priv->ch[k].enabled) |
| 790 | sh_mobile_lcdc_clk_off(priv); |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | static int sh_mobile_lcdc_check_interface(struct sh_mobile_lcdc_chan *ch) |
| 794 | { |
Laurent Pinchart | ce1c0b0 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 795 | int interface_type = ch->cfg.interface_type; |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 796 | |
Laurent Pinchart | ce1c0b0 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 797 | switch (interface_type) { |
| 798 | case RGB8: |
| 799 | case RGB9: |
| 800 | case RGB12A: |
| 801 | case RGB12B: |
| 802 | case RGB16: |
| 803 | case RGB18: |
| 804 | case RGB24: |
| 805 | case SYS8A: |
| 806 | case SYS8B: |
| 807 | case SYS8C: |
| 808 | case SYS8D: |
| 809 | case SYS9: |
| 810 | case SYS12: |
| 811 | case SYS16A: |
| 812 | case SYS16B: |
| 813 | case SYS16C: |
| 814 | case SYS18: |
| 815 | case SYS24: |
| 816 | break; |
| 817 | default: |
| 818 | return -EINVAL; |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | /* SUBLCD only supports SYS interface */ |
| 822 | if (lcdc_chan_is_sublcd(ch)) { |
Laurent Pinchart | ce1c0b0 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 823 | if (!(interface_type & LDMT1R_IFM)) |
| 824 | return -EINVAL; |
| 825 | |
| 826 | interface_type &= ~LDMT1R_IFM; |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 827 | } |
| 828 | |
Laurent Pinchart | ce1c0b0 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 829 | ch->ldmt1r_value = interface_type; |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 830 | return 0; |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 831 | } |
| 832 | |
Magnus Damm | b51339f | 2008-10-31 20:23:26 +0900 | [diff] [blame] | 833 | static int sh_mobile_lcdc_setup_clocks(struct platform_device *pdev, |
| 834 | int clock_source, |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 835 | struct sh_mobile_lcdc_priv *priv) |
| 836 | { |
| 837 | char *str; |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 838 | |
| 839 | switch (clock_source) { |
Laurent Pinchart | ce1c0b0 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 840 | case LCDC_CLK_BUS: |
| 841 | str = "bus_clk"; |
| 842 | priv->lddckr = LDDCKR_ICKSEL_BUS; |
| 843 | break; |
| 844 | case LCDC_CLK_PERIPHERAL: |
| 845 | str = "peripheral_clk"; |
| 846 | priv->lddckr = LDDCKR_ICKSEL_MIPI; |
| 847 | break; |
| 848 | case LCDC_CLK_EXTERNAL: |
| 849 | str = NULL; |
| 850 | priv->lddckr = LDDCKR_ICKSEL_HDMI; |
| 851 | break; |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 852 | default: |
| 853 | return -EINVAL; |
| 854 | } |
| 855 | |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 856 | if (str) { |
Magnus Damm | b51339f | 2008-10-31 20:23:26 +0900 | [diff] [blame] | 857 | priv->dot_clk = clk_get(&pdev->dev, str); |
| 858 | if (IS_ERR(priv->dot_clk)) { |
| 859 | dev_err(&pdev->dev, "cannot get dot clock %s\n", str); |
Magnus Damm | b51339f | 2008-10-31 20:23:26 +0900 | [diff] [blame] | 860 | return PTR_ERR(priv->dot_clk); |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 861 | } |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 862 | } |
| 863 | |
Magnus Damm | 0246c47 | 2009-08-14 10:49:08 +0000 | [diff] [blame] | 864 | /* Runtime PM support involves two step for this driver: |
| 865 | * 1) Enable Runtime PM |
| 866 | * 2) Force Runtime PM Resume since hardware is accessed from probe() |
| 867 | */ |
Guennadi Liakhovetski | 8bed905 | 2010-04-30 16:07:00 +0000 | [diff] [blame] | 868 | priv->dev = &pdev->dev; |
Magnus Damm | 0246c47 | 2009-08-14 10:49:08 +0000 | [diff] [blame] | 869 | pm_runtime_enable(priv->dev); |
| 870 | pm_runtime_resume(priv->dev); |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 871 | return 0; |
| 872 | } |
| 873 | |
| 874 | static int sh_mobile_lcdc_setcolreg(u_int regno, |
| 875 | u_int red, u_int green, u_int blue, |
| 876 | u_int transp, struct fb_info *info) |
| 877 | { |
| 878 | u32 *palette = info->pseudo_palette; |
| 879 | |
| 880 | if (regno >= PALETTE_NR) |
| 881 | return -EINVAL; |
| 882 | |
| 883 | /* only FB_VISUAL_TRUECOLOR supported */ |
| 884 | |
| 885 | red >>= 16 - info->var.red.length; |
| 886 | green >>= 16 - info->var.green.length; |
| 887 | blue >>= 16 - info->var.blue.length; |
| 888 | transp >>= 16 - info->var.transp.length; |
| 889 | |
| 890 | palette[regno] = (red << info->var.red.offset) | |
| 891 | (green << info->var.green.offset) | |
| 892 | (blue << info->var.blue.offset) | |
| 893 | (transp << info->var.transp.offset); |
| 894 | |
| 895 | return 0; |
| 896 | } |
| 897 | |
| 898 | static struct fb_fix_screeninfo sh_mobile_lcdc_fix = { |
| 899 | .id = "SH Mobile LCDC", |
| 900 | .type = FB_TYPE_PACKED_PIXELS, |
| 901 | .visual = FB_VISUAL_TRUECOLOR, |
| 902 | .accel = FB_ACCEL_NONE, |
Phil Edworthy | 9dd3881 | 2009-09-15 12:00:18 +0000 | [diff] [blame] | 903 | .xpanstep = 0, |
| 904 | .ypanstep = 1, |
| 905 | .ywrapstep = 0, |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 906 | .capabilities = FB_CAP_FOURCC, |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 907 | }; |
| 908 | |
Magnus Damm | 8564557 | 2008-12-19 15:34:41 +0900 | [diff] [blame] | 909 | static void sh_mobile_lcdc_fillrect(struct fb_info *info, |
| 910 | const struct fb_fillrect *rect) |
| 911 | { |
| 912 | sys_fillrect(info, rect); |
| 913 | sh_mobile_lcdc_deferred_io_touch(info); |
| 914 | } |
| 915 | |
| 916 | static void sh_mobile_lcdc_copyarea(struct fb_info *info, |
| 917 | const struct fb_copyarea *area) |
| 918 | { |
| 919 | sys_copyarea(info, area); |
| 920 | sh_mobile_lcdc_deferred_io_touch(info); |
| 921 | } |
| 922 | |
| 923 | static void sh_mobile_lcdc_imageblit(struct fb_info *info, |
| 924 | const struct fb_image *image) |
| 925 | { |
| 926 | sys_imageblit(info, image); |
| 927 | sh_mobile_lcdc_deferred_io_touch(info); |
| 928 | } |
| 929 | |
Phil Edworthy | 9dd3881 | 2009-09-15 12:00:18 +0000 | [diff] [blame] | 930 | static int sh_mobile_fb_pan_display(struct fb_var_screeninfo *var, |
| 931 | struct fb_info *info) |
| 932 | { |
| 933 | struct sh_mobile_lcdc_chan *ch = info->par; |
Phil Edworthy | 92e1f9a | 2010-02-11 10:24:25 +0000 | [diff] [blame] | 934 | struct sh_mobile_lcdc_priv *priv = ch->lcdc; |
| 935 | unsigned long ldrcntr; |
| 936 | unsigned long new_pan_offset; |
Damian Hobson-Garcia | 53b5031 | 2011-02-24 05:47:13 +0000 | [diff] [blame] | 937 | unsigned long base_addr_y, base_addr_c; |
| 938 | unsigned long c_offset; |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 939 | bool yuv = sh_mobile_format_is_yuv(&info->var); |
Phil Edworthy | 9dd3881 | 2009-09-15 12:00:18 +0000 | [diff] [blame] | 940 | |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 941 | if (!yuv) |
Laurent Pinchart | dc1d5ad | 2011-08-31 13:00:55 +0200 | [diff] [blame] | 942 | new_pan_offset = var->yoffset * info->fix.line_length |
| 943 | + var->xoffset * (info->var.bits_per_pixel / 8); |
Damian Hobson-Garcia | 53b5031 | 2011-02-24 05:47:13 +0000 | [diff] [blame] | 944 | else |
Laurent Pinchart | dc1d5ad | 2011-08-31 13:00:55 +0200 | [diff] [blame] | 945 | new_pan_offset = var->yoffset * info->fix.line_length |
| 946 | + var->xoffset; |
Phil Edworthy | 9dd3881 | 2009-09-15 12:00:18 +0000 | [diff] [blame] | 947 | |
Phil Edworthy | 92e1f9a | 2010-02-11 10:24:25 +0000 | [diff] [blame] | 948 | if (new_pan_offset == ch->pan_offset) |
| 949 | return 0; /* No change, do nothing */ |
| 950 | |
| 951 | ldrcntr = lcdc_read(priv, _LDRCNTR); |
| 952 | |
| 953 | /* Set the source address for the next refresh */ |
Damian Hobson-Garcia | 53b5031 | 2011-02-24 05:47:13 +0000 | [diff] [blame] | 954 | base_addr_y = ch->dma_handle + new_pan_offset; |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 955 | if (yuv) { |
Damian Hobson-Garcia | 53b5031 | 2011-02-24 05:47:13 +0000 | [diff] [blame] | 956 | /* Set y offset */ |
Laurent Pinchart | dc1d5ad | 2011-08-31 13:00:55 +0200 | [diff] [blame] | 957 | c_offset = var->yoffset * info->fix.line_length |
| 958 | * (info->var.bits_per_pixel - 8) / 8; |
| 959 | base_addr_c = ch->dma_handle |
| 960 | + info->var.xres * info->var.yres_virtual |
| 961 | + c_offset; |
Damian Hobson-Garcia | 53b5031 | 2011-02-24 05:47:13 +0000 | [diff] [blame] | 962 | /* Set x offset */ |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 963 | if (sh_mobile_format_fourcc(&info->var) == V4L2_PIX_FMT_NV24) |
Damian Hobson-Garcia | 53b5031 | 2011-02-24 05:47:13 +0000 | [diff] [blame] | 964 | base_addr_c += 2 * var->xoffset; |
| 965 | else |
| 966 | base_addr_c += var->xoffset; |
Laurent Pinchart | 49d79ba | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 967 | } |
Damian Hobson-Garcia | 53b5031 | 2011-02-24 05:47:13 +0000 | [diff] [blame] | 968 | |
Laurent Pinchart | 49d79ba | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 969 | if (ch->meram_enabled) { |
Damian | 7caa434 | 2011-05-18 11:10:07 +0000 | [diff] [blame] | 970 | struct sh_mobile_meram_cfg *cfg; |
| 971 | struct sh_mobile_meram_info *mdev; |
Damian | 7caa434 | 2011-05-18 11:10:07 +0000 | [diff] [blame] | 972 | int ret; |
| 973 | |
| 974 | cfg = ch->cfg.meram_cfg; |
| 975 | mdev = priv->meram_dev; |
| 976 | ret = mdev->ops->meram_update(mdev, cfg, |
| 977 | base_addr_y, base_addr_c, |
Laurent Pinchart | 49d79ba | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 978 | &base_addr_y, &base_addr_c); |
Damian | 7caa434 | 2011-05-18 11:10:07 +0000 | [diff] [blame] | 979 | if (ret) |
| 980 | return ret; |
Damian | 7caa434 | 2011-05-18 11:10:07 +0000 | [diff] [blame] | 981 | } |
Damian Hobson-Garcia | 53b5031 | 2011-02-24 05:47:13 +0000 | [diff] [blame] | 982 | |
Laurent Pinchart | 49d79ba | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 983 | ch->base_addr_y = base_addr_y; |
| 984 | ch->base_addr_c = base_addr_c; |
| 985 | |
| 986 | lcdc_write_chan_mirror(ch, LDSA1R, base_addr_y); |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 987 | if (yuv) |
Laurent Pinchart | 49d79ba | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 988 | lcdc_write_chan_mirror(ch, LDSA2R, base_addr_c); |
| 989 | |
Phil Edworthy | 92e1f9a | 2010-02-11 10:24:25 +0000 | [diff] [blame] | 990 | if (lcdc_chan_is_sublcd(ch)) |
| 991 | lcdc_write(ch->lcdc, _LDRCNTR, ldrcntr ^ LDRCNTR_SRS); |
| 992 | else |
| 993 | lcdc_write(ch->lcdc, _LDRCNTR, ldrcntr ^ LDRCNTR_MRS); |
| 994 | |
| 995 | ch->pan_offset = new_pan_offset; |
| 996 | |
| 997 | sh_mobile_lcdc_deferred_io_touch(info); |
Phil Edworthy | 9dd3881 | 2009-09-15 12:00:18 +0000 | [diff] [blame] | 998 | |
| 999 | return 0; |
| 1000 | } |
| 1001 | |
Phil Edworthy | 40331b2 | 2010-02-15 13:57:49 +0000 | [diff] [blame] | 1002 | static int sh_mobile_wait_for_vsync(struct fb_info *info) |
| 1003 | { |
| 1004 | struct sh_mobile_lcdc_chan *ch = info->par; |
| 1005 | unsigned long ldintr; |
| 1006 | int ret; |
| 1007 | |
Laurent Pinchart | dc48665 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 1008 | /* Enable VSync End interrupt and be careful not to acknowledge any |
| 1009 | * pending interrupt. |
| 1010 | */ |
Phil Edworthy | 40331b2 | 2010-02-15 13:57:49 +0000 | [diff] [blame] | 1011 | ldintr = lcdc_read(ch->lcdc, _LDINTR); |
Laurent Pinchart | dc48665 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 1012 | ldintr |= LDINTR_VEE | LDINTR_STATUS_MASK; |
Phil Edworthy | 40331b2 | 2010-02-15 13:57:49 +0000 | [diff] [blame] | 1013 | lcdc_write(ch->lcdc, _LDINTR, ldintr); |
| 1014 | |
| 1015 | ret = wait_for_completion_interruptible_timeout(&ch->vsync_completion, |
| 1016 | msecs_to_jiffies(100)); |
| 1017 | if (!ret) |
| 1018 | return -ETIMEDOUT; |
| 1019 | |
| 1020 | return 0; |
| 1021 | } |
| 1022 | |
| 1023 | static int sh_mobile_ioctl(struct fb_info *info, unsigned int cmd, |
| 1024 | unsigned long arg) |
| 1025 | { |
| 1026 | int retval; |
| 1027 | |
| 1028 | switch (cmd) { |
| 1029 | case FBIO_WAITFORVSYNC: |
| 1030 | retval = sh_mobile_wait_for_vsync(info); |
| 1031 | break; |
| 1032 | |
| 1033 | default: |
| 1034 | retval = -ENOIOCTLCMD; |
| 1035 | break; |
| 1036 | } |
| 1037 | return retval; |
| 1038 | } |
| 1039 | |
Guennadi Liakhovetski | dd21050 | 2010-09-14 14:48:54 +0000 | [diff] [blame] | 1040 | static void sh_mobile_fb_reconfig(struct fb_info *info) |
| 1041 | { |
| 1042 | struct sh_mobile_lcdc_chan *ch = info->par; |
| 1043 | struct fb_videomode mode1, mode2; |
| 1044 | struct fb_event event; |
| 1045 | int evnt = FB_EVENT_MODE_CHANGE_ALL; |
| 1046 | |
| 1047 | if (ch->use_count > 1 || (ch->use_count == 1 && !info->fbcon_par)) |
| 1048 | /* More framebuffer users are active */ |
| 1049 | return; |
| 1050 | |
| 1051 | fb_var_to_videomode(&mode1, &ch->display_var); |
| 1052 | fb_var_to_videomode(&mode2, &info->var); |
| 1053 | |
| 1054 | if (fb_mode_is_equal(&mode1, &mode2)) |
| 1055 | return; |
| 1056 | |
| 1057 | /* Display has been re-plugged, framebuffer is free now, reconfigure */ |
| 1058 | if (fb_set_var(info, &ch->display_var) < 0) |
| 1059 | /* Couldn't reconfigure, hopefully, can continue as before */ |
| 1060 | return; |
| 1061 | |
Guennadi Liakhovetski | dd21050 | 2010-09-14 14:48:54 +0000 | [diff] [blame] | 1062 | /* |
| 1063 | * fb_set_var() calls the notifier change internally, only if |
| 1064 | * FBINFO_MISC_USEREVENT flag is set. Since we do not want to fake a |
| 1065 | * user event, we have to call the chain ourselves. |
| 1066 | */ |
| 1067 | event.info = info; |
Arnd Hannemann | cc267ec | 2010-11-15 21:43:22 +0000 | [diff] [blame] | 1068 | event.data = &mode1; |
Guennadi Liakhovetski | dd21050 | 2010-09-14 14:48:54 +0000 | [diff] [blame] | 1069 | fb_notifier_call_chain(evnt, &event); |
| 1070 | } |
| 1071 | |
| 1072 | /* |
| 1073 | * Locking: both .fb_release() and .fb_open() are called with info->lock held if |
| 1074 | * user == 1, or with console sem held, if user == 0. |
| 1075 | */ |
| 1076 | static int sh_mobile_release(struct fb_info *info, int user) |
| 1077 | { |
| 1078 | struct sh_mobile_lcdc_chan *ch = info->par; |
| 1079 | |
| 1080 | mutex_lock(&ch->open_lock); |
| 1081 | dev_dbg(info->dev, "%s(): %d users\n", __func__, ch->use_count); |
| 1082 | |
| 1083 | ch->use_count--; |
| 1084 | |
| 1085 | /* Nothing to reconfigure, when called from fbcon */ |
| 1086 | if (user) { |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 1087 | console_lock(); |
Guennadi Liakhovetski | dd21050 | 2010-09-14 14:48:54 +0000 | [diff] [blame] | 1088 | sh_mobile_fb_reconfig(info); |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 1089 | console_unlock(); |
Guennadi Liakhovetski | dd21050 | 2010-09-14 14:48:54 +0000 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | mutex_unlock(&ch->open_lock); |
| 1093 | |
| 1094 | return 0; |
| 1095 | } |
| 1096 | |
| 1097 | static int sh_mobile_open(struct fb_info *info, int user) |
| 1098 | { |
| 1099 | struct sh_mobile_lcdc_chan *ch = info->par; |
| 1100 | |
| 1101 | mutex_lock(&ch->open_lock); |
| 1102 | ch->use_count++; |
| 1103 | |
| 1104 | dev_dbg(info->dev, "%s(): %d users\n", __func__, ch->use_count); |
| 1105 | mutex_unlock(&ch->open_lock); |
| 1106 | |
| 1107 | return 0; |
| 1108 | } |
| 1109 | |
| 1110 | static int sh_mobile_check_var(struct fb_var_screeninfo *var, struct fb_info *info) |
| 1111 | { |
| 1112 | struct sh_mobile_lcdc_chan *ch = info->par; |
Magnus Damm | 417d482 | 2011-01-05 10:21:00 +0000 | [diff] [blame] | 1113 | struct sh_mobile_lcdc_priv *p = ch->lcdc; |
Laurent Pinchart | 0386219 | 2011-08-31 13:00:53 +0200 | [diff] [blame] | 1114 | unsigned int best_dist = (unsigned int)-1; |
| 1115 | unsigned int best_xres = 0; |
| 1116 | unsigned int best_yres = 0; |
| 1117 | unsigned int i; |
Guennadi Liakhovetski | dd21050 | 2010-09-14 14:48:54 +0000 | [diff] [blame] | 1118 | |
Laurent Pinchart | 0386219 | 2011-08-31 13:00:53 +0200 | [diff] [blame] | 1119 | if (var->xres > MAX_XRES || var->yres > MAX_YRES) |
Guennadi Liakhovetski | dd21050 | 2010-09-14 14:48:54 +0000 | [diff] [blame] | 1120 | return -EINVAL; |
Laurent Pinchart | 0386219 | 2011-08-31 13:00:53 +0200 | [diff] [blame] | 1121 | |
| 1122 | /* If board code provides us with a list of available modes, make sure |
| 1123 | * we use one of them. Find the mode closest to the requested one. The |
| 1124 | * distance between two modes is defined as the size of the |
| 1125 | * non-overlapping parts of the two rectangles. |
| 1126 | */ |
| 1127 | for (i = 0; i < ch->cfg.num_cfg; ++i) { |
| 1128 | const struct fb_videomode *mode = &ch->cfg.lcd_cfg[i]; |
| 1129 | unsigned int dist; |
| 1130 | |
| 1131 | /* We can only round up. */ |
| 1132 | if (var->xres > mode->xres || var->yres > mode->yres) |
| 1133 | continue; |
| 1134 | |
| 1135 | dist = var->xres * var->yres + mode->xres * mode->yres |
| 1136 | - 2 * min(var->xres, mode->xres) |
| 1137 | * min(var->yres, mode->yres); |
| 1138 | |
| 1139 | if (dist < best_dist) { |
| 1140 | best_xres = mode->xres; |
| 1141 | best_yres = mode->yres; |
| 1142 | best_dist = dist; |
| 1143 | } |
Guennadi Liakhovetski | dd21050 | 2010-09-14 14:48:54 +0000 | [diff] [blame] | 1144 | } |
Magnus Damm | 417d482 | 2011-01-05 10:21:00 +0000 | [diff] [blame] | 1145 | |
Laurent Pinchart | 0386219 | 2011-08-31 13:00:53 +0200 | [diff] [blame] | 1146 | /* If no available mode can be used, return an error. */ |
| 1147 | if (ch->cfg.num_cfg != 0) { |
| 1148 | if (best_dist == (unsigned int)-1) |
| 1149 | return -EINVAL; |
| 1150 | |
| 1151 | var->xres = best_xres; |
| 1152 | var->yres = best_yres; |
| 1153 | } |
| 1154 | |
| 1155 | /* Make sure the virtual resolution is at least as big as the visible |
| 1156 | * resolution. |
| 1157 | */ |
| 1158 | if (var->xres_virtual < var->xres) |
| 1159 | var->xres_virtual = var->xres; |
| 1160 | if (var->yres_virtual < var->yres) |
| 1161 | var->yres_virtual = var->yres; |
| 1162 | |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 1163 | if (sh_mobile_format_is_fourcc(var)) { |
| 1164 | switch (var->grayscale) { |
| 1165 | case V4L2_PIX_FMT_NV12: |
| 1166 | case V4L2_PIX_FMT_NV21: |
| 1167 | var->bits_per_pixel = 12; |
| 1168 | break; |
| 1169 | case V4L2_PIX_FMT_RGB565: |
| 1170 | case V4L2_PIX_FMT_NV16: |
| 1171 | case V4L2_PIX_FMT_NV61: |
| 1172 | var->bits_per_pixel = 16; |
| 1173 | break; |
| 1174 | case V4L2_PIX_FMT_BGR24: |
| 1175 | case V4L2_PIX_FMT_NV24: |
| 1176 | case V4L2_PIX_FMT_NV42: |
| 1177 | var->bits_per_pixel = 24; |
| 1178 | break; |
| 1179 | case V4L2_PIX_FMT_BGR32: |
| 1180 | var->bits_per_pixel = 32; |
| 1181 | break; |
| 1182 | default: |
| 1183 | return -EINVAL; |
| 1184 | } |
Laurent Pinchart | 0386219 | 2011-08-31 13:00:53 +0200 | [diff] [blame] | 1185 | |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 1186 | /* Default to RGB and JPEG color-spaces for RGB and YUV formats |
| 1187 | * respectively. |
| 1188 | */ |
| 1189 | if (!sh_mobile_format_is_yuv(var)) |
| 1190 | var->colorspace = V4L2_COLORSPACE_SRGB; |
| 1191 | else if (var->colorspace != V4L2_COLORSPACE_REC709) |
| 1192 | var->colorspace = V4L2_COLORSPACE_JPEG; |
| 1193 | } else { |
| 1194 | if (var->bits_per_pixel <= 16) { /* RGB 565 */ |
| 1195 | var->bits_per_pixel = 16; |
| 1196 | var->red.offset = 11; |
| 1197 | var->red.length = 5; |
| 1198 | var->green.offset = 5; |
| 1199 | var->green.length = 6; |
| 1200 | var->blue.offset = 0; |
| 1201 | var->blue.length = 5; |
| 1202 | var->transp.offset = 0; |
| 1203 | var->transp.length = 0; |
| 1204 | } else if (var->bits_per_pixel <= 24) { /* RGB 888 */ |
| 1205 | var->bits_per_pixel = 24; |
| 1206 | var->red.offset = 16; |
| 1207 | var->red.length = 8; |
| 1208 | var->green.offset = 8; |
| 1209 | var->green.length = 8; |
| 1210 | var->blue.offset = 0; |
| 1211 | var->blue.length = 8; |
| 1212 | var->transp.offset = 0; |
| 1213 | var->transp.length = 0; |
| 1214 | } else if (var->bits_per_pixel <= 32) { /* RGBA 888 */ |
| 1215 | var->bits_per_pixel = 32; |
| 1216 | var->red.offset = 16; |
| 1217 | var->red.length = 8; |
| 1218 | var->green.offset = 8; |
| 1219 | var->green.length = 8; |
| 1220 | var->blue.offset = 0; |
| 1221 | var->blue.length = 8; |
| 1222 | var->transp.offset = 24; |
| 1223 | var->transp.length = 8; |
| 1224 | } else |
| 1225 | return -EINVAL; |
| 1226 | |
| 1227 | var->red.msb_right = 0; |
| 1228 | var->green.msb_right = 0; |
| 1229 | var->blue.msb_right = 0; |
| 1230 | var->transp.msb_right = 0; |
| 1231 | } |
Laurent Pinchart | 0386219 | 2011-08-31 13:00:53 +0200 | [diff] [blame] | 1232 | |
| 1233 | /* Make sure we don't exceed our allocated memory. */ |
| 1234 | if (var->xres_virtual * var->yres_virtual * var->bits_per_pixel / 8 > |
| 1235 | info->fix.smem_len) |
| 1236 | return -EINVAL; |
| 1237 | |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 1238 | /* only accept the forced_fourcc for dual channel configurations */ |
| 1239 | if (p->forced_fourcc && |
| 1240 | p->forced_fourcc != sh_mobile_format_fourcc(var)) |
Magnus Damm | 417d482 | 2011-01-05 10:21:00 +0000 | [diff] [blame] | 1241 | return -EINVAL; |
| 1242 | |
Guennadi Liakhovetski | dd21050 | 2010-09-14 14:48:54 +0000 | [diff] [blame] | 1243 | return 0; |
| 1244 | } |
Phil Edworthy | 40331b2 | 2010-02-15 13:57:49 +0000 | [diff] [blame] | 1245 | |
Laurent Pinchart | ed5bebf | 2011-08-31 13:00:54 +0200 | [diff] [blame] | 1246 | static int sh_mobile_set_par(struct fb_info *info) |
| 1247 | { |
| 1248 | struct sh_mobile_lcdc_chan *ch = info->par; |
Laurent Pinchart | 91fba48 | 2011-08-31 13:00:56 +0200 | [diff] [blame] | 1249 | u32 line_length = info->fix.line_length; |
Laurent Pinchart | ed5bebf | 2011-08-31 13:00:54 +0200 | [diff] [blame] | 1250 | int ret; |
| 1251 | |
| 1252 | sh_mobile_lcdc_stop(ch->lcdc); |
Laurent Pinchart | 91fba48 | 2011-08-31 13:00:56 +0200 | [diff] [blame] | 1253 | |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 1254 | if (sh_mobile_format_is_yuv(&info->var)) |
Laurent Pinchart | 91fba48 | 2011-08-31 13:00:56 +0200 | [diff] [blame] | 1255 | info->fix.line_length = info->var.xres; |
| 1256 | else |
| 1257 | info->fix.line_length = info->var.xres |
| 1258 | * info->var.bits_per_pixel / 8; |
| 1259 | |
Laurent Pinchart | ed5bebf | 2011-08-31 13:00:54 +0200 | [diff] [blame] | 1260 | ret = sh_mobile_lcdc_start(ch->lcdc); |
Laurent Pinchart | 91fba48 | 2011-08-31 13:00:56 +0200 | [diff] [blame] | 1261 | if (ret < 0) { |
Laurent Pinchart | ed5bebf | 2011-08-31 13:00:54 +0200 | [diff] [blame] | 1262 | dev_err(info->dev, "%s: unable to restart LCDC\n", __func__); |
Laurent Pinchart | 91fba48 | 2011-08-31 13:00:56 +0200 | [diff] [blame] | 1263 | info->fix.line_length = line_length; |
| 1264 | } |
Laurent Pinchart | ed5bebf | 2011-08-31 13:00:54 +0200 | [diff] [blame] | 1265 | |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 1266 | if (sh_mobile_format_is_fourcc(&info->var)) { |
| 1267 | info->fix.type = FB_TYPE_FOURCC; |
| 1268 | info->fix.visual = FB_VISUAL_FOURCC; |
| 1269 | } else { |
| 1270 | info->fix.type = FB_TYPE_PACKED_PIXELS; |
| 1271 | info->fix.visual = FB_VISUAL_TRUECOLOR; |
| 1272 | } |
| 1273 | |
Laurent Pinchart | ed5bebf | 2011-08-31 13:00:54 +0200 | [diff] [blame] | 1274 | return ret; |
| 1275 | } |
| 1276 | |
Alexandre Courbot | 8857b9a | 2011-02-23 08:36:30 +0000 | [diff] [blame] | 1277 | /* |
| 1278 | * Screen blanking. Behavior is as follows: |
| 1279 | * FB_BLANK_UNBLANK: screen unblanked, clocks enabled |
| 1280 | * FB_BLANK_NORMAL: screen blanked, clocks enabled |
| 1281 | * FB_BLANK_VSYNC, |
| 1282 | * FB_BLANK_HSYNC, |
| 1283 | * FB_BLANK_POWEROFF: screen blanked, clocks disabled |
| 1284 | */ |
| 1285 | static int sh_mobile_lcdc_blank(int blank, struct fb_info *info) |
| 1286 | { |
| 1287 | struct sh_mobile_lcdc_chan *ch = info->par; |
| 1288 | struct sh_mobile_lcdc_priv *p = ch->lcdc; |
| 1289 | |
| 1290 | /* blank the screen? */ |
| 1291 | if (blank > FB_BLANK_UNBLANK && ch->blank_status == FB_BLANK_UNBLANK) { |
| 1292 | struct fb_fillrect rect = { |
| 1293 | .width = info->var.xres, |
| 1294 | .height = info->var.yres, |
| 1295 | }; |
| 1296 | sh_mobile_lcdc_fillrect(info, &rect); |
| 1297 | } |
| 1298 | /* turn clocks on? */ |
| 1299 | if (blank <= FB_BLANK_NORMAL && ch->blank_status > FB_BLANK_NORMAL) { |
| 1300 | sh_mobile_lcdc_clk_on(p); |
| 1301 | } |
| 1302 | /* turn clocks off? */ |
| 1303 | if (blank > FB_BLANK_NORMAL && ch->blank_status <= FB_BLANK_NORMAL) { |
| 1304 | /* make sure the screen is updated with the black fill before |
| 1305 | * switching the clocks off. one vsync is not enough since |
| 1306 | * blanking may occur in the middle of a refresh. deferred io |
| 1307 | * mode will reenable the clocks and update the screen in time, |
| 1308 | * so it does not need this. */ |
| 1309 | if (!info->fbdefio) { |
| 1310 | sh_mobile_wait_for_vsync(info); |
| 1311 | sh_mobile_wait_for_vsync(info); |
| 1312 | } |
| 1313 | sh_mobile_lcdc_clk_off(p); |
| 1314 | } |
| 1315 | |
| 1316 | ch->blank_status = blank; |
| 1317 | return 0; |
| 1318 | } |
| 1319 | |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1320 | static struct fb_ops sh_mobile_lcdc_ops = { |
Phil Edworthy | 9dd3881 | 2009-09-15 12:00:18 +0000 | [diff] [blame] | 1321 | .owner = THIS_MODULE, |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1322 | .fb_setcolreg = sh_mobile_lcdc_setcolreg, |
Magnus Damm | 2540c11 | 2008-12-17 17:29:49 +0900 | [diff] [blame] | 1323 | .fb_read = fb_sys_read, |
| 1324 | .fb_write = fb_sys_write, |
Magnus Damm | 8564557 | 2008-12-19 15:34:41 +0900 | [diff] [blame] | 1325 | .fb_fillrect = sh_mobile_lcdc_fillrect, |
| 1326 | .fb_copyarea = sh_mobile_lcdc_copyarea, |
| 1327 | .fb_imageblit = sh_mobile_lcdc_imageblit, |
Alexandre Courbot | 8857b9a | 2011-02-23 08:36:30 +0000 | [diff] [blame] | 1328 | .fb_blank = sh_mobile_lcdc_blank, |
Phil Edworthy | 9dd3881 | 2009-09-15 12:00:18 +0000 | [diff] [blame] | 1329 | .fb_pan_display = sh_mobile_fb_pan_display, |
Phil Edworthy | 40331b2 | 2010-02-15 13:57:49 +0000 | [diff] [blame] | 1330 | .fb_ioctl = sh_mobile_ioctl, |
Guennadi Liakhovetski | dd21050 | 2010-09-14 14:48:54 +0000 | [diff] [blame] | 1331 | .fb_open = sh_mobile_open, |
| 1332 | .fb_release = sh_mobile_release, |
| 1333 | .fb_check_var = sh_mobile_check_var, |
Laurent Pinchart | ed5bebf | 2011-08-31 13:00:54 +0200 | [diff] [blame] | 1334 | .fb_set_par = sh_mobile_set_par, |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1335 | }; |
| 1336 | |
Alexandre Courbot | 3b0fd9d | 2011-02-16 03:49:01 +0000 | [diff] [blame] | 1337 | static int sh_mobile_lcdc_update_bl(struct backlight_device *bdev) |
| 1338 | { |
| 1339 | struct sh_mobile_lcdc_chan *ch = bl_get_data(bdev); |
| 1340 | struct sh_mobile_lcdc_board_cfg *cfg = &ch->cfg.board_cfg; |
| 1341 | int brightness = bdev->props.brightness; |
| 1342 | |
| 1343 | if (bdev->props.power != FB_BLANK_UNBLANK || |
| 1344 | bdev->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK)) |
| 1345 | brightness = 0; |
| 1346 | |
| 1347 | return cfg->set_brightness(cfg->board_data, brightness); |
| 1348 | } |
| 1349 | |
| 1350 | static int sh_mobile_lcdc_get_brightness(struct backlight_device *bdev) |
| 1351 | { |
| 1352 | struct sh_mobile_lcdc_chan *ch = bl_get_data(bdev); |
| 1353 | struct sh_mobile_lcdc_board_cfg *cfg = &ch->cfg.board_cfg; |
| 1354 | |
| 1355 | return cfg->get_brightness(cfg->board_data); |
| 1356 | } |
| 1357 | |
| 1358 | static int sh_mobile_lcdc_check_fb(struct backlight_device *bdev, |
| 1359 | struct fb_info *info) |
| 1360 | { |
| 1361 | return (info->bl_dev == bdev); |
| 1362 | } |
| 1363 | |
| 1364 | static struct backlight_ops sh_mobile_lcdc_bl_ops = { |
| 1365 | .options = BL_CORE_SUSPENDRESUME, |
| 1366 | .update_status = sh_mobile_lcdc_update_bl, |
| 1367 | .get_brightness = sh_mobile_lcdc_get_brightness, |
| 1368 | .check_fb = sh_mobile_lcdc_check_fb, |
| 1369 | }; |
| 1370 | |
| 1371 | static struct backlight_device *sh_mobile_lcdc_bl_probe(struct device *parent, |
| 1372 | struct sh_mobile_lcdc_chan *ch) |
| 1373 | { |
| 1374 | struct backlight_device *bl; |
| 1375 | |
| 1376 | bl = backlight_device_register(ch->cfg.bl_info.name, parent, ch, |
| 1377 | &sh_mobile_lcdc_bl_ops, NULL); |
Dan Carpenter | beee1f2 | 2011-03-21 15:03:13 +0000 | [diff] [blame] | 1378 | if (IS_ERR(bl)) { |
| 1379 | dev_err(parent, "unable to register backlight device: %ld\n", |
| 1380 | PTR_ERR(bl)); |
Alexandre Courbot | 3b0fd9d | 2011-02-16 03:49:01 +0000 | [diff] [blame] | 1381 | return NULL; |
| 1382 | } |
| 1383 | |
| 1384 | bl->props.max_brightness = ch->cfg.bl_info.max_brightness; |
| 1385 | bl->props.brightness = bl->props.max_brightness; |
| 1386 | backlight_update_status(bl); |
| 1387 | |
| 1388 | return bl; |
| 1389 | } |
| 1390 | |
| 1391 | static void sh_mobile_lcdc_bl_remove(struct backlight_device *bdev) |
| 1392 | { |
| 1393 | backlight_device_unregister(bdev); |
| 1394 | } |
| 1395 | |
Magnus Damm | 2feb075 | 2009-03-13 15:36:55 +0000 | [diff] [blame] | 1396 | static int sh_mobile_lcdc_suspend(struct device *dev) |
| 1397 | { |
| 1398 | struct platform_device *pdev = to_platform_device(dev); |
| 1399 | |
| 1400 | sh_mobile_lcdc_stop(platform_get_drvdata(pdev)); |
| 1401 | return 0; |
| 1402 | } |
| 1403 | |
| 1404 | static int sh_mobile_lcdc_resume(struct device *dev) |
| 1405 | { |
| 1406 | struct platform_device *pdev = to_platform_device(dev); |
| 1407 | |
| 1408 | return sh_mobile_lcdc_start(platform_get_drvdata(pdev)); |
| 1409 | } |
| 1410 | |
Magnus Damm | 0246c47 | 2009-08-14 10:49:08 +0000 | [diff] [blame] | 1411 | static int sh_mobile_lcdc_runtime_suspend(struct device *dev) |
| 1412 | { |
| 1413 | struct platform_device *pdev = to_platform_device(dev); |
Laurent Pinchart | 2427bb2 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 1414 | struct sh_mobile_lcdc_priv *priv = platform_get_drvdata(pdev); |
Magnus Damm | 0246c47 | 2009-08-14 10:49:08 +0000 | [diff] [blame] | 1415 | |
| 1416 | /* turn off LCDC hardware */ |
Laurent Pinchart | 2427bb2 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 1417 | lcdc_write(priv, _LDCNT1R, 0); |
| 1418 | |
Magnus Damm | 0246c47 | 2009-08-14 10:49:08 +0000 | [diff] [blame] | 1419 | return 0; |
| 1420 | } |
| 1421 | |
| 1422 | static int sh_mobile_lcdc_runtime_resume(struct device *dev) |
| 1423 | { |
| 1424 | struct platform_device *pdev = to_platform_device(dev); |
Laurent Pinchart | 2427bb2 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 1425 | struct sh_mobile_lcdc_priv *priv = platform_get_drvdata(pdev); |
Magnus Damm | 0246c47 | 2009-08-14 10:49:08 +0000 | [diff] [blame] | 1426 | |
Laurent Pinchart | 2427bb2 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 1427 | __sh_mobile_lcdc_start(priv); |
Magnus Damm | 0246c47 | 2009-08-14 10:49:08 +0000 | [diff] [blame] | 1428 | |
| 1429 | return 0; |
| 1430 | } |
| 1431 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 1432 | static const struct dev_pm_ops sh_mobile_lcdc_dev_pm_ops = { |
Magnus Damm | 2feb075 | 2009-03-13 15:36:55 +0000 | [diff] [blame] | 1433 | .suspend = sh_mobile_lcdc_suspend, |
| 1434 | .resume = sh_mobile_lcdc_resume, |
Magnus Damm | 0246c47 | 2009-08-14 10:49:08 +0000 | [diff] [blame] | 1435 | .runtime_suspend = sh_mobile_lcdc_runtime_suspend, |
| 1436 | .runtime_resume = sh_mobile_lcdc_runtime_resume, |
Magnus Damm | 2feb075 | 2009-03-13 15:36:55 +0000 | [diff] [blame] | 1437 | }; |
| 1438 | |
Guennadi Liakhovetski | 6de9edd | 2010-09-03 07:20:23 +0000 | [diff] [blame] | 1439 | /* locking: called with info->lock held */ |
Guennadi Liakhovetski | 6011bde | 2010-07-21 10:13:21 +0000 | [diff] [blame] | 1440 | static int sh_mobile_lcdc_notify(struct notifier_block *nb, |
| 1441 | unsigned long action, void *data) |
| 1442 | { |
| 1443 | struct fb_event *event = data; |
| 1444 | struct fb_info *info = event->info; |
| 1445 | struct sh_mobile_lcdc_chan *ch = info->par; |
| 1446 | struct sh_mobile_lcdc_board_cfg *board_cfg = &ch->cfg.board_cfg; |
Guennadi Liakhovetski | 6011bde | 2010-07-21 10:13:21 +0000 | [diff] [blame] | 1447 | |
| 1448 | if (&ch->lcdc->notifier != nb) |
Guennadi Liakhovetski | baf1637 | 2010-09-03 07:20:08 +0000 | [diff] [blame] | 1449 | return NOTIFY_DONE; |
Guennadi Liakhovetski | 6011bde | 2010-07-21 10:13:21 +0000 | [diff] [blame] | 1450 | |
| 1451 | dev_dbg(info->dev, "%s(): action = %lu, data = %p\n", |
| 1452 | __func__, action, event->data); |
| 1453 | |
| 1454 | switch(action) { |
| 1455 | case FB_EVENT_SUSPEND: |
Alexandre Courbot | 247f993 | 2011-02-23 08:41:50 +0000 | [diff] [blame] | 1456 | if (board_cfg->display_off && try_module_get(board_cfg->owner)) { |
Guennadi Liakhovetski | 6011bde | 2010-07-21 10:13:21 +0000 | [diff] [blame] | 1457 | board_cfg->display_off(board_cfg->board_data); |
Guennadi Liakhovetski | 6de9edd | 2010-09-03 07:20:23 +0000 | [diff] [blame] | 1458 | module_put(board_cfg->owner); |
| 1459 | } |
Guennadi Liakhovetski | afe417c | 2010-09-03 07:20:39 +0000 | [diff] [blame] | 1460 | sh_mobile_lcdc_stop(ch->lcdc); |
Guennadi Liakhovetski | 6011bde | 2010-07-21 10:13:21 +0000 | [diff] [blame] | 1461 | break; |
| 1462 | case FB_EVENT_RESUME: |
Guennadi Liakhovetski | dd21050 | 2010-09-14 14:48:54 +0000 | [diff] [blame] | 1463 | mutex_lock(&ch->open_lock); |
| 1464 | sh_mobile_fb_reconfig(info); |
| 1465 | mutex_unlock(&ch->open_lock); |
Guennadi Liakhovetski | 6011bde | 2010-07-21 10:13:21 +0000 | [diff] [blame] | 1466 | |
| 1467 | /* HDMI must be enabled before LCDC configuration */ |
Alexandre Courbot | 247f993 | 2011-02-23 08:41:50 +0000 | [diff] [blame] | 1468 | if (board_cfg->display_on && try_module_get(board_cfg->owner)) { |
Guennadi Liakhovetski | dd21050 | 2010-09-14 14:48:54 +0000 | [diff] [blame] | 1469 | board_cfg->display_on(board_cfg->board_data, info); |
Guennadi Liakhovetski | 6de9edd | 2010-09-03 07:20:23 +0000 | [diff] [blame] | 1470 | module_put(board_cfg->owner); |
Guennadi Liakhovetski | 6011bde | 2010-07-21 10:13:21 +0000 | [diff] [blame] | 1471 | } |
| 1472 | |
Guennadi Liakhovetski | ebe5e12 | 2011-05-05 16:33:40 +0000 | [diff] [blame] | 1473 | sh_mobile_lcdc_start(ch->lcdc); |
Guennadi Liakhovetski | 6011bde | 2010-07-21 10:13:21 +0000 | [diff] [blame] | 1474 | } |
| 1475 | |
Guennadi Liakhovetski | baf1637 | 2010-09-03 07:20:08 +0000 | [diff] [blame] | 1476 | return NOTIFY_OK; |
Guennadi Liakhovetski | 6011bde | 2010-07-21 10:13:21 +0000 | [diff] [blame] | 1477 | } |
| 1478 | |
Laurent Pinchart | b4bee69 | 2011-08-31 13:00:57 +0200 | [diff] [blame] | 1479 | static int sh_mobile_lcdc_remove(struct platform_device *pdev) |
| 1480 | { |
| 1481 | struct sh_mobile_lcdc_priv *priv = platform_get_drvdata(pdev); |
| 1482 | struct fb_info *info; |
| 1483 | int i; |
| 1484 | |
| 1485 | fb_unregister_client(&priv->notifier); |
| 1486 | |
| 1487 | for (i = 0; i < ARRAY_SIZE(priv->ch); i++) |
| 1488 | if (priv->ch[i].info && priv->ch[i].info->dev) |
| 1489 | unregister_framebuffer(priv->ch[i].info); |
| 1490 | |
| 1491 | sh_mobile_lcdc_stop(priv); |
| 1492 | |
| 1493 | for (i = 0; i < ARRAY_SIZE(priv->ch); i++) { |
| 1494 | info = priv->ch[i].info; |
| 1495 | |
| 1496 | if (!info || !info->device) |
| 1497 | continue; |
| 1498 | |
| 1499 | if (priv->ch[i].sglist) |
| 1500 | vfree(priv->ch[i].sglist); |
| 1501 | |
| 1502 | if (info->screen_base) |
| 1503 | dma_free_coherent(&pdev->dev, info->fix.smem_len, |
| 1504 | info->screen_base, |
| 1505 | priv->ch[i].dma_handle); |
| 1506 | fb_dealloc_cmap(&info->cmap); |
| 1507 | framebuffer_release(info); |
| 1508 | } |
| 1509 | |
| 1510 | for (i = 0; i < ARRAY_SIZE(priv->ch); i++) { |
| 1511 | if (priv->ch[i].bl) |
| 1512 | sh_mobile_lcdc_bl_remove(priv->ch[i].bl); |
| 1513 | } |
| 1514 | |
| 1515 | if (priv->dot_clk) |
| 1516 | clk_put(priv->dot_clk); |
| 1517 | |
| 1518 | if (priv->dev) |
| 1519 | pm_runtime_disable(priv->dev); |
| 1520 | |
| 1521 | if (priv->base) |
| 1522 | iounmap(priv->base); |
| 1523 | |
| 1524 | if (priv->irq) |
| 1525 | free_irq(priv->irq, priv); |
| 1526 | kfree(priv); |
| 1527 | return 0; |
| 1528 | } |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1529 | |
Laurent Pinchart | 3ce0559 | 2011-08-31 13:00:58 +0200 | [diff] [blame] | 1530 | static int __devinit sh_mobile_lcdc_channel_init(struct sh_mobile_lcdc_chan *ch, |
| 1531 | struct device *dev) |
| 1532 | { |
| 1533 | struct sh_mobile_lcdc_chan_cfg *cfg = &ch->cfg; |
| 1534 | const struct fb_videomode *max_mode; |
| 1535 | const struct fb_videomode *mode; |
| 1536 | struct fb_var_screeninfo *var; |
| 1537 | struct fb_info *info; |
| 1538 | unsigned int max_size; |
| 1539 | int num_cfg; |
| 1540 | void *buf; |
| 1541 | int ret; |
| 1542 | int i; |
| 1543 | |
Laurent Pinchart | a67472a | 2011-08-31 13:00:59 +0200 | [diff] [blame] | 1544 | mutex_init(&ch->open_lock); |
| 1545 | |
| 1546 | /* Allocate the frame buffer device. */ |
Laurent Pinchart | 3ce0559 | 2011-08-31 13:00:58 +0200 | [diff] [blame] | 1547 | ch->info = framebuffer_alloc(0, dev); |
| 1548 | if (!ch->info) { |
| 1549 | dev_err(dev, "unable to allocate fb_info\n"); |
| 1550 | return -ENOMEM; |
| 1551 | } |
| 1552 | |
| 1553 | info = ch->info; |
Laurent Pinchart | 3ce0559 | 2011-08-31 13:00:58 +0200 | [diff] [blame] | 1554 | info->fbops = &sh_mobile_lcdc_ops; |
| 1555 | info->par = ch; |
Laurent Pinchart | a67472a | 2011-08-31 13:00:59 +0200 | [diff] [blame] | 1556 | info->pseudo_palette = &ch->pseudo_palette; |
| 1557 | info->flags = FBINFO_FLAG_DEFAULT; |
Laurent Pinchart | 3ce0559 | 2011-08-31 13:00:58 +0200 | [diff] [blame] | 1558 | |
| 1559 | /* Iterate through the modes to validate them and find the highest |
| 1560 | * resolution. |
| 1561 | */ |
| 1562 | max_mode = NULL; |
| 1563 | max_size = 0; |
| 1564 | |
| 1565 | for (i = 0, mode = cfg->lcd_cfg; i < cfg->num_cfg; i++, mode++) { |
| 1566 | unsigned int size = mode->yres * mode->xres; |
| 1567 | |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 1568 | /* NV12/NV21 buffers must have even number of lines */ |
| 1569 | if ((cfg->fourcc == V4L2_PIX_FMT_NV12 || |
| 1570 | cfg->fourcc == V4L2_PIX_FMT_NV21) && (mode->yres & 0x1)) { |
Laurent Pinchart | 3ce0559 | 2011-08-31 13:00:58 +0200 | [diff] [blame] | 1571 | dev_err(dev, "yres must be multiple of 2 for YCbCr420 " |
| 1572 | "mode.\n"); |
| 1573 | return -EINVAL; |
| 1574 | } |
| 1575 | |
| 1576 | if (size > max_size) { |
| 1577 | max_mode = mode; |
| 1578 | max_size = size; |
| 1579 | } |
| 1580 | } |
| 1581 | |
| 1582 | if (!max_size) |
| 1583 | max_size = MAX_XRES * MAX_YRES; |
| 1584 | else |
| 1585 | dev_dbg(dev, "Found largest videomode %ux%u\n", |
| 1586 | max_mode->xres, max_mode->yres); |
| 1587 | |
Laurent Pinchart | a67472a | 2011-08-31 13:00:59 +0200 | [diff] [blame] | 1588 | /* Create the mode list. */ |
Laurent Pinchart | 3ce0559 | 2011-08-31 13:00:58 +0200 | [diff] [blame] | 1589 | if (cfg->lcd_cfg == NULL) { |
| 1590 | mode = &default_720p; |
| 1591 | num_cfg = 1; |
| 1592 | } else { |
| 1593 | mode = cfg->lcd_cfg; |
| 1594 | num_cfg = cfg->num_cfg; |
| 1595 | } |
| 1596 | |
| 1597 | fb_videomode_to_modelist(mode, num_cfg, &info->modelist); |
| 1598 | |
Laurent Pinchart | a67472a | 2011-08-31 13:00:59 +0200 | [diff] [blame] | 1599 | /* Initialize variable screen information using the first mode as |
| 1600 | * default. The default Y virtual resolution is twice the panel size to |
| 1601 | * allow for double-buffering. |
| 1602 | */ |
| 1603 | var = &info->var; |
Laurent Pinchart | 3ce0559 | 2011-08-31 13:00:58 +0200 | [diff] [blame] | 1604 | fb_videomode_to_var(var, mode); |
| 1605 | var->width = cfg->lcd_size_cfg.width; |
| 1606 | var->height = cfg->lcd_size_cfg.height; |
Laurent Pinchart | 3ce0559 | 2011-08-31 13:00:58 +0200 | [diff] [blame] | 1607 | var->yres_virtual = var->yres * 2; |
| 1608 | var->activate = FB_ACTIVATE_NOW; |
| 1609 | |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 1610 | switch (cfg->fourcc) { |
| 1611 | case V4L2_PIX_FMT_RGB565: |
| 1612 | var->bits_per_pixel = 16; |
| 1613 | break; |
| 1614 | case V4L2_PIX_FMT_BGR24: |
| 1615 | var->bits_per_pixel = 24; |
| 1616 | break; |
| 1617 | case V4L2_PIX_FMT_BGR32: |
| 1618 | var->bits_per_pixel = 32; |
| 1619 | break; |
| 1620 | default: |
| 1621 | var->grayscale = cfg->fourcc; |
| 1622 | break; |
| 1623 | } |
| 1624 | |
| 1625 | /* Make sure the memory size check won't fail. smem_len is initialized |
| 1626 | * later based on var. |
| 1627 | */ |
| 1628 | info->fix.smem_len = UINT_MAX; |
Laurent Pinchart | a67472a | 2011-08-31 13:00:59 +0200 | [diff] [blame] | 1629 | ret = sh_mobile_check_var(var, info); |
Laurent Pinchart | 3ce0559 | 2011-08-31 13:00:58 +0200 | [diff] [blame] | 1630 | if (ret) |
| 1631 | return ret; |
| 1632 | |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 1633 | max_size = max_size * var->bits_per_pixel / 8 * 2; |
| 1634 | |
Laurent Pinchart | a67472a | 2011-08-31 13:00:59 +0200 | [diff] [blame] | 1635 | /* Allocate frame buffer memory and color map. */ |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 1636 | buf = dma_alloc_coherent(dev, max_size, &ch->dma_handle, GFP_KERNEL); |
Laurent Pinchart | 3ce0559 | 2011-08-31 13:00:58 +0200 | [diff] [blame] | 1637 | if (!buf) { |
| 1638 | dev_err(dev, "unable to allocate buffer\n"); |
| 1639 | return -ENOMEM; |
| 1640 | } |
| 1641 | |
Laurent Pinchart | 3ce0559 | 2011-08-31 13:00:58 +0200 | [diff] [blame] | 1642 | ret = fb_alloc_cmap(&info->cmap, PALETTE_NR, 0); |
| 1643 | if (ret < 0) { |
| 1644 | dev_err(dev, "unable to allocate cmap\n"); |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 1645 | dma_free_coherent(dev, max_size, buf, ch->dma_handle); |
Laurent Pinchart | 3ce0559 | 2011-08-31 13:00:58 +0200 | [diff] [blame] | 1646 | return ret; |
| 1647 | } |
| 1648 | |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 1649 | /* Initialize fixed screen information. Restrict pan to 2 lines steps |
| 1650 | * for NV12 and NV21. |
| 1651 | */ |
| 1652 | info->fix = sh_mobile_lcdc_fix; |
Laurent Pinchart | 3ce0559 | 2011-08-31 13:00:58 +0200 | [diff] [blame] | 1653 | info->fix.smem_start = ch->dma_handle; |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 1654 | info->fix.smem_len = max_size; |
| 1655 | if (cfg->fourcc == V4L2_PIX_FMT_NV12 || |
| 1656 | cfg->fourcc == V4L2_PIX_FMT_NV21) |
| 1657 | info->fix.ypanstep = 2; |
| 1658 | |
| 1659 | if (sh_mobile_format_is_yuv(var)) { |
Laurent Pinchart | 3ce0559 | 2011-08-31 13:00:58 +0200 | [diff] [blame] | 1660 | info->fix.line_length = var->xres; |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 1661 | info->fix.visual = FB_VISUAL_FOURCC; |
| 1662 | } else { |
| 1663 | info->fix.line_length = var->xres * var->bits_per_pixel / 8; |
| 1664 | info->fix.visual = FB_VISUAL_TRUECOLOR; |
| 1665 | } |
Laurent Pinchart | 3ce0559 | 2011-08-31 13:00:58 +0200 | [diff] [blame] | 1666 | |
| 1667 | info->screen_base = buf; |
| 1668 | info->device = dev; |
| 1669 | ch->display_var = *var; |
| 1670 | |
| 1671 | return 0; |
| 1672 | } |
| 1673 | |
Uwe Kleine-König | c2e1303 | 2010-02-04 20:56:51 +0100 | [diff] [blame] | 1674 | static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev) |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1675 | { |
Guennadi Liakhovetski | 01ac25b | 2010-09-03 07:20:00 +0000 | [diff] [blame] | 1676 | struct sh_mobile_lcdc_info *pdata = pdev->dev.platform_data; |
Laurent Pinchart | 3ce0559 | 2011-08-31 13:00:58 +0200 | [diff] [blame] | 1677 | struct sh_mobile_lcdc_priv *priv; |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1678 | struct resource *res; |
Laurent Pinchart | 3ce0559 | 2011-08-31 13:00:58 +0200 | [diff] [blame] | 1679 | int num_channels; |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1680 | int error; |
Laurent Pinchart | 3ce0559 | 2011-08-31 13:00:58 +0200 | [diff] [blame] | 1681 | int i; |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1682 | |
Guennadi Liakhovetski | 01ac25b | 2010-09-03 07:20:00 +0000 | [diff] [blame] | 1683 | if (!pdata) { |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1684 | dev_err(&pdev->dev, "no platform data defined\n"); |
Guennadi Liakhovetski | 8bed905 | 2010-04-30 16:07:00 +0000 | [diff] [blame] | 1685 | return -EINVAL; |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1686 | } |
| 1687 | |
| 1688 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Magnus Damm | 8564557 | 2008-12-19 15:34:41 +0900 | [diff] [blame] | 1689 | i = platform_get_irq(pdev, 0); |
| 1690 | if (!res || i < 0) { |
| 1691 | dev_err(&pdev->dev, "cannot get platform resources\n"); |
Guennadi Liakhovetski | 8bed905 | 2010-04-30 16:07:00 +0000 | [diff] [blame] | 1692 | return -ENOENT; |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1693 | } |
| 1694 | |
| 1695 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
| 1696 | if (!priv) { |
| 1697 | dev_err(&pdev->dev, "cannot allocate device data\n"); |
Guennadi Liakhovetski | 8bed905 | 2010-04-30 16:07:00 +0000 | [diff] [blame] | 1698 | return -ENOMEM; |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1699 | } |
| 1700 | |
Guennadi Liakhovetski | 8bed905 | 2010-04-30 16:07:00 +0000 | [diff] [blame] | 1701 | platform_set_drvdata(pdev, priv); |
| 1702 | |
Yong Zhang | f8798cc | 2011-09-22 16:59:16 +0800 | [diff] [blame] | 1703 | error = request_irq(i, sh_mobile_lcdc_irq, 0, |
Kay Sievers | 7ad33e7 | 2009-03-24 16:38:21 -0700 | [diff] [blame] | 1704 | dev_name(&pdev->dev), priv); |
Magnus Damm | 8564557 | 2008-12-19 15:34:41 +0900 | [diff] [blame] | 1705 | if (error) { |
| 1706 | dev_err(&pdev->dev, "unable to request irq\n"); |
| 1707 | goto err1; |
| 1708 | } |
| 1709 | |
| 1710 | priv->irq = i; |
Guennadi Liakhovetski | 5ef6b50 | 2010-09-03 07:19:57 +0000 | [diff] [blame] | 1711 | atomic_set(&priv->hw_usecnt, -1); |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1712 | |
Laurent Pinchart | 3ce0559 | 2011-08-31 13:00:58 +0200 | [diff] [blame] | 1713 | for (i = 0, num_channels = 0; i < ARRAY_SIZE(pdata->ch); i++) { |
| 1714 | struct sh_mobile_lcdc_chan *ch = priv->ch + num_channels; |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1715 | |
Guennadi Liakhovetski | 01ac25b | 2010-09-03 07:20:00 +0000 | [diff] [blame] | 1716 | ch->lcdc = priv; |
| 1717 | memcpy(&ch->cfg, &pdata->ch[i], sizeof(pdata->ch[i])); |
| 1718 | |
| 1719 | error = sh_mobile_lcdc_check_interface(ch); |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1720 | if (error) { |
| 1721 | dev_err(&pdev->dev, "unsupported interface type\n"); |
| 1722 | goto err1; |
| 1723 | } |
Guennadi Liakhovetski | 01ac25b | 2010-09-03 07:20:00 +0000 | [diff] [blame] | 1724 | init_waitqueue_head(&ch->frame_end_wait); |
| 1725 | init_completion(&ch->vsync_completion); |
| 1726 | ch->pan_offset = 0; |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1727 | |
Alexandre Courbot | 3b0fd9d | 2011-02-16 03:49:01 +0000 | [diff] [blame] | 1728 | /* probe the backlight is there is one defined */ |
| 1729 | if (ch->cfg.bl_info.max_brightness) |
| 1730 | ch->bl = sh_mobile_lcdc_bl_probe(&pdev->dev, ch); |
| 1731 | |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1732 | switch (pdata->ch[i].chan) { |
| 1733 | case LCDC_CHAN_MAINLCD: |
Laurent Pinchart | ce1c0b0 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 1734 | ch->enabled = LDCNT2R_ME; |
Guennadi Liakhovetski | 01ac25b | 2010-09-03 07:20:00 +0000 | [diff] [blame] | 1735 | ch->reg_offs = lcdc_offs_mainlcd; |
Laurent Pinchart | 3ce0559 | 2011-08-31 13:00:58 +0200 | [diff] [blame] | 1736 | num_channels++; |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1737 | break; |
| 1738 | case LCDC_CHAN_SUBLCD: |
Laurent Pinchart | ce1c0b0 | 2011-07-13 12:13:47 +0200 | [diff] [blame] | 1739 | ch->enabled = LDCNT2R_SE; |
Guennadi Liakhovetski | 01ac25b | 2010-09-03 07:20:00 +0000 | [diff] [blame] | 1740 | ch->reg_offs = lcdc_offs_sublcd; |
Laurent Pinchart | 3ce0559 | 2011-08-31 13:00:58 +0200 | [diff] [blame] | 1741 | num_channels++; |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1742 | break; |
| 1743 | } |
| 1744 | } |
| 1745 | |
Laurent Pinchart | 3ce0559 | 2011-08-31 13:00:58 +0200 | [diff] [blame] | 1746 | if (!num_channels) { |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1747 | dev_err(&pdev->dev, "no channels defined\n"); |
| 1748 | error = -EINVAL; |
| 1749 | goto err1; |
| 1750 | } |
| 1751 | |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 1752 | /* for dual channel LCDC (MAIN + SUB) force shared format setting */ |
Laurent Pinchart | 3ce0559 | 2011-08-31 13:00:58 +0200 | [diff] [blame] | 1753 | if (num_channels == 2) |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 1754 | priv->forced_fourcc = pdata->ch[0].fourcc; |
Magnus Damm | 417d482 | 2011-01-05 10:21:00 +0000 | [diff] [blame] | 1755 | |
Guennadi Liakhovetski | dba6f38 | 2010-06-30 09:26:35 +0000 | [diff] [blame] | 1756 | priv->base = ioremap_nocache(res->start, resource_size(res)); |
| 1757 | if (!priv->base) |
| 1758 | goto err1; |
| 1759 | |
Magnus Damm | b51339f | 2008-10-31 20:23:26 +0900 | [diff] [blame] | 1760 | error = sh_mobile_lcdc_setup_clocks(pdev, pdata->clock_source, priv); |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1761 | if (error) { |
| 1762 | dev_err(&pdev->dev, "unable to setup clocks\n"); |
| 1763 | goto err1; |
| 1764 | } |
| 1765 | |
Damian | 7caa434 | 2011-05-18 11:10:07 +0000 | [diff] [blame] | 1766 | priv->meram_dev = pdata->meram_dev; |
| 1767 | |
Laurent Pinchart | 3ce0559 | 2011-08-31 13:00:58 +0200 | [diff] [blame] | 1768 | for (i = 0; i < num_channels; i++) { |
Guennadi Liakhovetski | 01ac25b | 2010-09-03 07:20:00 +0000 | [diff] [blame] | 1769 | struct sh_mobile_lcdc_chan *ch = priv->ch + i; |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1770 | |
Laurent Pinchart | 3ce0559 | 2011-08-31 13:00:58 +0200 | [diff] [blame] | 1771 | error = sh_mobile_lcdc_channel_init(ch, &pdev->dev); |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1772 | if (error) |
Laurent Pinchart | 3ce0559 | 2011-08-31 13:00:58 +0200 | [diff] [blame] | 1773 | goto err1; |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1774 | } |
| 1775 | |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1776 | error = sh_mobile_lcdc_start(priv); |
| 1777 | if (error) { |
| 1778 | dev_err(&pdev->dev, "unable to start hardware\n"); |
| 1779 | goto err1; |
| 1780 | } |
| 1781 | |
Laurent Pinchart | 3ce0559 | 2011-08-31 13:00:58 +0200 | [diff] [blame] | 1782 | for (i = 0; i < num_channels; i++) { |
Paul Mundt | 1c6a307 | 2009-07-01 06:50:31 +0000 | [diff] [blame] | 1783 | struct sh_mobile_lcdc_chan *ch = priv->ch + i; |
Laurent Pinchart | 3ce0559 | 2011-08-31 13:00:58 +0200 | [diff] [blame] | 1784 | struct fb_info *info = ch->info; |
Paul Mundt | 1c6a307 | 2009-07-01 06:50:31 +0000 | [diff] [blame] | 1785 | |
| 1786 | if (info->fbdefio) { |
Guennadi Liakhovetski | 8bed905 | 2010-04-30 16:07:00 +0000 | [diff] [blame] | 1787 | ch->sglist = vmalloc(sizeof(struct scatterlist) * |
Paul Mundt | 1c6a307 | 2009-07-01 06:50:31 +0000 | [diff] [blame] | 1788 | info->fix.smem_len >> PAGE_SHIFT); |
Guennadi Liakhovetski | 8bed905 | 2010-04-30 16:07:00 +0000 | [diff] [blame] | 1789 | if (!ch->sglist) { |
Paul Mundt | 1c6a307 | 2009-07-01 06:50:31 +0000 | [diff] [blame] | 1790 | dev_err(&pdev->dev, "cannot allocate sglist\n"); |
| 1791 | goto err1; |
| 1792 | } |
| 1793 | } |
| 1794 | |
Alexandre Courbot | 3b0fd9d | 2011-02-16 03:49:01 +0000 | [diff] [blame] | 1795 | info->bl_dev = ch->bl; |
| 1796 | |
Paul Mundt | 1c6a307 | 2009-07-01 06:50:31 +0000 | [diff] [blame] | 1797 | error = register_framebuffer(info); |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1798 | if (error < 0) |
| 1799 | goto err1; |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1800 | |
Laurent Pinchart | edd153a | 2011-12-13 14:02:28 +0100 | [diff] [blame] | 1801 | dev_info(info->dev, "registered %s/%s as %dx%d %dbpp.\n", |
| 1802 | pdev->name, (ch->cfg.chan == LCDC_CHAN_MAINLCD) ? |
| 1803 | "mainlcd" : "sublcd", info->var.xres, info->var.yres, |
| 1804 | info->var.bits_per_pixel); |
Magnus Damm | 8564557 | 2008-12-19 15:34:41 +0900 | [diff] [blame] | 1805 | |
| 1806 | /* deferred io mode: disable clock to save power */ |
Guennadi Liakhovetski | 6011bde | 2010-07-21 10:13:21 +0000 | [diff] [blame] | 1807 | if (info->fbdefio || info->state == FBINFO_STATE_SUSPENDED) |
Magnus Damm | 8564557 | 2008-12-19 15:34:41 +0900 | [diff] [blame] | 1808 | sh_mobile_lcdc_clk_off(priv); |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1809 | } |
| 1810 | |
Guennadi Liakhovetski | 6011bde | 2010-07-21 10:13:21 +0000 | [diff] [blame] | 1811 | /* Failure ignored */ |
| 1812 | priv->notifier.notifier_call = sh_mobile_lcdc_notify; |
| 1813 | fb_register_client(&priv->notifier); |
| 1814 | |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1815 | return 0; |
Guennadi Liakhovetski | 8bed905 | 2010-04-30 16:07:00 +0000 | [diff] [blame] | 1816 | err1: |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1817 | sh_mobile_lcdc_remove(pdev); |
Guennadi Liakhovetski | 8bed905 | 2010-04-30 16:07:00 +0000 | [diff] [blame] | 1818 | |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1819 | return error; |
| 1820 | } |
| 1821 | |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1822 | static struct platform_driver sh_mobile_lcdc_driver = { |
| 1823 | .driver = { |
| 1824 | .name = "sh_mobile_lcdc_fb", |
| 1825 | .owner = THIS_MODULE, |
Magnus Damm | 2feb075 | 2009-03-13 15:36:55 +0000 | [diff] [blame] | 1826 | .pm = &sh_mobile_lcdc_dev_pm_ops, |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1827 | }, |
| 1828 | .probe = sh_mobile_lcdc_probe, |
| 1829 | .remove = sh_mobile_lcdc_remove, |
| 1830 | }; |
| 1831 | |
Axel Lin | 4277f2c | 2011-11-26 10:25:54 +0800 | [diff] [blame] | 1832 | module_platform_driver(sh_mobile_lcdc_driver); |
Magnus Damm | cfb4f5d | 2008-07-23 21:31:24 -0700 | [diff] [blame] | 1833 | |
| 1834 | MODULE_DESCRIPTION("SuperH Mobile LCDC Framebuffer driver"); |
| 1835 | MODULE_AUTHOR("Magnus Damm <damm@opensource.se>"); |
| 1836 | MODULE_LICENSE("GPL v2"); |