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