nuc900fb.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  1. /*
  2. *
  3. * Copyright (c) 2009 Nuvoton technology corporation
  4. * All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Description:
  12. * Nuvoton LCD Controller Driver
  13. * Author:
  14. * Wang Qiang (rurality.linux@gmail.com) 2009/12/11
  15. */
  16. #include <linux/module.h>
  17. #include <linux/kernel.h>
  18. #include <linux/err.h>
  19. #include <linux/errno.h>
  20. #include <linux/string.h>
  21. #include <linux/mm.h>
  22. #include <linux/tty.h>
  23. #include <linux/slab.h>
  24. #include <linux/delay.h>
  25. #include <linux/fb.h>
  26. #include <linux/init.h>
  27. #include <linux/dma-mapping.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/workqueue.h>
  30. #include <linux/wait.h>
  31. #include <linux/platform_device.h>
  32. #include <linux/clk.h>
  33. #include <linux/cpufreq.h>
  34. #include <linux/io.h>
  35. #include <linux/pm.h>
  36. #include <linux/device.h>
  37. #include <mach/map.h>
  38. #include <mach/regs-clock.h>
  39. #include <mach/regs-ldm.h>
  40. #include <mach/fb.h>
  41. #include <mach/clkdev.h>
  42. #include "nuc900fb.h"
  43. /*
  44. * Initialize the nuc900 video (dual) buffer address
  45. */
  46. static void nuc900fb_set_lcdaddr(struct fb_info *info)
  47. {
  48. struct nuc900fb_info *fbi = info->par;
  49. void __iomem *regs = fbi->io;
  50. unsigned long vbaddr1, vbaddr2;
  51. vbaddr1 = info->fix.smem_start;
  52. vbaddr2 = info->fix.smem_start;
  53. vbaddr2 += info->fix.line_length * info->var.yres;
  54. /* set frambuffer start phy addr*/
  55. writel(vbaddr1, regs + REG_LCM_VA_BADDR0);
  56. writel(vbaddr2, regs + REG_LCM_VA_BADDR1);
  57. writel(fbi->regs.lcd_va_fbctrl, regs + REG_LCM_VA_FBCTRL);
  58. writel(fbi->regs.lcd_va_scale, regs + REG_LCM_VA_SCALE);
  59. }
  60. /*
  61. * calculate divider for lcd div
  62. */
  63. static unsigned int nuc900fb_calc_pixclk(struct nuc900fb_info *fbi,
  64. unsigned long pixclk)
  65. {
  66. unsigned long clk = fbi->clk_rate;
  67. unsigned long long div;
  68. /* pixclk is in picseconds. our clock is in Hz*/
  69. /* div = (clk * pixclk)/10^12 */
  70. div = (unsigned long long)clk * pixclk;
  71. div >>= 12;
  72. do_div(div, 625 * 625UL * 625);
  73. dev_dbg(fbi->dev, "pixclk %ld, divisor is %lld\n", pixclk, div);
  74. return div;
  75. }
  76. /*
  77. * Check the video params of 'var'.
  78. */
  79. static int nuc900fb_check_var(struct fb_var_screeninfo *var,
  80. struct fb_info *info)
  81. {
  82. struct nuc900fb_info *fbi = info->par;
  83. struct nuc900fb_mach_info *mach_info = fbi->dev->platform_data;
  84. struct nuc900fb_display *display = NULL;
  85. struct nuc900fb_display *default_display = mach_info->displays +
  86. mach_info->default_display;
  87. int i;
  88. dev_dbg(fbi->dev, "check_var(var=%p, info=%p)\n", var, info);
  89. /* validate x/y resolution */
  90. /* choose default mode if possible */
  91. if (var->xres == default_display->xres &&
  92. var->yres == default_display->yres &&
  93. var->bits_per_pixel == default_display->bpp)
  94. display = default_display;
  95. else
  96. for (i = 0; i < mach_info->num_displays; i++)
  97. if (var->xres == mach_info->displays[i].xres &&
  98. var->yres == mach_info->displays[i].yres &&
  99. var->bits_per_pixel == mach_info->displays[i].bpp) {
  100. display = mach_info->displays + i;
  101. break;
  102. }
  103. if (display == NULL) {
  104. printk(KERN_ERR "wrong resolution or depth %dx%d at %d bit per pixel\n",
  105. var->xres, var->yres, var->bits_per_pixel);
  106. return -EINVAL;
  107. }
  108. /* it should be the same size as the display */
  109. var->xres_virtual = display->xres;
  110. var->yres_virtual = display->yres;
  111. var->height = display->height;
  112. var->width = display->width;
  113. /* copy lcd settings */
  114. var->pixclock = display->pixclock;
  115. var->left_margin = display->left_margin;
  116. var->right_margin = display->right_margin;
  117. var->upper_margin = display->upper_margin;
  118. var->lower_margin = display->lower_margin;
  119. var->vsync_len = display->vsync_len;
  120. var->hsync_len = display->hsync_len;
  121. var->transp.offset = 0;
  122. var->transp.length = 0;
  123. fbi->regs.lcd_dccs = display->dccs;
  124. fbi->regs.lcd_device_ctrl = display->devctl;
  125. fbi->regs.lcd_va_fbctrl = display->fbctrl;
  126. fbi->regs.lcd_va_scale = display->scale;
  127. /* set R/G/B possions */
  128. switch (var->bits_per_pixel) {
  129. case 1:
  130. case 2:
  131. case 4:
  132. case 8:
  133. default:
  134. var->red.offset = 0;
  135. var->red.length = var->bits_per_pixel;
  136. var->green = var->red;
  137. var->blue = var->red;
  138. break;
  139. case 12:
  140. var->red.length = 4;
  141. var->green.length = 4;
  142. var->blue.length = 4;
  143. var->red.offset = 8;
  144. var->green.offset = 4;
  145. var->blue.offset = 0;
  146. break;
  147. case 16:
  148. var->red.length = 5;
  149. var->green.length = 6;
  150. var->blue.length = 5;
  151. var->red.offset = 11;
  152. var->green.offset = 5;
  153. var->blue.offset = 0;
  154. break;
  155. case 18:
  156. var->red.length = 6;
  157. var->green.length = 6;
  158. var->blue.length = 6;
  159. var->red.offset = 12;
  160. var->green.offset = 6;
  161. var->blue.offset = 0;
  162. break;
  163. case 32:
  164. var->red.length = 8;
  165. var->green.length = 8;
  166. var->blue.length = 8;
  167. var->red.offset = 16;
  168. var->green.offset = 8;
  169. var->blue.offset = 0;
  170. break;
  171. }
  172. return 0;
  173. }
  174. /*
  175. * Calculate lcd register values from var setting & save into hw
  176. */
  177. static void nuc900fb_calculate_lcd_regs(const struct fb_info *info,
  178. struct nuc900fb_hw *regs)
  179. {
  180. const struct fb_var_screeninfo *var = &info->var;
  181. int vtt = var->height + var->upper_margin + var->lower_margin;
  182. int htt = var->width + var->left_margin + var->right_margin;
  183. int hsync = var->width + var->right_margin;
  184. int vsync = var->height + var->lower_margin;
  185. regs->lcd_crtc_size = LCM_CRTC_SIZE_VTTVAL(vtt) |
  186. LCM_CRTC_SIZE_HTTVAL(htt);
  187. regs->lcd_crtc_dend = LCM_CRTC_DEND_VDENDVAL(var->height) |
  188. LCM_CRTC_DEND_HDENDVAL(var->width);
  189. regs->lcd_crtc_hr = LCM_CRTC_HR_EVAL(var->width + 5) |
  190. LCM_CRTC_HR_SVAL(var->width + 1);
  191. regs->lcd_crtc_hsync = LCM_CRTC_HSYNC_EVAL(hsync + var->hsync_len) |
  192. LCM_CRTC_HSYNC_SVAL(hsync);
  193. regs->lcd_crtc_vr = LCM_CRTC_VR_EVAL(vsync + var->vsync_len) |
  194. LCM_CRTC_VR_SVAL(vsync);
  195. }
  196. /*
  197. * Activate (set) the controller from the given framebuffer
  198. * information
  199. */
  200. static void nuc900fb_activate_var(struct fb_info *info)
  201. {
  202. struct nuc900fb_info *fbi = info->par;
  203. void __iomem *regs = fbi->io;
  204. struct fb_var_screeninfo *var = &info->var;
  205. int clkdiv;
  206. clkdiv = nuc900fb_calc_pixclk(fbi, var->pixclock) - 1;
  207. if (clkdiv < 0)
  208. clkdiv = 0;
  209. nuc900fb_calculate_lcd_regs(info, &fbi->regs);
  210. /* set the new lcd registers*/
  211. dev_dbg(fbi->dev, "new lcd register set:\n");
  212. dev_dbg(fbi->dev, "dccs = 0x%08x\n", fbi->regs.lcd_dccs);
  213. dev_dbg(fbi->dev, "dev_ctl = 0x%08x\n", fbi->regs.lcd_device_ctrl);
  214. dev_dbg(fbi->dev, "crtc_size = 0x%08x\n", fbi->regs.lcd_crtc_size);
  215. dev_dbg(fbi->dev, "crtc_dend = 0x%08x\n", fbi->regs.lcd_crtc_dend);
  216. dev_dbg(fbi->dev, "crtc_hr = 0x%08x\n", fbi->regs.lcd_crtc_hr);
  217. dev_dbg(fbi->dev, "crtc_hsync = 0x%08x\n", fbi->regs.lcd_crtc_hsync);
  218. dev_dbg(fbi->dev, "crtc_vr = 0x%08x\n", fbi->regs.lcd_crtc_vr);
  219. writel(fbi->regs.lcd_device_ctrl, regs + REG_LCM_DEV_CTRL);
  220. writel(fbi->regs.lcd_crtc_size, regs + REG_LCM_CRTC_SIZE);
  221. writel(fbi->regs.lcd_crtc_dend, regs + REG_LCM_CRTC_DEND);
  222. writel(fbi->regs.lcd_crtc_hr, regs + REG_LCM_CRTC_HR);
  223. writel(fbi->regs.lcd_crtc_hsync, regs + REG_LCM_CRTC_HSYNC);
  224. writel(fbi->regs.lcd_crtc_vr, regs + REG_LCM_CRTC_VR);
  225. /* set lcd address pointers */
  226. nuc900fb_set_lcdaddr(info);
  227. writel(fbi->regs.lcd_dccs, regs + REG_LCM_DCCS);
  228. }
  229. /*
  230. * Alters the hardware state.
  231. *
  232. */
  233. static int nuc900fb_set_par(struct fb_info *info)
  234. {
  235. struct fb_var_screeninfo *var = &info->var;
  236. switch (var->bits_per_pixel) {
  237. case 32:
  238. case 24:
  239. case 18:
  240. case 16:
  241. case 12:
  242. info->fix.visual = FB_VISUAL_TRUECOLOR;
  243. break;
  244. case 1:
  245. info->fix.visual = FB_VISUAL_MONO01;
  246. break;
  247. default:
  248. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  249. break;
  250. }
  251. info->fix.line_length = (var->xres_virtual * var->bits_per_pixel) / 8;
  252. /* activate this new configuration */
  253. nuc900fb_activate_var(info);
  254. return 0;
  255. }
  256. static inline unsigned int chan_to_field(unsigned int chan,
  257. struct fb_bitfield *bf)
  258. {
  259. chan &= 0xffff;
  260. chan >>= 16 - bf->length;
  261. return chan << bf->offset;
  262. }
  263. static int nuc900fb_setcolreg(unsigned regno,
  264. unsigned red, unsigned green, unsigned blue,
  265. unsigned transp, struct fb_info *info)
  266. {
  267. unsigned int val;
  268. switch (info->fix.visual) {
  269. case FB_VISUAL_TRUECOLOR:
  270. /* true-colour, use pseuo-palette */
  271. if (regno < 16) {
  272. u32 *pal = info->pseudo_palette;
  273. val = chan_to_field(red, &info->var.red);
  274. val |= chan_to_field(green, &info->var.green);
  275. val |= chan_to_field(blue, &info->var.blue);
  276. pal[regno] = val;
  277. }
  278. break;
  279. default:
  280. return 1; /* unknown type */
  281. }
  282. return 0;
  283. }
  284. /**
  285. * nuc900fb_blank
  286. *
  287. */
  288. static int nuc900fb_blank(int blank_mode, struct fb_info *info)
  289. {
  290. return 0;
  291. }
  292. static struct fb_ops nuc900fb_ops = {
  293. .owner = THIS_MODULE,
  294. .fb_check_var = nuc900fb_check_var,
  295. .fb_set_par = nuc900fb_set_par,
  296. .fb_blank = nuc900fb_blank,
  297. .fb_setcolreg = nuc900fb_setcolreg,
  298. .fb_fillrect = cfb_fillrect,
  299. .fb_copyarea = cfb_copyarea,
  300. .fb_imageblit = cfb_imageblit,
  301. };
  302. static inline void modify_gpio(void __iomem *reg,
  303. unsigned long set, unsigned long mask)
  304. {
  305. unsigned long tmp;
  306. tmp = readl(reg) & ~mask;
  307. writel(tmp | set, reg);
  308. }
  309. /*
  310. * Initialise LCD-related registers
  311. */
  312. static int nuc900fb_init_registers(struct fb_info *info)
  313. {
  314. struct nuc900fb_info *fbi = info->par;
  315. struct nuc900fb_mach_info *mach_info = fbi->dev->platform_data;
  316. void __iomem *regs = fbi->io;
  317. /*reset the display engine*/
  318. writel(0, regs + REG_LCM_DCCS);
  319. writel(readl(regs + REG_LCM_DCCS) | LCM_DCCS_ENG_RST,
  320. regs + REG_LCM_DCCS);
  321. ndelay(100);
  322. writel(readl(regs + REG_LCM_DCCS) & (~LCM_DCCS_ENG_RST),
  323. regs + REG_LCM_DCCS);
  324. ndelay(100);
  325. writel(0, regs + REG_LCM_DEV_CTRL);
  326. /* config gpio output */
  327. modify_gpio(W90X900_VA_GPIO + 0x54, mach_info->gpio_dir,
  328. mach_info->gpio_dir_mask);
  329. modify_gpio(W90X900_VA_GPIO + 0x58, mach_info->gpio_data,
  330. mach_info->gpio_data_mask);
  331. return 0;
  332. }
  333. /*
  334. * Alloc the SDRAM region of NUC900 for the frame buffer.
  335. * The buffer should be a non-cached, non-buffered, memory region
  336. * to allow palette and pixel writes without flushing the cache.
  337. */
  338. static int __init nuc900fb_map_video_memory(struct fb_info *info)
  339. {
  340. struct nuc900fb_info *fbi = info->par;
  341. dma_addr_t map_dma;
  342. unsigned long map_size = PAGE_ALIGN(info->fix.smem_len);
  343. dev_dbg(fbi->dev, "nuc900fb_map_video_memory(fbi=%p) map_size %lu\n",
  344. fbi, map_size);
  345. info->screen_base = dma_alloc_writecombine(fbi->dev, map_size,
  346. &map_dma, GFP_KERNEL);
  347. if (!info->screen_base)
  348. return -ENOMEM;
  349. memset(info->screen_base, 0x00, map_size);
  350. info->fix.smem_start = map_dma;
  351. return 0;
  352. }
  353. static inline void nuc900fb_unmap_video_memory(struct fb_info *info)
  354. {
  355. struct nuc900fb_info *fbi = info->par;
  356. dma_free_writecombine(fbi->dev, PAGE_ALIGN(info->fix.smem_len),
  357. info->screen_base, info->fix.smem_start);
  358. }
  359. static irqreturn_t nuc900fb_irqhandler(int irq, void *dev_id)
  360. {
  361. struct nuc900fb_info *fbi = dev_id;
  362. void __iomem *regs = fbi->io;
  363. void __iomem *irq_base = fbi->irq_base;
  364. unsigned long lcdirq = readl(regs + REG_LCM_INT_CS);
  365. if (lcdirq & LCM_INT_CS_DISP_F_STATUS) {
  366. writel(readl(irq_base) | 1<<30, irq_base);
  367. /* wait VA_EN low */
  368. if ((readl(regs + REG_LCM_DCCS) &
  369. LCM_DCCS_SINGLE) == LCM_DCCS_SINGLE)
  370. while ((readl(regs + REG_LCM_DCCS) &
  371. LCM_DCCS_VA_EN) == LCM_DCCS_VA_EN)
  372. ;
  373. /* display_out-enable */
  374. writel(readl(regs + REG_LCM_DCCS) | LCM_DCCS_DISP_OUT_EN,
  375. regs + REG_LCM_DCCS);
  376. /* va-enable*/
  377. writel(readl(regs + REG_LCM_DCCS) | LCM_DCCS_VA_EN,
  378. regs + REG_LCM_DCCS);
  379. } else if (lcdirq & LCM_INT_CS_UNDERRUN_INT) {
  380. writel(readl(irq_base) | LCM_INT_CS_UNDERRUN_INT, irq_base);
  381. } else if (lcdirq & LCM_INT_CS_BUS_ERROR_INT) {
  382. writel(readl(irq_base) | LCM_INT_CS_BUS_ERROR_INT, irq_base);
  383. }
  384. return IRQ_HANDLED;
  385. }
  386. #ifdef CONFIG_CPU_FREQ
  387. static int nuc900fb_cpufreq_transition(struct notifier_block *nb,
  388. unsigned long val, void *data)
  389. {
  390. struct nuc900fb_info *info;
  391. struct fb_info *fbinfo;
  392. long delta_f;
  393. info = container_of(nb, struct nuc900fb_info, freq_transition);
  394. fbinfo = platform_get_drvdata(to_platform_device(info->dev));
  395. delta_f = info->clk_rate - clk_get_rate(info->clk);
  396. if ((val == CPUFREQ_POSTCHANGE && delta_f > 0) ||
  397. (val == CPUFREQ_PRECHANGE && delta_f < 0)) {
  398. info->clk_rate = clk_get_rate(info->clk);
  399. nuc900fb_activate_var(fbinfo);
  400. }
  401. return 0;
  402. }
  403. static inline int nuc900fb_cpufreq_register(struct nuc900fb_info *fbi)
  404. {
  405. fbi->freq_transition.notifier_call = nuc900fb_cpufreq_transition;
  406. return cpufreq_register_notifier(&fbi->freq_transition,
  407. CPUFREQ_TRANSITION_NOTIFIER);
  408. }
  409. static inline void nuc900fb_cpufreq_deregister(struct nuc900fb_info *fbi)
  410. {
  411. cpufreq_unregister_notifier(&fbi->freq_transition,
  412. CPUFREQ_TRANSITION_NOTIFIER);
  413. }
  414. #else
  415. static inline int nuc900fb_cpufreq_transition(struct notifier_block *nb,
  416. unsigned long val, void *data)
  417. {
  418. return 0;
  419. }
  420. static inline int nuc900fb_cpufreq_register(struct nuc900fb_info *fbi)
  421. {
  422. return 0;
  423. }
  424. static inline void nuc900fb_cpufreq_deregister(struct nuc900fb_info *info)
  425. {
  426. }
  427. #endif
  428. static char driver_name[] = "nuc900fb";
  429. static int __devinit nuc900fb_probe(struct platform_device *pdev)
  430. {
  431. struct nuc900fb_info *fbi;
  432. struct nuc900fb_display *display;
  433. struct fb_info *fbinfo;
  434. struct nuc900fb_mach_info *mach_info;
  435. struct resource *res;
  436. int ret;
  437. int irq;
  438. int i;
  439. int size;
  440. dev_dbg(&pdev->dev, "devinit\n");
  441. mach_info = pdev->dev.platform_data;
  442. if (mach_info == NULL) {
  443. dev_err(&pdev->dev,
  444. "no platform data for lcd, cannot attach\n");
  445. return -EINVAL;
  446. }
  447. if (mach_info->default_display > mach_info->num_displays) {
  448. dev_err(&pdev->dev,
  449. "default display No. is %d but only %d displays \n",
  450. mach_info->default_display, mach_info->num_displays);
  451. return -EINVAL;
  452. }
  453. display = mach_info->displays + mach_info->default_display;
  454. irq = platform_get_irq(pdev, 0);
  455. if (irq < 0) {
  456. dev_err(&pdev->dev, "no irq for device\n");
  457. return -ENOENT;
  458. }
  459. fbinfo = framebuffer_alloc(sizeof(struct nuc900fb_info), &pdev->dev);
  460. if (!fbinfo)
  461. return -ENOMEM;
  462. platform_set_drvdata(pdev, fbinfo);
  463. fbi = fbinfo->par;
  464. fbi->dev = &pdev->dev;
  465. #ifdef CONFIG_CPU_NUC950
  466. fbi->drv_type = LCDDRV_NUC950;
  467. #endif
  468. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  469. size = (res->end - res->start) + 1;
  470. fbi->mem = request_mem_region(res->start, size, pdev->name);
  471. if (fbi->mem == NULL) {
  472. dev_err(&pdev->dev, "failed to alloc memory region\n");
  473. ret = -ENOENT;
  474. goto free_fb;
  475. }
  476. fbi->io = ioremap(res->start, size);
  477. if (fbi->io == NULL) {
  478. dev_err(&pdev->dev, "ioremap() of lcd registers failed\n");
  479. ret = -ENXIO;
  480. goto release_mem_region;
  481. }
  482. fbi->irq_base = fbi->io + REG_LCM_INT_CS;
  483. /* Stop the LCD */
  484. writel(0, fbi->io + REG_LCM_DCCS);
  485. /* fill the fbinfo*/
  486. strcpy(fbinfo->fix.id, driver_name);
  487. fbinfo->fix.type = FB_TYPE_PACKED_PIXELS;
  488. fbinfo->fix.type_aux = 0;
  489. fbinfo->fix.xpanstep = 0;
  490. fbinfo->fix.ypanstep = 0;
  491. fbinfo->fix.ywrapstep = 0;
  492. fbinfo->fix.accel = FB_ACCEL_NONE;
  493. fbinfo->var.nonstd = 0;
  494. fbinfo->var.activate = FB_ACTIVATE_NOW;
  495. fbinfo->var.accel_flags = 0;
  496. fbinfo->var.vmode = FB_VMODE_NONINTERLACED;
  497. fbinfo->fbops = &nuc900fb_ops;
  498. fbinfo->flags = FBINFO_FLAG_DEFAULT;
  499. fbinfo->pseudo_palette = &fbi->pseudo_pal;
  500. ret = request_irq(irq, nuc900fb_irqhandler, IRQF_DISABLED,
  501. pdev->name, fbinfo);
  502. if (ret) {
  503. dev_err(&pdev->dev, "cannot register irq handler %d -err %d\n",
  504. irq, ret);
  505. ret = -EBUSY;
  506. goto release_regs;
  507. }
  508. fbi->clk = clk_get(&pdev->dev, NULL);
  509. if (IS_ERR(fbi->clk)) {
  510. printk(KERN_ERR "nuc900-lcd:failed to get lcd clock source\n");
  511. ret = PTR_ERR(fbi->clk);
  512. goto release_irq;
  513. }
  514. clk_enable(fbi->clk);
  515. dev_dbg(&pdev->dev, "got and enabled clock\n");
  516. fbi->clk_rate = clk_get_rate(fbi->clk);
  517. /* calutate the video buffer size */
  518. for (i = 0; i < mach_info->num_displays; i++) {
  519. unsigned long smem_len = mach_info->displays[i].xres;
  520. smem_len *= mach_info->displays[i].yres;
  521. smem_len *= mach_info->displays[i].bpp;
  522. smem_len >>= 3;
  523. if (fbinfo->fix.smem_len < smem_len)
  524. fbinfo->fix.smem_len = smem_len;
  525. }
  526. /* Initialize Video Memory */
  527. ret = nuc900fb_map_video_memory(fbinfo);
  528. if (ret) {
  529. printk(KERN_ERR "Failed to allocate video RAM: %x\n", ret);
  530. goto release_clock;
  531. }
  532. dev_dbg(&pdev->dev, "got video memory\n");
  533. fbinfo->var.xres = display->xres;
  534. fbinfo->var.yres = display->yres;
  535. fbinfo->var.bits_per_pixel = display->bpp;
  536. nuc900fb_init_registers(fbinfo);
  537. nuc900fb_check_var(&fbinfo->var, fbinfo);
  538. ret = nuc900fb_cpufreq_register(fbi);
  539. if (ret < 0) {
  540. dev_err(&pdev->dev, "Failed to register cpufreq\n");
  541. goto free_video_memory;
  542. }
  543. ret = register_framebuffer(fbinfo);
  544. if (ret) {
  545. printk(KERN_ERR "failed to register framebuffer device: %d\n",
  546. ret);
  547. goto free_cpufreq;
  548. }
  549. printk(KERN_INFO "fb%d: %s frame buffer device\n",
  550. fbinfo->node, fbinfo->fix.id);
  551. return 0;
  552. free_cpufreq:
  553. nuc900fb_cpufreq_deregister(fbi);
  554. free_video_memory:
  555. nuc900fb_unmap_video_memory(fbinfo);
  556. release_clock:
  557. clk_disable(fbi->clk);
  558. clk_put(fbi->clk);
  559. release_irq:
  560. free_irq(irq, fbi);
  561. release_regs:
  562. iounmap(fbi->io);
  563. release_mem_region:
  564. release_mem_region(res->start, size);
  565. free_fb:
  566. framebuffer_release(fbinfo);
  567. return ret;
  568. }
  569. /*
  570. * shutdown the lcd controller
  571. */
  572. static void nuc900fb_stop_lcd(struct fb_info *info)
  573. {
  574. struct nuc900fb_info *fbi = info->par;
  575. void __iomem *regs = fbi->io;
  576. writel((~LCM_DCCS_DISP_INT_EN) | (~LCM_DCCS_VA_EN) | (~LCM_DCCS_OSD_EN),
  577. regs + REG_LCM_DCCS);
  578. }
  579. /*
  580. * Cleanup
  581. */
  582. static int nuc900fb_remove(struct platform_device *pdev)
  583. {
  584. struct fb_info *fbinfo = platform_get_drvdata(pdev);
  585. struct nuc900fb_info *fbi = fbinfo->par;
  586. int irq;
  587. nuc900fb_stop_lcd(fbinfo);
  588. msleep(1);
  589. unregister_framebuffer(fbinfo);
  590. nuc900fb_cpufreq_deregister(fbi);
  591. nuc900fb_unmap_video_memory(fbinfo);
  592. iounmap(fbi->io);
  593. irq = platform_get_irq(pdev, 0);
  594. free_irq(irq, fbi);
  595. release_resource(fbi->mem);
  596. kfree(fbi->mem);
  597. platform_set_drvdata(pdev, NULL);
  598. framebuffer_release(fbinfo);
  599. return 0;
  600. }
  601. #ifdef CONFIG_PM
  602. /*
  603. * suspend and resume support for the lcd controller
  604. */
  605. static int nuc900fb_suspend(struct platform_device *dev, pm_message_t state)
  606. {
  607. struct fb_info *fbinfo = platform_get_drvdata(dev);
  608. struct nuc900fb_info *info = fbinfo->par;
  609. nuc900fb_stop_lcd(fbinfo);
  610. msleep(1);
  611. clk_disable(info->clk);
  612. return 0;
  613. }
  614. static int nuc900fb_resume(struct platform_device *dev)
  615. {
  616. struct fb_info *fbinfo = platform_get_drvdata(dev);
  617. struct nuc900fb_info *fbi = fbinfo->par;
  618. printk(KERN_INFO "nuc900fb resume\n");
  619. clk_enable(fbi->clk);
  620. msleep(1);
  621. nuc900fb_init_registers(fbinfo);
  622. nuc900fb_activate_var(fbinfo);
  623. return 0;
  624. }
  625. #else
  626. #define nuc900fb_suspend NULL
  627. #define nuc900fb_resume NULL
  628. #endif
  629. static struct platform_driver nuc900fb_driver = {
  630. .probe = nuc900fb_probe,
  631. .remove = nuc900fb_remove,
  632. .suspend = nuc900fb_suspend,
  633. .resume = nuc900fb_resume,
  634. .driver = {
  635. .name = "nuc900-lcd",
  636. .owner = THIS_MODULE,
  637. },
  638. };
  639. int __devinit nuc900fb_init(void)
  640. {
  641. return platform_driver_register(&nuc900fb_driver);
  642. }
  643. static void __exit nuc900fb_cleanup(void)
  644. {
  645. platform_driver_unregister(&nuc900fb_driver);
  646. }
  647. module_init(nuc900fb_init);
  648. module_exit(nuc900fb_cleanup);
  649. MODULE_DESCRIPTION("Framebuffer driver for the NUC900");
  650. MODULE_LICENSE("GPL");