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