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