fbdev: sh_mobile_lcdc: Fix overlay registers update during pan operation
[linux-2.6-block.git] / drivers / video / sh_mobile_lcdcfb.c
CommitLineData
cfb4f5d1
MD
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
f1f60b5f
LP
11#include <linux/atomic.h>
12#include <linux/backlight.h>
cfb4f5d1 13#include <linux/clk.h>
f1f60b5f 14#include <linux/console.h>
c5deac3c 15#include <linux/ctype.h>
cfb4f5d1 16#include <linux/dma-mapping.h>
f1f60b5f
LP
17#include <linux/delay.h>
18#include <linux/gpio.h>
19#include <linux/init.h>
8564557a 20#include <linux/interrupt.h>
40331b21 21#include <linux/ioctl.h>
f1f60b5f
LP
22#include <linux/kernel.h>
23#include <linux/mm.h>
355b200b 24#include <linux/module.h>
f1f60b5f
LP
25#include <linux/platform_device.h>
26#include <linux/pm_runtime.h>
27#include <linux/slab.h>
28#include <linux/videodev2.h>
29#include <linux/vmalloc.h>
30
225c9a8d 31#include <video/sh_mobile_lcdc.h>
8a20974f 32#include <video/sh_mobile_meram.h>
cfb4f5d1 33
6de9edd5
GL
34#include "sh_mobile_lcdcfb.h"
35
c5deac3c
LP
36/* ----------------------------------------------------------------------------
37 * Overlay register definitions
38 */
39
40#define LDBCR 0xb00
41#define LDBCR_UPC(n) (1 << ((n) + 16))
42#define LDBCR_UPF(n) (1 << ((n) + 8))
43#define LDBCR_UPD(n) (1 << ((n) + 0))
44#define LDBnBSIFR(n) (0xb20 + (n) * 0x20 + 0x00)
45#define LDBBSIFR_EN (1 << 31)
46#define LDBBSIFR_VS (1 << 29)
47#define LDBBSIFR_BRSEL (1 << 28)
48#define LDBBSIFR_MX (1 << 27)
49#define LDBBSIFR_MY (1 << 26)
50#define LDBBSIFR_CV3 (3 << 24)
51#define LDBBSIFR_CV2 (2 << 24)
52#define LDBBSIFR_CV1 (1 << 24)
53#define LDBBSIFR_CV0 (0 << 24)
54#define LDBBSIFR_CV_MASK (3 << 24)
55#define LDBBSIFR_LAY_MASK (0xff << 16)
56#define LDBBSIFR_LAY_SHIFT 16
57#define LDBBSIFR_ROP3_MASK (0xff << 16)
58#define LDBBSIFR_ROP3_SHIFT 16
59#define LDBBSIFR_AL_PL8 (3 << 14)
60#define LDBBSIFR_AL_PL1 (2 << 14)
61#define LDBBSIFR_AL_PK (1 << 14)
62#define LDBBSIFR_AL_1 (0 << 14)
63#define LDBBSIFR_AL_MASK (3 << 14)
64#define LDBBSIFR_SWPL (1 << 10)
65#define LDBBSIFR_SWPW (1 << 9)
66#define LDBBSIFR_SWPB (1 << 8)
67#define LDBBSIFR_RY (1 << 7)
68#define LDBBSIFR_CHRR_420 (2 << 0)
69#define LDBBSIFR_CHRR_422 (1 << 0)
70#define LDBBSIFR_CHRR_444 (0 << 0)
71#define LDBBSIFR_RPKF_ARGB32 (0x00 << 0)
72#define LDBBSIFR_RPKF_RGB16 (0x03 << 0)
73#define LDBBSIFR_RPKF_RGB24 (0x0b << 0)
74#define LDBBSIFR_RPKF_MASK (0x1f << 0)
75#define LDBnBSSZR(n) (0xb20 + (n) * 0x20 + 0x04)
76#define LDBBSSZR_BVSS_MASK (0xfff << 16)
77#define LDBBSSZR_BVSS_SHIFT 16
78#define LDBBSSZR_BHSS_MASK (0xfff << 0)
79#define LDBBSSZR_BHSS_SHIFT 0
80#define LDBnBLOCR(n) (0xb20 + (n) * 0x20 + 0x08)
81#define LDBBLOCR_CVLC_MASK (0xfff << 16)
82#define LDBBLOCR_CVLC_SHIFT 16
83#define LDBBLOCR_CHLC_MASK (0xfff << 0)
84#define LDBBLOCR_CHLC_SHIFT 0
85#define LDBnBSMWR(n) (0xb20 + (n) * 0x20 + 0x0c)
86#define LDBBSMWR_BSMWA_MASK (0xffff << 16)
87#define LDBBSMWR_BSMWA_SHIFT 16
88#define LDBBSMWR_BSMW_MASK (0xffff << 0)
89#define LDBBSMWR_BSMW_SHIFT 0
90#define LDBnBSAYR(n) (0xb20 + (n) * 0x20 + 0x10)
91#define LDBBSAYR_FG1A_MASK (0xff << 24)
92#define LDBBSAYR_FG1A_SHIFT 24
93#define LDBBSAYR_FG1R_MASK (0xff << 16)
94#define LDBBSAYR_FG1R_SHIFT 16
95#define LDBBSAYR_FG1G_MASK (0xff << 8)
96#define LDBBSAYR_FG1G_SHIFT 8
97#define LDBBSAYR_FG1B_MASK (0xff << 0)
98#define LDBBSAYR_FG1B_SHIFT 0
99#define LDBnBSACR(n) (0xb20 + (n) * 0x20 + 0x14)
100#define LDBBSACR_FG2A_MASK (0xff << 24)
101#define LDBBSACR_FG2A_SHIFT 24
102#define LDBBSACR_FG2R_MASK (0xff << 16)
103#define LDBBSACR_FG2R_SHIFT 16
104#define LDBBSACR_FG2G_MASK (0xff << 8)
105#define LDBBSACR_FG2G_SHIFT 8
106#define LDBBSACR_FG2B_MASK (0xff << 0)
107#define LDBBSACR_FG2B_SHIFT 0
108#define LDBnBSAAR(n) (0xb20 + (n) * 0x20 + 0x18)
109#define LDBBSAAR_AP_MASK (0xff << 24)
110#define LDBBSAAR_AP_SHIFT 24
111#define LDBBSAAR_R_MASK (0xff << 16)
112#define LDBBSAAR_R_SHIFT 16
113#define LDBBSAAR_GY_MASK (0xff << 8)
114#define LDBBSAAR_GY_SHIFT 8
115#define LDBBSAAR_B_MASK (0xff << 0)
116#define LDBBSAAR_B_SHIFT 0
117#define LDBnBPPCR(n) (0xb20 + (n) * 0x20 + 0x1c)
118#define LDBBPPCR_AP_MASK (0xff << 24)
119#define LDBBPPCR_AP_SHIFT 24
120#define LDBBPPCR_R_MASK (0xff << 16)
121#define LDBBPPCR_R_SHIFT 16
122#define LDBBPPCR_GY_MASK (0xff << 8)
123#define LDBBPPCR_GY_SHIFT 8
124#define LDBBPPCR_B_MASK (0xff << 0)
125#define LDBBPPCR_B_SHIFT 0
126#define LDBnBBGCL(n) (0xb10 + (n) * 0x04)
127#define LDBBBGCL_BGA_MASK (0xff << 24)
128#define LDBBBGCL_BGA_SHIFT 24
129#define LDBBBGCL_BGR_MASK (0xff << 16)
130#define LDBBBGCL_BGR_SHIFT 16
131#define LDBBBGCL_BGG_MASK (0xff << 8)
132#define LDBBBGCL_BGG_SHIFT 8
133#define LDBBBGCL_BGB_MASK (0xff << 0)
134#define LDBBBGCL_BGB_SHIFT 0
135
a6f15ade
PE
136#define SIDE_B_OFFSET 0x1000
137#define MIRROR_OFFSET 0x2000
cfb4f5d1 138
d2ecbab5
GL
139#define MAX_XRES 1920
140#define MAX_YRES 1080
cfb4f5d1 141
c5deac3c
LP
142enum sh_mobile_lcdc_overlay_mode {
143 LCDC_OVERLAY_BLEND,
144 LCDC_OVERLAY_ROP3,
145};
146
147/*
148 * struct sh_mobile_lcdc_overlay - LCDC display overlay
149 *
150 * @channel: LCDC channel this overlay belongs to
151 * @cfg: Overlay configuration
152 * @info: Frame buffer device
153 * @index: Overlay index (0-3)
154 * @base: Overlay registers base address
155 * @enabled: True if the overlay is enabled
156 * @mode: Overlay blending mode (alpha blend or ROP3)
157 * @alpha: Global alpha blending value (0-255, for alpha blending mode)
158 * @rop3: Raster operation (for ROP3 mode)
159 * @fb_mem: Frame buffer virtual memory address
160 * @fb_size: Frame buffer size in bytes
161 * @dma_handle: Frame buffer DMA address
162 * @base_addr_y: Overlay base address (RGB or luma component)
163 * @base_addr_c: Overlay base address (chroma component)
164 * @pan_offset: Current pan offset in bytes
165 * @format: Current pixelf format
166 * @xres: Horizontal visible resolution
167 * @xres_virtual: Horizontal total resolution
168 * @yres: Vertical visible resolution
169 * @yres_virtual: Vertical total resolution
170 * @pitch: Overlay line pitch
171 * @pos_x: Horizontal overlay position
172 * @pos_y: Vertical overlay position
173 */
174struct sh_mobile_lcdc_overlay {
175 struct sh_mobile_lcdc_chan *channel;
176
177 const struct sh_mobile_lcdc_overlay_cfg *cfg;
178 struct fb_info *info;
179
180 unsigned int index;
181 unsigned long base;
182
183 bool enabled;
184 enum sh_mobile_lcdc_overlay_mode mode;
185 unsigned int alpha;
186 unsigned int rop3;
187
188 void *fb_mem;
189 unsigned long fb_size;
190
191 dma_addr_t dma_handle;
192 unsigned long base_addr_y;
193 unsigned long base_addr_c;
194 unsigned long pan_offset;
195
196 const struct sh_mobile_lcdc_format_info *format;
197 unsigned int xres;
198 unsigned int xres_virtual;
199 unsigned int yres;
200 unsigned int yres_virtual;
201 unsigned int pitch;
202 int pos_x;
203 int pos_y;
204};
205
f1f60b5f
LP
206struct sh_mobile_lcdc_priv {
207 void __iomem *base;
208 int irq;
209 atomic_t hw_usecnt;
210 struct device *dev;
211 struct clk *dot_clk;
212 unsigned long lddckr;
c5deac3c 213
f1f60b5f 214 struct sh_mobile_lcdc_chan ch[2];
c5deac3c
LP
215 struct sh_mobile_lcdc_overlay overlays[4];
216
f1f60b5f
LP
217 struct notifier_block notifier;
218 int started;
219 int forced_fourcc; /* 2 channel LCDC must share fourcc setting */
220 struct sh_mobile_meram_info *meram_dev;
221};
222
223/* -----------------------------------------------------------------------------
224 * Registers access
225 */
226
0246c471 227static unsigned long lcdc_offs_mainlcd[NR_CH_REGS] = {
cfb4f5d1
MD
228 [LDDCKPAT1R] = 0x400,
229 [LDDCKPAT2R] = 0x404,
230 [LDMT1R] = 0x418,
231 [LDMT2R] = 0x41c,
232 [LDMT3R] = 0x420,
233 [LDDFR] = 0x424,
234 [LDSM1R] = 0x428,
8564557a 235 [LDSM2R] = 0x42c,
cfb4f5d1 236 [LDSA1R] = 0x430,
53b50314 237 [LDSA2R] = 0x434,
cfb4f5d1
MD
238 [LDMLSR] = 0x438,
239 [LDHCNR] = 0x448,
240 [LDHSYNR] = 0x44c,
241 [LDVLNR] = 0x450,
242 [LDVSYNR] = 0x454,
243 [LDPMR] = 0x460,
6011bdea 244 [LDHAJR] = 0x4a0,
cfb4f5d1
MD
245};
246
0246c471 247static unsigned long lcdc_offs_sublcd[NR_CH_REGS] = {
cfb4f5d1
MD
248 [LDDCKPAT1R] = 0x408,
249 [LDDCKPAT2R] = 0x40c,
250 [LDMT1R] = 0x600,
251 [LDMT2R] = 0x604,
252 [LDMT3R] = 0x608,
253 [LDDFR] = 0x60c,
254 [LDSM1R] = 0x610,
8564557a 255 [LDSM2R] = 0x614,
cfb4f5d1
MD
256 [LDSA1R] = 0x618,
257 [LDMLSR] = 0x620,
258 [LDHCNR] = 0x624,
259 [LDHSYNR] = 0x628,
260 [LDVLNR] = 0x62c,
261 [LDVSYNR] = 0x630,
262 [LDPMR] = 0x63c,
263};
264
a6f15ade
PE
265static bool banked(int reg_nr)
266{
267 switch (reg_nr) {
268 case LDMT1R:
269 case LDMT2R:
270 case LDMT3R:
271 case LDDFR:
272 case LDSM1R:
273 case LDSA1R:
53b50314 274 case LDSA2R:
a6f15ade
PE
275 case LDMLSR:
276 case LDHCNR:
277 case LDHSYNR:
278 case LDVLNR:
279 case LDVSYNR:
280 return true;
281 }
282 return false;
283}
284
f1f60b5f
LP
285static int lcdc_chan_is_sublcd(struct sh_mobile_lcdc_chan *chan)
286{
b5ef967d 287 return chan->cfg->chan == LCDC_CHAN_SUBLCD;
f1f60b5f
LP
288}
289
cfb4f5d1
MD
290static void lcdc_write_chan(struct sh_mobile_lcdc_chan *chan,
291 int reg_nr, unsigned long data)
292{
293 iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr]);
a6f15ade
PE
294 if (banked(reg_nr))
295 iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr] +
296 SIDE_B_OFFSET);
297}
298
299static void lcdc_write_chan_mirror(struct sh_mobile_lcdc_chan *chan,
300 int reg_nr, unsigned long data)
301{
302 iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr] +
303 MIRROR_OFFSET);
cfb4f5d1
MD
304}
305
306static unsigned long lcdc_read_chan(struct sh_mobile_lcdc_chan *chan,
307 int reg_nr)
308{
309 return ioread32(chan->lcdc->base + chan->reg_offs[reg_nr]);
310}
311
c5deac3c
LP
312static void lcdc_write_overlay(struct sh_mobile_lcdc_overlay *ovl,
313 int reg, unsigned long data)
314{
315 iowrite32(data, ovl->channel->lcdc->base + reg);
316 iowrite32(data, ovl->channel->lcdc->base + reg + SIDE_B_OFFSET);
317}
318
cfb4f5d1
MD
319static void lcdc_write(struct sh_mobile_lcdc_priv *priv,
320 unsigned long reg_offs, unsigned long data)
321{
322 iowrite32(data, priv->base + reg_offs);
323}
324
325static unsigned long lcdc_read(struct sh_mobile_lcdc_priv *priv,
326 unsigned long reg_offs)
327{
328 return ioread32(priv->base + reg_offs);
329}
330
331static void lcdc_wait_bit(struct sh_mobile_lcdc_priv *priv,
332 unsigned long reg_offs,
333 unsigned long mask, unsigned long until)
334{
335 while ((lcdc_read(priv, reg_offs) & mask) != until)
336 cpu_relax();
337}
338
f1f60b5f
LP
339/* -----------------------------------------------------------------------------
340 * Clock management
341 */
342
343static void sh_mobile_lcdc_clk_on(struct sh_mobile_lcdc_priv *priv)
cfb4f5d1 344{
f1f60b5f
LP
345 if (atomic_inc_and_test(&priv->hw_usecnt)) {
346 if (priv->dot_clk)
347 clk_enable(priv->dot_clk);
348 pm_runtime_get_sync(priv->dev);
349 if (priv->meram_dev && priv->meram_dev->pdev)
350 pm_runtime_get_sync(&priv->meram_dev->pdev->dev);
351 }
cfb4f5d1
MD
352}
353
f1f60b5f
LP
354static void sh_mobile_lcdc_clk_off(struct sh_mobile_lcdc_priv *priv)
355{
356 if (atomic_sub_return(1, &priv->hw_usecnt) == -1) {
357 if (priv->meram_dev && priv->meram_dev->pdev)
358 pm_runtime_put_sync(&priv->meram_dev->pdev->dev);
359 pm_runtime_put(priv->dev);
360 if (priv->dot_clk)
361 clk_disable(priv->dot_clk);
362 }
363}
364
0a7f17aa
LP
365static int sh_mobile_lcdc_setup_clocks(struct sh_mobile_lcdc_priv *priv,
366 int clock_source)
f1f60b5f 367{
4774c12a 368 struct clk *clk;
f1f60b5f
LP
369 char *str;
370
371 switch (clock_source) {
372 case LCDC_CLK_BUS:
373 str = "bus_clk";
374 priv->lddckr = LDDCKR_ICKSEL_BUS;
375 break;
376 case LCDC_CLK_PERIPHERAL:
377 str = "peripheral_clk";
378 priv->lddckr = LDDCKR_ICKSEL_MIPI;
379 break;
380 case LCDC_CLK_EXTERNAL:
381 str = NULL;
382 priv->lddckr = LDDCKR_ICKSEL_HDMI;
383 break;
384 default:
385 return -EINVAL;
386 }
387
4774c12a
LP
388 if (str == NULL)
389 return 0;
390
0a7f17aa 391 clk = clk_get(priv->dev, str);
4774c12a 392 if (IS_ERR(clk)) {
0a7f17aa 393 dev_err(priv->dev, "cannot get dot clock %s\n", str);
4774c12a 394 return PTR_ERR(clk);
f1f60b5f
LP
395 }
396
4774c12a 397 priv->dot_clk = clk;
f1f60b5f
LP
398 return 0;
399}
400
401/* -----------------------------------------------------------------------------
37c5dcc2 402 * Display, panel and deferred I/O
f1f60b5f
LP
403 */
404
cfb4f5d1
MD
405static void lcdc_sys_write_index(void *handle, unsigned long data)
406{
407 struct sh_mobile_lcdc_chan *ch = handle;
408
ce1c0b08
LP
409 lcdc_write(ch->lcdc, _LDDWD0R, data | LDDWDxR_WDACT);
410 lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
411 lcdc_write(ch->lcdc, _LDDWAR, LDDWAR_WA |
412 (lcdc_chan_is_sublcd(ch) ? 2 : 0));
413 lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
cfb4f5d1
MD
414}
415
416static void lcdc_sys_write_data(void *handle, unsigned long data)
417{
418 struct sh_mobile_lcdc_chan *ch = handle;
419
ce1c0b08
LP
420 lcdc_write(ch->lcdc, _LDDWD0R, data | LDDWDxR_WDACT | LDDWDxR_RSW);
421 lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
422 lcdc_write(ch->lcdc, _LDDWAR, LDDWAR_WA |
423 (lcdc_chan_is_sublcd(ch) ? 2 : 0));
424 lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
cfb4f5d1
MD
425}
426
427static unsigned long lcdc_sys_read_data(void *handle)
428{
429 struct sh_mobile_lcdc_chan *ch = handle;
430
ce1c0b08
LP
431 lcdc_write(ch->lcdc, _LDDRDR, LDDRDR_RSR);
432 lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
433 lcdc_write(ch->lcdc, _LDDRAR, LDDRAR_RA |
434 (lcdc_chan_is_sublcd(ch) ? 2 : 0));
cfb4f5d1 435 udelay(1);
ce1c0b08 436 lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
cfb4f5d1 437
ce1c0b08 438 return lcdc_read(ch->lcdc, _LDDRDR) & LDDRDR_DRD_MASK;
cfb4f5d1
MD
439}
440
441struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
442 lcdc_sys_write_index,
443 lcdc_sys_write_data,
444 lcdc_sys_read_data,
445};
446
1c6a307a
PM
447static int sh_mobile_lcdc_sginit(struct fb_info *info,
448 struct list_head *pagelist)
449{
450 struct sh_mobile_lcdc_chan *ch = info->par;
58f03d99 451 unsigned int nr_pages_max = ch->fb_size >> PAGE_SHIFT;
1c6a307a
PM
452 struct page *page;
453 int nr_pages = 0;
454
455 sg_init_table(ch->sglist, nr_pages_max);
456
457 list_for_each_entry(page, pagelist, lru)
458 sg_set_page(&ch->sglist[nr_pages++], page, PAGE_SIZE, 0);
459
460 return nr_pages;
461}
462
8564557a
MD
463static void sh_mobile_lcdc_deferred_io(struct fb_info *info,
464 struct list_head *pagelist)
465{
466 struct sh_mobile_lcdc_chan *ch = info->par;
b5ef967d 467 const struct sh_mobile_lcdc_panel_cfg *panel = &ch->cfg->panel_cfg;
8564557a
MD
468
469 /* enable clocks before accessing hardware */
470 sh_mobile_lcdc_clk_on(ch->lcdc);
471
5c1a56b5
PM
472 /*
473 * It's possible to get here without anything on the pagelist via
474 * sh_mobile_lcdc_deferred_io_touch() or via a userspace fsync()
475 * invocation. In the former case, the acceleration routines are
476 * stepped in to when using the framebuffer console causing the
477 * workqueue to be scheduled without any dirty pages on the list.
478 *
479 * Despite this, a panel update is still needed given that the
480 * acceleration routines have their own methods for writing in
481 * that still need to be updated.
482 *
483 * The fsync() and empty pagelist case could be optimized for,
484 * but we don't bother, as any application exhibiting such
485 * behaviour is fundamentally broken anyways.
486 */
487 if (!list_empty(pagelist)) {
488 unsigned int nr_pages = sh_mobile_lcdc_sginit(info, pagelist);
489
490 /* trigger panel update */
e8363140 491 dma_map_sg(ch->lcdc->dev, ch->sglist, nr_pages, DMA_TO_DEVICE);
afaad83b
LP
492 if (panel->start_transfer)
493 panel->start_transfer(ch, &sh_mobile_lcdc_sys_bus_ops);
ce1c0b08 494 lcdc_write_chan(ch, LDSM2R, LDSM2R_OSTRG);
e8363140
LP
495 dma_unmap_sg(ch->lcdc->dev, ch->sglist, nr_pages,
496 DMA_TO_DEVICE);
ef61aae4 497 } else {
afaad83b
LP
498 if (panel->start_transfer)
499 panel->start_transfer(ch, &sh_mobile_lcdc_sys_bus_ops);
ce1c0b08 500 lcdc_write_chan(ch, LDSM2R, LDSM2R_OSTRG);
ef61aae4 501 }
8564557a
MD
502}
503
504static void sh_mobile_lcdc_deferred_io_touch(struct fb_info *info)
505{
506 struct fb_deferred_io *fbdefio = info->fbdefio;
507
508 if (fbdefio)
509 schedule_delayed_work(&info->deferred_work, fbdefio->delay);
510}
511
37c5dcc2
LP
512static void sh_mobile_lcdc_display_on(struct sh_mobile_lcdc_chan *ch)
513{
b5ef967d 514 const struct sh_mobile_lcdc_panel_cfg *panel = &ch->cfg->panel_cfg;
37c5dcc2 515
9a2985e7 516 if (ch->tx_dev) {
458981c3
LP
517 int ret;
518
519 ret = ch->tx_dev->ops->display_on(ch->tx_dev);
520 if (ret < 0)
9a2985e7 521 return;
458981c3
LP
522
523 if (ret == SH_MOBILE_LCDC_DISPLAY_DISCONNECTED)
524 ch->info->state = FBINFO_STATE_SUSPENDED;
9a2985e7
LP
525 }
526
37c5dcc2 527 /* HDMI must be enabled before LCDC configuration */
afaad83b
LP
528 if (panel->display_on)
529 panel->display_on();
37c5dcc2
LP
530}
531
532static void sh_mobile_lcdc_display_off(struct sh_mobile_lcdc_chan *ch)
533{
b5ef967d 534 const struct sh_mobile_lcdc_panel_cfg *panel = &ch->cfg->panel_cfg;
37c5dcc2 535
afaad83b
LP
536 if (panel->display_off)
537 panel->display_off();
9a2985e7
LP
538
539 if (ch->tx_dev)
540 ch->tx_dev->ops->display_off(ch->tx_dev);
37c5dcc2
LP
541}
542
ecd29947
LP
543static bool
544sh_mobile_lcdc_must_reconfigure(struct sh_mobile_lcdc_chan *ch,
e0c8601a 545 const struct fb_videomode *new_mode)
ecd29947 546{
ecd29947 547 dev_dbg(ch->info->dev, "Old %ux%u, new %ux%u\n",
2d04559d
LP
548 ch->display.mode.xres, ch->display.mode.yres,
549 new_mode->xres, new_mode->yres);
ecd29947 550
e0c8601a 551 /* It can be a different monitor with an equal video-mode */
2d04559d 552 if (fb_mode_is_equal(&ch->display.mode, new_mode))
ecd29947 553 return false;
ecd29947
LP
554
555 dev_dbg(ch->info->dev, "Switching %u -> %u lines\n",
2d04559d
LP
556 ch->display.mode.yres, new_mode->yres);
557 ch->display.mode = *new_mode;
ecd29947
LP
558
559 return true;
560}
561
d7ad3342
LP
562static int sh_mobile_lcdc_check_var(struct fb_var_screeninfo *var,
563 struct fb_info *info);
ecd29947
LP
564
565static int sh_mobile_lcdc_display_notify(struct sh_mobile_lcdc_chan *ch,
566 enum sh_mobile_lcdc_entity_event event,
e0c8601a
LP
567 const struct fb_videomode *mode,
568 const struct fb_monspecs *monspec)
ecd29947
LP
569{
570 struct fb_info *info = ch->info;
e0c8601a 571 struct fb_var_screeninfo var;
ecd29947
LP
572 int ret = 0;
573
574 switch (event) {
575 case SH_MOBILE_LCDC_EVENT_DISPLAY_CONNECT:
576 /* HDMI plug in */
577 if (lock_fb_info(info)) {
578 console_lock();
579
2d04559d
LP
580 ch->display.width = monspec->max_x * 10;
581 ch->display.height = monspec->max_y * 10;
e0c8601a
LP
582
583 if (!sh_mobile_lcdc_must_reconfigure(ch, mode) &&
ecd29947
LP
584 info->state == FBINFO_STATE_RUNNING) {
585 /* First activation with the default monitor.
586 * Just turn on, if we run a resume here, the
587 * logo disappears.
588 */
e0c8601a
LP
589 info->var.width = monspec->max_x * 10;
590 info->var.height = monspec->max_y * 10;
ecd29947
LP
591 sh_mobile_lcdc_display_on(ch);
592 } else {
593 /* New monitor or have to wake up */
594 fb_set_suspend(info, 0);
595 }
596
597 console_unlock();
598 unlock_fb_info(info);
599 }
600 break;
601
602 case SH_MOBILE_LCDC_EVENT_DISPLAY_DISCONNECT:
603 /* HDMI disconnect */
604 if (lock_fb_info(info)) {
605 console_lock();
606 fb_set_suspend(info, 1);
607 console_unlock();
608 unlock_fb_info(info);
609 }
610 break;
611
612 case SH_MOBILE_LCDC_EVENT_DISPLAY_MODE:
613 /* Validate a proposed new mode */
e0c8601a
LP
614 fb_videomode_to_var(&var, mode);
615 var.bits_per_pixel = info->var.bits_per_pixel;
616 var.grayscale = info->var.grayscale;
d7ad3342 617 ret = sh_mobile_lcdc_check_var(&var, info);
ecd29947
LP
618 break;
619 }
620
621 return ret;
622}
623
f1f60b5f
LP
624/* -----------------------------------------------------------------------------
625 * Format helpers
626 */
627
105784bb
LP
628struct sh_mobile_lcdc_format_info {
629 u32 fourcc;
630 unsigned int bpp;
631 bool yuv;
632 u32 lddfr;
633};
634
635static const struct sh_mobile_lcdc_format_info sh_mobile_format_infos[] = {
636 {
637 .fourcc = V4L2_PIX_FMT_RGB565,
638 .bpp = 16,
639 .yuv = false,
640 .lddfr = LDDFR_PKF_RGB16,
641 }, {
642 .fourcc = V4L2_PIX_FMT_BGR24,
643 .bpp = 24,
644 .yuv = false,
645 .lddfr = LDDFR_PKF_RGB24,
646 }, {
647 .fourcc = V4L2_PIX_FMT_BGR32,
648 .bpp = 32,
649 .yuv = false,
650 .lddfr = LDDFR_PKF_ARGB32,
651 }, {
652 .fourcc = V4L2_PIX_FMT_NV12,
653 .bpp = 12,
654 .yuv = true,
655 .lddfr = LDDFR_CC | LDDFR_YF_420,
656 }, {
657 .fourcc = V4L2_PIX_FMT_NV21,
658 .bpp = 12,
659 .yuv = true,
660 .lddfr = LDDFR_CC | LDDFR_YF_420,
661 }, {
662 .fourcc = V4L2_PIX_FMT_NV16,
663 .bpp = 16,
664 .yuv = true,
665 .lddfr = LDDFR_CC | LDDFR_YF_422,
666 }, {
667 .fourcc = V4L2_PIX_FMT_NV61,
668 .bpp = 16,
669 .yuv = true,
670 .lddfr = LDDFR_CC | LDDFR_YF_422,
671 }, {
672 .fourcc = V4L2_PIX_FMT_NV24,
673 .bpp = 24,
674 .yuv = true,
675 .lddfr = LDDFR_CC | LDDFR_YF_444,
676 }, {
677 .fourcc = V4L2_PIX_FMT_NV42,
678 .bpp = 24,
679 .yuv = true,
680 .lddfr = LDDFR_CC | LDDFR_YF_444,
681 },
682};
683
684static const struct sh_mobile_lcdc_format_info *
685sh_mobile_format_info(u32 fourcc)
686{
687 unsigned int i;
688
689 for (i = 0; i < ARRAY_SIZE(sh_mobile_format_infos); ++i) {
690 if (sh_mobile_format_infos[i].fourcc == fourcc)
691 return &sh_mobile_format_infos[i];
692 }
693
694 return NULL;
695}
696
f1f60b5f
LP
697static int sh_mobile_format_fourcc(const struct fb_var_screeninfo *var)
698{
699 if (var->grayscale > 1)
700 return var->grayscale;
701
702 switch (var->bits_per_pixel) {
703 case 16:
704 return V4L2_PIX_FMT_RGB565;
705 case 24:
706 return V4L2_PIX_FMT_BGR24;
707 case 32:
708 return V4L2_PIX_FMT_BGR32;
709 default:
710 return 0;
711 }
712}
713
714static int sh_mobile_format_is_fourcc(const struct fb_var_screeninfo *var)
715{
716 return var->grayscale > 1;
717}
718
f1f60b5f
LP
719/* -----------------------------------------------------------------------------
720 * Start, stop and IRQ
721 */
722
8564557a
MD
723static irqreturn_t sh_mobile_lcdc_irq(int irq, void *data)
724{
725 struct sh_mobile_lcdc_priv *priv = data;
2feb075a 726 struct sh_mobile_lcdc_chan *ch;
9dd38819 727 unsigned long ldintr;
2feb075a
MD
728 int is_sub;
729 int k;
8564557a 730
dc48665f
LP
731 /* Acknowledge interrupts and disable further VSYNC End IRQs. */
732 ldintr = lcdc_read(priv, _LDINTR);
733 lcdc_write(priv, _LDINTR, (ldintr ^ LDINTR_STATUS_MASK) & ~LDINTR_VEE);
8564557a 734
2feb075a 735 /* figure out if this interrupt is for main or sub lcd */
ce1c0b08 736 is_sub = (lcdc_read(priv, _LDSR) & LDSR_MSS) ? 1 : 0;
2feb075a 737
9dd38819 738 /* wake up channel and disable clocks */
2feb075a
MD
739 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
740 ch = &priv->ch[k];
741
742 if (!ch->enabled)
743 continue;
744
dc48665f 745 /* Frame End */
9dd38819
PE
746 if (ldintr & LDINTR_FS) {
747 if (is_sub == lcdc_chan_is_sublcd(ch)) {
748 ch->frame_end = 1;
749 wake_up(&ch->frame_end_wait);
2feb075a 750
9dd38819
PE
751 sh_mobile_lcdc_clk_off(priv);
752 }
753 }
754
755 /* VSYNC End */
40331b21
PE
756 if (ldintr & LDINTR_VES)
757 complete(&ch->vsync_completion);
2feb075a
MD
758 }
759
8564557a
MD
760 return IRQ_HANDLED;
761}
762
d7ad3342 763static int sh_mobile_lcdc_wait_for_vsync(struct sh_mobile_lcdc_chan *ch)
4976677f
LP
764{
765 unsigned long ldintr;
766 int ret;
767
768 /* Enable VSync End interrupt and be careful not to acknowledge any
769 * pending interrupt.
770 */
771 ldintr = lcdc_read(ch->lcdc, _LDINTR);
772 ldintr |= LDINTR_VEE | LDINTR_STATUS_MASK;
773 lcdc_write(ch->lcdc, _LDINTR, ldintr);
774
775 ret = wait_for_completion_interruptible_timeout(&ch->vsync_completion,
776 msecs_to_jiffies(100));
777 if (!ret)
778 return -ETIMEDOUT;
779
780 return 0;
781}
782
cfb4f5d1
MD
783static void sh_mobile_lcdc_start_stop(struct sh_mobile_lcdc_priv *priv,
784 int start)
785{
786 unsigned long tmp = lcdc_read(priv, _LDCNT2R);
787 int k;
788
789 /* start or stop the lcdc */
790 if (start)
ce1c0b08 791 lcdc_write(priv, _LDCNT2R, tmp | LDCNT2R_DO);
cfb4f5d1 792 else
ce1c0b08 793 lcdc_write(priv, _LDCNT2R, tmp & ~LDCNT2R_DO);
cfb4f5d1
MD
794
795 /* wait until power is applied/stopped on all channels */
796 for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
797 if (lcdc_read(priv, _LDCNT2R) & priv->ch[k].enabled)
798 while (1) {
ce1c0b08
LP
799 tmp = lcdc_read_chan(&priv->ch[k], LDPMR)
800 & LDPMR_LPS;
801 if (start && tmp == LDPMR_LPS)
cfb4f5d1
MD
802 break;
803 if (!start && tmp == 0)
804 break;
805 cpu_relax();
806 }
807
808 if (!start)
809 lcdc_write(priv, _LDDCKSTPR, 1); /* stop dotclock */
810}
811
6011bdea
GL
812static void sh_mobile_lcdc_geometry(struct sh_mobile_lcdc_chan *ch)
813{
2d04559d
LP
814 const struct fb_var_screeninfo *var = &ch->info->var;
815 const struct fb_videomode *mode = &ch->display.mode;
1c120deb 816 unsigned long h_total, hsync_pos, display_h_total;
6011bdea
GL
817 u32 tmp;
818
819 tmp = ch->ldmt1r_value;
ce1c0b08
LP
820 tmp |= (var->sync & FB_SYNC_VERT_HIGH_ACT) ? 0 : LDMT1R_VPOL;
821 tmp |= (var->sync & FB_SYNC_HOR_HIGH_ACT) ? 0 : LDMT1R_HPOL;
b5ef967d
LP
822 tmp |= (ch->cfg->flags & LCDC_FLAGS_DWPOL) ? LDMT1R_DWPOL : 0;
823 tmp |= (ch->cfg->flags & LCDC_FLAGS_DIPOL) ? LDMT1R_DIPOL : 0;
824 tmp |= (ch->cfg->flags & LCDC_FLAGS_DAPOL) ? LDMT1R_DAPOL : 0;
825 tmp |= (ch->cfg->flags & LCDC_FLAGS_HSCNT) ? LDMT1R_HSCNT : 0;
826 tmp |= (ch->cfg->flags & LCDC_FLAGS_DWCNT) ? LDMT1R_DWCNT : 0;
6011bdea
GL
827 lcdc_write_chan(ch, LDMT1R, tmp);
828
829 /* setup SYS bus */
b5ef967d
LP
830 lcdc_write_chan(ch, LDMT2R, ch->cfg->sys_bus_cfg.ldmt2r);
831 lcdc_write_chan(ch, LDMT3R, ch->cfg->sys_bus_cfg.ldmt3r);
6011bdea
GL
832
833 /* horizontal configuration */
2d04559d
LP
834 h_total = mode->xres + mode->hsync_len + mode->left_margin
835 + mode->right_margin;
6011bdea 836 tmp = h_total / 8; /* HTCN */
58f03d99 837 tmp |= (min(mode->xres, ch->xres) / 8) << 16; /* HDCN */
6011bdea
GL
838 lcdc_write_chan(ch, LDHCNR, tmp);
839
2d04559d 840 hsync_pos = mode->xres + mode->right_margin;
6011bdea 841 tmp = hsync_pos / 8; /* HSYNP */
2d04559d 842 tmp |= (mode->hsync_len / 8) << 16; /* HSYNW */
6011bdea
GL
843 lcdc_write_chan(ch, LDHSYNR, tmp);
844
845 /* vertical configuration */
2d04559d
LP
846 tmp = mode->yres + mode->vsync_len + mode->upper_margin
847 + mode->lower_margin; /* VTLN */
58f03d99 848 tmp |= min(mode->yres, ch->yres) << 16; /* VDLN */
6011bdea
GL
849 lcdc_write_chan(ch, LDVLNR, tmp);
850
2d04559d
LP
851 tmp = mode->yres + mode->lower_margin; /* VSYNP */
852 tmp |= mode->vsync_len << 16; /* VSYNW */
6011bdea
GL
853 lcdc_write_chan(ch, LDVSYNR, tmp);
854
855 /* Adjust horizontal synchronisation for HDMI */
2d04559d
LP
856 display_h_total = mode->xres + mode->hsync_len + mode->left_margin
857 + mode->right_margin;
858 tmp = ((mode->xres & 7) << 24) | ((display_h_total & 7) << 16)
859 | ((mode->hsync_len & 7) << 8) | (hsync_pos & 7);
6011bdea
GL
860 lcdc_write_chan(ch, LDHAJR, tmp);
861}
862
c5deac3c
LP
863static void sh_mobile_lcdc_overlay_setup(struct sh_mobile_lcdc_overlay *ovl)
864{
865 u32 format = 0;
866
867 if (!ovl->enabled) {
868 lcdc_write(ovl->channel->lcdc, LDBCR, LDBCR_UPC(ovl->index));
869 lcdc_write_overlay(ovl, LDBnBSIFR(ovl->index), 0);
870 lcdc_write(ovl->channel->lcdc, LDBCR,
871 LDBCR_UPF(ovl->index) | LDBCR_UPD(ovl->index));
872 return;
873 }
874
875 ovl->base_addr_y = ovl->dma_handle;
876 ovl->base_addr_c = ovl->base_addr_y + ovl->xres
877 * ovl->yres_virtual;
878
879 switch (ovl->mode) {
880 case LCDC_OVERLAY_BLEND:
881 format = LDBBSIFR_EN | (ovl->alpha << LDBBSIFR_LAY_SHIFT);
882 break;
883
884 case LCDC_OVERLAY_ROP3:
885 format = LDBBSIFR_EN | LDBBSIFR_BRSEL
886 | (ovl->rop3 << LDBBSIFR_ROP3_SHIFT);
887 break;
888 }
889
890 switch (ovl->format->fourcc) {
891 case V4L2_PIX_FMT_RGB565:
892 case V4L2_PIX_FMT_NV21:
893 case V4L2_PIX_FMT_NV61:
894 case V4L2_PIX_FMT_NV42:
895 format |= LDBBSIFR_SWPL | LDBBSIFR_SWPW;
896 break;
897 case V4L2_PIX_FMT_BGR24:
898 case V4L2_PIX_FMT_NV12:
899 case V4L2_PIX_FMT_NV16:
900 case V4L2_PIX_FMT_NV24:
901 format |= LDBBSIFR_SWPL | LDBBSIFR_SWPW | LDBBSIFR_SWPB;
902 break;
903 case V4L2_PIX_FMT_BGR32:
904 default:
905 format |= LDBBSIFR_SWPL;
906 break;
907 }
908
909 switch (ovl->format->fourcc) {
910 case V4L2_PIX_FMT_RGB565:
911 format |= LDBBSIFR_AL_1 | LDBBSIFR_RY | LDBBSIFR_RPKF_RGB16;
912 break;
913 case V4L2_PIX_FMT_BGR24:
914 format |= LDBBSIFR_AL_1 | LDBBSIFR_RY | LDBBSIFR_RPKF_RGB24;
915 break;
916 case V4L2_PIX_FMT_BGR32:
917 format |= LDBBSIFR_AL_PK | LDBBSIFR_RY | LDDFR_PKF_ARGB32;
918 break;
919 case V4L2_PIX_FMT_NV12:
920 case V4L2_PIX_FMT_NV21:
921 format |= LDBBSIFR_AL_1 | LDBBSIFR_CHRR_420;
922 break;
923 case V4L2_PIX_FMT_NV16:
924 case V4L2_PIX_FMT_NV61:
925 format |= LDBBSIFR_AL_1 | LDBBSIFR_CHRR_422;
926 break;
927 case V4L2_PIX_FMT_NV24:
928 case V4L2_PIX_FMT_NV42:
929 format |= LDBBSIFR_AL_1 | LDBBSIFR_CHRR_444;
930 break;
931 }
932
933 lcdc_write(ovl->channel->lcdc, LDBCR, LDBCR_UPC(ovl->index));
934
935 lcdc_write_overlay(ovl, LDBnBSIFR(ovl->index), format);
936
937 lcdc_write_overlay(ovl, LDBnBSSZR(ovl->index),
938 (ovl->yres << LDBBSSZR_BVSS_SHIFT) |
939 (ovl->xres << LDBBSSZR_BHSS_SHIFT));
940 lcdc_write_overlay(ovl, LDBnBLOCR(ovl->index),
941 (ovl->pos_y << LDBBLOCR_CVLC_SHIFT) |
942 (ovl->pos_x << LDBBLOCR_CHLC_SHIFT));
943 lcdc_write_overlay(ovl, LDBnBSMWR(ovl->index),
944 ovl->pitch << LDBBSMWR_BSMW_SHIFT);
945
946 lcdc_write_overlay(ovl, LDBnBSAYR(ovl->index), ovl->base_addr_y);
947 lcdc_write_overlay(ovl, LDBnBSACR(ovl->index), ovl->base_addr_c);
948
949 lcdc_write(ovl->channel->lcdc, LDBCR,
950 LDBCR_UPF(ovl->index) | LDBCR_UPD(ovl->index));
951}
952
9a217e34 953/*
d7ad3342 954 * __sh_mobile_lcdc_start - Configure and start the LCDC
9a217e34
LP
955 * @priv: LCDC device
956 *
957 * Configure all enabled channels and start the LCDC device. All external
958 * devices (clocks, MERAM, panels, ...) are not touched by this function.
959 */
960static void __sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv)
cfb4f5d1
MD
961{
962 struct sh_mobile_lcdc_chan *ch;
cfb4f5d1 963 unsigned long tmp;
9a217e34 964 int k, m;
8564557a 965
9a217e34
LP
966 /* Enable LCDC channels. Read data from external memory, avoid using the
967 * BEU for now.
968 */
969 lcdc_write(priv, _LDCNT2R, priv->ch[0].enabled | priv->ch[1].enabled);
cfb4f5d1 970
9a217e34 971 /* Stop the LCDC first and disable all interrupts. */
cfb4f5d1 972 sh_mobile_lcdc_start_stop(priv, 0);
9a217e34 973 lcdc_write(priv, _LDINTR, 0);
cfb4f5d1 974
9a217e34 975 /* Configure power supply, dot clocks and start them. */
cfb4f5d1
MD
976 tmp = priv->lddckr;
977 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
978 ch = &priv->ch[k];
9a217e34 979 if (!ch->enabled)
cfb4f5d1
MD
980 continue;
981
9a217e34
LP
982 /* Power supply */
983 lcdc_write_chan(ch, LDPMR, 0);
984
b5ef967d 985 m = ch->cfg->clock_divider;
cfb4f5d1
MD
986 if (!m)
987 continue;
988
505c7de5
LP
989 /* FIXME: sh7724 can only use 42, 48, 54 and 60 for the divider
990 * denominator.
991 */
992 lcdc_write_chan(ch, LDDCKPAT1R, 0);
993 lcdc_write_chan(ch, LDDCKPAT2R, (1 << (m/2)) - 1);
994
cfb4f5d1 995 if (m == 1)
ce1c0b08 996 m = LDDCKR_MOSEL;
cfb4f5d1 997 tmp |= m << (lcdc_chan_is_sublcd(ch) ? 8 : 0);
cfb4f5d1
MD
998 }
999
1000 lcdc_write(priv, _LDDCKR, tmp);
cfb4f5d1
MD
1001 lcdc_write(priv, _LDDCKSTPR, 0);
1002 lcdc_wait_bit(priv, _LDDCKSTPR, ~0, 0);
1003
9a217e34 1004 /* Setup geometry, format, frame buffer memory and operation mode. */
cfb4f5d1
MD
1005 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
1006 ch = &priv->ch[k];
cfb4f5d1
MD
1007 if (!ch->enabled)
1008 continue;
1009
6011bdea 1010 sh_mobile_lcdc_geometry(ch);
cfb4f5d1 1011
fc9e78e6 1012 tmp = ch->format->lddfr;
edd153a3 1013
fc9e78e6 1014 if (ch->format->yuv) {
58f03d99 1015 switch (ch->colorspace) {
edd153a3
LP
1016 case V4L2_COLORSPACE_REC709:
1017 tmp |= LDDFR_CF1;
53b50314 1018 break;
edd153a3
LP
1019 case V4L2_COLORSPACE_JPEG:
1020 tmp |= LDDFR_CF0;
53b50314
DHG
1021 break;
1022 }
417d4827 1023 }
7caa4342 1024
9a217e34 1025 lcdc_write_chan(ch, LDDFR, tmp);
72c04af9 1026 lcdc_write_chan(ch, LDMLSR, ch->line_size);
9a217e34 1027 lcdc_write_chan(ch, LDSA1R, ch->base_addr_y);
fc9e78e6 1028 if (ch->format->yuv)
9a217e34 1029 lcdc_write_chan(ch, LDSA2R, ch->base_addr_c);
7caa4342 1030
9a217e34
LP
1031 /* When using deferred I/O mode, configure the LCDC for one-shot
1032 * operation and enable the frame end interrupt. Otherwise use
1033 * continuous read mode.
1034 */
1035 if (ch->ldmt1r_value & LDMT1R_IFM &&
b5ef967d 1036 ch->cfg->sys_bus_cfg.deferred_io_msec) {
9a217e34
LP
1037 lcdc_write_chan(ch, LDSM1R, LDSM1R_OS);
1038 lcdc_write(priv, _LDINTR, LDINTR_FE);
1039 } else {
1040 lcdc_write_chan(ch, LDSM1R, 0);
1041 }
1042 }
7caa4342 1043
9a217e34 1044 /* Word and long word swap. */
fc9e78e6 1045 switch (priv->ch[0].format->fourcc) {
edd153a3
LP
1046 case V4L2_PIX_FMT_RGB565:
1047 case V4L2_PIX_FMT_NV21:
1048 case V4L2_PIX_FMT_NV61:
1049 case V4L2_PIX_FMT_NV42:
1050 tmp = LDDDSR_LS | LDDDSR_WS;
1051 break;
1052 case V4L2_PIX_FMT_BGR24:
1053 case V4L2_PIX_FMT_NV12:
1054 case V4L2_PIX_FMT_NV16:
1055 case V4L2_PIX_FMT_NV24:
9a217e34 1056 tmp = LDDDSR_LS | LDDDSR_WS | LDDDSR_BS;
edd153a3
LP
1057 break;
1058 case V4L2_PIX_FMT_BGR32:
1059 default:
1060 tmp = LDDDSR_LS;
1061 break;
9a217e34
LP
1062 }
1063 lcdc_write(priv, _LDDDSR, tmp);
7caa4342 1064
9a217e34
LP
1065 /* Enable the display output. */
1066 lcdc_write(priv, _LDCNT1R, LDCNT1R_DE);
1067 sh_mobile_lcdc_start_stop(priv, 1);
1068 priv->started = 1;
1069}
cfb4f5d1 1070
9a217e34
LP
1071static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv)
1072{
1073 struct sh_mobile_meram_info *mdev = priv->meram_dev;
9a217e34
LP
1074 struct sh_mobile_lcdc_chan *ch;
1075 unsigned long tmp;
1076 int ret;
1077 int k;
cfb4f5d1 1078
9a217e34
LP
1079 /* enable clocks before accessing the hardware */
1080 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
1081 if (priv->ch[k].enabled)
1082 sh_mobile_lcdc_clk_on(priv);
1083 }
8564557a 1084
9a217e34
LP
1085 /* reset */
1086 lcdc_write(priv, _LDCNT2R, lcdc_read(priv, _LDCNT2R) | LDCNT2R_BR);
1087 lcdc_wait_bit(priv, _LDCNT2R, LDCNT2R_BR, 0);
8564557a 1088
9a217e34 1089 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
b5ef967d 1090 const struct sh_mobile_lcdc_panel_cfg *panel;
8564557a 1091
37c5dcc2 1092 ch = &priv->ch[k];
9a217e34
LP
1093 if (!ch->enabled)
1094 continue;
1095
b5ef967d 1096 panel = &ch->cfg->panel_cfg;
afaad83b
LP
1097 if (panel->setup_sys) {
1098 ret = panel->setup_sys(ch, &sh_mobile_lcdc_sys_bus_ops);
9a217e34
LP
1099 if (ret)
1100 return ret;
8564557a 1101 }
cfb4f5d1
MD
1102 }
1103
9a217e34
LP
1104 /* Compute frame buffer base address and pitch for each channel. */
1105 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
9a217e34 1106 int pixelformat;
4a237177 1107 void *cache;
cfb4f5d1 1108
9a217e34
LP
1109 ch = &priv->ch[k];
1110 if (!ch->enabled)
1111 continue;
cfb4f5d1 1112
58f03d99
LP
1113 ch->base_addr_y = ch->dma_handle;
1114 ch->base_addr_c = ch->base_addr_y + ch->xres * ch->yres_virtual;
72c04af9 1115 ch->line_size = ch->pitch;
9a217e34
LP
1116
1117 /* Enable MERAM if possible. */
6e729b41 1118 if (mdev == NULL || ch->cfg->meram_cfg == NULL)
9a217e34
LP
1119 continue;
1120
4a237177
LP
1121 /* Free the allocated MERAM cache. */
1122 if (ch->cache) {
6e729b41 1123 sh_mobile_meram_cache_free(mdev, ch->cache);
4a237177 1124 ch->cache = NULL;
9a217e34
LP
1125 }
1126
fc9e78e6 1127 switch (ch->format->fourcc) {
edd153a3
LP
1128 case V4L2_PIX_FMT_NV12:
1129 case V4L2_PIX_FMT_NV21:
1130 case V4L2_PIX_FMT_NV16:
1131 case V4L2_PIX_FMT_NV61:
9a217e34 1132 pixelformat = SH_MOBILE_MERAM_PF_NV;
edd153a3
LP
1133 break;
1134 case V4L2_PIX_FMT_NV24:
1135 case V4L2_PIX_FMT_NV42:
1136 pixelformat = SH_MOBILE_MERAM_PF_NV24;
1137 break;
1138 case V4L2_PIX_FMT_RGB565:
1139 case V4L2_PIX_FMT_BGR24:
1140 case V4L2_PIX_FMT_BGR32:
1141 default:
1142 pixelformat = SH_MOBILE_MERAM_PF_RGB;
1143 break;
1144 }
9a217e34 1145
6e729b41 1146 cache = sh_mobile_meram_cache_alloc(mdev, ch->cfg->meram_cfg,
b5ef967d 1147 ch->pitch, ch->yres, pixelformat,
72c04af9 1148 &ch->line_size);
4a237177 1149 if (!IS_ERR(cache)) {
6e729b41 1150 sh_mobile_meram_cache_update(mdev, cache,
97d16fe6
LP
1151 ch->base_addr_y, ch->base_addr_c,
1152 &ch->base_addr_y, &ch->base_addr_c);
4a237177 1153 ch->cache = cache;
97d16fe6 1154 }
9a217e34
LP
1155 }
1156
c5deac3c
LP
1157 for (k = 0; k < ARRAY_SIZE(priv->overlays); ++k) {
1158 struct sh_mobile_lcdc_overlay *ovl = &priv->overlays[k];
1159 sh_mobile_lcdc_overlay_setup(ovl);
1160 }
1161
9a217e34
LP
1162 /* Start the LCDC. */
1163 __sh_mobile_lcdc_start(priv);
1164
1165 /* Setup deferred I/O, tell the board code to enable the panels, and
1166 * turn backlight on.
1167 */
cfb4f5d1
MD
1168 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
1169 ch = &priv->ch[k];
21bc1f02
MD
1170 if (!ch->enabled)
1171 continue;
1172
b5ef967d 1173 tmp = ch->cfg->sys_bus_cfg.deferred_io_msec;
9a217e34
LP
1174 if (ch->ldmt1r_value & LDMT1R_IFM && tmp) {
1175 ch->defio.deferred_io = sh_mobile_lcdc_deferred_io;
1176 ch->defio.delay = msecs_to_jiffies(tmp);
1177 ch->info->fbdefio = &ch->defio;
1178 fb_deferred_io_init(ch->info);
1179 }
1180
37c5dcc2 1181 sh_mobile_lcdc_display_on(ch);
3b0fd9d7
AC
1182
1183 if (ch->bl) {
1184 ch->bl->props.power = FB_BLANK_UNBLANK;
1185 backlight_update_status(ch->bl);
1186 }
cfb4f5d1
MD
1187 }
1188
1189 return 0;
1190}
1191
1192static void sh_mobile_lcdc_stop(struct sh_mobile_lcdc_priv *priv)
1193{
1194 struct sh_mobile_lcdc_chan *ch;
cfb4f5d1
MD
1195 int k;
1196
2feb075a 1197 /* clean up deferred io and ask board code to disable panel */
cfb4f5d1
MD
1198 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
1199 ch = &priv->ch[k];
21bc1f02
MD
1200 if (!ch->enabled)
1201 continue;
8564557a 1202
2feb075a
MD
1203 /* deferred io mode:
1204 * flush frame, and wait for frame end interrupt
1205 * clean up deferred io and enable clock
1206 */
5ef6b505 1207 if (ch->info && ch->info->fbdefio) {
2feb075a 1208 ch->frame_end = 0;
e33afddc 1209 schedule_delayed_work(&ch->info->deferred_work, 0);
2feb075a 1210 wait_event(ch->frame_end_wait, ch->frame_end);
e33afddc
PM
1211 fb_deferred_io_cleanup(ch->info);
1212 ch->info->fbdefio = NULL;
2feb075a 1213 sh_mobile_lcdc_clk_on(priv);
8564557a 1214 }
2feb075a 1215
3b0fd9d7
AC
1216 if (ch->bl) {
1217 ch->bl->props.power = FB_BLANK_POWERDOWN;
1218 backlight_update_status(ch->bl);
1219 }
1220
37c5dcc2 1221 sh_mobile_lcdc_display_off(ch);
7caa4342 1222
4a237177
LP
1223 /* Free the MERAM cache. */
1224 if (ch->cache) {
6e729b41 1225 sh_mobile_meram_cache_free(priv->meram_dev, ch->cache);
4a237177 1226 ch->cache = 0;
7caa4342
D
1227 }
1228
cfb4f5d1
MD
1229 }
1230
1231 /* stop the lcdc */
8e9bb19e
MD
1232 if (priv->started) {
1233 sh_mobile_lcdc_start_stop(priv, 0);
1234 priv->started = 0;
1235 }
b51339ff 1236
8564557a
MD
1237 /* stop clocks */
1238 for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
1239 if (priv->ch[k].enabled)
1240 sh_mobile_lcdc_clk_off(priv);
cfb4f5d1
MD
1241}
1242
c5deac3c
LP
1243static int __sh_mobile_lcdc_check_var(struct fb_var_screeninfo *var,
1244 struct fb_info *info)
1245{
1246 if (var->xres > MAX_XRES || var->yres > MAX_YRES)
1247 return -EINVAL;
1248
1249 /* Make sure the virtual resolution is at least as big as the visible
1250 * resolution.
1251 */
1252 if (var->xres_virtual < var->xres)
1253 var->xres_virtual = var->xres;
1254 if (var->yres_virtual < var->yres)
1255 var->yres_virtual = var->yres;
1256
1257 if (sh_mobile_format_is_fourcc(var)) {
1258 const struct sh_mobile_lcdc_format_info *format;
1259
1260 format = sh_mobile_format_info(var->grayscale);
1261 if (format == NULL)
1262 return -EINVAL;
1263 var->bits_per_pixel = format->bpp;
1264
1265 /* Default to RGB and JPEG color-spaces for RGB and YUV formats
1266 * respectively.
1267 */
1268 if (!format->yuv)
1269 var->colorspace = V4L2_COLORSPACE_SRGB;
1270 else if (var->colorspace != V4L2_COLORSPACE_REC709)
1271 var->colorspace = V4L2_COLORSPACE_JPEG;
1272 } else {
1273 if (var->bits_per_pixel <= 16) { /* RGB 565 */
1274 var->bits_per_pixel = 16;
1275 var->red.offset = 11;
1276 var->red.length = 5;
1277 var->green.offset = 5;
1278 var->green.length = 6;
1279 var->blue.offset = 0;
1280 var->blue.length = 5;
1281 var->transp.offset = 0;
1282 var->transp.length = 0;
1283 } else if (var->bits_per_pixel <= 24) { /* RGB 888 */
1284 var->bits_per_pixel = 24;
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 = 0;
1292 var->transp.length = 0;
1293 } else if (var->bits_per_pixel <= 32) { /* RGBA 888 */
1294 var->bits_per_pixel = 32;
1295 var->red.offset = 16;
1296 var->red.length = 8;
1297 var->green.offset = 8;
1298 var->green.length = 8;
1299 var->blue.offset = 0;
1300 var->blue.length = 8;
1301 var->transp.offset = 24;
1302 var->transp.length = 8;
1303 } else
1304 return -EINVAL;
1305
1306 var->red.msb_right = 0;
1307 var->green.msb_right = 0;
1308 var->blue.msb_right = 0;
1309 var->transp.msb_right = 0;
1310 }
1311
1312 /* Make sure we don't exceed our allocated memory. */
1313 if (var->xres_virtual * var->yres_virtual * var->bits_per_pixel / 8 >
1314 info->fix.smem_len)
1315 return -EINVAL;
1316
1317 return 0;
1318}
1319
1320/* -----------------------------------------------------------------------------
1321 * Frame buffer operations - Overlays
1322 */
1323
1324static ssize_t
1325overlay_alpha_show(struct device *dev, struct device_attribute *attr, char *buf)
1326{
1327 struct fb_info *info = dev_get_drvdata(dev);
1328 struct sh_mobile_lcdc_overlay *ovl = info->par;
1329
1330 return scnprintf(buf, PAGE_SIZE, "%u\n", ovl->alpha);
1331}
1332
1333static ssize_t
1334overlay_alpha_store(struct device *dev, struct device_attribute *attr,
1335 const char *buf, size_t count)
1336{
1337 struct fb_info *info = dev_get_drvdata(dev);
1338 struct sh_mobile_lcdc_overlay *ovl = info->par;
1339 unsigned int alpha;
1340 char *endp;
1341
1342 alpha = simple_strtoul(buf, &endp, 10);
1343 if (isspace(*endp))
1344 endp++;
1345
1346 if (endp - buf != count)
1347 return -EINVAL;
1348
1349 if (alpha > 255)
1350 return -EINVAL;
1351
1352 if (ovl->alpha != alpha) {
1353 ovl->alpha = alpha;
1354
1355 if (ovl->mode == LCDC_OVERLAY_BLEND && ovl->enabled)
1356 sh_mobile_lcdc_overlay_setup(ovl);
1357 }
1358
1359 return count;
1360}
1361
1362static ssize_t
1363overlay_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
1364{
1365 struct fb_info *info = dev_get_drvdata(dev);
1366 struct sh_mobile_lcdc_overlay *ovl = info->par;
1367
1368 return scnprintf(buf, PAGE_SIZE, "%u\n", ovl->mode);
1369}
1370
1371static ssize_t
1372overlay_mode_store(struct device *dev, struct device_attribute *attr,
1373 const char *buf, size_t count)
1374{
1375 struct fb_info *info = dev_get_drvdata(dev);
1376 struct sh_mobile_lcdc_overlay *ovl = info->par;
1377 unsigned int mode;
1378 char *endp;
1379
1380 mode = simple_strtoul(buf, &endp, 10);
1381 if (isspace(*endp))
1382 endp++;
1383
1384 if (endp - buf != count)
1385 return -EINVAL;
1386
1387 if (mode != LCDC_OVERLAY_BLEND && mode != LCDC_OVERLAY_ROP3)
1388 return -EINVAL;
1389
1390 if (ovl->mode != mode) {
1391 ovl->mode = mode;
1392
1393 if (ovl->enabled)
1394 sh_mobile_lcdc_overlay_setup(ovl);
1395 }
1396
1397 return count;
1398}
1399
1400static ssize_t
1401overlay_position_show(struct device *dev, struct device_attribute *attr,
1402 char *buf)
1403{
1404 struct fb_info *info = dev_get_drvdata(dev);
1405 struct sh_mobile_lcdc_overlay *ovl = info->par;
1406
1407 return scnprintf(buf, PAGE_SIZE, "%d,%d\n", ovl->pos_x, ovl->pos_y);
1408}
1409
1410static ssize_t
1411overlay_position_store(struct device *dev, struct device_attribute *attr,
1412 const char *buf, size_t count)
1413{
1414 struct fb_info *info = dev_get_drvdata(dev);
1415 struct sh_mobile_lcdc_overlay *ovl = info->par;
1416 char *endp;
1417 int pos_x;
1418 int pos_y;
1419
1420 pos_x = simple_strtol(buf, &endp, 10);
1421 if (*endp != ',')
1422 return -EINVAL;
1423
1424 pos_y = simple_strtol(endp + 1, &endp, 10);
1425 if (isspace(*endp))
1426 endp++;
1427
1428 if (endp - buf != count)
1429 return -EINVAL;
1430
1431 if (ovl->pos_x != pos_x || ovl->pos_y != pos_y) {
1432 ovl->pos_x = pos_x;
1433 ovl->pos_y = pos_y;
1434
1435 if (ovl->enabled)
1436 sh_mobile_lcdc_overlay_setup(ovl);
1437 }
1438
1439 return count;
1440}
1441
1442static ssize_t
1443overlay_rop3_show(struct device *dev, struct device_attribute *attr, char *buf)
1444{
1445 struct fb_info *info = dev_get_drvdata(dev);
1446 struct sh_mobile_lcdc_overlay *ovl = info->par;
1447
1448 return scnprintf(buf, PAGE_SIZE, "%u\n", ovl->rop3);
1449}
1450
1451static ssize_t
1452overlay_rop3_store(struct device *dev, struct device_attribute *attr,
1453 const char *buf, size_t count)
1454{
1455 struct fb_info *info = dev_get_drvdata(dev);
1456 struct sh_mobile_lcdc_overlay *ovl = info->par;
1457 unsigned int rop3;
1458 char *endp;
1459
1460 rop3 = !!simple_strtoul(buf, &endp, 10);
1461 if (isspace(*endp))
1462 endp++;
1463
1464 if (endp - buf != count)
1465 return -EINVAL;
1466
1467 if (rop3 > 255)
1468 return -EINVAL;
1469
1470 if (ovl->rop3 != rop3) {
1471 ovl->rop3 = rop3;
1472
1473 if (ovl->mode == LCDC_OVERLAY_ROP3 && ovl->enabled)
1474 sh_mobile_lcdc_overlay_setup(ovl);
1475 }
1476
1477 return count;
1478}
1479
1480static const struct device_attribute overlay_sysfs_attrs[] = {
1481 __ATTR(ovl_alpha, S_IRUGO|S_IWUSR,
1482 overlay_alpha_show, overlay_alpha_store),
1483 __ATTR(ovl_mode, S_IRUGO|S_IWUSR,
1484 overlay_mode_show, overlay_mode_store),
1485 __ATTR(ovl_position, S_IRUGO|S_IWUSR,
1486 overlay_position_show, overlay_position_store),
1487 __ATTR(ovl_rop3, S_IRUGO|S_IWUSR,
1488 overlay_rop3_show, overlay_rop3_store),
1489};
1490
1491static const struct fb_fix_screeninfo sh_mobile_lcdc_overlay_fix = {
1492 .id = "SH Mobile LCDC",
1493 .type = FB_TYPE_PACKED_PIXELS,
1494 .visual = FB_VISUAL_TRUECOLOR,
1495 .accel = FB_ACCEL_NONE,
15dede88 1496 .xpanstep = 1,
c5deac3c
LP
1497 .ypanstep = 1,
1498 .ywrapstep = 0,
1499 .capabilities = FB_CAP_FOURCC,
1500};
1501
1502static int sh_mobile_lcdc_overlay_pan(struct fb_var_screeninfo *var,
1503 struct fb_info *info)
1504{
1505 struct sh_mobile_lcdc_overlay *ovl = info->par;
1506 unsigned long base_addr_y;
1507 unsigned long base_addr_c;
1508 unsigned long pan_offset;
1509 unsigned long c_offset;
1510
1511 if (!ovl->format->yuv)
1512 pan_offset = var->yoffset * ovl->pitch
1513 + var->xoffset * (ovl->format->bpp / 8);
1514 else
1515 pan_offset = var->yoffset * ovl->pitch + var->xoffset;
1516
1517 if (pan_offset == ovl->pan_offset)
1518 return 0; /* No change, do nothing */
1519
1520 /* Set the source address for the next refresh */
1521 base_addr_y = ovl->dma_handle + pan_offset;
1522
1523 ovl->base_addr_y = base_addr_y;
1524 ovl->base_addr_c = base_addr_y;
1525
1526 if (ovl->format->yuv) {
1527 /* Set Y offset */
1528 c_offset = var->yoffset * ovl->pitch
1529 * (ovl->format->bpp - 8) / 8;
1530 base_addr_c = ovl->dma_handle
1531 + ovl->xres * ovl->yres_virtual
1532 + c_offset;
1533 /* Set X offset */
1534 if (ovl->format->fourcc == V4L2_PIX_FMT_NV24)
1535 base_addr_c += 2 * var->xoffset;
1536 else
1537 base_addr_c += var->xoffset;
1538
1539 ovl->base_addr_c = base_addr_c;
1540 }
1541
8be7c669
LP
1542 lcdc_write(ovl->channel->lcdc, LDBCR, LDBCR_UPC(ovl->index));
1543
c5deac3c
LP
1544 lcdc_write_overlay(ovl, LDBnBSAYR(ovl->index), ovl->base_addr_y);
1545 lcdc_write_overlay(ovl, LDBnBSACR(ovl->index), ovl->base_addr_c);
1546
8be7c669
LP
1547 lcdc_write(ovl->channel->lcdc, LDBCR,
1548 LDBCR_UPF(ovl->index) | LDBCR_UPD(ovl->index));
1549
c5deac3c
LP
1550 ovl->pan_offset = pan_offset;
1551
1552 return 0;
1553}
1554
1555static int sh_mobile_lcdc_overlay_ioctl(struct fb_info *info, unsigned int cmd,
1556 unsigned long arg)
1557{
1558 struct sh_mobile_lcdc_overlay *ovl = info->par;
1559
1560 switch (cmd) {
1561 case FBIO_WAITFORVSYNC:
1562 return sh_mobile_lcdc_wait_for_vsync(ovl->channel);
1563
1564 default:
1565 return -ENOIOCTLCMD;
1566 }
1567}
1568
1569static int sh_mobile_lcdc_overlay_check_var(struct fb_var_screeninfo *var,
1570 struct fb_info *info)
1571{
1572 return __sh_mobile_lcdc_check_var(var, info);
1573}
1574
1575static int sh_mobile_lcdc_overlay_set_par(struct fb_info *info)
1576{
1577 struct sh_mobile_lcdc_overlay *ovl = info->par;
1578
1579 ovl->format =
1580 sh_mobile_format_info(sh_mobile_format_fourcc(&info->var));
1581
1582 ovl->xres = info->var.xres;
1583 ovl->xres_virtual = info->var.xres_virtual;
1584 ovl->yres = info->var.yres;
1585 ovl->yres_virtual = info->var.yres_virtual;
1586
1587 if (ovl->format->yuv)
16ca21c9 1588 ovl->pitch = info->var.xres_virtual;
c5deac3c 1589 else
16ca21c9 1590 ovl->pitch = info->var.xres_virtual * ovl->format->bpp / 8;
c5deac3c
LP
1591
1592 sh_mobile_lcdc_overlay_setup(ovl);
1593
1594 info->fix.line_length = ovl->pitch;
1595
1596 if (sh_mobile_format_is_fourcc(&info->var)) {
1597 info->fix.type = FB_TYPE_FOURCC;
1598 info->fix.visual = FB_VISUAL_FOURCC;
1599 } else {
1600 info->fix.type = FB_TYPE_PACKED_PIXELS;
1601 info->fix.visual = FB_VISUAL_TRUECOLOR;
1602 }
1603
1604 return 0;
1605}
1606
1607/* Overlay blanking. Disable the overlay when blanked. */
1608static int sh_mobile_lcdc_overlay_blank(int blank, struct fb_info *info)
1609{
1610 struct sh_mobile_lcdc_overlay *ovl = info->par;
1611
1612 ovl->enabled = !blank;
1613 sh_mobile_lcdc_overlay_setup(ovl);
1614
1615 /* Prevent the backlight from receiving a blanking event by returning
1616 * a non-zero value.
1617 */
1618 return 1;
1619}
1620
1621static struct fb_ops sh_mobile_lcdc_overlay_ops = {
1622 .owner = THIS_MODULE,
1623 .fb_read = fb_sys_read,
1624 .fb_write = fb_sys_write,
1625 .fb_fillrect = sys_fillrect,
1626 .fb_copyarea = sys_copyarea,
1627 .fb_imageblit = sys_imageblit,
1628 .fb_blank = sh_mobile_lcdc_overlay_blank,
1629 .fb_pan_display = sh_mobile_lcdc_overlay_pan,
1630 .fb_ioctl = sh_mobile_lcdc_overlay_ioctl,
1631 .fb_check_var = sh_mobile_lcdc_overlay_check_var,
1632 .fb_set_par = sh_mobile_lcdc_overlay_set_par,
1633};
1634
1635static void
1636sh_mobile_lcdc_overlay_fb_unregister(struct sh_mobile_lcdc_overlay *ovl)
1637{
1638 struct fb_info *info = ovl->info;
1639
1640 if (info == NULL || info->dev == NULL)
1641 return;
1642
1643 unregister_framebuffer(ovl->info);
1644}
1645
1646static int __devinit
1647sh_mobile_lcdc_overlay_fb_register(struct sh_mobile_lcdc_overlay *ovl)
1648{
1649 struct sh_mobile_lcdc_priv *lcdc = ovl->channel->lcdc;
1650 struct fb_info *info = ovl->info;
1651 unsigned int i;
1652 int ret;
1653
1654 if (info == NULL)
1655 return 0;
1656
1657 ret = register_framebuffer(info);
1658 if (ret < 0)
1659 return ret;
1660
1661 dev_info(lcdc->dev, "registered %s/overlay %u as %dx%d %dbpp.\n",
1662 dev_name(lcdc->dev), ovl->index, info->var.xres,
1663 info->var.yres, info->var.bits_per_pixel);
1664
1665 for (i = 0; i < ARRAY_SIZE(overlay_sysfs_attrs); ++i) {
1666 ret = device_create_file(info->dev, &overlay_sysfs_attrs[i]);
1667 if (ret < 0)
1668 return ret;
1669 }
1670
1671 return 0;
1672}
1673
1674static void
1675sh_mobile_lcdc_overlay_fb_cleanup(struct sh_mobile_lcdc_overlay *ovl)
1676{
1677 struct fb_info *info = ovl->info;
1678
1679 if (info == NULL || info->device == NULL)
1680 return;
1681
1682 framebuffer_release(info);
1683}
1684
1685static int __devinit
1686sh_mobile_lcdc_overlay_fb_init(struct sh_mobile_lcdc_overlay *ovl)
1687{
1688 struct sh_mobile_lcdc_priv *priv = ovl->channel->lcdc;
1689 struct fb_var_screeninfo *var;
1690 struct fb_info *info;
1691
1692 /* Allocate and initialize the frame buffer device. */
1693 info = framebuffer_alloc(0, priv->dev);
1694 if (info == NULL) {
1695 dev_err(priv->dev, "unable to allocate fb_info\n");
1696 return -ENOMEM;
1697 }
1698
1699 ovl->info = info;
1700
1701 info->flags = FBINFO_FLAG_DEFAULT;
1702 info->fbops = &sh_mobile_lcdc_overlay_ops;
1703 info->device = priv->dev;
1704 info->screen_base = ovl->fb_mem;
1705 info->par = ovl;
1706
1707 /* Initialize fixed screen information. Restrict pan to 2 lines steps
1708 * for NV12 and NV21.
1709 */
1710 info->fix = sh_mobile_lcdc_overlay_fix;
1711 snprintf(info->fix.id, sizeof(info->fix.id),
1712 "SH Mobile LCDC Overlay %u", ovl->index);
1713 info->fix.smem_start = ovl->dma_handle;
1714 info->fix.smem_len = ovl->fb_size;
1715 info->fix.line_length = ovl->pitch;
1716
1717 if (ovl->format->yuv)
1718 info->fix.visual = FB_VISUAL_FOURCC;
1719 else
1720 info->fix.visual = FB_VISUAL_TRUECOLOR;
1721
15dede88
LP
1722 switch (ovl->format->fourcc) {
1723 case V4L2_PIX_FMT_NV16:
1724 case V4L2_PIX_FMT_NV61:
c5deac3c 1725 info->fix.ypanstep = 2;
15dede88
LP
1726 case V4L2_PIX_FMT_NV12:
1727 case V4L2_PIX_FMT_NV21:
1728 info->fix.xpanstep = 2;
1729 }
c5deac3c
LP
1730
1731 /* Initialize variable screen information. */
1732 var = &info->var;
1733 memset(var, 0, sizeof(*var));
1734 var->xres = ovl->xres;
1735 var->yres = ovl->yres;
1736 var->xres_virtual = ovl->xres_virtual;
1737 var->yres_virtual = ovl->yres_virtual;
1738 var->activate = FB_ACTIVATE_NOW;
1739
1740 /* Use the legacy API by default for RGB formats, and the FOURCC API
1741 * for YUV formats.
1742 */
1743 if (!ovl->format->yuv)
1744 var->bits_per_pixel = ovl->format->bpp;
1745 else
1746 var->grayscale = ovl->format->fourcc;
1747
1748 return sh_mobile_lcdc_overlay_check_var(var, info);
1749}
1750
f1f60b5f 1751/* -----------------------------------------------------------------------------
c5deac3c 1752 * Frame buffer operations - main frame buffer
f1f60b5f 1753 */
cfb4f5d1
MD
1754
1755static int sh_mobile_lcdc_setcolreg(u_int regno,
1756 u_int red, u_int green, u_int blue,
1757 u_int transp, struct fb_info *info)
1758{
1759 u32 *palette = info->pseudo_palette;
1760
1761 if (regno >= PALETTE_NR)
1762 return -EINVAL;
1763
1764 /* only FB_VISUAL_TRUECOLOR supported */
1765
1766 red >>= 16 - info->var.red.length;
1767 green >>= 16 - info->var.green.length;
1768 blue >>= 16 - info->var.blue.length;
1769 transp >>= 16 - info->var.transp.length;
1770
1771 palette[regno] = (red << info->var.red.offset) |
1772 (green << info->var.green.offset) |
1773 (blue << info->var.blue.offset) |
1774 (transp << info->var.transp.offset);
1775
1776 return 0;
1777}
1778
3281e54c 1779static const struct fb_fix_screeninfo sh_mobile_lcdc_fix = {
cfb4f5d1
MD
1780 .id = "SH Mobile LCDC",
1781 .type = FB_TYPE_PACKED_PIXELS,
1782 .visual = FB_VISUAL_TRUECOLOR,
1783 .accel = FB_ACCEL_NONE,
15dede88 1784 .xpanstep = 1,
9dd38819
PE
1785 .ypanstep = 1,
1786 .ywrapstep = 0,
edd153a3 1787 .capabilities = FB_CAP_FOURCC,
cfb4f5d1
MD
1788};
1789
8564557a
MD
1790static void sh_mobile_lcdc_fillrect(struct fb_info *info,
1791 const struct fb_fillrect *rect)
1792{
1793 sys_fillrect(info, rect);
1794 sh_mobile_lcdc_deferred_io_touch(info);
1795}
1796
1797static void sh_mobile_lcdc_copyarea(struct fb_info *info,
1798 const struct fb_copyarea *area)
1799{
1800 sys_copyarea(info, area);
1801 sh_mobile_lcdc_deferred_io_touch(info);
1802}
1803
1804static void sh_mobile_lcdc_imageblit(struct fb_info *info,
1805 const struct fb_image *image)
1806{
1807 sys_imageblit(info, image);
1808 sh_mobile_lcdc_deferred_io_touch(info);
1809}
1810
d7ad3342
LP
1811static int sh_mobile_lcdc_pan(struct fb_var_screeninfo *var,
1812 struct fb_info *info)
9dd38819
PE
1813{
1814 struct sh_mobile_lcdc_chan *ch = info->par;
92e1f9a7
PE
1815 struct sh_mobile_lcdc_priv *priv = ch->lcdc;
1816 unsigned long ldrcntr;
1817 unsigned long new_pan_offset;
6e729b41 1818 unsigned long base_addr_y, base_addr_c = 0;
53b50314 1819 unsigned long c_offset;
92e1f9a7 1820
58f03d99
LP
1821 if (!ch->format->yuv)
1822 new_pan_offset = var->yoffset * ch->pitch
1823 + var->xoffset * (ch->format->bpp / 8);
53b50314 1824 else
58f03d99 1825 new_pan_offset = var->yoffset * ch->pitch + var->xoffset;
9dd38819 1826
92e1f9a7 1827 if (new_pan_offset == ch->pan_offset)
9dd38819
PE
1828 return 0; /* No change, do nothing */
1829
92e1f9a7 1830 ldrcntr = lcdc_read(priv, _LDRCNTR);
9dd38819 1831
92e1f9a7 1832 /* Set the source address for the next refresh */
53b50314 1833 base_addr_y = ch->dma_handle + new_pan_offset;
58f03d99 1834 if (ch->format->yuv) {
53b50314 1835 /* Set y offset */
58f03d99
LP
1836 c_offset = var->yoffset * ch->pitch
1837 * (ch->format->bpp - 8) / 8;
1838 base_addr_c = ch->dma_handle + ch->xres * ch->yres_virtual
dc1d5ada 1839 + c_offset;
53b50314 1840 /* Set x offset */
fc9e78e6 1841 if (ch->format->fourcc == V4L2_PIX_FMT_NV24)
53b50314
DHG
1842 base_addr_c += 2 * var->xoffset;
1843 else
1844 base_addr_c += var->xoffset;
49d79ba2 1845 }
53b50314 1846
6e729b41
LP
1847 if (ch->cache)
1848 sh_mobile_meram_cache_update(priv->meram_dev, ch->cache,
1849 base_addr_y, base_addr_c,
1850 &base_addr_y, &base_addr_c);
7caa4342 1851
49d79ba2
LP
1852 ch->base_addr_y = base_addr_y;
1853 ch->base_addr_c = base_addr_c;
7caa4342 1854
49d79ba2 1855 lcdc_write_chan_mirror(ch, LDSA1R, base_addr_y);
58f03d99 1856 if (ch->format->yuv)
49d79ba2 1857 lcdc_write_chan_mirror(ch, LDSA2R, base_addr_c);
53b50314 1858
92e1f9a7
PE
1859 if (lcdc_chan_is_sublcd(ch))
1860 lcdc_write(ch->lcdc, _LDRCNTR, ldrcntr ^ LDRCNTR_SRS);
1861 else
1862 lcdc_write(ch->lcdc, _LDRCNTR, ldrcntr ^ LDRCNTR_MRS);
1863
1864 ch->pan_offset = new_pan_offset;
1865
1866 sh_mobile_lcdc_deferred_io_touch(info);
9dd38819
PE
1867
1868 return 0;
1869}
1870
d7ad3342
LP
1871static int sh_mobile_lcdc_ioctl(struct fb_info *info, unsigned int cmd,
1872 unsigned long arg)
40331b21 1873{
d7ad3342 1874 struct sh_mobile_lcdc_chan *ch = info->par;
40331b21
PE
1875 int retval;
1876
1877 switch (cmd) {
1878 case FBIO_WAITFORVSYNC:
d7ad3342 1879 retval = sh_mobile_lcdc_wait_for_vsync(ch);
40331b21
PE
1880 break;
1881
1882 default:
1883 retval = -ENOIOCTLCMD;
1884 break;
1885 }
1886 return retval;
1887}
1888
dd210503
GL
1889static void sh_mobile_fb_reconfig(struct fb_info *info)
1890{
1891 struct sh_mobile_lcdc_chan *ch = info->par;
2d04559d
LP
1892 struct fb_var_screeninfo var;
1893 struct fb_videomode mode;
dd210503
GL
1894 struct fb_event event;
1895 int evnt = FB_EVENT_MODE_CHANGE_ALL;
1896
1897 if (ch->use_count > 1 || (ch->use_count == 1 && !info->fbcon_par))
1898 /* More framebuffer users are active */
1899 return;
1900
2d04559d 1901 fb_var_to_videomode(&mode, &info->var);
dd210503 1902
2d04559d 1903 if (fb_mode_is_equal(&ch->display.mode, &mode))
dd210503
GL
1904 return;
1905
1906 /* Display has been re-plugged, framebuffer is free now, reconfigure */
2d04559d
LP
1907 var = info->var;
1908 fb_videomode_to_var(&var, &ch->display.mode);
1909 var.width = ch->display.width;
1910 var.height = ch->display.height;
1911 var.activate = FB_ACTIVATE_NOW;
1912
1913 if (fb_set_var(info, &var) < 0)
dd210503
GL
1914 /* Couldn't reconfigure, hopefully, can continue as before */
1915 return;
1916
dd210503
GL
1917 /*
1918 * fb_set_var() calls the notifier change internally, only if
1919 * FBINFO_MISC_USEREVENT flag is set. Since we do not want to fake a
1920 * user event, we have to call the chain ourselves.
1921 */
1922 event.info = info;
2d04559d 1923 event.data = &ch->display.mode;
dd210503
GL
1924 fb_notifier_call_chain(evnt, &event);
1925}
1926
1927/*
1928 * Locking: both .fb_release() and .fb_open() are called with info->lock held if
1929 * user == 1, or with console sem held, if user == 0.
1930 */
d7ad3342 1931static int sh_mobile_lcdc_release(struct fb_info *info, int user)
dd210503
GL
1932{
1933 struct sh_mobile_lcdc_chan *ch = info->par;
1934
1935 mutex_lock(&ch->open_lock);
1936 dev_dbg(info->dev, "%s(): %d users\n", __func__, ch->use_count);
1937
1938 ch->use_count--;
1939
1940 /* Nothing to reconfigure, when called from fbcon */
1941 if (user) {
ac751efa 1942 console_lock();
dd210503 1943 sh_mobile_fb_reconfig(info);
ac751efa 1944 console_unlock();
dd210503
GL
1945 }
1946
1947 mutex_unlock(&ch->open_lock);
1948
1949 return 0;
1950}
1951
d7ad3342 1952static int sh_mobile_lcdc_open(struct fb_info *info, int user)
dd210503
GL
1953{
1954 struct sh_mobile_lcdc_chan *ch = info->par;
1955
1956 mutex_lock(&ch->open_lock);
1957 ch->use_count++;
1958
1959 dev_dbg(info->dev, "%s(): %d users\n", __func__, ch->use_count);
1960 mutex_unlock(&ch->open_lock);
1961
1962 return 0;
1963}
1964
d7ad3342
LP
1965static int sh_mobile_lcdc_check_var(struct fb_var_screeninfo *var,
1966 struct fb_info *info)
dd210503
GL
1967{
1968 struct sh_mobile_lcdc_chan *ch = info->par;
417d4827 1969 struct sh_mobile_lcdc_priv *p = ch->lcdc;
03862194
LP
1970 unsigned int best_dist = (unsigned int)-1;
1971 unsigned int best_xres = 0;
1972 unsigned int best_yres = 0;
1973 unsigned int i;
c5deac3c 1974 int ret;
03862194
LP
1975
1976 /* If board code provides us with a list of available modes, make sure
1977 * we use one of them. Find the mode closest to the requested one. The
1978 * distance between two modes is defined as the size of the
1979 * non-overlapping parts of the two rectangles.
1980 */
b5ef967d
LP
1981 for (i = 0; i < ch->cfg->num_modes; ++i) {
1982 const struct fb_videomode *mode = &ch->cfg->lcd_modes[i];
03862194
LP
1983 unsigned int dist;
1984
1985 /* We can only round up. */
1986 if (var->xres > mode->xres || var->yres > mode->yres)
1987 continue;
1988
1989 dist = var->xres * var->yres + mode->xres * mode->yres
1990 - 2 * min(var->xres, mode->xres)
1991 * min(var->yres, mode->yres);
1992
1993 if (dist < best_dist) {
1994 best_xres = mode->xres;
1995 best_yres = mode->yres;
1996 best_dist = dist;
1997 }
dd210503 1998 }
417d4827 1999
03862194 2000 /* If no available mode can be used, return an error. */
b5ef967d 2001 if (ch->cfg->num_modes != 0) {
03862194
LP
2002 if (best_dist == (unsigned int)-1)
2003 return -EINVAL;
2004
2005 var->xres = best_xres;
2006 var->yres = best_yres;
2007 }
2008
c5deac3c
LP
2009 ret = __sh_mobile_lcdc_check_var(var, info);
2010 if (ret < 0)
2011 return ret;
03862194 2012
edd153a3
LP
2013 /* only accept the forced_fourcc for dual channel configurations */
2014 if (p->forced_fourcc &&
2015 p->forced_fourcc != sh_mobile_format_fourcc(var))
417d4827 2016 return -EINVAL;
417d4827 2017
dd210503
GL
2018 return 0;
2019}
40331b21 2020
d7ad3342 2021static int sh_mobile_lcdc_set_par(struct fb_info *info)
ed5bebf2
LP
2022{
2023 struct sh_mobile_lcdc_chan *ch = info->par;
2024 int ret;
2025
2026 sh_mobile_lcdc_stop(ch->lcdc);
91fba48d 2027
fc9e78e6 2028 ch->format = sh_mobile_format_info(sh_mobile_format_fourcc(&info->var));
58f03d99
LP
2029 ch->colorspace = info->var.colorspace;
2030
2031 ch->xres = info->var.xres;
2032 ch->xres_virtual = info->var.xres_virtual;
2033 ch->yres = info->var.yres;
2034 ch->yres_virtual = info->var.yres_virtual;
2035
2036 if (ch->format->yuv)
16ca21c9 2037 ch->pitch = info->var.xres_virtual;
58f03d99 2038 else
16ca21c9 2039 ch->pitch = info->var.xres_virtual * ch->format->bpp / 8;
fc9e78e6 2040
ed5bebf2 2041 ret = sh_mobile_lcdc_start(ch->lcdc);
58f03d99 2042 if (ret < 0)
ed5bebf2 2043 dev_err(info->dev, "%s: unable to restart LCDC\n", __func__);
58f03d99
LP
2044
2045 info->fix.line_length = ch->pitch;
ed5bebf2 2046
edd153a3
LP
2047 if (sh_mobile_format_is_fourcc(&info->var)) {
2048 info->fix.type = FB_TYPE_FOURCC;
2049 info->fix.visual = FB_VISUAL_FOURCC;
2050 } else {
2051 info->fix.type = FB_TYPE_PACKED_PIXELS;
2052 info->fix.visual = FB_VISUAL_TRUECOLOR;
2053 }
2054
ed5bebf2
LP
2055 return ret;
2056}
2057
8857b9aa
AC
2058/*
2059 * Screen blanking. Behavior is as follows:
2060 * FB_BLANK_UNBLANK: screen unblanked, clocks enabled
2061 * FB_BLANK_NORMAL: screen blanked, clocks enabled
2062 * FB_BLANK_VSYNC,
2063 * FB_BLANK_HSYNC,
2064 * FB_BLANK_POWEROFF: screen blanked, clocks disabled
2065 */
2066static int sh_mobile_lcdc_blank(int blank, struct fb_info *info)
2067{
2068 struct sh_mobile_lcdc_chan *ch = info->par;
2069 struct sh_mobile_lcdc_priv *p = ch->lcdc;
2070
2071 /* blank the screen? */
2072 if (blank > FB_BLANK_UNBLANK && ch->blank_status == FB_BLANK_UNBLANK) {
2073 struct fb_fillrect rect = {
58f03d99
LP
2074 .width = ch->xres,
2075 .height = ch->yres,
8857b9aa
AC
2076 };
2077 sh_mobile_lcdc_fillrect(info, &rect);
2078 }
2079 /* turn clocks on? */
2080 if (blank <= FB_BLANK_NORMAL && ch->blank_status > FB_BLANK_NORMAL) {
2081 sh_mobile_lcdc_clk_on(p);
2082 }
2083 /* turn clocks off? */
2084 if (blank > FB_BLANK_NORMAL && ch->blank_status <= FB_BLANK_NORMAL) {
2085 /* make sure the screen is updated with the black fill before
2086 * switching the clocks off. one vsync is not enough since
2087 * blanking may occur in the middle of a refresh. deferred io
2088 * mode will reenable the clocks and update the screen in time,
2089 * so it does not need this. */
2090 if (!info->fbdefio) {
d7ad3342
LP
2091 sh_mobile_lcdc_wait_for_vsync(ch);
2092 sh_mobile_lcdc_wait_for_vsync(ch);
8857b9aa
AC
2093 }
2094 sh_mobile_lcdc_clk_off(p);
2095 }
2096
2097 ch->blank_status = blank;
2098 return 0;
2099}
2100
cfb4f5d1 2101static struct fb_ops sh_mobile_lcdc_ops = {
9dd38819 2102 .owner = THIS_MODULE,
cfb4f5d1 2103 .fb_setcolreg = sh_mobile_lcdc_setcolreg,
2540c111
MD
2104 .fb_read = fb_sys_read,
2105 .fb_write = fb_sys_write,
8564557a
MD
2106 .fb_fillrect = sh_mobile_lcdc_fillrect,
2107 .fb_copyarea = sh_mobile_lcdc_copyarea,
2108 .fb_imageblit = sh_mobile_lcdc_imageblit,
8857b9aa 2109 .fb_blank = sh_mobile_lcdc_blank,
d7ad3342
LP
2110 .fb_pan_display = sh_mobile_lcdc_pan,
2111 .fb_ioctl = sh_mobile_lcdc_ioctl,
2112 .fb_open = sh_mobile_lcdc_open,
2113 .fb_release = sh_mobile_lcdc_release,
2114 .fb_check_var = sh_mobile_lcdc_check_var,
2115 .fb_set_par = sh_mobile_lcdc_set_par,
cfb4f5d1
MD
2116};
2117
a67f379d
LP
2118static void
2119sh_mobile_lcdc_channel_fb_unregister(struct sh_mobile_lcdc_chan *ch)
2120{
2121 if (ch->info && ch->info->dev)
2122 unregister_framebuffer(ch->info);
2123}
2124
2125static int __devinit
2126sh_mobile_lcdc_channel_fb_register(struct sh_mobile_lcdc_chan *ch)
2127{
2128 struct fb_info *info = ch->info;
2129 int ret;
2130
2131 if (info->fbdefio) {
2132 ch->sglist = vmalloc(sizeof(struct scatterlist) *
2133 ch->fb_size >> PAGE_SHIFT);
2134 if (!ch->sglist) {
2135 dev_err(ch->lcdc->dev, "cannot allocate sglist\n");
2136 return -ENOMEM;
2137 }
2138 }
2139
2140 info->bl_dev = ch->bl;
2141
2142 ret = register_framebuffer(info);
2143 if (ret < 0)
2144 return ret;
2145
2146 dev_info(ch->lcdc->dev, "registered %s/%s as %dx%d %dbpp.\n",
b5ef967d 2147 dev_name(ch->lcdc->dev), (ch->cfg->chan == LCDC_CHAN_MAINLCD) ?
a67f379d
LP
2148 "mainlcd" : "sublcd", info->var.xres, info->var.yres,
2149 info->var.bits_per_pixel);
2150
2151 /* deferred io mode: disable clock to save power */
2152 if (info->fbdefio || info->state == FBINFO_STATE_SUSPENDED)
2153 sh_mobile_lcdc_clk_off(ch->lcdc);
2154
2155 return ret;
2156}
2157
2158static void
2159sh_mobile_lcdc_channel_fb_cleanup(struct sh_mobile_lcdc_chan *ch)
2160{
2161 struct fb_info *info = ch->info;
2162
2163 if (!info || !info->device)
2164 return;
2165
2166 if (ch->sglist)
2167 vfree(ch->sglist);
2168
2169 fb_dealloc_cmap(&info->cmap);
2170 framebuffer_release(info);
2171}
2172
2173static int __devinit
2174sh_mobile_lcdc_channel_fb_init(struct sh_mobile_lcdc_chan *ch,
2175 const struct fb_videomode *mode,
2176 unsigned int num_modes)
2177{
2178 struct sh_mobile_lcdc_priv *priv = ch->lcdc;
2179 struct fb_var_screeninfo *var;
2180 struct fb_info *info;
2181 int ret;
2182
2183 /* Allocate and initialize the frame buffer device. Create the modes
2184 * list and allocate the color map.
2185 */
2186 info = framebuffer_alloc(0, priv->dev);
2187 if (info == NULL) {
2188 dev_err(priv->dev, "unable to allocate fb_info\n");
2189 return -ENOMEM;
2190 }
2191
2192 ch->info = info;
2193
2194 info->flags = FBINFO_FLAG_DEFAULT;
2195 info->fbops = &sh_mobile_lcdc_ops;
2196 info->device = priv->dev;
2197 info->screen_base = ch->fb_mem;
2198 info->pseudo_palette = &ch->pseudo_palette;
2199 info->par = ch;
2200
2201 fb_videomode_to_modelist(mode, num_modes, &info->modelist);
2202
2203 ret = fb_alloc_cmap(&info->cmap, PALETTE_NR, 0);
2204 if (ret < 0) {
2205 dev_err(priv->dev, "unable to allocate cmap\n");
2206 return ret;
2207 }
2208
2209 /* Initialize fixed screen information. Restrict pan to 2 lines steps
2210 * for NV12 and NV21.
2211 */
2212 info->fix = sh_mobile_lcdc_fix;
2213 info->fix.smem_start = ch->dma_handle;
2214 info->fix.smem_len = ch->fb_size;
58f03d99
LP
2215 info->fix.line_length = ch->pitch;
2216
2217 if (ch->format->yuv)
2218 info->fix.visual = FB_VISUAL_FOURCC;
2219 else
2220 info->fix.visual = FB_VISUAL_TRUECOLOR;
2221
15dede88
LP
2222 switch (ch->format->fourcc) {
2223 case V4L2_PIX_FMT_NV16:
2224 case V4L2_PIX_FMT_NV61:
a67f379d 2225 info->fix.ypanstep = 2;
15dede88
LP
2226 case V4L2_PIX_FMT_NV12:
2227 case V4L2_PIX_FMT_NV21:
2228 info->fix.xpanstep = 2;
2229 }
a67f379d
LP
2230
2231 /* Initialize variable screen information using the first mode as
bd5f2c69 2232 * default.
a67f379d
LP
2233 */
2234 var = &info->var;
2235 fb_videomode_to_var(var, mode);
b5ef967d
LP
2236 var->width = ch->cfg->panel_cfg.width;
2237 var->height = ch->cfg->panel_cfg.height;
bd5f2c69
LP
2238 var->xres_virtual = ch->xres_virtual;
2239 var->yres_virtual = ch->yres_virtual;
a67f379d
LP
2240 var->activate = FB_ACTIVATE_NOW;
2241
2242 /* Use the legacy API by default for RGB formats, and the FOURCC API
2243 * for YUV formats.
2244 */
2245 if (!ch->format->yuv)
2246 var->bits_per_pixel = ch->format->bpp;
2247 else
2248 var->grayscale = ch->format->fourcc;
2249
d7ad3342 2250 ret = sh_mobile_lcdc_check_var(var, info);
a67f379d
LP
2251 if (ret)
2252 return ret;
2253
a67f379d
LP
2254 return 0;
2255}
2256
f1f60b5f
LP
2257/* -----------------------------------------------------------------------------
2258 * Backlight
2259 */
2260
3b0fd9d7
AC
2261static int sh_mobile_lcdc_update_bl(struct backlight_device *bdev)
2262{
2263 struct sh_mobile_lcdc_chan *ch = bl_get_data(bdev);
3b0fd9d7
AC
2264 int brightness = bdev->props.brightness;
2265
2266 if (bdev->props.power != FB_BLANK_UNBLANK ||
2267 bdev->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK))
2268 brightness = 0;
2269
b5ef967d 2270 return ch->cfg->bl_info.set_brightness(brightness);
3b0fd9d7
AC
2271}
2272
2273static int sh_mobile_lcdc_get_brightness(struct backlight_device *bdev)
2274{
2275 struct sh_mobile_lcdc_chan *ch = bl_get_data(bdev);
3b0fd9d7 2276
b5ef967d 2277 return ch->cfg->bl_info.get_brightness();
3b0fd9d7
AC
2278}
2279
2280static int sh_mobile_lcdc_check_fb(struct backlight_device *bdev,
2281 struct fb_info *info)
2282{
2283 return (info->bl_dev == bdev);
2284}
2285
2286static struct backlight_ops sh_mobile_lcdc_bl_ops = {
2287 .options = BL_CORE_SUSPENDRESUME,
2288 .update_status = sh_mobile_lcdc_update_bl,
2289 .get_brightness = sh_mobile_lcdc_get_brightness,
2290 .check_fb = sh_mobile_lcdc_check_fb,
2291};
2292
2293static struct backlight_device *sh_mobile_lcdc_bl_probe(struct device *parent,
2294 struct sh_mobile_lcdc_chan *ch)
2295{
2296 struct backlight_device *bl;
2297
b5ef967d 2298 bl = backlight_device_register(ch->cfg->bl_info.name, parent, ch,
3b0fd9d7 2299 &sh_mobile_lcdc_bl_ops, NULL);
beee1f20
DC
2300 if (IS_ERR(bl)) {
2301 dev_err(parent, "unable to register backlight device: %ld\n",
2302 PTR_ERR(bl));
3b0fd9d7
AC
2303 return NULL;
2304 }
2305
b5ef967d 2306 bl->props.max_brightness = ch->cfg->bl_info.max_brightness;
3b0fd9d7
AC
2307 bl->props.brightness = bl->props.max_brightness;
2308 backlight_update_status(bl);
2309
2310 return bl;
2311}
2312
2313static void sh_mobile_lcdc_bl_remove(struct backlight_device *bdev)
2314{
2315 backlight_device_unregister(bdev);
2316}
2317
f1f60b5f
LP
2318/* -----------------------------------------------------------------------------
2319 * Power management
2320 */
2321
2feb075a
MD
2322static int sh_mobile_lcdc_suspend(struct device *dev)
2323{
2324 struct platform_device *pdev = to_platform_device(dev);
2325
2326 sh_mobile_lcdc_stop(platform_get_drvdata(pdev));
2327 return 0;
2328}
2329
2330static int sh_mobile_lcdc_resume(struct device *dev)
2331{
2332 struct platform_device *pdev = to_platform_device(dev);
2333
2334 return sh_mobile_lcdc_start(platform_get_drvdata(pdev));
2335}
2336
0246c471
MD
2337static int sh_mobile_lcdc_runtime_suspend(struct device *dev)
2338{
2339 struct platform_device *pdev = to_platform_device(dev);
2427bb24 2340 struct sh_mobile_lcdc_priv *priv = platform_get_drvdata(pdev);
0246c471
MD
2341
2342 /* turn off LCDC hardware */
2427bb24
LP
2343 lcdc_write(priv, _LDCNT1R, 0);
2344
0246c471
MD
2345 return 0;
2346}
2347
2348static int sh_mobile_lcdc_runtime_resume(struct device *dev)
2349{
2350 struct platform_device *pdev = to_platform_device(dev);
2427bb24 2351 struct sh_mobile_lcdc_priv *priv = platform_get_drvdata(pdev);
0246c471 2352
2427bb24 2353 __sh_mobile_lcdc_start(priv);
0246c471
MD
2354
2355 return 0;
2356}
2357
47145210 2358static const struct dev_pm_ops sh_mobile_lcdc_dev_pm_ops = {
2feb075a
MD
2359 .suspend = sh_mobile_lcdc_suspend,
2360 .resume = sh_mobile_lcdc_resume,
0246c471
MD
2361 .runtime_suspend = sh_mobile_lcdc_runtime_suspend,
2362 .runtime_resume = sh_mobile_lcdc_runtime_resume,
2feb075a
MD
2363};
2364
f1f60b5f
LP
2365/* -----------------------------------------------------------------------------
2366 * Framebuffer notifier
2367 */
2368
6de9edd5 2369/* locking: called with info->lock held */
6011bdea
GL
2370static int sh_mobile_lcdc_notify(struct notifier_block *nb,
2371 unsigned long action, void *data)
2372{
2373 struct fb_event *event = data;
2374 struct fb_info *info = event->info;
2375 struct sh_mobile_lcdc_chan *ch = info->par;
6011bdea
GL
2376
2377 if (&ch->lcdc->notifier != nb)
baf16374 2378 return NOTIFY_DONE;
6011bdea
GL
2379
2380 dev_dbg(info->dev, "%s(): action = %lu, data = %p\n",
2381 __func__, action, event->data);
2382
2383 switch(action) {
2384 case FB_EVENT_SUSPEND:
37c5dcc2 2385 sh_mobile_lcdc_display_off(ch);
afe417c0 2386 sh_mobile_lcdc_stop(ch->lcdc);
6011bdea
GL
2387 break;
2388 case FB_EVENT_RESUME:
dd210503
GL
2389 mutex_lock(&ch->open_lock);
2390 sh_mobile_fb_reconfig(info);
2391 mutex_unlock(&ch->open_lock);
6011bdea 2392
37c5dcc2 2393 sh_mobile_lcdc_display_on(ch);
ebe5e12d 2394 sh_mobile_lcdc_start(ch->lcdc);
6011bdea
GL
2395 }
2396
baf16374 2397 return NOTIFY_OK;
6011bdea
GL
2398}
2399
f1f60b5f
LP
2400/* -----------------------------------------------------------------------------
2401 * Probe/remove and driver init/exit
2402 */
2403
217e9c43 2404static const struct fb_videomode default_720p __devinitconst = {
f1f60b5f
LP
2405 .name = "HDMI 720p",
2406 .xres = 1280,
2407 .yres = 720,
2408
2409 .left_margin = 220,
2410 .right_margin = 110,
2411 .hsync_len = 40,
2412
2413 .upper_margin = 20,
2414 .lower_margin = 5,
2415 .vsync_len = 5,
2416
2417 .pixclock = 13468,
2418 .refresh = 60,
2419 .sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT,
2420};
2421
b4bee692
LP
2422static int sh_mobile_lcdc_remove(struct platform_device *pdev)
2423{
2424 struct sh_mobile_lcdc_priv *priv = platform_get_drvdata(pdev);
c5deac3c 2425 unsigned int i;
b4bee692
LP
2426
2427 fb_unregister_client(&priv->notifier);
2428
c5deac3c
LP
2429 for (i = 0; i < ARRAY_SIZE(priv->overlays); i++)
2430 sh_mobile_lcdc_overlay_fb_unregister(&priv->overlays[i]);
b4bee692 2431 for (i = 0; i < ARRAY_SIZE(priv->ch); i++)
a67f379d 2432 sh_mobile_lcdc_channel_fb_unregister(&priv->ch[i]);
b4bee692
LP
2433
2434 sh_mobile_lcdc_stop(priv);
2435
c5deac3c
LP
2436 for (i = 0; i < ARRAY_SIZE(priv->overlays); i++) {
2437 struct sh_mobile_lcdc_overlay *ovl = &priv->overlays[i];
2438
2439 sh_mobile_lcdc_overlay_fb_cleanup(ovl);
2440
2441 if (ovl->fb_mem)
2442 dma_free_coherent(&pdev->dev, ovl->fb_size,
2443 ovl->fb_mem, ovl->dma_handle);
2444 }
2445
b4bee692 2446 for (i = 0; i < ARRAY_SIZE(priv->ch); i++) {
9a2985e7 2447 struct sh_mobile_lcdc_chan *ch = &priv->ch[i];
b4bee692 2448
e34d0bbb
LP
2449 if (ch->tx_dev) {
2450 ch->tx_dev->lcdc = NULL;
b5ef967d 2451 module_put(ch->cfg->tx_dev->dev.driver->owner);
e34d0bbb 2452 }
9a2985e7 2453
a67f379d 2454 sh_mobile_lcdc_channel_fb_cleanup(ch);
b4bee692 2455
a67f379d
LP
2456 if (ch->fb_mem)
2457 dma_free_coherent(&pdev->dev, ch->fb_size,
2458 ch->fb_mem, ch->dma_handle);
b4bee692
LP
2459 }
2460
2461 for (i = 0; i < ARRAY_SIZE(priv->ch); i++) {
0c75c4e0
LP
2462 struct sh_mobile_lcdc_chan *ch = &priv->ch[i];
2463
2464 if (ch->bl)
2465 sh_mobile_lcdc_bl_remove(ch->bl);
2466 mutex_destroy(&ch->open_lock);
b4bee692
LP
2467 }
2468
4774c12a
LP
2469 if (priv->dot_clk) {
2470 pm_runtime_disable(&pdev->dev);
b4bee692 2471 clk_put(priv->dot_clk);
4774c12a 2472 }
b4bee692
LP
2473
2474 if (priv->base)
2475 iounmap(priv->base);
2476
2477 if (priv->irq)
2478 free_irq(priv->irq, priv);
2479 kfree(priv);
2480 return 0;
2481}
cfb4f5d1 2482
217e9c43 2483static int __devinit sh_mobile_lcdc_check_interface(struct sh_mobile_lcdc_chan *ch)
f1f60b5f 2484{
b5ef967d 2485 int interface_type = ch->cfg->interface_type;
f1f60b5f
LP
2486
2487 switch (interface_type) {
2488 case RGB8:
2489 case RGB9:
2490 case RGB12A:
2491 case RGB12B:
2492 case RGB16:
2493 case RGB18:
2494 case RGB24:
2495 case SYS8A:
2496 case SYS8B:
2497 case SYS8C:
2498 case SYS8D:
2499 case SYS9:
2500 case SYS12:
2501 case SYS16A:
2502 case SYS16B:
2503 case SYS16C:
2504 case SYS18:
2505 case SYS24:
2506 break;
2507 default:
2508 return -EINVAL;
2509 }
2510
2511 /* SUBLCD only supports SYS interface */
2512 if (lcdc_chan_is_sublcd(ch)) {
2513 if (!(interface_type & LDMT1R_IFM))
2514 return -EINVAL;
2515
2516 interface_type &= ~LDMT1R_IFM;
2517 }
2518
2519 ch->ldmt1r_value = interface_type;
2520 return 0;
2521}
2522
c5deac3c
LP
2523static int __devinit
2524sh_mobile_lcdc_overlay_init(struct sh_mobile_lcdc_priv *priv,
2525 struct sh_mobile_lcdc_overlay *ovl)
2526{
2527 const struct sh_mobile_lcdc_format_info *format;
2528 int ret;
2529
2530 if (ovl->cfg->fourcc == 0)
2531 return 0;
2532
2533 /* Validate the format. */
2534 format = sh_mobile_format_info(ovl->cfg->fourcc);
2535 if (format == NULL) {
2536 dev_err(priv->dev, "Invalid FOURCC %08x\n", ovl->cfg->fourcc);
2537 return -EINVAL;
2538 }
2539
2540 ovl->enabled = false;
2541 ovl->mode = LCDC_OVERLAY_BLEND;
2542 ovl->alpha = 255;
2543 ovl->rop3 = 0;
2544 ovl->pos_x = 0;
2545 ovl->pos_y = 0;
2546
2547 /* The default Y virtual resolution is twice the panel size to allow for
2548 * double-buffering.
2549 */
2550 ovl->format = format;
2551 ovl->xres = ovl->cfg->max_xres;
2552 ovl->xres_virtual = ovl->xres;
2553 ovl->yres = ovl->cfg->max_yres;
2554 ovl->yres_virtual = ovl->yres * 2;
2555
2556 if (!format->yuv)
16ca21c9 2557 ovl->pitch = ovl->xres_virtual * format->bpp / 8;
c5deac3c 2558 else
16ca21c9 2559 ovl->pitch = ovl->xres_virtual;
c5deac3c
LP
2560
2561 /* Allocate frame buffer memory. */
2562 ovl->fb_size = ovl->cfg->max_xres * ovl->cfg->max_yres
2563 * format->bpp / 8 * 2;
2564 ovl->fb_mem = dma_alloc_coherent(priv->dev, ovl->fb_size,
2565 &ovl->dma_handle, GFP_KERNEL);
2566 if (!ovl->fb_mem) {
2567 dev_err(priv->dev, "unable to allocate buffer\n");
2568 return -ENOMEM;
2569 }
2570
2571 ret = sh_mobile_lcdc_overlay_fb_init(ovl);
2572 if (ret < 0)
2573 return ret;
2574
2575 return 0;
2576}
2577
0a7f17aa
LP
2578static int __devinit
2579sh_mobile_lcdc_channel_init(struct sh_mobile_lcdc_priv *priv,
2580 struct sh_mobile_lcdc_chan *ch)
cfb4f5d1 2581{
105784bb 2582 const struct sh_mobile_lcdc_format_info *format;
b5ef967d 2583 const struct sh_mobile_lcdc_chan_cfg *cfg = ch->cfg;
3ce05599
LP
2584 const struct fb_videomode *max_mode;
2585 const struct fb_videomode *mode;
a67f379d 2586 unsigned int num_modes;
3ce05599 2587 unsigned int max_size;
a67f379d 2588 unsigned int i;
3ce05599 2589
a67472ad 2590 mutex_init(&ch->open_lock);
ecd29947 2591 ch->notify = sh_mobile_lcdc_display_notify;
a67472ad 2592
105784bb
LP
2593 /* Validate the format. */
2594 format = sh_mobile_format_info(cfg->fourcc);
2595 if (format == NULL) {
2596 dev_err(priv->dev, "Invalid FOURCC %08x.\n", cfg->fourcc);
2597 return -EINVAL;
2598 }
2599
3ce05599
LP
2600 /* Iterate through the modes to validate them and find the highest
2601 * resolution.
2602 */
2603 max_mode = NULL;
2604 max_size = 0;
2605
93ff2598 2606 for (i = 0, mode = cfg->lcd_modes; i < cfg->num_modes; i++, mode++) {
3ce05599
LP
2607 unsigned int size = mode->yres * mode->xres;
2608
edd153a3
LP
2609 /* NV12/NV21 buffers must have even number of lines */
2610 if ((cfg->fourcc == V4L2_PIX_FMT_NV12 ||
2611 cfg->fourcc == V4L2_PIX_FMT_NV21) && (mode->yres & 0x1)) {
0a7f17aa
LP
2612 dev_err(priv->dev, "yres must be multiple of 2 for "
2613 "YCbCr420 mode.\n");
3ce05599
LP
2614 return -EINVAL;
2615 }
2616
2617 if (size > max_size) {
2618 max_mode = mode;
2619 max_size = size;
2620 }
2621 }
2622
2623 if (!max_size)
2624 max_size = MAX_XRES * MAX_YRES;
2625 else
0a7f17aa 2626 dev_dbg(priv->dev, "Found largest videomode %ux%u\n",
3ce05599
LP
2627 max_mode->xres, max_mode->yres);
2628
93ff2598 2629 if (cfg->lcd_modes == NULL) {
3ce05599 2630 mode = &default_720p;
93ff2598 2631 num_modes = 1;
3ce05599 2632 } else {
93ff2598
LP
2633 mode = cfg->lcd_modes;
2634 num_modes = cfg->num_modes;
3ce05599
LP
2635 }
2636
bd5f2c69
LP
2637 /* Use the first mode as default. The default Y virtual resolution is
2638 * twice the panel size to allow for double-buffering.
2639 */
58f03d99
LP
2640 ch->format = format;
2641 ch->xres = mode->xres;
2642 ch->xres_virtual = mode->xres;
2643 ch->yres = mode->yres;
2644 ch->yres_virtual = mode->yres * 2;
2645
2646 if (!format->yuv) {
2647 ch->colorspace = V4L2_COLORSPACE_SRGB;
16ca21c9 2648 ch->pitch = ch->xres_virtual * format->bpp / 8;
58f03d99
LP
2649 } else {
2650 ch->colorspace = V4L2_COLORSPACE_REC709;
16ca21c9 2651 ch->pitch = ch->xres_virtual;
58f03d99
LP
2652 }
2653
a67f379d
LP
2654 ch->display.width = cfg->panel_cfg.width;
2655 ch->display.height = cfg->panel_cfg.height;
2656 ch->display.mode = *mode;
2657
2658 /* Allocate frame buffer memory. */
2659 ch->fb_size = max_size * format->bpp / 8 * 2;
2660 ch->fb_mem = dma_alloc_coherent(priv->dev, ch->fb_size, &ch->dma_handle,
2661 GFP_KERNEL);
2662 if (ch->fb_mem == NULL) {
2663 dev_err(priv->dev, "unable to allocate buffer\n");
2664 return -ENOMEM;
2665 }
3ce05599 2666
13f80eea
LP
2667 /* Initialize the transmitter device if present. */
2668 if (cfg->tx_dev) {
2669 if (!cfg->tx_dev->dev.driver ||
2670 !try_module_get(cfg->tx_dev->dev.driver->owner)) {
2671 dev_warn(priv->dev,
2672 "unable to get transmitter device\n");
2673 return -EINVAL;
2674 }
2675 ch->tx_dev = platform_get_drvdata(cfg->tx_dev);
2676 ch->tx_dev->lcdc = ch;
2677 ch->tx_dev->def_mode = *mode;
2678 }
2679
a67f379d 2680 return sh_mobile_lcdc_channel_fb_init(ch, mode, num_modes);
3ce05599
LP
2681}
2682
2683static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
2684{
01ac25b5 2685 struct sh_mobile_lcdc_info *pdata = pdev->dev.platform_data;
3ce05599 2686 struct sh_mobile_lcdc_priv *priv;
cfb4f5d1 2687 struct resource *res;
3ce05599 2688 int num_channels;
cfb4f5d1 2689 int error;
3ce05599 2690 int i;
cfb4f5d1 2691
01ac25b5 2692 if (!pdata) {
cfb4f5d1 2693 dev_err(&pdev->dev, "no platform data defined\n");
8bed9055 2694 return -EINVAL;
cfb4f5d1
MD
2695 }
2696
2697 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
8564557a
MD
2698 i = platform_get_irq(pdev, 0);
2699 if (!res || i < 0) {
2700 dev_err(&pdev->dev, "cannot get platform resources\n");
8bed9055 2701 return -ENOENT;
cfb4f5d1
MD
2702 }
2703
2704 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
2705 if (!priv) {
2706 dev_err(&pdev->dev, "cannot allocate device data\n");
8bed9055 2707 return -ENOMEM;
cfb4f5d1
MD
2708 }
2709
4774c12a
LP
2710 priv->dev = &pdev->dev;
2711 priv->meram_dev = pdata->meram_dev;
8bed9055
GL
2712 platform_set_drvdata(pdev, priv);
2713
f8798ccb 2714 error = request_irq(i, sh_mobile_lcdc_irq, 0,
7ad33e74 2715 dev_name(&pdev->dev), priv);
8564557a
MD
2716 if (error) {
2717 dev_err(&pdev->dev, "unable to request irq\n");
2718 goto err1;
2719 }
2720
2721 priv->irq = i;
5ef6b505 2722 atomic_set(&priv->hw_usecnt, -1);
cfb4f5d1 2723
3ce05599
LP
2724 for (i = 0, num_channels = 0; i < ARRAY_SIZE(pdata->ch); i++) {
2725 struct sh_mobile_lcdc_chan *ch = priv->ch + num_channels;
cfb4f5d1 2726
01ac25b5 2727 ch->lcdc = priv;
b5ef967d 2728 ch->cfg = &pdata->ch[i];
cfb4f5d1 2729
01ac25b5 2730 error = sh_mobile_lcdc_check_interface(ch);
cfb4f5d1
MD
2731 if (error) {
2732 dev_err(&pdev->dev, "unsupported interface type\n");
2733 goto err1;
2734 }
01ac25b5
GL
2735 init_waitqueue_head(&ch->frame_end_wait);
2736 init_completion(&ch->vsync_completion);
2737 ch->pan_offset = 0;
cfb4f5d1 2738
3b0fd9d7 2739 /* probe the backlight is there is one defined */
b5ef967d 2740 if (ch->cfg->bl_info.max_brightness)
3b0fd9d7
AC
2741 ch->bl = sh_mobile_lcdc_bl_probe(&pdev->dev, ch);
2742
cfb4f5d1
MD
2743 switch (pdata->ch[i].chan) {
2744 case LCDC_CHAN_MAINLCD:
ce1c0b08 2745 ch->enabled = LDCNT2R_ME;
01ac25b5 2746 ch->reg_offs = lcdc_offs_mainlcd;
3ce05599 2747 num_channels++;
cfb4f5d1
MD
2748 break;
2749 case LCDC_CHAN_SUBLCD:
ce1c0b08 2750 ch->enabled = LDCNT2R_SE;
01ac25b5 2751 ch->reg_offs = lcdc_offs_sublcd;
3ce05599 2752 num_channels++;
cfb4f5d1
MD
2753 break;
2754 }
2755 }
2756
3ce05599 2757 if (!num_channels) {
cfb4f5d1
MD
2758 dev_err(&pdev->dev, "no channels defined\n");
2759 error = -EINVAL;
2760 goto err1;
2761 }
2762
edd153a3 2763 /* for dual channel LCDC (MAIN + SUB) force shared format setting */
3ce05599 2764 if (num_channels == 2)
edd153a3 2765 priv->forced_fourcc = pdata->ch[0].fourcc;
417d4827 2766
dba6f385
GL
2767 priv->base = ioremap_nocache(res->start, resource_size(res));
2768 if (!priv->base)
2769 goto err1;
2770
0a7f17aa 2771 error = sh_mobile_lcdc_setup_clocks(priv, pdata->clock_source);
cfb4f5d1
MD
2772 if (error) {
2773 dev_err(&pdev->dev, "unable to setup clocks\n");
2774 goto err1;
2775 }
2776
4774c12a
LP
2777 /* Enable runtime PM. */
2778 pm_runtime_enable(&pdev->dev);
7caa4342 2779
3ce05599 2780 for (i = 0; i < num_channels; i++) {
01ac25b5 2781 struct sh_mobile_lcdc_chan *ch = priv->ch + i;
c44f9f76 2782
0a7f17aa 2783 error = sh_mobile_lcdc_channel_init(priv, ch);
cfb4f5d1 2784 if (error)
3ce05599 2785 goto err1;
cfb4f5d1
MD
2786 }
2787
c5deac3c
LP
2788 for (i = 0; i < ARRAY_SIZE(pdata->overlays); i++) {
2789 struct sh_mobile_lcdc_overlay *ovl = &priv->overlays[i];
2790
2791 ovl->cfg = &pdata->overlays[i];
2792 ovl->channel = &priv->ch[0];
2793
2794 error = sh_mobile_lcdc_overlay_init(priv, ovl);
2795 if (error)
2796 goto err1;
2797 }
2798
cfb4f5d1
MD
2799 error = sh_mobile_lcdc_start(priv);
2800 if (error) {
2801 dev_err(&pdev->dev, "unable to start hardware\n");
2802 goto err1;
2803 }
2804
3ce05599 2805 for (i = 0; i < num_channels; i++) {
1c6a307a 2806 struct sh_mobile_lcdc_chan *ch = priv->ch + i;
1c6a307a 2807
a67f379d
LP
2808 error = sh_mobile_lcdc_channel_fb_register(ch);
2809 if (error)
cfb4f5d1 2810 goto err1;
cfb4f5d1
MD
2811 }
2812
c5deac3c
LP
2813 for (i = 0; i < ARRAY_SIZE(pdata->overlays); i++) {
2814 struct sh_mobile_lcdc_overlay *ovl = &priv->overlays[i];
2815
2816 error = sh_mobile_lcdc_overlay_fb_register(ovl);
2817 if (error)
2818 goto err1;
2819 }
2820
6011bdea
GL
2821 /* Failure ignored */
2822 priv->notifier.notifier_call = sh_mobile_lcdc_notify;
2823 fb_register_client(&priv->notifier);
2824
cfb4f5d1 2825 return 0;
8bed9055 2826err1:
cfb4f5d1 2827 sh_mobile_lcdc_remove(pdev);
8bed9055 2828
cfb4f5d1
MD
2829 return error;
2830}
2831
cfb4f5d1
MD
2832static struct platform_driver sh_mobile_lcdc_driver = {
2833 .driver = {
2834 .name = "sh_mobile_lcdc_fb",
2835 .owner = THIS_MODULE,
2feb075a 2836 .pm = &sh_mobile_lcdc_dev_pm_ops,
cfb4f5d1
MD
2837 },
2838 .probe = sh_mobile_lcdc_probe,
2839 .remove = sh_mobile_lcdc_remove,
2840};
2841
4277f2c4 2842module_platform_driver(sh_mobile_lcdc_driver);
cfb4f5d1
MD
2843
2844MODULE_DESCRIPTION("SuperH Mobile LCDC Framebuffer driver");
2845MODULE_AUTHOR("Magnus Damm <damm@opensource.se>");
2846MODULE_LICENSE("GPL v2");