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