Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/drivers/video/epson1355fb.c -- Epson S1D13505 frame buffer for 2.5. | |
3 | * | |
4 | * Epson Research S1D13505 Embedded RAMDAC LCD/CRT Controller | |
5 | * (previously known as SED1355) | |
6 | * | |
7 | * Cf. http://www.erd.epson.com/vdc/html/S1D13505.html | |
8 | * | |
9 | * | |
10 | * Copyright (C) Hewlett-Packard Company. All rights reserved. | |
11 | * | |
12 | * Written by Christopher Hoover <ch@hpl.hp.com> | |
13 | * | |
14 | * Adapted from: | |
15 | * | |
16 | * linux/drivers/video/skeletonfb.c | |
17 | * Modified to new api Jan 2001 by James Simmons (jsimmons@infradead.org) | |
18 | * Created 28 Dec 1997 by Geert Uytterhoeven | |
19 | * | |
20 | * linux/drivers/video/epson1355fb.c (2.4 driver) | |
21 | * Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org> | |
22 | * | |
23 | * This file is subject to the terms and conditions of the GNU General Public | |
24 | * License. See the file COPYING in the main directory of this archive for | |
25 | * more details. | |
26 | * | |
27 | * | |
28 | * Noteworthy Issues | |
29 | * ----------------- | |
30 | * | |
31 | * This driver is complicated by the fact that this is a 16-bit chip | |
32 | * and, on at least one platform (ceiva), we can only do 16-bit reads | |
33 | * and writes to the framebuffer. We hide this from user space | |
34 | * except in the case of mmap(). | |
35 | * | |
36 | * | |
37 | * To Do | |
38 | * ----- | |
39 | * | |
40 | * - Test 8-bit pseudocolor mode | |
41 | * - Allow setting bpp, virtual resolution | |
42 | * - Implement horizontal panning | |
43 | * - (maybe) Implement hardware cursor | |
44 | */ | |
45 | ||
46 | #include <linux/module.h> | |
47 | #include <linux/kernel.h> | |
48 | #include <linux/errno.h> | |
49 | #include <linux/string.h> | |
50 | #include <linux/mm.h> | |
1da177e4 LT |
51 | #include <linux/slab.h> |
52 | #include <linux/delay.h> | |
53 | #include <linux/fb.h> | |
54 | #include <linux/init.h> | |
55 | #include <linux/ioport.h> | |
d052d1be RK |
56 | #include <linux/platform_device.h> |
57 | ||
1da177e4 LT |
58 | #include <asm/types.h> |
59 | #include <asm/io.h> | |
60 | #include <asm/uaccess.h> | |
61 | ||
62 | #include <video/epson1355.h> | |
63 | ||
64 | struct epson1355_par { | |
65 | unsigned long reg_addr; | |
4a1b9279 | 66 | u32 pseudo_palette[16]; |
1da177e4 LT |
67 | }; |
68 | ||
69 | /* ------------------------------------------------------------------------- */ | |
70 | ||
71 | #ifdef CONFIG_SUPERH | |
72 | ||
73 | static inline u8 epson1355_read_reg(int index) | |
74 | { | |
75 | return ctrl_inb(par.reg_addr + index); | |
76 | } | |
77 | ||
78 | static inline void epson1355_write_reg(u8 data, int index) | |
79 | { | |
80 | ctrl_outb(data, par.reg_addr + index); | |
81 | } | |
82 | ||
83 | #elif defined(CONFIG_ARM) | |
84 | ||
85 | # ifdef CONFIG_ARCH_CEIVA | |
86 | # include <asm/arch/hardware.h> | |
87 | # define EPSON1355FB_BASE_PHYS (CEIVA_PHYS_SED1355) | |
88 | # endif | |
89 | ||
90 | static inline u8 epson1355_read_reg(struct epson1355_par *par, int index) | |
91 | { | |
92 | return __raw_readb(par->reg_addr + index); | |
93 | } | |
94 | ||
95 | static inline void epson1355_write_reg(struct epson1355_par *par, u8 data, int index) | |
96 | { | |
97 | __raw_writeb(data, par->reg_addr + index); | |
98 | } | |
99 | ||
100 | #else | |
101 | # error "no architecture-specific epson1355_{read,write}_reg" | |
102 | #endif | |
103 | ||
104 | #ifndef EPSON1355FB_BASE_PHYS | |
105 | # error "EPSON1355FB_BASE_PHYS is not defined" | |
106 | #endif | |
107 | ||
108 | #define EPSON1355FB_REGS_OFS (0) | |
109 | #define EPSON1355FB_REGS_PHYS (EPSON1355FB_BASE_PHYS + EPSON1355FB_REGS_OFS) | |
110 | #define EPSON1355FB_REGS_LEN (64) | |
111 | ||
112 | #define EPSON1355FB_FB_OFS (0x00200000) | |
113 | #define EPSON1355FB_FB_PHYS (EPSON1355FB_BASE_PHYS + EPSON1355FB_FB_OFS) | |
114 | #define EPSON1355FB_FB_LEN (2 * 1024 * 1024) | |
115 | ||
116 | /* ------------------------------------------------------------------------- */ | |
117 | ||
118 | static inline u16 epson1355_read_reg16(struct epson1355_par *par, int index) | |
119 | { | |
120 | u8 lo = epson1355_read_reg(par, index); | |
121 | u8 hi = epson1355_read_reg(par, index + 1); | |
122 | ||
123 | return (hi << 8) | lo; | |
124 | } | |
125 | ||
126 | static inline void epson1355_write_reg16(struct epson1355_par *par, u16 data, int index) | |
127 | { | |
128 | u8 lo = data & 0xff; | |
129 | u8 hi = (data >> 8) & 0xff; | |
130 | ||
131 | epson1355_write_reg(par, lo, index); | |
132 | epson1355_write_reg(par, hi, index + 1); | |
133 | } | |
134 | ||
135 | static inline u32 epson1355_read_reg20(struct epson1355_par *par, int index) | |
136 | { | |
137 | u8 b0 = epson1355_read_reg(par, index); | |
138 | u8 b1 = epson1355_read_reg(par, index + 1); | |
139 | u8 b2 = epson1355_read_reg(par, index + 2); | |
140 | ||
141 | return (b2 & 0x0f) << 16 | (b1 << 8) | b0; | |
142 | } | |
143 | ||
144 | static inline void epson1355_write_reg20(struct epson1355_par *par, u32 data, int index) | |
145 | { | |
146 | u8 b0 = data & 0xff; | |
147 | u8 b1 = (data >> 8) & 0xff; | |
148 | u8 b2 = (data >> 16) & 0x0f; | |
149 | ||
150 | epson1355_write_reg(par, b0, index); | |
151 | epson1355_write_reg(par, b1, index + 1); | |
152 | epson1355_write_reg(par, b2, index + 2); | |
153 | } | |
154 | ||
155 | /* ------------------------------------------------------------------------- */ | |
156 | ||
157 | static void set_lut(struct epson1355_par *par, u8 index, u8 r, u8 g, u8 b) | |
158 | { | |
159 | epson1355_write_reg(par, index, REG_LUT_ADDR); | |
160 | epson1355_write_reg(par, r, REG_LUT_DATA); | |
161 | epson1355_write_reg(par, g, REG_LUT_DATA); | |
162 | epson1355_write_reg(par, b, REG_LUT_DATA); | |
163 | } | |
164 | ||
165 | ||
166 | /** | |
167 | * epson1355fb_setcolreg - sets a color register. | |
168 | * @regno: Which register in the CLUT we are programming | |
169 | * @red: The red value which can be up to 16 bits wide | |
170 | * @green: The green value which can be up to 16 bits wide | |
171 | * @blue: The blue value which can be up to 16 bits wide. | |
172 | * @transp: If supported the alpha value which can be up to 16 bits wide. | |
173 | * @info: frame buffer info structure | |
174 | * | |
175 | * Returns negative errno on error, or zero on success. | |
176 | */ | |
177 | static int epson1355fb_setcolreg(unsigned regno, unsigned r, unsigned g, | |
178 | unsigned b, unsigned transp, | |
179 | struct fb_info *info) | |
180 | { | |
181 | struct epson1355_par *par = info->par; | |
182 | ||
183 | if (info->var.grayscale) | |
184 | r = g = b = (19595 * r + 38470 * g + 7471 * b) >> 16; | |
185 | ||
186 | switch (info->fix.visual) { | |
187 | case FB_VISUAL_TRUECOLOR: | |
188 | if (regno >= 16) | |
189 | return -EINVAL; | |
190 | ||
191 | ((u32 *) info->pseudo_palette)[regno] = | |
192 | (r & 0xf800) | (g & 0xfc00) >> 5 | (b & 0xf800) >> 11; | |
193 | ||
194 | break; | |
195 | case FB_VISUAL_PSEUDOCOLOR: | |
196 | if (regno >= 256) | |
197 | return -EINVAL; | |
198 | ||
199 | set_lut(par, regno, r >> 8, g >> 8, b >> 8); | |
200 | ||
201 | break; | |
202 | default: | |
203 | return -ENOSYS; | |
204 | } | |
205 | return 0; | |
206 | } | |
207 | ||
208 | /* ------------------------------------------------------------------------- */ | |
209 | ||
210 | /** | |
211 | * epson1355fb_pan_display - Pans the display. | |
212 | * @var: frame buffer variable screen structure | |
213 | * @info: frame buffer structure that represents a single frame buffer | |
214 | * | |
215 | * Pan (or wrap, depending on the `vmode' field) the display using the | |
216 | * `xoffset' and `yoffset' fields of the `var' structure. | |
217 | * If the values don't fit, return -EINVAL. | |
218 | * | |
219 | * Returns negative errno on error, or zero on success. | |
220 | */ | |
221 | static int epson1355fb_pan_display(struct fb_var_screeninfo *var, | |
222 | struct fb_info *info) | |
223 | { | |
224 | struct epson1355_par *par = info->par; | |
225 | u32 start; | |
226 | ||
227 | if (var->xoffset != 0) /* not yet ... */ | |
228 | return -EINVAL; | |
229 | ||
230 | if (var->yoffset + info->var.yres > info->var.yres_virtual) | |
231 | return -EINVAL; | |
232 | ||
233 | start = (info->fix.line_length >> 1) * var->yoffset; | |
234 | ||
235 | epson1355_write_reg20(par, start, REG_SCRN1_DISP_START_ADDR0); | |
236 | ||
237 | return 0; | |
238 | } | |
239 | ||
240 | /* ------------------------------------------------------------------------- */ | |
241 | ||
242 | static void lcd_enable(struct epson1355_par *par, int enable) | |
243 | { | |
244 | u8 mode = epson1355_read_reg(par, REG_DISPLAY_MODE); | |
245 | ||
246 | if (enable) | |
247 | mode |= 1; | |
248 | else | |
249 | mode &= ~1; | |
250 | ||
251 | epson1355_write_reg(par, mode, REG_DISPLAY_MODE); | |
252 | } | |
253 | ||
254 | #if defined(CONFIG_ARCH_CEIVA) | |
255 | static void backlight_enable(int enable) | |
256 | { | |
257 | /* ### this should be protected by a spinlock ... */ | |
258 | u8 pddr = clps_readb(PDDR); | |
259 | if (enable) | |
260 | pddr |= (1 << 5); | |
261 | else | |
262 | pddr &= ~(1 << 5); | |
263 | clps_writeb(pddr, PDDR); | |
264 | } | |
265 | #else | |
266 | static void backlight_enable(int enable) | |
267 | { | |
268 | } | |
269 | #endif | |
270 | ||
271 | ||
272 | /** | |
273 | * epson1355fb_blank - blanks the display. | |
274 | * @blank_mode: the blank mode we want. | |
275 | * @info: frame buffer structure that represents a single frame buffer | |
276 | * | |
277 | * Blank the screen if blank_mode != 0, else unblank. Return 0 if | |
278 | * blanking succeeded, != 0 if un-/blanking failed due to e.g. a | |
279 | * video mode which doesn't support it. Implements VESA suspend | |
280 | * and powerdown modes on hardware that supports disabling hsync/vsync: | |
281 | * blank_mode == 2: suspend vsync | |
282 | * blank_mode == 3: suspend hsync | |
283 | * blank_mode == 4: powerdown | |
284 | * | |
285 | * Returns negative errno on error, or zero on success. | |
286 | * | |
287 | */ | |
288 | static int epson1355fb_blank(int blank_mode, struct fb_info *info) | |
289 | { | |
290 | struct epson1355_par *par = info->par; | |
291 | ||
292 | switch (blank_mode) { | |
293 | case FB_BLANK_UNBLANKING: | |
294 | case FB_BLANK_NORMAL: | |
295 | lcd_enable(par, 1); | |
296 | backlight_enable(1); | |
297 | break; | |
298 | case FB_BLANK_VSYNC_SUSPEND: | |
299 | case FB_BLANK_HSYNC_SUSPEND: | |
300 | backlight_enable(0); | |
301 | break; | |
302 | case FB_BLANK_POWERDOWN: | |
303 | backlight_enable(0); | |
304 | lcd_enable(par, 0); | |
305 | break; | |
306 | default: | |
307 | return -EINVAL; | |
308 | } | |
309 | ||
310 | /* let fbcon do a soft blank for us */ | |
311 | return (blank_mode == FB_BLANK_NORMAL) ? 1 : 0; | |
312 | } | |
313 | ||
314 | /* ------------------------------------------------------------------------- */ | |
315 | ||
316 | /* | |
317 | * We can't use the cfb generic routines, as we have to limit | |
318 | * ourselves to 16-bit or 8-bit loads and stores to this 16-bit | |
319 | * chip. | |
320 | */ | |
321 | ||
322 | static inline void epson1355fb_fb_writel(unsigned long v, unsigned long *a) | |
323 | { | |
324 | u16 *p = (u16 *) a; | |
325 | u16 l = v & 0xffff; | |
326 | u16 h = v >> 16; | |
327 | ||
328 | fb_writew(l, p); | |
329 | fb_writew(h, p + 1); | |
330 | } | |
331 | ||
332 | static inline unsigned long epson1355fb_fb_readl(const unsigned long *a) | |
333 | { | |
334 | const u16 *p = (u16 *) a; | |
335 | u16 l = fb_readw(p); | |
336 | u16 h = fb_readw(p + 1); | |
337 | ||
338 | return (h << 16) | l; | |
339 | } | |
340 | ||
341 | #define FB_READL epson1355fb_fb_readl | |
342 | #define FB_WRITEL epson1355fb_fb_writel | |
343 | ||
344 | /* ------------------------------------------------------------------------- */ | |
345 | ||
346 | static inline unsigned long copy_from_user16(void *to, const void *from, | |
347 | unsigned long n) | |
348 | { | |
349 | u16 *dst = (u16 *) to; | |
350 | u16 *src = (u16 *) from; | |
351 | ||
352 | if (!access_ok(VERIFY_READ, from, n)) | |
353 | return n; | |
354 | ||
355 | while (n > 1) { | |
356 | u16 v; | |
357 | if (__get_user(v, src)) | |
358 | return n; | |
359 | ||
360 | fb_writew(v, dst); | |
361 | ||
362 | src++, dst++; | |
363 | n -= 2; | |
364 | } | |
365 | ||
366 | if (n) { | |
367 | u8 v; | |
368 | ||
369 | if (__get_user(v, ((u8 *) src))) | |
370 | return n; | |
371 | ||
372 | fb_writeb(v, dst); | |
373 | } | |
374 | return 0; | |
375 | } | |
376 | ||
377 | static inline unsigned long copy_to_user16(void *to, const void *from, | |
378 | unsigned long n) | |
379 | { | |
380 | u16 *dst = (u16 *) to; | |
381 | u16 *src = (u16 *) from; | |
382 | ||
383 | if (!access_ok(VERIFY_WRITE, to, n)) | |
384 | return n; | |
385 | ||
386 | while (n > 1) { | |
387 | u16 v = fb_readw(src); | |
388 | ||
389 | if (__put_user(v, dst)) | |
390 | return n; | |
391 | ||
392 | src++, dst++; | |
393 | n -= 2; | |
394 | } | |
395 | ||
396 | if (n) { | |
397 | u8 v = fb_readb(src); | |
398 | ||
399 | if (__put_user(v, ((u8 *) dst))) | |
400 | return n; | |
401 | } | |
402 | return 0; | |
403 | } | |
404 | ||
405 | ||
406 | static ssize_t | |
3f9b0880 | 407 | epson1355fb_read(struct fb_info *info, char *buf, size_t count, loff_t * ppos) |
1da177e4 | 408 | { |
1da177e4 LT |
409 | unsigned long p = *ppos; |
410 | ||
1da177e4 LT |
411 | if (p >= info->fix.smem_len) |
412 | return 0; | |
413 | if (count >= info->fix.smem_len) | |
414 | count = info->fix.smem_len; | |
415 | if (count + p > info->fix.smem_len) | |
416 | count = info->fix.smem_len - p; | |
417 | ||
418 | if (count) { | |
419 | char *base_addr; | |
420 | ||
421 | base_addr = info->screen_base; | |
422 | count -= copy_to_user16(buf, base_addr + p, count); | |
423 | if (!count) | |
424 | return -EFAULT; | |
425 | *ppos += count; | |
426 | } | |
427 | return count; | |
428 | } | |
429 | ||
430 | static ssize_t | |
3f9b0880 | 431 | epson1355fb_write(struct fb_info *info, const char *buf, |
1da177e4 LT |
432 | size_t count, loff_t * ppos) |
433 | { | |
1da177e4 LT |
434 | unsigned long p = *ppos; |
435 | int err; | |
436 | ||
1da177e4 LT |
437 | /* from fbmem.c except for our own copy_*_user */ |
438 | if (p > info->fix.smem_len) | |
439 | return -ENOSPC; | |
440 | if (count >= info->fix.smem_len) | |
441 | count = info->fix.smem_len; | |
442 | err = 0; | |
443 | if (count + p > info->fix.smem_len) { | |
444 | count = info->fix.smem_len - p; | |
445 | err = -ENOSPC; | |
446 | } | |
447 | ||
448 | if (count) { | |
449 | char *base_addr; | |
450 | ||
451 | base_addr = info->screen_base; | |
452 | count -= copy_from_user16(base_addr + p, buf, count); | |
453 | *ppos += count; | |
454 | err = -EFAULT; | |
455 | } | |
456 | if (count) | |
457 | return count; | |
458 | return err; | |
459 | } | |
460 | ||
461 | /* ------------------------------------------------------------------------- */ | |
462 | ||
463 | static struct fb_ops epson1355fb_fbops = { | |
464 | .owner = THIS_MODULE, | |
465 | .fb_setcolreg = epson1355fb_setcolreg, | |
466 | .fb_pan_display = epson1355fb_pan_display, | |
467 | .fb_blank = epson1355fb_blank, | |
468 | .fb_fillrect = cfb_fillrect, | |
469 | .fb_copyarea = cfb_copyarea, | |
470 | .fb_imageblit = cfb_imageblit, | |
471 | .fb_read = epson1355fb_read, | |
472 | .fb_write = epson1355fb_write, | |
1da177e4 LT |
473 | }; |
474 | ||
475 | /* ------------------------------------------------------------------------- */ | |
476 | ||
477 | static __init unsigned int get_fb_size(struct fb_info *info) | |
478 | { | |
479 | unsigned int size = 2 * 1024 * 1024; | |
480 | char *p = info->screen_base; | |
481 | ||
482 | /* the 512k framebuffer is aliased at start + 0x80000 * n */ | |
483 | fb_writeb(1, p); | |
484 | fb_writeb(0, p + 0x80000); | |
485 | if (!fb_readb(p)) | |
486 | size = 512 * 1024; | |
487 | ||
488 | fb_writeb(0, p); | |
489 | ||
490 | return size; | |
491 | } | |
492 | ||
493 | static int epson1355_width_tab[2][4] __initdata = | |
494 | { {4, 8, 16, -1}, {9, 12, 16, -1} }; | |
495 | static int epson1355_bpp_tab[8] __initdata = { 1, 2, 4, 8, 15, 16 }; | |
496 | ||
497 | static void __init fetch_hw_state(struct fb_info *info, struct epson1355_par *par) | |
498 | { | |
499 | struct fb_var_screeninfo *var = &info->var; | |
500 | struct fb_fix_screeninfo *fix = &info->fix; | |
501 | u8 panel, display; | |
502 | u16 offset; | |
503 | u32 xres, yres; | |
504 | u32 xres_virtual, yres_virtual; | |
505 | int bpp, lcd_bpp; | |
506 | int is_color, is_dual, is_tft; | |
507 | int lcd_enabled, crt_enabled; | |
508 | ||
509 | fix->type = FB_TYPE_PACKED_PIXELS; | |
510 | ||
511 | display = epson1355_read_reg(par, REG_DISPLAY_MODE); | |
512 | bpp = epson1355_bpp_tab[(display >> 2) & 7]; | |
513 | ||
514 | switch (bpp) { | |
515 | case 8: | |
516 | fix->visual = FB_VISUAL_PSEUDOCOLOR; | |
517 | var->bits_per_pixel = 8; | |
518 | var->red.offset = var->green.offset = var->blue.offset = 0; | |
519 | var->red.length = var->green.length = var->blue.length = 8; | |
520 | break; | |
521 | case 16: | |
522 | /* 5-6-5 RGB */ | |
523 | fix->visual = FB_VISUAL_TRUECOLOR; | |
524 | var->bits_per_pixel = 16; | |
525 | var->red.offset = 11; | |
526 | var->red.length = 5; | |
527 | var->green.offset = 5; | |
528 | var->green.length = 6; | |
529 | var->blue.offset = 0; | |
530 | var->blue.length = 5; | |
531 | break; | |
532 | default: | |
533 | BUG(); | |
534 | } | |
535 | fb_alloc_cmap(&(info->cmap), 256, 0); | |
536 | ||
537 | panel = epson1355_read_reg(par, REG_PANEL_TYPE); | |
538 | is_color = (panel & 0x04) != 0; | |
539 | is_dual = (panel & 0x02) != 0; | |
540 | is_tft = (panel & 0x01) != 0; | |
541 | crt_enabled = (display & 0x02) != 0; | |
542 | lcd_enabled = (display & 0x01) != 0; | |
543 | lcd_bpp = epson1355_width_tab[is_tft][(panel >> 4) & 3]; | |
544 | ||
545 | xres = (epson1355_read_reg(par, REG_HORZ_DISP_WIDTH) + 1) * 8; | |
546 | yres = (epson1355_read_reg16(par, REG_VERT_DISP_HEIGHT0) + 1) * | |
547 | ((is_dual && !crt_enabled) ? 2 : 1); | |
548 | offset = epson1355_read_reg16(par, REG_MEM_ADDR_OFFSET0) & 0x7ff; | |
549 | xres_virtual = offset * 16 / bpp; | |
550 | yres_virtual = fix->smem_len / (offset * 2); | |
551 | ||
552 | var->xres = xres; | |
553 | var->yres = yres; | |
554 | var->xres_virtual = xres_virtual; | |
555 | var->yres_virtual = yres_virtual; | |
556 | var->xoffset = var->yoffset = 0; | |
557 | ||
558 | fix->line_length = offset * 2; | |
559 | ||
560 | fix->xpanstep = 0; /* no pan yet */ | |
561 | fix->ypanstep = 1; | |
562 | fix->ywrapstep = 0; | |
563 | fix->accel = FB_ACCEL_NONE; | |
564 | ||
565 | var->grayscale = !is_color; | |
566 | ||
567 | #ifdef DEBUG | |
568 | printk(KERN_INFO | |
569 | "epson1355fb: xres=%d, yres=%d, " | |
570 | "is_color=%d, is_dual=%d, is_tft=%d\n", | |
571 | xres, yres, is_color, is_dual, is_tft); | |
572 | printk(KERN_INFO | |
573 | "epson1355fb: bpp=%d, lcd_bpp=%d, " | |
574 | "crt_enabled=%d, lcd_enabled=%d\n", | |
575 | bpp, lcd_bpp, crt_enabled, lcd_enabled); | |
576 | #endif | |
577 | } | |
578 | ||
579 | ||
580 | static void clearfb16(struct fb_info *info) | |
581 | { | |
582 | u16 *dst = (u16 *) info->screen_base; | |
583 | unsigned long n = info->fix.smem_len; | |
584 | ||
585 | while (n > 1) { | |
586 | fb_writew(0, dst); | |
587 | dst++, n -= 2; | |
588 | } | |
589 | ||
590 | if (n) | |
591 | fb_writeb(0, dst); | |
592 | } | |
593 | ||
3ae5eaec | 594 | static int epson1355fb_remove(struct platform_device *dev) |
1da177e4 | 595 | { |
3ae5eaec | 596 | struct fb_info *info = platform_get_drvdata(dev); |
1da177e4 LT |
597 | struct epson1355_par *par = info->par; |
598 | ||
599 | backlight_enable(0); | |
600 | if (par) { | |
601 | lcd_enable(par, 0); | |
602 | if (par && par->reg_addr) | |
603 | iounmap((void *) par->reg_addr); | |
604 | } | |
605 | ||
606 | if (info) { | |
607 | fb_dealloc_cmap(&info->cmap); | |
608 | if (info->screen_base) | |
609 | iounmap(info->screen_base); | |
610 | framebuffer_release(info); | |
611 | } | |
612 | release_mem_region(EPSON1355FB_FB_PHYS, EPSON1355FB_FB_LEN); | |
613 | release_mem_region(EPSON1355FB_REGS_PHYS, EPSON1355FB_REGS_LEN); | |
614 | return 0; | |
615 | } | |
616 | ||
3ae5eaec | 617 | int __init epson1355fb_probe(struct platform_device *dev) |
1da177e4 | 618 | { |
1da177e4 LT |
619 | struct epson1355_par *default_par; |
620 | struct fb_info *info; | |
621 | u8 revision; | |
622 | int rc = 0; | |
623 | ||
624 | if (!request_mem_region(EPSON1355FB_REGS_PHYS, EPSON1355FB_REGS_LEN, "S1D13505 registers")) { | |
625 | printk(KERN_ERR "epson1355fb: unable to reserve " | |
626 | "registers at 0x%0x\n", EPSON1355FB_REGS_PHYS); | |
627 | rc = -EBUSY; | |
628 | goto bail; | |
629 | } | |
630 | ||
631 | if (!request_mem_region(EPSON1355FB_FB_PHYS, EPSON1355FB_FB_LEN, | |
632 | "S1D13505 framebuffer")) { | |
633 | printk(KERN_ERR "epson1355fb: unable to reserve " | |
634 | "framebuffer at 0x%0x\n", EPSON1355FB_FB_PHYS); | |
635 | rc = -EBUSY; | |
636 | goto bail; | |
637 | } | |
638 | ||
4a1b9279 | 639 | info = framebuffer_alloc(sizeof(struct epson1355_par), &dev->dev); |
19f3d3a5 | 640 | if (!info) { |
1da177e4 LT |
641 | rc = -ENOMEM; |
642 | goto bail; | |
19f3d3a5 | 643 | } |
1da177e4 LT |
644 | |
645 | default_par = info->par; | |
646 | default_par->reg_addr = (unsigned long) ioremap(EPSON1355FB_REGS_PHYS, EPSON1355FB_REGS_LEN); | |
647 | if (!default_par->reg_addr) { | |
648 | printk(KERN_ERR "epson1355fb: unable to map registers\n"); | |
649 | rc = -ENOMEM; | |
650 | goto bail; | |
651 | } | |
4a1b9279 | 652 | info->pseudo_palette = default_par->pseudo_palette; |
1da177e4 LT |
653 | |
654 | info->screen_base = ioremap(EPSON1355FB_FB_PHYS, EPSON1355FB_FB_LEN); | |
655 | if (!info->screen_base) { | |
656 | printk(KERN_ERR "epson1355fb: unable to map framebuffer\n"); | |
657 | rc = -ENOMEM; | |
658 | goto bail; | |
659 | } | |
660 | ||
661 | revision = epson1355_read_reg(default_par, REG_REVISION_CODE); | |
662 | if ((revision >> 2) != 3) { | |
663 | printk(KERN_INFO "epson1355fb: epson1355 not found\n"); | |
664 | rc = -ENODEV; | |
665 | goto bail; | |
666 | } | |
667 | ||
668 | info->fix.mmio_start = EPSON1355FB_REGS_PHYS; | |
669 | info->fix.mmio_len = EPSON1355FB_REGS_LEN; | |
670 | info->fix.smem_start = EPSON1355FB_FB_PHYS; | |
671 | info->fix.smem_len = get_fb_size(info); | |
672 | ||
673 | printk(KERN_INFO "epson1355fb: regs mapped at 0x%lx, fb %d KiB mapped at 0x%p\n", | |
674 | default_par->reg_addr, info->fix.smem_len / 1024, info->screen_base); | |
675 | ||
676 | strcpy(info->fix.id, "S1D13505"); | |
677 | info->par = default_par; | |
678 | info->fbops = &epson1355fb_fbops; | |
679 | info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN; | |
680 | ||
681 | /* we expect the boot loader to have initialized the chip | |
682 | with appropriate parameters from which we can determinte | |
683 | the flavor of lcd panel attached */ | |
684 | fetch_hw_state(info, default_par); | |
685 | ||
686 | /* turn this puppy on ... */ | |
687 | clearfb16(info); | |
688 | backlight_enable(1); | |
689 | lcd_enable(default_par, 1); | |
690 | ||
691 | if (register_framebuffer(info) < 0) { | |
692 | rc = -EINVAL; | |
693 | goto bail; | |
694 | } | |
695 | /* | |
696 | * Our driver data. | |
697 | */ | |
3ae5eaec | 698 | platform_set_drvdata(dev, info); |
1da177e4 LT |
699 | |
700 | printk(KERN_INFO "fb%d: %s frame buffer device\n", | |
701 | info->node, info->fix.id); | |
702 | ||
703 | return 0; | |
704 | ||
705 | bail: | |
3ae5eaec | 706 | epson1355fb_remove(dev); |
1da177e4 LT |
707 | return rc; |
708 | } | |
709 | ||
3ae5eaec | 710 | static struct platform_driver epson1355fb_driver = { |
1da177e4 LT |
711 | .probe = epson1355fb_probe, |
712 | .remove = epson1355fb_remove, | |
3ae5eaec RK |
713 | .driver = { |
714 | .name = "epson1355fb", | |
715 | }, | |
1da177e4 LT |
716 | }; |
717 | ||
673681c1 | 718 | static struct platform_device *epson1355fb_device; |
1da177e4 LT |
719 | |
720 | int __init epson1355fb_init(void) | |
721 | { | |
722 | int ret = 0; | |
723 | ||
724 | if (fb_get_options("epson1355fb", NULL)) | |
725 | return -ENODEV; | |
726 | ||
3ae5eaec | 727 | ret = platform_driver_register(&epson1355fb_driver); |
673681c1 | 728 | |
1da177e4 | 729 | if (!ret) { |
673681c1 AD |
730 | epson1355fb_device = platform_device_alloc("epson1355fb", 0); |
731 | ||
732 | if (epson1355fb_device) | |
733 | ret = platform_device_add(epson1355fb_device); | |
734 | else | |
735 | ret = -ENOMEM; | |
736 | ||
737 | if (ret) { | |
738 | platform_device_put(epson1355fb_device); | |
3ae5eaec | 739 | platform_driver_unregister(&epson1355fb_driver); |
673681c1 | 740 | } |
1da177e4 | 741 | } |
673681c1 | 742 | |
1da177e4 LT |
743 | return ret; |
744 | } | |
745 | ||
746 | module_init(epson1355fb_init); | |
747 | ||
748 | #ifdef MODULE | |
749 | static void __exit epson1355fb_exit(void) | |
750 | { | |
673681c1 | 751 | platform_device_unregister(epson1355fb_device); |
3ae5eaec | 752 | platform_driver_unregister(&epson1355fb_driver); |
1da177e4 LT |
753 | } |
754 | ||
755 | /* ------------------------------------------------------------------------- */ | |
756 | ||
757 | module_exit(epson1355fb_exit); | |
758 | #endif | |
759 | ||
760 | MODULE_AUTHOR("Christopher Hoover <ch@hpl.hp.com>"); | |
761 | MODULE_DESCRIPTION("Framebuffer driver for Epson S1D13505"); | |
762 | MODULE_LICENSE("GPL"); |