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