blob: 99656f593de480140c27ca3ac01a45210dc8b9f5 [file] [log] [blame]
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001/*
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 Dammcfb4f5d2008-07-23 21:31:24 -070015#include <linux/clk.h>
Magnus Damm0246c472009-08-14 10:49:08 +000016#include <linux/pm_runtime.h>
Magnus Dammcfb4f5d2008-07-23 21:31:24 -070017#include <linux/platform_device.h>
18#include <linux/dma-mapping.h>
Magnus Damm85645572008-12-19 15:34:41 +090019#include <linux/interrupt.h>
Paul Mundt1c6a3072009-07-01 06:50:31 +000020#include <linux/vmalloc.h>
Phil Edworthy40331b22010-02-15 13:57:49 +000021#include <linux/ioctl.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/slab.h>
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +000023#include <linux/console.h>
Alexandre Courbot3b0fd9d2011-02-16 03:49:01 +000024#include <linux/backlight.h>
25#include <linux/gpio.h>
Paul Mundt225c9a82008-10-01 16:24:32 +090026#include <video/sh_mobile_lcdc.h>
Arun Sharma600634972011-07-26 16:09:06 -070027#include <linux/atomic.h>
Magnus Dammcfb4f5d2008-07-23 21:31:24 -070028
Guennadi Liakhovetski6de9edd2010-09-03 07:20:23 +000029#include "sh_mobile_lcdcfb.h"
Damian7caa4342011-05-18 11:10:07 +000030#include "sh_mobile_meram.h"
Guennadi Liakhovetski6de9edd2010-09-03 07:20:23 +000031
Phil Edworthya6f15ad2009-09-15 12:00:30 +000032#define SIDE_B_OFFSET 0x1000
33#define MIRROR_OFFSET 0x2000
Magnus Dammcfb4f5d2008-07-23 21:31:24 -070034
Magnus Damm0246c472009-08-14 10:49:08 +000035/* shared registers and their order for context save/restore */
36static int lcdc_shared_regs[] = {
37 _LDDCKR,
38 _LDDCKSTPR,
39 _LDINTR,
40 _LDDDSR,
41 _LDCNT1R,
42 _LDCNT2R,
43};
44#define NR_SHARED_REGS ARRAY_SIZE(lcdc_shared_regs)
45
Guennadi Liakhovetskid2ecbab2010-11-04 11:06:06 +000046#define MAX_XRES 1920
47#define MAX_YRES 1080
Magnus Dammcfb4f5d2008-07-23 21:31:24 -070048
Magnus Damm0246c472009-08-14 10:49:08 +000049static unsigned long lcdc_offs_mainlcd[NR_CH_REGS] = {
Magnus Dammcfb4f5d2008-07-23 21:31:24 -070050 [LDDCKPAT1R] = 0x400,
51 [LDDCKPAT2R] = 0x404,
52 [LDMT1R] = 0x418,
53 [LDMT2R] = 0x41c,
54 [LDMT3R] = 0x420,
55 [LDDFR] = 0x424,
56 [LDSM1R] = 0x428,
Magnus Damm85645572008-12-19 15:34:41 +090057 [LDSM2R] = 0x42c,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -070058 [LDSA1R] = 0x430,
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +000059 [LDSA2R] = 0x434,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -070060 [LDMLSR] = 0x438,
61 [LDHCNR] = 0x448,
62 [LDHSYNR] = 0x44c,
63 [LDVLNR] = 0x450,
64 [LDVSYNR] = 0x454,
65 [LDPMR] = 0x460,
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +000066 [LDHAJR] = 0x4a0,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -070067};
68
Magnus Damm0246c472009-08-14 10:49:08 +000069static unsigned long lcdc_offs_sublcd[NR_CH_REGS] = {
Magnus Dammcfb4f5d2008-07-23 21:31:24 -070070 [LDDCKPAT1R] = 0x408,
71 [LDDCKPAT2R] = 0x40c,
72 [LDMT1R] = 0x600,
73 [LDMT2R] = 0x604,
74 [LDMT3R] = 0x608,
75 [LDDFR] = 0x60c,
76 [LDSM1R] = 0x610,
Magnus Damm85645572008-12-19 15:34:41 +090077 [LDSM2R] = 0x614,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -070078 [LDSA1R] = 0x618,
79 [LDMLSR] = 0x620,
80 [LDHCNR] = 0x624,
81 [LDHSYNR] = 0x628,
82 [LDVLNR] = 0x62c,
83 [LDVSYNR] = 0x630,
84 [LDPMR] = 0x63c,
85};
86
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +000087static const struct fb_videomode default_720p = {
88 .name = "HDMI 720p",
89 .xres = 1280,
90 .yres = 720,
91
Guennadi Liakhovetski5ae0cf82010-11-04 11:06:01 +000092 .left_margin = 220,
93 .right_margin = 110,
94 .hsync_len = 40,
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +000095
96 .upper_margin = 20,
97 .lower_margin = 5,
98 .vsync_len = 5,
99
100 .pixclock = 13468,
Guennadi Liakhovetski5ae0cf82010-11-04 11:06:01 +0000101 .refresh = 60,
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +0000102 .sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT,
Magnus Damm0246c472009-08-14 10:49:08 +0000103};
104
105struct sh_mobile_lcdc_priv {
106 void __iomem *base;
107 int irq;
108 atomic_t hw_usecnt;
109 struct device *dev;
110 struct clk *dot_clk;
111 unsigned long lddckr;
112 struct sh_mobile_lcdc_chan ch[2];
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000113 struct notifier_block notifier;
Magnus Damm0246c472009-08-14 10:49:08 +0000114 unsigned long saved_shared_regs[NR_SHARED_REGS];
115 int started;
Magnus Damm417d4822011-01-05 10:21:00 +0000116 int forced_bpp; /* 2 channel LCDC must share bpp setting */
Damian7caa4342011-05-18 11:10:07 +0000117 struct sh_mobile_meram_info *meram_dev;
Magnus Damm0246c472009-08-14 10:49:08 +0000118};
119
Phil Edworthya6f15ad2009-09-15 12:00:30 +0000120static bool banked(int reg_nr)
121{
122 switch (reg_nr) {
123 case LDMT1R:
124 case LDMT2R:
125 case LDMT3R:
126 case LDDFR:
127 case LDSM1R:
128 case LDSA1R:
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000129 case LDSA2R:
Phil Edworthya6f15ad2009-09-15 12:00:30 +0000130 case LDMLSR:
131 case LDHCNR:
132 case LDHSYNR:
133 case LDVLNR:
134 case LDVSYNR:
135 return true;
136 }
137 return false;
138}
139
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700140static void lcdc_write_chan(struct sh_mobile_lcdc_chan *chan,
141 int reg_nr, unsigned long data)
142{
143 iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr]);
Phil Edworthya6f15ad2009-09-15 12:00:30 +0000144 if (banked(reg_nr))
145 iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr] +
146 SIDE_B_OFFSET);
147}
148
149static void lcdc_write_chan_mirror(struct sh_mobile_lcdc_chan *chan,
150 int reg_nr, unsigned long data)
151{
152 iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr] +
153 MIRROR_OFFSET);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700154}
155
156static unsigned long lcdc_read_chan(struct sh_mobile_lcdc_chan *chan,
157 int reg_nr)
158{
159 return ioread32(chan->lcdc->base + chan->reg_offs[reg_nr]);
160}
161
162static void lcdc_write(struct sh_mobile_lcdc_priv *priv,
163 unsigned long reg_offs, unsigned long data)
164{
165 iowrite32(data, priv->base + reg_offs);
166}
167
168static unsigned long lcdc_read(struct sh_mobile_lcdc_priv *priv,
169 unsigned long reg_offs)
170{
171 return ioread32(priv->base + reg_offs);
172}
173
174static void lcdc_wait_bit(struct sh_mobile_lcdc_priv *priv,
175 unsigned long reg_offs,
176 unsigned long mask, unsigned long until)
177{
178 while ((lcdc_read(priv, reg_offs) & mask) != until)
179 cpu_relax();
180}
181
182static int lcdc_chan_is_sublcd(struct sh_mobile_lcdc_chan *chan)
183{
184 return chan->cfg.chan == LCDC_CHAN_SUBLCD;
185}
186
187static void lcdc_sys_write_index(void *handle, unsigned long data)
188{
189 struct sh_mobile_lcdc_chan *ch = handle;
190
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200191 lcdc_write(ch->lcdc, _LDDWD0R, data | LDDWDxR_WDACT);
192 lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
193 lcdc_write(ch->lcdc, _LDDWAR, LDDWAR_WA |
194 (lcdc_chan_is_sublcd(ch) ? 2 : 0));
195 lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700196}
197
198static void lcdc_sys_write_data(void *handle, unsigned long data)
199{
200 struct sh_mobile_lcdc_chan *ch = handle;
201
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200202 lcdc_write(ch->lcdc, _LDDWD0R, data | LDDWDxR_WDACT | LDDWDxR_RSW);
203 lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
204 lcdc_write(ch->lcdc, _LDDWAR, LDDWAR_WA |
205 (lcdc_chan_is_sublcd(ch) ? 2 : 0));
206 lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700207}
208
209static unsigned long lcdc_sys_read_data(void *handle)
210{
211 struct sh_mobile_lcdc_chan *ch = handle;
212
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200213 lcdc_write(ch->lcdc, _LDDRDR, LDDRDR_RSR);
214 lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
215 lcdc_write(ch->lcdc, _LDDRAR, LDDRAR_RA |
216 (lcdc_chan_is_sublcd(ch) ? 2 : 0));
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700217 udelay(1);
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200218 lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700219
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200220 return lcdc_read(ch->lcdc, _LDDRDR) & LDDRDR_DRD_MASK;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700221}
222
223struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
224 lcdc_sys_write_index,
225 lcdc_sys_write_data,
226 lcdc_sys_read_data,
227};
228
Magnus Damm85645572008-12-19 15:34:41 +0900229static void sh_mobile_lcdc_clk_on(struct sh_mobile_lcdc_priv *priv)
230{
Magnus Damm0246c472009-08-14 10:49:08 +0000231 if (atomic_inc_and_test(&priv->hw_usecnt)) {
Magnus Damm85645572008-12-19 15:34:41 +0900232 if (priv->dot_clk)
233 clk_enable(priv->dot_clk);
Laurent Pinchartf1ad90d2011-07-11 11:05:49 +0200234 pm_runtime_get_sync(priv->dev);
Damian Hobson-Garciaec19b9e2011-07-04 08:06:47 +0200235 if (priv->meram_dev && priv->meram_dev->pdev)
236 pm_runtime_get_sync(&priv->meram_dev->pdev->dev);
Magnus Damm85645572008-12-19 15:34:41 +0900237 }
238}
239
240static void sh_mobile_lcdc_clk_off(struct sh_mobile_lcdc_priv *priv)
241{
Magnus Damm0246c472009-08-14 10:49:08 +0000242 if (atomic_sub_return(1, &priv->hw_usecnt) == -1) {
Damian Hobson-Garciaec19b9e2011-07-04 08:06:47 +0200243 if (priv->meram_dev && priv->meram_dev->pdev)
244 pm_runtime_put_sync(&priv->meram_dev->pdev->dev);
Magnus Damm0246c472009-08-14 10:49:08 +0000245 pm_runtime_put(priv->dev);
Laurent Pinchartf1ad90d2011-07-11 11:05:49 +0200246 if (priv->dot_clk)
247 clk_disable(priv->dot_clk);
Magnus Damm85645572008-12-19 15:34:41 +0900248 }
249}
Magnus Damm85645572008-12-19 15:34:41 +0900250
Paul Mundt1c6a3072009-07-01 06:50:31 +0000251static int sh_mobile_lcdc_sginit(struct fb_info *info,
252 struct list_head *pagelist)
253{
254 struct sh_mobile_lcdc_chan *ch = info->par;
255 unsigned int nr_pages_max = info->fix.smem_len >> PAGE_SHIFT;
256 struct page *page;
257 int nr_pages = 0;
258
259 sg_init_table(ch->sglist, nr_pages_max);
260
261 list_for_each_entry(page, pagelist, lru)
262 sg_set_page(&ch->sglist[nr_pages++], page, PAGE_SIZE, 0);
263
264 return nr_pages;
265}
266
Magnus Damm85645572008-12-19 15:34:41 +0900267static void sh_mobile_lcdc_deferred_io(struct fb_info *info,
268 struct list_head *pagelist)
269{
270 struct sh_mobile_lcdc_chan *ch = info->par;
Magnus Dammef61aae2009-12-07 14:20:06 +0000271 struct sh_mobile_lcdc_board_cfg *bcfg = &ch->cfg.board_cfg;
Magnus Damm85645572008-12-19 15:34:41 +0900272
273 /* enable clocks before accessing hardware */
274 sh_mobile_lcdc_clk_on(ch->lcdc);
275
Paul Mundt5c1a56b2009-11-04 15:59:04 +0900276 /*
277 * It's possible to get here without anything on the pagelist via
278 * sh_mobile_lcdc_deferred_io_touch() or via a userspace fsync()
279 * invocation. In the former case, the acceleration routines are
280 * stepped in to when using the framebuffer console causing the
281 * workqueue to be scheduled without any dirty pages on the list.
282 *
283 * Despite this, a panel update is still needed given that the
284 * acceleration routines have their own methods for writing in
285 * that still need to be updated.
286 *
287 * The fsync() and empty pagelist case could be optimized for,
288 * but we don't bother, as any application exhibiting such
289 * behaviour is fundamentally broken anyways.
290 */
291 if (!list_empty(pagelist)) {
292 unsigned int nr_pages = sh_mobile_lcdc_sginit(info, pagelist);
Paul Mundt1c6a3072009-07-01 06:50:31 +0000293
Paul Mundt5c1a56b2009-11-04 15:59:04 +0900294 /* trigger panel update */
295 dma_map_sg(info->dev, ch->sglist, nr_pages, DMA_TO_DEVICE);
Magnus Dammef61aae2009-12-07 14:20:06 +0000296 if (bcfg->start_transfer)
297 bcfg->start_transfer(bcfg->board_data, ch,
298 &sh_mobile_lcdc_sys_bus_ops);
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200299 lcdc_write_chan(ch, LDSM2R, LDSM2R_OSTRG);
Paul Mundt5c1a56b2009-11-04 15:59:04 +0900300 dma_unmap_sg(info->dev, ch->sglist, nr_pages, DMA_TO_DEVICE);
Magnus Dammef61aae2009-12-07 14:20:06 +0000301 } else {
302 if (bcfg->start_transfer)
303 bcfg->start_transfer(bcfg->board_data, ch,
304 &sh_mobile_lcdc_sys_bus_ops);
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200305 lcdc_write_chan(ch, LDSM2R, LDSM2R_OSTRG);
Magnus Dammef61aae2009-12-07 14:20:06 +0000306 }
Magnus Damm85645572008-12-19 15:34:41 +0900307}
308
309static void sh_mobile_lcdc_deferred_io_touch(struct fb_info *info)
310{
311 struct fb_deferred_io *fbdefio = info->fbdefio;
312
313 if (fbdefio)
314 schedule_delayed_work(&info->deferred_work, fbdefio->delay);
315}
316
317static irqreturn_t sh_mobile_lcdc_irq(int irq, void *data)
318{
319 struct sh_mobile_lcdc_priv *priv = data;
Magnus Damm2feb0752009-03-13 15:36:55 +0000320 struct sh_mobile_lcdc_chan *ch;
Phil Edworthy9dd38812009-09-15 12:00:18 +0000321 unsigned long ldintr;
Magnus Damm2feb0752009-03-13 15:36:55 +0000322 int is_sub;
323 int k;
Magnus Damm85645572008-12-19 15:34:41 +0900324
Laurent Pinchartdc486652011-07-13 12:13:47 +0200325 /* Acknowledge interrupts and disable further VSYNC End IRQs. */
326 ldintr = lcdc_read(priv, _LDINTR);
327 lcdc_write(priv, _LDINTR, (ldintr ^ LDINTR_STATUS_MASK) & ~LDINTR_VEE);
Magnus Damm85645572008-12-19 15:34:41 +0900328
Magnus Damm2feb0752009-03-13 15:36:55 +0000329 /* figure out if this interrupt is for main or sub lcd */
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200330 is_sub = (lcdc_read(priv, _LDSR) & LDSR_MSS) ? 1 : 0;
Magnus Damm2feb0752009-03-13 15:36:55 +0000331
Phil Edworthy9dd38812009-09-15 12:00:18 +0000332 /* wake up channel and disable clocks */
Magnus Damm2feb0752009-03-13 15:36:55 +0000333 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
334 ch = &priv->ch[k];
335
336 if (!ch->enabled)
337 continue;
338
Laurent Pinchartdc486652011-07-13 12:13:47 +0200339 /* Frame End */
Phil Edworthy9dd38812009-09-15 12:00:18 +0000340 if (ldintr & LDINTR_FS) {
341 if (is_sub == lcdc_chan_is_sublcd(ch)) {
342 ch->frame_end = 1;
343 wake_up(&ch->frame_end_wait);
Magnus Damm2feb0752009-03-13 15:36:55 +0000344
Phil Edworthy9dd38812009-09-15 12:00:18 +0000345 sh_mobile_lcdc_clk_off(priv);
346 }
347 }
348
349 /* VSYNC End */
Phil Edworthy40331b22010-02-15 13:57:49 +0000350 if (ldintr & LDINTR_VES)
351 complete(&ch->vsync_completion);
Magnus Damm2feb0752009-03-13 15:36:55 +0000352 }
353
Magnus Damm85645572008-12-19 15:34:41 +0900354 return IRQ_HANDLED;
355}
356
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700357static void sh_mobile_lcdc_start_stop(struct sh_mobile_lcdc_priv *priv,
358 int start)
359{
360 unsigned long tmp = lcdc_read(priv, _LDCNT2R);
361 int k;
362
363 /* start or stop the lcdc */
364 if (start)
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200365 lcdc_write(priv, _LDCNT2R, tmp | LDCNT2R_DO);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700366 else
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200367 lcdc_write(priv, _LDCNT2R, tmp & ~LDCNT2R_DO);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700368
369 /* wait until power is applied/stopped on all channels */
370 for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
371 if (lcdc_read(priv, _LDCNT2R) & priv->ch[k].enabled)
372 while (1) {
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200373 tmp = lcdc_read_chan(&priv->ch[k], LDPMR)
374 & LDPMR_LPS;
375 if (start && tmp == LDPMR_LPS)
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700376 break;
377 if (!start && tmp == 0)
378 break;
379 cpu_relax();
380 }
381
382 if (!start)
383 lcdc_write(priv, _LDDCKSTPR, 1); /* stop dotclock */
384}
385
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000386static void sh_mobile_lcdc_geometry(struct sh_mobile_lcdc_chan *ch)
387{
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000388 struct fb_var_screeninfo *var = &ch->info->var, *display_var = &ch->display_var;
389 unsigned long h_total, hsync_pos, display_h_total;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000390 u32 tmp;
391
392 tmp = ch->ldmt1r_value;
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200393 tmp |= (var->sync & FB_SYNC_VERT_HIGH_ACT) ? 0 : LDMT1R_VPOL;
394 tmp |= (var->sync & FB_SYNC_HOR_HIGH_ACT) ? 0 : LDMT1R_HPOL;
395 tmp |= (ch->cfg.flags & LCDC_FLAGS_DWPOL) ? LDMT1R_DWPOL : 0;
396 tmp |= (ch->cfg.flags & LCDC_FLAGS_DIPOL) ? LDMT1R_DIPOL : 0;
397 tmp |= (ch->cfg.flags & LCDC_FLAGS_DAPOL) ? LDMT1R_DAPOL : 0;
398 tmp |= (ch->cfg.flags & LCDC_FLAGS_HSCNT) ? LDMT1R_HSCNT : 0;
399 tmp |= (ch->cfg.flags & LCDC_FLAGS_DWCNT) ? LDMT1R_DWCNT : 0;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000400 lcdc_write_chan(ch, LDMT1R, tmp);
401
402 /* setup SYS bus */
403 lcdc_write_chan(ch, LDMT2R, ch->cfg.sys_bus_cfg.ldmt2r);
404 lcdc_write_chan(ch, LDMT3R, ch->cfg.sys_bus_cfg.ldmt3r);
405
406 /* horizontal configuration */
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000407 h_total = display_var->xres + display_var->hsync_len +
408 display_var->left_margin + display_var->right_margin;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000409 tmp = h_total / 8; /* HTCN */
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000410 tmp |= (min(display_var->xres, var->xres) / 8) << 16; /* HDCN */
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000411 lcdc_write_chan(ch, LDHCNR, tmp);
412
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000413 hsync_pos = display_var->xres + display_var->right_margin;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000414 tmp = hsync_pos / 8; /* HSYNP */
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000415 tmp |= (display_var->hsync_len / 8) << 16; /* HSYNW */
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000416 lcdc_write_chan(ch, LDHSYNR, tmp);
417
418 /* vertical configuration */
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000419 tmp = display_var->yres + display_var->vsync_len +
420 display_var->upper_margin + display_var->lower_margin; /* VTLN */
421 tmp |= min(display_var->yres, var->yres) << 16; /* VDLN */
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000422 lcdc_write_chan(ch, LDVLNR, tmp);
423
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000424 tmp = display_var->yres + display_var->lower_margin; /* VSYNP */
425 tmp |= display_var->vsync_len << 16; /* VSYNW */
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000426 lcdc_write_chan(ch, LDVSYNR, tmp);
427
428 /* Adjust horizontal synchronisation for HDMI */
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000429 display_h_total = display_var->xres + display_var->hsync_len +
430 display_var->left_margin + display_var->right_margin;
431 tmp = ((display_var->xres & 7) << 24) |
432 ((display_h_total & 7) << 16) |
433 ((display_var->hsync_len & 7) << 8) |
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000434 hsync_pos;
435 lcdc_write_chan(ch, LDHAJR, tmp);
436}
437
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700438static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv)
439{
440 struct sh_mobile_lcdc_chan *ch;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700441 struct sh_mobile_lcdc_board_cfg *board_cfg;
442 unsigned long tmp;
Magnus Damm417d4822011-01-05 10:21:00 +0000443 int bpp = 0;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000444 unsigned long ldddsr;
Paul Mundt554cc102011-05-26 15:01:22 +0900445 int k, m, ret;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700446
Magnus Damm85645572008-12-19 15:34:41 +0900447 /* enable clocks before accessing the hardware */
Magnus Damm417d4822011-01-05 10:21:00 +0000448 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
449 if (priv->ch[k].enabled) {
Magnus Damm85645572008-12-19 15:34:41 +0900450 sh_mobile_lcdc_clk_on(priv);
Magnus Damm417d4822011-01-05 10:21:00 +0000451 if (!bpp)
452 bpp = priv->ch[k].info->var.bits_per_pixel;
453 }
454 }
Magnus Damm85645572008-12-19 15:34:41 +0900455
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700456 /* reset */
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200457 lcdc_write(priv, _LDCNT2R, lcdc_read(priv, _LDCNT2R) | LDCNT2R_BR);
458 lcdc_wait_bit(priv, _LDCNT2R, LDCNT2R_BR, 0);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700459
460 /* enable LCDC channels */
461 tmp = lcdc_read(priv, _LDCNT2R);
462 tmp |= priv->ch[0].enabled;
463 tmp |= priv->ch[1].enabled;
464 lcdc_write(priv, _LDCNT2R, tmp);
465
466 /* read data from external memory, avoid using the BEU for now */
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200467 lcdc_write(priv, _LDCNT2R, lcdc_read(priv, _LDCNT2R) & ~LDCNT2R_MD);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700468
469 /* stop the lcdc first */
470 sh_mobile_lcdc_start_stop(priv, 0);
471
472 /* configure clocks */
473 tmp = priv->lddckr;
474 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
475 ch = &priv->ch[k];
476
477 if (!priv->ch[k].enabled)
478 continue;
479
480 m = ch->cfg.clock_divider;
481 if (!m)
482 continue;
483
484 if (m == 1)
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200485 m = LDDCKR_MOSEL;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700486 tmp |= m << (lcdc_chan_is_sublcd(ch) ? 8 : 0);
487
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +0000488 /* FIXME: sh7724 can only use 42, 48, 54 and 60 for the divider denominator */
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000489 lcdc_write_chan(ch, LDDCKPAT1R, 0);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700490 lcdc_write_chan(ch, LDDCKPAT2R, (1 << (m/2)) - 1);
491 }
492
493 lcdc_write(priv, _LDDCKR, tmp);
494
495 /* start dotclock again */
496 lcdc_write(priv, _LDDCKSTPR, 0);
497 lcdc_wait_bit(priv, _LDDCKSTPR, ~0, 0);
498
Magnus Damm85645572008-12-19 15:34:41 +0900499 /* interrupts are disabled to begin with */
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700500 lcdc_write(priv, _LDINTR, 0);
501
502 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
503 ch = &priv->ch[k];
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700504
505 if (!ch->enabled)
506 continue;
507
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000508 sh_mobile_lcdc_geometry(ch);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700509
510 /* power supply */
511 lcdc_write_chan(ch, LDPMR, 0);
512
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700513 board_cfg = &ch->cfg.board_cfg;
Guennadi Liakhovetski69843ba2011-05-05 16:32:36 +0000514 if (board_cfg->setup_sys) {
Paul Mundt554cc102011-05-26 15:01:22 +0900515 ret = board_cfg->setup_sys(board_cfg->board_data,
Guennadi Liakhovetski69843ba2011-05-05 16:32:36 +0000516 ch, &sh_mobile_lcdc_sys_bus_ops);
517 if (ret)
518 return ret;
519 }
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700520 }
521
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700522 /* word and long word swap */
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000523 ldddsr = lcdc_read(priv, _LDDDSR);
524 if (priv->ch[0].info->var.nonstd)
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200525 ldddsr |= LDDDSR_LS | LDDDSR_WS | LDDDSR_BS;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000526 else {
527 switch (bpp) {
528 case 16:
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200529 ldddsr |= LDDDSR_LS | LDDDSR_WS;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000530 break;
531 case 24:
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200532 ldddsr |= LDDDSR_LS | LDDDSR_WS | LDDDSR_BS;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000533 break;
534 case 32:
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200535 ldddsr |= LDDDSR_LS;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000536 break;
537 }
Magnus Damm417d4822011-01-05 10:21:00 +0000538 }
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200539 lcdc_write(priv, _LDDDSR, ldddsr);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700540
541 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
Damian7caa4342011-05-18 11:10:07 +0000542 unsigned long base_addr_y;
543 unsigned long base_addr_c = 0;
544 int pitch;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700545 ch = &priv->ch[k];
546
547 if (!priv->ch[k].enabled)
548 continue;
549
550 /* set bpp format in PKF[4:0] */
551 tmp = lcdc_read_chan(ch, LDDFR);
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200552 tmp &= ~(LDDFR_CF0 | LDDFR_CC | LDDFR_YF_MASK | LDDFR_PKF_MASK);
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000553 if (ch->info->var.nonstd) {
554 tmp |= (ch->info->var.nonstd << 16);
555 switch (ch->info->var.bits_per_pixel) {
556 case 12:
557 break;
558 case 16:
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200559 tmp |= LDDFR_YF_422;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000560 break;
561 case 24:
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200562 tmp |= LDDFR_YF_444;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000563 break;
564 }
565 } else {
566 switch (ch->info->var.bits_per_pixel) {
567 case 16:
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200568 tmp |= LDDFR_PKF_RGB16;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000569 break;
570 case 24:
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200571 tmp |= LDDFR_PKF_RGB24;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000572 break;
573 case 32:
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200574 tmp |= LDDFR_PKF_ARGB32;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000575 break;
576 }
Magnus Damm417d4822011-01-05 10:21:00 +0000577 }
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700578 lcdc_write_chan(ch, LDDFR, tmp);
579
Damian7caa4342011-05-18 11:10:07 +0000580 base_addr_y = ch->info->fix.smem_start;
581 base_addr_c = base_addr_y +
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000582 ch->info->var.xres *
Damian7caa4342011-05-18 11:10:07 +0000583 ch->info->var.yres_virtual;
584 pitch = ch->info->fix.line_length;
585
586 /* test if we can enable meram */
Damianeae9b852011-05-24 07:01:21 +0000587 if (ch->cfg.meram_cfg && priv->meram_dev &&
588 priv->meram_dev->ops) {
Damian7caa4342011-05-18 11:10:07 +0000589 struct sh_mobile_meram_cfg *cfg;
590 struct sh_mobile_meram_info *mdev;
591 unsigned long icb_addr_y, icb_addr_c;
592 int icb_pitch;
593 int pf;
594
595 cfg = ch->cfg.meram_cfg;
596 mdev = priv->meram_dev;
597 /* we need to de-init configured ICBs before we
598 * we can re-initialize them.
599 */
600 if (ch->meram_enabled)
601 mdev->ops->meram_unregister(mdev, cfg);
602
603 ch->meram_enabled = 0;
604
Damian3fedd2a2011-05-18 11:10:08 +0000605 if (ch->info->var.nonstd) {
606 if (ch->info->var.bits_per_pixel == 24)
607 pf = SH_MOBILE_MERAM_PF_NV24;
608 else
609 pf = SH_MOBILE_MERAM_PF_NV;
610 } else {
Damian7caa4342011-05-18 11:10:07 +0000611 pf = SH_MOBILE_MERAM_PF_RGB;
Damian3fedd2a2011-05-18 11:10:08 +0000612 }
Damian7caa4342011-05-18 11:10:07 +0000613
614 ret = mdev->ops->meram_register(mdev, cfg, pitch,
615 ch->info->var.yres,
616 pf,
617 base_addr_y,
618 base_addr_c,
619 &icb_addr_y,
620 &icb_addr_c,
621 &icb_pitch);
622 if (!ret) {
623 /* set LDSA1R value */
624 base_addr_y = icb_addr_y;
625 pitch = icb_pitch;
626
627 /* set LDSA2R value if required */
628 if (base_addr_c)
629 base_addr_c = icb_addr_c;
630
631 ch->meram_enabled = 1;
632 }
633 }
634
635 /* point out our frame buffer */
636 lcdc_write_chan(ch, LDSA1R, base_addr_y);
637 if (ch->info->var.nonstd)
638 lcdc_write_chan(ch, LDSA2R, base_addr_c);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700639
640 /* set line size */
Damian7caa4342011-05-18 11:10:07 +0000641 lcdc_write_chan(ch, LDMLSR, pitch);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700642
Magnus Damm85645572008-12-19 15:34:41 +0900643 /* setup deferred io if SYS bus */
644 tmp = ch->cfg.sys_bus_cfg.deferred_io_msec;
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200645 if (ch->ldmt1r_value & LDMT1R_IFM && tmp) {
Magnus Damm85645572008-12-19 15:34:41 +0900646 ch->defio.deferred_io = sh_mobile_lcdc_deferred_io;
647 ch->defio.delay = msecs_to_jiffies(tmp);
Paul Mundte33afdd2009-07-07 11:24:32 +0900648 ch->info->fbdefio = &ch->defio;
649 fb_deferred_io_init(ch->info);
Magnus Damm85645572008-12-19 15:34:41 +0900650
651 /* one-shot mode */
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200652 lcdc_write_chan(ch, LDSM1R, LDSM1R_OS);
Magnus Damm85645572008-12-19 15:34:41 +0900653
654 /* enable "Frame End Interrupt Enable" bit */
655 lcdc_write(priv, _LDINTR, LDINTR_FE);
656
657 } else {
658 /* continuous read mode */
659 lcdc_write_chan(ch, LDSM1R, 0);
660 }
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700661 }
662
663 /* display output */
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200664 lcdc_write(priv, _LDCNT1R, LDCNT1R_DE);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700665
666 /* start the lcdc */
667 sh_mobile_lcdc_start_stop(priv, 1);
Magnus Damm8e9bb192009-05-20 14:34:43 +0000668 priv->started = 1;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700669
670 /* tell the board code to enable the panel */
671 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
672 ch = &priv->ch[k];
Magnus Damm21bc1f02009-08-15 02:53:16 +0000673 if (!ch->enabled)
674 continue;
675
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700676 board_cfg = &ch->cfg.board_cfg;
Alexandre Courbot247f9932011-02-23 08:41:50 +0000677 if (board_cfg->display_on && try_module_get(board_cfg->owner)) {
Guennadi Liakhovetskic2439392010-07-21 10:13:17 +0000678 board_cfg->display_on(board_cfg->board_data, ch->info);
Guennadi Liakhovetski6de9edd2010-09-03 07:20:23 +0000679 module_put(board_cfg->owner);
680 }
Alexandre Courbot3b0fd9d2011-02-16 03:49:01 +0000681
682 if (ch->bl) {
683 ch->bl->props.power = FB_BLANK_UNBLANK;
684 backlight_update_status(ch->bl);
685 }
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700686 }
687
688 return 0;
689}
690
691static void sh_mobile_lcdc_stop(struct sh_mobile_lcdc_priv *priv)
692{
693 struct sh_mobile_lcdc_chan *ch;
694 struct sh_mobile_lcdc_board_cfg *board_cfg;
695 int k;
696
Magnus Damm2feb0752009-03-13 15:36:55 +0000697 /* clean up deferred io and ask board code to disable panel */
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700698 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
699 ch = &priv->ch[k];
Magnus Damm21bc1f02009-08-15 02:53:16 +0000700 if (!ch->enabled)
701 continue;
Magnus Damm2feb0752009-03-13 15:36:55 +0000702
703 /* deferred io mode:
704 * flush frame, and wait for frame end interrupt
705 * clean up deferred io and enable clock
706 */
Guennadi Liakhovetski5ef6b502010-09-03 07:19:57 +0000707 if (ch->info && ch->info->fbdefio) {
Magnus Damm2feb0752009-03-13 15:36:55 +0000708 ch->frame_end = 0;
Paul Mundte33afdd2009-07-07 11:24:32 +0900709 schedule_delayed_work(&ch->info->deferred_work, 0);
Magnus Damm2feb0752009-03-13 15:36:55 +0000710 wait_event(ch->frame_end_wait, ch->frame_end);
Paul Mundte33afdd2009-07-07 11:24:32 +0900711 fb_deferred_io_cleanup(ch->info);
712 ch->info->fbdefio = NULL;
Magnus Damm2feb0752009-03-13 15:36:55 +0000713 sh_mobile_lcdc_clk_on(priv);
714 }
715
Alexandre Courbot3b0fd9d2011-02-16 03:49:01 +0000716 if (ch->bl) {
717 ch->bl->props.power = FB_BLANK_POWERDOWN;
718 backlight_update_status(ch->bl);
719 }
720
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700721 board_cfg = &ch->cfg.board_cfg;
Alexandre Courbot247f9932011-02-23 08:41:50 +0000722 if (board_cfg->display_off && try_module_get(board_cfg->owner)) {
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700723 board_cfg->display_off(board_cfg->board_data);
Guennadi Liakhovetski6de9edd2010-09-03 07:20:23 +0000724 module_put(board_cfg->owner);
725 }
Damian7caa4342011-05-18 11:10:07 +0000726
727 /* disable the meram */
728 if (ch->meram_enabled) {
729 struct sh_mobile_meram_cfg *cfg;
730 struct sh_mobile_meram_info *mdev;
731 cfg = ch->cfg.meram_cfg;
732 mdev = priv->meram_dev;
733 mdev->ops->meram_unregister(mdev, cfg);
734 ch->meram_enabled = 0;
735 }
736
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700737 }
738
739 /* stop the lcdc */
Magnus Damm8e9bb192009-05-20 14:34:43 +0000740 if (priv->started) {
741 sh_mobile_lcdc_start_stop(priv, 0);
742 priv->started = 0;
743 }
Magnus Dammb51339f2008-10-31 20:23:26 +0900744
Magnus Damm85645572008-12-19 15:34:41 +0900745 /* stop clocks */
746 for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
747 if (priv->ch[k].enabled)
748 sh_mobile_lcdc_clk_off(priv);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700749}
750
751static int sh_mobile_lcdc_check_interface(struct sh_mobile_lcdc_chan *ch)
752{
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200753 int interface_type = ch->cfg.interface_type;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700754
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200755 switch (interface_type) {
756 case RGB8:
757 case RGB9:
758 case RGB12A:
759 case RGB12B:
760 case RGB16:
761 case RGB18:
762 case RGB24:
763 case SYS8A:
764 case SYS8B:
765 case SYS8C:
766 case SYS8D:
767 case SYS9:
768 case SYS12:
769 case SYS16A:
770 case SYS16B:
771 case SYS16C:
772 case SYS18:
773 case SYS24:
774 break;
775 default:
776 return -EINVAL;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700777 }
778
779 /* SUBLCD only supports SYS interface */
780 if (lcdc_chan_is_sublcd(ch)) {
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200781 if (!(interface_type & LDMT1R_IFM))
782 return -EINVAL;
783
784 interface_type &= ~LDMT1R_IFM;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700785 }
786
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200787 ch->ldmt1r_value = interface_type;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700788 return 0;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700789}
790
Magnus Dammb51339f2008-10-31 20:23:26 +0900791static int sh_mobile_lcdc_setup_clocks(struct platform_device *pdev,
792 int clock_source,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700793 struct sh_mobile_lcdc_priv *priv)
794{
795 char *str;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700796
797 switch (clock_source) {
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200798 case LCDC_CLK_BUS:
799 str = "bus_clk";
800 priv->lddckr = LDDCKR_ICKSEL_BUS;
801 break;
802 case LCDC_CLK_PERIPHERAL:
803 str = "peripheral_clk";
804 priv->lddckr = LDDCKR_ICKSEL_MIPI;
805 break;
806 case LCDC_CLK_EXTERNAL:
807 str = NULL;
808 priv->lddckr = LDDCKR_ICKSEL_HDMI;
809 break;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700810 default:
811 return -EINVAL;
812 }
813
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700814 if (str) {
Magnus Dammb51339f2008-10-31 20:23:26 +0900815 priv->dot_clk = clk_get(&pdev->dev, str);
816 if (IS_ERR(priv->dot_clk)) {
817 dev_err(&pdev->dev, "cannot get dot clock %s\n", str);
Magnus Dammb51339f2008-10-31 20:23:26 +0900818 return PTR_ERR(priv->dot_clk);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700819 }
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700820 }
821
Magnus Damm0246c472009-08-14 10:49:08 +0000822 /* Runtime PM support involves two step for this driver:
823 * 1) Enable Runtime PM
824 * 2) Force Runtime PM Resume since hardware is accessed from probe()
825 */
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +0000826 priv->dev = &pdev->dev;
Magnus Damm0246c472009-08-14 10:49:08 +0000827 pm_runtime_enable(priv->dev);
828 pm_runtime_resume(priv->dev);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700829 return 0;
830}
831
832static int sh_mobile_lcdc_setcolreg(u_int regno,
833 u_int red, u_int green, u_int blue,
834 u_int transp, struct fb_info *info)
835{
836 u32 *palette = info->pseudo_palette;
837
838 if (regno >= PALETTE_NR)
839 return -EINVAL;
840
841 /* only FB_VISUAL_TRUECOLOR supported */
842
843 red >>= 16 - info->var.red.length;
844 green >>= 16 - info->var.green.length;
845 blue >>= 16 - info->var.blue.length;
846 transp >>= 16 - info->var.transp.length;
847
848 palette[regno] = (red << info->var.red.offset) |
849 (green << info->var.green.offset) |
850 (blue << info->var.blue.offset) |
851 (transp << info->var.transp.offset);
852
853 return 0;
854}
855
856static struct fb_fix_screeninfo sh_mobile_lcdc_fix = {
857 .id = "SH Mobile LCDC",
858 .type = FB_TYPE_PACKED_PIXELS,
859 .visual = FB_VISUAL_TRUECOLOR,
860 .accel = FB_ACCEL_NONE,
Phil Edworthy9dd38812009-09-15 12:00:18 +0000861 .xpanstep = 0,
862 .ypanstep = 1,
863 .ywrapstep = 0,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700864};
865
Magnus Damm85645572008-12-19 15:34:41 +0900866static void sh_mobile_lcdc_fillrect(struct fb_info *info,
867 const struct fb_fillrect *rect)
868{
869 sys_fillrect(info, rect);
870 sh_mobile_lcdc_deferred_io_touch(info);
871}
872
873static void sh_mobile_lcdc_copyarea(struct fb_info *info,
874 const struct fb_copyarea *area)
875{
876 sys_copyarea(info, area);
877 sh_mobile_lcdc_deferred_io_touch(info);
878}
879
880static void sh_mobile_lcdc_imageblit(struct fb_info *info,
881 const struct fb_image *image)
882{
883 sys_imageblit(info, image);
884 sh_mobile_lcdc_deferred_io_touch(info);
885}
886
Phil Edworthy9dd38812009-09-15 12:00:18 +0000887static int sh_mobile_fb_pan_display(struct fb_var_screeninfo *var,
888 struct fb_info *info)
889{
890 struct sh_mobile_lcdc_chan *ch = info->par;
Phil Edworthy92e1f9a2010-02-11 10:24:25 +0000891 struct sh_mobile_lcdc_priv *priv = ch->lcdc;
892 unsigned long ldrcntr;
893 unsigned long new_pan_offset;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000894 unsigned long base_addr_y, base_addr_c;
895 unsigned long c_offset;
Phil Edworthy9dd38812009-09-15 12:00:18 +0000896
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000897 if (!var->nonstd)
898 new_pan_offset = (var->yoffset * info->fix.line_length) +
899 (var->xoffset * (info->var.bits_per_pixel / 8));
900 else
901 new_pan_offset = (var->yoffset * info->fix.line_length) +
902 (var->xoffset);
Phil Edworthy9dd38812009-09-15 12:00:18 +0000903
Phil Edworthy92e1f9a2010-02-11 10:24:25 +0000904 if (new_pan_offset == ch->pan_offset)
905 return 0; /* No change, do nothing */
906
907 ldrcntr = lcdc_read(priv, _LDRCNTR);
908
909 /* Set the source address for the next refresh */
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000910 base_addr_y = ch->dma_handle + new_pan_offset;
911 if (var->nonstd) {
912 /* Set y offset */
913 c_offset = (var->yoffset *
914 info->fix.line_length *
915 (info->var.bits_per_pixel - 8)) / 8;
916 base_addr_c = ch->dma_handle + var->xres * var->yres_virtual +
917 c_offset;
918 /* Set x offset */
919 if (info->var.bits_per_pixel == 24)
920 base_addr_c += 2 * var->xoffset;
921 else
922 base_addr_c += var->xoffset;
923 } else
924 base_addr_c = 0;
925
Damian7caa4342011-05-18 11:10:07 +0000926 if (!ch->meram_enabled) {
927 lcdc_write_chan_mirror(ch, LDSA1R, base_addr_y);
928 if (base_addr_c)
929 lcdc_write_chan_mirror(ch, LDSA2R, base_addr_c);
930 } else {
931 struct sh_mobile_meram_cfg *cfg;
932 struct sh_mobile_meram_info *mdev;
933 unsigned long icb_addr_y, icb_addr_c;
934 int ret;
935
936 cfg = ch->cfg.meram_cfg;
937 mdev = priv->meram_dev;
938 ret = mdev->ops->meram_update(mdev, cfg,
939 base_addr_y, base_addr_c,
940 &icb_addr_y, &icb_addr_c);
941 if (ret)
942 return ret;
943
944 lcdc_write_chan_mirror(ch, LDSA1R, icb_addr_y);
945 if (icb_addr_c)
946 lcdc_write_chan_mirror(ch, LDSA2R, icb_addr_c);
947
948 }
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000949
Phil Edworthy92e1f9a2010-02-11 10:24:25 +0000950 if (lcdc_chan_is_sublcd(ch))
951 lcdc_write(ch->lcdc, _LDRCNTR, ldrcntr ^ LDRCNTR_SRS);
952 else
953 lcdc_write(ch->lcdc, _LDRCNTR, ldrcntr ^ LDRCNTR_MRS);
954
955 ch->pan_offset = new_pan_offset;
956
957 sh_mobile_lcdc_deferred_io_touch(info);
Phil Edworthy9dd38812009-09-15 12:00:18 +0000958
959 return 0;
960}
961
Phil Edworthy40331b22010-02-15 13:57:49 +0000962static int sh_mobile_wait_for_vsync(struct fb_info *info)
963{
964 struct sh_mobile_lcdc_chan *ch = info->par;
965 unsigned long ldintr;
966 int ret;
967
Laurent Pinchartdc486652011-07-13 12:13:47 +0200968 /* Enable VSync End interrupt and be careful not to acknowledge any
969 * pending interrupt.
970 */
Phil Edworthy40331b22010-02-15 13:57:49 +0000971 ldintr = lcdc_read(ch->lcdc, _LDINTR);
Laurent Pinchartdc486652011-07-13 12:13:47 +0200972 ldintr |= LDINTR_VEE | LDINTR_STATUS_MASK;
Phil Edworthy40331b22010-02-15 13:57:49 +0000973 lcdc_write(ch->lcdc, _LDINTR, ldintr);
974
975 ret = wait_for_completion_interruptible_timeout(&ch->vsync_completion,
976 msecs_to_jiffies(100));
977 if (!ret)
978 return -ETIMEDOUT;
979
980 return 0;
981}
982
983static int sh_mobile_ioctl(struct fb_info *info, unsigned int cmd,
984 unsigned long arg)
985{
986 int retval;
987
988 switch (cmd) {
989 case FBIO_WAITFORVSYNC:
990 retval = sh_mobile_wait_for_vsync(info);
991 break;
992
993 default:
994 retval = -ENOIOCTLCMD;
995 break;
996 }
997 return retval;
998}
999
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001000static void sh_mobile_fb_reconfig(struct fb_info *info)
1001{
1002 struct sh_mobile_lcdc_chan *ch = info->par;
1003 struct fb_videomode mode1, mode2;
1004 struct fb_event event;
1005 int evnt = FB_EVENT_MODE_CHANGE_ALL;
1006
1007 if (ch->use_count > 1 || (ch->use_count == 1 && !info->fbcon_par))
1008 /* More framebuffer users are active */
1009 return;
1010
1011 fb_var_to_videomode(&mode1, &ch->display_var);
1012 fb_var_to_videomode(&mode2, &info->var);
1013
1014 if (fb_mode_is_equal(&mode1, &mode2))
1015 return;
1016
1017 /* Display has been re-plugged, framebuffer is free now, reconfigure */
1018 if (fb_set_var(info, &ch->display_var) < 0)
1019 /* Couldn't reconfigure, hopefully, can continue as before */
1020 return;
1021
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +00001022 if (info->var.nonstd)
1023 info->fix.line_length = mode1.xres;
1024 else
1025 info->fix.line_length = mode1.xres * (ch->cfg.bpp / 8);
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001026
1027 /*
1028 * fb_set_var() calls the notifier change internally, only if
1029 * FBINFO_MISC_USEREVENT flag is set. Since we do not want to fake a
1030 * user event, we have to call the chain ourselves.
1031 */
1032 event.info = info;
Arnd Hannemanncc267ec2010-11-15 21:43:22 +00001033 event.data = &mode1;
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001034 fb_notifier_call_chain(evnt, &event);
1035}
1036
1037/*
1038 * Locking: both .fb_release() and .fb_open() are called with info->lock held if
1039 * user == 1, or with console sem held, if user == 0.
1040 */
1041static int sh_mobile_release(struct fb_info *info, int user)
1042{
1043 struct sh_mobile_lcdc_chan *ch = info->par;
1044
1045 mutex_lock(&ch->open_lock);
1046 dev_dbg(info->dev, "%s(): %d users\n", __func__, ch->use_count);
1047
1048 ch->use_count--;
1049
1050 /* Nothing to reconfigure, when called from fbcon */
1051 if (user) {
Torben Hohnac751ef2011-01-25 15:07:35 -08001052 console_lock();
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001053 sh_mobile_fb_reconfig(info);
Torben Hohnac751ef2011-01-25 15:07:35 -08001054 console_unlock();
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001055 }
1056
1057 mutex_unlock(&ch->open_lock);
1058
1059 return 0;
1060}
1061
1062static int sh_mobile_open(struct fb_info *info, int user)
1063{
1064 struct sh_mobile_lcdc_chan *ch = info->par;
1065
1066 mutex_lock(&ch->open_lock);
1067 ch->use_count++;
1068
1069 dev_dbg(info->dev, "%s(): %d users\n", __func__, ch->use_count);
1070 mutex_unlock(&ch->open_lock);
1071
1072 return 0;
1073}
1074
1075static int sh_mobile_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1076{
1077 struct sh_mobile_lcdc_chan *ch = info->par;
Magnus Damm417d4822011-01-05 10:21:00 +00001078 struct sh_mobile_lcdc_priv *p = ch->lcdc;
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001079
Guennadi Liakhovetskid2ecbab2010-11-04 11:06:06 +00001080 if (var->xres > MAX_XRES || var->yres > MAX_YRES ||
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001081 var->xres * var->yres * (ch->cfg.bpp / 8) * 2 > info->fix.smem_len) {
Paul Mundt830539d2010-11-10 17:51:44 +09001082 dev_warn(info->dev, "Invalid info: %u-%u-%u-%u x %u-%u-%u-%u @ %lukHz!\n",
Guennadi Liakhovetskid2ecbab2010-11-04 11:06:06 +00001083 var->left_margin, var->xres, var->right_margin, var->hsync_len,
1084 var->upper_margin, var->yres, var->lower_margin, var->vsync_len,
1085 PICOS2KHZ(var->pixclock));
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001086 return -EINVAL;
1087 }
Magnus Damm417d4822011-01-05 10:21:00 +00001088
1089 /* only accept the forced_bpp for dual channel configurations */
1090 if (p->forced_bpp && p->forced_bpp != var->bits_per_pixel)
1091 return -EINVAL;
1092
1093 switch (var->bits_per_pixel) {
1094 case 16: /* PKF[4:0] = 00011 - RGB 565 */
1095 case 24: /* PKF[4:0] = 01011 - RGB 888 */
1096 case 32: /* PKF[4:0] = 00000 - RGBA 888 */
1097 break;
1098 default:
1099 return -EINVAL;
1100 }
1101
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001102 return 0;
1103}
Phil Edworthy40331b22010-02-15 13:57:49 +00001104
Alexandre Courbot8857b9a2011-02-23 08:36:30 +00001105/*
1106 * Screen blanking. Behavior is as follows:
1107 * FB_BLANK_UNBLANK: screen unblanked, clocks enabled
1108 * FB_BLANK_NORMAL: screen blanked, clocks enabled
1109 * FB_BLANK_VSYNC,
1110 * FB_BLANK_HSYNC,
1111 * FB_BLANK_POWEROFF: screen blanked, clocks disabled
1112 */
1113static int sh_mobile_lcdc_blank(int blank, struct fb_info *info)
1114{
1115 struct sh_mobile_lcdc_chan *ch = info->par;
1116 struct sh_mobile_lcdc_priv *p = ch->lcdc;
1117
1118 /* blank the screen? */
1119 if (blank > FB_BLANK_UNBLANK && ch->blank_status == FB_BLANK_UNBLANK) {
1120 struct fb_fillrect rect = {
1121 .width = info->var.xres,
1122 .height = info->var.yres,
1123 };
1124 sh_mobile_lcdc_fillrect(info, &rect);
1125 }
1126 /* turn clocks on? */
1127 if (blank <= FB_BLANK_NORMAL && ch->blank_status > FB_BLANK_NORMAL) {
1128 sh_mobile_lcdc_clk_on(p);
1129 }
1130 /* turn clocks off? */
1131 if (blank > FB_BLANK_NORMAL && ch->blank_status <= FB_BLANK_NORMAL) {
1132 /* make sure the screen is updated with the black fill before
1133 * switching the clocks off. one vsync is not enough since
1134 * blanking may occur in the middle of a refresh. deferred io
1135 * mode will reenable the clocks and update the screen in time,
1136 * so it does not need this. */
1137 if (!info->fbdefio) {
1138 sh_mobile_wait_for_vsync(info);
1139 sh_mobile_wait_for_vsync(info);
1140 }
1141 sh_mobile_lcdc_clk_off(p);
1142 }
1143
1144 ch->blank_status = blank;
1145 return 0;
1146}
1147
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001148static struct fb_ops sh_mobile_lcdc_ops = {
Phil Edworthy9dd38812009-09-15 12:00:18 +00001149 .owner = THIS_MODULE,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001150 .fb_setcolreg = sh_mobile_lcdc_setcolreg,
Magnus Damm2540c112008-12-17 17:29:49 +09001151 .fb_read = fb_sys_read,
1152 .fb_write = fb_sys_write,
Magnus Damm85645572008-12-19 15:34:41 +09001153 .fb_fillrect = sh_mobile_lcdc_fillrect,
1154 .fb_copyarea = sh_mobile_lcdc_copyarea,
1155 .fb_imageblit = sh_mobile_lcdc_imageblit,
Alexandre Courbot8857b9a2011-02-23 08:36:30 +00001156 .fb_blank = sh_mobile_lcdc_blank,
Phil Edworthy9dd38812009-09-15 12:00:18 +00001157 .fb_pan_display = sh_mobile_fb_pan_display,
Phil Edworthy40331b22010-02-15 13:57:49 +00001158 .fb_ioctl = sh_mobile_ioctl,
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001159 .fb_open = sh_mobile_open,
1160 .fb_release = sh_mobile_release,
1161 .fb_check_var = sh_mobile_check_var,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001162};
1163
Alexandre Courbot3b0fd9d2011-02-16 03:49:01 +00001164static int sh_mobile_lcdc_update_bl(struct backlight_device *bdev)
1165{
1166 struct sh_mobile_lcdc_chan *ch = bl_get_data(bdev);
1167 struct sh_mobile_lcdc_board_cfg *cfg = &ch->cfg.board_cfg;
1168 int brightness = bdev->props.brightness;
1169
1170 if (bdev->props.power != FB_BLANK_UNBLANK ||
1171 bdev->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK))
1172 brightness = 0;
1173
1174 return cfg->set_brightness(cfg->board_data, brightness);
1175}
1176
1177static int sh_mobile_lcdc_get_brightness(struct backlight_device *bdev)
1178{
1179 struct sh_mobile_lcdc_chan *ch = bl_get_data(bdev);
1180 struct sh_mobile_lcdc_board_cfg *cfg = &ch->cfg.board_cfg;
1181
1182 return cfg->get_brightness(cfg->board_data);
1183}
1184
1185static int sh_mobile_lcdc_check_fb(struct backlight_device *bdev,
1186 struct fb_info *info)
1187{
1188 return (info->bl_dev == bdev);
1189}
1190
1191static struct backlight_ops sh_mobile_lcdc_bl_ops = {
1192 .options = BL_CORE_SUSPENDRESUME,
1193 .update_status = sh_mobile_lcdc_update_bl,
1194 .get_brightness = sh_mobile_lcdc_get_brightness,
1195 .check_fb = sh_mobile_lcdc_check_fb,
1196};
1197
1198static struct backlight_device *sh_mobile_lcdc_bl_probe(struct device *parent,
1199 struct sh_mobile_lcdc_chan *ch)
1200{
1201 struct backlight_device *bl;
1202
1203 bl = backlight_device_register(ch->cfg.bl_info.name, parent, ch,
1204 &sh_mobile_lcdc_bl_ops, NULL);
Dan Carpenterbeee1f22011-03-21 15:03:13 +00001205 if (IS_ERR(bl)) {
1206 dev_err(parent, "unable to register backlight device: %ld\n",
1207 PTR_ERR(bl));
Alexandre Courbot3b0fd9d2011-02-16 03:49:01 +00001208 return NULL;
1209 }
1210
1211 bl->props.max_brightness = ch->cfg.bl_info.max_brightness;
1212 bl->props.brightness = bl->props.max_brightness;
1213 backlight_update_status(bl);
1214
1215 return bl;
1216}
1217
1218static void sh_mobile_lcdc_bl_remove(struct backlight_device *bdev)
1219{
1220 backlight_device_unregister(bdev);
1221}
1222
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +00001223static int sh_mobile_lcdc_set_bpp(struct fb_var_screeninfo *var, int bpp,
1224 int nonstd)
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001225{
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +00001226 if (nonstd) {
1227 switch (bpp) {
1228 case 12:
1229 case 16:
1230 case 24:
1231 var->bits_per_pixel = bpp;
1232 var->nonstd = nonstd;
1233 return 0;
1234 default:
1235 return -EINVAL;
1236 }
1237 }
1238
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001239 switch (bpp) {
1240 case 16: /* PKF[4:0] = 00011 - RGB 565 */
1241 var->red.offset = 11;
1242 var->red.length = 5;
1243 var->green.offset = 5;
1244 var->green.length = 6;
1245 var->blue.offset = 0;
1246 var->blue.length = 5;
1247 var->transp.offset = 0;
1248 var->transp.length = 0;
1249 break;
1250
Magnus Damm417d4822011-01-05 10:21:00 +00001251 case 24: /* PKF[4:0] = 01011 - RGB 888 */
1252 var->red.offset = 16;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001253 var->red.length = 8;
Magnus Damm417d4822011-01-05 10:21:00 +00001254 var->green.offset = 8;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001255 var->green.length = 8;
Magnus Damm417d4822011-01-05 10:21:00 +00001256 var->blue.offset = 0;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001257 var->blue.length = 8;
1258 var->transp.offset = 0;
1259 var->transp.length = 0;
1260 break;
Magnus Damm417d4822011-01-05 10:21:00 +00001261
1262 case 32: /* PKF[4:0] = 00000 - RGBA 888 */
1263 var->red.offset = 16;
1264 var->red.length = 8;
1265 var->green.offset = 8;
1266 var->green.length = 8;
1267 var->blue.offset = 0;
1268 var->blue.length = 8;
1269 var->transp.offset = 24;
1270 var->transp.length = 8;
1271 break;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001272 default:
1273 return -EINVAL;
1274 }
1275 var->bits_per_pixel = bpp;
1276 var->red.msb_right = 0;
1277 var->green.msb_right = 0;
1278 var->blue.msb_right = 0;
1279 var->transp.msb_right = 0;
1280 return 0;
1281}
1282
Magnus Damm2feb0752009-03-13 15:36:55 +00001283static int sh_mobile_lcdc_suspend(struct device *dev)
1284{
1285 struct platform_device *pdev = to_platform_device(dev);
1286
1287 sh_mobile_lcdc_stop(platform_get_drvdata(pdev));
1288 return 0;
1289}
1290
1291static int sh_mobile_lcdc_resume(struct device *dev)
1292{
1293 struct platform_device *pdev = to_platform_device(dev);
1294
1295 return sh_mobile_lcdc_start(platform_get_drvdata(pdev));
1296}
1297
Magnus Damm0246c472009-08-14 10:49:08 +00001298static int sh_mobile_lcdc_runtime_suspend(struct device *dev)
1299{
1300 struct platform_device *pdev = to_platform_device(dev);
1301 struct sh_mobile_lcdc_priv *p = platform_get_drvdata(pdev);
1302 struct sh_mobile_lcdc_chan *ch;
1303 int k, n;
1304
1305 /* save per-channel registers */
1306 for (k = 0; k < ARRAY_SIZE(p->ch); k++) {
1307 ch = &p->ch[k];
1308 if (!ch->enabled)
1309 continue;
1310 for (n = 0; n < NR_CH_REGS; n++)
1311 ch->saved_ch_regs[n] = lcdc_read_chan(ch, n);
1312 }
1313
1314 /* save shared registers */
1315 for (n = 0; n < NR_SHARED_REGS; n++)
1316 p->saved_shared_regs[n] = lcdc_read(p, lcdc_shared_regs[n]);
1317
1318 /* turn off LCDC hardware */
1319 lcdc_write(p, _LDCNT1R, 0);
1320 return 0;
1321}
1322
1323static int sh_mobile_lcdc_runtime_resume(struct device *dev)
1324{
1325 struct platform_device *pdev = to_platform_device(dev);
1326 struct sh_mobile_lcdc_priv *p = platform_get_drvdata(pdev);
1327 struct sh_mobile_lcdc_chan *ch;
1328 int k, n;
1329
1330 /* restore per-channel registers */
1331 for (k = 0; k < ARRAY_SIZE(p->ch); k++) {
1332 ch = &p->ch[k];
1333 if (!ch->enabled)
1334 continue;
1335 for (n = 0; n < NR_CH_REGS; n++)
1336 lcdc_write_chan(ch, n, ch->saved_ch_regs[n]);
1337 }
1338
1339 /* restore shared registers */
1340 for (n = 0; n < NR_SHARED_REGS; n++)
1341 lcdc_write(p, lcdc_shared_regs[n], p->saved_shared_regs[n]);
1342
1343 return 0;
1344}
1345
Alexey Dobriyan47145212009-12-14 18:00:08 -08001346static const struct dev_pm_ops sh_mobile_lcdc_dev_pm_ops = {
Magnus Damm2feb0752009-03-13 15:36:55 +00001347 .suspend = sh_mobile_lcdc_suspend,
1348 .resume = sh_mobile_lcdc_resume,
Magnus Damm0246c472009-08-14 10:49:08 +00001349 .runtime_suspend = sh_mobile_lcdc_runtime_suspend,
1350 .runtime_resume = sh_mobile_lcdc_runtime_resume,
Magnus Damm2feb0752009-03-13 15:36:55 +00001351};
1352
Guennadi Liakhovetski6de9edd2010-09-03 07:20:23 +00001353/* locking: called with info->lock held */
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001354static int sh_mobile_lcdc_notify(struct notifier_block *nb,
1355 unsigned long action, void *data)
1356{
1357 struct fb_event *event = data;
1358 struct fb_info *info = event->info;
1359 struct sh_mobile_lcdc_chan *ch = info->par;
1360 struct sh_mobile_lcdc_board_cfg *board_cfg = &ch->cfg.board_cfg;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001361
1362 if (&ch->lcdc->notifier != nb)
Guennadi Liakhovetskibaf16372010-09-03 07:20:08 +00001363 return NOTIFY_DONE;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001364
1365 dev_dbg(info->dev, "%s(): action = %lu, data = %p\n",
1366 __func__, action, event->data);
1367
1368 switch(action) {
1369 case FB_EVENT_SUSPEND:
Alexandre Courbot247f9932011-02-23 08:41:50 +00001370 if (board_cfg->display_off && try_module_get(board_cfg->owner)) {
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001371 board_cfg->display_off(board_cfg->board_data);
Guennadi Liakhovetski6de9edd2010-09-03 07:20:23 +00001372 module_put(board_cfg->owner);
1373 }
Guennadi Liakhovetskiafe417c2010-09-03 07:20:39 +00001374 sh_mobile_lcdc_stop(ch->lcdc);
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001375 break;
1376 case FB_EVENT_RESUME:
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001377 mutex_lock(&ch->open_lock);
1378 sh_mobile_fb_reconfig(info);
1379 mutex_unlock(&ch->open_lock);
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001380
1381 /* HDMI must be enabled before LCDC configuration */
Alexandre Courbot247f9932011-02-23 08:41:50 +00001382 if (board_cfg->display_on && try_module_get(board_cfg->owner)) {
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001383 board_cfg->display_on(board_cfg->board_data, info);
Guennadi Liakhovetski6de9edd2010-09-03 07:20:23 +00001384 module_put(board_cfg->owner);
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001385 }
1386
Guennadi Liakhovetskiebe5e122011-05-05 16:33:40 +00001387 sh_mobile_lcdc_start(ch->lcdc);
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001388 }
1389
Guennadi Liakhovetskibaf16372010-09-03 07:20:08 +00001390 return NOTIFY_OK;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001391}
1392
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001393static int sh_mobile_lcdc_remove(struct platform_device *pdev);
1394
Uwe Kleine-Königc2e13032010-02-04 20:56:51 +01001395static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001396{
1397 struct fb_info *info;
1398 struct sh_mobile_lcdc_priv *priv;
Guennadi Liakhovetski01ac25b52010-09-03 07:20:00 +00001399 struct sh_mobile_lcdc_info *pdata = pdev->dev.platform_data;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001400 struct resource *res;
1401 int error;
1402 void *buf;
1403 int i, j;
1404
Guennadi Liakhovetski01ac25b52010-09-03 07:20:00 +00001405 if (!pdata) {
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001406 dev_err(&pdev->dev, "no platform data defined\n");
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001407 return -EINVAL;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001408 }
1409
1410 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Magnus Damm85645572008-12-19 15:34:41 +09001411 i = platform_get_irq(pdev, 0);
1412 if (!res || i < 0) {
1413 dev_err(&pdev->dev, "cannot get platform resources\n");
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001414 return -ENOENT;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001415 }
1416
1417 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
1418 if (!priv) {
1419 dev_err(&pdev->dev, "cannot allocate device data\n");
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001420 return -ENOMEM;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001421 }
1422
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001423 platform_set_drvdata(pdev, priv);
1424
Magnus Damm85645572008-12-19 15:34:41 +09001425 error = request_irq(i, sh_mobile_lcdc_irq, IRQF_DISABLED,
Kay Sievers7ad33e72009-03-24 16:38:21 -07001426 dev_name(&pdev->dev), priv);
Magnus Damm85645572008-12-19 15:34:41 +09001427 if (error) {
1428 dev_err(&pdev->dev, "unable to request irq\n");
1429 goto err1;
1430 }
1431
1432 priv->irq = i;
Guennadi Liakhovetski5ef6b502010-09-03 07:19:57 +00001433 atomic_set(&priv->hw_usecnt, -1);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001434
1435 j = 0;
1436 for (i = 0; i < ARRAY_SIZE(pdata->ch); i++) {
Guennadi Liakhovetski01ac25b52010-09-03 07:20:00 +00001437 struct sh_mobile_lcdc_chan *ch = priv->ch + j;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001438
Guennadi Liakhovetski01ac25b52010-09-03 07:20:00 +00001439 ch->lcdc = priv;
1440 memcpy(&ch->cfg, &pdata->ch[i], sizeof(pdata->ch[i]));
1441
1442 error = sh_mobile_lcdc_check_interface(ch);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001443 if (error) {
1444 dev_err(&pdev->dev, "unsupported interface type\n");
1445 goto err1;
1446 }
Guennadi Liakhovetski01ac25b52010-09-03 07:20:00 +00001447 init_waitqueue_head(&ch->frame_end_wait);
1448 init_completion(&ch->vsync_completion);
1449 ch->pan_offset = 0;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001450
Alexandre Courbot3b0fd9d2011-02-16 03:49:01 +00001451 /* probe the backlight is there is one defined */
1452 if (ch->cfg.bl_info.max_brightness)
1453 ch->bl = sh_mobile_lcdc_bl_probe(&pdev->dev, ch);
1454
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001455 switch (pdata->ch[i].chan) {
1456 case LCDC_CHAN_MAINLCD:
Laurent Pinchartce1c0b02011-07-13 12:13:47 +02001457 ch->enabled = LDCNT2R_ME;
Guennadi Liakhovetski01ac25b52010-09-03 07:20:00 +00001458 ch->reg_offs = lcdc_offs_mainlcd;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001459 j++;
1460 break;
1461 case LCDC_CHAN_SUBLCD:
Laurent Pinchartce1c0b02011-07-13 12:13:47 +02001462 ch->enabled = LDCNT2R_SE;
Guennadi Liakhovetski01ac25b52010-09-03 07:20:00 +00001463 ch->reg_offs = lcdc_offs_sublcd;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001464 j++;
1465 break;
1466 }
1467 }
1468
1469 if (!j) {
1470 dev_err(&pdev->dev, "no channels defined\n");
1471 error = -EINVAL;
1472 goto err1;
1473 }
1474
Magnus Damm417d4822011-01-05 10:21:00 +00001475 /* for dual channel LCDC (MAIN + SUB) force shared bpp setting */
1476 if (j == 2)
1477 priv->forced_bpp = pdata->ch[0].bpp;
1478
Guennadi Liakhovetskidba6f382010-06-30 09:26:35 +00001479 priv->base = ioremap_nocache(res->start, resource_size(res));
1480 if (!priv->base)
1481 goto err1;
1482
Magnus Dammb51339f2008-10-31 20:23:26 +09001483 error = sh_mobile_lcdc_setup_clocks(pdev, pdata->clock_source, priv);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001484 if (error) {
1485 dev_err(&pdev->dev, "unable to setup clocks\n");
1486 goto err1;
1487 }
1488
Damian7caa4342011-05-18 11:10:07 +00001489 priv->meram_dev = pdata->meram_dev;
1490
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001491 for (i = 0; i < j; i++) {
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001492 struct fb_var_screeninfo *var;
Guennadi Liakhovetski71d3b0f2010-09-03 07:20:12 +00001493 const struct fb_videomode *lcd_cfg, *max_cfg = NULL;
Guennadi Liakhovetski01ac25b52010-09-03 07:20:00 +00001494 struct sh_mobile_lcdc_chan *ch = priv->ch + i;
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001495 struct sh_mobile_lcdc_chan_cfg *cfg = &ch->cfg;
1496 const struct fb_videomode *mode = cfg->lcd_cfg;
Guennadi Liakhovetski71d3b0f2010-09-03 07:20:12 +00001497 unsigned long max_size = 0;
1498 int k;
Guennadi Liakhovetski5fd284e2010-11-04 11:06:11 +00001499 int num_cfg;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001500
Guennadi Liakhovetski01ac25b52010-09-03 07:20:00 +00001501 ch->info = framebuffer_alloc(0, &pdev->dev);
1502 if (!ch->info) {
Paul Mundte33afdd2009-07-07 11:24:32 +09001503 dev_err(&pdev->dev, "unable to allocate fb_info\n");
1504 error = -ENOMEM;
1505 break;
1506 }
1507
Guennadi Liakhovetski01ac25b52010-09-03 07:20:00 +00001508 info = ch->info;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001509 var = &info->var;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001510 info->fbops = &sh_mobile_lcdc_ops;
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001511 info->par = ch;
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001512
1513 mutex_init(&ch->open_lock);
1514
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001515 for (k = 0, lcd_cfg = mode;
1516 k < cfg->num_cfg && lcd_cfg;
Guennadi Liakhovetski71d3b0f2010-09-03 07:20:12 +00001517 k++, lcd_cfg++) {
1518 unsigned long size = lcd_cfg->yres * lcd_cfg->xres;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +00001519 /* NV12 buffers must have even number of lines */
1520 if ((cfg->nonstd) && cfg->bpp == 12 &&
1521 (lcd_cfg->yres & 0x1)) {
1522 dev_err(&pdev->dev, "yres must be multiple of 2"
1523 " for YCbCr420 mode.\n");
1524 error = -EINVAL;
1525 goto err1;
1526 }
Guennadi Liakhovetski71d3b0f2010-09-03 07:20:12 +00001527
1528 if (size > max_size) {
1529 max_cfg = lcd_cfg;
1530 max_size = size;
1531 }
1532 }
1533
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001534 if (!mode)
Guennadi Liakhovetskid2ecbab2010-11-04 11:06:06 +00001535 max_size = MAX_XRES * MAX_YRES;
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001536 else if (max_cfg)
1537 dev_dbg(&pdev->dev, "Found largest videomode %ux%u\n",
1538 max_cfg->xres, max_cfg->yres);
Guennadi Liakhovetski71d3b0f2010-09-03 07:20:12 +00001539
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001540 info->fix = sh_mobile_lcdc_fix;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +00001541 info->fix.smem_len = max_size * 2 * cfg->bpp / 8;
1542
1543 /* Only pan in 2 line steps for NV12 */
1544 if (cfg->nonstd && cfg->bpp == 12)
1545 info->fix.ypanstep = 2;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001546
Guennadi Liakhovetski5fd284e2010-11-04 11:06:11 +00001547 if (!mode) {
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001548 mode = &default_720p;
Guennadi Liakhovetski5fd284e2010-11-04 11:06:11 +00001549 num_cfg = 1;
1550 } else {
Guennadi Liakhovetskie0b9fb22010-12-21 11:46:26 +01001551 num_cfg = cfg->num_cfg;
Guennadi Liakhovetski5fd284e2010-11-04 11:06:11 +00001552 }
1553
1554 fb_videomode_to_modelist(mode, num_cfg, &info->modelist);
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001555
1556 fb_videomode_to_var(var, mode);
Guennadi Liakhovetskie0b9fb22010-12-21 11:46:26 +01001557 var->width = cfg->lcd_size_cfg.width;
1558 var->height = cfg->lcd_size_cfg.height;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001559 /* Default Y virtual resolution is 2x panel size */
1560 var->yres_virtual = var->yres * 2;
Paul Mundt1c6a3072009-07-01 06:50:31 +00001561 var->activate = FB_ACTIVATE_NOW;
Paul Mundt1c6a3072009-07-01 06:50:31 +00001562
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +00001563 error = sh_mobile_lcdc_set_bpp(var, cfg->bpp, cfg->nonstd);
Paul Mundt1c6a3072009-07-01 06:50:31 +00001564 if (error)
1565 break;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001566
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001567 buf = dma_alloc_coherent(&pdev->dev, info->fix.smem_len,
Guennadi Liakhovetski01ac25b52010-09-03 07:20:00 +00001568 &ch->dma_handle, GFP_KERNEL);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001569 if (!buf) {
1570 dev_err(&pdev->dev, "unable to allocate buffer\n");
1571 error = -ENOMEM;
1572 break;
1573 }
1574
Guennadi Liakhovetski01ac25b52010-09-03 07:20:00 +00001575 info->pseudo_palette = &ch->pseudo_palette;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001576 info->flags = FBINFO_FLAG_DEFAULT;
1577
1578 error = fb_alloc_cmap(&info->cmap, PALETTE_NR, 0);
1579 if (error < 0) {
1580 dev_err(&pdev->dev, "unable to allocate cmap\n");
1581 dma_free_coherent(&pdev->dev, info->fix.smem_len,
Guennadi Liakhovetski01ac25b52010-09-03 07:20:00 +00001582 buf, ch->dma_handle);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001583 break;
1584 }
1585
Guennadi Liakhovetski01ac25b52010-09-03 07:20:00 +00001586 info->fix.smem_start = ch->dma_handle;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +00001587 if (var->nonstd)
1588 info->fix.line_length = var->xres;
1589 else
1590 info->fix.line_length = var->xres * (cfg->bpp / 8);
1591
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001592 info->screen_base = buf;
1593 info->device = &pdev->dev;
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +00001594 ch->display_var = *var;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001595 }
1596
1597 if (error)
1598 goto err1;
1599
1600 error = sh_mobile_lcdc_start(priv);
1601 if (error) {
1602 dev_err(&pdev->dev, "unable to start hardware\n");
1603 goto err1;
1604 }
1605
1606 for (i = 0; i < j; i++) {
1607 struct sh_mobile_lcdc_chan *ch = priv->ch + i;
1608
1609 info = ch->info;
1610
1611 if (info->fbdefio) {
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001612 ch->sglist = vmalloc(sizeof(struct scatterlist) *
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001613 info->fix.smem_len >> PAGE_SHIFT);
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001614 if (!ch->sglist) {
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001615 dev_err(&pdev->dev, "cannot allocate sglist\n");
1616 goto err1;
1617 }
1618 }
1619
Alexandre Courbot3b0fd9d2011-02-16 03:49:01 +00001620 info->bl_dev = ch->bl;
1621
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001622 error = register_framebuffer(info);
1623 if (error < 0)
1624 goto err1;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001625
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001626 dev_info(info->dev,
1627 "registered %s/%s as %dx%d %dbpp.\n",
1628 pdev->name,
Paul Mundt1c6a3072009-07-01 06:50:31 +00001629 (ch->cfg.chan == LCDC_CHAN_MAINLCD) ?
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001630 "mainlcd" : "sublcd",
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001631 info->var.xres, info->var.yres,
Paul Mundt1c6a3072009-07-01 06:50:31 +00001632 ch->cfg.bpp);
Magnus Damm85645572008-12-19 15:34:41 +09001633
1634 /* deferred io mode: disable clock to save power */
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001635 if (info->fbdefio || info->state == FBINFO_STATE_SUSPENDED)
Magnus Damm85645572008-12-19 15:34:41 +09001636 sh_mobile_lcdc_clk_off(priv);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001637 }
1638
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001639 /* Failure ignored */
1640 priv->notifier.notifier_call = sh_mobile_lcdc_notify;
1641 fb_register_client(&priv->notifier);
1642
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001643 return 0;
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001644err1:
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001645 sh_mobile_lcdc_remove(pdev);
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001646
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001647 return error;
1648}
1649
1650static int sh_mobile_lcdc_remove(struct platform_device *pdev)
1651{
1652 struct sh_mobile_lcdc_priv *priv = platform_get_drvdata(pdev);
1653 struct fb_info *info;
1654 int i;
1655
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001656 fb_unregister_client(&priv->notifier);
1657
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001658 for (i = 0; i < ARRAY_SIZE(priv->ch); i++)
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001659 if (priv->ch[i].info && priv->ch[i].info->dev)
Paul Mundte33afdd2009-07-07 11:24:32 +09001660 unregister_framebuffer(priv->ch[i].info);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001661
1662 sh_mobile_lcdc_stop(priv);
1663
1664 for (i = 0; i < ARRAY_SIZE(priv->ch); i++) {
Paul Mundte33afdd2009-07-07 11:24:32 +09001665 info = priv->ch[i].info;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001666
Paul Mundte33afdd2009-07-07 11:24:32 +09001667 if (!info || !info->device)
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001668 continue;
1669
Paul Mundt1c6a3072009-07-01 06:50:31 +00001670 if (priv->ch[i].sglist)
1671 vfree(priv->ch[i].sglist);
1672
Magnus Damm1ffbb032010-10-13 07:17:45 +00001673 if (info->screen_base)
1674 dma_free_coherent(&pdev->dev, info->fix.smem_len,
1675 info->screen_base,
1676 priv->ch[i].dma_handle);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001677 fb_dealloc_cmap(&info->cmap);
Paul Mundte33afdd2009-07-07 11:24:32 +09001678 framebuffer_release(info);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001679 }
1680
Alexandre Courbot3b0fd9d2011-02-16 03:49:01 +00001681 for (i = 0; i < ARRAY_SIZE(priv->ch); i++) {
1682 if (priv->ch[i].bl)
1683 sh_mobile_lcdc_bl_remove(priv->ch[i].bl);
1684 }
1685
Magnus Dammb51339f2008-10-31 20:23:26 +09001686 if (priv->dot_clk)
1687 clk_put(priv->dot_clk);
Magnus Damm0246c472009-08-14 10:49:08 +00001688
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001689 if (priv->dev)
1690 pm_runtime_disable(priv->dev);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001691
1692 if (priv->base)
1693 iounmap(priv->base);
1694
Magnus Damm85645572008-12-19 15:34:41 +09001695 if (priv->irq)
1696 free_irq(priv->irq, priv);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001697 kfree(priv);
1698 return 0;
1699}
1700
1701static struct platform_driver sh_mobile_lcdc_driver = {
1702 .driver = {
1703 .name = "sh_mobile_lcdc_fb",
1704 .owner = THIS_MODULE,
Magnus Damm2feb0752009-03-13 15:36:55 +00001705 .pm = &sh_mobile_lcdc_dev_pm_ops,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001706 },
1707 .probe = sh_mobile_lcdc_probe,
1708 .remove = sh_mobile_lcdc_remove,
1709};
1710
1711static int __init sh_mobile_lcdc_init(void)
1712{
1713 return platform_driver_register(&sh_mobile_lcdc_driver);
1714}
1715
1716static void __exit sh_mobile_lcdc_exit(void)
1717{
1718 platform_driver_unregister(&sh_mobile_lcdc_driver);
1719}
1720
1721module_init(sh_mobile_lcdc_init);
1722module_exit(sh_mobile_lcdc_exit);
1723
1724MODULE_DESCRIPTION("SuperH Mobile LCDC Framebuffer driver");
1725MODULE_AUTHOR("Magnus Damm <damm@opensource.se>");
1726MODULE_LICENSE("GPL v2");