sh: split coherent pages
[deliverable/linux.git] / drivers / video / sh_mobile_lcdcfb.c
CommitLineData
cfb4f5d1
MD
1/*
2 * SuperH Mobile LCDC Framebuffer
3 *
4 * Copyright (c) 2008 Magnus Damm
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/delay.h>
14#include <linux/mm.h>
15#include <linux/fb.h>
16#include <linux/clk.h>
17#include <linux/platform_device.h>
18#include <linux/dma-mapping.h>
225c9a8d 19#include <video/sh_mobile_lcdc.h>
cfb4f5d1
MD
20
21#define PALETTE_NR 16
22
23struct sh_mobile_lcdc_priv;
24struct sh_mobile_lcdc_chan {
25 struct sh_mobile_lcdc_priv *lcdc;
26 unsigned long *reg_offs;
27 unsigned long ldmt1r_value;
28 unsigned long enabled; /* ME and SE in LDCNT2R */
29 struct sh_mobile_lcdc_chan_cfg cfg;
30 u32 pseudo_palette[PALETTE_NR];
31 struct fb_info info;
32 dma_addr_t dma_handle;
33};
34
35struct sh_mobile_lcdc_priv {
36 void __iomem *base;
225c9a8d 37#ifdef CONFIG_HAVE_CLK
b51339ff 38 struct clk *dot_clk;
cfb4f5d1 39 struct clk *clk;
225c9a8d 40#endif
cfb4f5d1
MD
41 unsigned long lddckr;
42 struct sh_mobile_lcdc_chan ch[2];
43};
44
45/* shared registers */
46#define _LDDCKR 0x410
47#define _LDDCKSTPR 0x414
48#define _LDINTR 0x468
49#define _LDSR 0x46c
50#define _LDCNT1R 0x470
51#define _LDCNT2R 0x474
52#define _LDDDSR 0x47c
53#define _LDDWD0R 0x800
54#define _LDDRDR 0x840
55#define _LDDWAR 0x900
56#define _LDDRAR 0x904
57
58/* per-channel registers */
59enum { LDDCKPAT1R, LDDCKPAT2R, LDMT1R, LDMT2R, LDMT3R, LDDFR, LDSM1R,
60 LDSA1R, LDMLSR, LDHCNR, LDHSYNR, LDVLNR, LDVSYNR, LDPMR };
61
62static unsigned long lcdc_offs_mainlcd[] = {
63 [LDDCKPAT1R] = 0x400,
64 [LDDCKPAT2R] = 0x404,
65 [LDMT1R] = 0x418,
66 [LDMT2R] = 0x41c,
67 [LDMT3R] = 0x420,
68 [LDDFR] = 0x424,
69 [LDSM1R] = 0x428,
70 [LDSA1R] = 0x430,
71 [LDMLSR] = 0x438,
72 [LDHCNR] = 0x448,
73 [LDHSYNR] = 0x44c,
74 [LDVLNR] = 0x450,
75 [LDVSYNR] = 0x454,
76 [LDPMR] = 0x460,
77};
78
79static unsigned long lcdc_offs_sublcd[] = {
80 [LDDCKPAT1R] = 0x408,
81 [LDDCKPAT2R] = 0x40c,
82 [LDMT1R] = 0x600,
83 [LDMT2R] = 0x604,
84 [LDMT3R] = 0x608,
85 [LDDFR] = 0x60c,
86 [LDSM1R] = 0x610,
87 [LDSA1R] = 0x618,
88 [LDMLSR] = 0x620,
89 [LDHCNR] = 0x624,
90 [LDHSYNR] = 0x628,
91 [LDVLNR] = 0x62c,
92 [LDVSYNR] = 0x630,
93 [LDPMR] = 0x63c,
94};
95
96#define START_LCDC 0x00000001
97#define LCDC_RESET 0x00000100
98#define DISPLAY_BEU 0x00000008
99#define LCDC_ENABLE 0x00000001
100
101static void lcdc_write_chan(struct sh_mobile_lcdc_chan *chan,
102 int reg_nr, unsigned long data)
103{
104 iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr]);
105}
106
107static unsigned long lcdc_read_chan(struct sh_mobile_lcdc_chan *chan,
108 int reg_nr)
109{
110 return ioread32(chan->lcdc->base + chan->reg_offs[reg_nr]);
111}
112
113static void lcdc_write(struct sh_mobile_lcdc_priv *priv,
114 unsigned long reg_offs, unsigned long data)
115{
116 iowrite32(data, priv->base + reg_offs);
117}
118
119static unsigned long lcdc_read(struct sh_mobile_lcdc_priv *priv,
120 unsigned long reg_offs)
121{
122 return ioread32(priv->base + reg_offs);
123}
124
125static void lcdc_wait_bit(struct sh_mobile_lcdc_priv *priv,
126 unsigned long reg_offs,
127 unsigned long mask, unsigned long until)
128{
129 while ((lcdc_read(priv, reg_offs) & mask) != until)
130 cpu_relax();
131}
132
133static int lcdc_chan_is_sublcd(struct sh_mobile_lcdc_chan *chan)
134{
135 return chan->cfg.chan == LCDC_CHAN_SUBLCD;
136}
137
138static void lcdc_sys_write_index(void *handle, unsigned long data)
139{
140 struct sh_mobile_lcdc_chan *ch = handle;
141
142 lcdc_write(ch->lcdc, _LDDWD0R, data | 0x10000000);
143 lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
144 lcdc_write(ch->lcdc, _LDDWAR, 1 | (lcdc_chan_is_sublcd(ch) ? 2 : 0));
145}
146
147static void lcdc_sys_write_data(void *handle, unsigned long data)
148{
149 struct sh_mobile_lcdc_chan *ch = handle;
150
151 lcdc_write(ch->lcdc, _LDDWD0R, data | 0x11000000);
152 lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
153 lcdc_write(ch->lcdc, _LDDWAR, 1 | (lcdc_chan_is_sublcd(ch) ? 2 : 0));
154}
155
156static unsigned long lcdc_sys_read_data(void *handle)
157{
158 struct sh_mobile_lcdc_chan *ch = handle;
159
160 lcdc_write(ch->lcdc, _LDDRDR, 0x01000000);
161 lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
162 lcdc_write(ch->lcdc, _LDDRAR, 1 | (lcdc_chan_is_sublcd(ch) ? 2 : 0));
163 udelay(1);
164
165 return lcdc_read(ch->lcdc, _LDDRDR) & 0xffff;
166}
167
168struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
169 lcdc_sys_write_index,
170 lcdc_sys_write_data,
171 lcdc_sys_read_data,
172};
173
174static void sh_mobile_lcdc_start_stop(struct sh_mobile_lcdc_priv *priv,
175 int start)
176{
177 unsigned long tmp = lcdc_read(priv, _LDCNT2R);
178 int k;
179
180 /* start or stop the lcdc */
181 if (start)
182 lcdc_write(priv, _LDCNT2R, tmp | START_LCDC);
183 else
184 lcdc_write(priv, _LDCNT2R, tmp & ~START_LCDC);
185
186 /* wait until power is applied/stopped on all channels */
187 for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
188 if (lcdc_read(priv, _LDCNT2R) & priv->ch[k].enabled)
189 while (1) {
190 tmp = lcdc_read_chan(&priv->ch[k], LDPMR) & 3;
191 if (start && tmp == 3)
192 break;
193 if (!start && tmp == 0)
194 break;
195 cpu_relax();
196 }
197
198 if (!start)
199 lcdc_write(priv, _LDDCKSTPR, 1); /* stop dotclock */
200}
201
202static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv)
203{
204 struct sh_mobile_lcdc_chan *ch;
205 struct fb_videomode *lcd_cfg;
206 struct sh_mobile_lcdc_board_cfg *board_cfg;
207 unsigned long tmp;
208 int k, m;
209 int ret = 0;
210
b51339ff
MD
211#ifdef CONFIG_HAVE_CLK
212 clk_enable(priv->clk);
213 if (priv->dot_clk)
214 clk_enable(priv->dot_clk);
215#endif
cfb4f5d1
MD
216 /* reset */
217 lcdc_write(priv, _LDCNT2R, lcdc_read(priv, _LDCNT2R) | LCDC_RESET);
218 lcdc_wait_bit(priv, _LDCNT2R, LCDC_RESET, 0);
219
220 /* enable LCDC channels */
221 tmp = lcdc_read(priv, _LDCNT2R);
222 tmp |= priv->ch[0].enabled;
223 tmp |= priv->ch[1].enabled;
224 lcdc_write(priv, _LDCNT2R, tmp);
225
226 /* read data from external memory, avoid using the BEU for now */
227 lcdc_write(priv, _LDCNT2R, lcdc_read(priv, _LDCNT2R) & ~DISPLAY_BEU);
228
229 /* stop the lcdc first */
230 sh_mobile_lcdc_start_stop(priv, 0);
231
232 /* configure clocks */
233 tmp = priv->lddckr;
234 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
235 ch = &priv->ch[k];
236
237 if (!priv->ch[k].enabled)
238 continue;
239
240 m = ch->cfg.clock_divider;
241 if (!m)
242 continue;
243
244 if (m == 1)
245 m = 1 << 6;
246 tmp |= m << (lcdc_chan_is_sublcd(ch) ? 8 : 0);
247
248 lcdc_write_chan(ch, LDDCKPAT1R, 0x00000000);
249 lcdc_write_chan(ch, LDDCKPAT2R, (1 << (m/2)) - 1);
250 }
251
252 lcdc_write(priv, _LDDCKR, tmp);
253
254 /* start dotclock again */
255 lcdc_write(priv, _LDDCKSTPR, 0);
256 lcdc_wait_bit(priv, _LDDCKSTPR, ~0, 0);
257
258 /* interrupts are disabled */
259 lcdc_write(priv, _LDINTR, 0);
260
261 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
262 ch = &priv->ch[k];
263 lcd_cfg = &ch->cfg.lcd_cfg;
264
265 if (!ch->enabled)
266 continue;
267
268 tmp = ch->ldmt1r_value;
269 tmp |= (lcd_cfg->sync & FB_SYNC_VERT_HIGH_ACT) ? 0 : 1 << 28;
270 tmp |= (lcd_cfg->sync & FB_SYNC_HOR_HIGH_ACT) ? 0 : 1 << 27;
f400f510
MD
271 tmp |= (ch->cfg.flags & LCDC_FLAGS_DWPOL) ? 1 << 26 : 0;
272 tmp |= (ch->cfg.flags & LCDC_FLAGS_DIPOL) ? 1 << 25 : 0;
273 tmp |= (ch->cfg.flags & LCDC_FLAGS_DAPOL) ? 1 << 24 : 0;
274 tmp |= (ch->cfg.flags & LCDC_FLAGS_HSCNT) ? 1 << 17 : 0;
275 tmp |= (ch->cfg.flags & LCDC_FLAGS_DWCNT) ? 1 << 16 : 0;
cfb4f5d1
MD
276 lcdc_write_chan(ch, LDMT1R, tmp);
277
278 /* setup SYS bus */
279 lcdc_write_chan(ch, LDMT2R, ch->cfg.sys_bus_cfg.ldmt2r);
280 lcdc_write_chan(ch, LDMT3R, ch->cfg.sys_bus_cfg.ldmt3r);
281
282 /* horizontal configuration */
283 tmp = lcd_cfg->xres + lcd_cfg->hsync_len;
284 tmp += lcd_cfg->left_margin;
285 tmp += lcd_cfg->right_margin;
286 tmp /= 8; /* HTCN */
287 tmp |= (lcd_cfg->xres / 8) << 16; /* HDCN */
288 lcdc_write_chan(ch, LDHCNR, tmp);
289
290 tmp = lcd_cfg->xres;
291 tmp += lcd_cfg->right_margin;
292 tmp /= 8; /* HSYNP */
293 tmp |= (lcd_cfg->hsync_len / 8) << 16; /* HSYNW */
294 lcdc_write_chan(ch, LDHSYNR, tmp);
295
296 /* power supply */
297 lcdc_write_chan(ch, LDPMR, 0);
298
299 /* vertical configuration */
300 tmp = lcd_cfg->yres + lcd_cfg->vsync_len;
301 tmp += lcd_cfg->upper_margin;
302 tmp += lcd_cfg->lower_margin; /* VTLN */
303 tmp |= lcd_cfg->yres << 16; /* VDLN */
304 lcdc_write_chan(ch, LDVLNR, tmp);
305
306 tmp = lcd_cfg->yres;
307 tmp += lcd_cfg->lower_margin; /* VSYNP */
308 tmp |= lcd_cfg->vsync_len << 16; /* VSYNW */
309 lcdc_write_chan(ch, LDVSYNR, tmp);
310
311 board_cfg = &ch->cfg.board_cfg;
312 if (board_cfg->setup_sys)
313 ret = board_cfg->setup_sys(board_cfg->board_data, ch,
314 &sh_mobile_lcdc_sys_bus_ops);
315 if (ret)
316 return ret;
317 }
318
319 /* --- display_lcdc_data() --- */
320 lcdc_write(priv, _LDINTR, 0x00000f00);
321
322 /* word and long word swap */
323 lcdc_write(priv, _LDDDSR, lcdc_read(priv, _LDDDSR) | 6);
324
325 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
326 ch = &priv->ch[k];
327
328 if (!priv->ch[k].enabled)
329 continue;
330
331 /* set bpp format in PKF[4:0] */
332 tmp = lcdc_read_chan(ch, LDDFR);
333 tmp &= ~(0x0001001f);
334 tmp |= (priv->ch[k].info.var.bits_per_pixel == 16) ? 3 : 0;
335 lcdc_write_chan(ch, LDDFR, tmp);
336
337 /* point out our frame buffer */
338 lcdc_write_chan(ch, LDSA1R, ch->info.fix.smem_start);
339
340 /* set line size */
341 lcdc_write_chan(ch, LDMLSR, ch->info.fix.line_length);
342
343 /* continuous read mode */
344 lcdc_write_chan(ch, LDSM1R, 0);
345 }
346
347 /* display output */
348 lcdc_write(priv, _LDCNT1R, LCDC_ENABLE);
349
350 /* start the lcdc */
351 sh_mobile_lcdc_start_stop(priv, 1);
352
353 /* tell the board code to enable the panel */
354 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
355 ch = &priv->ch[k];
356 board_cfg = &ch->cfg.board_cfg;
357 if (board_cfg->display_on)
358 board_cfg->display_on(board_cfg->board_data);
359 }
360
361 return 0;
362}
363
364static void sh_mobile_lcdc_stop(struct sh_mobile_lcdc_priv *priv)
365{
366 struct sh_mobile_lcdc_chan *ch;
367 struct sh_mobile_lcdc_board_cfg *board_cfg;
368 int k;
369
370 /* tell the board code to disable the panel */
371 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
372 ch = &priv->ch[k];
373 board_cfg = &ch->cfg.board_cfg;
374 if (board_cfg->display_off)
375 board_cfg->display_off(board_cfg->board_data);
376 }
377
378 /* stop the lcdc */
379 sh_mobile_lcdc_start_stop(priv, 0);
b51339ff
MD
380
381#ifdef CONFIG_HAVE_CLK
382 if (priv->dot_clk)
383 clk_disable(priv->dot_clk);
384 clk_disable(priv->clk);
385#endif
cfb4f5d1
MD
386}
387
388static int sh_mobile_lcdc_check_interface(struct sh_mobile_lcdc_chan *ch)
389{
390 int ifm, miftyp;
391
392 switch (ch->cfg.interface_type) {
393 case RGB8: ifm = 0; miftyp = 0; break;
394 case RGB9: ifm = 0; miftyp = 4; break;
395 case RGB12A: ifm = 0; miftyp = 5; break;
396 case RGB12B: ifm = 0; miftyp = 6; break;
397 case RGB16: ifm = 0; miftyp = 7; break;
398 case RGB18: ifm = 0; miftyp = 10; break;
399 case RGB24: ifm = 0; miftyp = 11; break;
400 case SYS8A: ifm = 1; miftyp = 0; break;
401 case SYS8B: ifm = 1; miftyp = 1; break;
402 case SYS8C: ifm = 1; miftyp = 2; break;
403 case SYS8D: ifm = 1; miftyp = 3; break;
404 case SYS9: ifm = 1; miftyp = 4; break;
405 case SYS12: ifm = 1; miftyp = 5; break;
406 case SYS16A: ifm = 1; miftyp = 7; break;
407 case SYS16B: ifm = 1; miftyp = 8; break;
408 case SYS16C: ifm = 1; miftyp = 9; break;
409 case SYS18: ifm = 1; miftyp = 10; break;
410 case SYS24: ifm = 1; miftyp = 11; break;
411 default: goto bad;
412 }
413
414 /* SUBLCD only supports SYS interface */
415 if (lcdc_chan_is_sublcd(ch)) {
416 if (ifm == 0)
417 goto bad;
418 else
419 ifm = 0;
420 }
421
422 ch->ldmt1r_value = (ifm << 12) | miftyp;
423 return 0;
424 bad:
425 return -EINVAL;
426}
427
b51339ff
MD
428static int sh_mobile_lcdc_setup_clocks(struct platform_device *pdev,
429 int clock_source,
cfb4f5d1
MD
430 struct sh_mobile_lcdc_priv *priv)
431{
b51339ff
MD
432#ifdef CONFIG_HAVE_CLK
433 char clk_name[8];
434#endif
cfb4f5d1
MD
435 char *str;
436 int icksel;
437
438 switch (clock_source) {
439 case LCDC_CLK_BUS: str = "bus_clk"; icksel = 0; break;
440 case LCDC_CLK_PERIPHERAL: str = "peripheral_clk"; icksel = 1; break;
441 case LCDC_CLK_EXTERNAL: str = NULL; icksel = 2; break;
442 default:
443 return -EINVAL;
444 }
445
446 priv->lddckr = icksel << 16;
447
225c9a8d 448#ifdef CONFIG_HAVE_CLK
b51339ff
MD
449 snprintf(clk_name, sizeof(clk_name), "lcdc%d", pdev->id);
450 priv->clk = clk_get(&pdev->dev, clk_name);
451 if (IS_ERR(priv->clk)) {
452 dev_err(&pdev->dev, "cannot get clock \"%s\"\n", clk_name);
453 return PTR_ERR(priv->clk);
454 }
455
cfb4f5d1 456 if (str) {
b51339ff
MD
457 priv->dot_clk = clk_get(&pdev->dev, str);
458 if (IS_ERR(priv->dot_clk)) {
459 dev_err(&pdev->dev, "cannot get dot clock %s\n", str);
460 clk_put(priv->clk);
461 return PTR_ERR(priv->dot_clk);
cfb4f5d1 462 }
cfb4f5d1 463 }
225c9a8d 464#endif
cfb4f5d1
MD
465
466 return 0;
467}
468
469static int sh_mobile_lcdc_setcolreg(u_int regno,
470 u_int red, u_int green, u_int blue,
471 u_int transp, struct fb_info *info)
472{
473 u32 *palette = info->pseudo_palette;
474
475 if (regno >= PALETTE_NR)
476 return -EINVAL;
477
478 /* only FB_VISUAL_TRUECOLOR supported */
479
480 red >>= 16 - info->var.red.length;
481 green >>= 16 - info->var.green.length;
482 blue >>= 16 - info->var.blue.length;
483 transp >>= 16 - info->var.transp.length;
484
485 palette[regno] = (red << info->var.red.offset) |
486 (green << info->var.green.offset) |
487 (blue << info->var.blue.offset) |
488 (transp << info->var.transp.offset);
489
490 return 0;
491}
492
493static struct fb_fix_screeninfo sh_mobile_lcdc_fix = {
494 .id = "SH Mobile LCDC",
495 .type = FB_TYPE_PACKED_PIXELS,
496 .visual = FB_VISUAL_TRUECOLOR,
497 .accel = FB_ACCEL_NONE,
498};
499
500static struct fb_ops sh_mobile_lcdc_ops = {
501 .fb_setcolreg = sh_mobile_lcdc_setcolreg,
502 .fb_fillrect = cfb_fillrect,
503 .fb_copyarea = cfb_copyarea,
504 .fb_imageblit = cfb_imageblit,
505};
506
507static int sh_mobile_lcdc_set_bpp(struct fb_var_screeninfo *var, int bpp)
508{
509 switch (bpp) {
510 case 16: /* PKF[4:0] = 00011 - RGB 565 */
511 var->red.offset = 11;
512 var->red.length = 5;
513 var->green.offset = 5;
514 var->green.length = 6;
515 var->blue.offset = 0;
516 var->blue.length = 5;
517 var->transp.offset = 0;
518 var->transp.length = 0;
519 break;
520
521 case 32: /* PKF[4:0] = 00000 - RGB 888
522 * sh7722 pdf says 00RRGGBB but reality is GGBB00RR
523 * this may be because LDDDSR has word swap enabled..
524 */
525 var->red.offset = 0;
526 var->red.length = 8;
527 var->green.offset = 24;
528 var->green.length = 8;
529 var->blue.offset = 16;
530 var->blue.length = 8;
531 var->transp.offset = 0;
532 var->transp.length = 0;
533 break;
534 default:
535 return -EINVAL;
536 }
537 var->bits_per_pixel = bpp;
538 var->red.msb_right = 0;
539 var->green.msb_right = 0;
540 var->blue.msb_right = 0;
541 var->transp.msb_right = 0;
542 return 0;
543}
544
545static int sh_mobile_lcdc_remove(struct platform_device *pdev);
546
547static int __init sh_mobile_lcdc_probe(struct platform_device *pdev)
548{
549 struct fb_info *info;
550 struct sh_mobile_lcdc_priv *priv;
551 struct sh_mobile_lcdc_info *pdata;
552 struct sh_mobile_lcdc_chan_cfg *cfg;
553 struct resource *res;
554 int error;
555 void *buf;
556 int i, j;
557
558 if (!pdev->dev.platform_data) {
559 dev_err(&pdev->dev, "no platform data defined\n");
560 error = -EINVAL;
561 goto err0;
562 }
563
564 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
565 if (res == NULL) {
566 dev_err(&pdev->dev, "cannot find IO resource\n");
567 error = -ENOENT;
568 goto err0;
569 }
570
571 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
572 if (!priv) {
573 dev_err(&pdev->dev, "cannot allocate device data\n");
574 error = -ENOMEM;
575 goto err0;
576 }
577
578 platform_set_drvdata(pdev, priv);
579 pdata = pdev->dev.platform_data;
580
581 j = 0;
582 for (i = 0; i < ARRAY_SIZE(pdata->ch); i++) {
583 priv->ch[j].lcdc = priv;
584 memcpy(&priv->ch[j].cfg, &pdata->ch[i], sizeof(pdata->ch[i]));
585
586 error = sh_mobile_lcdc_check_interface(&priv->ch[i]);
587 if (error) {
588 dev_err(&pdev->dev, "unsupported interface type\n");
589 goto err1;
590 }
591
592 switch (pdata->ch[i].chan) {
593 case LCDC_CHAN_MAINLCD:
594 priv->ch[j].enabled = 1 << 1;
595 priv->ch[j].reg_offs = lcdc_offs_mainlcd;
596 j++;
597 break;
598 case LCDC_CHAN_SUBLCD:
599 priv->ch[j].enabled = 1 << 2;
600 priv->ch[j].reg_offs = lcdc_offs_sublcd;
601 j++;
602 break;
603 }
604 }
605
606 if (!j) {
607 dev_err(&pdev->dev, "no channels defined\n");
608 error = -EINVAL;
609 goto err1;
610 }
611
b51339ff 612 error = sh_mobile_lcdc_setup_clocks(pdev, pdata->clock_source, priv);
cfb4f5d1
MD
613 if (error) {
614 dev_err(&pdev->dev, "unable to setup clocks\n");
615 goto err1;
616 }
617
cfb4f5d1
MD
618 priv->base = ioremap_nocache(res->start, (res->end - res->start) + 1);
619
620 for (i = 0; i < j; i++) {
621 info = &priv->ch[i].info;
622 cfg = &priv->ch[i].cfg;
623
624 info->fbops = &sh_mobile_lcdc_ops;
625 info->var.xres = info->var.xres_virtual = cfg->lcd_cfg.xres;
626 info->var.yres = info->var.yres_virtual = cfg->lcd_cfg.yres;
ce9c008c
MD
627 info->var.width = cfg->lcd_size_cfg.width;
628 info->var.height = cfg->lcd_size_cfg.height;
cfb4f5d1
MD
629 info->var.activate = FB_ACTIVATE_NOW;
630 error = sh_mobile_lcdc_set_bpp(&info->var, cfg->bpp);
631 if (error)
632 break;
633
634 info->fix = sh_mobile_lcdc_fix;
635 info->fix.line_length = cfg->lcd_cfg.xres * (cfg->bpp / 8);
636 info->fix.smem_len = info->fix.line_length * cfg->lcd_cfg.yres;
637
638 buf = dma_alloc_coherent(&pdev->dev, info->fix.smem_len,
639 &priv->ch[i].dma_handle, GFP_KERNEL);
640 if (!buf) {
641 dev_err(&pdev->dev, "unable to allocate buffer\n");
642 error = -ENOMEM;
643 break;
644 }
645
646 info->pseudo_palette = &priv->ch[i].pseudo_palette;
647 info->flags = FBINFO_FLAG_DEFAULT;
648
649 error = fb_alloc_cmap(&info->cmap, PALETTE_NR, 0);
650 if (error < 0) {
651 dev_err(&pdev->dev, "unable to allocate cmap\n");
652 dma_free_coherent(&pdev->dev, info->fix.smem_len,
653 buf, priv->ch[i].dma_handle);
654 break;
655 }
656
657 memset(buf, 0, info->fix.smem_len);
658 info->fix.smem_start = priv->ch[i].dma_handle;
659 info->screen_base = buf;
660 info->device = &pdev->dev;
661 }
662
663 if (error)
664 goto err1;
665
666 error = sh_mobile_lcdc_start(priv);
667 if (error) {
668 dev_err(&pdev->dev, "unable to start hardware\n");
669 goto err1;
670 }
671
672 for (i = 0; i < j; i++) {
673 error = register_framebuffer(&priv->ch[i].info);
674 if (error < 0)
675 goto err1;
676 }
677
678 for (i = 0; i < j; i++) {
679 info = &priv->ch[i].info;
680 dev_info(info->dev,
681 "registered %s/%s as %dx%d %dbpp.\n",
682 pdev->name,
683 (priv->ch[i].cfg.chan == LCDC_CHAN_MAINLCD) ?
684 "mainlcd" : "sublcd",
685 (int) priv->ch[i].cfg.lcd_cfg.xres,
686 (int) priv->ch[i].cfg.lcd_cfg.yres,
687 priv->ch[i].cfg.bpp);
688 }
689
690 return 0;
691 err1:
692 sh_mobile_lcdc_remove(pdev);
693 err0:
694 return error;
695}
696
697static int sh_mobile_lcdc_remove(struct platform_device *pdev)
698{
699 struct sh_mobile_lcdc_priv *priv = platform_get_drvdata(pdev);
700 struct fb_info *info;
701 int i;
702
703 for (i = 0; i < ARRAY_SIZE(priv->ch); i++)
704 if (priv->ch[i].info.dev)
705 unregister_framebuffer(&priv->ch[i].info);
706
707 sh_mobile_lcdc_stop(priv);
708
709 for (i = 0; i < ARRAY_SIZE(priv->ch); i++) {
710 info = &priv->ch[i].info;
711
712 if (!info->device)
713 continue;
714
715 dma_free_coherent(&pdev->dev, info->fix.smem_len,
716 info->screen_base, priv->ch[i].dma_handle);
717 fb_dealloc_cmap(&info->cmap);
718 }
719
225c9a8d 720#ifdef CONFIG_HAVE_CLK
b51339ff
MD
721 if (priv->dot_clk)
722 clk_put(priv->dot_clk);
723 clk_put(priv->clk);
225c9a8d 724#endif
cfb4f5d1
MD
725
726 if (priv->base)
727 iounmap(priv->base);
728
729 kfree(priv);
730 return 0;
731}
732
733static struct platform_driver sh_mobile_lcdc_driver = {
734 .driver = {
735 .name = "sh_mobile_lcdc_fb",
736 .owner = THIS_MODULE,
737 },
738 .probe = sh_mobile_lcdc_probe,
739 .remove = sh_mobile_lcdc_remove,
740};
741
742static int __init sh_mobile_lcdc_init(void)
743{
744 return platform_driver_register(&sh_mobile_lcdc_driver);
745}
746
747static void __exit sh_mobile_lcdc_exit(void)
748{
749 platform_driver_unregister(&sh_mobile_lcdc_driver);
750}
751
752module_init(sh_mobile_lcdc_init);
753module_exit(sh_mobile_lcdc_exit);
754
755MODULE_DESCRIPTION("SuperH Mobile LCDC Framebuffer driver");
756MODULE_AUTHOR("Magnus Damm <damm@opensource.se>");
757MODULE_LICENSE("GPL v2");
This page took 0.084473 seconds and 5 git commands to generate.