blob: 84504d5749860a6473b3f07d08e57aad96dc1fd4 [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;
Magnus Damm85645572008-12-19 15:34:41 +0900321 unsigned long tmp;
Phil Edworthy9dd38812009-09-15 12:00:18 +0000322 unsigned long ldintr;
Magnus Damm2feb0752009-03-13 15:36:55 +0000323 int is_sub;
324 int k;
Magnus Damm85645572008-12-19 15:34:41 +0900325
326 /* acknowledge interrupt */
Phil Edworthy9dd38812009-09-15 12:00:18 +0000327 ldintr = tmp = lcdc_read(priv, _LDINTR);
328 /*
329 * disable further VSYNC End IRQs, preserve all other enabled IRQs,
330 * write 0 to bits 0-6 to ack all triggered IRQs.
331 */
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200332 tmp &= ~LDINTR_STATUS_MASK & ~LDINTR_VEE;
Magnus Damm85645572008-12-19 15:34:41 +0900333 lcdc_write(priv, _LDINTR, tmp);
334
Magnus Damm2feb0752009-03-13 15:36:55 +0000335 /* figure out if this interrupt is for main or sub lcd */
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200336 is_sub = (lcdc_read(priv, _LDSR) & LDSR_MSS) ? 1 : 0;
Magnus Damm2feb0752009-03-13 15:36:55 +0000337
Phil Edworthy9dd38812009-09-15 12:00:18 +0000338 /* wake up channel and disable clocks */
Magnus Damm2feb0752009-03-13 15:36:55 +0000339 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
340 ch = &priv->ch[k];
341
342 if (!ch->enabled)
343 continue;
344
Phil Edworthy9dd38812009-09-15 12:00:18 +0000345 /* Frame Start */
346 if (ldintr & LDINTR_FS) {
347 if (is_sub == lcdc_chan_is_sublcd(ch)) {
348 ch->frame_end = 1;
349 wake_up(&ch->frame_end_wait);
Magnus Damm2feb0752009-03-13 15:36:55 +0000350
Phil Edworthy9dd38812009-09-15 12:00:18 +0000351 sh_mobile_lcdc_clk_off(priv);
352 }
353 }
354
355 /* VSYNC End */
Phil Edworthy40331b22010-02-15 13:57:49 +0000356 if (ldintr & LDINTR_VES)
357 complete(&ch->vsync_completion);
Magnus Damm2feb0752009-03-13 15:36:55 +0000358 }
359
Magnus Damm85645572008-12-19 15:34:41 +0900360 return IRQ_HANDLED;
361}
362
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700363static void sh_mobile_lcdc_start_stop(struct sh_mobile_lcdc_priv *priv,
364 int start)
365{
366 unsigned long tmp = lcdc_read(priv, _LDCNT2R);
367 int k;
368
369 /* start or stop the lcdc */
370 if (start)
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200371 lcdc_write(priv, _LDCNT2R, tmp | LDCNT2R_DO);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700372 else
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200373 lcdc_write(priv, _LDCNT2R, tmp & ~LDCNT2R_DO);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700374
375 /* wait until power is applied/stopped on all channels */
376 for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
377 if (lcdc_read(priv, _LDCNT2R) & priv->ch[k].enabled)
378 while (1) {
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200379 tmp = lcdc_read_chan(&priv->ch[k], LDPMR)
380 & LDPMR_LPS;
381 if (start && tmp == LDPMR_LPS)
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700382 break;
383 if (!start && tmp == 0)
384 break;
385 cpu_relax();
386 }
387
388 if (!start)
389 lcdc_write(priv, _LDDCKSTPR, 1); /* stop dotclock */
390}
391
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000392static void sh_mobile_lcdc_geometry(struct sh_mobile_lcdc_chan *ch)
393{
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000394 struct fb_var_screeninfo *var = &ch->info->var, *display_var = &ch->display_var;
395 unsigned long h_total, hsync_pos, display_h_total;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000396 u32 tmp;
397
398 tmp = ch->ldmt1r_value;
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200399 tmp |= (var->sync & FB_SYNC_VERT_HIGH_ACT) ? 0 : LDMT1R_VPOL;
400 tmp |= (var->sync & FB_SYNC_HOR_HIGH_ACT) ? 0 : LDMT1R_HPOL;
401 tmp |= (ch->cfg.flags & LCDC_FLAGS_DWPOL) ? LDMT1R_DWPOL : 0;
402 tmp |= (ch->cfg.flags & LCDC_FLAGS_DIPOL) ? LDMT1R_DIPOL : 0;
403 tmp |= (ch->cfg.flags & LCDC_FLAGS_DAPOL) ? LDMT1R_DAPOL : 0;
404 tmp |= (ch->cfg.flags & LCDC_FLAGS_HSCNT) ? LDMT1R_HSCNT : 0;
405 tmp |= (ch->cfg.flags & LCDC_FLAGS_DWCNT) ? LDMT1R_DWCNT : 0;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000406 lcdc_write_chan(ch, LDMT1R, tmp);
407
408 /* setup SYS bus */
409 lcdc_write_chan(ch, LDMT2R, ch->cfg.sys_bus_cfg.ldmt2r);
410 lcdc_write_chan(ch, LDMT3R, ch->cfg.sys_bus_cfg.ldmt3r);
411
412 /* horizontal configuration */
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000413 h_total = display_var->xres + display_var->hsync_len +
414 display_var->left_margin + display_var->right_margin;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000415 tmp = h_total / 8; /* HTCN */
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000416 tmp |= (min(display_var->xres, var->xres) / 8) << 16; /* HDCN */
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000417 lcdc_write_chan(ch, LDHCNR, tmp);
418
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000419 hsync_pos = display_var->xres + display_var->right_margin;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000420 tmp = hsync_pos / 8; /* HSYNP */
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000421 tmp |= (display_var->hsync_len / 8) << 16; /* HSYNW */
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000422 lcdc_write_chan(ch, LDHSYNR, tmp);
423
424 /* vertical configuration */
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000425 tmp = display_var->yres + display_var->vsync_len +
426 display_var->upper_margin + display_var->lower_margin; /* VTLN */
427 tmp |= min(display_var->yres, var->yres) << 16; /* VDLN */
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000428 lcdc_write_chan(ch, LDVLNR, tmp);
429
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000430 tmp = display_var->yres + display_var->lower_margin; /* VSYNP */
431 tmp |= display_var->vsync_len << 16; /* VSYNW */
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000432 lcdc_write_chan(ch, LDVSYNR, tmp);
433
434 /* Adjust horizontal synchronisation for HDMI */
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000435 display_h_total = display_var->xres + display_var->hsync_len +
436 display_var->left_margin + display_var->right_margin;
437 tmp = ((display_var->xres & 7) << 24) |
438 ((display_h_total & 7) << 16) |
439 ((display_var->hsync_len & 7) << 8) |
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000440 hsync_pos;
441 lcdc_write_chan(ch, LDHAJR, tmp);
442}
443
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700444static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv)
445{
446 struct sh_mobile_lcdc_chan *ch;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700447 struct sh_mobile_lcdc_board_cfg *board_cfg;
448 unsigned long tmp;
Magnus Damm417d4822011-01-05 10:21:00 +0000449 int bpp = 0;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000450 unsigned long ldddsr;
Paul Mundt554cc102011-05-26 15:01:22 +0900451 int k, m, ret;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700452
Magnus Damm85645572008-12-19 15:34:41 +0900453 /* enable clocks before accessing the hardware */
Magnus Damm417d4822011-01-05 10:21:00 +0000454 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
455 if (priv->ch[k].enabled) {
Magnus Damm85645572008-12-19 15:34:41 +0900456 sh_mobile_lcdc_clk_on(priv);
Magnus Damm417d4822011-01-05 10:21:00 +0000457 if (!bpp)
458 bpp = priv->ch[k].info->var.bits_per_pixel;
459 }
460 }
Magnus Damm85645572008-12-19 15:34:41 +0900461
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700462 /* reset */
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200463 lcdc_write(priv, _LDCNT2R, lcdc_read(priv, _LDCNT2R) | LDCNT2R_BR);
464 lcdc_wait_bit(priv, _LDCNT2R, LDCNT2R_BR, 0);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700465
466 /* enable LCDC channels */
467 tmp = lcdc_read(priv, _LDCNT2R);
468 tmp |= priv->ch[0].enabled;
469 tmp |= priv->ch[1].enabled;
470 lcdc_write(priv, _LDCNT2R, tmp);
471
472 /* read data from external memory, avoid using the BEU for now */
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200473 lcdc_write(priv, _LDCNT2R, lcdc_read(priv, _LDCNT2R) & ~LDCNT2R_MD);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700474
475 /* stop the lcdc first */
476 sh_mobile_lcdc_start_stop(priv, 0);
477
478 /* configure clocks */
479 tmp = priv->lddckr;
480 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
481 ch = &priv->ch[k];
482
483 if (!priv->ch[k].enabled)
484 continue;
485
486 m = ch->cfg.clock_divider;
487 if (!m)
488 continue;
489
490 if (m == 1)
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200491 m = LDDCKR_MOSEL;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700492 tmp |= m << (lcdc_chan_is_sublcd(ch) ? 8 : 0);
493
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +0000494 /* FIXME: sh7724 can only use 42, 48, 54 and 60 for the divider denominator */
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000495 lcdc_write_chan(ch, LDDCKPAT1R, 0);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700496 lcdc_write_chan(ch, LDDCKPAT2R, (1 << (m/2)) - 1);
497 }
498
499 lcdc_write(priv, _LDDCKR, tmp);
500
501 /* start dotclock again */
502 lcdc_write(priv, _LDDCKSTPR, 0);
503 lcdc_wait_bit(priv, _LDDCKSTPR, ~0, 0);
504
Magnus Damm85645572008-12-19 15:34:41 +0900505 /* interrupts are disabled to begin with */
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700506 lcdc_write(priv, _LDINTR, 0);
507
508 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
509 ch = &priv->ch[k];
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700510
511 if (!ch->enabled)
512 continue;
513
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000514 sh_mobile_lcdc_geometry(ch);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700515
516 /* power supply */
517 lcdc_write_chan(ch, LDPMR, 0);
518
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700519 board_cfg = &ch->cfg.board_cfg;
Guennadi Liakhovetski69843ba2011-05-05 16:32:36 +0000520 if (board_cfg->setup_sys) {
Paul Mundt554cc102011-05-26 15:01:22 +0900521 ret = board_cfg->setup_sys(board_cfg->board_data,
Guennadi Liakhovetski69843ba2011-05-05 16:32:36 +0000522 ch, &sh_mobile_lcdc_sys_bus_ops);
523 if (ret)
524 return ret;
525 }
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700526 }
527
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700528 /* word and long word swap */
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000529 ldddsr = lcdc_read(priv, _LDDDSR);
530 if (priv->ch[0].info->var.nonstd)
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200531 ldddsr |= LDDDSR_LS | LDDDSR_WS | LDDDSR_BS;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000532 else {
533 switch (bpp) {
534 case 16:
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200535 ldddsr |= LDDDSR_LS | LDDDSR_WS;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000536 break;
537 case 24:
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200538 ldddsr |= LDDDSR_LS | LDDDSR_WS | LDDDSR_BS;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000539 break;
540 case 32:
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200541 ldddsr |= LDDDSR_LS;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000542 break;
543 }
Magnus Damm417d4822011-01-05 10:21:00 +0000544 }
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200545 lcdc_write(priv, _LDDDSR, ldddsr);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700546
547 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
Damian7caa4342011-05-18 11:10:07 +0000548 unsigned long base_addr_y;
549 unsigned long base_addr_c = 0;
550 int pitch;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700551 ch = &priv->ch[k];
552
553 if (!priv->ch[k].enabled)
554 continue;
555
556 /* set bpp format in PKF[4:0] */
557 tmp = lcdc_read_chan(ch, LDDFR);
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200558 tmp &= ~(LDDFR_CF0 | LDDFR_CC | LDDFR_YF_MASK | LDDFR_PKF_MASK);
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000559 if (ch->info->var.nonstd) {
560 tmp |= (ch->info->var.nonstd << 16);
561 switch (ch->info->var.bits_per_pixel) {
562 case 12:
563 break;
564 case 16:
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200565 tmp |= LDDFR_YF_422;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000566 break;
567 case 24:
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200568 tmp |= LDDFR_YF_444;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000569 break;
570 }
571 } else {
572 switch (ch->info->var.bits_per_pixel) {
573 case 16:
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200574 tmp |= LDDFR_PKF_RGB16;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000575 break;
576 case 24:
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200577 tmp |= LDDFR_PKF_RGB24;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000578 break;
579 case 32:
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200580 tmp |= LDDFR_PKF_ARGB32;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000581 break;
582 }
Magnus Damm417d4822011-01-05 10:21:00 +0000583 }
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700584 lcdc_write_chan(ch, LDDFR, tmp);
585
Damian7caa4342011-05-18 11:10:07 +0000586 base_addr_y = ch->info->fix.smem_start;
587 base_addr_c = base_addr_y +
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000588 ch->info->var.xres *
Damian7caa4342011-05-18 11:10:07 +0000589 ch->info->var.yres_virtual;
590 pitch = ch->info->fix.line_length;
591
592 /* test if we can enable meram */
Damianeae9b852011-05-24 07:01:21 +0000593 if (ch->cfg.meram_cfg && priv->meram_dev &&
594 priv->meram_dev->ops) {
Damian7caa4342011-05-18 11:10:07 +0000595 struct sh_mobile_meram_cfg *cfg;
596 struct sh_mobile_meram_info *mdev;
597 unsigned long icb_addr_y, icb_addr_c;
598 int icb_pitch;
599 int pf;
600
601 cfg = ch->cfg.meram_cfg;
602 mdev = priv->meram_dev;
603 /* we need to de-init configured ICBs before we
604 * we can re-initialize them.
605 */
606 if (ch->meram_enabled)
607 mdev->ops->meram_unregister(mdev, cfg);
608
609 ch->meram_enabled = 0;
610
Damian3fedd2a2011-05-18 11:10:08 +0000611 if (ch->info->var.nonstd) {
612 if (ch->info->var.bits_per_pixel == 24)
613 pf = SH_MOBILE_MERAM_PF_NV24;
614 else
615 pf = SH_MOBILE_MERAM_PF_NV;
616 } else {
Damian7caa4342011-05-18 11:10:07 +0000617 pf = SH_MOBILE_MERAM_PF_RGB;
Damian3fedd2a2011-05-18 11:10:08 +0000618 }
Damian7caa4342011-05-18 11:10:07 +0000619
620 ret = mdev->ops->meram_register(mdev, cfg, pitch,
621 ch->info->var.yres,
622 pf,
623 base_addr_y,
624 base_addr_c,
625 &icb_addr_y,
626 &icb_addr_c,
627 &icb_pitch);
628 if (!ret) {
629 /* set LDSA1R value */
630 base_addr_y = icb_addr_y;
631 pitch = icb_pitch;
632
633 /* set LDSA2R value if required */
634 if (base_addr_c)
635 base_addr_c = icb_addr_c;
636
637 ch->meram_enabled = 1;
638 }
639 }
640
641 /* point out our frame buffer */
642 lcdc_write_chan(ch, LDSA1R, base_addr_y);
643 if (ch->info->var.nonstd)
644 lcdc_write_chan(ch, LDSA2R, base_addr_c);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700645
646 /* set line size */
Damian7caa4342011-05-18 11:10:07 +0000647 lcdc_write_chan(ch, LDMLSR, pitch);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700648
Magnus Damm85645572008-12-19 15:34:41 +0900649 /* setup deferred io if SYS bus */
650 tmp = ch->cfg.sys_bus_cfg.deferred_io_msec;
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200651 if (ch->ldmt1r_value & LDMT1R_IFM && tmp) {
Magnus Damm85645572008-12-19 15:34:41 +0900652 ch->defio.deferred_io = sh_mobile_lcdc_deferred_io;
653 ch->defio.delay = msecs_to_jiffies(tmp);
Paul Mundte33afdd2009-07-07 11:24:32 +0900654 ch->info->fbdefio = &ch->defio;
655 fb_deferred_io_init(ch->info);
Magnus Damm85645572008-12-19 15:34:41 +0900656
657 /* one-shot mode */
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200658 lcdc_write_chan(ch, LDSM1R, LDSM1R_OS);
Magnus Damm85645572008-12-19 15:34:41 +0900659
660 /* enable "Frame End Interrupt Enable" bit */
661 lcdc_write(priv, _LDINTR, LDINTR_FE);
662
663 } else {
664 /* continuous read mode */
665 lcdc_write_chan(ch, LDSM1R, 0);
666 }
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700667 }
668
669 /* display output */
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200670 lcdc_write(priv, _LDCNT1R, LDCNT1R_DE);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700671
672 /* start the lcdc */
673 sh_mobile_lcdc_start_stop(priv, 1);
Magnus Damm8e9bb192009-05-20 14:34:43 +0000674 priv->started = 1;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700675
676 /* tell the board code to enable the panel */
677 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
678 ch = &priv->ch[k];
Magnus Damm21bc1f02009-08-15 02:53:16 +0000679 if (!ch->enabled)
680 continue;
681
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700682 board_cfg = &ch->cfg.board_cfg;
Alexandre Courbot247f9932011-02-23 08:41:50 +0000683 if (board_cfg->display_on && try_module_get(board_cfg->owner)) {
Guennadi Liakhovetskic2439392010-07-21 10:13:17 +0000684 board_cfg->display_on(board_cfg->board_data, ch->info);
Guennadi Liakhovetski6de9edd2010-09-03 07:20:23 +0000685 module_put(board_cfg->owner);
686 }
Alexandre Courbot3b0fd9d2011-02-16 03:49:01 +0000687
688 if (ch->bl) {
689 ch->bl->props.power = FB_BLANK_UNBLANK;
690 backlight_update_status(ch->bl);
691 }
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700692 }
693
694 return 0;
695}
696
697static void sh_mobile_lcdc_stop(struct sh_mobile_lcdc_priv *priv)
698{
699 struct sh_mobile_lcdc_chan *ch;
700 struct sh_mobile_lcdc_board_cfg *board_cfg;
701 int k;
702
Magnus Damm2feb0752009-03-13 15:36:55 +0000703 /* clean up deferred io and ask board code to disable panel */
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700704 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
705 ch = &priv->ch[k];
Magnus Damm21bc1f02009-08-15 02:53:16 +0000706 if (!ch->enabled)
707 continue;
Magnus Damm2feb0752009-03-13 15:36:55 +0000708
709 /* deferred io mode:
710 * flush frame, and wait for frame end interrupt
711 * clean up deferred io and enable clock
712 */
Guennadi Liakhovetski5ef6b502010-09-03 07:19:57 +0000713 if (ch->info && ch->info->fbdefio) {
Magnus Damm2feb0752009-03-13 15:36:55 +0000714 ch->frame_end = 0;
Paul Mundte33afdd2009-07-07 11:24:32 +0900715 schedule_delayed_work(&ch->info->deferred_work, 0);
Magnus Damm2feb0752009-03-13 15:36:55 +0000716 wait_event(ch->frame_end_wait, ch->frame_end);
Paul Mundte33afdd2009-07-07 11:24:32 +0900717 fb_deferred_io_cleanup(ch->info);
718 ch->info->fbdefio = NULL;
Magnus Damm2feb0752009-03-13 15:36:55 +0000719 sh_mobile_lcdc_clk_on(priv);
720 }
721
Alexandre Courbot3b0fd9d2011-02-16 03:49:01 +0000722 if (ch->bl) {
723 ch->bl->props.power = FB_BLANK_POWERDOWN;
724 backlight_update_status(ch->bl);
725 }
726
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700727 board_cfg = &ch->cfg.board_cfg;
Alexandre Courbot247f9932011-02-23 08:41:50 +0000728 if (board_cfg->display_off && try_module_get(board_cfg->owner)) {
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700729 board_cfg->display_off(board_cfg->board_data);
Guennadi Liakhovetski6de9edd2010-09-03 07:20:23 +0000730 module_put(board_cfg->owner);
731 }
Damian7caa4342011-05-18 11:10:07 +0000732
733 /* disable the meram */
734 if (ch->meram_enabled) {
735 struct sh_mobile_meram_cfg *cfg;
736 struct sh_mobile_meram_info *mdev;
737 cfg = ch->cfg.meram_cfg;
738 mdev = priv->meram_dev;
739 mdev->ops->meram_unregister(mdev, cfg);
740 ch->meram_enabled = 0;
741 }
742
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700743 }
744
745 /* stop the lcdc */
Magnus Damm8e9bb192009-05-20 14:34:43 +0000746 if (priv->started) {
747 sh_mobile_lcdc_start_stop(priv, 0);
748 priv->started = 0;
749 }
Magnus Dammb51339f2008-10-31 20:23:26 +0900750
Magnus Damm85645572008-12-19 15:34:41 +0900751 /* stop clocks */
752 for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
753 if (priv->ch[k].enabled)
754 sh_mobile_lcdc_clk_off(priv);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700755}
756
757static int sh_mobile_lcdc_check_interface(struct sh_mobile_lcdc_chan *ch)
758{
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200759 int interface_type = ch->cfg.interface_type;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700760
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200761 switch (interface_type) {
762 case RGB8:
763 case RGB9:
764 case RGB12A:
765 case RGB12B:
766 case RGB16:
767 case RGB18:
768 case RGB24:
769 case SYS8A:
770 case SYS8B:
771 case SYS8C:
772 case SYS8D:
773 case SYS9:
774 case SYS12:
775 case SYS16A:
776 case SYS16B:
777 case SYS16C:
778 case SYS18:
779 case SYS24:
780 break;
781 default:
782 return -EINVAL;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700783 }
784
785 /* SUBLCD only supports SYS interface */
786 if (lcdc_chan_is_sublcd(ch)) {
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200787 if (!(interface_type & LDMT1R_IFM))
788 return -EINVAL;
789
790 interface_type &= ~LDMT1R_IFM;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700791 }
792
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200793 ch->ldmt1r_value = interface_type;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700794 return 0;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700795}
796
Magnus Dammb51339f2008-10-31 20:23:26 +0900797static int sh_mobile_lcdc_setup_clocks(struct platform_device *pdev,
798 int clock_source,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700799 struct sh_mobile_lcdc_priv *priv)
800{
801 char *str;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700802
803 switch (clock_source) {
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200804 case LCDC_CLK_BUS:
805 str = "bus_clk";
806 priv->lddckr = LDDCKR_ICKSEL_BUS;
807 break;
808 case LCDC_CLK_PERIPHERAL:
809 str = "peripheral_clk";
810 priv->lddckr = LDDCKR_ICKSEL_MIPI;
811 break;
812 case LCDC_CLK_EXTERNAL:
813 str = NULL;
814 priv->lddckr = LDDCKR_ICKSEL_HDMI;
815 break;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700816 default:
817 return -EINVAL;
818 }
819
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700820 if (str) {
Magnus Dammb51339f2008-10-31 20:23:26 +0900821 priv->dot_clk = clk_get(&pdev->dev, str);
822 if (IS_ERR(priv->dot_clk)) {
823 dev_err(&pdev->dev, "cannot get dot clock %s\n", str);
Magnus Dammb51339f2008-10-31 20:23:26 +0900824 return PTR_ERR(priv->dot_clk);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700825 }
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700826 }
827
Magnus Damm0246c472009-08-14 10:49:08 +0000828 /* Runtime PM support involves two step for this driver:
829 * 1) Enable Runtime PM
830 * 2) Force Runtime PM Resume since hardware is accessed from probe()
831 */
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +0000832 priv->dev = &pdev->dev;
Magnus Damm0246c472009-08-14 10:49:08 +0000833 pm_runtime_enable(priv->dev);
834 pm_runtime_resume(priv->dev);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700835 return 0;
836}
837
838static int sh_mobile_lcdc_setcolreg(u_int regno,
839 u_int red, u_int green, u_int blue,
840 u_int transp, struct fb_info *info)
841{
842 u32 *palette = info->pseudo_palette;
843
844 if (regno >= PALETTE_NR)
845 return -EINVAL;
846
847 /* only FB_VISUAL_TRUECOLOR supported */
848
849 red >>= 16 - info->var.red.length;
850 green >>= 16 - info->var.green.length;
851 blue >>= 16 - info->var.blue.length;
852 transp >>= 16 - info->var.transp.length;
853
854 palette[regno] = (red << info->var.red.offset) |
855 (green << info->var.green.offset) |
856 (blue << info->var.blue.offset) |
857 (transp << info->var.transp.offset);
858
859 return 0;
860}
861
862static struct fb_fix_screeninfo sh_mobile_lcdc_fix = {
863 .id = "SH Mobile LCDC",
864 .type = FB_TYPE_PACKED_PIXELS,
865 .visual = FB_VISUAL_TRUECOLOR,
866 .accel = FB_ACCEL_NONE,
Phil Edworthy9dd38812009-09-15 12:00:18 +0000867 .xpanstep = 0,
868 .ypanstep = 1,
869 .ywrapstep = 0,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700870};
871
Magnus Damm85645572008-12-19 15:34:41 +0900872static void sh_mobile_lcdc_fillrect(struct fb_info *info,
873 const struct fb_fillrect *rect)
874{
875 sys_fillrect(info, rect);
876 sh_mobile_lcdc_deferred_io_touch(info);
877}
878
879static void sh_mobile_lcdc_copyarea(struct fb_info *info,
880 const struct fb_copyarea *area)
881{
882 sys_copyarea(info, area);
883 sh_mobile_lcdc_deferred_io_touch(info);
884}
885
886static void sh_mobile_lcdc_imageblit(struct fb_info *info,
887 const struct fb_image *image)
888{
889 sys_imageblit(info, image);
890 sh_mobile_lcdc_deferred_io_touch(info);
891}
892
Phil Edworthy9dd38812009-09-15 12:00:18 +0000893static int sh_mobile_fb_pan_display(struct fb_var_screeninfo *var,
894 struct fb_info *info)
895{
896 struct sh_mobile_lcdc_chan *ch = info->par;
Phil Edworthy92e1f9a2010-02-11 10:24:25 +0000897 struct sh_mobile_lcdc_priv *priv = ch->lcdc;
898 unsigned long ldrcntr;
899 unsigned long new_pan_offset;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000900 unsigned long base_addr_y, base_addr_c;
901 unsigned long c_offset;
Phil Edworthy9dd38812009-09-15 12:00:18 +0000902
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000903 if (!var->nonstd)
904 new_pan_offset = (var->yoffset * info->fix.line_length) +
905 (var->xoffset * (info->var.bits_per_pixel / 8));
906 else
907 new_pan_offset = (var->yoffset * info->fix.line_length) +
908 (var->xoffset);
Phil Edworthy9dd38812009-09-15 12:00:18 +0000909
Phil Edworthy92e1f9a2010-02-11 10:24:25 +0000910 if (new_pan_offset == ch->pan_offset)
911 return 0; /* No change, do nothing */
912
913 ldrcntr = lcdc_read(priv, _LDRCNTR);
914
915 /* Set the source address for the next refresh */
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000916 base_addr_y = ch->dma_handle + new_pan_offset;
917 if (var->nonstd) {
918 /* Set y offset */
919 c_offset = (var->yoffset *
920 info->fix.line_length *
921 (info->var.bits_per_pixel - 8)) / 8;
922 base_addr_c = ch->dma_handle + var->xres * var->yres_virtual +
923 c_offset;
924 /* Set x offset */
925 if (info->var.bits_per_pixel == 24)
926 base_addr_c += 2 * var->xoffset;
927 else
928 base_addr_c += var->xoffset;
929 } else
930 base_addr_c = 0;
931
Damian7caa4342011-05-18 11:10:07 +0000932 if (!ch->meram_enabled) {
933 lcdc_write_chan_mirror(ch, LDSA1R, base_addr_y);
934 if (base_addr_c)
935 lcdc_write_chan_mirror(ch, LDSA2R, base_addr_c);
936 } else {
937 struct sh_mobile_meram_cfg *cfg;
938 struct sh_mobile_meram_info *mdev;
939 unsigned long icb_addr_y, icb_addr_c;
940 int ret;
941
942 cfg = ch->cfg.meram_cfg;
943 mdev = priv->meram_dev;
944 ret = mdev->ops->meram_update(mdev, cfg,
945 base_addr_y, base_addr_c,
946 &icb_addr_y, &icb_addr_c);
947 if (ret)
948 return ret;
949
950 lcdc_write_chan_mirror(ch, LDSA1R, icb_addr_y);
951 if (icb_addr_c)
952 lcdc_write_chan_mirror(ch, LDSA2R, icb_addr_c);
953
954 }
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000955
Phil Edworthy92e1f9a2010-02-11 10:24:25 +0000956 if (lcdc_chan_is_sublcd(ch))
957 lcdc_write(ch->lcdc, _LDRCNTR, ldrcntr ^ LDRCNTR_SRS);
958 else
959 lcdc_write(ch->lcdc, _LDRCNTR, ldrcntr ^ LDRCNTR_MRS);
960
961 ch->pan_offset = new_pan_offset;
962
963 sh_mobile_lcdc_deferred_io_touch(info);
Phil Edworthy9dd38812009-09-15 12:00:18 +0000964
965 return 0;
966}
967
Phil Edworthy40331b22010-02-15 13:57:49 +0000968static int sh_mobile_wait_for_vsync(struct fb_info *info)
969{
970 struct sh_mobile_lcdc_chan *ch = info->par;
971 unsigned long ldintr;
972 int ret;
973
974 /* Enable VSync End interrupt */
975 ldintr = lcdc_read(ch->lcdc, _LDINTR);
976 ldintr |= LDINTR_VEE;
977 lcdc_write(ch->lcdc, _LDINTR, ldintr);
978
979 ret = wait_for_completion_interruptible_timeout(&ch->vsync_completion,
980 msecs_to_jiffies(100));
981 if (!ret)
982 return -ETIMEDOUT;
983
984 return 0;
985}
986
987static int sh_mobile_ioctl(struct fb_info *info, unsigned int cmd,
988 unsigned long arg)
989{
990 int retval;
991
992 switch (cmd) {
993 case FBIO_WAITFORVSYNC:
994 retval = sh_mobile_wait_for_vsync(info);
995 break;
996
997 default:
998 retval = -ENOIOCTLCMD;
999 break;
1000 }
1001 return retval;
1002}
1003
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001004static void sh_mobile_fb_reconfig(struct fb_info *info)
1005{
1006 struct sh_mobile_lcdc_chan *ch = info->par;
1007 struct fb_videomode mode1, mode2;
1008 struct fb_event event;
1009 int evnt = FB_EVENT_MODE_CHANGE_ALL;
1010
1011 if (ch->use_count > 1 || (ch->use_count == 1 && !info->fbcon_par))
1012 /* More framebuffer users are active */
1013 return;
1014
1015 fb_var_to_videomode(&mode1, &ch->display_var);
1016 fb_var_to_videomode(&mode2, &info->var);
1017
1018 if (fb_mode_is_equal(&mode1, &mode2))
1019 return;
1020
1021 /* Display has been re-plugged, framebuffer is free now, reconfigure */
1022 if (fb_set_var(info, &ch->display_var) < 0)
1023 /* Couldn't reconfigure, hopefully, can continue as before */
1024 return;
1025
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +00001026 if (info->var.nonstd)
1027 info->fix.line_length = mode1.xres;
1028 else
1029 info->fix.line_length = mode1.xres * (ch->cfg.bpp / 8);
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001030
1031 /*
1032 * fb_set_var() calls the notifier change internally, only if
1033 * FBINFO_MISC_USEREVENT flag is set. Since we do not want to fake a
1034 * user event, we have to call the chain ourselves.
1035 */
1036 event.info = info;
Arnd Hannemanncc267ec2010-11-15 21:43:22 +00001037 event.data = &mode1;
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001038 fb_notifier_call_chain(evnt, &event);
1039}
1040
1041/*
1042 * Locking: both .fb_release() and .fb_open() are called with info->lock held if
1043 * user == 1, or with console sem held, if user == 0.
1044 */
1045static int sh_mobile_release(struct fb_info *info, int user)
1046{
1047 struct sh_mobile_lcdc_chan *ch = info->par;
1048
1049 mutex_lock(&ch->open_lock);
1050 dev_dbg(info->dev, "%s(): %d users\n", __func__, ch->use_count);
1051
1052 ch->use_count--;
1053
1054 /* Nothing to reconfigure, when called from fbcon */
1055 if (user) {
Torben Hohnac751ef2011-01-25 15:07:35 -08001056 console_lock();
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001057 sh_mobile_fb_reconfig(info);
Torben Hohnac751ef2011-01-25 15:07:35 -08001058 console_unlock();
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001059 }
1060
1061 mutex_unlock(&ch->open_lock);
1062
1063 return 0;
1064}
1065
1066static int sh_mobile_open(struct fb_info *info, int user)
1067{
1068 struct sh_mobile_lcdc_chan *ch = info->par;
1069
1070 mutex_lock(&ch->open_lock);
1071 ch->use_count++;
1072
1073 dev_dbg(info->dev, "%s(): %d users\n", __func__, ch->use_count);
1074 mutex_unlock(&ch->open_lock);
1075
1076 return 0;
1077}
1078
1079static int sh_mobile_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1080{
1081 struct sh_mobile_lcdc_chan *ch = info->par;
Magnus Damm417d4822011-01-05 10:21:00 +00001082 struct sh_mobile_lcdc_priv *p = ch->lcdc;
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001083
Guennadi Liakhovetskid2ecbab2010-11-04 11:06:06 +00001084 if (var->xres > MAX_XRES || var->yres > MAX_YRES ||
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001085 var->xres * var->yres * (ch->cfg.bpp / 8) * 2 > info->fix.smem_len) {
Paul Mundt830539d2010-11-10 17:51:44 +09001086 dev_warn(info->dev, "Invalid info: %u-%u-%u-%u x %u-%u-%u-%u @ %lukHz!\n",
Guennadi Liakhovetskid2ecbab2010-11-04 11:06:06 +00001087 var->left_margin, var->xres, var->right_margin, var->hsync_len,
1088 var->upper_margin, var->yres, var->lower_margin, var->vsync_len,
1089 PICOS2KHZ(var->pixclock));
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001090 return -EINVAL;
1091 }
Magnus Damm417d4822011-01-05 10:21:00 +00001092
1093 /* only accept the forced_bpp for dual channel configurations */
1094 if (p->forced_bpp && p->forced_bpp != var->bits_per_pixel)
1095 return -EINVAL;
1096
1097 switch (var->bits_per_pixel) {
1098 case 16: /* PKF[4:0] = 00011 - RGB 565 */
1099 case 24: /* PKF[4:0] = 01011 - RGB 888 */
1100 case 32: /* PKF[4:0] = 00000 - RGBA 888 */
1101 break;
1102 default:
1103 return -EINVAL;
1104 }
1105
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001106 return 0;
1107}
Phil Edworthy40331b22010-02-15 13:57:49 +00001108
Alexandre Courbot8857b9a2011-02-23 08:36:30 +00001109/*
1110 * Screen blanking. Behavior is as follows:
1111 * FB_BLANK_UNBLANK: screen unblanked, clocks enabled
1112 * FB_BLANK_NORMAL: screen blanked, clocks enabled
1113 * FB_BLANK_VSYNC,
1114 * FB_BLANK_HSYNC,
1115 * FB_BLANK_POWEROFF: screen blanked, clocks disabled
1116 */
1117static int sh_mobile_lcdc_blank(int blank, struct fb_info *info)
1118{
1119 struct sh_mobile_lcdc_chan *ch = info->par;
1120 struct sh_mobile_lcdc_priv *p = ch->lcdc;
1121
1122 /* blank the screen? */
1123 if (blank > FB_BLANK_UNBLANK && ch->blank_status == FB_BLANK_UNBLANK) {
1124 struct fb_fillrect rect = {
1125 .width = info->var.xres,
1126 .height = info->var.yres,
1127 };
1128 sh_mobile_lcdc_fillrect(info, &rect);
1129 }
1130 /* turn clocks on? */
1131 if (blank <= FB_BLANK_NORMAL && ch->blank_status > FB_BLANK_NORMAL) {
1132 sh_mobile_lcdc_clk_on(p);
1133 }
1134 /* turn clocks off? */
1135 if (blank > FB_BLANK_NORMAL && ch->blank_status <= FB_BLANK_NORMAL) {
1136 /* make sure the screen is updated with the black fill before
1137 * switching the clocks off. one vsync is not enough since
1138 * blanking may occur in the middle of a refresh. deferred io
1139 * mode will reenable the clocks and update the screen in time,
1140 * so it does not need this. */
1141 if (!info->fbdefio) {
1142 sh_mobile_wait_for_vsync(info);
1143 sh_mobile_wait_for_vsync(info);
1144 }
1145 sh_mobile_lcdc_clk_off(p);
1146 }
1147
1148 ch->blank_status = blank;
1149 return 0;
1150}
1151
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001152static struct fb_ops sh_mobile_lcdc_ops = {
Phil Edworthy9dd38812009-09-15 12:00:18 +00001153 .owner = THIS_MODULE,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001154 .fb_setcolreg = sh_mobile_lcdc_setcolreg,
Magnus Damm2540c112008-12-17 17:29:49 +09001155 .fb_read = fb_sys_read,
1156 .fb_write = fb_sys_write,
Magnus Damm85645572008-12-19 15:34:41 +09001157 .fb_fillrect = sh_mobile_lcdc_fillrect,
1158 .fb_copyarea = sh_mobile_lcdc_copyarea,
1159 .fb_imageblit = sh_mobile_lcdc_imageblit,
Alexandre Courbot8857b9a2011-02-23 08:36:30 +00001160 .fb_blank = sh_mobile_lcdc_blank,
Phil Edworthy9dd38812009-09-15 12:00:18 +00001161 .fb_pan_display = sh_mobile_fb_pan_display,
Phil Edworthy40331b22010-02-15 13:57:49 +00001162 .fb_ioctl = sh_mobile_ioctl,
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001163 .fb_open = sh_mobile_open,
1164 .fb_release = sh_mobile_release,
1165 .fb_check_var = sh_mobile_check_var,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001166};
1167
Alexandre Courbot3b0fd9d2011-02-16 03:49:01 +00001168static int sh_mobile_lcdc_update_bl(struct backlight_device *bdev)
1169{
1170 struct sh_mobile_lcdc_chan *ch = bl_get_data(bdev);
1171 struct sh_mobile_lcdc_board_cfg *cfg = &ch->cfg.board_cfg;
1172 int brightness = bdev->props.brightness;
1173
1174 if (bdev->props.power != FB_BLANK_UNBLANK ||
1175 bdev->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK))
1176 brightness = 0;
1177
1178 return cfg->set_brightness(cfg->board_data, brightness);
1179}
1180
1181static int sh_mobile_lcdc_get_brightness(struct backlight_device *bdev)
1182{
1183 struct sh_mobile_lcdc_chan *ch = bl_get_data(bdev);
1184 struct sh_mobile_lcdc_board_cfg *cfg = &ch->cfg.board_cfg;
1185
1186 return cfg->get_brightness(cfg->board_data);
1187}
1188
1189static int sh_mobile_lcdc_check_fb(struct backlight_device *bdev,
1190 struct fb_info *info)
1191{
1192 return (info->bl_dev == bdev);
1193}
1194
1195static struct backlight_ops sh_mobile_lcdc_bl_ops = {
1196 .options = BL_CORE_SUSPENDRESUME,
1197 .update_status = sh_mobile_lcdc_update_bl,
1198 .get_brightness = sh_mobile_lcdc_get_brightness,
1199 .check_fb = sh_mobile_lcdc_check_fb,
1200};
1201
1202static struct backlight_device *sh_mobile_lcdc_bl_probe(struct device *parent,
1203 struct sh_mobile_lcdc_chan *ch)
1204{
1205 struct backlight_device *bl;
1206
1207 bl = backlight_device_register(ch->cfg.bl_info.name, parent, ch,
1208 &sh_mobile_lcdc_bl_ops, NULL);
Dan Carpenterbeee1f22011-03-21 15:03:13 +00001209 if (IS_ERR(bl)) {
1210 dev_err(parent, "unable to register backlight device: %ld\n",
1211 PTR_ERR(bl));
Alexandre Courbot3b0fd9d2011-02-16 03:49:01 +00001212 return NULL;
1213 }
1214
1215 bl->props.max_brightness = ch->cfg.bl_info.max_brightness;
1216 bl->props.brightness = bl->props.max_brightness;
1217 backlight_update_status(bl);
1218
1219 return bl;
1220}
1221
1222static void sh_mobile_lcdc_bl_remove(struct backlight_device *bdev)
1223{
1224 backlight_device_unregister(bdev);
1225}
1226
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +00001227static int sh_mobile_lcdc_set_bpp(struct fb_var_screeninfo *var, int bpp,
1228 int nonstd)
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001229{
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +00001230 if (nonstd) {
1231 switch (bpp) {
1232 case 12:
1233 case 16:
1234 case 24:
1235 var->bits_per_pixel = bpp;
1236 var->nonstd = nonstd;
1237 return 0;
1238 default:
1239 return -EINVAL;
1240 }
1241 }
1242
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001243 switch (bpp) {
1244 case 16: /* PKF[4:0] = 00011 - RGB 565 */
1245 var->red.offset = 11;
1246 var->red.length = 5;
1247 var->green.offset = 5;
1248 var->green.length = 6;
1249 var->blue.offset = 0;
1250 var->blue.length = 5;
1251 var->transp.offset = 0;
1252 var->transp.length = 0;
1253 break;
1254
Magnus Damm417d4822011-01-05 10:21:00 +00001255 case 24: /* PKF[4:0] = 01011 - RGB 888 */
1256 var->red.offset = 16;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001257 var->red.length = 8;
Magnus Damm417d4822011-01-05 10:21:00 +00001258 var->green.offset = 8;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001259 var->green.length = 8;
Magnus Damm417d4822011-01-05 10:21:00 +00001260 var->blue.offset = 0;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001261 var->blue.length = 8;
1262 var->transp.offset = 0;
1263 var->transp.length = 0;
1264 break;
Magnus Damm417d4822011-01-05 10:21:00 +00001265
1266 case 32: /* PKF[4:0] = 00000 - RGBA 888 */
1267 var->red.offset = 16;
1268 var->red.length = 8;
1269 var->green.offset = 8;
1270 var->green.length = 8;
1271 var->blue.offset = 0;
1272 var->blue.length = 8;
1273 var->transp.offset = 24;
1274 var->transp.length = 8;
1275 break;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001276 default:
1277 return -EINVAL;
1278 }
1279 var->bits_per_pixel = bpp;
1280 var->red.msb_right = 0;
1281 var->green.msb_right = 0;
1282 var->blue.msb_right = 0;
1283 var->transp.msb_right = 0;
1284 return 0;
1285}
1286
Magnus Damm2feb0752009-03-13 15:36:55 +00001287static int sh_mobile_lcdc_suspend(struct device *dev)
1288{
1289 struct platform_device *pdev = to_platform_device(dev);
1290
1291 sh_mobile_lcdc_stop(platform_get_drvdata(pdev));
1292 return 0;
1293}
1294
1295static int sh_mobile_lcdc_resume(struct device *dev)
1296{
1297 struct platform_device *pdev = to_platform_device(dev);
1298
1299 return sh_mobile_lcdc_start(platform_get_drvdata(pdev));
1300}
1301
Magnus Damm0246c472009-08-14 10:49:08 +00001302static int sh_mobile_lcdc_runtime_suspend(struct device *dev)
1303{
1304 struct platform_device *pdev = to_platform_device(dev);
1305 struct sh_mobile_lcdc_priv *p = platform_get_drvdata(pdev);
1306 struct sh_mobile_lcdc_chan *ch;
1307 int k, n;
1308
1309 /* save per-channel registers */
1310 for (k = 0; k < ARRAY_SIZE(p->ch); k++) {
1311 ch = &p->ch[k];
1312 if (!ch->enabled)
1313 continue;
1314 for (n = 0; n < NR_CH_REGS; n++)
1315 ch->saved_ch_regs[n] = lcdc_read_chan(ch, n);
1316 }
1317
1318 /* save shared registers */
1319 for (n = 0; n < NR_SHARED_REGS; n++)
1320 p->saved_shared_regs[n] = lcdc_read(p, lcdc_shared_regs[n]);
1321
1322 /* turn off LCDC hardware */
1323 lcdc_write(p, _LDCNT1R, 0);
1324 return 0;
1325}
1326
1327static int sh_mobile_lcdc_runtime_resume(struct device *dev)
1328{
1329 struct platform_device *pdev = to_platform_device(dev);
1330 struct sh_mobile_lcdc_priv *p = platform_get_drvdata(pdev);
1331 struct sh_mobile_lcdc_chan *ch;
1332 int k, n;
1333
1334 /* restore per-channel registers */
1335 for (k = 0; k < ARRAY_SIZE(p->ch); k++) {
1336 ch = &p->ch[k];
1337 if (!ch->enabled)
1338 continue;
1339 for (n = 0; n < NR_CH_REGS; n++)
1340 lcdc_write_chan(ch, n, ch->saved_ch_regs[n]);
1341 }
1342
1343 /* restore shared registers */
1344 for (n = 0; n < NR_SHARED_REGS; n++)
1345 lcdc_write(p, lcdc_shared_regs[n], p->saved_shared_regs[n]);
1346
1347 return 0;
1348}
1349
Alexey Dobriyan47145212009-12-14 18:00:08 -08001350static const struct dev_pm_ops sh_mobile_lcdc_dev_pm_ops = {
Magnus Damm2feb0752009-03-13 15:36:55 +00001351 .suspend = sh_mobile_lcdc_suspend,
1352 .resume = sh_mobile_lcdc_resume,
Magnus Damm0246c472009-08-14 10:49:08 +00001353 .runtime_suspend = sh_mobile_lcdc_runtime_suspend,
1354 .runtime_resume = sh_mobile_lcdc_runtime_resume,
Magnus Damm2feb0752009-03-13 15:36:55 +00001355};
1356
Guennadi Liakhovetski6de9edd2010-09-03 07:20:23 +00001357/* locking: called with info->lock held */
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001358static int sh_mobile_lcdc_notify(struct notifier_block *nb,
1359 unsigned long action, void *data)
1360{
1361 struct fb_event *event = data;
1362 struct fb_info *info = event->info;
1363 struct sh_mobile_lcdc_chan *ch = info->par;
1364 struct sh_mobile_lcdc_board_cfg *board_cfg = &ch->cfg.board_cfg;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001365
1366 if (&ch->lcdc->notifier != nb)
Guennadi Liakhovetskibaf16372010-09-03 07:20:08 +00001367 return NOTIFY_DONE;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001368
1369 dev_dbg(info->dev, "%s(): action = %lu, data = %p\n",
1370 __func__, action, event->data);
1371
1372 switch(action) {
1373 case FB_EVENT_SUSPEND:
Alexandre Courbot247f9932011-02-23 08:41:50 +00001374 if (board_cfg->display_off && try_module_get(board_cfg->owner)) {
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001375 board_cfg->display_off(board_cfg->board_data);
Guennadi Liakhovetski6de9edd2010-09-03 07:20:23 +00001376 module_put(board_cfg->owner);
1377 }
Guennadi Liakhovetskiafe417c2010-09-03 07:20:39 +00001378 sh_mobile_lcdc_stop(ch->lcdc);
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001379 break;
1380 case FB_EVENT_RESUME:
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001381 mutex_lock(&ch->open_lock);
1382 sh_mobile_fb_reconfig(info);
1383 mutex_unlock(&ch->open_lock);
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001384
1385 /* HDMI must be enabled before LCDC configuration */
Alexandre Courbot247f9932011-02-23 08:41:50 +00001386 if (board_cfg->display_on && try_module_get(board_cfg->owner)) {
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001387 board_cfg->display_on(board_cfg->board_data, info);
Guennadi Liakhovetski6de9edd2010-09-03 07:20:23 +00001388 module_put(board_cfg->owner);
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001389 }
1390
Guennadi Liakhovetskiebe5e122011-05-05 16:33:40 +00001391 sh_mobile_lcdc_start(ch->lcdc);
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001392 }
1393
Guennadi Liakhovetskibaf16372010-09-03 07:20:08 +00001394 return NOTIFY_OK;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001395}
1396
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001397static int sh_mobile_lcdc_remove(struct platform_device *pdev);
1398
Uwe Kleine-Königc2e13032010-02-04 20:56:51 +01001399static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001400{
1401 struct fb_info *info;
1402 struct sh_mobile_lcdc_priv *priv;
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001403 struct sh_mobile_lcdc_info *pdata = pdev->dev.platform_data;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001404 struct resource *res;
1405 int error;
1406 void *buf;
1407 int i, j;
1408
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001409 if (!pdata) {
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001410 dev_err(&pdev->dev, "no platform data defined\n");
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001411 return -EINVAL;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001412 }
1413
1414 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Magnus Damm85645572008-12-19 15:34:41 +09001415 i = platform_get_irq(pdev, 0);
1416 if (!res || i < 0) {
1417 dev_err(&pdev->dev, "cannot get platform resources\n");
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001418 return -ENOENT;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001419 }
1420
1421 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
1422 if (!priv) {
1423 dev_err(&pdev->dev, "cannot allocate device data\n");
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001424 return -ENOMEM;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001425 }
1426
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001427 platform_set_drvdata(pdev, priv);
1428
Magnus Damm85645572008-12-19 15:34:41 +09001429 error = request_irq(i, sh_mobile_lcdc_irq, IRQF_DISABLED,
Kay Sievers7ad33e72009-03-24 16:38:21 -07001430 dev_name(&pdev->dev), priv);
Magnus Damm85645572008-12-19 15:34:41 +09001431 if (error) {
1432 dev_err(&pdev->dev, "unable to request irq\n");
1433 goto err1;
1434 }
1435
1436 priv->irq = i;
Guennadi Liakhovetski5ef6b502010-09-03 07:19:57 +00001437 atomic_set(&priv->hw_usecnt, -1);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001438
1439 j = 0;
1440 for (i = 0; i < ARRAY_SIZE(pdata->ch); i++) {
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001441 struct sh_mobile_lcdc_chan *ch = priv->ch + j;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001442
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001443 ch->lcdc = priv;
1444 memcpy(&ch->cfg, &pdata->ch[i], sizeof(pdata->ch[i]));
1445
1446 error = sh_mobile_lcdc_check_interface(ch);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001447 if (error) {
1448 dev_err(&pdev->dev, "unsupported interface type\n");
1449 goto err1;
1450 }
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001451 init_waitqueue_head(&ch->frame_end_wait);
1452 init_completion(&ch->vsync_completion);
1453 ch->pan_offset = 0;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001454
Alexandre Courbot3b0fd9d2011-02-16 03:49:01 +00001455 /* probe the backlight is there is one defined */
1456 if (ch->cfg.bl_info.max_brightness)
1457 ch->bl = sh_mobile_lcdc_bl_probe(&pdev->dev, ch);
1458
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001459 switch (pdata->ch[i].chan) {
1460 case LCDC_CHAN_MAINLCD:
Laurent Pinchartce1c0b02011-07-13 12:13:47 +02001461 ch->enabled = LDCNT2R_ME;
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001462 ch->reg_offs = lcdc_offs_mainlcd;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001463 j++;
1464 break;
1465 case LCDC_CHAN_SUBLCD:
Laurent Pinchartce1c0b02011-07-13 12:13:47 +02001466 ch->enabled = LDCNT2R_SE;
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001467 ch->reg_offs = lcdc_offs_sublcd;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001468 j++;
1469 break;
1470 }
1471 }
1472
1473 if (!j) {
1474 dev_err(&pdev->dev, "no channels defined\n");
1475 error = -EINVAL;
1476 goto err1;
1477 }
1478
Magnus Damm417d4822011-01-05 10:21:00 +00001479 /* for dual channel LCDC (MAIN + SUB) force shared bpp setting */
1480 if (j == 2)
1481 priv->forced_bpp = pdata->ch[0].bpp;
1482
Guennadi Liakhovetskidba6f382010-06-30 09:26:35 +00001483 priv->base = ioremap_nocache(res->start, resource_size(res));
1484 if (!priv->base)
1485 goto err1;
1486
Magnus Dammb51339f2008-10-31 20:23:26 +09001487 error = sh_mobile_lcdc_setup_clocks(pdev, pdata->clock_source, priv);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001488 if (error) {
1489 dev_err(&pdev->dev, "unable to setup clocks\n");
1490 goto err1;
1491 }
1492
Damian7caa4342011-05-18 11:10:07 +00001493 priv->meram_dev = pdata->meram_dev;
1494
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001495 for (i = 0; i < j; i++) {
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001496 struct fb_var_screeninfo *var;
Guennadi Liakhovetski71d3b0f2010-09-03 07:20:12 +00001497 const struct fb_videomode *lcd_cfg, *max_cfg = NULL;
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001498 struct sh_mobile_lcdc_chan *ch = priv->ch + i;
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001499 struct sh_mobile_lcdc_chan_cfg *cfg = &ch->cfg;
1500 const struct fb_videomode *mode = cfg->lcd_cfg;
Guennadi Liakhovetski71d3b0f2010-09-03 07:20:12 +00001501 unsigned long max_size = 0;
1502 int k;
Guennadi Liakhovetski5fd284e2010-11-04 11:06:11 +00001503 int num_cfg;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001504
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001505 ch->info = framebuffer_alloc(0, &pdev->dev);
1506 if (!ch->info) {
Paul Mundte33afdd2009-07-07 11:24:32 +09001507 dev_err(&pdev->dev, "unable to allocate fb_info\n");
1508 error = -ENOMEM;
1509 break;
1510 }
1511
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001512 info = ch->info;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001513 var = &info->var;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001514 info->fbops = &sh_mobile_lcdc_ops;
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001515 info->par = ch;
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001516
1517 mutex_init(&ch->open_lock);
1518
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001519 for (k = 0, lcd_cfg = mode;
1520 k < cfg->num_cfg && lcd_cfg;
Guennadi Liakhovetski71d3b0f2010-09-03 07:20:12 +00001521 k++, lcd_cfg++) {
1522 unsigned long size = lcd_cfg->yres * lcd_cfg->xres;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +00001523 /* NV12 buffers must have even number of lines */
1524 if ((cfg->nonstd) && cfg->bpp == 12 &&
1525 (lcd_cfg->yres & 0x1)) {
1526 dev_err(&pdev->dev, "yres must be multiple of 2"
1527 " for YCbCr420 mode.\n");
1528 error = -EINVAL;
1529 goto err1;
1530 }
Guennadi Liakhovetski71d3b0f2010-09-03 07:20:12 +00001531
1532 if (size > max_size) {
1533 max_cfg = lcd_cfg;
1534 max_size = size;
1535 }
1536 }
1537
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001538 if (!mode)
Guennadi Liakhovetskid2ecbab2010-11-04 11:06:06 +00001539 max_size = MAX_XRES * MAX_YRES;
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001540 else if (max_cfg)
1541 dev_dbg(&pdev->dev, "Found largest videomode %ux%u\n",
1542 max_cfg->xres, max_cfg->yres);
Guennadi Liakhovetski71d3b0f2010-09-03 07:20:12 +00001543
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001544 info->fix = sh_mobile_lcdc_fix;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +00001545 info->fix.smem_len = max_size * 2 * cfg->bpp / 8;
1546
1547 /* Only pan in 2 line steps for NV12 */
1548 if (cfg->nonstd && cfg->bpp == 12)
1549 info->fix.ypanstep = 2;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001550
Guennadi Liakhovetski5fd284e2010-11-04 11:06:11 +00001551 if (!mode) {
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001552 mode = &default_720p;
Guennadi Liakhovetski5fd284e2010-11-04 11:06:11 +00001553 num_cfg = 1;
1554 } else {
Guennadi Liakhovetskie0b9fb22010-12-21 11:46:26 +01001555 num_cfg = cfg->num_cfg;
Guennadi Liakhovetski5fd284e2010-11-04 11:06:11 +00001556 }
1557
1558 fb_videomode_to_modelist(mode, num_cfg, &info->modelist);
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001559
1560 fb_videomode_to_var(var, mode);
Guennadi Liakhovetskie0b9fb22010-12-21 11:46:26 +01001561 var->width = cfg->lcd_size_cfg.width;
1562 var->height = cfg->lcd_size_cfg.height;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001563 /* Default Y virtual resolution is 2x panel size */
1564 var->yres_virtual = var->yres * 2;
Paul Mundt1c6a3072009-07-01 06:50:31 +00001565 var->activate = FB_ACTIVATE_NOW;
Paul Mundt1c6a3072009-07-01 06:50:31 +00001566
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +00001567 error = sh_mobile_lcdc_set_bpp(var, cfg->bpp, cfg->nonstd);
Paul Mundt1c6a3072009-07-01 06:50:31 +00001568 if (error)
1569 break;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001570
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001571 buf = dma_alloc_coherent(&pdev->dev, info->fix.smem_len,
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001572 &ch->dma_handle, GFP_KERNEL);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001573 if (!buf) {
1574 dev_err(&pdev->dev, "unable to allocate buffer\n");
1575 error = -ENOMEM;
1576 break;
1577 }
1578
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001579 info->pseudo_palette = &ch->pseudo_palette;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001580 info->flags = FBINFO_FLAG_DEFAULT;
1581
1582 error = fb_alloc_cmap(&info->cmap, PALETTE_NR, 0);
1583 if (error < 0) {
1584 dev_err(&pdev->dev, "unable to allocate cmap\n");
1585 dma_free_coherent(&pdev->dev, info->fix.smem_len,
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001586 buf, ch->dma_handle);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001587 break;
1588 }
1589
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001590 info->fix.smem_start = ch->dma_handle;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +00001591 if (var->nonstd)
1592 info->fix.line_length = var->xres;
1593 else
1594 info->fix.line_length = var->xres * (cfg->bpp / 8);
1595
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001596 info->screen_base = buf;
1597 info->device = &pdev->dev;
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +00001598 ch->display_var = *var;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001599 }
1600
1601 if (error)
1602 goto err1;
1603
1604 error = sh_mobile_lcdc_start(priv);
1605 if (error) {
1606 dev_err(&pdev->dev, "unable to start hardware\n");
1607 goto err1;
1608 }
1609
1610 for (i = 0; i < j; i++) {
1611 struct sh_mobile_lcdc_chan *ch = priv->ch + i;
1612
1613 info = ch->info;
1614
1615 if (info->fbdefio) {
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001616 ch->sglist = vmalloc(sizeof(struct scatterlist) *
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001617 info->fix.smem_len >> PAGE_SHIFT);
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001618 if (!ch->sglist) {
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001619 dev_err(&pdev->dev, "cannot allocate sglist\n");
1620 goto err1;
1621 }
1622 }
1623
Alexandre Courbot3b0fd9d2011-02-16 03:49:01 +00001624 info->bl_dev = ch->bl;
1625
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001626 error = register_framebuffer(info);
1627 if (error < 0)
1628 goto err1;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001629
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001630 dev_info(info->dev,
1631 "registered %s/%s as %dx%d %dbpp.\n",
1632 pdev->name,
Paul Mundt1c6a3072009-07-01 06:50:31 +00001633 (ch->cfg.chan == LCDC_CHAN_MAINLCD) ?
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001634 "mainlcd" : "sublcd",
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001635 info->var.xres, info->var.yres,
Paul Mundt1c6a3072009-07-01 06:50:31 +00001636 ch->cfg.bpp);
Magnus Damm85645572008-12-19 15:34:41 +09001637
1638 /* deferred io mode: disable clock to save power */
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001639 if (info->fbdefio || info->state == FBINFO_STATE_SUSPENDED)
Magnus Damm85645572008-12-19 15:34:41 +09001640 sh_mobile_lcdc_clk_off(priv);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001641 }
1642
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001643 /* Failure ignored */
1644 priv->notifier.notifier_call = sh_mobile_lcdc_notify;
1645 fb_register_client(&priv->notifier);
1646
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001647 return 0;
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001648err1:
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001649 sh_mobile_lcdc_remove(pdev);
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001650
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001651 return error;
1652}
1653
1654static int sh_mobile_lcdc_remove(struct platform_device *pdev)
1655{
1656 struct sh_mobile_lcdc_priv *priv = platform_get_drvdata(pdev);
1657 struct fb_info *info;
1658 int i;
1659
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001660 fb_unregister_client(&priv->notifier);
1661
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001662 for (i = 0; i < ARRAY_SIZE(priv->ch); i++)
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001663 if (priv->ch[i].info && priv->ch[i].info->dev)
Paul Mundte33afdd2009-07-07 11:24:32 +09001664 unregister_framebuffer(priv->ch[i].info);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001665
1666 sh_mobile_lcdc_stop(priv);
1667
1668 for (i = 0; i < ARRAY_SIZE(priv->ch); i++) {
Paul Mundte33afdd2009-07-07 11:24:32 +09001669 info = priv->ch[i].info;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001670
Paul Mundte33afdd2009-07-07 11:24:32 +09001671 if (!info || !info->device)
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001672 continue;
1673
Paul Mundt1c6a3072009-07-01 06:50:31 +00001674 if (priv->ch[i].sglist)
1675 vfree(priv->ch[i].sglist);
1676
Magnus Damm1ffbb032010-10-13 07:17:45 +00001677 if (info->screen_base)
1678 dma_free_coherent(&pdev->dev, info->fix.smem_len,
1679 info->screen_base,
1680 priv->ch[i].dma_handle);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001681 fb_dealloc_cmap(&info->cmap);
Paul Mundte33afdd2009-07-07 11:24:32 +09001682 framebuffer_release(info);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001683 }
1684
Alexandre Courbot3b0fd9d2011-02-16 03:49:01 +00001685 for (i = 0; i < ARRAY_SIZE(priv->ch); i++) {
1686 if (priv->ch[i].bl)
1687 sh_mobile_lcdc_bl_remove(priv->ch[i].bl);
1688 }
1689
Magnus Dammb51339f2008-10-31 20:23:26 +09001690 if (priv->dot_clk)
1691 clk_put(priv->dot_clk);
Magnus Damm0246c472009-08-14 10:49:08 +00001692
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001693 if (priv->dev)
1694 pm_runtime_disable(priv->dev);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001695
1696 if (priv->base)
1697 iounmap(priv->base);
1698
Magnus Damm85645572008-12-19 15:34:41 +09001699 if (priv->irq)
1700 free_irq(priv->irq, priv);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001701 kfree(priv);
1702 return 0;
1703}
1704
1705static struct platform_driver sh_mobile_lcdc_driver = {
1706 .driver = {
1707 .name = "sh_mobile_lcdc_fb",
1708 .owner = THIS_MODULE,
Magnus Damm2feb0752009-03-13 15:36:55 +00001709 .pm = &sh_mobile_lcdc_dev_pm_ops,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001710 },
1711 .probe = sh_mobile_lcdc_probe,
1712 .remove = sh_mobile_lcdc_remove,
1713};
1714
1715static int __init sh_mobile_lcdc_init(void)
1716{
1717 return platform_driver_register(&sh_mobile_lcdc_driver);
1718}
1719
1720static void __exit sh_mobile_lcdc_exit(void)
1721{
1722 platform_driver_unregister(&sh_mobile_lcdc_driver);
1723}
1724
1725module_init(sh_mobile_lcdc_init);
1726module_exit(sh_mobile_lcdc_exit);
1727
1728MODULE_DESCRIPTION("SuperH Mobile LCDC Framebuffer driver");
1729MODULE_AUTHOR("Magnus Damm <damm@opensource.se>");
1730MODULE_LICENSE("GPL v2");