epson1355fb.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  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. #include <linux/module.h>
  46. #include <linux/kernel.h>
  47. #include <linux/errno.h>
  48. #include <linux/string.h>
  49. #include <linux/mm.h>
  50. #include <linux/slab.h>
  51. #include <linux/delay.h>
  52. #include <linux/fb.h>
  53. #include <linux/init.h>
  54. #include <linux/ioport.h>
  55. #include <linux/platform_device.h>
  56. #include <asm/types.h>
  57. #include <asm/io.h>
  58. #include <asm/uaccess.h>
  59. #include <video/epson1355.h>
  60. struct epson1355_par {
  61. unsigned long reg_addr;
  62. };
  63. /* ------------------------------------------------------------------------- */
  64. #ifdef CONFIG_SUPERH
  65. static inline u8 epson1355_read_reg(int index)
  66. {
  67. return ctrl_inb(par.reg_addr + index);
  68. }
  69. static inline void epson1355_write_reg(u8 data, int index)
  70. {
  71. ctrl_outb(data, par.reg_addr + index);
  72. }
  73. #elif defined(CONFIG_ARM)
  74. # ifdef CONFIG_ARCH_CEIVA
  75. # include <asm/arch/hardware.h>
  76. # define EPSON1355FB_BASE_PHYS (CEIVA_PHYS_SED1355)
  77. # endif
  78. static inline u8 epson1355_read_reg(struct epson1355_par *par, int index)
  79. {
  80. return __raw_readb(par->reg_addr + index);
  81. }
  82. static inline void epson1355_write_reg(struct epson1355_par *par, u8 data, int index)
  83. {
  84. __raw_writeb(data, par->reg_addr + index);
  85. }
  86. #else
  87. # error "no architecture-specific epson1355_{read,write}_reg"
  88. #endif
  89. #ifndef EPSON1355FB_BASE_PHYS
  90. # error "EPSON1355FB_BASE_PHYS is not defined"
  91. #endif
  92. #define EPSON1355FB_REGS_OFS (0)
  93. #define EPSON1355FB_REGS_PHYS (EPSON1355FB_BASE_PHYS + EPSON1355FB_REGS_OFS)
  94. #define EPSON1355FB_REGS_LEN (64)
  95. #define EPSON1355FB_FB_OFS (0x00200000)
  96. #define EPSON1355FB_FB_PHYS (EPSON1355FB_BASE_PHYS + EPSON1355FB_FB_OFS)
  97. #define EPSON1355FB_FB_LEN (2 * 1024 * 1024)
  98. /* ------------------------------------------------------------------------- */
  99. static inline u16 epson1355_read_reg16(struct epson1355_par *par, int index)
  100. {
  101. u8 lo = epson1355_read_reg(par, index);
  102. u8 hi = epson1355_read_reg(par, index + 1);
  103. return (hi << 8) | lo;
  104. }
  105. static inline void epson1355_write_reg16(struct epson1355_par *par, u16 data, int index)
  106. {
  107. u8 lo = data & 0xff;
  108. u8 hi = (data >> 8) & 0xff;
  109. epson1355_write_reg(par, lo, index);
  110. epson1355_write_reg(par, hi, index + 1);
  111. }
  112. static inline u32 epson1355_read_reg20(struct epson1355_par *par, int index)
  113. {
  114. u8 b0 = epson1355_read_reg(par, index);
  115. u8 b1 = epson1355_read_reg(par, index + 1);
  116. u8 b2 = epson1355_read_reg(par, index + 2);
  117. return (b2 & 0x0f) << 16 | (b1 << 8) | b0;
  118. }
  119. static inline void epson1355_write_reg20(struct epson1355_par *par, u32 data, int index)
  120. {
  121. u8 b0 = data & 0xff;
  122. u8 b1 = (data >> 8) & 0xff;
  123. u8 b2 = (data >> 16) & 0x0f;
  124. epson1355_write_reg(par, b0, index);
  125. epson1355_write_reg(par, b1, index + 1);
  126. epson1355_write_reg(par, b2, index + 2);
  127. }
  128. /* ------------------------------------------------------------------------- */
  129. static void set_lut(struct epson1355_par *par, u8 index, u8 r, u8 g, u8 b)
  130. {
  131. epson1355_write_reg(par, index, REG_LUT_ADDR);
  132. epson1355_write_reg(par, r, REG_LUT_DATA);
  133. epson1355_write_reg(par, g, REG_LUT_DATA);
  134. epson1355_write_reg(par, b, REG_LUT_DATA);
  135. }
  136. /**
  137. * epson1355fb_setcolreg - sets a color register.
  138. * @regno: Which register in the CLUT we are programming
  139. * @red: The red value which can be up to 16 bits wide
  140. * @green: The green value which can be up to 16 bits wide
  141. * @blue: The blue value which can be up to 16 bits wide.
  142. * @transp: If supported the alpha value which can be up to 16 bits wide.
  143. * @info: frame buffer info structure
  144. *
  145. * Returns negative errno on error, or zero on success.
  146. */
  147. static int epson1355fb_setcolreg(unsigned regno, unsigned r, unsigned g,
  148. unsigned b, unsigned transp,
  149. struct fb_info *info)
  150. {
  151. struct epson1355_par *par = info->par;
  152. if (info->var.grayscale)
  153. r = g = b = (19595 * r + 38470 * g + 7471 * b) >> 16;
  154. switch (info->fix.visual) {
  155. case FB_VISUAL_TRUECOLOR:
  156. if (regno >= 16)
  157. return -EINVAL;
  158. ((u32 *) info->pseudo_palette)[regno] =
  159. (r & 0xf800) | (g & 0xfc00) >> 5 | (b & 0xf800) >> 11;
  160. break;
  161. case FB_VISUAL_PSEUDOCOLOR:
  162. if (regno >= 256)
  163. return -EINVAL;
  164. set_lut(par, regno, r >> 8, g >> 8, b >> 8);
  165. break;
  166. default:
  167. return -ENOSYS;
  168. }
  169. return 0;
  170. }
  171. /* ------------------------------------------------------------------------- */
  172. /**
  173. * epson1355fb_pan_display - Pans the display.
  174. * @var: frame buffer variable screen structure
  175. * @info: frame buffer structure that represents a single frame buffer
  176. *
  177. * Pan (or wrap, depending on the `vmode' field) the display using the
  178. * `xoffset' and `yoffset' fields of the `var' structure.
  179. * If the values don't fit, return -EINVAL.
  180. *
  181. * Returns negative errno on error, or zero on success.
  182. */
  183. static int epson1355fb_pan_display(struct fb_var_screeninfo *var,
  184. struct fb_info *info)
  185. {
  186. struct epson1355_par *par = info->par;
  187. u32 start;
  188. if (var->xoffset != 0) /* not yet ... */
  189. return -EINVAL;
  190. if (var->yoffset + info->var.yres > info->var.yres_virtual)
  191. return -EINVAL;
  192. start = (info->fix.line_length >> 1) * var->yoffset;
  193. epson1355_write_reg20(par, start, REG_SCRN1_DISP_START_ADDR0);
  194. return 0;
  195. }
  196. /* ------------------------------------------------------------------------- */
  197. static void lcd_enable(struct epson1355_par *par, int enable)
  198. {
  199. u8 mode = epson1355_read_reg(par, REG_DISPLAY_MODE);
  200. if (enable)
  201. mode |= 1;
  202. else
  203. mode &= ~1;
  204. epson1355_write_reg(par, mode, REG_DISPLAY_MODE);
  205. }
  206. #if defined(CONFIG_ARCH_CEIVA)
  207. static void backlight_enable(int enable)
  208. {
  209. /* ### this should be protected by a spinlock ... */
  210. u8 pddr = clps_readb(PDDR);
  211. if (enable)
  212. pddr |= (1 << 5);
  213. else
  214. pddr &= ~(1 << 5);
  215. clps_writeb(pddr, PDDR);
  216. }
  217. #else
  218. static void backlight_enable(int enable)
  219. {
  220. }
  221. #endif
  222. /**
  223. * epson1355fb_blank - blanks the display.
  224. * @blank_mode: the blank mode we want.
  225. * @info: frame buffer structure that represents a single frame buffer
  226. *
  227. * Blank the screen if blank_mode != 0, else unblank. Return 0 if
  228. * blanking succeeded, != 0 if un-/blanking failed due to e.g. a
  229. * video mode which doesn't support it. Implements VESA suspend
  230. * and powerdown modes on hardware that supports disabling hsync/vsync:
  231. * blank_mode == 2: suspend vsync
  232. * blank_mode == 3: suspend hsync
  233. * blank_mode == 4: powerdown
  234. *
  235. * Returns negative errno on error, or zero on success.
  236. *
  237. */
  238. static int epson1355fb_blank(int blank_mode, struct fb_info *info)
  239. {
  240. struct epson1355_par *par = info->par;
  241. switch (blank_mode) {
  242. case FB_BLANK_UNBLANKING:
  243. case FB_BLANK_NORMAL:
  244. lcd_enable(par, 1);
  245. backlight_enable(1);
  246. break;
  247. case FB_BLANK_VSYNC_SUSPEND:
  248. case FB_BLANK_HSYNC_SUSPEND:
  249. backlight_enable(0);
  250. break;
  251. case FB_BLANK_POWERDOWN:
  252. backlight_enable(0);
  253. lcd_enable(par, 0);
  254. break;
  255. default:
  256. return -EINVAL;
  257. }
  258. /* let fbcon do a soft blank for us */
  259. return (blank_mode == FB_BLANK_NORMAL) ? 1 : 0;
  260. }
  261. /* ------------------------------------------------------------------------- */
  262. /*
  263. * We can't use the cfb generic routines, as we have to limit
  264. * ourselves to 16-bit or 8-bit loads and stores to this 16-bit
  265. * chip.
  266. */
  267. static inline void epson1355fb_fb_writel(unsigned long v, unsigned long *a)
  268. {
  269. u16 *p = (u16 *) a;
  270. u16 l = v & 0xffff;
  271. u16 h = v >> 16;
  272. fb_writew(l, p);
  273. fb_writew(h, p + 1);
  274. }
  275. static inline unsigned long epson1355fb_fb_readl(const unsigned long *a)
  276. {
  277. const u16 *p = (u16 *) a;
  278. u16 l = fb_readw(p);
  279. u16 h = fb_readw(p + 1);
  280. return (h << 16) | l;
  281. }
  282. #define FB_READL epson1355fb_fb_readl
  283. #define FB_WRITEL epson1355fb_fb_writel
  284. /* ------------------------------------------------------------------------- */
  285. static inline unsigned long copy_from_user16(void *to, const void *from,
  286. unsigned long n)
  287. {
  288. u16 *dst = (u16 *) to;
  289. u16 *src = (u16 *) from;
  290. if (!access_ok(VERIFY_READ, from, n))
  291. return n;
  292. while (n > 1) {
  293. u16 v;
  294. if (__get_user(v, src))
  295. return n;
  296. fb_writew(v, dst);
  297. src++, dst++;
  298. n -= 2;
  299. }
  300. if (n) {
  301. u8 v;
  302. if (__get_user(v, ((u8 *) src)))
  303. return n;
  304. fb_writeb(v, dst);
  305. }
  306. return 0;
  307. }
  308. static inline unsigned long copy_to_user16(void *to, const void *from,
  309. unsigned long n)
  310. {
  311. u16 *dst = (u16 *) to;
  312. u16 *src = (u16 *) from;
  313. if (!access_ok(VERIFY_WRITE, to, n))
  314. return n;
  315. while (n > 1) {
  316. u16 v = fb_readw(src);
  317. if (__put_user(v, dst))
  318. return n;
  319. src++, dst++;
  320. n -= 2;
  321. }
  322. if (n) {
  323. u8 v = fb_readb(src);
  324. if (__put_user(v, ((u8 *) dst)))
  325. return n;
  326. }
  327. return 0;
  328. }
  329. static ssize_t
  330. epson1355fb_read(struct file *file, char *buf, size_t count, loff_t * ppos)
  331. {
  332. struct inode *inode = file->f_path.dentry->d_inode;
  333. int fbidx = iminor(inode);
  334. struct fb_info *info = registered_fb[fbidx];
  335. unsigned long p = *ppos;
  336. /* from fbmem.c except for our own copy_*_user */
  337. if (!info || !info->screen_base)
  338. return -ENODEV;
  339. if (p >= info->fix.smem_len)
  340. return 0;
  341. if (count >= info->fix.smem_len)
  342. count = info->fix.smem_len;
  343. if (count + p > info->fix.smem_len)
  344. count = info->fix.smem_len - p;
  345. if (count) {
  346. char *base_addr;
  347. base_addr = info->screen_base;
  348. count -= copy_to_user16(buf, base_addr + p, count);
  349. if (!count)
  350. return -EFAULT;
  351. *ppos += count;
  352. }
  353. return count;
  354. }
  355. static ssize_t
  356. epson1355fb_write(struct file *file, const char *buf,
  357. size_t count, loff_t * ppos)
  358. {
  359. struct inode *inode = file->f_path.dentry->d_inode;
  360. int fbidx = iminor(inode);
  361. struct fb_info *info = registered_fb[fbidx];
  362. unsigned long p = *ppos;
  363. int err;
  364. /* from fbmem.c except for our own copy_*_user */
  365. if (!info || !info->screen_base)
  366. return -ENODEV;
  367. /* from fbmem.c except for our own copy_*_user */
  368. if (p > info->fix.smem_len)
  369. return -ENOSPC;
  370. if (count >= info->fix.smem_len)
  371. count = info->fix.smem_len;
  372. err = 0;
  373. if (count + p > info->fix.smem_len) {
  374. count = info->fix.smem_len - p;
  375. err = -ENOSPC;
  376. }
  377. if (count) {
  378. char *base_addr;
  379. base_addr = info->screen_base;
  380. count -= copy_from_user16(base_addr + p, buf, count);
  381. *ppos += count;
  382. err = -EFAULT;
  383. }
  384. if (count)
  385. return count;
  386. return err;
  387. }
  388. /* ------------------------------------------------------------------------- */
  389. static struct fb_ops epson1355fb_fbops = {
  390. .owner = THIS_MODULE,
  391. .fb_setcolreg = epson1355fb_setcolreg,
  392. .fb_pan_display = epson1355fb_pan_display,
  393. .fb_blank = epson1355fb_blank,
  394. .fb_fillrect = cfb_fillrect,
  395. .fb_copyarea = cfb_copyarea,
  396. .fb_imageblit = cfb_imageblit,
  397. .fb_read = epson1355fb_read,
  398. .fb_write = epson1355fb_write,
  399. };
  400. /* ------------------------------------------------------------------------- */
  401. static __init unsigned int get_fb_size(struct fb_info *info)
  402. {
  403. unsigned int size = 2 * 1024 * 1024;
  404. char *p = info->screen_base;
  405. /* the 512k framebuffer is aliased at start + 0x80000 * n */
  406. fb_writeb(1, p);
  407. fb_writeb(0, p + 0x80000);
  408. if (!fb_readb(p))
  409. size = 512 * 1024;
  410. fb_writeb(0, p);
  411. return size;
  412. }
  413. static int epson1355_width_tab[2][4] __initdata =
  414. { {4, 8, 16, -1}, {9, 12, 16, -1} };
  415. static int epson1355_bpp_tab[8] __initdata = { 1, 2, 4, 8, 15, 16 };
  416. static void __init fetch_hw_state(struct fb_info *info, struct epson1355_par *par)
  417. {
  418. struct fb_var_screeninfo *var = &info->var;
  419. struct fb_fix_screeninfo *fix = &info->fix;
  420. u8 panel, display;
  421. u16 offset;
  422. u32 xres, yres;
  423. u32 xres_virtual, yres_virtual;
  424. int bpp, lcd_bpp;
  425. int is_color, is_dual, is_tft;
  426. int lcd_enabled, crt_enabled;
  427. fix->type = FB_TYPE_PACKED_PIXELS;
  428. display = epson1355_read_reg(par, REG_DISPLAY_MODE);
  429. bpp = epson1355_bpp_tab[(display >> 2) & 7];
  430. switch (bpp) {
  431. case 8:
  432. fix->visual = FB_VISUAL_PSEUDOCOLOR;
  433. var->bits_per_pixel = 8;
  434. var->red.offset = var->green.offset = var->blue.offset = 0;
  435. var->red.length = var->green.length = var->blue.length = 8;
  436. break;
  437. case 16:
  438. /* 5-6-5 RGB */
  439. fix->visual = FB_VISUAL_TRUECOLOR;
  440. var->bits_per_pixel = 16;
  441. var->red.offset = 11;
  442. var->red.length = 5;
  443. var->green.offset = 5;
  444. var->green.length = 6;
  445. var->blue.offset = 0;
  446. var->blue.length = 5;
  447. break;
  448. default:
  449. BUG();
  450. }
  451. fb_alloc_cmap(&(info->cmap), 256, 0);
  452. panel = epson1355_read_reg(par, REG_PANEL_TYPE);
  453. is_color = (panel & 0x04) != 0;
  454. is_dual = (panel & 0x02) != 0;
  455. is_tft = (panel & 0x01) != 0;
  456. crt_enabled = (display & 0x02) != 0;
  457. lcd_enabled = (display & 0x01) != 0;
  458. lcd_bpp = epson1355_width_tab[is_tft][(panel >> 4) & 3];
  459. xres = (epson1355_read_reg(par, REG_HORZ_DISP_WIDTH) + 1) * 8;
  460. yres = (epson1355_read_reg16(par, REG_VERT_DISP_HEIGHT0) + 1) *
  461. ((is_dual && !crt_enabled) ? 2 : 1);
  462. offset = epson1355_read_reg16(par, REG_MEM_ADDR_OFFSET0) & 0x7ff;
  463. xres_virtual = offset * 16 / bpp;
  464. yres_virtual = fix->smem_len / (offset * 2);
  465. var->xres = xres;
  466. var->yres = yres;
  467. var->xres_virtual = xres_virtual;
  468. var->yres_virtual = yres_virtual;
  469. var->xoffset = var->yoffset = 0;
  470. fix->line_length = offset * 2;
  471. fix->xpanstep = 0; /* no pan yet */
  472. fix->ypanstep = 1;
  473. fix->ywrapstep = 0;
  474. fix->accel = FB_ACCEL_NONE;
  475. var->grayscale = !is_color;
  476. #ifdef DEBUG
  477. printk(KERN_INFO
  478. "epson1355fb: xres=%d, yres=%d, "
  479. "is_color=%d, is_dual=%d, is_tft=%d\n",
  480. xres, yres, is_color, is_dual, is_tft);
  481. printk(KERN_INFO
  482. "epson1355fb: bpp=%d, lcd_bpp=%d, "
  483. "crt_enabled=%d, lcd_enabled=%d\n",
  484. bpp, lcd_bpp, crt_enabled, lcd_enabled);
  485. #endif
  486. }
  487. static void clearfb16(struct fb_info *info)
  488. {
  489. u16 *dst = (u16 *) info->screen_base;
  490. unsigned long n = info->fix.smem_len;
  491. while (n > 1) {
  492. fb_writew(0, dst);
  493. dst++, n -= 2;
  494. }
  495. if (n)
  496. fb_writeb(0, dst);
  497. }
  498. static int epson1355fb_remove(struct platform_device *dev)
  499. {
  500. struct fb_info *info = platform_get_drvdata(dev);
  501. struct epson1355_par *par = info->par;
  502. backlight_enable(0);
  503. if (par) {
  504. lcd_enable(par, 0);
  505. if (par && par->reg_addr)
  506. iounmap((void *) par->reg_addr);
  507. }
  508. if (info) {
  509. fb_dealloc_cmap(&info->cmap);
  510. if (info->screen_base)
  511. iounmap(info->screen_base);
  512. framebuffer_release(info);
  513. }
  514. release_mem_region(EPSON1355FB_FB_PHYS, EPSON1355FB_FB_LEN);
  515. release_mem_region(EPSON1355FB_REGS_PHYS, EPSON1355FB_REGS_LEN);
  516. return 0;
  517. }
  518. int __init epson1355fb_probe(struct platform_device *dev)
  519. {
  520. struct epson1355_par *default_par;
  521. struct fb_info *info;
  522. u8 revision;
  523. int rc = 0;
  524. if (!request_mem_region(EPSON1355FB_REGS_PHYS, EPSON1355FB_REGS_LEN, "S1D13505 registers")) {
  525. printk(KERN_ERR "epson1355fb: unable to reserve "
  526. "registers at 0x%0x\n", EPSON1355FB_REGS_PHYS);
  527. rc = -EBUSY;
  528. goto bail;
  529. }
  530. if (!request_mem_region(EPSON1355FB_FB_PHYS, EPSON1355FB_FB_LEN,
  531. "S1D13505 framebuffer")) {
  532. printk(KERN_ERR "epson1355fb: unable to reserve "
  533. "framebuffer at 0x%0x\n", EPSON1355FB_FB_PHYS);
  534. rc = -EBUSY;
  535. goto bail;
  536. }
  537. info = framebuffer_alloc(sizeof(struct epson1355_par) + sizeof(u32) * 256, &dev->dev);
  538. if (!info)
  539. rc = -ENOMEM;
  540. goto bail;
  541. default_par = info->par;
  542. default_par->reg_addr = (unsigned long) ioremap(EPSON1355FB_REGS_PHYS, EPSON1355FB_REGS_LEN);
  543. if (!default_par->reg_addr) {
  544. printk(KERN_ERR "epson1355fb: unable to map registers\n");
  545. rc = -ENOMEM;
  546. goto bail;
  547. }
  548. info->pseudo_palette = (void *)(default_par + 1);
  549. info->screen_base = ioremap(EPSON1355FB_FB_PHYS, EPSON1355FB_FB_LEN);
  550. if (!info->screen_base) {
  551. printk(KERN_ERR "epson1355fb: unable to map framebuffer\n");
  552. rc = -ENOMEM;
  553. goto bail;
  554. }
  555. revision = epson1355_read_reg(default_par, REG_REVISION_CODE);
  556. if ((revision >> 2) != 3) {
  557. printk(KERN_INFO "epson1355fb: epson1355 not found\n");
  558. rc = -ENODEV;
  559. goto bail;
  560. }
  561. info->fix.mmio_start = EPSON1355FB_REGS_PHYS;
  562. info->fix.mmio_len = EPSON1355FB_REGS_LEN;
  563. info->fix.smem_start = EPSON1355FB_FB_PHYS;
  564. info->fix.smem_len = get_fb_size(info);
  565. printk(KERN_INFO "epson1355fb: regs mapped at 0x%lx, fb %d KiB mapped at 0x%p\n",
  566. default_par->reg_addr, info->fix.smem_len / 1024, info->screen_base);
  567. strcpy(info->fix.id, "S1D13505");
  568. info->par = default_par;
  569. info->fbops = &epson1355fb_fbops;
  570. info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
  571. /* we expect the boot loader to have initialized the chip
  572. with appropriate parameters from which we can determinte
  573. the flavor of lcd panel attached */
  574. fetch_hw_state(info, default_par);
  575. /* turn this puppy on ... */
  576. clearfb16(info);
  577. backlight_enable(1);
  578. lcd_enable(default_par, 1);
  579. if (register_framebuffer(info) < 0) {
  580. rc = -EINVAL;
  581. goto bail;
  582. }
  583. /*
  584. * Our driver data.
  585. */
  586. platform_set_drvdata(dev, info);
  587. printk(KERN_INFO "fb%d: %s frame buffer device\n",
  588. info->node, info->fix.id);
  589. return 0;
  590. bail:
  591. epson1355fb_remove(dev);
  592. return rc;
  593. }
  594. static struct platform_driver epson1355fb_driver = {
  595. .probe = epson1355fb_probe,
  596. .remove = epson1355fb_remove,
  597. .driver = {
  598. .name = "epson1355fb",
  599. },
  600. };
  601. static struct platform_device *epson1355fb_device;
  602. int __init epson1355fb_init(void)
  603. {
  604. int ret = 0;
  605. if (fb_get_options("epson1355fb", NULL))
  606. return -ENODEV;
  607. ret = platform_driver_register(&epson1355fb_driver);
  608. if (!ret) {
  609. epson1355fb_device = platform_device_alloc("epson1355fb", 0);
  610. if (epson1355fb_device)
  611. ret = platform_device_add(epson1355fb_device);
  612. else
  613. ret = -ENOMEM;
  614. if (ret) {
  615. platform_device_put(epson1355fb_device);
  616. platform_driver_unregister(&epson1355fb_driver);
  617. }
  618. }
  619. return ret;
  620. }
  621. module_init(epson1355fb_init);
  622. #ifdef MODULE
  623. static void __exit epson1355fb_exit(void)
  624. {
  625. platform_device_unregister(epson1355fb_device);
  626. platform_driver_unregister(&epson1355fb_driver);
  627. }
  628. /* ------------------------------------------------------------------------- */
  629. module_exit(epson1355fb_exit);
  630. #endif
  631. MODULE_AUTHOR("Christopher Hoover <ch@hpl.hp.com>");
  632. MODULE_DESCRIPTION("Framebuffer driver for Epson S1D13505");
  633. MODULE_LICENSE("GPL");