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