atmel_lcdfb.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171
  1. /*
  2. * Driver for AT91/AT32 LCD Controller
  3. *
  4. * Copyright (C) 2007 Atmel Corporation
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file COPYING in the main directory of this archive for
  8. * more details.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/dma-mapping.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/clk.h>
  15. #include <linux/fb.h>
  16. #include <linux/init.h>
  17. #include <linux/delay.h>
  18. #include <linux/backlight.h>
  19. #include <linux/gfp.h>
  20. #include <linux/module.h>
  21. #include <mach/board.h>
  22. #include <mach/cpu.h>
  23. #include <asm/gpio.h>
  24. #include <video/atmel_lcdc.h>
  25. #define lcdc_readl(sinfo, reg) __raw_readl((sinfo)->mmio+(reg))
  26. #define lcdc_writel(sinfo, reg, val) __raw_writel((val), (sinfo)->mmio+(reg))
  27. /* configurable parameters */
  28. #define ATMEL_LCDC_CVAL_DEFAULT 0xc8
  29. #define ATMEL_LCDC_DMA_BURST_LEN 8 /* words */
  30. #define ATMEL_LCDC_FIFO_SIZE 512 /* words */
  31. #if defined(CONFIG_ARCH_AT91)
  32. #define ATMEL_LCDFB_FBINFO_DEFAULT (FBINFO_DEFAULT \
  33. | FBINFO_PARTIAL_PAN_OK \
  34. | FBINFO_HWACCEL_YPAN)
  35. static inline void atmel_lcdfb_update_dma2d(struct atmel_lcdfb_info *sinfo,
  36. struct fb_var_screeninfo *var,
  37. struct fb_info *info)
  38. {
  39. }
  40. #elif defined(CONFIG_AVR32)
  41. #define ATMEL_LCDFB_FBINFO_DEFAULT (FBINFO_DEFAULT \
  42. | FBINFO_PARTIAL_PAN_OK \
  43. | FBINFO_HWACCEL_XPAN \
  44. | FBINFO_HWACCEL_YPAN)
  45. static void atmel_lcdfb_update_dma2d(struct atmel_lcdfb_info *sinfo,
  46. struct fb_var_screeninfo *var,
  47. struct fb_info *info)
  48. {
  49. u32 dma2dcfg;
  50. u32 pixeloff;
  51. pixeloff = (var->xoffset * info->var.bits_per_pixel) & 0x1f;
  52. dma2dcfg = (info->var.xres_virtual - info->var.xres)
  53. * info->var.bits_per_pixel / 8;
  54. dma2dcfg |= pixeloff << ATMEL_LCDC_PIXELOFF_OFFSET;
  55. lcdc_writel(sinfo, ATMEL_LCDC_DMA2DCFG, dma2dcfg);
  56. /* Update configuration */
  57. lcdc_writel(sinfo, ATMEL_LCDC_DMACON,
  58. lcdc_readl(sinfo, ATMEL_LCDC_DMACON)
  59. | ATMEL_LCDC_DMAUPDT);
  60. }
  61. #endif
  62. static u32 contrast_ctr = ATMEL_LCDC_PS_DIV8
  63. | ATMEL_LCDC_POL_POSITIVE
  64. | ATMEL_LCDC_ENA_PWMENABLE;
  65. #ifdef CONFIG_BACKLIGHT_ATMEL_LCDC
  66. /* some bl->props field just changed */
  67. static int atmel_bl_update_status(struct backlight_device *bl)
  68. {
  69. struct atmel_lcdfb_info *sinfo = bl_get_data(bl);
  70. int power = sinfo->bl_power;
  71. int brightness = bl->props.brightness;
  72. /* REVISIT there may be a meaningful difference between
  73. * fb_blank and power ... there seem to be some cases
  74. * this doesn't handle correctly.
  75. */
  76. if (bl->props.fb_blank != sinfo->bl_power)
  77. power = bl->props.fb_blank;
  78. else if (bl->props.power != sinfo->bl_power)
  79. power = bl->props.power;
  80. if (brightness < 0 && power == FB_BLANK_UNBLANK)
  81. brightness = lcdc_readl(sinfo, ATMEL_LCDC_CONTRAST_VAL);
  82. else if (power != FB_BLANK_UNBLANK)
  83. brightness = 0;
  84. lcdc_writel(sinfo, ATMEL_LCDC_CONTRAST_VAL, brightness);
  85. if (contrast_ctr & ATMEL_LCDC_POL_POSITIVE)
  86. lcdc_writel(sinfo, ATMEL_LCDC_CONTRAST_CTR,
  87. brightness ? contrast_ctr : 0);
  88. else
  89. lcdc_writel(sinfo, ATMEL_LCDC_CONTRAST_CTR, contrast_ctr);
  90. bl->props.fb_blank = bl->props.power = sinfo->bl_power = power;
  91. return 0;
  92. }
  93. static int atmel_bl_get_brightness(struct backlight_device *bl)
  94. {
  95. struct atmel_lcdfb_info *sinfo = bl_get_data(bl);
  96. return lcdc_readl(sinfo, ATMEL_LCDC_CONTRAST_VAL);
  97. }
  98. static const struct backlight_ops atmel_lcdc_bl_ops = {
  99. .update_status = atmel_bl_update_status,
  100. .get_brightness = atmel_bl_get_brightness,
  101. };
  102. static void init_backlight(struct atmel_lcdfb_info *sinfo)
  103. {
  104. struct backlight_properties props;
  105. struct backlight_device *bl;
  106. sinfo->bl_power = FB_BLANK_UNBLANK;
  107. if (sinfo->backlight)
  108. return;
  109. memset(&props, 0, sizeof(struct backlight_properties));
  110. props.type = BACKLIGHT_RAW;
  111. props.max_brightness = 0xff;
  112. bl = backlight_device_register("backlight", &sinfo->pdev->dev, sinfo,
  113. &atmel_lcdc_bl_ops, &props);
  114. if (IS_ERR(bl)) {
  115. dev_err(&sinfo->pdev->dev, "error %ld on backlight register\n",
  116. PTR_ERR(bl));
  117. return;
  118. }
  119. sinfo->backlight = bl;
  120. bl->props.power = FB_BLANK_UNBLANK;
  121. bl->props.fb_blank = FB_BLANK_UNBLANK;
  122. bl->props.brightness = atmel_bl_get_brightness(bl);
  123. }
  124. static void exit_backlight(struct atmel_lcdfb_info *sinfo)
  125. {
  126. if (sinfo->backlight)
  127. backlight_device_unregister(sinfo->backlight);
  128. }
  129. #else
  130. static void init_backlight(struct atmel_lcdfb_info *sinfo)
  131. {
  132. dev_warn(&sinfo->pdev->dev, "backlight control is not available\n");
  133. }
  134. static void exit_backlight(struct atmel_lcdfb_info *sinfo)
  135. {
  136. }
  137. #endif
  138. static void init_contrast(struct atmel_lcdfb_info *sinfo)
  139. {
  140. /* contrast pwm can be 'inverted' */
  141. if (sinfo->lcdcon_pol_negative)
  142. contrast_ctr &= ~(ATMEL_LCDC_POL_POSITIVE);
  143. /* have some default contrast/backlight settings */
  144. lcdc_writel(sinfo, ATMEL_LCDC_CONTRAST_CTR, contrast_ctr);
  145. lcdc_writel(sinfo, ATMEL_LCDC_CONTRAST_VAL, ATMEL_LCDC_CVAL_DEFAULT);
  146. if (sinfo->lcdcon_is_backlight)
  147. init_backlight(sinfo);
  148. }
  149. static struct fb_fix_screeninfo atmel_lcdfb_fix __initdata = {
  150. .type = FB_TYPE_PACKED_PIXELS,
  151. .visual = FB_VISUAL_TRUECOLOR,
  152. .xpanstep = 0,
  153. .ypanstep = 1,
  154. .ywrapstep = 0,
  155. .accel = FB_ACCEL_NONE,
  156. };
  157. static unsigned long compute_hozval(unsigned long xres, unsigned long lcdcon2)
  158. {
  159. unsigned long value;
  160. if (!(cpu_is_at91sam9261() || cpu_is_at91sam9g10()
  161. || cpu_is_at32ap7000()))
  162. return xres;
  163. value = xres;
  164. if ((lcdcon2 & ATMEL_LCDC_DISTYPE) != ATMEL_LCDC_DISTYPE_TFT) {
  165. /* STN display */
  166. if ((lcdcon2 & ATMEL_LCDC_DISTYPE) == ATMEL_LCDC_DISTYPE_STNCOLOR) {
  167. value *= 3;
  168. }
  169. if ( (lcdcon2 & ATMEL_LCDC_IFWIDTH) == ATMEL_LCDC_IFWIDTH_4
  170. || ( (lcdcon2 & ATMEL_LCDC_IFWIDTH) == ATMEL_LCDC_IFWIDTH_8
  171. && (lcdcon2 & ATMEL_LCDC_SCANMOD) == ATMEL_LCDC_SCANMOD_DUAL ))
  172. value = DIV_ROUND_UP(value, 4);
  173. else
  174. value = DIV_ROUND_UP(value, 8);
  175. }
  176. return value;
  177. }
  178. static void atmel_lcdfb_stop_nowait(struct atmel_lcdfb_info *sinfo)
  179. {
  180. /* Turn off the LCD controller and the DMA controller */
  181. lcdc_writel(sinfo, ATMEL_LCDC_PWRCON,
  182. sinfo->guard_time << ATMEL_LCDC_GUARDT_OFFSET);
  183. /* Wait for the LCDC core to become idle */
  184. while (lcdc_readl(sinfo, ATMEL_LCDC_PWRCON) & ATMEL_LCDC_BUSY)
  185. msleep(10);
  186. lcdc_writel(sinfo, ATMEL_LCDC_DMACON, 0);
  187. }
  188. static void atmel_lcdfb_stop(struct atmel_lcdfb_info *sinfo)
  189. {
  190. atmel_lcdfb_stop_nowait(sinfo);
  191. /* Wait for DMA engine to become idle... */
  192. while (lcdc_readl(sinfo, ATMEL_LCDC_DMACON) & ATMEL_LCDC_DMABUSY)
  193. msleep(10);
  194. }
  195. static void atmel_lcdfb_start(struct atmel_lcdfb_info *sinfo)
  196. {
  197. lcdc_writel(sinfo, ATMEL_LCDC_DMACON, sinfo->default_dmacon);
  198. lcdc_writel(sinfo, ATMEL_LCDC_PWRCON,
  199. (sinfo->guard_time << ATMEL_LCDC_GUARDT_OFFSET)
  200. | ATMEL_LCDC_PWR);
  201. }
  202. static void atmel_lcdfb_update_dma(struct fb_info *info,
  203. struct fb_var_screeninfo *var)
  204. {
  205. struct atmel_lcdfb_info *sinfo = info->par;
  206. struct fb_fix_screeninfo *fix = &info->fix;
  207. unsigned long dma_addr;
  208. dma_addr = (fix->smem_start + var->yoffset * fix->line_length
  209. + var->xoffset * info->var.bits_per_pixel / 8);
  210. dma_addr &= ~3UL;
  211. /* Set framebuffer DMA base address and pixel offset */
  212. lcdc_writel(sinfo, ATMEL_LCDC_DMABADDR1, dma_addr);
  213. atmel_lcdfb_update_dma2d(sinfo, var, info);
  214. }
  215. static inline void atmel_lcdfb_free_video_memory(struct atmel_lcdfb_info *sinfo)
  216. {
  217. struct fb_info *info = sinfo->info;
  218. dma_free_writecombine(info->device, info->fix.smem_len,
  219. info->screen_base, info->fix.smem_start);
  220. }
  221. /**
  222. * atmel_lcdfb_alloc_video_memory - Allocate framebuffer memory
  223. * @sinfo: the frame buffer to allocate memory for
  224. *
  225. * This function is called only from the atmel_lcdfb_probe()
  226. * so no locking by fb_info->mm_lock around smem_len setting is needed.
  227. */
  228. static int atmel_lcdfb_alloc_video_memory(struct atmel_lcdfb_info *sinfo)
  229. {
  230. struct fb_info *info = sinfo->info;
  231. struct fb_var_screeninfo *var = &info->var;
  232. unsigned int smem_len;
  233. smem_len = (var->xres_virtual * var->yres_virtual
  234. * ((var->bits_per_pixel + 7) / 8));
  235. info->fix.smem_len = max(smem_len, sinfo->smem_len);
  236. info->screen_base = dma_alloc_writecombine(info->device, info->fix.smem_len,
  237. (dma_addr_t *)&info->fix.smem_start, GFP_KERNEL);
  238. if (!info->screen_base) {
  239. return -ENOMEM;
  240. }
  241. memset(info->screen_base, 0, info->fix.smem_len);
  242. return 0;
  243. }
  244. static const struct fb_videomode *atmel_lcdfb_choose_mode(struct fb_var_screeninfo *var,
  245. struct fb_info *info)
  246. {
  247. struct fb_videomode varfbmode;
  248. const struct fb_videomode *fbmode = NULL;
  249. fb_var_to_videomode(&varfbmode, var);
  250. fbmode = fb_find_nearest_mode(&varfbmode, &info->modelist);
  251. if (fbmode)
  252. fb_videomode_to_var(var, fbmode);
  253. return fbmode;
  254. }
  255. /**
  256. * atmel_lcdfb_check_var - Validates a var passed in.
  257. * @var: frame buffer variable screen structure
  258. * @info: frame buffer structure that represents a single frame buffer
  259. *
  260. * Checks to see if the hardware supports the state requested by
  261. * var passed in. This function does not alter the hardware
  262. * state!!! This means the data stored in struct fb_info and
  263. * struct atmel_lcdfb_info do not change. This includes the var
  264. * inside of struct fb_info. Do NOT change these. This function
  265. * can be called on its own if we intent to only test a mode and
  266. * not actually set it. The stuff in modedb.c is a example of
  267. * this. If the var passed in is slightly off by what the
  268. * hardware can support then we alter the var PASSED in to what
  269. * we can do. If the hardware doesn't support mode change a
  270. * -EINVAL will be returned by the upper layers. You don't need
  271. * to implement this function then. If you hardware doesn't
  272. * support changing the resolution then this function is not
  273. * needed. In this case the driver would just provide a var that
  274. * represents the static state the screen is in.
  275. *
  276. * Returns negative errno on error, or zero on success.
  277. */
  278. static int atmel_lcdfb_check_var(struct fb_var_screeninfo *var,
  279. struct fb_info *info)
  280. {
  281. struct device *dev = info->device;
  282. struct atmel_lcdfb_info *sinfo = info->par;
  283. unsigned long clk_value_khz;
  284. clk_value_khz = clk_get_rate(sinfo->lcdc_clk) / 1000;
  285. dev_dbg(dev, "%s:\n", __func__);
  286. if (!(var->pixclock && var->bits_per_pixel)) {
  287. /* choose a suitable mode if possible */
  288. if (!atmel_lcdfb_choose_mode(var, info)) {
  289. dev_err(dev, "needed value not specified\n");
  290. return -EINVAL;
  291. }
  292. }
  293. dev_dbg(dev, " resolution: %ux%u\n", var->xres, var->yres);
  294. dev_dbg(dev, " pixclk: %lu KHz\n", PICOS2KHZ(var->pixclock));
  295. dev_dbg(dev, " bpp: %u\n", var->bits_per_pixel);
  296. dev_dbg(dev, " clk: %lu KHz\n", clk_value_khz);
  297. if (PICOS2KHZ(var->pixclock) > clk_value_khz) {
  298. dev_err(dev, "%lu KHz pixel clock is too fast\n", PICOS2KHZ(var->pixclock));
  299. return -EINVAL;
  300. }
  301. /* Do not allow to have real resoulution larger than virtual */
  302. if (var->xres > var->xres_virtual)
  303. var->xres_virtual = var->xres;
  304. if (var->yres > var->yres_virtual)
  305. var->yres_virtual = var->yres;
  306. /* Force same alignment for each line */
  307. var->xres = (var->xres + 3) & ~3UL;
  308. var->xres_virtual = (var->xres_virtual + 3) & ~3UL;
  309. var->red.msb_right = var->green.msb_right = var->blue.msb_right = 0;
  310. var->transp.msb_right = 0;
  311. var->transp.offset = var->transp.length = 0;
  312. var->xoffset = var->yoffset = 0;
  313. if (info->fix.smem_len) {
  314. unsigned int smem_len = (var->xres_virtual * var->yres_virtual
  315. * ((var->bits_per_pixel + 7) / 8));
  316. if (smem_len > info->fix.smem_len)
  317. return -EINVAL;
  318. }
  319. /* Saturate vertical and horizontal timings at maximum values */
  320. var->vsync_len = min_t(u32, var->vsync_len,
  321. (ATMEL_LCDC_VPW >> ATMEL_LCDC_VPW_OFFSET) + 1);
  322. var->upper_margin = min_t(u32, var->upper_margin,
  323. ATMEL_LCDC_VBP >> ATMEL_LCDC_VBP_OFFSET);
  324. var->lower_margin = min_t(u32, var->lower_margin,
  325. ATMEL_LCDC_VFP);
  326. var->right_margin = min_t(u32, var->right_margin,
  327. (ATMEL_LCDC_HFP >> ATMEL_LCDC_HFP_OFFSET) + 1);
  328. var->hsync_len = min_t(u32, var->hsync_len,
  329. (ATMEL_LCDC_HPW >> ATMEL_LCDC_HPW_OFFSET) + 1);
  330. var->left_margin = min_t(u32, var->left_margin,
  331. ATMEL_LCDC_HBP + 1);
  332. /* Some parameters can't be zero */
  333. var->vsync_len = max_t(u32, var->vsync_len, 1);
  334. var->right_margin = max_t(u32, var->right_margin, 1);
  335. var->hsync_len = max_t(u32, var->hsync_len, 1);
  336. var->left_margin = max_t(u32, var->left_margin, 1);
  337. switch (var->bits_per_pixel) {
  338. case 1:
  339. case 2:
  340. case 4:
  341. case 8:
  342. var->red.offset = var->green.offset = var->blue.offset = 0;
  343. var->red.length = var->green.length = var->blue.length
  344. = var->bits_per_pixel;
  345. break;
  346. case 15:
  347. case 16:
  348. if (sinfo->lcd_wiring_mode == ATMEL_LCDC_WIRING_RGB) {
  349. /* RGB:565 mode */
  350. var->red.offset = 11;
  351. var->blue.offset = 0;
  352. var->green.length = 6;
  353. } else if (sinfo->lcd_wiring_mode == ATMEL_LCDC_WIRING_RGB555) {
  354. var->red.offset = 10;
  355. var->blue.offset = 0;
  356. var->green.length = 5;
  357. } else {
  358. /* BGR:555 mode */
  359. var->red.offset = 0;
  360. var->blue.offset = 10;
  361. var->green.length = 5;
  362. }
  363. var->green.offset = 5;
  364. var->red.length = var->blue.length = 5;
  365. break;
  366. case 32:
  367. var->transp.offset = 24;
  368. var->transp.length = 8;
  369. /* fall through */
  370. case 24:
  371. if (sinfo->lcd_wiring_mode == ATMEL_LCDC_WIRING_RGB) {
  372. /* RGB:888 mode */
  373. var->red.offset = 16;
  374. var->blue.offset = 0;
  375. } else {
  376. /* BGR:888 mode */
  377. var->red.offset = 0;
  378. var->blue.offset = 16;
  379. }
  380. var->green.offset = 8;
  381. var->red.length = var->green.length = var->blue.length = 8;
  382. break;
  383. default:
  384. dev_err(dev, "color depth %d not supported\n",
  385. var->bits_per_pixel);
  386. return -EINVAL;
  387. }
  388. return 0;
  389. }
  390. /*
  391. * LCD reset sequence
  392. */
  393. static void atmel_lcdfb_reset(struct atmel_lcdfb_info *sinfo)
  394. {
  395. might_sleep();
  396. atmel_lcdfb_stop(sinfo);
  397. atmel_lcdfb_start(sinfo);
  398. }
  399. /**
  400. * atmel_lcdfb_set_par - Alters the hardware state.
  401. * @info: frame buffer structure that represents a single frame buffer
  402. *
  403. * Using the fb_var_screeninfo in fb_info we set the resolution
  404. * of the this particular framebuffer. This function alters the
  405. * par AND the fb_fix_screeninfo stored in fb_info. It doesn't
  406. * not alter var in fb_info since we are using that data. This
  407. * means we depend on the data in var inside fb_info to be
  408. * supported by the hardware. atmel_lcdfb_check_var is always called
  409. * before atmel_lcdfb_set_par to ensure this. Again if you can't
  410. * change the resolution you don't need this function.
  411. *
  412. */
  413. static int atmel_lcdfb_set_par(struct fb_info *info)
  414. {
  415. struct atmel_lcdfb_info *sinfo = info->par;
  416. unsigned long hozval_linesz;
  417. unsigned long value;
  418. unsigned long clk_value_khz;
  419. unsigned long bits_per_line;
  420. unsigned long pix_factor = 2;
  421. might_sleep();
  422. dev_dbg(info->device, "%s:\n", __func__);
  423. dev_dbg(info->device, " * resolution: %ux%u (%ux%u virtual)\n",
  424. info->var.xres, info->var.yres,
  425. info->var.xres_virtual, info->var.yres_virtual);
  426. atmel_lcdfb_stop_nowait(sinfo);
  427. if (info->var.bits_per_pixel == 1)
  428. info->fix.visual = FB_VISUAL_MONO01;
  429. else if (info->var.bits_per_pixel <= 8)
  430. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  431. else
  432. info->fix.visual = FB_VISUAL_TRUECOLOR;
  433. bits_per_line = info->var.xres_virtual * info->var.bits_per_pixel;
  434. info->fix.line_length = DIV_ROUND_UP(bits_per_line, 8);
  435. /* Re-initialize the DMA engine... */
  436. dev_dbg(info->device, " * update DMA engine\n");
  437. atmel_lcdfb_update_dma(info, &info->var);
  438. /* ...set frame size and burst length = 8 words (?) */
  439. value = (info->var.yres * info->var.xres * info->var.bits_per_pixel) / 32;
  440. value |= ((ATMEL_LCDC_DMA_BURST_LEN - 1) << ATMEL_LCDC_BLENGTH_OFFSET);
  441. lcdc_writel(sinfo, ATMEL_LCDC_DMAFRMCFG, value);
  442. /* Now, the LCDC core... */
  443. /* Set pixel clock */
  444. if (cpu_is_at91sam9g45() && !cpu_is_at91sam9g45es())
  445. pix_factor = 1;
  446. clk_value_khz = clk_get_rate(sinfo->lcdc_clk) / 1000;
  447. value = DIV_ROUND_UP(clk_value_khz, PICOS2KHZ(info->var.pixclock));
  448. if (value < pix_factor) {
  449. dev_notice(info->device, "Bypassing pixel clock divider\n");
  450. lcdc_writel(sinfo, ATMEL_LCDC_LCDCON1, ATMEL_LCDC_BYPASS);
  451. } else {
  452. value = (value / pix_factor) - 1;
  453. dev_dbg(info->device, " * programming CLKVAL = 0x%08lx\n",
  454. value);
  455. lcdc_writel(sinfo, ATMEL_LCDC_LCDCON1,
  456. value << ATMEL_LCDC_CLKVAL_OFFSET);
  457. info->var.pixclock =
  458. KHZ2PICOS(clk_value_khz / (pix_factor * (value + 1)));
  459. dev_dbg(info->device, " updated pixclk: %lu KHz\n",
  460. PICOS2KHZ(info->var.pixclock));
  461. }
  462. /* Initialize control register 2 */
  463. value = sinfo->default_lcdcon2;
  464. if (!(info->var.sync & FB_SYNC_HOR_HIGH_ACT))
  465. value |= ATMEL_LCDC_INVLINE_INVERTED;
  466. if (!(info->var.sync & FB_SYNC_VERT_HIGH_ACT))
  467. value |= ATMEL_LCDC_INVFRAME_INVERTED;
  468. switch (info->var.bits_per_pixel) {
  469. case 1: value |= ATMEL_LCDC_PIXELSIZE_1; break;
  470. case 2: value |= ATMEL_LCDC_PIXELSIZE_2; break;
  471. case 4: value |= ATMEL_LCDC_PIXELSIZE_4; break;
  472. case 8: value |= ATMEL_LCDC_PIXELSIZE_8; break;
  473. case 15: /* fall through */
  474. case 16: value |= ATMEL_LCDC_PIXELSIZE_16; break;
  475. case 24: value |= ATMEL_LCDC_PIXELSIZE_24; break;
  476. case 32: value |= ATMEL_LCDC_PIXELSIZE_32; break;
  477. default: BUG(); break;
  478. }
  479. dev_dbg(info->device, " * LCDCON2 = %08lx\n", value);
  480. lcdc_writel(sinfo, ATMEL_LCDC_LCDCON2, value);
  481. /* Vertical timing */
  482. value = (info->var.vsync_len - 1) << ATMEL_LCDC_VPW_OFFSET;
  483. value |= info->var.upper_margin << ATMEL_LCDC_VBP_OFFSET;
  484. value |= info->var.lower_margin;
  485. dev_dbg(info->device, " * LCDTIM1 = %08lx\n", value);
  486. lcdc_writel(sinfo, ATMEL_LCDC_TIM1, value);
  487. /* Horizontal timing */
  488. value = (info->var.right_margin - 1) << ATMEL_LCDC_HFP_OFFSET;
  489. value |= (info->var.hsync_len - 1) << ATMEL_LCDC_HPW_OFFSET;
  490. value |= (info->var.left_margin - 1);
  491. dev_dbg(info->device, " * LCDTIM2 = %08lx\n", value);
  492. lcdc_writel(sinfo, ATMEL_LCDC_TIM2, value);
  493. /* Horizontal value (aka line size) */
  494. hozval_linesz = compute_hozval(info->var.xres,
  495. lcdc_readl(sinfo, ATMEL_LCDC_LCDCON2));
  496. /* Display size */
  497. value = (hozval_linesz - 1) << ATMEL_LCDC_HOZVAL_OFFSET;
  498. value |= info->var.yres - 1;
  499. dev_dbg(info->device, " * LCDFRMCFG = %08lx\n", value);
  500. lcdc_writel(sinfo, ATMEL_LCDC_LCDFRMCFG, value);
  501. /* FIFO Threshold: Use formula from data sheet */
  502. value = ATMEL_LCDC_FIFO_SIZE - (2 * ATMEL_LCDC_DMA_BURST_LEN + 3);
  503. lcdc_writel(sinfo, ATMEL_LCDC_FIFO, value);
  504. /* Toggle LCD_MODE every frame */
  505. lcdc_writel(sinfo, ATMEL_LCDC_MVAL, 0);
  506. /* Disable all interrupts */
  507. lcdc_writel(sinfo, ATMEL_LCDC_IDR, ~0UL);
  508. /* Enable FIFO & DMA errors */
  509. lcdc_writel(sinfo, ATMEL_LCDC_IER, ATMEL_LCDC_UFLWI | ATMEL_LCDC_OWRI | ATMEL_LCDC_MERI);
  510. /* ...wait for DMA engine to become idle... */
  511. while (lcdc_readl(sinfo, ATMEL_LCDC_DMACON) & ATMEL_LCDC_DMABUSY)
  512. msleep(10);
  513. atmel_lcdfb_start(sinfo);
  514. dev_dbg(info->device, " * DONE\n");
  515. return 0;
  516. }
  517. static inline unsigned int chan_to_field(unsigned int chan, const struct fb_bitfield *bf)
  518. {
  519. chan &= 0xffff;
  520. chan >>= 16 - bf->length;
  521. return chan << bf->offset;
  522. }
  523. /**
  524. * atmel_lcdfb_setcolreg - Optional function. Sets a color register.
  525. * @regno: Which register in the CLUT we are programming
  526. * @red: The red value which can be up to 16 bits wide
  527. * @green: The green value which can be up to 16 bits wide
  528. * @blue: The blue value which can be up to 16 bits wide.
  529. * @transp: If supported the alpha value which can be up to 16 bits wide.
  530. * @info: frame buffer info structure
  531. *
  532. * Set a single color register. The values supplied have a 16 bit
  533. * magnitude which needs to be scaled in this function for the hardware.
  534. * Things to take into consideration are how many color registers, if
  535. * any, are supported with the current color visual. With truecolor mode
  536. * no color palettes are supported. Here a pseudo palette is created
  537. * which we store the value in pseudo_palette in struct fb_info. For
  538. * pseudocolor mode we have a limited color palette. To deal with this
  539. * we can program what color is displayed for a particular pixel value.
  540. * DirectColor is similar in that we can program each color field. If
  541. * we have a static colormap we don't need to implement this function.
  542. *
  543. * Returns negative errno on error, or zero on success. In an
  544. * ideal world, this would have been the case, but as it turns
  545. * out, the other drivers return 1 on failure, so that's what
  546. * we're going to do.
  547. */
  548. static int atmel_lcdfb_setcolreg(unsigned int regno, unsigned int red,
  549. unsigned int green, unsigned int blue,
  550. unsigned int transp, struct fb_info *info)
  551. {
  552. struct atmel_lcdfb_info *sinfo = info->par;
  553. unsigned int val;
  554. u32 *pal;
  555. int ret = 1;
  556. if (info->var.grayscale)
  557. red = green = blue = (19595 * red + 38470 * green
  558. + 7471 * blue) >> 16;
  559. switch (info->fix.visual) {
  560. case FB_VISUAL_TRUECOLOR:
  561. if (regno < 16) {
  562. pal = info->pseudo_palette;
  563. val = chan_to_field(red, &info->var.red);
  564. val |= chan_to_field(green, &info->var.green);
  565. val |= chan_to_field(blue, &info->var.blue);
  566. pal[regno] = val;
  567. ret = 0;
  568. }
  569. break;
  570. case FB_VISUAL_PSEUDOCOLOR:
  571. if (regno < 256) {
  572. if (cpu_is_at91sam9261() || cpu_is_at91sam9263()
  573. || cpu_is_at91sam9rl()) {
  574. /* old style I+BGR:555 */
  575. val = ((red >> 11) & 0x001f);
  576. val |= ((green >> 6) & 0x03e0);
  577. val |= ((blue >> 1) & 0x7c00);
  578. /*
  579. * TODO: intensity bit. Maybe something like
  580. * ~(red[10] ^ green[10] ^ blue[10]) & 1
  581. */
  582. } else {
  583. /* new style BGR:565 / RGB:565 */
  584. if (sinfo->lcd_wiring_mode ==
  585. ATMEL_LCDC_WIRING_RGB) {
  586. val = ((blue >> 11) & 0x001f);
  587. val |= ((red >> 0) & 0xf800);
  588. } else {
  589. val = ((red >> 11) & 0x001f);
  590. val |= ((blue >> 0) & 0xf800);
  591. }
  592. val |= ((green >> 5) & 0x07e0);
  593. }
  594. lcdc_writel(sinfo, ATMEL_LCDC_LUT(regno), val);
  595. ret = 0;
  596. }
  597. break;
  598. case FB_VISUAL_MONO01:
  599. if (regno < 2) {
  600. val = (regno == 0) ? 0x00 : 0x1F;
  601. lcdc_writel(sinfo, ATMEL_LCDC_LUT(regno), val);
  602. ret = 0;
  603. }
  604. break;
  605. }
  606. return ret;
  607. }
  608. static int atmel_lcdfb_pan_display(struct fb_var_screeninfo *var,
  609. struct fb_info *info)
  610. {
  611. dev_dbg(info->device, "%s\n", __func__);
  612. atmel_lcdfb_update_dma(info, var);
  613. return 0;
  614. }
  615. static int atmel_lcdfb_blank(int blank_mode, struct fb_info *info)
  616. {
  617. struct atmel_lcdfb_info *sinfo = info->par;
  618. switch (blank_mode) {
  619. case FB_BLANK_UNBLANK:
  620. case FB_BLANK_NORMAL:
  621. atmel_lcdfb_start(sinfo);
  622. break;
  623. case FB_BLANK_VSYNC_SUSPEND:
  624. case FB_BLANK_HSYNC_SUSPEND:
  625. break;
  626. case FB_BLANK_POWERDOWN:
  627. atmel_lcdfb_stop(sinfo);
  628. break;
  629. default:
  630. return -EINVAL;
  631. }
  632. /* let fbcon do a soft blank for us */
  633. return ((blank_mode == FB_BLANK_NORMAL) ? 1 : 0);
  634. }
  635. static struct fb_ops atmel_lcdfb_ops = {
  636. .owner = THIS_MODULE,
  637. .fb_check_var = atmel_lcdfb_check_var,
  638. .fb_set_par = atmel_lcdfb_set_par,
  639. .fb_setcolreg = atmel_lcdfb_setcolreg,
  640. .fb_blank = atmel_lcdfb_blank,
  641. .fb_pan_display = atmel_lcdfb_pan_display,
  642. .fb_fillrect = cfb_fillrect,
  643. .fb_copyarea = cfb_copyarea,
  644. .fb_imageblit = cfb_imageblit,
  645. };
  646. static irqreturn_t atmel_lcdfb_interrupt(int irq, void *dev_id)
  647. {
  648. struct fb_info *info = dev_id;
  649. struct atmel_lcdfb_info *sinfo = info->par;
  650. u32 status;
  651. status = lcdc_readl(sinfo, ATMEL_LCDC_ISR);
  652. if (status & ATMEL_LCDC_UFLWI) {
  653. dev_warn(info->device, "FIFO underflow %#x\n", status);
  654. /* reset DMA and FIFO to avoid screen shifting */
  655. schedule_work(&sinfo->task);
  656. }
  657. lcdc_writel(sinfo, ATMEL_LCDC_ICR, status);
  658. return IRQ_HANDLED;
  659. }
  660. /*
  661. * LCD controller task (to reset the LCD)
  662. */
  663. static void atmel_lcdfb_task(struct work_struct *work)
  664. {
  665. struct atmel_lcdfb_info *sinfo =
  666. container_of(work, struct atmel_lcdfb_info, task);
  667. atmel_lcdfb_reset(sinfo);
  668. }
  669. static int __init atmel_lcdfb_init_fbinfo(struct atmel_lcdfb_info *sinfo)
  670. {
  671. struct fb_info *info = sinfo->info;
  672. int ret = 0;
  673. info->var.activate |= FB_ACTIVATE_FORCE | FB_ACTIVATE_NOW;
  674. dev_info(info->device,
  675. "%luKiB frame buffer at %08lx (mapped at %p)\n",
  676. (unsigned long)info->fix.smem_len / 1024,
  677. (unsigned long)info->fix.smem_start,
  678. info->screen_base);
  679. /* Allocate colormap */
  680. ret = fb_alloc_cmap(&info->cmap, 256, 0);
  681. if (ret < 0)
  682. dev_err(info->device, "Alloc color map failed\n");
  683. return ret;
  684. }
  685. static void atmel_lcdfb_start_clock(struct atmel_lcdfb_info *sinfo)
  686. {
  687. if (sinfo->bus_clk)
  688. clk_enable(sinfo->bus_clk);
  689. clk_enable(sinfo->lcdc_clk);
  690. }
  691. static void atmel_lcdfb_stop_clock(struct atmel_lcdfb_info *sinfo)
  692. {
  693. if (sinfo->bus_clk)
  694. clk_disable(sinfo->bus_clk);
  695. clk_disable(sinfo->lcdc_clk);
  696. }
  697. static int __init atmel_lcdfb_probe(struct platform_device *pdev)
  698. {
  699. struct device *dev = &pdev->dev;
  700. struct fb_info *info;
  701. struct atmel_lcdfb_info *sinfo;
  702. struct atmel_lcdfb_info *pdata_sinfo;
  703. struct fb_videomode fbmode;
  704. struct resource *regs = NULL;
  705. struct resource *map = NULL;
  706. int ret;
  707. dev_dbg(dev, "%s BEGIN\n", __func__);
  708. ret = -ENOMEM;
  709. info = framebuffer_alloc(sizeof(struct atmel_lcdfb_info), dev);
  710. if (!info) {
  711. dev_err(dev, "cannot allocate memory\n");
  712. goto out;
  713. }
  714. sinfo = info->par;
  715. if (dev->platform_data) {
  716. pdata_sinfo = (struct atmel_lcdfb_info *)dev->platform_data;
  717. sinfo->default_bpp = pdata_sinfo->default_bpp;
  718. sinfo->default_dmacon = pdata_sinfo->default_dmacon;
  719. sinfo->default_lcdcon2 = pdata_sinfo->default_lcdcon2;
  720. sinfo->default_monspecs = pdata_sinfo->default_monspecs;
  721. sinfo->atmel_lcdfb_power_control = pdata_sinfo->atmel_lcdfb_power_control;
  722. sinfo->guard_time = pdata_sinfo->guard_time;
  723. sinfo->smem_len = pdata_sinfo->smem_len;
  724. sinfo->lcdcon_is_backlight = pdata_sinfo->lcdcon_is_backlight;
  725. sinfo->lcdcon_pol_negative = pdata_sinfo->lcdcon_pol_negative;
  726. sinfo->lcd_wiring_mode = pdata_sinfo->lcd_wiring_mode;
  727. } else {
  728. dev_err(dev, "cannot get default configuration\n");
  729. goto free_info;
  730. }
  731. sinfo->info = info;
  732. sinfo->pdev = pdev;
  733. strcpy(info->fix.id, sinfo->pdev->name);
  734. info->flags = ATMEL_LCDFB_FBINFO_DEFAULT;
  735. info->pseudo_palette = sinfo->pseudo_palette;
  736. info->fbops = &atmel_lcdfb_ops;
  737. memcpy(&info->monspecs, sinfo->default_monspecs, sizeof(info->monspecs));
  738. info->fix = atmel_lcdfb_fix;
  739. /* Enable LCDC Clocks */
  740. if (cpu_is_at91sam9261() || cpu_is_at91sam9g10()
  741. || cpu_is_at32ap7000()) {
  742. sinfo->bus_clk = clk_get(dev, "hck1");
  743. if (IS_ERR(sinfo->bus_clk)) {
  744. ret = PTR_ERR(sinfo->bus_clk);
  745. goto free_info;
  746. }
  747. }
  748. sinfo->lcdc_clk = clk_get(dev, "lcdc_clk");
  749. if (IS_ERR(sinfo->lcdc_clk)) {
  750. ret = PTR_ERR(sinfo->lcdc_clk);
  751. goto put_bus_clk;
  752. }
  753. atmel_lcdfb_start_clock(sinfo);
  754. ret = fb_find_mode(&info->var, info, NULL, info->monspecs.modedb,
  755. info->monspecs.modedb_len, info->monspecs.modedb,
  756. sinfo->default_bpp);
  757. if (!ret) {
  758. dev_err(dev, "no suitable video mode found\n");
  759. goto stop_clk;
  760. }
  761. regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  762. if (!regs) {
  763. dev_err(dev, "resources unusable\n");
  764. ret = -ENXIO;
  765. goto stop_clk;
  766. }
  767. sinfo->irq_base = platform_get_irq(pdev, 0);
  768. if (sinfo->irq_base < 0) {
  769. dev_err(dev, "unable to get irq\n");
  770. ret = sinfo->irq_base;
  771. goto stop_clk;
  772. }
  773. /* Initialize video memory */
  774. map = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  775. if (map) {
  776. /* use a pre-allocated memory buffer */
  777. info->fix.smem_start = map->start;
  778. info->fix.smem_len = resource_size(map);
  779. if (!request_mem_region(info->fix.smem_start,
  780. info->fix.smem_len, pdev->name)) {
  781. ret = -EBUSY;
  782. goto stop_clk;
  783. }
  784. info->screen_base = ioremap(info->fix.smem_start, info->fix.smem_len);
  785. if (!info->screen_base)
  786. goto release_intmem;
  787. /*
  788. * Don't clear the framebuffer -- someone may have set
  789. * up a splash image.
  790. */
  791. } else {
  792. /* alocate memory buffer */
  793. ret = atmel_lcdfb_alloc_video_memory(sinfo);
  794. if (ret < 0) {
  795. dev_err(dev, "cannot allocate framebuffer: %d\n", ret);
  796. goto stop_clk;
  797. }
  798. }
  799. /* LCDC registers */
  800. info->fix.mmio_start = regs->start;
  801. info->fix.mmio_len = resource_size(regs);
  802. if (!request_mem_region(info->fix.mmio_start,
  803. info->fix.mmio_len, pdev->name)) {
  804. ret = -EBUSY;
  805. goto free_fb;
  806. }
  807. sinfo->mmio = ioremap(info->fix.mmio_start, info->fix.mmio_len);
  808. if (!sinfo->mmio) {
  809. dev_err(dev, "cannot map LCDC registers\n");
  810. goto release_mem;
  811. }
  812. /* Initialize PWM for contrast or backlight ("off") */
  813. init_contrast(sinfo);
  814. /* interrupt */
  815. ret = request_irq(sinfo->irq_base, atmel_lcdfb_interrupt, 0, pdev->name, info);
  816. if (ret) {
  817. dev_err(dev, "request_irq failed: %d\n", ret);
  818. goto unmap_mmio;
  819. }
  820. /* Some operations on the LCDC might sleep and
  821. * require a preemptible task context */
  822. INIT_WORK(&sinfo->task, atmel_lcdfb_task);
  823. ret = atmel_lcdfb_init_fbinfo(sinfo);
  824. if (ret < 0) {
  825. dev_err(dev, "init fbinfo failed: %d\n", ret);
  826. goto unregister_irqs;
  827. }
  828. /*
  829. * This makes sure that our colour bitfield
  830. * descriptors are correctly initialised.
  831. */
  832. atmel_lcdfb_check_var(&info->var, info);
  833. ret = fb_set_var(info, &info->var);
  834. if (ret) {
  835. dev_warn(dev, "unable to set display parameters\n");
  836. goto free_cmap;
  837. }
  838. dev_set_drvdata(dev, info);
  839. /*
  840. * Tell the world that we're ready to go
  841. */
  842. ret = register_framebuffer(info);
  843. if (ret < 0) {
  844. dev_err(dev, "failed to register framebuffer device: %d\n", ret);
  845. goto reset_drvdata;
  846. }
  847. /* add selected videomode to modelist */
  848. fb_var_to_videomode(&fbmode, &info->var);
  849. fb_add_videomode(&fbmode, &info->modelist);
  850. /* Power up the LCDC screen */
  851. if (sinfo->atmel_lcdfb_power_control)
  852. sinfo->atmel_lcdfb_power_control(1);
  853. dev_info(dev, "fb%d: Atmel LCDC at 0x%08lx (mapped at %p), irq %d\n",
  854. info->node, info->fix.mmio_start, sinfo->mmio, sinfo->irq_base);
  855. return 0;
  856. reset_drvdata:
  857. dev_set_drvdata(dev, NULL);
  858. free_cmap:
  859. fb_dealloc_cmap(&info->cmap);
  860. unregister_irqs:
  861. cancel_work_sync(&sinfo->task);
  862. free_irq(sinfo->irq_base, info);
  863. unmap_mmio:
  864. exit_backlight(sinfo);
  865. iounmap(sinfo->mmio);
  866. release_mem:
  867. release_mem_region(info->fix.mmio_start, info->fix.mmio_len);
  868. free_fb:
  869. if (map)
  870. iounmap(info->screen_base);
  871. else
  872. atmel_lcdfb_free_video_memory(sinfo);
  873. release_intmem:
  874. if (map)
  875. release_mem_region(info->fix.smem_start, info->fix.smem_len);
  876. stop_clk:
  877. atmel_lcdfb_stop_clock(sinfo);
  878. clk_put(sinfo->lcdc_clk);
  879. put_bus_clk:
  880. if (sinfo->bus_clk)
  881. clk_put(sinfo->bus_clk);
  882. free_info:
  883. framebuffer_release(info);
  884. out:
  885. dev_dbg(dev, "%s FAILED\n", __func__);
  886. return ret;
  887. }
  888. static int __exit atmel_lcdfb_remove(struct platform_device *pdev)
  889. {
  890. struct device *dev = &pdev->dev;
  891. struct fb_info *info = dev_get_drvdata(dev);
  892. struct atmel_lcdfb_info *sinfo;
  893. if (!info || !info->par)
  894. return 0;
  895. sinfo = info->par;
  896. cancel_work_sync(&sinfo->task);
  897. exit_backlight(sinfo);
  898. if (sinfo->atmel_lcdfb_power_control)
  899. sinfo->atmel_lcdfb_power_control(0);
  900. unregister_framebuffer(info);
  901. atmel_lcdfb_stop_clock(sinfo);
  902. clk_put(sinfo->lcdc_clk);
  903. if (sinfo->bus_clk)
  904. clk_put(sinfo->bus_clk);
  905. fb_dealloc_cmap(&info->cmap);
  906. free_irq(sinfo->irq_base, info);
  907. iounmap(sinfo->mmio);
  908. release_mem_region(info->fix.mmio_start, info->fix.mmio_len);
  909. if (platform_get_resource(pdev, IORESOURCE_MEM, 1)) {
  910. iounmap(info->screen_base);
  911. release_mem_region(info->fix.smem_start, info->fix.smem_len);
  912. } else {
  913. atmel_lcdfb_free_video_memory(sinfo);
  914. }
  915. dev_set_drvdata(dev, NULL);
  916. framebuffer_release(info);
  917. return 0;
  918. }
  919. #ifdef CONFIG_PM
  920. static int atmel_lcdfb_suspend(struct platform_device *pdev, pm_message_t mesg)
  921. {
  922. struct fb_info *info = platform_get_drvdata(pdev);
  923. struct atmel_lcdfb_info *sinfo = info->par;
  924. /*
  925. * We don't want to handle interrupts while the clock is
  926. * stopped. It may take forever.
  927. */
  928. lcdc_writel(sinfo, ATMEL_LCDC_IDR, ~0UL);
  929. sinfo->saved_lcdcon = lcdc_readl(sinfo, ATMEL_LCDC_CONTRAST_VAL);
  930. lcdc_writel(sinfo, ATMEL_LCDC_CONTRAST_CTR, 0);
  931. if (sinfo->atmel_lcdfb_power_control)
  932. sinfo->atmel_lcdfb_power_control(0);
  933. atmel_lcdfb_stop(sinfo);
  934. atmel_lcdfb_stop_clock(sinfo);
  935. return 0;
  936. }
  937. static int atmel_lcdfb_resume(struct platform_device *pdev)
  938. {
  939. struct fb_info *info = platform_get_drvdata(pdev);
  940. struct atmel_lcdfb_info *sinfo = info->par;
  941. atmel_lcdfb_start_clock(sinfo);
  942. atmel_lcdfb_start(sinfo);
  943. if (sinfo->atmel_lcdfb_power_control)
  944. sinfo->atmel_lcdfb_power_control(1);
  945. lcdc_writel(sinfo, ATMEL_LCDC_CONTRAST_CTR, sinfo->saved_lcdcon);
  946. /* Enable FIFO & DMA errors */
  947. lcdc_writel(sinfo, ATMEL_LCDC_IER, ATMEL_LCDC_UFLWI
  948. | ATMEL_LCDC_OWRI | ATMEL_LCDC_MERI);
  949. return 0;
  950. }
  951. #else
  952. #define atmel_lcdfb_suspend NULL
  953. #define atmel_lcdfb_resume NULL
  954. #endif
  955. static struct platform_driver atmel_lcdfb_driver = {
  956. .remove = __exit_p(atmel_lcdfb_remove),
  957. .suspend = atmel_lcdfb_suspend,
  958. .resume = atmel_lcdfb_resume,
  959. .driver = {
  960. .name = "atmel_lcdfb",
  961. .owner = THIS_MODULE,
  962. },
  963. };
  964. static int __init atmel_lcdfb_init(void)
  965. {
  966. return platform_driver_probe(&atmel_lcdfb_driver, atmel_lcdfb_probe);
  967. }
  968. static void __exit atmel_lcdfb_exit(void)
  969. {
  970. platform_driver_unregister(&atmel_lcdfb_driver);
  971. }
  972. module_init(atmel_lcdfb_init);
  973. module_exit(atmel_lcdfb_exit);
  974. MODULE_DESCRIPTION("AT91/AT32 LCD Controller framebuffer driver");
  975. MODULE_AUTHOR("Nicolas Ferre <nicolas.ferre@atmel.com>");
  976. MODULE_LICENSE("GPL");