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