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