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