blob: 1ff215c42c4140420885ce2cfef82b9ab7a59079 [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>
Laurent Pinchart8a209742011-07-13 12:13:47 +020027#include <video/sh_mobile_meram.h>
Arun Sharma600634972011-07-26 16:09:06 -070028#include <linux/atomic.h>
Magnus Dammcfb4f5d2008-07-23 21:31:24 -070029
Guennadi Liakhovetski6de9edd2010-09-03 07:20:23 +000030#include "sh_mobile_lcdcfb.h"
31
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
Guennadi Liakhovetskid2ecbab2010-11-04 11:06:06 +000035#define MAX_XRES 1920
36#define MAX_YRES 1080
Magnus Dammcfb4f5d2008-07-23 21:31:24 -070037
Magnus Damm0246c472009-08-14 10:49:08 +000038static unsigned long lcdc_offs_mainlcd[NR_CH_REGS] = {
Magnus Dammcfb4f5d2008-07-23 21:31:24 -070039 [LDDCKPAT1R] = 0x400,
40 [LDDCKPAT2R] = 0x404,
41 [LDMT1R] = 0x418,
42 [LDMT2R] = 0x41c,
43 [LDMT3R] = 0x420,
44 [LDDFR] = 0x424,
45 [LDSM1R] = 0x428,
Magnus Damm85645572008-12-19 15:34:41 +090046 [LDSM2R] = 0x42c,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -070047 [LDSA1R] = 0x430,
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +000048 [LDSA2R] = 0x434,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -070049 [LDMLSR] = 0x438,
50 [LDHCNR] = 0x448,
51 [LDHSYNR] = 0x44c,
52 [LDVLNR] = 0x450,
53 [LDVSYNR] = 0x454,
54 [LDPMR] = 0x460,
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +000055 [LDHAJR] = 0x4a0,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -070056};
57
Magnus Damm0246c472009-08-14 10:49:08 +000058static unsigned long lcdc_offs_sublcd[NR_CH_REGS] = {
Magnus Dammcfb4f5d2008-07-23 21:31:24 -070059 [LDDCKPAT1R] = 0x408,
60 [LDDCKPAT2R] = 0x40c,
61 [LDMT1R] = 0x600,
62 [LDMT2R] = 0x604,
63 [LDMT3R] = 0x608,
64 [LDDFR] = 0x60c,
65 [LDSM1R] = 0x610,
Magnus Damm85645572008-12-19 15:34:41 +090066 [LDSM2R] = 0x614,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -070067 [LDSA1R] = 0x618,
68 [LDMLSR] = 0x620,
69 [LDHCNR] = 0x624,
70 [LDHSYNR] = 0x628,
71 [LDVLNR] = 0x62c,
72 [LDVSYNR] = 0x630,
73 [LDPMR] = 0x63c,
74};
75
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +000076static const struct fb_videomode default_720p = {
77 .name = "HDMI 720p",
78 .xres = 1280,
79 .yres = 720,
80
Guennadi Liakhovetski5ae0cf82010-11-04 11:06:01 +000081 .left_margin = 220,
82 .right_margin = 110,
83 .hsync_len = 40,
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +000084
85 .upper_margin = 20,
86 .lower_margin = 5,
87 .vsync_len = 5,
88
89 .pixclock = 13468,
Guennadi Liakhovetski5ae0cf82010-11-04 11:06:01 +000090 .refresh = 60,
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +000091 .sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT,
Magnus Damm0246c472009-08-14 10:49:08 +000092};
93
94struct sh_mobile_lcdc_priv {
95 void __iomem *base;
96 int irq;
97 atomic_t hw_usecnt;
98 struct device *dev;
99 struct clk *dot_clk;
100 unsigned long lddckr;
101 struct sh_mobile_lcdc_chan ch[2];
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000102 struct notifier_block notifier;
Magnus Damm0246c472009-08-14 10:49:08 +0000103 int started;
Magnus Damm417d4822011-01-05 10:21:00 +0000104 int forced_bpp; /* 2 channel LCDC must share bpp setting */
Damian7caa4342011-05-18 11:10:07 +0000105 struct sh_mobile_meram_info *meram_dev;
Magnus Damm0246c472009-08-14 10:49:08 +0000106};
107
Phil Edworthya6f15ad2009-09-15 12:00:30 +0000108static bool banked(int reg_nr)
109{
110 switch (reg_nr) {
111 case LDMT1R:
112 case LDMT2R:
113 case LDMT3R:
114 case LDDFR:
115 case LDSM1R:
116 case LDSA1R:
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000117 case LDSA2R:
Phil Edworthya6f15ad2009-09-15 12:00:30 +0000118 case LDMLSR:
119 case LDHCNR:
120 case LDHSYNR:
121 case LDVLNR:
122 case LDVSYNR:
123 return true;
124 }
125 return false;
126}
127
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700128static void lcdc_write_chan(struct sh_mobile_lcdc_chan *chan,
129 int reg_nr, unsigned long data)
130{
131 iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr]);
Phil Edworthya6f15ad2009-09-15 12:00:30 +0000132 if (banked(reg_nr))
133 iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr] +
134 SIDE_B_OFFSET);
135}
136
137static void lcdc_write_chan_mirror(struct sh_mobile_lcdc_chan *chan,
138 int reg_nr, unsigned long data)
139{
140 iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr] +
141 MIRROR_OFFSET);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700142}
143
144static unsigned long lcdc_read_chan(struct sh_mobile_lcdc_chan *chan,
145 int reg_nr)
146{
147 return ioread32(chan->lcdc->base + chan->reg_offs[reg_nr]);
148}
149
150static void lcdc_write(struct sh_mobile_lcdc_priv *priv,
151 unsigned long reg_offs, unsigned long data)
152{
153 iowrite32(data, priv->base + reg_offs);
154}
155
156static unsigned long lcdc_read(struct sh_mobile_lcdc_priv *priv,
157 unsigned long reg_offs)
158{
159 return ioread32(priv->base + reg_offs);
160}
161
162static void lcdc_wait_bit(struct sh_mobile_lcdc_priv *priv,
163 unsigned long reg_offs,
164 unsigned long mask, unsigned long until)
165{
166 while ((lcdc_read(priv, reg_offs) & mask) != until)
167 cpu_relax();
168}
169
170static int lcdc_chan_is_sublcd(struct sh_mobile_lcdc_chan *chan)
171{
172 return chan->cfg.chan == LCDC_CHAN_SUBLCD;
173}
174
175static void lcdc_sys_write_index(void *handle, unsigned long data)
176{
177 struct sh_mobile_lcdc_chan *ch = handle;
178
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200179 lcdc_write(ch->lcdc, _LDDWD0R, data | LDDWDxR_WDACT);
180 lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
181 lcdc_write(ch->lcdc, _LDDWAR, LDDWAR_WA |
182 (lcdc_chan_is_sublcd(ch) ? 2 : 0));
183 lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700184}
185
186static void lcdc_sys_write_data(void *handle, unsigned long data)
187{
188 struct sh_mobile_lcdc_chan *ch = handle;
189
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200190 lcdc_write(ch->lcdc, _LDDWD0R, data | LDDWDxR_WDACT | LDDWDxR_RSW);
191 lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
192 lcdc_write(ch->lcdc, _LDDWAR, LDDWAR_WA |
193 (lcdc_chan_is_sublcd(ch) ? 2 : 0));
194 lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700195}
196
197static unsigned long lcdc_sys_read_data(void *handle)
198{
199 struct sh_mobile_lcdc_chan *ch = handle;
200
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200201 lcdc_write(ch->lcdc, _LDDRDR, LDDRDR_RSR);
202 lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
203 lcdc_write(ch->lcdc, _LDDRAR, LDDRAR_RA |
204 (lcdc_chan_is_sublcd(ch) ? 2 : 0));
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700205 udelay(1);
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200206 lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700207
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200208 return lcdc_read(ch->lcdc, _LDDRDR) & LDDRDR_DRD_MASK;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700209}
210
211struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
212 lcdc_sys_write_index,
213 lcdc_sys_write_data,
214 lcdc_sys_read_data,
215};
216
Magnus Damm85645572008-12-19 15:34:41 +0900217static void sh_mobile_lcdc_clk_on(struct sh_mobile_lcdc_priv *priv)
218{
Magnus Damm0246c472009-08-14 10:49:08 +0000219 if (atomic_inc_and_test(&priv->hw_usecnt)) {
Magnus Damm85645572008-12-19 15:34:41 +0900220 if (priv->dot_clk)
221 clk_enable(priv->dot_clk);
Laurent Pinchartf1ad90d2011-07-11 11:05:49 +0200222 pm_runtime_get_sync(priv->dev);
Damian Hobson-Garciaec19b9e2011-07-04 08:06:47 +0200223 if (priv->meram_dev && priv->meram_dev->pdev)
224 pm_runtime_get_sync(&priv->meram_dev->pdev->dev);
Magnus Damm85645572008-12-19 15:34:41 +0900225 }
226}
227
228static void sh_mobile_lcdc_clk_off(struct sh_mobile_lcdc_priv *priv)
229{
Magnus Damm0246c472009-08-14 10:49:08 +0000230 if (atomic_sub_return(1, &priv->hw_usecnt) == -1) {
Damian Hobson-Garciaec19b9e2011-07-04 08:06:47 +0200231 if (priv->meram_dev && priv->meram_dev->pdev)
232 pm_runtime_put_sync(&priv->meram_dev->pdev->dev);
Magnus Damm0246c472009-08-14 10:49:08 +0000233 pm_runtime_put(priv->dev);
Laurent Pinchartf1ad90d2011-07-11 11:05:49 +0200234 if (priv->dot_clk)
235 clk_disable(priv->dot_clk);
Magnus Damm85645572008-12-19 15:34:41 +0900236 }
237}
Magnus Damm85645572008-12-19 15:34:41 +0900238
Paul Mundt1c6a3072009-07-01 06:50:31 +0000239static int sh_mobile_lcdc_sginit(struct fb_info *info,
240 struct list_head *pagelist)
241{
242 struct sh_mobile_lcdc_chan *ch = info->par;
243 unsigned int nr_pages_max = info->fix.smem_len >> PAGE_SHIFT;
244 struct page *page;
245 int nr_pages = 0;
246
247 sg_init_table(ch->sglist, nr_pages_max);
248
249 list_for_each_entry(page, pagelist, lru)
250 sg_set_page(&ch->sglist[nr_pages++], page, PAGE_SIZE, 0);
251
252 return nr_pages;
253}
254
Magnus Damm85645572008-12-19 15:34:41 +0900255static void sh_mobile_lcdc_deferred_io(struct fb_info *info,
256 struct list_head *pagelist)
257{
258 struct sh_mobile_lcdc_chan *ch = info->par;
Magnus Dammef61aae2009-12-07 14:20:06 +0000259 struct sh_mobile_lcdc_board_cfg *bcfg = &ch->cfg.board_cfg;
Magnus Damm85645572008-12-19 15:34:41 +0900260
261 /* enable clocks before accessing hardware */
262 sh_mobile_lcdc_clk_on(ch->lcdc);
263
Paul Mundt5c1a56b2009-11-04 15:59:04 +0900264 /*
265 * It's possible to get here without anything on the pagelist via
266 * sh_mobile_lcdc_deferred_io_touch() or via a userspace fsync()
267 * invocation. In the former case, the acceleration routines are
268 * stepped in to when using the framebuffer console causing the
269 * workqueue to be scheduled without any dirty pages on the list.
270 *
271 * Despite this, a panel update is still needed given that the
272 * acceleration routines have their own methods for writing in
273 * that still need to be updated.
274 *
275 * The fsync() and empty pagelist case could be optimized for,
276 * but we don't bother, as any application exhibiting such
277 * behaviour is fundamentally broken anyways.
278 */
279 if (!list_empty(pagelist)) {
280 unsigned int nr_pages = sh_mobile_lcdc_sginit(info, pagelist);
Paul Mundt1c6a3072009-07-01 06:50:31 +0000281
Paul Mundt5c1a56b2009-11-04 15:59:04 +0900282 /* trigger panel update */
283 dma_map_sg(info->dev, ch->sglist, nr_pages, DMA_TO_DEVICE);
Magnus Dammef61aae2009-12-07 14:20:06 +0000284 if (bcfg->start_transfer)
285 bcfg->start_transfer(bcfg->board_data, ch,
286 &sh_mobile_lcdc_sys_bus_ops);
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200287 lcdc_write_chan(ch, LDSM2R, LDSM2R_OSTRG);
Paul Mundt5c1a56b2009-11-04 15:59:04 +0900288 dma_unmap_sg(info->dev, ch->sglist, nr_pages, DMA_TO_DEVICE);
Magnus Dammef61aae2009-12-07 14:20:06 +0000289 } else {
290 if (bcfg->start_transfer)
291 bcfg->start_transfer(bcfg->board_data, ch,
292 &sh_mobile_lcdc_sys_bus_ops);
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200293 lcdc_write_chan(ch, LDSM2R, LDSM2R_OSTRG);
Magnus Dammef61aae2009-12-07 14:20:06 +0000294 }
Magnus Damm85645572008-12-19 15:34:41 +0900295}
296
297static void sh_mobile_lcdc_deferred_io_touch(struct fb_info *info)
298{
299 struct fb_deferred_io *fbdefio = info->fbdefio;
300
301 if (fbdefio)
302 schedule_delayed_work(&info->deferred_work, fbdefio->delay);
303}
304
305static irqreturn_t sh_mobile_lcdc_irq(int irq, void *data)
306{
307 struct sh_mobile_lcdc_priv *priv = data;
Magnus Damm2feb0752009-03-13 15:36:55 +0000308 struct sh_mobile_lcdc_chan *ch;
Phil Edworthy9dd38812009-09-15 12:00:18 +0000309 unsigned long ldintr;
Magnus Damm2feb0752009-03-13 15:36:55 +0000310 int is_sub;
311 int k;
Magnus Damm85645572008-12-19 15:34:41 +0900312
Laurent Pinchartdc486652011-07-13 12:13:47 +0200313 /* Acknowledge interrupts and disable further VSYNC End IRQs. */
314 ldintr = lcdc_read(priv, _LDINTR);
315 lcdc_write(priv, _LDINTR, (ldintr ^ LDINTR_STATUS_MASK) & ~LDINTR_VEE);
Magnus Damm85645572008-12-19 15:34:41 +0900316
Magnus Damm2feb0752009-03-13 15:36:55 +0000317 /* figure out if this interrupt is for main or sub lcd */
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200318 is_sub = (lcdc_read(priv, _LDSR) & LDSR_MSS) ? 1 : 0;
Magnus Damm2feb0752009-03-13 15:36:55 +0000319
Phil Edworthy9dd38812009-09-15 12:00:18 +0000320 /* wake up channel and disable clocks */
Magnus Damm2feb0752009-03-13 15:36:55 +0000321 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
322 ch = &priv->ch[k];
323
324 if (!ch->enabled)
325 continue;
326
Laurent Pinchartdc486652011-07-13 12:13:47 +0200327 /* Frame End */
Phil Edworthy9dd38812009-09-15 12:00:18 +0000328 if (ldintr & LDINTR_FS) {
329 if (is_sub == lcdc_chan_is_sublcd(ch)) {
330 ch->frame_end = 1;
331 wake_up(&ch->frame_end_wait);
Magnus Damm2feb0752009-03-13 15:36:55 +0000332
Phil Edworthy9dd38812009-09-15 12:00:18 +0000333 sh_mobile_lcdc_clk_off(priv);
334 }
335 }
336
337 /* VSYNC End */
Phil Edworthy40331b22010-02-15 13:57:49 +0000338 if (ldintr & LDINTR_VES)
339 complete(&ch->vsync_completion);
Magnus Damm2feb0752009-03-13 15:36:55 +0000340 }
341
Magnus Damm85645572008-12-19 15:34:41 +0900342 return IRQ_HANDLED;
343}
344
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700345static void sh_mobile_lcdc_start_stop(struct sh_mobile_lcdc_priv *priv,
346 int start)
347{
348 unsigned long tmp = lcdc_read(priv, _LDCNT2R);
349 int k;
350
351 /* start or stop the lcdc */
352 if (start)
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200353 lcdc_write(priv, _LDCNT2R, tmp | LDCNT2R_DO);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700354 else
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200355 lcdc_write(priv, _LDCNT2R, tmp & ~LDCNT2R_DO);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700356
357 /* wait until power is applied/stopped on all channels */
358 for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
359 if (lcdc_read(priv, _LDCNT2R) & priv->ch[k].enabled)
360 while (1) {
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200361 tmp = lcdc_read_chan(&priv->ch[k], LDPMR)
362 & LDPMR_LPS;
363 if (start && tmp == LDPMR_LPS)
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700364 break;
365 if (!start && tmp == 0)
366 break;
367 cpu_relax();
368 }
369
370 if (!start)
371 lcdc_write(priv, _LDDCKSTPR, 1); /* stop dotclock */
372}
373
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000374static void sh_mobile_lcdc_geometry(struct sh_mobile_lcdc_chan *ch)
375{
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000376 struct fb_var_screeninfo *var = &ch->info->var, *display_var = &ch->display_var;
377 unsigned long h_total, hsync_pos, display_h_total;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000378 u32 tmp;
379
380 tmp = ch->ldmt1r_value;
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200381 tmp |= (var->sync & FB_SYNC_VERT_HIGH_ACT) ? 0 : LDMT1R_VPOL;
382 tmp |= (var->sync & FB_SYNC_HOR_HIGH_ACT) ? 0 : LDMT1R_HPOL;
383 tmp |= (ch->cfg.flags & LCDC_FLAGS_DWPOL) ? LDMT1R_DWPOL : 0;
384 tmp |= (ch->cfg.flags & LCDC_FLAGS_DIPOL) ? LDMT1R_DIPOL : 0;
385 tmp |= (ch->cfg.flags & LCDC_FLAGS_DAPOL) ? LDMT1R_DAPOL : 0;
386 tmp |= (ch->cfg.flags & LCDC_FLAGS_HSCNT) ? LDMT1R_HSCNT : 0;
387 tmp |= (ch->cfg.flags & LCDC_FLAGS_DWCNT) ? LDMT1R_DWCNT : 0;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000388 lcdc_write_chan(ch, LDMT1R, tmp);
389
390 /* setup SYS bus */
391 lcdc_write_chan(ch, LDMT2R, ch->cfg.sys_bus_cfg.ldmt2r);
392 lcdc_write_chan(ch, LDMT3R, ch->cfg.sys_bus_cfg.ldmt3r);
393
394 /* horizontal configuration */
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000395 h_total = display_var->xres + display_var->hsync_len +
396 display_var->left_margin + display_var->right_margin;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000397 tmp = h_total / 8; /* HTCN */
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000398 tmp |= (min(display_var->xres, var->xres) / 8) << 16; /* HDCN */
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000399 lcdc_write_chan(ch, LDHCNR, tmp);
400
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000401 hsync_pos = display_var->xres + display_var->right_margin;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000402 tmp = hsync_pos / 8; /* HSYNP */
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000403 tmp |= (display_var->hsync_len / 8) << 16; /* HSYNW */
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000404 lcdc_write_chan(ch, LDHSYNR, tmp);
405
406 /* vertical configuration */
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000407 tmp = display_var->yres + display_var->vsync_len +
408 display_var->upper_margin + display_var->lower_margin; /* VTLN */
409 tmp |= min(display_var->yres, var->yres) << 16; /* VDLN */
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000410 lcdc_write_chan(ch, LDVLNR, tmp);
411
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000412 tmp = display_var->yres + display_var->lower_margin; /* VSYNP */
413 tmp |= display_var->vsync_len << 16; /* VSYNW */
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000414 lcdc_write_chan(ch, LDVSYNR, tmp);
415
416 /* Adjust horizontal synchronisation for HDMI */
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000417 display_h_total = display_var->xres + display_var->hsync_len +
418 display_var->left_margin + display_var->right_margin;
419 tmp = ((display_var->xres & 7) << 24) |
420 ((display_h_total & 7) << 16) |
421 ((display_var->hsync_len & 7) << 8) |
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000422 hsync_pos;
423 lcdc_write_chan(ch, LDHAJR, tmp);
424}
425
Laurent Pinchart9a217e32011-07-13 12:13:47 +0200426/*
427 * __sh_mobile_lcdc_start - Configure and tart the LCDC
428 * @priv: LCDC device
429 *
430 * Configure all enabled channels and start the LCDC device. All external
431 * devices (clocks, MERAM, panels, ...) are not touched by this function.
432 */
433static void __sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv)
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700434{
435 struct sh_mobile_lcdc_chan *ch;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700436 unsigned long tmp;
Magnus Damm417d4822011-01-05 10:21:00 +0000437 int bpp = 0;
Laurent Pinchart9a217e32011-07-13 12:13:47 +0200438 int k, m;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700439
Laurent Pinchart9a217e32011-07-13 12:13:47 +0200440 /* Enable LCDC channels. Read data from external memory, avoid using the
441 * BEU for now.
442 */
443 lcdc_write(priv, _LDCNT2R, priv->ch[0].enabled | priv->ch[1].enabled);
Magnus Damm85645572008-12-19 15:34:41 +0900444
Laurent Pinchart9a217e32011-07-13 12:13:47 +0200445 /* Stop the LCDC first and disable all interrupts. */
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700446 sh_mobile_lcdc_start_stop(priv, 0);
Laurent Pinchart9a217e32011-07-13 12:13:47 +0200447 lcdc_write(priv, _LDINTR, 0);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700448
Laurent Pinchart9a217e32011-07-13 12:13:47 +0200449 /* Configure power supply, dot clocks and start them. */
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700450 tmp = priv->lddckr;
451 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
452 ch = &priv->ch[k];
Laurent Pinchart9a217e32011-07-13 12:13:47 +0200453 if (!ch->enabled)
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700454 continue;
455
Laurent Pinchart9a217e32011-07-13 12:13:47 +0200456 if (!bpp)
457 bpp = ch->info->var.bits_per_pixel;
458
459 /* Power supply */
460 lcdc_write_chan(ch, LDPMR, 0);
461
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700462 m = ch->cfg.clock_divider;
463 if (!m)
464 continue;
465
Laurent Pinchart505c7de52011-07-13 12:13:47 +0200466 /* FIXME: sh7724 can only use 42, 48, 54 and 60 for the divider
467 * denominator.
468 */
469 lcdc_write_chan(ch, LDDCKPAT1R, 0);
470 lcdc_write_chan(ch, LDDCKPAT2R, (1 << (m/2)) - 1);
471
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700472 if (m == 1)
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200473 m = LDDCKR_MOSEL;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700474 tmp |= m << (lcdc_chan_is_sublcd(ch) ? 8 : 0);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700475 }
476
477 lcdc_write(priv, _LDDCKR, tmp);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700478 lcdc_write(priv, _LDDCKSTPR, 0);
479 lcdc_wait_bit(priv, _LDDCKSTPR, ~0, 0);
480
Laurent Pinchart9a217e32011-07-13 12:13:47 +0200481 /* Setup geometry, format, frame buffer memory and operation mode. */
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700482 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
483 ch = &priv->ch[k];
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700484 if (!ch->enabled)
485 continue;
486
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000487 sh_mobile_lcdc_geometry(ch);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700488
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000489 if (ch->info->var.nonstd) {
Laurent Pinchart9a217e32011-07-13 12:13:47 +0200490 tmp = (ch->info->var.nonstd << 16);
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000491 switch (ch->info->var.bits_per_pixel) {
492 case 12:
Laurent Pinchart9a217e32011-07-13 12:13:47 +0200493 tmp |= LDDFR_YF_420;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000494 break;
495 case 16:
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200496 tmp |= LDDFR_YF_422;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000497 break;
498 case 24:
Laurent Pinchart9a217e32011-07-13 12:13:47 +0200499 default:
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200500 tmp |= LDDFR_YF_444;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000501 break;
502 }
503 } else {
504 switch (ch->info->var.bits_per_pixel) {
505 case 16:
Laurent Pinchart9a217e32011-07-13 12:13:47 +0200506 tmp = LDDFR_PKF_RGB16;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000507 break;
508 case 24:
Laurent Pinchart9a217e32011-07-13 12:13:47 +0200509 tmp = LDDFR_PKF_RGB24;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000510 break;
511 case 32:
Laurent Pinchart9a217e32011-07-13 12:13:47 +0200512 default:
513 tmp = LDDFR_PKF_ARGB32;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000514 break;
515 }
Magnus Damm417d4822011-01-05 10:21:00 +0000516 }
Laurent Pinchart9a217e32011-07-13 12:13:47 +0200517
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700518 lcdc_write_chan(ch, LDDFR, tmp);
Laurent Pinchart9a217e32011-07-13 12:13:47 +0200519 lcdc_write_chan(ch, LDMLSR, ch->pitch);
520 lcdc_write_chan(ch, LDSA1R, ch->base_addr_y);
521 if (ch->info->var.nonstd)
522 lcdc_write_chan(ch, LDSA2R, ch->base_addr_c);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700523
Laurent Pinchart9a217e32011-07-13 12:13:47 +0200524 /* When using deferred I/O mode, configure the LCDC for one-shot
525 * operation and enable the frame end interrupt. Otherwise use
526 * continuous read mode.
527 */
528 if (ch->ldmt1r_value & LDMT1R_IFM &&
529 ch->cfg.sys_bus_cfg.deferred_io_msec) {
530 lcdc_write_chan(ch, LDSM1R, LDSM1R_OS);
531 lcdc_write(priv, _LDINTR, LDINTR_FE);
532 } else {
533 lcdc_write_chan(ch, LDSM1R, 0);
534 }
535 }
Damian7caa4342011-05-18 11:10:07 +0000536
Laurent Pinchart9a217e32011-07-13 12:13:47 +0200537 /* Word and long word swap. */
538 if (priv->ch[0].info->var.nonstd)
539 tmp = LDDDSR_LS | LDDDSR_WS | LDDDSR_BS;
540 else {
541 switch (bpp) {
542 case 16:
543 tmp = LDDDSR_LS | LDDDSR_WS;
544 break;
545 case 24:
546 tmp = LDDDSR_LS | LDDDSR_WS | LDDDSR_BS;
547 break;
548 case 32:
549 default:
550 tmp = LDDDSR_LS;
551 break;
552 }
553 }
554 lcdc_write(priv, _LDDDSR, tmp);
Damian7caa4342011-05-18 11:10:07 +0000555
Laurent Pinchart9a217e32011-07-13 12:13:47 +0200556 /* Enable the display output. */
557 lcdc_write(priv, _LDCNT1R, LDCNT1R_DE);
558 sh_mobile_lcdc_start_stop(priv, 1);
559 priv->started = 1;
560}
Damian7caa4342011-05-18 11:10:07 +0000561
Laurent Pinchart9a217e32011-07-13 12:13:47 +0200562static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv)
563{
564 struct sh_mobile_meram_info *mdev = priv->meram_dev;
565 struct sh_mobile_lcdc_board_cfg *board_cfg;
566 struct sh_mobile_lcdc_chan *ch;
567 unsigned long tmp;
568 int ret;
569 int k;
570
571 /* enable clocks before accessing the hardware */
572 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
573 if (priv->ch[k].enabled)
574 sh_mobile_lcdc_clk_on(priv);
575 }
576
577 /* reset */
578 lcdc_write(priv, _LDCNT2R, lcdc_read(priv, _LDCNT2R) | LDCNT2R_BR);
579 lcdc_wait_bit(priv, _LDCNT2R, LDCNT2R_BR, 0);
580
581 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
582 ch = &priv->ch[k];
583
584 if (!ch->enabled)
585 continue;
586
587 board_cfg = &ch->cfg.board_cfg;
588 if (board_cfg->setup_sys) {
589 ret = board_cfg->setup_sys(board_cfg->board_data, ch,
590 &sh_mobile_lcdc_sys_bus_ops);
591 if (ret)
592 return ret;
593 }
594 }
595
596 /* Compute frame buffer base address and pitch for each channel. */
597 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
598 struct sh_mobile_meram_cfg *cfg;
599 int pixelformat;
600
601 ch = &priv->ch[k];
602 if (!ch->enabled)
603 continue;
604
605 ch->base_addr_y = ch->info->fix.smem_start;
606 ch->base_addr_c = ch->base_addr_y
607 + ch->info->var.xres
608 * ch->info->var.yres_virtual;
609 ch->pitch = ch->info->fix.line_length;
610
611 /* Enable MERAM if possible. */
612 cfg = ch->cfg.meram_cfg;
613 if (mdev == NULL || mdev->ops == NULL || cfg == NULL)
614 continue;
615
616 /* we need to de-init configured ICBs before we can
617 * re-initialize them.
618 */
619 if (ch->meram_enabled) {
620 mdev->ops->meram_unregister(mdev, cfg);
Damian7caa4342011-05-18 11:10:07 +0000621 ch->meram_enabled = 0;
Damian7caa4342011-05-18 11:10:07 +0000622 }
623
Laurent Pinchart9a217e32011-07-13 12:13:47 +0200624 if (!ch->info->var.nonstd)
625 pixelformat = SH_MOBILE_MERAM_PF_RGB;
626 else if (ch->info->var.bits_per_pixel == 24)
627 pixelformat = SH_MOBILE_MERAM_PF_NV24;
628 else
629 pixelformat = SH_MOBILE_MERAM_PF_NV;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700630
Laurent Pinchart9a217e32011-07-13 12:13:47 +0200631 ret = mdev->ops->meram_register(mdev, cfg, ch->pitch,
632 ch->info->var.yres, pixelformat,
633 ch->base_addr_y, ch->base_addr_c,
634 &ch->base_addr_y, &ch->base_addr_c,
635 &ch->pitch);
636 if (!ret)
637 ch->meram_enabled = 1;
638 }
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700639
Laurent Pinchart9a217e32011-07-13 12:13:47 +0200640 /* Start the LCDC. */
641 __sh_mobile_lcdc_start(priv);
642
643 /* Setup deferred I/O, tell the board code to enable the panels, and
644 * turn backlight on.
645 */
646 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
647 ch = &priv->ch[k];
648 if (!ch->enabled)
649 continue;
650
Magnus Damm85645572008-12-19 15:34:41 +0900651 tmp = ch->cfg.sys_bus_cfg.deferred_io_msec;
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200652 if (ch->ldmt1r_value & LDMT1R_IFM && tmp) {
Magnus Damm85645572008-12-19 15:34:41 +0900653 ch->defio.deferred_io = sh_mobile_lcdc_deferred_io;
654 ch->defio.delay = msecs_to_jiffies(tmp);
Paul Mundte33afdd2009-07-07 11:24:32 +0900655 ch->info->fbdefio = &ch->defio;
656 fb_deferred_io_init(ch->info);
Magnus Damm85645572008-12-19 15:34:41 +0900657 }
Magnus Damm21bc1f02009-08-15 02:53:16 +0000658
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700659 board_cfg = &ch->cfg.board_cfg;
Alexandre Courbot247f9932011-02-23 08:41:50 +0000660 if (board_cfg->display_on && try_module_get(board_cfg->owner)) {
Guennadi Liakhovetskic2439392010-07-21 10:13:17 +0000661 board_cfg->display_on(board_cfg->board_data, ch->info);
Guennadi Liakhovetski6de9edd2010-09-03 07:20:23 +0000662 module_put(board_cfg->owner);
663 }
Alexandre Courbot3b0fd9d2011-02-16 03:49:01 +0000664
665 if (ch->bl) {
666 ch->bl->props.power = FB_BLANK_UNBLANK;
667 backlight_update_status(ch->bl);
668 }
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700669 }
670
671 return 0;
672}
673
674static void sh_mobile_lcdc_stop(struct sh_mobile_lcdc_priv *priv)
675{
676 struct sh_mobile_lcdc_chan *ch;
677 struct sh_mobile_lcdc_board_cfg *board_cfg;
678 int k;
679
Magnus Damm2feb0752009-03-13 15:36:55 +0000680 /* clean up deferred io and ask board code to disable panel */
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700681 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
682 ch = &priv->ch[k];
Magnus Damm21bc1f02009-08-15 02:53:16 +0000683 if (!ch->enabled)
684 continue;
Magnus Damm2feb0752009-03-13 15:36:55 +0000685
686 /* deferred io mode:
687 * flush frame, and wait for frame end interrupt
688 * clean up deferred io and enable clock
689 */
Guennadi Liakhovetski5ef6b502010-09-03 07:19:57 +0000690 if (ch->info && ch->info->fbdefio) {
Magnus Damm2feb0752009-03-13 15:36:55 +0000691 ch->frame_end = 0;
Paul Mundte33afdd2009-07-07 11:24:32 +0900692 schedule_delayed_work(&ch->info->deferred_work, 0);
Magnus Damm2feb0752009-03-13 15:36:55 +0000693 wait_event(ch->frame_end_wait, ch->frame_end);
Paul Mundte33afdd2009-07-07 11:24:32 +0900694 fb_deferred_io_cleanup(ch->info);
695 ch->info->fbdefio = NULL;
Magnus Damm2feb0752009-03-13 15:36:55 +0000696 sh_mobile_lcdc_clk_on(priv);
697 }
698
Alexandre Courbot3b0fd9d2011-02-16 03:49:01 +0000699 if (ch->bl) {
700 ch->bl->props.power = FB_BLANK_POWERDOWN;
701 backlight_update_status(ch->bl);
702 }
703
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700704 board_cfg = &ch->cfg.board_cfg;
Alexandre Courbot247f9932011-02-23 08:41:50 +0000705 if (board_cfg->display_off && try_module_get(board_cfg->owner)) {
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700706 board_cfg->display_off(board_cfg->board_data);
Guennadi Liakhovetski6de9edd2010-09-03 07:20:23 +0000707 module_put(board_cfg->owner);
708 }
Damian7caa4342011-05-18 11:10:07 +0000709
710 /* disable the meram */
711 if (ch->meram_enabled) {
712 struct sh_mobile_meram_cfg *cfg;
713 struct sh_mobile_meram_info *mdev;
714 cfg = ch->cfg.meram_cfg;
715 mdev = priv->meram_dev;
716 mdev->ops->meram_unregister(mdev, cfg);
717 ch->meram_enabled = 0;
718 }
719
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700720 }
721
722 /* stop the lcdc */
Magnus Damm8e9bb192009-05-20 14:34:43 +0000723 if (priv->started) {
724 sh_mobile_lcdc_start_stop(priv, 0);
725 priv->started = 0;
726 }
Magnus Dammb51339f2008-10-31 20:23:26 +0900727
Magnus Damm85645572008-12-19 15:34:41 +0900728 /* stop clocks */
729 for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
730 if (priv->ch[k].enabled)
731 sh_mobile_lcdc_clk_off(priv);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700732}
733
734static int sh_mobile_lcdc_check_interface(struct sh_mobile_lcdc_chan *ch)
735{
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200736 int interface_type = ch->cfg.interface_type;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700737
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200738 switch (interface_type) {
739 case RGB8:
740 case RGB9:
741 case RGB12A:
742 case RGB12B:
743 case RGB16:
744 case RGB18:
745 case RGB24:
746 case SYS8A:
747 case SYS8B:
748 case SYS8C:
749 case SYS8D:
750 case SYS9:
751 case SYS12:
752 case SYS16A:
753 case SYS16B:
754 case SYS16C:
755 case SYS18:
756 case SYS24:
757 break;
758 default:
759 return -EINVAL;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700760 }
761
762 /* SUBLCD only supports SYS interface */
763 if (lcdc_chan_is_sublcd(ch)) {
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200764 if (!(interface_type & LDMT1R_IFM))
765 return -EINVAL;
766
767 interface_type &= ~LDMT1R_IFM;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700768 }
769
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200770 ch->ldmt1r_value = interface_type;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700771 return 0;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700772}
773
Magnus Dammb51339f2008-10-31 20:23:26 +0900774static int sh_mobile_lcdc_setup_clocks(struct platform_device *pdev,
775 int clock_source,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700776 struct sh_mobile_lcdc_priv *priv)
777{
778 char *str;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700779
780 switch (clock_source) {
Laurent Pinchartce1c0b02011-07-13 12:13:47 +0200781 case LCDC_CLK_BUS:
782 str = "bus_clk";
783 priv->lddckr = LDDCKR_ICKSEL_BUS;
784 break;
785 case LCDC_CLK_PERIPHERAL:
786 str = "peripheral_clk";
787 priv->lddckr = LDDCKR_ICKSEL_MIPI;
788 break;
789 case LCDC_CLK_EXTERNAL:
790 str = NULL;
791 priv->lddckr = LDDCKR_ICKSEL_HDMI;
792 break;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700793 default:
794 return -EINVAL;
795 }
796
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700797 if (str) {
Magnus Dammb51339f2008-10-31 20:23:26 +0900798 priv->dot_clk = clk_get(&pdev->dev, str);
799 if (IS_ERR(priv->dot_clk)) {
800 dev_err(&pdev->dev, "cannot get dot clock %s\n", str);
Magnus Dammb51339f2008-10-31 20:23:26 +0900801 return PTR_ERR(priv->dot_clk);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700802 }
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700803 }
804
Magnus Damm0246c472009-08-14 10:49:08 +0000805 /* Runtime PM support involves two step for this driver:
806 * 1) Enable Runtime PM
807 * 2) Force Runtime PM Resume since hardware is accessed from probe()
808 */
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +0000809 priv->dev = &pdev->dev;
Magnus Damm0246c472009-08-14 10:49:08 +0000810 pm_runtime_enable(priv->dev);
811 pm_runtime_resume(priv->dev);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700812 return 0;
813}
814
815static int sh_mobile_lcdc_setcolreg(u_int regno,
816 u_int red, u_int green, u_int blue,
817 u_int transp, struct fb_info *info)
818{
819 u32 *palette = info->pseudo_palette;
820
821 if (regno >= PALETTE_NR)
822 return -EINVAL;
823
824 /* only FB_VISUAL_TRUECOLOR supported */
825
826 red >>= 16 - info->var.red.length;
827 green >>= 16 - info->var.green.length;
828 blue >>= 16 - info->var.blue.length;
829 transp >>= 16 - info->var.transp.length;
830
831 palette[regno] = (red << info->var.red.offset) |
832 (green << info->var.green.offset) |
833 (blue << info->var.blue.offset) |
834 (transp << info->var.transp.offset);
835
836 return 0;
837}
838
839static struct fb_fix_screeninfo sh_mobile_lcdc_fix = {
840 .id = "SH Mobile LCDC",
841 .type = FB_TYPE_PACKED_PIXELS,
842 .visual = FB_VISUAL_TRUECOLOR,
843 .accel = FB_ACCEL_NONE,
Phil Edworthy9dd38812009-09-15 12:00:18 +0000844 .xpanstep = 0,
845 .ypanstep = 1,
846 .ywrapstep = 0,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700847};
848
Magnus Damm85645572008-12-19 15:34:41 +0900849static void sh_mobile_lcdc_fillrect(struct fb_info *info,
850 const struct fb_fillrect *rect)
851{
852 sys_fillrect(info, rect);
853 sh_mobile_lcdc_deferred_io_touch(info);
854}
855
856static void sh_mobile_lcdc_copyarea(struct fb_info *info,
857 const struct fb_copyarea *area)
858{
859 sys_copyarea(info, area);
860 sh_mobile_lcdc_deferred_io_touch(info);
861}
862
863static void sh_mobile_lcdc_imageblit(struct fb_info *info,
864 const struct fb_image *image)
865{
866 sys_imageblit(info, image);
867 sh_mobile_lcdc_deferred_io_touch(info);
868}
869
Phil Edworthy9dd38812009-09-15 12:00:18 +0000870static int sh_mobile_fb_pan_display(struct fb_var_screeninfo *var,
871 struct fb_info *info)
872{
873 struct sh_mobile_lcdc_chan *ch = info->par;
Phil Edworthy92e1f9a2010-02-11 10:24:25 +0000874 struct sh_mobile_lcdc_priv *priv = ch->lcdc;
875 unsigned long ldrcntr;
876 unsigned long new_pan_offset;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000877 unsigned long base_addr_y, base_addr_c;
878 unsigned long c_offset;
Phil Edworthy9dd38812009-09-15 12:00:18 +0000879
Laurent Pinchartdc1d5ad2011-08-31 13:00:55 +0200880 if (!info->var.nonstd)
881 new_pan_offset = var->yoffset * info->fix.line_length
882 + var->xoffset * (info->var.bits_per_pixel / 8);
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000883 else
Laurent Pinchartdc1d5ad2011-08-31 13:00:55 +0200884 new_pan_offset = var->yoffset * info->fix.line_length
885 + var->xoffset;
Phil Edworthy9dd38812009-09-15 12:00:18 +0000886
Phil Edworthy92e1f9a2010-02-11 10:24:25 +0000887 if (new_pan_offset == ch->pan_offset)
888 return 0; /* No change, do nothing */
889
890 ldrcntr = lcdc_read(priv, _LDRCNTR);
891
892 /* Set the source address for the next refresh */
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000893 base_addr_y = ch->dma_handle + new_pan_offset;
Laurent Pinchartdc1d5ad2011-08-31 13:00:55 +0200894 if (info->var.nonstd) {
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000895 /* Set y offset */
Laurent Pinchartdc1d5ad2011-08-31 13:00:55 +0200896 c_offset = var->yoffset * info->fix.line_length
897 * (info->var.bits_per_pixel - 8) / 8;
898 base_addr_c = ch->dma_handle
899 + info->var.xres * info->var.yres_virtual
900 + c_offset;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000901 /* Set x offset */
902 if (info->var.bits_per_pixel == 24)
903 base_addr_c += 2 * var->xoffset;
904 else
905 base_addr_c += var->xoffset;
Laurent Pinchart49d79ba2011-07-13 12:13:47 +0200906 }
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000907
Laurent Pinchart49d79ba2011-07-13 12:13:47 +0200908 if (ch->meram_enabled) {
Damian7caa4342011-05-18 11:10:07 +0000909 struct sh_mobile_meram_cfg *cfg;
910 struct sh_mobile_meram_info *mdev;
Damian7caa4342011-05-18 11:10:07 +0000911 int ret;
912
913 cfg = ch->cfg.meram_cfg;
914 mdev = priv->meram_dev;
915 ret = mdev->ops->meram_update(mdev, cfg,
916 base_addr_y, base_addr_c,
Laurent Pinchart49d79ba2011-07-13 12:13:47 +0200917 &base_addr_y, &base_addr_c);
Damian7caa4342011-05-18 11:10:07 +0000918 if (ret)
919 return ret;
Damian7caa4342011-05-18 11:10:07 +0000920 }
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +0000921
Laurent Pinchart49d79ba2011-07-13 12:13:47 +0200922 ch->base_addr_y = base_addr_y;
923 ch->base_addr_c = base_addr_c;
924
925 lcdc_write_chan_mirror(ch, LDSA1R, base_addr_y);
Laurent Pinchartdc1d5ad2011-08-31 13:00:55 +0200926 if (info->var.nonstd)
Laurent Pinchart49d79ba2011-07-13 12:13:47 +0200927 lcdc_write_chan_mirror(ch, LDSA2R, base_addr_c);
928
Phil Edworthy92e1f9a2010-02-11 10:24:25 +0000929 if (lcdc_chan_is_sublcd(ch))
930 lcdc_write(ch->lcdc, _LDRCNTR, ldrcntr ^ LDRCNTR_SRS);
931 else
932 lcdc_write(ch->lcdc, _LDRCNTR, ldrcntr ^ LDRCNTR_MRS);
933
934 ch->pan_offset = new_pan_offset;
935
936 sh_mobile_lcdc_deferred_io_touch(info);
Phil Edworthy9dd38812009-09-15 12:00:18 +0000937
938 return 0;
939}
940
Phil Edworthy40331b22010-02-15 13:57:49 +0000941static int sh_mobile_wait_for_vsync(struct fb_info *info)
942{
943 struct sh_mobile_lcdc_chan *ch = info->par;
944 unsigned long ldintr;
945 int ret;
946
Laurent Pinchartdc486652011-07-13 12:13:47 +0200947 /* Enable VSync End interrupt and be careful not to acknowledge any
948 * pending interrupt.
949 */
Phil Edworthy40331b22010-02-15 13:57:49 +0000950 ldintr = lcdc_read(ch->lcdc, _LDINTR);
Laurent Pinchartdc486652011-07-13 12:13:47 +0200951 ldintr |= LDINTR_VEE | LDINTR_STATUS_MASK;
Phil Edworthy40331b22010-02-15 13:57:49 +0000952 lcdc_write(ch->lcdc, _LDINTR, ldintr);
953
954 ret = wait_for_completion_interruptible_timeout(&ch->vsync_completion,
955 msecs_to_jiffies(100));
956 if (!ret)
957 return -ETIMEDOUT;
958
959 return 0;
960}
961
962static int sh_mobile_ioctl(struct fb_info *info, unsigned int cmd,
963 unsigned long arg)
964{
965 int retval;
966
967 switch (cmd) {
968 case FBIO_WAITFORVSYNC:
969 retval = sh_mobile_wait_for_vsync(info);
970 break;
971
972 default:
973 retval = -ENOIOCTLCMD;
974 break;
975 }
976 return retval;
977}
978
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +0000979static void sh_mobile_fb_reconfig(struct fb_info *info)
980{
981 struct sh_mobile_lcdc_chan *ch = info->par;
982 struct fb_videomode mode1, mode2;
983 struct fb_event event;
984 int evnt = FB_EVENT_MODE_CHANGE_ALL;
985
986 if (ch->use_count > 1 || (ch->use_count == 1 && !info->fbcon_par))
987 /* More framebuffer users are active */
988 return;
989
990 fb_var_to_videomode(&mode1, &ch->display_var);
991 fb_var_to_videomode(&mode2, &info->var);
992
993 if (fb_mode_is_equal(&mode1, &mode2))
994 return;
995
996 /* Display has been re-plugged, framebuffer is free now, reconfigure */
997 if (fb_set_var(info, &ch->display_var) < 0)
998 /* Couldn't reconfigure, hopefully, can continue as before */
999 return;
1000
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +00001001 if (info->var.nonstd)
1002 info->fix.line_length = mode1.xres;
1003 else
1004 info->fix.line_length = mode1.xres * (ch->cfg.bpp / 8);
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001005
1006 /*
1007 * fb_set_var() calls the notifier change internally, only if
1008 * FBINFO_MISC_USEREVENT flag is set. Since we do not want to fake a
1009 * user event, we have to call the chain ourselves.
1010 */
1011 event.info = info;
Arnd Hannemanncc267ec2010-11-15 21:43:22 +00001012 event.data = &mode1;
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001013 fb_notifier_call_chain(evnt, &event);
1014}
1015
1016/*
1017 * Locking: both .fb_release() and .fb_open() are called with info->lock held if
1018 * user == 1, or with console sem held, if user == 0.
1019 */
1020static int sh_mobile_release(struct fb_info *info, int user)
1021{
1022 struct sh_mobile_lcdc_chan *ch = info->par;
1023
1024 mutex_lock(&ch->open_lock);
1025 dev_dbg(info->dev, "%s(): %d users\n", __func__, ch->use_count);
1026
1027 ch->use_count--;
1028
1029 /* Nothing to reconfigure, when called from fbcon */
1030 if (user) {
Torben Hohnac751ef2011-01-25 15:07:35 -08001031 console_lock();
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001032 sh_mobile_fb_reconfig(info);
Torben Hohnac751ef2011-01-25 15:07:35 -08001033 console_unlock();
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001034 }
1035
1036 mutex_unlock(&ch->open_lock);
1037
1038 return 0;
1039}
1040
1041static int sh_mobile_open(struct fb_info *info, int user)
1042{
1043 struct sh_mobile_lcdc_chan *ch = info->par;
1044
1045 mutex_lock(&ch->open_lock);
1046 ch->use_count++;
1047
1048 dev_dbg(info->dev, "%s(): %d users\n", __func__, ch->use_count);
1049 mutex_unlock(&ch->open_lock);
1050
1051 return 0;
1052}
1053
1054static int sh_mobile_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1055{
1056 struct sh_mobile_lcdc_chan *ch = info->par;
Magnus Damm417d4822011-01-05 10:21:00 +00001057 struct sh_mobile_lcdc_priv *p = ch->lcdc;
Laurent Pinchart03862192011-08-31 13:00:53 +02001058 unsigned int best_dist = (unsigned int)-1;
1059 unsigned int best_xres = 0;
1060 unsigned int best_yres = 0;
1061 unsigned int i;
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001062
Laurent Pinchart03862192011-08-31 13:00:53 +02001063 if (var->xres > MAX_XRES || var->yres > MAX_YRES)
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001064 return -EINVAL;
Laurent Pinchart03862192011-08-31 13:00:53 +02001065
1066 /* If board code provides us with a list of available modes, make sure
1067 * we use one of them. Find the mode closest to the requested one. The
1068 * distance between two modes is defined as the size of the
1069 * non-overlapping parts of the two rectangles.
1070 */
1071 for (i = 0; i < ch->cfg.num_cfg; ++i) {
1072 const struct fb_videomode *mode = &ch->cfg.lcd_cfg[i];
1073 unsigned int dist;
1074
1075 /* We can only round up. */
1076 if (var->xres > mode->xres || var->yres > mode->yres)
1077 continue;
1078
1079 dist = var->xres * var->yres + mode->xres * mode->yres
1080 - 2 * min(var->xres, mode->xres)
1081 * min(var->yres, mode->yres);
1082
1083 if (dist < best_dist) {
1084 best_xres = mode->xres;
1085 best_yres = mode->yres;
1086 best_dist = dist;
1087 }
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001088 }
Magnus Damm417d4822011-01-05 10:21:00 +00001089
Laurent Pinchart03862192011-08-31 13:00:53 +02001090 /* If no available mode can be used, return an error. */
1091 if (ch->cfg.num_cfg != 0) {
1092 if (best_dist == (unsigned int)-1)
1093 return -EINVAL;
1094
1095 var->xres = best_xres;
1096 var->yres = best_yres;
1097 }
1098
1099 /* Make sure the virtual resolution is at least as big as the visible
1100 * resolution.
1101 */
1102 if (var->xres_virtual < var->xres)
1103 var->xres_virtual = var->xres;
1104 if (var->yres_virtual < var->yres)
1105 var->yres_virtual = var->yres;
1106
1107 if (var->bits_per_pixel <= 16) { /* RGB 565 */
1108 var->bits_per_pixel = 16;
1109 var->red.offset = 11;
1110 var->red.length = 5;
1111 var->green.offset = 5;
1112 var->green.length = 6;
1113 var->blue.offset = 0;
1114 var->blue.length = 5;
1115 var->transp.offset = 0;
1116 var->transp.length = 0;
1117 } else if (var->bits_per_pixel <= 24) { /* RGB 888 */
1118 var->bits_per_pixel = 24;
1119 var->red.offset = 16;
1120 var->red.length = 8;
1121 var->green.offset = 8;
1122 var->green.length = 8;
1123 var->blue.offset = 0;
1124 var->blue.length = 8;
1125 var->transp.offset = 0;
1126 var->transp.length = 0;
1127 } else if (var->bits_per_pixel <= 32) { /* RGBA 888 */
1128 var->bits_per_pixel = 32;
1129 var->red.offset = 16;
1130 var->red.length = 8;
1131 var->green.offset = 8;
1132 var->green.length = 8;
1133 var->blue.offset = 0;
1134 var->blue.length = 8;
1135 var->transp.offset = 24;
1136 var->transp.length = 8;
1137 } else
1138 return -EINVAL;
1139
1140 var->red.msb_right = 0;
1141 var->green.msb_right = 0;
1142 var->blue.msb_right = 0;
1143 var->transp.msb_right = 0;
1144
1145 /* Make sure we don't exceed our allocated memory. */
1146 if (var->xres_virtual * var->yres_virtual * var->bits_per_pixel / 8 >
1147 info->fix.smem_len)
1148 return -EINVAL;
1149
Magnus Damm417d4822011-01-05 10:21:00 +00001150 /* only accept the forced_bpp for dual channel configurations */
1151 if (p->forced_bpp && p->forced_bpp != var->bits_per_pixel)
1152 return -EINVAL;
1153
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001154 return 0;
1155}
Phil Edworthy40331b22010-02-15 13:57:49 +00001156
Laurent Pincharted5bebf2011-08-31 13:00:54 +02001157static int sh_mobile_set_par(struct fb_info *info)
1158{
1159 struct sh_mobile_lcdc_chan *ch = info->par;
1160 int ret;
1161
1162 sh_mobile_lcdc_stop(ch->lcdc);
1163 ret = sh_mobile_lcdc_start(ch->lcdc);
1164 if (ret < 0)
1165 dev_err(info->dev, "%s: unable to restart LCDC\n", __func__);
1166
1167 return ret;
1168}
1169
Alexandre Courbot8857b9a2011-02-23 08:36:30 +00001170/*
1171 * Screen blanking. Behavior is as follows:
1172 * FB_BLANK_UNBLANK: screen unblanked, clocks enabled
1173 * FB_BLANK_NORMAL: screen blanked, clocks enabled
1174 * FB_BLANK_VSYNC,
1175 * FB_BLANK_HSYNC,
1176 * FB_BLANK_POWEROFF: screen blanked, clocks disabled
1177 */
1178static int sh_mobile_lcdc_blank(int blank, struct fb_info *info)
1179{
1180 struct sh_mobile_lcdc_chan *ch = info->par;
1181 struct sh_mobile_lcdc_priv *p = ch->lcdc;
1182
1183 /* blank the screen? */
1184 if (blank > FB_BLANK_UNBLANK && ch->blank_status == FB_BLANK_UNBLANK) {
1185 struct fb_fillrect rect = {
1186 .width = info->var.xres,
1187 .height = info->var.yres,
1188 };
1189 sh_mobile_lcdc_fillrect(info, &rect);
1190 }
1191 /* turn clocks on? */
1192 if (blank <= FB_BLANK_NORMAL && ch->blank_status > FB_BLANK_NORMAL) {
1193 sh_mobile_lcdc_clk_on(p);
1194 }
1195 /* turn clocks off? */
1196 if (blank > FB_BLANK_NORMAL && ch->blank_status <= FB_BLANK_NORMAL) {
1197 /* make sure the screen is updated with the black fill before
1198 * switching the clocks off. one vsync is not enough since
1199 * blanking may occur in the middle of a refresh. deferred io
1200 * mode will reenable the clocks and update the screen in time,
1201 * so it does not need this. */
1202 if (!info->fbdefio) {
1203 sh_mobile_wait_for_vsync(info);
1204 sh_mobile_wait_for_vsync(info);
1205 }
1206 sh_mobile_lcdc_clk_off(p);
1207 }
1208
1209 ch->blank_status = blank;
1210 return 0;
1211}
1212
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001213static struct fb_ops sh_mobile_lcdc_ops = {
Phil Edworthy9dd38812009-09-15 12:00:18 +00001214 .owner = THIS_MODULE,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001215 .fb_setcolreg = sh_mobile_lcdc_setcolreg,
Magnus Damm2540c112008-12-17 17:29:49 +09001216 .fb_read = fb_sys_read,
1217 .fb_write = fb_sys_write,
Magnus Damm85645572008-12-19 15:34:41 +09001218 .fb_fillrect = sh_mobile_lcdc_fillrect,
1219 .fb_copyarea = sh_mobile_lcdc_copyarea,
1220 .fb_imageblit = sh_mobile_lcdc_imageblit,
Alexandre Courbot8857b9a2011-02-23 08:36:30 +00001221 .fb_blank = sh_mobile_lcdc_blank,
Phil Edworthy9dd38812009-09-15 12:00:18 +00001222 .fb_pan_display = sh_mobile_fb_pan_display,
Phil Edworthy40331b22010-02-15 13:57:49 +00001223 .fb_ioctl = sh_mobile_ioctl,
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001224 .fb_open = sh_mobile_open,
1225 .fb_release = sh_mobile_release,
1226 .fb_check_var = sh_mobile_check_var,
Laurent Pincharted5bebf2011-08-31 13:00:54 +02001227 .fb_set_par = sh_mobile_set_par,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001228};
1229
Alexandre Courbot3b0fd9d2011-02-16 03:49:01 +00001230static int sh_mobile_lcdc_update_bl(struct backlight_device *bdev)
1231{
1232 struct sh_mobile_lcdc_chan *ch = bl_get_data(bdev);
1233 struct sh_mobile_lcdc_board_cfg *cfg = &ch->cfg.board_cfg;
1234 int brightness = bdev->props.brightness;
1235
1236 if (bdev->props.power != FB_BLANK_UNBLANK ||
1237 bdev->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK))
1238 brightness = 0;
1239
1240 return cfg->set_brightness(cfg->board_data, brightness);
1241}
1242
1243static int sh_mobile_lcdc_get_brightness(struct backlight_device *bdev)
1244{
1245 struct sh_mobile_lcdc_chan *ch = bl_get_data(bdev);
1246 struct sh_mobile_lcdc_board_cfg *cfg = &ch->cfg.board_cfg;
1247
1248 return cfg->get_brightness(cfg->board_data);
1249}
1250
1251static int sh_mobile_lcdc_check_fb(struct backlight_device *bdev,
1252 struct fb_info *info)
1253{
1254 return (info->bl_dev == bdev);
1255}
1256
1257static struct backlight_ops sh_mobile_lcdc_bl_ops = {
1258 .options = BL_CORE_SUSPENDRESUME,
1259 .update_status = sh_mobile_lcdc_update_bl,
1260 .get_brightness = sh_mobile_lcdc_get_brightness,
1261 .check_fb = sh_mobile_lcdc_check_fb,
1262};
1263
1264static struct backlight_device *sh_mobile_lcdc_bl_probe(struct device *parent,
1265 struct sh_mobile_lcdc_chan *ch)
1266{
1267 struct backlight_device *bl;
1268
1269 bl = backlight_device_register(ch->cfg.bl_info.name, parent, ch,
1270 &sh_mobile_lcdc_bl_ops, NULL);
Dan Carpenterbeee1f22011-03-21 15:03:13 +00001271 if (IS_ERR(bl)) {
1272 dev_err(parent, "unable to register backlight device: %ld\n",
1273 PTR_ERR(bl));
Alexandre Courbot3b0fd9d2011-02-16 03:49:01 +00001274 return NULL;
1275 }
1276
1277 bl->props.max_brightness = ch->cfg.bl_info.max_brightness;
1278 bl->props.brightness = bl->props.max_brightness;
1279 backlight_update_status(bl);
1280
1281 return bl;
1282}
1283
1284static void sh_mobile_lcdc_bl_remove(struct backlight_device *bdev)
1285{
1286 backlight_device_unregister(bdev);
1287}
1288
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +00001289static int sh_mobile_lcdc_set_bpp(struct fb_var_screeninfo *var, int bpp,
1290 int nonstd)
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001291{
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +00001292 if (nonstd) {
1293 switch (bpp) {
1294 case 12:
1295 case 16:
1296 case 24:
1297 var->bits_per_pixel = bpp;
1298 var->nonstd = nonstd;
1299 return 0;
1300 default:
1301 return -EINVAL;
1302 }
1303 }
1304
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001305 switch (bpp) {
1306 case 16: /* PKF[4:0] = 00011 - RGB 565 */
1307 var->red.offset = 11;
1308 var->red.length = 5;
1309 var->green.offset = 5;
1310 var->green.length = 6;
1311 var->blue.offset = 0;
1312 var->blue.length = 5;
1313 var->transp.offset = 0;
1314 var->transp.length = 0;
1315 break;
1316
Magnus Damm417d4822011-01-05 10:21:00 +00001317 case 24: /* PKF[4:0] = 01011 - RGB 888 */
1318 var->red.offset = 16;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001319 var->red.length = 8;
Magnus Damm417d4822011-01-05 10:21:00 +00001320 var->green.offset = 8;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001321 var->green.length = 8;
Magnus Damm417d4822011-01-05 10:21:00 +00001322 var->blue.offset = 0;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001323 var->blue.length = 8;
1324 var->transp.offset = 0;
1325 var->transp.length = 0;
1326 break;
Magnus Damm417d4822011-01-05 10:21:00 +00001327
1328 case 32: /* PKF[4:0] = 00000 - RGBA 888 */
1329 var->red.offset = 16;
1330 var->red.length = 8;
1331 var->green.offset = 8;
1332 var->green.length = 8;
1333 var->blue.offset = 0;
1334 var->blue.length = 8;
1335 var->transp.offset = 24;
1336 var->transp.length = 8;
1337 break;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001338 default:
1339 return -EINVAL;
1340 }
1341 var->bits_per_pixel = bpp;
1342 var->red.msb_right = 0;
1343 var->green.msb_right = 0;
1344 var->blue.msb_right = 0;
1345 var->transp.msb_right = 0;
1346 return 0;
1347}
1348
Magnus Damm2feb0752009-03-13 15:36:55 +00001349static int sh_mobile_lcdc_suspend(struct device *dev)
1350{
1351 struct platform_device *pdev = to_platform_device(dev);
1352
1353 sh_mobile_lcdc_stop(platform_get_drvdata(pdev));
1354 return 0;
1355}
1356
1357static int sh_mobile_lcdc_resume(struct device *dev)
1358{
1359 struct platform_device *pdev = to_platform_device(dev);
1360
1361 return sh_mobile_lcdc_start(platform_get_drvdata(pdev));
1362}
1363
Magnus Damm0246c472009-08-14 10:49:08 +00001364static int sh_mobile_lcdc_runtime_suspend(struct device *dev)
1365{
1366 struct platform_device *pdev = to_platform_device(dev);
Laurent Pinchart2427bb22011-07-13 12:13:47 +02001367 struct sh_mobile_lcdc_priv *priv = platform_get_drvdata(pdev);
Magnus Damm0246c472009-08-14 10:49:08 +00001368
1369 /* turn off LCDC hardware */
Laurent Pinchart2427bb22011-07-13 12:13:47 +02001370 lcdc_write(priv, _LDCNT1R, 0);
1371
Magnus Damm0246c472009-08-14 10:49:08 +00001372 return 0;
1373}
1374
1375static int sh_mobile_lcdc_runtime_resume(struct device *dev)
1376{
1377 struct platform_device *pdev = to_platform_device(dev);
Laurent Pinchart2427bb22011-07-13 12:13:47 +02001378 struct sh_mobile_lcdc_priv *priv = platform_get_drvdata(pdev);
Magnus Damm0246c472009-08-14 10:49:08 +00001379
Laurent Pinchart2427bb22011-07-13 12:13:47 +02001380 __sh_mobile_lcdc_start(priv);
Magnus Damm0246c472009-08-14 10:49:08 +00001381
1382 return 0;
1383}
1384
Alexey Dobriyan47145212009-12-14 18:00:08 -08001385static const struct dev_pm_ops sh_mobile_lcdc_dev_pm_ops = {
Magnus Damm2feb0752009-03-13 15:36:55 +00001386 .suspend = sh_mobile_lcdc_suspend,
1387 .resume = sh_mobile_lcdc_resume,
Magnus Damm0246c472009-08-14 10:49:08 +00001388 .runtime_suspend = sh_mobile_lcdc_runtime_suspend,
1389 .runtime_resume = sh_mobile_lcdc_runtime_resume,
Magnus Damm2feb0752009-03-13 15:36:55 +00001390};
1391
Guennadi Liakhovetski6de9edd2010-09-03 07:20:23 +00001392/* locking: called with info->lock held */
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001393static int sh_mobile_lcdc_notify(struct notifier_block *nb,
1394 unsigned long action, void *data)
1395{
1396 struct fb_event *event = data;
1397 struct fb_info *info = event->info;
1398 struct sh_mobile_lcdc_chan *ch = info->par;
1399 struct sh_mobile_lcdc_board_cfg *board_cfg = &ch->cfg.board_cfg;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001400
1401 if (&ch->lcdc->notifier != nb)
Guennadi Liakhovetskibaf16372010-09-03 07:20:08 +00001402 return NOTIFY_DONE;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001403
1404 dev_dbg(info->dev, "%s(): action = %lu, data = %p\n",
1405 __func__, action, event->data);
1406
1407 switch(action) {
1408 case FB_EVENT_SUSPEND:
Alexandre Courbot247f9932011-02-23 08:41:50 +00001409 if (board_cfg->display_off && try_module_get(board_cfg->owner)) {
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001410 board_cfg->display_off(board_cfg->board_data);
Guennadi Liakhovetski6de9edd2010-09-03 07:20:23 +00001411 module_put(board_cfg->owner);
1412 }
Guennadi Liakhovetskiafe417c2010-09-03 07:20:39 +00001413 sh_mobile_lcdc_stop(ch->lcdc);
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001414 break;
1415 case FB_EVENT_RESUME:
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001416 mutex_lock(&ch->open_lock);
1417 sh_mobile_fb_reconfig(info);
1418 mutex_unlock(&ch->open_lock);
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001419
1420 /* HDMI must be enabled before LCDC configuration */
Alexandre Courbot247f9932011-02-23 08:41:50 +00001421 if (board_cfg->display_on && try_module_get(board_cfg->owner)) {
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001422 board_cfg->display_on(board_cfg->board_data, info);
Guennadi Liakhovetski6de9edd2010-09-03 07:20:23 +00001423 module_put(board_cfg->owner);
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001424 }
1425
Guennadi Liakhovetskiebe5e122011-05-05 16:33:40 +00001426 sh_mobile_lcdc_start(ch->lcdc);
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001427 }
1428
Guennadi Liakhovetskibaf16372010-09-03 07:20:08 +00001429 return NOTIFY_OK;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001430}
1431
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001432static int sh_mobile_lcdc_remove(struct platform_device *pdev);
1433
Uwe Kleine-Königc2e13032010-02-04 20:56:51 +01001434static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001435{
1436 struct fb_info *info;
1437 struct sh_mobile_lcdc_priv *priv;
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001438 struct sh_mobile_lcdc_info *pdata = pdev->dev.platform_data;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001439 struct resource *res;
1440 int error;
1441 void *buf;
1442 int i, j;
1443
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001444 if (!pdata) {
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001445 dev_err(&pdev->dev, "no platform data defined\n");
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001446 return -EINVAL;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001447 }
1448
1449 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Magnus Damm85645572008-12-19 15:34:41 +09001450 i = platform_get_irq(pdev, 0);
1451 if (!res || i < 0) {
1452 dev_err(&pdev->dev, "cannot get platform resources\n");
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001453 return -ENOENT;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001454 }
1455
1456 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
1457 if (!priv) {
1458 dev_err(&pdev->dev, "cannot allocate device data\n");
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001459 return -ENOMEM;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001460 }
1461
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001462 platform_set_drvdata(pdev, priv);
1463
Magnus Damm85645572008-12-19 15:34:41 +09001464 error = request_irq(i, sh_mobile_lcdc_irq, IRQF_DISABLED,
Kay Sievers7ad33e72009-03-24 16:38:21 -07001465 dev_name(&pdev->dev), priv);
Magnus Damm85645572008-12-19 15:34:41 +09001466 if (error) {
1467 dev_err(&pdev->dev, "unable to request irq\n");
1468 goto err1;
1469 }
1470
1471 priv->irq = i;
Guennadi Liakhovetski5ef6b502010-09-03 07:19:57 +00001472 atomic_set(&priv->hw_usecnt, -1);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001473
1474 j = 0;
1475 for (i = 0; i < ARRAY_SIZE(pdata->ch); i++) {
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001476 struct sh_mobile_lcdc_chan *ch = priv->ch + j;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001477
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001478 ch->lcdc = priv;
1479 memcpy(&ch->cfg, &pdata->ch[i], sizeof(pdata->ch[i]));
1480
1481 error = sh_mobile_lcdc_check_interface(ch);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001482 if (error) {
1483 dev_err(&pdev->dev, "unsupported interface type\n");
1484 goto err1;
1485 }
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001486 init_waitqueue_head(&ch->frame_end_wait);
1487 init_completion(&ch->vsync_completion);
1488 ch->pan_offset = 0;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001489
Alexandre Courbot3b0fd9d2011-02-16 03:49:01 +00001490 /* probe the backlight is there is one defined */
1491 if (ch->cfg.bl_info.max_brightness)
1492 ch->bl = sh_mobile_lcdc_bl_probe(&pdev->dev, ch);
1493
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001494 switch (pdata->ch[i].chan) {
1495 case LCDC_CHAN_MAINLCD:
Laurent Pinchartce1c0b02011-07-13 12:13:47 +02001496 ch->enabled = LDCNT2R_ME;
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001497 ch->reg_offs = lcdc_offs_mainlcd;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001498 j++;
1499 break;
1500 case LCDC_CHAN_SUBLCD:
Laurent Pinchartce1c0b02011-07-13 12:13:47 +02001501 ch->enabled = LDCNT2R_SE;
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001502 ch->reg_offs = lcdc_offs_sublcd;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001503 j++;
1504 break;
1505 }
1506 }
1507
1508 if (!j) {
1509 dev_err(&pdev->dev, "no channels defined\n");
1510 error = -EINVAL;
1511 goto err1;
1512 }
1513
Magnus Damm417d4822011-01-05 10:21:00 +00001514 /* for dual channel LCDC (MAIN + SUB) force shared bpp setting */
1515 if (j == 2)
1516 priv->forced_bpp = pdata->ch[0].bpp;
1517
Guennadi Liakhovetskidba6f382010-06-30 09:26:35 +00001518 priv->base = ioremap_nocache(res->start, resource_size(res));
1519 if (!priv->base)
1520 goto err1;
1521
Magnus Dammb51339f2008-10-31 20:23:26 +09001522 error = sh_mobile_lcdc_setup_clocks(pdev, pdata->clock_source, priv);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001523 if (error) {
1524 dev_err(&pdev->dev, "unable to setup clocks\n");
1525 goto err1;
1526 }
1527
Damian7caa4342011-05-18 11:10:07 +00001528 priv->meram_dev = pdata->meram_dev;
1529
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001530 for (i = 0; i < j; i++) {
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001531 struct fb_var_screeninfo *var;
Guennadi Liakhovetski71d3b0f2010-09-03 07:20:12 +00001532 const struct fb_videomode *lcd_cfg, *max_cfg = NULL;
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001533 struct sh_mobile_lcdc_chan *ch = priv->ch + i;
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001534 struct sh_mobile_lcdc_chan_cfg *cfg = &ch->cfg;
1535 const struct fb_videomode *mode = cfg->lcd_cfg;
Guennadi Liakhovetski71d3b0f2010-09-03 07:20:12 +00001536 unsigned long max_size = 0;
1537 int k;
Guennadi Liakhovetski5fd284e2010-11-04 11:06:11 +00001538 int num_cfg;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001539
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001540 ch->info = framebuffer_alloc(0, &pdev->dev);
1541 if (!ch->info) {
Paul Mundte33afdd2009-07-07 11:24:32 +09001542 dev_err(&pdev->dev, "unable to allocate fb_info\n");
1543 error = -ENOMEM;
1544 break;
1545 }
1546
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001547 info = ch->info;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001548 var = &info->var;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001549 info->fbops = &sh_mobile_lcdc_ops;
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001550 info->par = ch;
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001551
1552 mutex_init(&ch->open_lock);
1553
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001554 for (k = 0, lcd_cfg = mode;
1555 k < cfg->num_cfg && lcd_cfg;
Guennadi Liakhovetski71d3b0f2010-09-03 07:20:12 +00001556 k++, lcd_cfg++) {
1557 unsigned long size = lcd_cfg->yres * lcd_cfg->xres;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +00001558 /* NV12 buffers must have even number of lines */
1559 if ((cfg->nonstd) && cfg->bpp == 12 &&
1560 (lcd_cfg->yres & 0x1)) {
1561 dev_err(&pdev->dev, "yres must be multiple of 2"
1562 " for YCbCr420 mode.\n");
1563 error = -EINVAL;
1564 goto err1;
1565 }
Guennadi Liakhovetski71d3b0f2010-09-03 07:20:12 +00001566
1567 if (size > max_size) {
1568 max_cfg = lcd_cfg;
1569 max_size = size;
1570 }
1571 }
1572
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001573 if (!mode)
Guennadi Liakhovetskid2ecbab2010-11-04 11:06:06 +00001574 max_size = MAX_XRES * MAX_YRES;
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001575 else if (max_cfg)
1576 dev_dbg(&pdev->dev, "Found largest videomode %ux%u\n",
1577 max_cfg->xres, max_cfg->yres);
Guennadi Liakhovetski71d3b0f2010-09-03 07:20:12 +00001578
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001579 info->fix = sh_mobile_lcdc_fix;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +00001580 info->fix.smem_len = max_size * 2 * cfg->bpp / 8;
1581
1582 /* Only pan in 2 line steps for NV12 */
1583 if (cfg->nonstd && cfg->bpp == 12)
1584 info->fix.ypanstep = 2;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001585
Guennadi Liakhovetski5fd284e2010-11-04 11:06:11 +00001586 if (!mode) {
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001587 mode = &default_720p;
Guennadi Liakhovetski5fd284e2010-11-04 11:06:11 +00001588 num_cfg = 1;
1589 } else {
Guennadi Liakhovetskie0b9fb22010-12-21 11:46:26 +01001590 num_cfg = cfg->num_cfg;
Guennadi Liakhovetski5fd284e2010-11-04 11:06:11 +00001591 }
1592
1593 fb_videomode_to_modelist(mode, num_cfg, &info->modelist);
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001594
1595 fb_videomode_to_var(var, mode);
Guennadi Liakhovetskie0b9fb22010-12-21 11:46:26 +01001596 var->width = cfg->lcd_size_cfg.width;
1597 var->height = cfg->lcd_size_cfg.height;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001598 /* Default Y virtual resolution is 2x panel size */
1599 var->yres_virtual = var->yres * 2;
Paul Mundt1c6a3072009-07-01 06:50:31 +00001600 var->activate = FB_ACTIVATE_NOW;
Paul Mundt1c6a3072009-07-01 06:50:31 +00001601
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +00001602 error = sh_mobile_lcdc_set_bpp(var, cfg->bpp, cfg->nonstd);
Paul Mundt1c6a3072009-07-01 06:50:31 +00001603 if (error)
1604 break;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001605
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001606 buf = dma_alloc_coherent(&pdev->dev, info->fix.smem_len,
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001607 &ch->dma_handle, GFP_KERNEL);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001608 if (!buf) {
1609 dev_err(&pdev->dev, "unable to allocate buffer\n");
1610 error = -ENOMEM;
1611 break;
1612 }
1613
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001614 info->pseudo_palette = &ch->pseudo_palette;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001615 info->flags = FBINFO_FLAG_DEFAULT;
1616
1617 error = fb_alloc_cmap(&info->cmap, PALETTE_NR, 0);
1618 if (error < 0) {
1619 dev_err(&pdev->dev, "unable to allocate cmap\n");
1620 dma_free_coherent(&pdev->dev, info->fix.smem_len,
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001621 buf, ch->dma_handle);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001622 break;
1623 }
1624
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001625 info->fix.smem_start = ch->dma_handle;
Damian Hobson-Garcia53b50312011-02-24 05:47:13 +00001626 if (var->nonstd)
1627 info->fix.line_length = var->xres;
1628 else
1629 info->fix.line_length = var->xres * (cfg->bpp / 8);
1630
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001631 info->screen_base = buf;
1632 info->device = &pdev->dev;
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +00001633 ch->display_var = *var;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001634 }
1635
1636 if (error)
1637 goto err1;
1638
1639 error = sh_mobile_lcdc_start(priv);
1640 if (error) {
1641 dev_err(&pdev->dev, "unable to start hardware\n");
1642 goto err1;
1643 }
1644
1645 for (i = 0; i < j; i++) {
1646 struct sh_mobile_lcdc_chan *ch = priv->ch + i;
1647
1648 info = ch->info;
1649
1650 if (info->fbdefio) {
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001651 ch->sglist = vmalloc(sizeof(struct scatterlist) *
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001652 info->fix.smem_len >> PAGE_SHIFT);
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001653 if (!ch->sglist) {
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001654 dev_err(&pdev->dev, "cannot allocate sglist\n");
1655 goto err1;
1656 }
1657 }
1658
Alexandre Courbot3b0fd9d2011-02-16 03:49:01 +00001659 info->bl_dev = ch->bl;
1660
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001661 error = register_framebuffer(info);
1662 if (error < 0)
1663 goto err1;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001664
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001665 dev_info(info->dev,
1666 "registered %s/%s as %dx%d %dbpp.\n",
1667 pdev->name,
Paul Mundt1c6a3072009-07-01 06:50:31 +00001668 (ch->cfg.chan == LCDC_CHAN_MAINLCD) ?
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001669 "mainlcd" : "sublcd",
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001670 info->var.xres, info->var.yres,
Paul Mundt1c6a3072009-07-01 06:50:31 +00001671 ch->cfg.bpp);
Magnus Damm85645572008-12-19 15:34:41 +09001672
1673 /* deferred io mode: disable clock to save power */
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001674 if (info->fbdefio || info->state == FBINFO_STATE_SUSPENDED)
Magnus Damm85645572008-12-19 15:34:41 +09001675 sh_mobile_lcdc_clk_off(priv);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001676 }
1677
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001678 /* Failure ignored */
1679 priv->notifier.notifier_call = sh_mobile_lcdc_notify;
1680 fb_register_client(&priv->notifier);
1681
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001682 return 0;
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001683err1:
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001684 sh_mobile_lcdc_remove(pdev);
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001685
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001686 return error;
1687}
1688
1689static int sh_mobile_lcdc_remove(struct platform_device *pdev)
1690{
1691 struct sh_mobile_lcdc_priv *priv = platform_get_drvdata(pdev);
1692 struct fb_info *info;
1693 int i;
1694
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001695 fb_unregister_client(&priv->notifier);
1696
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001697 for (i = 0; i < ARRAY_SIZE(priv->ch); i++)
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001698 if (priv->ch[i].info && priv->ch[i].info->dev)
Paul Mundte33afdd2009-07-07 11:24:32 +09001699 unregister_framebuffer(priv->ch[i].info);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001700
1701 sh_mobile_lcdc_stop(priv);
1702
1703 for (i = 0; i < ARRAY_SIZE(priv->ch); i++) {
Paul Mundte33afdd2009-07-07 11:24:32 +09001704 info = priv->ch[i].info;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001705
Paul Mundte33afdd2009-07-07 11:24:32 +09001706 if (!info || !info->device)
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001707 continue;
1708
Paul Mundt1c6a3072009-07-01 06:50:31 +00001709 if (priv->ch[i].sglist)
1710 vfree(priv->ch[i].sglist);
1711
Magnus Damm1ffbb032010-10-13 07:17:45 +00001712 if (info->screen_base)
1713 dma_free_coherent(&pdev->dev, info->fix.smem_len,
1714 info->screen_base,
1715 priv->ch[i].dma_handle);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001716 fb_dealloc_cmap(&info->cmap);
Paul Mundte33afdd2009-07-07 11:24:32 +09001717 framebuffer_release(info);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001718 }
1719
Alexandre Courbot3b0fd9d2011-02-16 03:49:01 +00001720 for (i = 0; i < ARRAY_SIZE(priv->ch); i++) {
1721 if (priv->ch[i].bl)
1722 sh_mobile_lcdc_bl_remove(priv->ch[i].bl);
1723 }
1724
Magnus Dammb51339f2008-10-31 20:23:26 +09001725 if (priv->dot_clk)
1726 clk_put(priv->dot_clk);
Magnus Damm0246c472009-08-14 10:49:08 +00001727
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001728 if (priv->dev)
1729 pm_runtime_disable(priv->dev);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001730
1731 if (priv->base)
1732 iounmap(priv->base);
1733
Magnus Damm85645572008-12-19 15:34:41 +09001734 if (priv->irq)
1735 free_irq(priv->irq, priv);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001736 kfree(priv);
1737 return 0;
1738}
1739
1740static struct platform_driver sh_mobile_lcdc_driver = {
1741 .driver = {
1742 .name = "sh_mobile_lcdc_fb",
1743 .owner = THIS_MODULE,
Magnus Damm2feb0752009-03-13 15:36:55 +00001744 .pm = &sh_mobile_lcdc_dev_pm_ops,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001745 },
1746 .probe = sh_mobile_lcdc_probe,
1747 .remove = sh_mobile_lcdc_remove,
1748};
1749
1750static int __init sh_mobile_lcdc_init(void)
1751{
1752 return platform_driver_register(&sh_mobile_lcdc_driver);
1753}
1754
1755static void __exit sh_mobile_lcdc_exit(void)
1756{
1757 platform_driver_unregister(&sh_mobile_lcdc_driver);
1758}
1759
1760module_init(sh_mobile_lcdc_init);
1761module_exit(sh_mobile_lcdc_exit);
1762
1763MODULE_DESCRIPTION("SuperH Mobile LCDC Framebuffer driver");
1764MODULE_AUTHOR("Magnus Damm <damm@opensource.se>");
1765MODULE_LICENSE("GPL v2");