epson1355fb.c 19 KB

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