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