atmel_lcdfb.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176
  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 <linux/platform_data/atmel.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 16:
  347. /* Older SOCs use IBGR:555 rather than BGR:565. */
  348. if (sinfo->have_intensity_bit)
  349. var->green.length = 5;
  350. else
  351. var->green.length = 6;
  352. if (sinfo->lcd_wiring_mode == ATMEL_LCDC_WIRING_RGB) {
  353. /* RGB:5X5 mode */
  354. var->red.offset = var->green.length + 5;
  355. var->blue.offset = 0;
  356. } else {
  357. /* BGR:5X5 mode */
  358. var->red.offset = 0;
  359. var->blue.offset = var->green.length + 5;
  360. }
  361. var->green.offset = 5;
  362. var->red.length = var->blue.length = 5;
  363. break;
  364. case 32:
  365. var->transp.offset = 24;
  366. var->transp.length = 8;
  367. /* fall through */
  368. case 24:
  369. if (sinfo->lcd_wiring_mode == ATMEL_LCDC_WIRING_RGB) {
  370. /* RGB:888 mode */
  371. var->red.offset = 16;
  372. var->blue.offset = 0;
  373. } else {
  374. /* BGR:888 mode */
  375. var->red.offset = 0;
  376. var->blue.offset = 16;
  377. }
  378. var->green.offset = 8;
  379. var->red.length = var->green.length = var->blue.length = 8;
  380. break;
  381. default:
  382. dev_err(dev, "color depth %d not supported\n",
  383. var->bits_per_pixel);
  384. return -EINVAL;
  385. }
  386. return 0;
  387. }
  388. /*
  389. * LCD reset sequence
  390. */
  391. static void atmel_lcdfb_reset(struct atmel_lcdfb_info *sinfo)
  392. {
  393. might_sleep();
  394. atmel_lcdfb_stop(sinfo);
  395. atmel_lcdfb_start(sinfo);
  396. }
  397. /**
  398. * atmel_lcdfb_set_par - Alters the hardware state.
  399. * @info: frame buffer structure that represents a single frame buffer
  400. *
  401. * Using the fb_var_screeninfo in fb_info we set the resolution
  402. * of the this particular framebuffer. This function alters the
  403. * par AND the fb_fix_screeninfo stored in fb_info. It doesn't
  404. * not alter var in fb_info since we are using that data. This
  405. * means we depend on the data in var inside fb_info to be
  406. * supported by the hardware. atmel_lcdfb_check_var is always called
  407. * before atmel_lcdfb_set_par to ensure this. Again if you can't
  408. * change the resolution you don't need this function.
  409. *
  410. */
  411. static int atmel_lcdfb_set_par(struct fb_info *info)
  412. {
  413. struct atmel_lcdfb_info *sinfo = info->par;
  414. unsigned long hozval_linesz;
  415. unsigned long value;
  416. unsigned long clk_value_khz;
  417. unsigned long bits_per_line;
  418. unsigned long pix_factor = 2;
  419. might_sleep();
  420. dev_dbg(info->device, "%s:\n", __func__);
  421. dev_dbg(info->device, " * resolution: %ux%u (%ux%u virtual)\n",
  422. info->var.xres, info->var.yres,
  423. info->var.xres_virtual, info->var.yres_virtual);
  424. atmel_lcdfb_stop_nowait(sinfo);
  425. if (info->var.bits_per_pixel == 1)
  426. info->fix.visual = FB_VISUAL_MONO01;
  427. else if (info->var.bits_per_pixel <= 8)
  428. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  429. else
  430. info->fix.visual = FB_VISUAL_TRUECOLOR;
  431. bits_per_line = info->var.xres_virtual * info->var.bits_per_pixel;
  432. info->fix.line_length = DIV_ROUND_UP(bits_per_line, 8);
  433. /* Re-initialize the DMA engine... */
  434. dev_dbg(info->device, " * update DMA engine\n");
  435. atmel_lcdfb_update_dma(info, &info->var);
  436. /* ...set frame size and burst length = 8 words (?) */
  437. value = (info->var.yres * info->var.xres * info->var.bits_per_pixel) / 32;
  438. value |= ((ATMEL_LCDC_DMA_BURST_LEN - 1) << ATMEL_LCDC_BLENGTH_OFFSET);
  439. lcdc_writel(sinfo, ATMEL_LCDC_DMAFRMCFG, value);
  440. /* Now, the LCDC core... */
  441. /* Set pixel clock */
  442. if (cpu_is_at91sam9g45() && !cpu_is_at91sam9g45es())
  443. pix_factor = 1;
  444. clk_value_khz = clk_get_rate(sinfo->lcdc_clk) / 1000;
  445. value = DIV_ROUND_UP(clk_value_khz, PICOS2KHZ(info->var.pixclock));
  446. if (value < pix_factor) {
  447. dev_notice(info->device, "Bypassing pixel clock divider\n");
  448. lcdc_writel(sinfo, ATMEL_LCDC_LCDCON1, ATMEL_LCDC_BYPASS);
  449. } else {
  450. value = (value / pix_factor) - 1;
  451. dev_dbg(info->device, " * programming CLKVAL = 0x%08lx\n",
  452. value);
  453. lcdc_writel(sinfo, ATMEL_LCDC_LCDCON1,
  454. value << ATMEL_LCDC_CLKVAL_OFFSET);
  455. info->var.pixclock =
  456. KHZ2PICOS(clk_value_khz / (pix_factor * (value + 1)));
  457. dev_dbg(info->device, " updated pixclk: %lu KHz\n",
  458. PICOS2KHZ(info->var.pixclock));
  459. }
  460. /* Initialize control register 2 */
  461. value = sinfo->default_lcdcon2;
  462. if (!(info->var.sync & FB_SYNC_HOR_HIGH_ACT))
  463. value |= ATMEL_LCDC_INVLINE_INVERTED;
  464. if (!(info->var.sync & FB_SYNC_VERT_HIGH_ACT))
  465. value |= ATMEL_LCDC_INVFRAME_INVERTED;
  466. switch (info->var.bits_per_pixel) {
  467. case 1: value |= ATMEL_LCDC_PIXELSIZE_1; break;
  468. case 2: value |= ATMEL_LCDC_PIXELSIZE_2; break;
  469. case 4: value |= ATMEL_LCDC_PIXELSIZE_4; break;
  470. case 8: value |= ATMEL_LCDC_PIXELSIZE_8; break;
  471. case 15: /* fall through */
  472. case 16: value |= ATMEL_LCDC_PIXELSIZE_16; break;
  473. case 24: value |= ATMEL_LCDC_PIXELSIZE_24; break;
  474. case 32: value |= ATMEL_LCDC_PIXELSIZE_32; break;
  475. default: BUG(); break;
  476. }
  477. dev_dbg(info->device, " * LCDCON2 = %08lx\n", value);
  478. lcdc_writel(sinfo, ATMEL_LCDC_LCDCON2, value);
  479. /* Vertical timing */
  480. value = (info->var.vsync_len - 1) << ATMEL_LCDC_VPW_OFFSET;
  481. value |= info->var.upper_margin << ATMEL_LCDC_VBP_OFFSET;
  482. value |= info->var.lower_margin;
  483. dev_dbg(info->device, " * LCDTIM1 = %08lx\n", value);
  484. lcdc_writel(sinfo, ATMEL_LCDC_TIM1, value);
  485. /* Horizontal timing */
  486. value = (info->var.right_margin - 1) << ATMEL_LCDC_HFP_OFFSET;
  487. value |= (info->var.hsync_len - 1) << ATMEL_LCDC_HPW_OFFSET;
  488. value |= (info->var.left_margin - 1);
  489. dev_dbg(info->device, " * LCDTIM2 = %08lx\n", value);
  490. lcdc_writel(sinfo, ATMEL_LCDC_TIM2, value);
  491. /* Horizontal value (aka line size) */
  492. hozval_linesz = compute_hozval(info->var.xres,
  493. lcdc_readl(sinfo, ATMEL_LCDC_LCDCON2));
  494. /* Display size */
  495. value = (hozval_linesz - 1) << ATMEL_LCDC_HOZVAL_OFFSET;
  496. value |= info->var.yres - 1;
  497. dev_dbg(info->device, " * LCDFRMCFG = %08lx\n", value);
  498. lcdc_writel(sinfo, ATMEL_LCDC_LCDFRMCFG, value);
  499. /* FIFO Threshold: Use formula from data sheet */
  500. value = ATMEL_LCDC_FIFO_SIZE - (2 * ATMEL_LCDC_DMA_BURST_LEN + 3);
  501. lcdc_writel(sinfo, ATMEL_LCDC_FIFO, value);
  502. /* Toggle LCD_MODE every frame */
  503. lcdc_writel(sinfo, ATMEL_LCDC_MVAL, 0);
  504. /* Disable all interrupts */
  505. lcdc_writel(sinfo, ATMEL_LCDC_IDR, ~0UL);
  506. /* Enable FIFO & DMA errors */
  507. lcdc_writel(sinfo, ATMEL_LCDC_IER, ATMEL_LCDC_UFLWI | ATMEL_LCDC_OWRI | ATMEL_LCDC_MERI);
  508. /* ...wait for DMA engine to become idle... */
  509. while (lcdc_readl(sinfo, ATMEL_LCDC_DMACON) & ATMEL_LCDC_DMABUSY)
  510. msleep(10);
  511. atmel_lcdfb_start(sinfo);
  512. dev_dbg(info->device, " * DONE\n");
  513. return 0;
  514. }
  515. static inline unsigned int chan_to_field(unsigned int chan, const struct fb_bitfield *bf)
  516. {
  517. chan &= 0xffff;
  518. chan >>= 16 - bf->length;
  519. return chan << bf->offset;
  520. }
  521. /**
  522. * atmel_lcdfb_setcolreg - Optional function. Sets a color register.
  523. * @regno: Which register in the CLUT we are programming
  524. * @red: The red value which can be up to 16 bits wide
  525. * @green: The green value which can be up to 16 bits wide
  526. * @blue: The blue value which can be up to 16 bits wide.
  527. * @transp: If supported the alpha value which can be up to 16 bits wide.
  528. * @info: frame buffer info structure
  529. *
  530. * Set a single color register. The values supplied have a 16 bit
  531. * magnitude which needs to be scaled in this function for the hardware.
  532. * Things to take into consideration are how many color registers, if
  533. * any, are supported with the current color visual. With truecolor mode
  534. * no color palettes are supported. Here a pseudo palette is created
  535. * which we store the value in pseudo_palette in struct fb_info. For
  536. * pseudocolor mode we have a limited color palette. To deal with this
  537. * we can program what color is displayed for a particular pixel value.
  538. * DirectColor is similar in that we can program each color field. If
  539. * we have a static colormap we don't need to implement this function.
  540. *
  541. * Returns negative errno on error, or zero on success. In an
  542. * ideal world, this would have been the case, but as it turns
  543. * out, the other drivers return 1 on failure, so that's what
  544. * we're going to do.
  545. */
  546. static int atmel_lcdfb_setcolreg(unsigned int regno, unsigned int red,
  547. unsigned int green, unsigned int blue,
  548. unsigned int transp, struct fb_info *info)
  549. {
  550. struct atmel_lcdfb_info *sinfo = info->par;
  551. unsigned int val;
  552. u32 *pal;
  553. int ret = 1;
  554. if (info->var.grayscale)
  555. red = green = blue = (19595 * red + 38470 * green
  556. + 7471 * blue) >> 16;
  557. switch (info->fix.visual) {
  558. case FB_VISUAL_TRUECOLOR:
  559. if (regno < 16) {
  560. pal = info->pseudo_palette;
  561. val = chan_to_field(red, &info->var.red);
  562. val |= chan_to_field(green, &info->var.green);
  563. val |= chan_to_field(blue, &info->var.blue);
  564. pal[regno] = val;
  565. ret = 0;
  566. }
  567. break;
  568. case FB_VISUAL_PSEUDOCOLOR:
  569. if (regno < 256) {
  570. if (sinfo->have_intensity_bit) {
  571. /* old style I+BGR:555 */
  572. val = ((red >> 11) & 0x001f);
  573. val |= ((green >> 6) & 0x03e0);
  574. val |= ((blue >> 1) & 0x7c00);
  575. /*
  576. * TODO: intensity bit. Maybe something like
  577. * ~(red[10] ^ green[10] ^ blue[10]) & 1
  578. */
  579. } else {
  580. /* new style BGR:565 / RGB:565 */
  581. if (sinfo->lcd_wiring_mode ==
  582. ATMEL_LCDC_WIRING_RGB) {
  583. val = ((blue >> 11) & 0x001f);
  584. val |= ((red >> 0) & 0xf800);
  585. } else {
  586. val = ((red >> 11) & 0x001f);
  587. val |= ((blue >> 0) & 0xf800);
  588. }
  589. val |= ((green >> 5) & 0x07e0);
  590. }
  591. lcdc_writel(sinfo, ATMEL_LCDC_LUT(regno), val);
  592. ret = 0;
  593. }
  594. break;
  595. case FB_VISUAL_MONO01:
  596. if (regno < 2) {
  597. val = (regno == 0) ? 0x00 : 0x1F;
  598. lcdc_writel(sinfo, ATMEL_LCDC_LUT(regno), val);
  599. ret = 0;
  600. }
  601. break;
  602. }
  603. return ret;
  604. }
  605. static int atmel_lcdfb_pan_display(struct fb_var_screeninfo *var,
  606. struct fb_info *info)
  607. {
  608. dev_dbg(info->device, "%s\n", __func__);
  609. atmel_lcdfb_update_dma(info, var);
  610. return 0;
  611. }
  612. static int atmel_lcdfb_blank(int blank_mode, struct fb_info *info)
  613. {
  614. struct atmel_lcdfb_info *sinfo = info->par;
  615. switch (blank_mode) {
  616. case FB_BLANK_UNBLANK:
  617. case FB_BLANK_NORMAL:
  618. atmel_lcdfb_start(sinfo);
  619. break;
  620. case FB_BLANK_VSYNC_SUSPEND:
  621. case FB_BLANK_HSYNC_SUSPEND:
  622. break;
  623. case FB_BLANK_POWERDOWN:
  624. atmel_lcdfb_stop(sinfo);
  625. break;
  626. default:
  627. return -EINVAL;
  628. }
  629. /* let fbcon do a soft blank for us */
  630. return ((blank_mode == FB_BLANK_NORMAL) ? 1 : 0);
  631. }
  632. static struct fb_ops atmel_lcdfb_ops = {
  633. .owner = THIS_MODULE,
  634. .fb_check_var = atmel_lcdfb_check_var,
  635. .fb_set_par = atmel_lcdfb_set_par,
  636. .fb_setcolreg = atmel_lcdfb_setcolreg,
  637. .fb_blank = atmel_lcdfb_blank,
  638. .fb_pan_display = atmel_lcdfb_pan_display,
  639. .fb_fillrect = cfb_fillrect,
  640. .fb_copyarea = cfb_copyarea,
  641. .fb_imageblit = cfb_imageblit,
  642. };
  643. static irqreturn_t atmel_lcdfb_interrupt(int irq, void *dev_id)
  644. {
  645. struct fb_info *info = dev_id;
  646. struct atmel_lcdfb_info *sinfo = info->par;
  647. u32 status;
  648. status = lcdc_readl(sinfo, ATMEL_LCDC_ISR);
  649. if (status & ATMEL_LCDC_UFLWI) {
  650. dev_warn(info->device, "FIFO underflow %#x\n", status);
  651. /* reset DMA and FIFO to avoid screen shifting */
  652. schedule_work(&sinfo->task);
  653. }
  654. lcdc_writel(sinfo, ATMEL_LCDC_ICR, status);
  655. return IRQ_HANDLED;
  656. }
  657. /*
  658. * LCD controller task (to reset the LCD)
  659. */
  660. static void atmel_lcdfb_task(struct work_struct *work)
  661. {
  662. struct atmel_lcdfb_info *sinfo =
  663. container_of(work, struct atmel_lcdfb_info, task);
  664. atmel_lcdfb_reset(sinfo);
  665. }
  666. static int __init atmel_lcdfb_init_fbinfo(struct atmel_lcdfb_info *sinfo)
  667. {
  668. struct fb_info *info = sinfo->info;
  669. int ret = 0;
  670. info->var.activate |= FB_ACTIVATE_FORCE | FB_ACTIVATE_NOW;
  671. dev_info(info->device,
  672. "%luKiB frame buffer at %08lx (mapped at %p)\n",
  673. (unsigned long)info->fix.smem_len / 1024,
  674. (unsigned long)info->fix.smem_start,
  675. info->screen_base);
  676. /* Allocate colormap */
  677. ret = fb_alloc_cmap(&info->cmap, 256, 0);
  678. if (ret < 0)
  679. dev_err(info->device, "Alloc color map failed\n");
  680. return ret;
  681. }
  682. static void atmel_lcdfb_start_clock(struct atmel_lcdfb_info *sinfo)
  683. {
  684. if (sinfo->bus_clk)
  685. clk_enable(sinfo->bus_clk);
  686. clk_enable(sinfo->lcdc_clk);
  687. }
  688. static void atmel_lcdfb_stop_clock(struct atmel_lcdfb_info *sinfo)
  689. {
  690. if (sinfo->bus_clk)
  691. clk_disable(sinfo->bus_clk);
  692. clk_disable(sinfo->lcdc_clk);
  693. }
  694. static int __init atmel_lcdfb_probe(struct platform_device *pdev)
  695. {
  696. struct device *dev = &pdev->dev;
  697. struct fb_info *info;
  698. struct atmel_lcdfb_info *sinfo;
  699. struct atmel_lcdfb_info *pdata_sinfo;
  700. struct fb_videomode fbmode;
  701. struct resource *regs = NULL;
  702. struct resource *map = NULL;
  703. int ret;
  704. dev_dbg(dev, "%s BEGIN\n", __func__);
  705. ret = -ENOMEM;
  706. info = framebuffer_alloc(sizeof(struct atmel_lcdfb_info), dev);
  707. if (!info) {
  708. dev_err(dev, "cannot allocate memory\n");
  709. goto out;
  710. }
  711. sinfo = info->par;
  712. if (dev->platform_data) {
  713. pdata_sinfo = (struct atmel_lcdfb_info *)dev->platform_data;
  714. sinfo->default_bpp = pdata_sinfo->default_bpp;
  715. sinfo->default_dmacon = pdata_sinfo->default_dmacon;
  716. sinfo->default_lcdcon2 = pdata_sinfo->default_lcdcon2;
  717. sinfo->default_monspecs = pdata_sinfo->default_monspecs;
  718. sinfo->atmel_lcdfb_power_control = pdata_sinfo->atmel_lcdfb_power_control;
  719. sinfo->guard_time = pdata_sinfo->guard_time;
  720. sinfo->smem_len = pdata_sinfo->smem_len;
  721. sinfo->lcdcon_is_backlight = pdata_sinfo->lcdcon_is_backlight;
  722. sinfo->lcdcon_pol_negative = pdata_sinfo->lcdcon_pol_negative;
  723. sinfo->lcd_wiring_mode = pdata_sinfo->lcd_wiring_mode;
  724. } else {
  725. dev_err(dev, "cannot get default configuration\n");
  726. goto free_info;
  727. }
  728. sinfo->info = info;
  729. sinfo->pdev = pdev;
  730. if (cpu_is_at91sam9261() || cpu_is_at91sam9263() ||
  731. cpu_is_at91sam9rl()) {
  732. sinfo->have_intensity_bit = true;
  733. }
  734. strcpy(info->fix.id, sinfo->pdev->name);
  735. info->flags = ATMEL_LCDFB_FBINFO_DEFAULT;
  736. info->pseudo_palette = sinfo->pseudo_palette;
  737. info->fbops = &atmel_lcdfb_ops;
  738. memcpy(&info->monspecs, sinfo->default_monspecs, sizeof(info->monspecs));
  739. info->fix = atmel_lcdfb_fix;
  740. /* Enable LCDC Clocks */
  741. if (cpu_is_at91sam9261() || cpu_is_at91sam9g10()
  742. || cpu_is_at32ap7000()) {
  743. sinfo->bus_clk = clk_get(dev, "hck1");
  744. if (IS_ERR(sinfo->bus_clk)) {
  745. ret = PTR_ERR(sinfo->bus_clk);
  746. goto free_info;
  747. }
  748. }
  749. sinfo->lcdc_clk = clk_get(dev, "lcdc_clk");
  750. if (IS_ERR(sinfo->lcdc_clk)) {
  751. ret = PTR_ERR(sinfo->lcdc_clk);
  752. goto put_bus_clk;
  753. }
  754. atmel_lcdfb_start_clock(sinfo);
  755. ret = fb_find_mode(&info->var, info, NULL, info->monspecs.modedb,
  756. info->monspecs.modedb_len, info->monspecs.modedb,
  757. sinfo->default_bpp);
  758. if (!ret) {
  759. dev_err(dev, "no suitable video mode found\n");
  760. goto stop_clk;
  761. }
  762. regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  763. if (!regs) {
  764. dev_err(dev, "resources unusable\n");
  765. ret = -ENXIO;
  766. goto stop_clk;
  767. }
  768. sinfo->irq_base = platform_get_irq(pdev, 0);
  769. if (sinfo->irq_base < 0) {
  770. dev_err(dev, "unable to get irq\n");
  771. ret = sinfo->irq_base;
  772. goto stop_clk;
  773. }
  774. /* Initialize video memory */
  775. map = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  776. if (map) {
  777. /* use a pre-allocated memory buffer */
  778. info->fix.smem_start = map->start;
  779. info->fix.smem_len = resource_size(map);
  780. if (!request_mem_region(info->fix.smem_start,
  781. info->fix.smem_len, pdev->name)) {
  782. ret = -EBUSY;
  783. goto stop_clk;
  784. }
  785. info->screen_base = ioremap(info->fix.smem_start, info->fix.smem_len);
  786. if (!info->screen_base) {
  787. ret = -ENOMEM;
  788. goto release_intmem;
  789. }
  790. /*
  791. * Don't clear the framebuffer -- someone may have set
  792. * up a splash image.
  793. */
  794. } else {
  795. /* allocate memory buffer */
  796. ret = atmel_lcdfb_alloc_video_memory(sinfo);
  797. if (ret < 0) {
  798. dev_err(dev, "cannot allocate framebuffer: %d\n", ret);
  799. goto stop_clk;
  800. }
  801. }
  802. /* LCDC registers */
  803. info->fix.mmio_start = regs->start;
  804. info->fix.mmio_len = resource_size(regs);
  805. if (!request_mem_region(info->fix.mmio_start,
  806. info->fix.mmio_len, pdev->name)) {
  807. ret = -EBUSY;
  808. goto free_fb;
  809. }
  810. sinfo->mmio = ioremap(info->fix.mmio_start, info->fix.mmio_len);
  811. if (!sinfo->mmio) {
  812. dev_err(dev, "cannot map LCDC registers\n");
  813. ret = -ENOMEM;
  814. goto release_mem;
  815. }
  816. /* Initialize PWM for contrast or backlight ("off") */
  817. init_contrast(sinfo);
  818. /* interrupt */
  819. ret = request_irq(sinfo->irq_base, atmel_lcdfb_interrupt, 0, pdev->name, info);
  820. if (ret) {
  821. dev_err(dev, "request_irq failed: %d\n", ret);
  822. goto unmap_mmio;
  823. }
  824. /* Some operations on the LCDC might sleep and
  825. * require a preemptible task context */
  826. INIT_WORK(&sinfo->task, atmel_lcdfb_task);
  827. ret = atmel_lcdfb_init_fbinfo(sinfo);
  828. if (ret < 0) {
  829. dev_err(dev, "init fbinfo failed: %d\n", ret);
  830. goto unregister_irqs;
  831. }
  832. /*
  833. * This makes sure that our colour bitfield
  834. * descriptors are correctly initialised.
  835. */
  836. atmel_lcdfb_check_var(&info->var, info);
  837. ret = fb_set_var(info, &info->var);
  838. if (ret) {
  839. dev_warn(dev, "unable to set display parameters\n");
  840. goto free_cmap;
  841. }
  842. dev_set_drvdata(dev, info);
  843. /*
  844. * Tell the world that we're ready to go
  845. */
  846. ret = register_framebuffer(info);
  847. if (ret < 0) {
  848. dev_err(dev, "failed to register framebuffer device: %d\n", ret);
  849. goto reset_drvdata;
  850. }
  851. /* add selected videomode to modelist */
  852. fb_var_to_videomode(&fbmode, &info->var);
  853. fb_add_videomode(&fbmode, &info->modelist);
  854. /* Power up the LCDC screen */
  855. if (sinfo->atmel_lcdfb_power_control)
  856. sinfo->atmel_lcdfb_power_control(1);
  857. dev_info(dev, "fb%d: Atmel LCDC at 0x%08lx (mapped at %p), irq %d\n",
  858. info->node, info->fix.mmio_start, sinfo->mmio, sinfo->irq_base);
  859. return 0;
  860. reset_drvdata:
  861. dev_set_drvdata(dev, NULL);
  862. free_cmap:
  863. fb_dealloc_cmap(&info->cmap);
  864. unregister_irqs:
  865. cancel_work_sync(&sinfo->task);
  866. free_irq(sinfo->irq_base, info);
  867. unmap_mmio:
  868. exit_backlight(sinfo);
  869. iounmap(sinfo->mmio);
  870. release_mem:
  871. release_mem_region(info->fix.mmio_start, info->fix.mmio_len);
  872. free_fb:
  873. if (map)
  874. iounmap(info->screen_base);
  875. else
  876. atmel_lcdfb_free_video_memory(sinfo);
  877. release_intmem:
  878. if (map)
  879. release_mem_region(info->fix.smem_start, info->fix.smem_len);
  880. stop_clk:
  881. atmel_lcdfb_stop_clock(sinfo);
  882. clk_put(sinfo->lcdc_clk);
  883. put_bus_clk:
  884. if (sinfo->bus_clk)
  885. clk_put(sinfo->bus_clk);
  886. free_info:
  887. framebuffer_release(info);
  888. out:
  889. dev_dbg(dev, "%s FAILED\n", __func__);
  890. return ret;
  891. }
  892. static int __exit atmel_lcdfb_remove(struct platform_device *pdev)
  893. {
  894. struct device *dev = &pdev->dev;
  895. struct fb_info *info = dev_get_drvdata(dev);
  896. struct atmel_lcdfb_info *sinfo;
  897. if (!info || !info->par)
  898. return 0;
  899. sinfo = info->par;
  900. cancel_work_sync(&sinfo->task);
  901. exit_backlight(sinfo);
  902. if (sinfo->atmel_lcdfb_power_control)
  903. sinfo->atmel_lcdfb_power_control(0);
  904. unregister_framebuffer(info);
  905. atmel_lcdfb_stop_clock(sinfo);
  906. clk_put(sinfo->lcdc_clk);
  907. if (sinfo->bus_clk)
  908. clk_put(sinfo->bus_clk);
  909. fb_dealloc_cmap(&info->cmap);
  910. free_irq(sinfo->irq_base, info);
  911. iounmap(sinfo->mmio);
  912. release_mem_region(info->fix.mmio_start, info->fix.mmio_len);
  913. if (platform_get_resource(pdev, IORESOURCE_MEM, 1)) {
  914. iounmap(info->screen_base);
  915. release_mem_region(info->fix.smem_start, info->fix.smem_len);
  916. } else {
  917. atmel_lcdfb_free_video_memory(sinfo);
  918. }
  919. dev_set_drvdata(dev, NULL);
  920. framebuffer_release(info);
  921. return 0;
  922. }
  923. #ifdef CONFIG_PM
  924. static int atmel_lcdfb_suspend(struct platform_device *pdev, pm_message_t mesg)
  925. {
  926. struct fb_info *info = platform_get_drvdata(pdev);
  927. struct atmel_lcdfb_info *sinfo = info->par;
  928. /*
  929. * We don't want to handle interrupts while the clock is
  930. * stopped. It may take forever.
  931. */
  932. lcdc_writel(sinfo, ATMEL_LCDC_IDR, ~0UL);
  933. sinfo->saved_lcdcon = lcdc_readl(sinfo, ATMEL_LCDC_CONTRAST_CTR);
  934. lcdc_writel(sinfo, ATMEL_LCDC_CONTRAST_CTR, 0);
  935. if (sinfo->atmel_lcdfb_power_control)
  936. sinfo->atmel_lcdfb_power_control(0);
  937. atmel_lcdfb_stop(sinfo);
  938. atmel_lcdfb_stop_clock(sinfo);
  939. return 0;
  940. }
  941. static int atmel_lcdfb_resume(struct platform_device *pdev)
  942. {
  943. struct fb_info *info = platform_get_drvdata(pdev);
  944. struct atmel_lcdfb_info *sinfo = info->par;
  945. atmel_lcdfb_start_clock(sinfo);
  946. atmel_lcdfb_start(sinfo);
  947. if (sinfo->atmel_lcdfb_power_control)
  948. sinfo->atmel_lcdfb_power_control(1);
  949. lcdc_writel(sinfo, ATMEL_LCDC_CONTRAST_CTR, sinfo->saved_lcdcon);
  950. /* Enable FIFO & DMA errors */
  951. lcdc_writel(sinfo, ATMEL_LCDC_IER, ATMEL_LCDC_UFLWI
  952. | ATMEL_LCDC_OWRI | ATMEL_LCDC_MERI);
  953. return 0;
  954. }
  955. #else
  956. #define atmel_lcdfb_suspend NULL
  957. #define atmel_lcdfb_resume NULL
  958. #endif
  959. static struct platform_driver atmel_lcdfb_driver = {
  960. .remove = __exit_p(atmel_lcdfb_remove),
  961. .suspend = atmel_lcdfb_suspend,
  962. .resume = atmel_lcdfb_resume,
  963. .driver = {
  964. .name = "atmel_lcdfb",
  965. .owner = THIS_MODULE,
  966. },
  967. };
  968. static int __init atmel_lcdfb_init(void)
  969. {
  970. return platform_driver_probe(&atmel_lcdfb_driver, atmel_lcdfb_probe);
  971. }
  972. static void __exit atmel_lcdfb_exit(void)
  973. {
  974. platform_driver_unregister(&atmel_lcdfb_driver);
  975. }
  976. module_init(atmel_lcdfb_init);
  977. module_exit(atmel_lcdfb_exit);
  978. MODULE_DESCRIPTION("AT91/AT32 LCD Controller framebuffer driver");
  979. MODULE_AUTHOR("Nicolas Ferre <nicolas.ferre@atmel.com>");
  980. MODULE_LICENSE("GPL");