blob: a777cb99739ca193ce236f1460d886ccad54728b [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>
Paul Mundt225c9a82008-10-01 16:24:32 +090024#include <video/sh_mobile_lcdc.h>
Magnus Damm85645572008-12-19 15:34:41 +090025#include <asm/atomic.h>
Magnus Dammcfb4f5d2008-07-23 21:31:24 -070026
Guennadi Liakhovetski6de9edd2010-09-03 07:20:23 +000027#include "sh_mobile_lcdcfb.h"
28
Phil Edworthya6f15ad2009-09-15 12:00:30 +000029#define SIDE_B_OFFSET 0x1000
30#define MIRROR_OFFSET 0x2000
Magnus Dammcfb4f5d2008-07-23 21:31:24 -070031
Magnus Dammcfb4f5d2008-07-23 21:31:24 -070032/* shared registers */
33#define _LDDCKR 0x410
34#define _LDDCKSTPR 0x414
35#define _LDINTR 0x468
36#define _LDSR 0x46c
37#define _LDCNT1R 0x470
38#define _LDCNT2R 0x474
Phil Edworthy9dd38812009-09-15 12:00:18 +000039#define _LDRCNTR 0x478
Magnus Dammcfb4f5d2008-07-23 21:31:24 -070040#define _LDDDSR 0x47c
41#define _LDDWD0R 0x800
42#define _LDDRDR 0x840
43#define _LDDWAR 0x900
44#define _LDDRAR 0x904
45
Magnus Damm0246c472009-08-14 10:49:08 +000046/* shared registers and their order for context save/restore */
47static int lcdc_shared_regs[] = {
48 _LDDCKR,
49 _LDDCKSTPR,
50 _LDINTR,
51 _LDDDSR,
52 _LDCNT1R,
53 _LDCNT2R,
54};
55#define NR_SHARED_REGS ARRAY_SIZE(lcdc_shared_regs)
56
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +000057#define DEFAULT_XRES 1280
58#define DEFAULT_YRES 1024
59
Magnus Damm0246c472009-08-14 10:49:08 +000060static unsigned long lcdc_offs_mainlcd[NR_CH_REGS] = {
Magnus Dammcfb4f5d2008-07-23 21:31:24 -070061 [LDDCKPAT1R] = 0x400,
62 [LDDCKPAT2R] = 0x404,
63 [LDMT1R] = 0x418,
64 [LDMT2R] = 0x41c,
65 [LDMT3R] = 0x420,
66 [LDDFR] = 0x424,
67 [LDSM1R] = 0x428,
Magnus Damm85645572008-12-19 15:34:41 +090068 [LDSM2R] = 0x42c,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -070069 [LDSA1R] = 0x430,
70 [LDMLSR] = 0x438,
71 [LDHCNR] = 0x448,
72 [LDHSYNR] = 0x44c,
73 [LDVLNR] = 0x450,
74 [LDVSYNR] = 0x454,
75 [LDPMR] = 0x460,
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +000076 [LDHAJR] = 0x4a0,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -070077};
78
Magnus Damm0246c472009-08-14 10:49:08 +000079static unsigned long lcdc_offs_sublcd[NR_CH_REGS] = {
Magnus Dammcfb4f5d2008-07-23 21:31:24 -070080 [LDDCKPAT1R] = 0x408,
81 [LDDCKPAT2R] = 0x40c,
82 [LDMT1R] = 0x600,
83 [LDMT2R] = 0x604,
84 [LDMT3R] = 0x608,
85 [LDDFR] = 0x60c,
86 [LDSM1R] = 0x610,
Magnus Damm85645572008-12-19 15:34:41 +090087 [LDSM2R] = 0x614,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -070088 [LDSA1R] = 0x618,
89 [LDMLSR] = 0x620,
90 [LDHCNR] = 0x624,
91 [LDHSYNR] = 0x628,
92 [LDVLNR] = 0x62c,
93 [LDVSYNR] = 0x630,
94 [LDPMR] = 0x63c,
95};
96
97#define START_LCDC 0x00000001
98#define LCDC_RESET 0x00000100
99#define DISPLAY_BEU 0x00000008
100#define LCDC_ENABLE 0x00000001
Magnus Damm85645572008-12-19 15:34:41 +0900101#define LDINTR_FE 0x00000400
Phil Edworthy9dd38812009-09-15 12:00:18 +0000102#define LDINTR_VSE 0x00000200
103#define LDINTR_VEE 0x00000100
Magnus Damm85645572008-12-19 15:34:41 +0900104#define LDINTR_FS 0x00000004
Phil Edworthy9dd38812009-09-15 12:00:18 +0000105#define LDINTR_VSS 0x00000002
106#define LDINTR_VES 0x00000001
Phil Edworthya6f15ad2009-09-15 12:00:30 +0000107#define LDRCNTR_SRS 0x00020000
108#define LDRCNTR_SRC 0x00010000
109#define LDRCNTR_MRS 0x00000002
110#define LDRCNTR_MRC 0x00000001
Phil Edworthy40331b22010-02-15 13:57:49 +0000111#define LDSR_MRS 0x00000100
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700112
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +0000113static const struct fb_videomode default_720p = {
114 .name = "HDMI 720p",
115 .xres = 1280,
116 .yres = 720,
117
118 .left_margin = 200,
119 .right_margin = 88,
120 .hsync_len = 48,
121
122 .upper_margin = 20,
123 .lower_margin = 5,
124 .vsync_len = 5,
125
126 .pixclock = 13468,
127 .sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT,
128};
129
Magnus Damm0246c472009-08-14 10:49:08 +0000130struct sh_mobile_lcdc_priv {
131 void __iomem *base;
132 int irq;
133 atomic_t hw_usecnt;
134 struct device *dev;
135 struct clk *dot_clk;
136 unsigned long lddckr;
137 struct sh_mobile_lcdc_chan ch[2];
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000138 struct notifier_block notifier;
Magnus Damm0246c472009-08-14 10:49:08 +0000139 unsigned long saved_shared_regs[NR_SHARED_REGS];
140 int started;
141};
142
Phil Edworthya6f15ad2009-09-15 12:00:30 +0000143static bool banked(int reg_nr)
144{
145 switch (reg_nr) {
146 case LDMT1R:
147 case LDMT2R:
148 case LDMT3R:
149 case LDDFR:
150 case LDSM1R:
151 case LDSA1R:
152 case LDMLSR:
153 case LDHCNR:
154 case LDHSYNR:
155 case LDVLNR:
156 case LDVSYNR:
157 return true;
158 }
159 return false;
160}
161
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700162static void lcdc_write_chan(struct sh_mobile_lcdc_chan *chan,
163 int reg_nr, unsigned long data)
164{
165 iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr]);
Phil Edworthya6f15ad2009-09-15 12:00:30 +0000166 if (banked(reg_nr))
167 iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr] +
168 SIDE_B_OFFSET);
169}
170
171static void lcdc_write_chan_mirror(struct sh_mobile_lcdc_chan *chan,
172 int reg_nr, unsigned long data)
173{
174 iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr] +
175 MIRROR_OFFSET);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700176}
177
178static unsigned long lcdc_read_chan(struct sh_mobile_lcdc_chan *chan,
179 int reg_nr)
180{
181 return ioread32(chan->lcdc->base + chan->reg_offs[reg_nr]);
182}
183
184static void lcdc_write(struct sh_mobile_lcdc_priv *priv,
185 unsigned long reg_offs, unsigned long data)
186{
187 iowrite32(data, priv->base + reg_offs);
188}
189
190static unsigned long lcdc_read(struct sh_mobile_lcdc_priv *priv,
191 unsigned long reg_offs)
192{
193 return ioread32(priv->base + reg_offs);
194}
195
196static void lcdc_wait_bit(struct sh_mobile_lcdc_priv *priv,
197 unsigned long reg_offs,
198 unsigned long mask, unsigned long until)
199{
200 while ((lcdc_read(priv, reg_offs) & mask) != until)
201 cpu_relax();
202}
203
204static int lcdc_chan_is_sublcd(struct sh_mobile_lcdc_chan *chan)
205{
206 return chan->cfg.chan == LCDC_CHAN_SUBLCD;
207}
208
209static void lcdc_sys_write_index(void *handle, unsigned long data)
210{
211 struct sh_mobile_lcdc_chan *ch = handle;
212
213 lcdc_write(ch->lcdc, _LDDWD0R, data | 0x10000000);
214 lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
215 lcdc_write(ch->lcdc, _LDDWAR, 1 | (lcdc_chan_is_sublcd(ch) ? 2 : 0));
Magnus Damm909f10d2009-08-06 14:28:12 +0000216 lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700217}
218
219static void lcdc_sys_write_data(void *handle, unsigned long data)
220{
221 struct sh_mobile_lcdc_chan *ch = handle;
222
223 lcdc_write(ch->lcdc, _LDDWD0R, data | 0x11000000);
224 lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
225 lcdc_write(ch->lcdc, _LDDWAR, 1 | (lcdc_chan_is_sublcd(ch) ? 2 : 0));
Magnus Damm909f10d2009-08-06 14:28:12 +0000226 lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700227}
228
229static unsigned long lcdc_sys_read_data(void *handle)
230{
231 struct sh_mobile_lcdc_chan *ch = handle;
232
233 lcdc_write(ch->lcdc, _LDDRDR, 0x01000000);
234 lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
235 lcdc_write(ch->lcdc, _LDDRAR, 1 | (lcdc_chan_is_sublcd(ch) ? 2 : 0));
236 udelay(1);
Magnus Damm909f10d2009-08-06 14:28:12 +0000237 lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700238
Magnus Dammec56b662009-08-06 14:34:38 +0000239 return lcdc_read(ch->lcdc, _LDDRDR) & 0x3ffff;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700240}
241
242struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
243 lcdc_sys_write_index,
244 lcdc_sys_write_data,
245 lcdc_sys_read_data,
246};
247
Magnus Damm85645572008-12-19 15:34:41 +0900248static void sh_mobile_lcdc_clk_on(struct sh_mobile_lcdc_priv *priv)
249{
Magnus Damm0246c472009-08-14 10:49:08 +0000250 if (atomic_inc_and_test(&priv->hw_usecnt)) {
251 pm_runtime_get_sync(priv->dev);
Magnus Damm85645572008-12-19 15:34:41 +0900252 if (priv->dot_clk)
253 clk_enable(priv->dot_clk);
254 }
255}
256
257static void sh_mobile_lcdc_clk_off(struct sh_mobile_lcdc_priv *priv)
258{
Magnus Damm0246c472009-08-14 10:49:08 +0000259 if (atomic_sub_return(1, &priv->hw_usecnt) == -1) {
Magnus Damm85645572008-12-19 15:34:41 +0900260 if (priv->dot_clk)
261 clk_disable(priv->dot_clk);
Magnus Damm0246c472009-08-14 10:49:08 +0000262 pm_runtime_put(priv->dev);
Magnus Damm85645572008-12-19 15:34:41 +0900263 }
264}
Magnus Damm85645572008-12-19 15:34:41 +0900265
Paul Mundt1c6a3072009-07-01 06:50:31 +0000266static int sh_mobile_lcdc_sginit(struct fb_info *info,
267 struct list_head *pagelist)
268{
269 struct sh_mobile_lcdc_chan *ch = info->par;
270 unsigned int nr_pages_max = info->fix.smem_len >> PAGE_SHIFT;
271 struct page *page;
272 int nr_pages = 0;
273
274 sg_init_table(ch->sglist, nr_pages_max);
275
276 list_for_each_entry(page, pagelist, lru)
277 sg_set_page(&ch->sglist[nr_pages++], page, PAGE_SIZE, 0);
278
279 return nr_pages;
280}
281
Magnus Damm85645572008-12-19 15:34:41 +0900282static void sh_mobile_lcdc_deferred_io(struct fb_info *info,
283 struct list_head *pagelist)
284{
285 struct sh_mobile_lcdc_chan *ch = info->par;
Magnus Dammef61aae2009-12-07 14:20:06 +0000286 struct sh_mobile_lcdc_board_cfg *bcfg = &ch->cfg.board_cfg;
Magnus Damm85645572008-12-19 15:34:41 +0900287
288 /* enable clocks before accessing hardware */
289 sh_mobile_lcdc_clk_on(ch->lcdc);
290
Paul Mundt5c1a56b2009-11-04 15:59:04 +0900291 /*
292 * It's possible to get here without anything on the pagelist via
293 * sh_mobile_lcdc_deferred_io_touch() or via a userspace fsync()
294 * invocation. In the former case, the acceleration routines are
295 * stepped in to when using the framebuffer console causing the
296 * workqueue to be scheduled without any dirty pages on the list.
297 *
298 * Despite this, a panel update is still needed given that the
299 * acceleration routines have their own methods for writing in
300 * that still need to be updated.
301 *
302 * The fsync() and empty pagelist case could be optimized for,
303 * but we don't bother, as any application exhibiting such
304 * behaviour is fundamentally broken anyways.
305 */
306 if (!list_empty(pagelist)) {
307 unsigned int nr_pages = sh_mobile_lcdc_sginit(info, pagelist);
Paul Mundt1c6a3072009-07-01 06:50:31 +0000308
Paul Mundt5c1a56b2009-11-04 15:59:04 +0900309 /* trigger panel update */
310 dma_map_sg(info->dev, ch->sglist, nr_pages, DMA_TO_DEVICE);
Magnus Dammef61aae2009-12-07 14:20:06 +0000311 if (bcfg->start_transfer)
312 bcfg->start_transfer(bcfg->board_data, ch,
313 &sh_mobile_lcdc_sys_bus_ops);
Paul Mundt5c1a56b2009-11-04 15:59:04 +0900314 lcdc_write_chan(ch, LDSM2R, 1);
315 dma_unmap_sg(info->dev, ch->sglist, nr_pages, DMA_TO_DEVICE);
Magnus Dammef61aae2009-12-07 14:20:06 +0000316 } else {
317 if (bcfg->start_transfer)
318 bcfg->start_transfer(bcfg->board_data, ch,
319 &sh_mobile_lcdc_sys_bus_ops);
Paul Mundt5c1a56b2009-11-04 15:59:04 +0900320 lcdc_write_chan(ch, LDSM2R, 1);
Magnus Dammef61aae2009-12-07 14:20:06 +0000321 }
Magnus Damm85645572008-12-19 15:34:41 +0900322}
323
324static void sh_mobile_lcdc_deferred_io_touch(struct fb_info *info)
325{
326 struct fb_deferred_io *fbdefio = info->fbdefio;
327
328 if (fbdefio)
329 schedule_delayed_work(&info->deferred_work, fbdefio->delay);
330}
331
332static irqreturn_t sh_mobile_lcdc_irq(int irq, void *data)
333{
334 struct sh_mobile_lcdc_priv *priv = data;
Magnus Damm2feb0752009-03-13 15:36:55 +0000335 struct sh_mobile_lcdc_chan *ch;
Magnus Damm85645572008-12-19 15:34:41 +0900336 unsigned long tmp;
Phil Edworthy9dd38812009-09-15 12:00:18 +0000337 unsigned long ldintr;
Magnus Damm2feb0752009-03-13 15:36:55 +0000338 int is_sub;
339 int k;
Magnus Damm85645572008-12-19 15:34:41 +0900340
341 /* acknowledge interrupt */
Phil Edworthy9dd38812009-09-15 12:00:18 +0000342 ldintr = tmp = lcdc_read(priv, _LDINTR);
343 /*
344 * disable further VSYNC End IRQs, preserve all other enabled IRQs,
345 * write 0 to bits 0-6 to ack all triggered IRQs.
346 */
347 tmp &= 0xffffff00 & ~LDINTR_VEE;
Magnus Damm85645572008-12-19 15:34:41 +0900348 lcdc_write(priv, _LDINTR, tmp);
349
Magnus Damm2feb0752009-03-13 15:36:55 +0000350 /* figure out if this interrupt is for main or sub lcd */
351 is_sub = (lcdc_read(priv, _LDSR) & (1 << 10)) ? 1 : 0;
352
Phil Edworthy9dd38812009-09-15 12:00:18 +0000353 /* wake up channel and disable clocks */
Magnus Damm2feb0752009-03-13 15:36:55 +0000354 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
355 ch = &priv->ch[k];
356
357 if (!ch->enabled)
358 continue;
359
Phil Edworthy9dd38812009-09-15 12:00:18 +0000360 /* Frame Start */
361 if (ldintr & LDINTR_FS) {
362 if (is_sub == lcdc_chan_is_sublcd(ch)) {
363 ch->frame_end = 1;
364 wake_up(&ch->frame_end_wait);
Magnus Damm2feb0752009-03-13 15:36:55 +0000365
Phil Edworthy9dd38812009-09-15 12:00:18 +0000366 sh_mobile_lcdc_clk_off(priv);
367 }
368 }
369
370 /* VSYNC End */
Phil Edworthy40331b22010-02-15 13:57:49 +0000371 if (ldintr & LDINTR_VES)
372 complete(&ch->vsync_completion);
Magnus Damm2feb0752009-03-13 15:36:55 +0000373 }
374
Magnus Damm85645572008-12-19 15:34:41 +0900375 return IRQ_HANDLED;
376}
377
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700378static void sh_mobile_lcdc_start_stop(struct sh_mobile_lcdc_priv *priv,
379 int start)
380{
381 unsigned long tmp = lcdc_read(priv, _LDCNT2R);
382 int k;
383
384 /* start or stop the lcdc */
385 if (start)
386 lcdc_write(priv, _LDCNT2R, tmp | START_LCDC);
387 else
388 lcdc_write(priv, _LDCNT2R, tmp & ~START_LCDC);
389
390 /* wait until power is applied/stopped on all channels */
391 for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
392 if (lcdc_read(priv, _LDCNT2R) & priv->ch[k].enabled)
393 while (1) {
394 tmp = lcdc_read_chan(&priv->ch[k], LDPMR) & 3;
395 if (start && tmp == 3)
396 break;
397 if (!start && tmp == 0)
398 break;
399 cpu_relax();
400 }
401
402 if (!start)
403 lcdc_write(priv, _LDDCKSTPR, 1); /* stop dotclock */
404}
405
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000406static void sh_mobile_lcdc_geometry(struct sh_mobile_lcdc_chan *ch)
407{
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000408 struct fb_var_screeninfo *var = &ch->info->var, *display_var = &ch->display_var;
409 unsigned long h_total, hsync_pos, display_h_total;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000410 u32 tmp;
411
412 tmp = ch->ldmt1r_value;
413 tmp |= (var->sync & FB_SYNC_VERT_HIGH_ACT) ? 0 : 1 << 28;
414 tmp |= (var->sync & FB_SYNC_HOR_HIGH_ACT) ? 0 : 1 << 27;
415 tmp |= (ch->cfg.flags & LCDC_FLAGS_DWPOL) ? 1 << 26 : 0;
416 tmp |= (ch->cfg.flags & LCDC_FLAGS_DIPOL) ? 1 << 25 : 0;
417 tmp |= (ch->cfg.flags & LCDC_FLAGS_DAPOL) ? 1 << 24 : 0;
418 tmp |= (ch->cfg.flags & LCDC_FLAGS_HSCNT) ? 1 << 17 : 0;
419 tmp |= (ch->cfg.flags & LCDC_FLAGS_DWCNT) ? 1 << 16 : 0;
420 lcdc_write_chan(ch, LDMT1R, tmp);
421
422 /* setup SYS bus */
423 lcdc_write_chan(ch, LDMT2R, ch->cfg.sys_bus_cfg.ldmt2r);
424 lcdc_write_chan(ch, LDMT3R, ch->cfg.sys_bus_cfg.ldmt3r);
425
426 /* horizontal configuration */
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000427 h_total = display_var->xres + display_var->hsync_len +
428 display_var->left_margin + display_var->right_margin;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000429 tmp = h_total / 8; /* HTCN */
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000430 tmp |= (min(display_var->xres, var->xres) / 8) << 16; /* HDCN */
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000431 lcdc_write_chan(ch, LDHCNR, tmp);
432
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000433 hsync_pos = display_var->xres + display_var->right_margin;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000434 tmp = hsync_pos / 8; /* HSYNP */
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000435 tmp |= (display_var->hsync_len / 8) << 16; /* HSYNW */
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000436 lcdc_write_chan(ch, LDHSYNR, tmp);
437
438 /* vertical configuration */
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000439 tmp = display_var->yres + display_var->vsync_len +
440 display_var->upper_margin + display_var->lower_margin; /* VTLN */
441 tmp |= min(display_var->yres, var->yres) << 16; /* VDLN */
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000442 lcdc_write_chan(ch, LDVLNR, tmp);
443
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000444 tmp = display_var->yres + display_var->lower_margin; /* VSYNP */
445 tmp |= display_var->vsync_len << 16; /* VSYNW */
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000446 lcdc_write_chan(ch, LDVSYNR, tmp);
447
448 /* Adjust horizontal synchronisation for HDMI */
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000449 display_h_total = display_var->xres + display_var->hsync_len +
450 display_var->left_margin + display_var->right_margin;
451 tmp = ((display_var->xres & 7) << 24) |
452 ((display_h_total & 7) << 16) |
453 ((display_var->hsync_len & 7) << 8) |
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000454 hsync_pos;
455 lcdc_write_chan(ch, LDHAJR, tmp);
456}
457
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700458static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv)
459{
460 struct sh_mobile_lcdc_chan *ch;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700461 struct sh_mobile_lcdc_board_cfg *board_cfg;
462 unsigned long tmp;
463 int k, m;
464 int ret = 0;
465
Magnus Damm85645572008-12-19 15:34:41 +0900466 /* enable clocks before accessing the hardware */
467 for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
468 if (priv->ch[k].enabled)
469 sh_mobile_lcdc_clk_on(priv);
470
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700471 /* reset */
472 lcdc_write(priv, _LDCNT2R, lcdc_read(priv, _LDCNT2R) | LCDC_RESET);
473 lcdc_wait_bit(priv, _LDCNT2R, LCDC_RESET, 0);
474
475 /* enable LCDC channels */
476 tmp = lcdc_read(priv, _LDCNT2R);
477 tmp |= priv->ch[0].enabled;
478 tmp |= priv->ch[1].enabled;
479 lcdc_write(priv, _LDCNT2R, tmp);
480
481 /* read data from external memory, avoid using the BEU for now */
482 lcdc_write(priv, _LDCNT2R, lcdc_read(priv, _LDCNT2R) & ~DISPLAY_BEU);
483
484 /* stop the lcdc first */
485 sh_mobile_lcdc_start_stop(priv, 0);
486
487 /* configure clocks */
488 tmp = priv->lddckr;
489 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
490 ch = &priv->ch[k];
491
492 if (!priv->ch[k].enabled)
493 continue;
494
495 m = ch->cfg.clock_divider;
496 if (!m)
497 continue;
498
499 if (m == 1)
500 m = 1 << 6;
501 tmp |= m << (lcdc_chan_is_sublcd(ch) ? 8 : 0);
502
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +0000503 /* FIXME: sh7724 can only use 42, 48, 54 and 60 for the divider denominator */
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000504 lcdc_write_chan(ch, LDDCKPAT1R, 0);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700505 lcdc_write_chan(ch, LDDCKPAT2R, (1 << (m/2)) - 1);
506 }
507
508 lcdc_write(priv, _LDDCKR, tmp);
509
510 /* start dotclock again */
511 lcdc_write(priv, _LDDCKSTPR, 0);
512 lcdc_wait_bit(priv, _LDDCKSTPR, ~0, 0);
513
Magnus Damm85645572008-12-19 15:34:41 +0900514 /* interrupts are disabled to begin with */
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700515 lcdc_write(priv, _LDINTR, 0);
516
517 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
518 ch = &priv->ch[k];
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700519
520 if (!ch->enabled)
521 continue;
522
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +0000523 sh_mobile_lcdc_geometry(ch);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700524
525 /* power supply */
526 lcdc_write_chan(ch, LDPMR, 0);
527
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700528 board_cfg = &ch->cfg.board_cfg;
529 if (board_cfg->setup_sys)
530 ret = board_cfg->setup_sys(board_cfg->board_data, ch,
531 &sh_mobile_lcdc_sys_bus_ops);
532 if (ret)
533 return ret;
534 }
535
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700536 /* word and long word swap */
537 lcdc_write(priv, _LDDDSR, lcdc_read(priv, _LDDDSR) | 6);
538
539 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
540 ch = &priv->ch[k];
541
542 if (!priv->ch[k].enabled)
543 continue;
544
545 /* set bpp format in PKF[4:0] */
546 tmp = lcdc_read_chan(ch, LDDFR);
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +0000547 tmp &= ~0x0001001f;
Paul Mundte33afdd2009-07-07 11:24:32 +0900548 tmp |= (ch->info->var.bits_per_pixel == 16) ? 3 : 0;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700549 lcdc_write_chan(ch, LDDFR, tmp);
550
551 /* point out our frame buffer */
Paul Mundte33afdd2009-07-07 11:24:32 +0900552 lcdc_write_chan(ch, LDSA1R, ch->info->fix.smem_start);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700553
554 /* set line size */
Paul Mundte33afdd2009-07-07 11:24:32 +0900555 lcdc_write_chan(ch, LDMLSR, ch->info->fix.line_length);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700556
Magnus Damm85645572008-12-19 15:34:41 +0900557 /* setup deferred io if SYS bus */
558 tmp = ch->cfg.sys_bus_cfg.deferred_io_msec;
559 if (ch->ldmt1r_value & (1 << 12) && tmp) {
560 ch->defio.deferred_io = sh_mobile_lcdc_deferred_io;
561 ch->defio.delay = msecs_to_jiffies(tmp);
Paul Mundte33afdd2009-07-07 11:24:32 +0900562 ch->info->fbdefio = &ch->defio;
563 fb_deferred_io_init(ch->info);
Magnus Damm85645572008-12-19 15:34:41 +0900564
565 /* one-shot mode */
566 lcdc_write_chan(ch, LDSM1R, 1);
567
568 /* enable "Frame End Interrupt Enable" bit */
569 lcdc_write(priv, _LDINTR, LDINTR_FE);
570
571 } else {
572 /* continuous read mode */
573 lcdc_write_chan(ch, LDSM1R, 0);
574 }
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700575 }
576
577 /* display output */
578 lcdc_write(priv, _LDCNT1R, LCDC_ENABLE);
579
580 /* start the lcdc */
581 sh_mobile_lcdc_start_stop(priv, 1);
Magnus Damm8e9bb192009-05-20 14:34:43 +0000582 priv->started = 1;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700583
584 /* tell the board code to enable the panel */
585 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
586 ch = &priv->ch[k];
Magnus Damm21bc1f02009-08-15 02:53:16 +0000587 if (!ch->enabled)
588 continue;
589
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700590 board_cfg = &ch->cfg.board_cfg;
Guennadi Liakhovetski6de9edd2010-09-03 07:20:23 +0000591 if (try_module_get(board_cfg->owner) && board_cfg->display_on) {
Guennadi Liakhovetskic2439392010-07-21 10:13:17 +0000592 board_cfg->display_on(board_cfg->board_data, ch->info);
Guennadi Liakhovetski6de9edd2010-09-03 07:20:23 +0000593 module_put(board_cfg->owner);
594 }
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700595 }
596
597 return 0;
598}
599
600static void sh_mobile_lcdc_stop(struct sh_mobile_lcdc_priv *priv)
601{
602 struct sh_mobile_lcdc_chan *ch;
603 struct sh_mobile_lcdc_board_cfg *board_cfg;
604 int k;
605
Magnus Damm2feb0752009-03-13 15:36:55 +0000606 /* clean up deferred io and ask board code to disable panel */
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700607 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
608 ch = &priv->ch[k];
Magnus Damm21bc1f02009-08-15 02:53:16 +0000609 if (!ch->enabled)
610 continue;
Magnus Damm2feb0752009-03-13 15:36:55 +0000611
612 /* deferred io mode:
613 * flush frame, and wait for frame end interrupt
614 * clean up deferred io and enable clock
615 */
Guennadi Liakhovetski5ef6b502010-09-03 07:19:57 +0000616 if (ch->info && ch->info->fbdefio) {
Magnus Damm2feb0752009-03-13 15:36:55 +0000617 ch->frame_end = 0;
Paul Mundte33afdd2009-07-07 11:24:32 +0900618 schedule_delayed_work(&ch->info->deferred_work, 0);
Magnus Damm2feb0752009-03-13 15:36:55 +0000619 wait_event(ch->frame_end_wait, ch->frame_end);
Paul Mundte33afdd2009-07-07 11:24:32 +0900620 fb_deferred_io_cleanup(ch->info);
621 ch->info->fbdefio = NULL;
Magnus Damm2feb0752009-03-13 15:36:55 +0000622 sh_mobile_lcdc_clk_on(priv);
623 }
624
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700625 board_cfg = &ch->cfg.board_cfg;
Guennadi Liakhovetski6de9edd2010-09-03 07:20:23 +0000626 if (try_module_get(board_cfg->owner) && board_cfg->display_off) {
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700627 board_cfg->display_off(board_cfg->board_data);
Guennadi Liakhovetski6de9edd2010-09-03 07:20:23 +0000628 module_put(board_cfg->owner);
629 }
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700630 }
631
632 /* stop the lcdc */
Magnus Damm8e9bb192009-05-20 14:34:43 +0000633 if (priv->started) {
634 sh_mobile_lcdc_start_stop(priv, 0);
635 priv->started = 0;
636 }
Magnus Dammb51339f2008-10-31 20:23:26 +0900637
Magnus Damm85645572008-12-19 15:34:41 +0900638 /* stop clocks */
639 for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
640 if (priv->ch[k].enabled)
641 sh_mobile_lcdc_clk_off(priv);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700642}
643
644static int sh_mobile_lcdc_check_interface(struct sh_mobile_lcdc_chan *ch)
645{
646 int ifm, miftyp;
647
648 switch (ch->cfg.interface_type) {
649 case RGB8: ifm = 0; miftyp = 0; break;
650 case RGB9: ifm = 0; miftyp = 4; break;
651 case RGB12A: ifm = 0; miftyp = 5; break;
652 case RGB12B: ifm = 0; miftyp = 6; break;
653 case RGB16: ifm = 0; miftyp = 7; break;
654 case RGB18: ifm = 0; miftyp = 10; break;
655 case RGB24: ifm = 0; miftyp = 11; break;
656 case SYS8A: ifm = 1; miftyp = 0; break;
657 case SYS8B: ifm = 1; miftyp = 1; break;
658 case SYS8C: ifm = 1; miftyp = 2; break;
659 case SYS8D: ifm = 1; miftyp = 3; break;
660 case SYS9: ifm = 1; miftyp = 4; break;
661 case SYS12: ifm = 1; miftyp = 5; break;
662 case SYS16A: ifm = 1; miftyp = 7; break;
663 case SYS16B: ifm = 1; miftyp = 8; break;
664 case SYS16C: ifm = 1; miftyp = 9; break;
665 case SYS18: ifm = 1; miftyp = 10; break;
666 case SYS24: ifm = 1; miftyp = 11; break;
667 default: goto bad;
668 }
669
670 /* SUBLCD only supports SYS interface */
671 if (lcdc_chan_is_sublcd(ch)) {
672 if (ifm == 0)
673 goto bad;
674 else
675 ifm = 0;
676 }
677
678 ch->ldmt1r_value = (ifm << 12) | miftyp;
679 return 0;
680 bad:
681 return -EINVAL;
682}
683
Magnus Dammb51339f2008-10-31 20:23:26 +0900684static int sh_mobile_lcdc_setup_clocks(struct platform_device *pdev,
685 int clock_source,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700686 struct sh_mobile_lcdc_priv *priv)
687{
688 char *str;
689 int icksel;
690
691 switch (clock_source) {
692 case LCDC_CLK_BUS: str = "bus_clk"; icksel = 0; break;
693 case LCDC_CLK_PERIPHERAL: str = "peripheral_clk"; icksel = 1; break;
694 case LCDC_CLK_EXTERNAL: str = NULL; icksel = 2; break;
695 default:
696 return -EINVAL;
697 }
698
699 priv->lddckr = icksel << 16;
700
701 if (str) {
Magnus Dammb51339f2008-10-31 20:23:26 +0900702 priv->dot_clk = clk_get(&pdev->dev, str);
703 if (IS_ERR(priv->dot_clk)) {
704 dev_err(&pdev->dev, "cannot get dot clock %s\n", str);
Magnus Dammb51339f2008-10-31 20:23:26 +0900705 return PTR_ERR(priv->dot_clk);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700706 }
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700707 }
708
Magnus Damm0246c472009-08-14 10:49:08 +0000709 /* Runtime PM support involves two step for this driver:
710 * 1) Enable Runtime PM
711 * 2) Force Runtime PM Resume since hardware is accessed from probe()
712 */
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +0000713 priv->dev = &pdev->dev;
Magnus Damm0246c472009-08-14 10:49:08 +0000714 pm_runtime_enable(priv->dev);
715 pm_runtime_resume(priv->dev);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700716 return 0;
717}
718
719static int sh_mobile_lcdc_setcolreg(u_int regno,
720 u_int red, u_int green, u_int blue,
721 u_int transp, struct fb_info *info)
722{
723 u32 *palette = info->pseudo_palette;
724
725 if (regno >= PALETTE_NR)
726 return -EINVAL;
727
728 /* only FB_VISUAL_TRUECOLOR supported */
729
730 red >>= 16 - info->var.red.length;
731 green >>= 16 - info->var.green.length;
732 blue >>= 16 - info->var.blue.length;
733 transp >>= 16 - info->var.transp.length;
734
735 palette[regno] = (red << info->var.red.offset) |
736 (green << info->var.green.offset) |
737 (blue << info->var.blue.offset) |
738 (transp << info->var.transp.offset);
739
740 return 0;
741}
742
743static struct fb_fix_screeninfo sh_mobile_lcdc_fix = {
744 .id = "SH Mobile LCDC",
745 .type = FB_TYPE_PACKED_PIXELS,
746 .visual = FB_VISUAL_TRUECOLOR,
747 .accel = FB_ACCEL_NONE,
Phil Edworthy9dd38812009-09-15 12:00:18 +0000748 .xpanstep = 0,
749 .ypanstep = 1,
750 .ywrapstep = 0,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700751};
752
Magnus Damm85645572008-12-19 15:34:41 +0900753static void sh_mobile_lcdc_fillrect(struct fb_info *info,
754 const struct fb_fillrect *rect)
755{
756 sys_fillrect(info, rect);
757 sh_mobile_lcdc_deferred_io_touch(info);
758}
759
760static void sh_mobile_lcdc_copyarea(struct fb_info *info,
761 const struct fb_copyarea *area)
762{
763 sys_copyarea(info, area);
764 sh_mobile_lcdc_deferred_io_touch(info);
765}
766
767static void sh_mobile_lcdc_imageblit(struct fb_info *info,
768 const struct fb_image *image)
769{
770 sys_imageblit(info, image);
771 sh_mobile_lcdc_deferred_io_touch(info);
772}
773
Phil Edworthy9dd38812009-09-15 12:00:18 +0000774static int sh_mobile_fb_pan_display(struct fb_var_screeninfo *var,
775 struct fb_info *info)
776{
777 struct sh_mobile_lcdc_chan *ch = info->par;
Phil Edworthy92e1f9a2010-02-11 10:24:25 +0000778 struct sh_mobile_lcdc_priv *priv = ch->lcdc;
779 unsigned long ldrcntr;
780 unsigned long new_pan_offset;
Phil Edworthy9dd38812009-09-15 12:00:18 +0000781
Phil Edworthy92e1f9a2010-02-11 10:24:25 +0000782 new_pan_offset = (var->yoffset * info->fix.line_length) +
Phil Edworthy9dd38812009-09-15 12:00:18 +0000783 (var->xoffset * (info->var.bits_per_pixel / 8));
784
Phil Edworthy92e1f9a2010-02-11 10:24:25 +0000785 if (new_pan_offset == ch->pan_offset)
786 return 0; /* No change, do nothing */
787
788 ldrcntr = lcdc_read(priv, _LDRCNTR);
789
790 /* Set the source address for the next refresh */
791 lcdc_write_chan_mirror(ch, LDSA1R, ch->dma_handle + new_pan_offset);
792 if (lcdc_chan_is_sublcd(ch))
793 lcdc_write(ch->lcdc, _LDRCNTR, ldrcntr ^ LDRCNTR_SRS);
794 else
795 lcdc_write(ch->lcdc, _LDRCNTR, ldrcntr ^ LDRCNTR_MRS);
796
797 ch->pan_offset = new_pan_offset;
798
799 sh_mobile_lcdc_deferred_io_touch(info);
Phil Edworthy9dd38812009-09-15 12:00:18 +0000800
801 return 0;
802}
803
Phil Edworthy40331b22010-02-15 13:57:49 +0000804static int sh_mobile_wait_for_vsync(struct fb_info *info)
805{
806 struct sh_mobile_lcdc_chan *ch = info->par;
807 unsigned long ldintr;
808 int ret;
809
810 /* Enable VSync End interrupt */
811 ldintr = lcdc_read(ch->lcdc, _LDINTR);
812 ldintr |= LDINTR_VEE;
813 lcdc_write(ch->lcdc, _LDINTR, ldintr);
814
815 ret = wait_for_completion_interruptible_timeout(&ch->vsync_completion,
816 msecs_to_jiffies(100));
817 if (!ret)
818 return -ETIMEDOUT;
819
820 return 0;
821}
822
823static int sh_mobile_ioctl(struct fb_info *info, unsigned int cmd,
824 unsigned long arg)
825{
826 int retval;
827
828 switch (cmd) {
829 case FBIO_WAITFORVSYNC:
830 retval = sh_mobile_wait_for_vsync(info);
831 break;
832
833 default:
834 retval = -ENOIOCTLCMD;
835 break;
836 }
837 return retval;
838}
839
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +0000840static void sh_mobile_fb_reconfig(struct fb_info *info)
841{
842 struct sh_mobile_lcdc_chan *ch = info->par;
843 struct fb_videomode mode1, mode2;
844 struct fb_event event;
845 int evnt = FB_EVENT_MODE_CHANGE_ALL;
846
847 if (ch->use_count > 1 || (ch->use_count == 1 && !info->fbcon_par))
848 /* More framebuffer users are active */
849 return;
850
851 fb_var_to_videomode(&mode1, &ch->display_var);
852 fb_var_to_videomode(&mode2, &info->var);
853
854 if (fb_mode_is_equal(&mode1, &mode2))
855 return;
856
857 /* Display has been re-plugged, framebuffer is free now, reconfigure */
858 if (fb_set_var(info, &ch->display_var) < 0)
859 /* Couldn't reconfigure, hopefully, can continue as before */
860 return;
861
862 info->fix.line_length = mode2.xres * (ch->cfg.bpp / 8);
863
864 /*
865 * fb_set_var() calls the notifier change internally, only if
866 * FBINFO_MISC_USEREVENT flag is set. Since we do not want to fake a
867 * user event, we have to call the chain ourselves.
868 */
869 event.info = info;
870 event.data = &mode2;
871 fb_notifier_call_chain(evnt, &event);
872}
873
874/*
875 * Locking: both .fb_release() and .fb_open() are called with info->lock held if
876 * user == 1, or with console sem held, if user == 0.
877 */
878static int sh_mobile_release(struct fb_info *info, int user)
879{
880 struct sh_mobile_lcdc_chan *ch = info->par;
881
882 mutex_lock(&ch->open_lock);
883 dev_dbg(info->dev, "%s(): %d users\n", __func__, ch->use_count);
884
885 ch->use_count--;
886
887 /* Nothing to reconfigure, when called from fbcon */
888 if (user) {
889 acquire_console_sem();
890 sh_mobile_fb_reconfig(info);
891 release_console_sem();
892 }
893
894 mutex_unlock(&ch->open_lock);
895
896 return 0;
897}
898
899static int sh_mobile_open(struct fb_info *info, int user)
900{
901 struct sh_mobile_lcdc_chan *ch = info->par;
902
903 mutex_lock(&ch->open_lock);
904 ch->use_count++;
905
906 dev_dbg(info->dev, "%s(): %d users\n", __func__, ch->use_count);
907 mutex_unlock(&ch->open_lock);
908
909 return 0;
910}
911
912static int sh_mobile_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
913{
914 struct sh_mobile_lcdc_chan *ch = info->par;
915
916 if (var->xres < 160 || var->xres > 1920 ||
917 var->yres < 120 || var->yres > 1080 ||
918 var->left_margin < 32 || var->left_margin > 320 ||
919 var->right_margin < 12 || var->right_margin > 240 ||
920 var->upper_margin < 12 || var->upper_margin > 120 ||
921 var->lower_margin < 1 || var->lower_margin > 64 ||
922 var->hsync_len < 32 || var->hsync_len > 120 ||
923 var->vsync_len < 2 || var->vsync_len > 64 ||
924 var->pixclock < 6000 || var->pixclock > 40000 ||
925 var->xres * var->yres * (ch->cfg.bpp / 8) * 2 > info->fix.smem_len) {
926 dev_warn(info->dev, "Invalid info: %u %u %u %u %u %u %u %u %u!\n",
927 var->xres, var->yres,
928 var->left_margin, var->right_margin,
929 var->upper_margin, var->lower_margin,
930 var->hsync_len, var->vsync_len,
931 var->pixclock);
932 return -EINVAL;
933 }
934 return 0;
935}
936
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700937static struct fb_ops sh_mobile_lcdc_ops = {
Phil Edworthy9dd38812009-09-15 12:00:18 +0000938 .owner = THIS_MODULE,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700939 .fb_setcolreg = sh_mobile_lcdc_setcolreg,
Magnus Damm2540c112008-12-17 17:29:49 +0900940 .fb_read = fb_sys_read,
941 .fb_write = fb_sys_write,
Magnus Damm85645572008-12-19 15:34:41 +0900942 .fb_fillrect = sh_mobile_lcdc_fillrect,
943 .fb_copyarea = sh_mobile_lcdc_copyarea,
944 .fb_imageblit = sh_mobile_lcdc_imageblit,
Phil Edworthy9dd38812009-09-15 12:00:18 +0000945 .fb_pan_display = sh_mobile_fb_pan_display,
Phil Edworthy40331b22010-02-15 13:57:49 +0000946 .fb_ioctl = sh_mobile_ioctl,
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +0000947 .fb_open = sh_mobile_open,
948 .fb_release = sh_mobile_release,
949 .fb_check_var = sh_mobile_check_var,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -0700950};
951
952static int sh_mobile_lcdc_set_bpp(struct fb_var_screeninfo *var, int bpp)
953{
954 switch (bpp) {
955 case 16: /* PKF[4:0] = 00011 - RGB 565 */
956 var->red.offset = 11;
957 var->red.length = 5;
958 var->green.offset = 5;
959 var->green.length = 6;
960 var->blue.offset = 0;
961 var->blue.length = 5;
962 var->transp.offset = 0;
963 var->transp.length = 0;
964 break;
965
966 case 32: /* PKF[4:0] = 00000 - RGB 888
967 * sh7722 pdf says 00RRGGBB but reality is GGBB00RR
968 * this may be because LDDDSR has word swap enabled..
969 */
970 var->red.offset = 0;
971 var->red.length = 8;
972 var->green.offset = 24;
973 var->green.length = 8;
974 var->blue.offset = 16;
975 var->blue.length = 8;
976 var->transp.offset = 0;
977 var->transp.length = 0;
978 break;
979 default:
980 return -EINVAL;
981 }
982 var->bits_per_pixel = bpp;
983 var->red.msb_right = 0;
984 var->green.msb_right = 0;
985 var->blue.msb_right = 0;
986 var->transp.msb_right = 0;
987 return 0;
988}
989
Magnus Damm2feb0752009-03-13 15:36:55 +0000990static int sh_mobile_lcdc_suspend(struct device *dev)
991{
992 struct platform_device *pdev = to_platform_device(dev);
993
994 sh_mobile_lcdc_stop(platform_get_drvdata(pdev));
995 return 0;
996}
997
998static int sh_mobile_lcdc_resume(struct device *dev)
999{
1000 struct platform_device *pdev = to_platform_device(dev);
1001
1002 return sh_mobile_lcdc_start(platform_get_drvdata(pdev));
1003}
1004
Magnus Damm0246c472009-08-14 10:49:08 +00001005static int sh_mobile_lcdc_runtime_suspend(struct device *dev)
1006{
1007 struct platform_device *pdev = to_platform_device(dev);
1008 struct sh_mobile_lcdc_priv *p = platform_get_drvdata(pdev);
1009 struct sh_mobile_lcdc_chan *ch;
1010 int k, n;
1011
1012 /* save per-channel registers */
1013 for (k = 0; k < ARRAY_SIZE(p->ch); k++) {
1014 ch = &p->ch[k];
1015 if (!ch->enabled)
1016 continue;
1017 for (n = 0; n < NR_CH_REGS; n++)
1018 ch->saved_ch_regs[n] = lcdc_read_chan(ch, n);
1019 }
1020
1021 /* save shared registers */
1022 for (n = 0; n < NR_SHARED_REGS; n++)
1023 p->saved_shared_regs[n] = lcdc_read(p, lcdc_shared_regs[n]);
1024
1025 /* turn off LCDC hardware */
1026 lcdc_write(p, _LDCNT1R, 0);
1027 return 0;
1028}
1029
1030static int sh_mobile_lcdc_runtime_resume(struct device *dev)
1031{
1032 struct platform_device *pdev = to_platform_device(dev);
1033 struct sh_mobile_lcdc_priv *p = platform_get_drvdata(pdev);
1034 struct sh_mobile_lcdc_chan *ch;
1035 int k, n;
1036
1037 /* restore per-channel registers */
1038 for (k = 0; k < ARRAY_SIZE(p->ch); k++) {
1039 ch = &p->ch[k];
1040 if (!ch->enabled)
1041 continue;
1042 for (n = 0; n < NR_CH_REGS; n++)
1043 lcdc_write_chan(ch, n, ch->saved_ch_regs[n]);
1044 }
1045
1046 /* restore shared registers */
1047 for (n = 0; n < NR_SHARED_REGS; n++)
1048 lcdc_write(p, lcdc_shared_regs[n], p->saved_shared_regs[n]);
1049
1050 return 0;
1051}
1052
Alexey Dobriyan47145212009-12-14 18:00:08 -08001053static const struct dev_pm_ops sh_mobile_lcdc_dev_pm_ops = {
Magnus Damm2feb0752009-03-13 15:36:55 +00001054 .suspend = sh_mobile_lcdc_suspend,
1055 .resume = sh_mobile_lcdc_resume,
Magnus Damm0246c472009-08-14 10:49:08 +00001056 .runtime_suspend = sh_mobile_lcdc_runtime_suspend,
1057 .runtime_resume = sh_mobile_lcdc_runtime_resume,
Magnus Damm2feb0752009-03-13 15:36:55 +00001058};
1059
Guennadi Liakhovetski6de9edd2010-09-03 07:20:23 +00001060/* locking: called with info->lock held */
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001061static int sh_mobile_lcdc_notify(struct notifier_block *nb,
1062 unsigned long action, void *data)
1063{
1064 struct fb_event *event = data;
1065 struct fb_info *info = event->info;
1066 struct sh_mobile_lcdc_chan *ch = info->par;
1067 struct sh_mobile_lcdc_board_cfg *board_cfg = &ch->cfg.board_cfg;
Guennadi Liakhovetskiafe417c2010-09-03 07:20:39 +00001068 int ret;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001069
1070 if (&ch->lcdc->notifier != nb)
Guennadi Liakhovetskibaf16372010-09-03 07:20:08 +00001071 return NOTIFY_DONE;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001072
1073 dev_dbg(info->dev, "%s(): action = %lu, data = %p\n",
1074 __func__, action, event->data);
1075
1076 switch(action) {
1077 case FB_EVENT_SUSPEND:
Guennadi Liakhovetski6de9edd2010-09-03 07:20:23 +00001078 if (try_module_get(board_cfg->owner) && board_cfg->display_off) {
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001079 board_cfg->display_off(board_cfg->board_data);
Guennadi Liakhovetski6de9edd2010-09-03 07:20:23 +00001080 module_put(board_cfg->owner);
1081 }
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001082 pm_runtime_put(info->device);
Guennadi Liakhovetskiafe417c2010-09-03 07:20:39 +00001083 sh_mobile_lcdc_stop(ch->lcdc);
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001084 break;
1085 case FB_EVENT_RESUME:
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001086 mutex_lock(&ch->open_lock);
1087 sh_mobile_fb_reconfig(info);
1088 mutex_unlock(&ch->open_lock);
1089
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001090 /* HDMI must be enabled before LCDC configuration */
Guennadi Liakhovetski6de9edd2010-09-03 07:20:23 +00001091 if (try_module_get(board_cfg->owner) && board_cfg->display_on) {
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001092 board_cfg->display_on(board_cfg->board_data, info);
Guennadi Liakhovetski6de9edd2010-09-03 07:20:23 +00001093 module_put(board_cfg->owner);
1094 }
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001095
Guennadi Liakhovetskiafe417c2010-09-03 07:20:39 +00001096 ret = sh_mobile_lcdc_start(ch->lcdc);
1097 if (!ret)
1098 pm_runtime_get_sync(info->device);
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001099 }
1100
Guennadi Liakhovetskibaf16372010-09-03 07:20:08 +00001101 return NOTIFY_OK;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001102}
1103
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001104static int sh_mobile_lcdc_remove(struct platform_device *pdev);
1105
Uwe Kleine-Königc2e13032010-02-04 20:56:51 +01001106static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001107{
1108 struct fb_info *info;
1109 struct sh_mobile_lcdc_priv *priv;
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001110 struct sh_mobile_lcdc_info *pdata = pdev->dev.platform_data;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001111 struct resource *res;
1112 int error;
1113 void *buf;
1114 int i, j;
1115
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001116 if (!pdata) {
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001117 dev_err(&pdev->dev, "no platform data defined\n");
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001118 return -EINVAL;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001119 }
1120
1121 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Magnus Damm85645572008-12-19 15:34:41 +09001122 i = platform_get_irq(pdev, 0);
1123 if (!res || i < 0) {
1124 dev_err(&pdev->dev, "cannot get platform resources\n");
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001125 return -ENOENT;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001126 }
1127
1128 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
1129 if (!priv) {
1130 dev_err(&pdev->dev, "cannot allocate device data\n");
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001131 return -ENOMEM;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001132 }
1133
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001134 platform_set_drvdata(pdev, priv);
1135
Magnus Damm85645572008-12-19 15:34:41 +09001136 error = request_irq(i, sh_mobile_lcdc_irq, IRQF_DISABLED,
Kay Sievers7ad33e72009-03-24 16:38:21 -07001137 dev_name(&pdev->dev), priv);
Magnus Damm85645572008-12-19 15:34:41 +09001138 if (error) {
1139 dev_err(&pdev->dev, "unable to request irq\n");
1140 goto err1;
1141 }
1142
1143 priv->irq = i;
Guennadi Liakhovetski5ef6b502010-09-03 07:19:57 +00001144 atomic_set(&priv->hw_usecnt, -1);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001145
1146 j = 0;
1147 for (i = 0; i < ARRAY_SIZE(pdata->ch); i++) {
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001148 struct sh_mobile_lcdc_chan *ch = priv->ch + j;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001149
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001150 ch->lcdc = priv;
1151 memcpy(&ch->cfg, &pdata->ch[i], sizeof(pdata->ch[i]));
1152
1153 error = sh_mobile_lcdc_check_interface(ch);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001154 if (error) {
1155 dev_err(&pdev->dev, "unsupported interface type\n");
1156 goto err1;
1157 }
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001158 init_waitqueue_head(&ch->frame_end_wait);
1159 init_completion(&ch->vsync_completion);
1160 ch->pan_offset = 0;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001161
1162 switch (pdata->ch[i].chan) {
1163 case LCDC_CHAN_MAINLCD:
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001164 ch->enabled = 1 << 1;
1165 ch->reg_offs = lcdc_offs_mainlcd;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001166 j++;
1167 break;
1168 case LCDC_CHAN_SUBLCD:
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001169 ch->enabled = 1 << 2;
1170 ch->reg_offs = lcdc_offs_sublcd;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001171 j++;
1172 break;
1173 }
1174 }
1175
1176 if (!j) {
1177 dev_err(&pdev->dev, "no channels defined\n");
1178 error = -EINVAL;
1179 goto err1;
1180 }
1181
Guennadi Liakhovetskidba6f382010-06-30 09:26:35 +00001182 priv->base = ioremap_nocache(res->start, resource_size(res));
1183 if (!priv->base)
1184 goto err1;
1185
Magnus Dammb51339f2008-10-31 20:23:26 +09001186 error = sh_mobile_lcdc_setup_clocks(pdev, pdata->clock_source, priv);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001187 if (error) {
1188 dev_err(&pdev->dev, "unable to setup clocks\n");
1189 goto err1;
1190 }
1191
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001192 for (i = 0; i < j; i++) {
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001193 struct fb_var_screeninfo *var;
Guennadi Liakhovetski71d3b0f2010-09-03 07:20:12 +00001194 const struct fb_videomode *lcd_cfg, *max_cfg = NULL;
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001195 struct sh_mobile_lcdc_chan *ch = priv->ch + i;
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001196 struct sh_mobile_lcdc_chan_cfg *cfg = &ch->cfg;
1197 const struct fb_videomode *mode = cfg->lcd_cfg;
Guennadi Liakhovetski71d3b0f2010-09-03 07:20:12 +00001198 unsigned long max_size = 0;
1199 int k;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001200
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001201 ch->info = framebuffer_alloc(0, &pdev->dev);
1202 if (!ch->info) {
Paul Mundte33afdd2009-07-07 11:24:32 +09001203 dev_err(&pdev->dev, "unable to allocate fb_info\n");
1204 error = -ENOMEM;
1205 break;
1206 }
1207
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001208 info = ch->info;
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001209 var = &info->var;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001210 info->fbops = &sh_mobile_lcdc_ops;
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001211 info->par = ch;
Guennadi Liakhovetskidd210502010-09-14 14:48:54 +00001212
1213 mutex_init(&ch->open_lock);
1214
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001215 for (k = 0, lcd_cfg = mode;
1216 k < cfg->num_cfg && lcd_cfg;
Guennadi Liakhovetski71d3b0f2010-09-03 07:20:12 +00001217 k++, lcd_cfg++) {
1218 unsigned long size = lcd_cfg->yres * lcd_cfg->xres;
1219
1220 if (size > max_size) {
1221 max_cfg = lcd_cfg;
1222 max_size = size;
1223 }
1224 }
1225
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001226 if (!mode)
1227 max_size = DEFAULT_XRES * DEFAULT_YRES;
1228 else if (max_cfg)
1229 dev_dbg(&pdev->dev, "Found largest videomode %ux%u\n",
1230 max_cfg->xres, max_cfg->yres);
Guennadi Liakhovetski71d3b0f2010-09-03 07:20:12 +00001231
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001232 info->fix = sh_mobile_lcdc_fix;
Guennadi Liakhovetski71d3b0f2010-09-03 07:20:12 +00001233 info->fix.smem_len = max_size * (cfg->bpp / 8) * 2;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001234
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001235 if (!mode)
1236 mode = &default_720p;
1237
1238 fb_videomode_to_var(var, mode);
1239 /* Default Y virtual resolution is 2x panel size */
1240 var->yres_virtual = var->yres * 2;
1241 var->activate = FB_ACTIVATE_NOW;
1242
1243 error = sh_mobile_lcdc_set_bpp(var, cfg->bpp);
1244 if (error)
1245 break;
1246
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001247 buf = dma_alloc_coherent(&pdev->dev, info->fix.smem_len,
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001248 &ch->dma_handle, GFP_KERNEL);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001249 if (!buf) {
1250 dev_err(&pdev->dev, "unable to allocate buffer\n");
1251 error = -ENOMEM;
1252 break;
1253 }
1254
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001255 info->pseudo_palette = &ch->pseudo_palette;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001256 info->flags = FBINFO_FLAG_DEFAULT;
1257
1258 error = fb_alloc_cmap(&info->cmap, PALETTE_NR, 0);
1259 if (error < 0) {
1260 dev_err(&pdev->dev, "unable to allocate cmap\n");
1261 dma_free_coherent(&pdev->dev, info->fix.smem_len,
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001262 buf, ch->dma_handle);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001263 break;
1264 }
1265
Guennadi Liakhovetski01ac25b2010-09-03 07:20:00 +00001266 info->fix.smem_start = ch->dma_handle;
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001267 info->fix.line_length = var->xres * (cfg->bpp / 8);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001268 info->screen_base = buf;
1269 info->device = &pdev->dev;
Guennadi Liakhovetski1c120de2010-09-03 07:20:27 +00001270 ch->display_var = *var;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001271 }
1272
1273 if (error)
1274 goto err1;
1275
1276 error = sh_mobile_lcdc_start(priv);
1277 if (error) {
1278 dev_err(&pdev->dev, "unable to start hardware\n");
1279 goto err1;
1280 }
1281
1282 for (i = 0; i < j; i++) {
Paul Mundt1c6a3072009-07-01 06:50:31 +00001283 struct sh_mobile_lcdc_chan *ch = priv->ch + i;
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001284 const struct fb_videomode *mode = ch->cfg.lcd_cfg;
1285
1286 if (!mode)
1287 mode = &default_720p;
Paul Mundt1c6a3072009-07-01 06:50:31 +00001288
Paul Mundte33afdd2009-07-07 11:24:32 +09001289 info = ch->info;
Paul Mundt1c6a3072009-07-01 06:50:31 +00001290
1291 if (info->fbdefio) {
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001292 ch->sglist = vmalloc(sizeof(struct scatterlist) *
Paul Mundt1c6a3072009-07-01 06:50:31 +00001293 info->fix.smem_len >> PAGE_SHIFT);
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001294 if (!ch->sglist) {
Paul Mundt1c6a3072009-07-01 06:50:31 +00001295 dev_err(&pdev->dev, "cannot allocate sglist\n");
1296 goto err1;
1297 }
1298 }
1299
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001300 fb_videomode_to_modelist(mode, ch->cfg.num_cfg, &info->modelist);
Paul Mundt1c6a3072009-07-01 06:50:31 +00001301 error = register_framebuffer(info);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001302 if (error < 0)
1303 goto err1;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001304
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001305 dev_info(info->dev,
1306 "registered %s/%s as %dx%d %dbpp.\n",
1307 pdev->name,
Paul Mundt1c6a3072009-07-01 06:50:31 +00001308 (ch->cfg.chan == LCDC_CHAN_MAINLCD) ?
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001309 "mainlcd" : "sublcd",
Guennadi Liakhovetskic44f9f72010-10-15 07:53:52 +00001310 info->var.xres, info->var.yres,
Paul Mundt1c6a3072009-07-01 06:50:31 +00001311 ch->cfg.bpp);
Magnus Damm85645572008-12-19 15:34:41 +09001312
1313 /* deferred io mode: disable clock to save power */
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001314 if (info->fbdefio || info->state == FBINFO_STATE_SUSPENDED)
Magnus Damm85645572008-12-19 15:34:41 +09001315 sh_mobile_lcdc_clk_off(priv);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001316 }
1317
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001318 /* Failure ignored */
1319 priv->notifier.notifier_call = sh_mobile_lcdc_notify;
1320 fb_register_client(&priv->notifier);
1321
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001322 return 0;
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001323err1:
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001324 sh_mobile_lcdc_remove(pdev);
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001325
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001326 return error;
1327}
1328
1329static int sh_mobile_lcdc_remove(struct platform_device *pdev)
1330{
1331 struct sh_mobile_lcdc_priv *priv = platform_get_drvdata(pdev);
1332 struct fb_info *info;
1333 int i;
1334
Guennadi Liakhovetski6011bde2010-07-21 10:13:21 +00001335 fb_unregister_client(&priv->notifier);
1336
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001337 for (i = 0; i < ARRAY_SIZE(priv->ch); i++)
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001338 if (priv->ch[i].info && priv->ch[i].info->dev)
Paul Mundte33afdd2009-07-07 11:24:32 +09001339 unregister_framebuffer(priv->ch[i].info);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001340
1341 sh_mobile_lcdc_stop(priv);
1342
1343 for (i = 0; i < ARRAY_SIZE(priv->ch); i++) {
Paul Mundte33afdd2009-07-07 11:24:32 +09001344 info = priv->ch[i].info;
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001345
Paul Mundte33afdd2009-07-07 11:24:32 +09001346 if (!info || !info->device)
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001347 continue;
1348
Paul Mundt1c6a3072009-07-01 06:50:31 +00001349 if (priv->ch[i].sglist)
1350 vfree(priv->ch[i].sglist);
1351
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001352 dma_free_coherent(&pdev->dev, info->fix.smem_len,
1353 info->screen_base, priv->ch[i].dma_handle);
1354 fb_dealloc_cmap(&info->cmap);
Paul Mundte33afdd2009-07-07 11:24:32 +09001355 framebuffer_release(info);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001356 }
1357
Magnus Dammb51339f2008-10-31 20:23:26 +09001358 if (priv->dot_clk)
1359 clk_put(priv->dot_clk);
Magnus Damm0246c472009-08-14 10:49:08 +00001360
Guennadi Liakhovetski8bed9052010-04-30 16:07:00 +00001361 if (priv->dev)
1362 pm_runtime_disable(priv->dev);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001363
1364 if (priv->base)
1365 iounmap(priv->base);
1366
Magnus Damm85645572008-12-19 15:34:41 +09001367 if (priv->irq)
1368 free_irq(priv->irq, priv);
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001369 kfree(priv);
1370 return 0;
1371}
1372
1373static struct platform_driver sh_mobile_lcdc_driver = {
1374 .driver = {
1375 .name = "sh_mobile_lcdc_fb",
1376 .owner = THIS_MODULE,
Magnus Damm2feb0752009-03-13 15:36:55 +00001377 .pm = &sh_mobile_lcdc_dev_pm_ops,
Magnus Dammcfb4f5d2008-07-23 21:31:24 -07001378 },
1379 .probe = sh_mobile_lcdc_probe,
1380 .remove = sh_mobile_lcdc_remove,
1381};
1382
1383static int __init sh_mobile_lcdc_init(void)
1384{
1385 return platform_driver_register(&sh_mobile_lcdc_driver);
1386}
1387
1388static void __exit sh_mobile_lcdc_exit(void)
1389{
1390 platform_driver_unregister(&sh_mobile_lcdc_driver);
1391}
1392
1393module_init(sh_mobile_lcdc_init);
1394module_exit(sh_mobile_lcdc_exit);
1395
1396MODULE_DESCRIPTION("SuperH Mobile LCDC Framebuffer driver");
1397MODULE_AUTHOR("Magnus Damm <damm@opensource.se>");
1398MODULE_LICENSE("GPL v2");