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