ark1668e_lcdfb.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198
  1. /*
  2. * Arkmicro ark1668e lcd driver
  3. *
  4. * Licensed under GPLv2 or later.
  5. */
  6. #define DEBUG
  7. #include <linux/kernel.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/dma-mapping.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/clk.h>
  12. #include <linux/fb.h>
  13. #include <linux/init.h>
  14. #include <linux/delay.h>
  15. #include <linux/backlight.h>
  16. #include <linux/gfp.h>
  17. #include <linux/module.h>
  18. #include <linux/of.h>
  19. #include <linux/of_device.h>
  20. #include <linux/of_gpio.h>
  21. #include <video/of_display_timing.h>
  22. #include <video/display_timing.h>
  23. #include <video/videomode.h>
  24. #include "ark1668e_lcdc.h"
  25. #define BACKLIGHT_PWM_PERIOD 50000
  26. #define BACKLIGHT_MAX_BRIGHTNESS 100
  27. #define SYS_REG_BASE 0xe4900000
  28. #define SYS_CLK_DELAY 0x70
  29. #define SYS_CTL_2A 0xa8
  30. #define SYS_PIXEL_CLK_INV_OFFSET 16
  31. #define SYS_ANALOG_REG1 0x144
  32. #define SYS_LVDS_CTRL_CFG 0x190
  33. #define SYS_LVDS_CTRL_CFG1 0x194
  34. #define SWITCH_LVDS_TO_TTL 0x80000000
  35. #define SWITCH_TTL_TO_LVDS 0x00000000
  36. #define BALCK_BACKCOLOR 0x000000
  37. #define RED_BACKCOLOR 0xFF0000
  38. #ifdef CONFIG_VIDEO_ARK1668E_VIN
  39. extern int ark_vin_display_int_handler(void);
  40. #endif
  41. struct ark1668e_lcdfb_power_ctrl_gpio {
  42. int gpio;
  43. int active_low;
  44. struct list_head list;
  45. };
  46. #define lcdc_readl(sinfo, reg) __raw_readl((sinfo)->mmio+(reg))
  47. #define lcdc_writel(sinfo, reg, val) __raw_writel((val), (sinfo)->mmio+(reg))
  48. #define lcdc_readl_sys(sinfo, reg) __raw_readl((sinfo)->sysreg+(reg))
  49. #define lcdc_writel_sys(_syssinfo, reg, val) __raw_writel((val), (sinfo)->sysreg+(reg))
  50. #define ARK1668E_LCDFB_FBINFO_DEFAULT (FBINFO_DEFAULT \
  51. | FBINFO_HWACCEL_NONE)
  52. static int ark1668e_set_backlight(struct ark1668e_lcdfb_pdata *pdata,
  53. int brightness)
  54. {
  55. int duty = brightness * BACKLIGHT_PWM_PERIOD / BACKLIGHT_MAX_BRIGHTNESS;
  56. pwm_enable(pdata->pwm);
  57. pwm_config(pdata->pwm, duty, BACKLIGHT_PWM_PERIOD);
  58. pdata->backlight_value = brightness;
  59. return 0;
  60. }
  61. /* some bl->props field just changed */
  62. static int ark1668e_bl_update_status(struct backlight_device *bl)
  63. {
  64. struct ark1668e_lcdfb_info *sinfo = bl_get_data(bl);
  65. struct ark1668e_lcdfb_pdata *pdata = &sinfo->pdata;
  66. int power = sinfo->bl_power;
  67. int brightness = bl->props.brightness;
  68. /* REVISIT there may be a meaningful difference between
  69. * fb_blank and power ... there seem to be some cases
  70. * this doesn't handle correctly.
  71. */
  72. if (bl->props.fb_blank != sinfo->bl_power)
  73. power = bl->props.fb_blank;
  74. else if (bl->props.power != sinfo->bl_power)
  75. power = bl->props.power;
  76. if (brightness < 0 && power == FB_BLANK_UNBLANK)
  77. brightness = pdata->backlight_value;
  78. else if (power != FB_BLANK_UNBLANK)
  79. brightness = 0;
  80. ark1668e_set_backlight(pdata, brightness);
  81. bl->props.fb_blank = bl->props.power = sinfo->bl_power = power;
  82. return 0;
  83. }
  84. static int ark1668e_bl_get_brightness(struct backlight_device *bl)
  85. {
  86. struct ark1668e_lcdfb_info *sinfo = bl_get_data(bl);
  87. struct ark1668e_lcdfb_pdata *pdata = &sinfo->pdata;
  88. return pdata->backlight_value;
  89. }
  90. static const struct backlight_ops ark1668e_lcdc_bl_ops = {
  91. .update_status = ark1668e_bl_update_status,
  92. .get_brightness = ark1668e_bl_get_brightness,
  93. };
  94. static void init_backlight(struct ark1668e_lcdfb_info *sinfo)
  95. {
  96. struct ark1668e_lcdfb_pdata *pdata = &sinfo->pdata;
  97. struct backlight_properties props;
  98. struct backlight_device *bl;
  99. sinfo->bl_power = FB_BLANK_UNBLANK;
  100. if (sinfo->backlight)
  101. return;
  102. memset(&props, 0, sizeof(struct backlight_properties));
  103. props.type = BACKLIGHT_RAW;
  104. props.max_brightness = BACKLIGHT_MAX_BRIGHTNESS;
  105. bl = backlight_device_register("backlight", &sinfo->pdev->dev, sinfo,
  106. &ark1668e_lcdc_bl_ops, &props);
  107. if (IS_ERR(bl)) {
  108. dev_err(&sinfo->pdev->dev, "error %ld on backlight register\n",
  109. PTR_ERR(bl));
  110. return;
  111. }
  112. sinfo->backlight = bl;
  113. bl->props.power = FB_BLANK_UNBLANK;
  114. bl->props.fb_blank = FB_BLANK_UNBLANK;
  115. bl->props.brightness = ark1668e_bl_get_brightness(bl);
  116. ark1668e_set_backlight(pdata, pdata->backlight_value);
  117. }
  118. static void exit_backlight(struct ark1668e_lcdfb_info *sinfo)
  119. {
  120. if (!sinfo->backlight)
  121. return;
  122. if (sinfo->backlight->ops) {
  123. sinfo->backlight->props.power = FB_BLANK_POWERDOWN;
  124. sinfo->backlight->ops->update_status(sinfo->backlight);
  125. }
  126. backlight_device_unregister(sinfo->backlight);
  127. }
  128. static inline void ark1668e_lcdfb_power_control(struct ark1668e_lcdfb_info *sinfo, int on)
  129. {
  130. struct ark1668e_lcdfb_pdata *pdata = &sinfo->pdata;
  131. if (pdata->ark1668e_lcdfb_power_control)
  132. pdata->ark1668e_lcdfb_power_control(pdata, on);
  133. }
  134. static const struct fb_fix_screeninfo ark1668e_lcdfb_fix __initconst = {
  135. .type = FB_TYPE_PACKED_PIXELS,
  136. .visual = FB_VISUAL_TRUECOLOR,
  137. .xpanstep = 0,
  138. .ypanstep = 1,
  139. .ywrapstep = 0,
  140. .accel = FB_ACCEL_NONE,
  141. };
  142. /* static void ark1668e_lcdfb_stop(struct ark1668e_lcdfb_info *sinfo)
  143. {
  144. lcdc_writel(sinfo, ARK1668E_LCDC_EANBLE, 0);
  145. } */
  146. static void ark1668e_lcdfb_start(struct ark1668e_lcdfb_info *sinfo)
  147. {
  148. lcdc_writel(sinfo, ARK1668E_LCDC_EANBLE, 1);
  149. }
  150. static inline void ark1668e_lcdfb_free_video_memory(struct ark1668e_lcdfb_info *sinfo)
  151. {
  152. struct fb_info *info = sinfo->info;
  153. dma_free_wc(info->device, info->fix.smem_len, info->screen_base,
  154. info->fix.smem_start);
  155. }
  156. /**
  157. * ark1668e_lcdfb_alloc_video_memory - Allocate framebuffer memory
  158. * @sinfo: the frame buffer to allocate memory for
  159. *
  160. * This function is called only from the ark1668e_lcdfb_probe()
  161. * so no locking by fb_info->mm_lock around smem_len setting is needed.
  162. */
  163. static int ark1668e_lcdfb_alloc_video_memory(struct ark1668e_lcdfb_info *sinfo)
  164. {
  165. struct fb_info *info = sinfo->info;
  166. struct fb_var_screeninfo *var = &info->var;
  167. unsigned int smem_len;
  168. smem_len = (var->xres_virtual * var->yres_virtual
  169. * ((var->bits_per_pixel + 7) / 8));
  170. info->fix.smem_len = max(smem_len, sinfo->smem_len);
  171. info->screen_base = dma_alloc_wc(info->device, info->fix.smem_len,
  172. (dma_addr_t *)&info->fix.smem_start,
  173. GFP_KERNEL);
  174. if (!info->screen_base) {
  175. return -ENOMEM;
  176. }
  177. memset(info->screen_base, 0, info->fix.smem_len);
  178. return 0;
  179. }
  180. static const struct fb_videomode *ark1668e_lcdfb_choose_mode(struct fb_var_screeninfo *var,
  181. struct fb_info *info)
  182. {
  183. struct fb_videomode varfbmode;
  184. const struct fb_videomode *fbmode = NULL;
  185. fb_var_to_videomode(&varfbmode, var);
  186. fbmode = fb_find_nearest_mode(&varfbmode, &info->modelist);
  187. if (fbmode)
  188. fb_videomode_to_var(var, fbmode);
  189. return fbmode;
  190. }
  191. /**
  192. * ark1668e_lcdfb_check_var - Validates a var passed in.
  193. * @var: frame buffer variable screen structure
  194. * @info: frame buffer structure that represents a single frame buffer
  195. *
  196. * Checks to see if the hardware supports the state requested by
  197. * var passed in. This function does not alter the hardware
  198. * state!!! This means the data stored in struct fb_info and
  199. * struct ark1668e_lcdfb_info do not change. This includes the var
  200. * inside of struct fb_info. Do NOT change these. This function
  201. * can be called on its own if we intent to only test a mode and
  202. * not actually set it. The stuff in modedb.c is a example of
  203. * this. If the var passed in is slightly off by what the
  204. * hardware can support then we alter the var PASSED in to what
  205. * we can do. If the hardware doesn't support mode change a
  206. * -EINVAL will be returned by the upper layers. You don't need
  207. * to implement this function then. If you hardware doesn't
  208. * support changing the resolution then this function is not
  209. * needed. In this case the driver would just provide a var that
  210. * represents the static state the screen is in.
  211. *
  212. * Returns negative errno on error, or zero on success.
  213. */
  214. static int ark1668e_lcdfb_check_var(struct fb_var_screeninfo *var,
  215. struct fb_info *info)
  216. {
  217. struct device *dev = info->device;
  218. /* struct ark1668e_lcdfb_info *sinfo = info->par;
  219. struct ark1668e_lcdfb_pdata *pdata = &sinfo->pdata; */
  220. dev_dbg(dev, "%s:\n", __func__);
  221. if (!(var->pixclock && var->bits_per_pixel)) {
  222. /* choose a suitable mode if possible */
  223. if (!ark1668e_lcdfb_choose_mode(var, info)) {
  224. dev_err(dev, "needed value not specified\n");
  225. return -EINVAL;
  226. }
  227. }
  228. dev_dbg(dev, " resolution: %ux%u\n", var->xres, var->yres);
  229. dev_dbg(dev, " pixclk: %lu KHz\n", PICOS2KHZ(var->pixclock));
  230. dev_dbg(dev, " bpp: %u\n", var->bits_per_pixel);
  231. /* Do not allow to have real resoulution larger than virtual */
  232. if (var->xres >= var->xres_virtual)
  233. var->xres_virtual = var->xres;
  234. if (var->yres >= var->yres_virtual)
  235. var->yres_virtual = var->yres * 2;
  236. /* Force same alignment for each line */
  237. var->xres = (var->xres + 3) & ~3UL;
  238. var->xres_virtual = (var->xres_virtual + 3) & ~3UL;
  239. var->red.msb_right = var->green.msb_right = var->blue.msb_right = 0;
  240. var->transp.msb_right = 0;
  241. var->transp.offset = var->transp.length = 0;
  242. var->xoffset = var->yoffset = 0;
  243. if (info->fix.smem_len) {
  244. unsigned int smem_len = (var->xres_virtual * var->yres_virtual
  245. * ((var->bits_per_pixel + 7) / 8));
  246. if (smem_len > info->fix.smem_len) {
  247. dev_err(dev, "Frame buffer is too small (%u) for screen size (need at least %u)\n",
  248. info->fix.smem_len, smem_len);
  249. return -EINVAL;
  250. }
  251. }
  252. /* Saturate vertical and horizontal timings at maximum values */
  253. var->vsync_len = min_t(u32, var->vsync_len,
  254. (ARK1668E_LCDC_VPW >> ARK1668E_LCDC_VPW_OFFSET) + 1);
  255. var->upper_margin = min_t(u32, var->upper_margin,
  256. ARK1668E_LCDC_VBP);
  257. var->lower_margin = min_t(u32, var->lower_margin,
  258. ARK1668E_LCDC_VFP >> ARK1668E_LCDC_VFP_OFFSET);
  259. var->right_margin = min_t(u32, var->right_margin,
  260. ARK1668E_LCDC_HFP + 1);
  261. var->hsync_len = min_t(u32, var->hsync_len,
  262. (ARK1668E_LCDC_HPW >> ARK1668E_LCDC_HPW_OFFSET) + 1);
  263. var->left_margin = min_t(u32, var->left_margin,
  264. (ARK1668E_LCDC_HBP >> ARK1668E_LCDC_HBP_OFFSET) + 1);
  265. /* Some parameters can't be zero */
  266. var->vsync_len = max_t(u32, var->vsync_len, 1);
  267. var->right_margin = max_t(u32, var->right_margin, 1);
  268. var->hsync_len = max_t(u32, var->hsync_len, 1);
  269. var->left_margin = max_t(u32, var->left_margin, 1);
  270. switch (var->bits_per_pixel) {
  271. case 1:
  272. case 2:
  273. case 4:
  274. case 8:
  275. var->red.offset = var->green.offset = var->blue.offset = 0;
  276. var->red.length = var->green.length = var->blue.length
  277. = var->bits_per_pixel;
  278. break;
  279. case 16:
  280. var->green.length = 6;
  281. var->red.offset = var->green.length + 5;
  282. var->blue.offset = 0;
  283. var->green.offset = 5;
  284. var->red.length = var->blue.length = 5;
  285. break;
  286. case 32:
  287. var->transp.offset = 24;
  288. var->transp.length = 8;
  289. /* fall through */
  290. case 24:
  291. var->red.offset = 16;
  292. var->blue.offset = 0;
  293. var->green.offset = 8;
  294. var->red.length = var->green.length = var->blue.length = 8;
  295. break;
  296. default:
  297. dev_err(dev, "color depth %d not supported\n",
  298. var->bits_per_pixel);
  299. return -EINVAL;
  300. }
  301. return 0;
  302. }
  303. /*
  304. * LCD reset sequence
  305. */
  306. /* static void ark1668e_lcdfb_reset(struct ark1668e_lcdfb_info *sinfo)
  307. {
  308. might_sleep();
  309. ark1668e_lcdfb_stop(sinfo);
  310. ark1668e_lcdfb_start(sinfo);
  311. } */
  312. static int ark1668e_lcdfb_pan_display(struct fb_var_screeninfo *var,
  313. struct fb_info *info)
  314. {
  315. struct ark1668e_lcdfb_info *sinfo = info->par;
  316. struct fb_fix_screeninfo *fix = &info->fix;
  317. unsigned long addr;
  318. addr = fix->smem_start + var->yoffset * fix->line_length
  319. + var->xoffset * info->var.bits_per_pixel / 8;
  320. lcdc_writel(sinfo, ARK1668E_LCDC_OSD2_ADDR, addr);
  321. //printk(KERN_ALERT "ark1668e_lcdfb_pan_display 0x%x.\n", addr);
  322. return 0;
  323. }
  324. /**
  325. * ark1668e_lcdfb_set_par - Alters the hardware state.
  326. * @info: frame buffer structure that represents a single frame buffer
  327. *
  328. * Using the fb_var_screeninfo in fb_info we set the resolution
  329. * of the this particular framebuffer. This function alters the
  330. * par AND the fb_fix_screeninfo stored in fb_info. It doesn't
  331. * not alter var in fb_info since we are using that data. This
  332. * means we depend on the data in var inside fb_info to be
  333. * supported by the hardware. ark1668e_lcdfb_check_var is always called
  334. * before ark1668e_lcdfb_set_par to ensure this. Again if you can't
  335. * change the resolution you don't need this function.
  336. *
  337. */
  338. static int ark1668e_lcdfb_set_par(struct fb_info *info)
  339. {
  340. //struct ark1668e_lcdfb_info *sinfo = info->par;
  341. //struct ark1668e_lcdfb_pdata *pdata = &sinfo->pdata;
  342. might_sleep();
  343. dev_dbg(info->device, "%s:\n", __func__);
  344. dev_dbg(info->device, " * DONE\n");
  345. return 0;
  346. }
  347. /* static int ark1668e_lcdfb_blank(int blank_mode, struct fb_info *info)
  348. {
  349. struct ark1668e_lcdfb_info *sinfo = info->par;
  350. switch (blank_mode) {
  351. case FB_BLANK_UNBLANK:
  352. case FB_BLANK_NORMAL:
  353. ark1668e_lcdfb_start(sinfo);
  354. break;
  355. case FB_BLANK_VSYNC_SUSPEND:
  356. case FB_BLANK_HSYNC_SUSPEND:
  357. break;
  358. case FB_BLANK_POWERDOWN:
  359. ark1668e_lcdfb_stop(sinfo);
  360. break;
  361. default:
  362. return -EINVAL;
  363. }
  364. return ((blank_mode == FB_BLANK_NORMAL) ? 1 : 0);
  365. } */
  366. static struct fb_ops ark1668e_lcdfb_ops = {
  367. .owner = THIS_MODULE,
  368. .fb_check_var = ark1668e_lcdfb_check_var,
  369. .fb_set_par = ark1668e_lcdfb_set_par,
  370. //.fb_blank = ark1668e_lcdfb_blank,
  371. .fb_pan_display = ark1668e_lcdfb_pan_display,
  372. .fb_fillrect = cfb_fillrect,
  373. .fb_copyarea = cfb_copyarea,
  374. .fb_imageblit = cfb_imageblit,
  375. .fb_ioctl = ark1668e_lcdfb_ioctl,
  376. };
  377. static irqreturn_t ark1668e_lcdfb_interrupt(int irq, void *dev_id)
  378. {
  379. struct fb_info *info = dev_id;
  380. struct ark1668e_lcdfb_info *sinfo = info->par;
  381. u32 status;
  382. int i;
  383. status = lcdc_readl(sinfo, ARK1668E_LCDC_INTERRUPT_STATUS);
  384. /* clear intr */
  385. lcdc_writel(sinfo, ARK1668E_LCDC_INTERRUPT_STATUS, 0);
  386. if (status & ARK1668E_LCDC_INT_LCD_FRAME) {
  387. for (i = 0; i < ARK1668E_LCDC_LAYER_MAX; i++) {
  388. if (sinfo->render_addr[i].yaddr) {
  389. if((i >= ARK1668E_LCDC_LAYER_OSD1) && (i <= ARK1668E_LCDC_LAYER_OSD3))
  390. ark1668e_lcdc_set_osd_addr(i, sinfo->render_addr[i].yaddr);
  391. else
  392. ark1668e_lcdc_set_video_addr(i, sinfo->render_addr[i].yaddr,
  393. sinfo->render_addr[i].cbaddr, sinfo->render_addr[i].craddr);
  394. sinfo->render_addr[i].yaddr = 0;
  395. }
  396. }
  397. sinfo->vsync_flag = 1;
  398. wake_up_interruptible(&sinfo->vsync_waitq);
  399. schedule_work(&sinfo->task);
  400. }
  401. return IRQ_HANDLED;
  402. }
  403. /*
  404. * LCD controller task (to reset the LCD)
  405. */
  406. static void ark1668e_lcdfb_task(struct work_struct *work)
  407. {
  408. /* struct ark1668e_lcdfb_info *sinfo =
  409. container_of(work, struct ark1668e_lcdfb_info, task); */
  410. #ifdef CONFIG_VIDEO_ARK1668E_VIN
  411. ark_vin_display_int_handler();
  412. #endif
  413. }
  414. static int __init ark1668e_lcdfb_init_fbinfo(struct ark1668e_lcdfb_info *sinfo)
  415. {
  416. struct fb_info *info = sinfo->info;
  417. int ret = 0;
  418. info->var.activate |= FB_ACTIVATE_FORCE | FB_ACTIVATE_NOW;
  419. dev_info(info->device,
  420. "%luKiB frame buffer at %08lx (mapped at %p)\n",
  421. (unsigned long)info->fix.smem_len / 1024,
  422. (unsigned long)info->fix.smem_start,
  423. info->screen_base);
  424. /* Allocate colormap */
  425. ret = fb_alloc_cmap(&info->cmap, 256, 0);
  426. if (ret < 0)
  427. dev_err(info->device, "Alloc color map failed\n");
  428. return ret;
  429. }
  430. /* static void ark1668e_lcdfb_start_clock(struct ark1668e_lcdfb_info *sinfo)
  431. {
  432. clk_prepare_enable(sinfo->lcdc_clk);
  433. }
  434. static void ark1668e_lcdfb_stop_clock(struct ark1668e_lcdfb_info *sinfo)
  435. {
  436. clk_disable_unprepare(sinfo->lcdc_clk);
  437. } */
  438. static const struct of_device_id ark1668e_lcdfb_dt_ids[] = {
  439. { .compatible = "arkmicro,ark1668e-lcdc",},
  440. { /* sentinel */ }
  441. };
  442. MODULE_DEVICE_TABLE(of, ark1668e_lcdfb_dt_ids);
  443. static const char *ark1668e_lcdfb_interface_types[] = {
  444. [ARK1668E_LCDC_INTERFACE_TTL] = "TTL",
  445. [ARK1668E_LCDC_INTERFACE_LVDS] = "LVDS",
  446. [ARK1668E_LCDC_INTERFACE_DUAL_LVDS] = "DLVDS",
  447. };
  448. static int ark1668e_lcdfb_get_of_interface_types(struct device_node *np)
  449. {
  450. const char *type;
  451. int err, i;
  452. err = of_property_read_string(np, "interface-type", &type);
  453. if (err < 0)
  454. return ARK1668E_LCDC_INTERFACE_TTL;
  455. for (i = 0; i < ARRAY_SIZE(ark1668e_lcdfb_interface_types); i++)
  456. if (!strcasecmp(type, ark1668e_lcdfb_interface_types[i]))
  457. return i;
  458. return -ENODEV;
  459. }
  460. static const char *ark1668e_lcdfb_wiring_modes[] = {
  461. [ARK1668E_LCDC_WIRING_BGR] = "BGR",
  462. [ARK1668E_LCDC_WIRING_GBR] = "GBR",
  463. [ARK1668E_LCDC_WIRING_RBG] = "RBG",
  464. [ARK1668E_LCDC_WIRING_BRG] = "BRG",
  465. [ARK1668E_LCDC_WIRING_GRB] = "GRB",
  466. [ARK1668E_LCDC_WIRING_RGB] = "RGB",
  467. };
  468. static int ark1668e_lcdfb_get_of_wiring_modes(struct device_node *np)
  469. {
  470. const char *mode;
  471. int err, i;
  472. err = of_property_read_string(np, "lcd-wiring-mode", &mode);
  473. if (err < 0)
  474. return ARK1668E_LCDC_WIRING_BGR;
  475. for (i = 0; i < ARRAY_SIZE(ark1668e_lcdfb_wiring_modes); i++)
  476. if (!strcasecmp(mode, ark1668e_lcdfb_wiring_modes[i]))
  477. return i;
  478. return -ENODEV;
  479. }
  480. static void ark1668e_lcdfb_power_control_gpio(struct ark1668e_lcdfb_pdata *pdata, int on)
  481. {
  482. struct ark1668e_lcdfb_power_ctrl_gpio *og;
  483. list_for_each_entry(og, &pdata->pwr_gpios, list)
  484. gpio_set_value(og->gpio, on ? !og->active_low : og->active_low);
  485. }
  486. /*
  487. * Timer function for delayed backlight power up/down
  488. */
  489. static void ark1668e_backlight_timer_func(struct timer_list *t)
  490. {
  491. struct ark1668e_lcdfb_info *sinfo = from_timer(sinfo, t, pdata.backlight_timer);
  492. struct ark1668e_lcdfb_pdata *pdata = &sinfo->pdata;
  493. ark1668e_lcdfb_power_control(sinfo, 1);
  494. //del_timer_sync(&pdata->backlight_timer);
  495. del_timer(&pdata->backlight_timer);
  496. }
  497. static int ark1668e_lcdfb_of_init(struct ark1668e_lcdfb_info *sinfo)
  498. {
  499. struct fb_info *info = sinfo->info;
  500. struct ark1668e_lcdfb_pdata *pdata = &sinfo->pdata;
  501. struct fb_var_screeninfo *var = &info->var;
  502. struct device *dev = &sinfo->pdev->dev;
  503. struct device_node *np =dev->of_node;
  504. struct device_node *display_np;
  505. struct device_node *timings_np;
  506. struct display_timings *timings;
  507. enum of_gpio_flags flags;
  508. struct ark1668e_lcdfb_power_ctrl_gpio *og;
  509. bool is_gpio_power = false;
  510. int ret = -ENOENT;
  511. int i, gpio;
  512. display_np = of_parse_phandle(np, "display", 0);
  513. if (!display_np) {
  514. dev_err(dev, "failed to find display phandle\n");
  515. return -ENOENT;
  516. }
  517. ret = of_property_read_u32(display_np, "bits-per-pixel", &var->bits_per_pixel);
  518. if (ret < 0) {
  519. dev_err(dev, "failed to get property bits-per-pixel\n");
  520. goto put_display_node;
  521. }
  522. INIT_LIST_HEAD(&pdata->pwr_gpios);
  523. ret = -ENOMEM;
  524. for (i = 0; i < of_gpio_named_count(display_np, "power-control-gpio"); i++) {
  525. gpio = of_get_named_gpio_flags(display_np, "power-control-gpio",
  526. i, &flags);
  527. if (gpio < 0)
  528. continue;
  529. og = devm_kzalloc(dev, sizeof(*og), GFP_KERNEL);
  530. if (!og)
  531. goto put_display_node;
  532. og->gpio = gpio;
  533. og->active_low = flags & OF_GPIO_ACTIVE_LOW;
  534. is_gpio_power = true;
  535. ret = devm_gpio_request(dev, gpio, "lcd-power-control-gpio");
  536. if (ret) {
  537. dev_err(dev, "request gpio %d failed\n", gpio);
  538. goto put_display_node;
  539. }
  540. ret = gpio_direction_output(gpio, og->active_low);
  541. if (ret) {
  542. dev_err(dev, "set direction output gpio %d failed\n", gpio);
  543. goto put_display_node;
  544. }
  545. list_add(&og->list, &pdata->pwr_gpios);
  546. }
  547. if (is_gpio_power)
  548. pdata->ark1668e_lcdfb_power_control = ark1668e_lcdfb_power_control_gpio;
  549. ret = ark1668e_lcdfb_get_of_interface_types(display_np);
  550. if (ret < 0) {
  551. dev_err(dev, "invalid interface-type\n");
  552. goto put_display_node;
  553. }
  554. pdata->interface_type = ret;
  555. if (pdata->interface_type == ARK1668E_LCDC_INTERFACE_LVDS) {
  556. ret = of_property_read_u32(display_np, "lvds-con", &pdata->lvds_con);
  557. if (ret < 0) {
  558. dev_err(dev, "failed to get property lvds-con\n");
  559. goto put_display_node;
  560. }
  561. ret = of_property_read_u32(display_np, "lvds-con2", &pdata->lvds_con2);
  562. if (ret < 0) {
  563. dev_err(dev, "failed to get property lvds-con2\n");
  564. goto put_display_node;
  565. }
  566. } else if (pdata->interface_type == ARK1668E_LCDC_INTERFACE_DUAL_LVDS) {
  567. ret = of_property_read_u32(display_np, "lvds-con", &pdata->lvds_con);
  568. if (ret < 0) {
  569. dev_err(dev, "failed to get property lvds-con\n");
  570. goto put_display_node;
  571. }
  572. ret = of_property_read_u32(display_np, "lvds-con2", &pdata->lvds_con2);
  573. if (ret < 0) {
  574. dev_err(dev, "failed to get property lvds-con2\n");
  575. goto put_display_node;
  576. }
  577. }
  578. ret = ark1668e_lcdfb_get_of_wiring_modes(display_np);
  579. if (ret < 0) {
  580. dev_err(dev, "invalid lcd-wiring-mode\n");
  581. goto put_display_node;
  582. }
  583. pdata->lcd_wiring_mode = ret;
  584. pdata->lcdcon_is_backlight = of_property_read_bool(display_np, "lcdcon-backlight");
  585. if (pdata->lcdcon_is_backlight) {
  586. pdata->pwm = devm_of_pwm_get(dev, display_np, NULL);
  587. if (IS_ERR(pdata->pwm) && PTR_ERR(pdata->pwm) != -EPROBE_DEFER) {
  588. dev_err(dev, "unable to request PWM\n");
  589. goto put_display_node;
  590. }
  591. ret = of_property_read_u32(display_np, "backlight-value", &pdata->backlight_value);
  592. if (ret < 0) {
  593. pdata->backlight_value = 30;
  594. }
  595. ret = of_property_read_u32(display_np, "backlight-delay", &pdata->backlight_delay);
  596. if (ret < 0) {
  597. pdata->backlight_delay = 100;
  598. }
  599. timer_setup(&pdata->backlight_timer, ark1668e_backlight_timer_func, 0);
  600. /* Deferred power up the LCDC screen */
  601. mod_timer(&pdata->backlight_timer,
  602. jiffies +
  603. msecs_to_jiffies(pdata->backlight_delay));
  604. }
  605. timings = of_get_display_timings(display_np);
  606. if (!timings) {
  607. dev_err(dev, "failed to get display timings\n");
  608. ret = -EINVAL;
  609. goto del_timer;
  610. }
  611. timings_np = of_get_child_by_name(display_np, "display-timings");
  612. if (!timings_np) {
  613. dev_err(dev, "failed to find display-timings node\n");
  614. ret = -ENODEV;
  615. goto del_timer;
  616. }
  617. for (i = 0; i < of_get_child_count(timings_np); i++) {
  618. struct videomode vm;
  619. struct fb_videomode fb_vm;
  620. ret = videomode_from_timings(timings, &vm, i);
  621. if (ret < 0)
  622. goto put_timings_node;
  623. ret = fb_videomode_from_videomode(&vm, &fb_vm);
  624. if (ret < 0)
  625. goto put_timings_node;
  626. fb_add_videomode(&fb_vm, &info->modelist);
  627. if (vm.flags & DISPLAY_FLAGS_DE_HIGH)
  628. pdata->de_active_high = true;
  629. if (vm.flags & DISPLAY_FLAGS_PIXDATA_POSEDGE)
  630. pdata->pixelclk_active_high = true;
  631. }
  632. /*
  633. * FIXME: Make sure we are not referencing any fields in display_np
  634. * and timings_np and drop our references to them before returning to
  635. * avoid leaking the nodes on probe deferral and driver unbind.
  636. */
  637. return 0;
  638. put_timings_node:
  639. of_node_put(timings_np);
  640. del_timer:
  641. if (pdata->lcdcon_is_backlight)
  642. del_timer_sync(&pdata->backlight_timer);
  643. put_display_node:
  644. of_node_put(display_np);
  645. return ret;
  646. }
  647. static int ark1668e_lcdc_dev_init(struct fb_info *info)
  648. {
  649. struct ark1668e_lcdfb_info *sinfo = info->par;
  650. struct ark1668e_lcdfb_pdata *pdata = &sinfo->pdata;
  651. unsigned long value;
  652. unsigned long bits_per_line;
  653. dev_dbg(info->device, " * resolution: %ux%u (%ux%u virtual)\n",
  654. info->var.xres, info->var.yres,
  655. info->var.xres_virtual, info->var.yres_virtual);
  656. if (info->var.bits_per_pixel == 1)
  657. info->fix.visual = FB_VISUAL_MONO01;
  658. else if (info->var.bits_per_pixel <= 8)
  659. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  660. else
  661. info->fix.visual = FB_VISUAL_TRUECOLOR;
  662. bits_per_line = info->var.xres_virtual * info->var.bits_per_pixel;
  663. info->fix.line_length = DIV_ROUND_UP(bits_per_line, 8);
  664. /* set lcd back color */
  665. lcdc_writel(sinfo, ARK1668E_LCDC_BACK_COLOR, BALCK_BACKCOLOR);
  666. /* Now, the LCDC core... */
  667. value = lcdc_readl_sys(sinfo, SYS_CLK_DELAY);
  668. if (pdata->pixelclk_active_high)
  669. value |= (1 << SYS_PIXEL_CLK_INV_OFFSET);
  670. else
  671. value &= ~(1 << SYS_PIXEL_CLK_INV_OFFSET);
  672. lcdc_writel_sys(sinfo, SYS_CLK_DELAY, value);
  673. /* Initialize control register */
  674. value = (6 << 23) | (1 << 0);
  675. /* set interrupt at the start of the front porch when vfp is not zero */
  676. if (info->var.lower_margin)
  677. value |= (3 << 21);
  678. value |= pdata->lcd_wiring_mode << 18;
  679. lcdc_writel(sinfo, ARK1668E_LCDC_CONTROL, value);
  680. /* timing */
  681. value = (info->var.hsync_len - 1) << ARK1668E_LCDC_HPW_OFFSET;
  682. value |= (info->var.left_margin - 1) << ARK1668E_LCDC_HBP_OFFSET;
  683. value |= (info->var.right_margin - 1);
  684. lcdc_writel(sinfo, ARK1668E_LCDC_TIMING0, value);
  685. value = info->var.lower_margin << ARK1668E_LCDC_VFP_OFFSET;
  686. value |= (info->var.vsync_len - 1) << ARK1668E_LCDC_VPW_OFFSET;
  687. value |= (info->var.xres - 1);
  688. lcdc_writel(sinfo, ARK1668E_LCDC_TIMING1, value);
  689. value = pdata->de_active_high << ARK1668E_LCDC_IOE_OFFSET;
  690. value |= !!(info->var.sync & FB_SYNC_HOR_HIGH_ACT) << ARK1668E_LCDC_IHS_OFFSET;
  691. value |= !!(info->var.sync & FB_SYNC_VERT_HIGH_ACT) << ARK1668E_LCDC_IVS_OFFSET;
  692. value |= (info->var.yres - 1) << ARK1668E_LCDC_LPS_OFFSET;
  693. value |= info->var.upper_margin;
  694. lcdc_writel(sinfo, ARK1668E_LCDC_TIMING2, value);
  695. /* Initialize specific screen type */
  696. if (pdata->interface_type == ARK1668E_LCDC_INTERFACE_LVDS) {
  697. lcdc_writel_sys(sinfo, SYS_CTL_2A, SWITCH_TTL_TO_LVDS);
  698. /* value = lcdc_readl_sys(sinfo, SYS_ANALOG_REG1);
  699. value |= (1 << 26);
  700. lcdc_writel_sys(sinfo, SYS_ANALOG_REG1, value);
  701. lcdc_writel_sys(sinfo, SYS_LVDS_CTRL_CFG, pdata->lvds_con); */
  702. lcdc_writel_sys(sinfo, SYS_LVDS_CTRL_CFG, pdata->lvds_con);
  703. lcdc_writel_sys(sinfo, SYS_LVDS_CTRL_CFG1, pdata->lvds_con2);
  704. } else if (pdata->interface_type == ARK1668E_LCDC_INTERFACE_DUAL_LVDS) {
  705. lcdc_writel_sys(sinfo, SYS_CTL_2A, SWITCH_TTL_TO_LVDS);
  706. lcdc_writel_sys(sinfo, SYS_LVDS_CTRL_CFG, pdata->lvds_con);
  707. lcdc_writel_sys(sinfo, SYS_LVDS_CTRL_CFG1, pdata->lvds_con2);
  708. }
  709. else if(pdata->interface_type == ARK1668E_LCDC_INTERFACE_TTL)
  710. {
  711. lcdc_writel_sys(sinfo, SYS_CTL_2A, SWITCH_LVDS_TO_TTL);
  712. }
  713. /* sync always on */
  714. lcdc_writel(sinfo, ARK1668E_LCDC_PARAMTERS_SYNC_SWITCH, 0x7f);
  715. /* Display osd layer1(fb0) size,pos,format,addr... */
  716. ark1668e_lcdfb_pan_display(&info->var, info);
  717. value = (info->var.yres << ARK1668E_LCDC_HEIGHT_OFFSET) | info->var.xres;
  718. lcdc_writel(sinfo, ARK1668E_LCDC_OSD2_SIZE, value);
  719. lcdc_writel(sinfo, ARK1668E_LCDC_OSD2_SOURCE_SIZE, value);
  720. lcdc_writel(sinfo, ARK1668E_LCDC_OSD2_POSITION, 0);
  721. lcdc_writel(sinfo, ARK1668E_LCDC_OSD2_WIN_POINT, 0);
  722. value = (1 << 17) | (ARK1668E_LCDC_FORMAT_RGBA888 << 12) | 0xff;
  723. lcdc_writel(sinfo, ARK1668E_LCDC_OSD2_CTL, value);
  724. /* open osd layer1 */
  725. value = lcdc_readl(sinfo, ARK1668E_LCDC_CONTROL);
  726. value |= (1 << ARK1668E_LCDC_OSD2_EN_OFFSET);
  727. lcdc_writel(sinfo, ARK1668E_LCDC_CONTROL, value);
  728. /* Clear all interrupts */
  729. lcdc_writel(sinfo, ARK1668E_LCDC_INTERRUPT_STATUS, 0);
  730. /* Enable frame interrupt */
  731. lcdc_writel(sinfo, ARK1668E_LCDC_INTERRUPT_CTL, ARK1668E_LCDC_INT_LCD_FRAME);
  732. /* set layer1(fb0) vp */
  733. /* set layer priority and blend mode */
  734. lcdc_writel(sinfo, ARK1668E_LCDC_BLD_MODE_LCD_REG0, 0x04030200);
  735. lcdc_writel(sinfo, ARK1668E_LCDC_BLD_MODE_LCD_REG1, 0x0003f001);
  736. ark1668e_lcdfb_start(sinfo);
  737. return 0;
  738. }
  739. static int ark1668e_lcdfb_probe(struct platform_device *pdev)
  740. {
  741. struct device *dev = &pdev->dev;
  742. struct fb_info *info;
  743. struct ark1668e_lcdfb_info *sinfo;
  744. struct ark1668e_lcdfb_pdata *pdata = NULL;
  745. struct resource *regs = NULL;
  746. struct resource *map = NULL;
  747. struct fb_modelist *modelist;
  748. int ret;
  749. dev_dbg(dev, "%s BEGIN\n", __func__);
  750. info = framebuffer_alloc(sizeof(struct ark1668e_lcdfb_info), dev);
  751. if (!info) {
  752. dev_err(dev, "cannot allocate memory\n");
  753. ret = -ENOMEM;
  754. goto out;
  755. }
  756. sinfo = info->par;
  757. sinfo->pdev = pdev;
  758. sinfo->info = info;
  759. pdata = &sinfo->pdata;
  760. INIT_LIST_HEAD(&info->modelist);
  761. ret = ark1668e_lcdfb_of_init(sinfo);
  762. if (ret)
  763. goto free_info;
  764. info->flags = ARK1668E_LCDFB_FBINFO_DEFAULT;
  765. info->fbops = &ark1668e_lcdfb_ops;
  766. info->fix = ark1668e_lcdfb_fix;
  767. strcpy(info->fix.id, sinfo->pdev->name);
  768. /* Enable LCDC Clocks */
  769. sinfo->lcdc_clk = clk_get(dev, "lcdc_clk");
  770. if (IS_ERR(sinfo->lcdc_clk)) {
  771. ret = PTR_ERR(sinfo->lcdc_clk);
  772. goto free_info;
  773. }
  774. /* ark1668e_lcdfb_start_clock(sinfo); */
  775. modelist = list_first_entry(&info->modelist,
  776. struct fb_modelist, list);
  777. fb_videomode_to_var(&info->var, &modelist->mode);
  778. /* Set pixel clock */
  779. clk_set_rate(sinfo->lcdc_clk, PICOS2KHZ(info->var.pixclock) * 1000);
  780. info->var.pixclock = KHZ2PICOS(clk_get_rate(sinfo->lcdc_clk) / 1000);
  781. ark1668e_lcdfb_check_var(&info->var, info);
  782. regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  783. if (!regs) {
  784. dev_err(dev, "resources unusable\n");
  785. ret = -ENXIO;
  786. goto stop_clk;
  787. }
  788. /* LCDC registers */
  789. info->fix.mmio_start = regs->start;
  790. info->fix.mmio_len = resource_size(regs);
  791. if (!request_mem_region(info->fix.mmio_start,
  792. info->fix.mmio_len, pdev->name)) {
  793. ret = -EBUSY;
  794. goto free_fb;
  795. }
  796. sinfo->mmio = ioremap(info->fix.mmio_start, info->fix.mmio_len);
  797. if (!sinfo->mmio) {
  798. dev_err(dev, "cannot map LCDC registers\n");
  799. ret = -ENOMEM;
  800. goto release_mem;
  801. }
  802. sinfo->sysreg = ioremap(SYS_REG_BASE, 0x400);
  803. if (!sinfo->sysreg) {
  804. dev_err(dev, "cannot map sys registers\n");
  805. ret = -ENOMEM;
  806. goto unmap_mmio;
  807. }
  808. sinfo->irq_base = platform_get_irq(pdev, 0);
  809. if (sinfo->irq_base < 0) {
  810. dev_err(dev, "unable to get irq\n");
  811. ret = sinfo->irq_base;
  812. goto stop_clk;
  813. }
  814. /* Initialize video memory */
  815. map = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  816. if (map && map->start) {
  817. /* use a pre-allocated memory buffer */
  818. info->fix.smem_start = map->start;
  819. info->fix.smem_len = resource_size(map);
  820. if (!request_mem_region(info->fix.smem_start,
  821. info->fix.smem_len, pdev->name)) {
  822. ret = -EBUSY;
  823. goto stop_clk;
  824. }
  825. info->screen_base = ioremap_wc(info->fix.smem_start,
  826. info->fix.smem_len);
  827. if (!info->screen_base) {
  828. ret = -ENOMEM;
  829. goto release_intmem;
  830. }
  831. memset(info->screen_base, 0, info->var.xres * info->var.yres * 4);
  832. /*
  833. * Don't clear the framebuffer -- someone may have set
  834. * up a splash image.
  835. */
  836. } else {
  837. if(map && !map->start) {
  838. sinfo->smem_len = resource_size(map);
  839. }
  840. /* allocate memory buffer */
  841. ret = ark1668e_lcdfb_alloc_video_memory(sinfo);
  842. if (ret < 0) {
  843. dev_err(dev, "cannot allocate framebuffer: %d\n", ret);
  844. goto stop_clk;
  845. }
  846. }
  847. /* Initialize PWM for contrast or backlight ("off") */
  848. if (pdata->lcdcon_is_backlight)
  849. init_backlight(sinfo);
  850. /* interrupt */
  851. ret = request_irq(sinfo->irq_base, ark1668e_lcdfb_interrupt, 0, pdev->name, info);
  852. if (ret) {
  853. dev_err(dev, "request_irq failed: %d\n", ret);
  854. goto unmap_sysreg;
  855. }
  856. /* Some operations on the LCDC might sleep and
  857. * require a preemptible task context */
  858. INIT_WORK(&sinfo->task, ark1668e_lcdfb_task);
  859. init_waitqueue_head(&sinfo->vsync_waitq);
  860. ret = ark1668e_lcdfb_init_fbinfo(sinfo);
  861. if (ret < 0) {
  862. dev_err(dev, "init fbinfo failed: %d\n", ret);
  863. goto unregister_irqs;
  864. }
  865. ark1668e_lcdc_funcs_init(sinfo);
  866. ret = ark1668e_lcdc_dev_init(info);
  867. if (ret < 0) {
  868. dev_err(dev, "init lcdc dev failed: %d\n", ret);
  869. goto unregister_irqs;
  870. }
  871. dev_set_drvdata(dev, info);
  872. /*
  873. * Tell the world that we're ready to go
  874. */
  875. ret = register_framebuffer(info);
  876. if (ret < 0) {
  877. dev_err(dev, "failed to register framebuffer device: %d\n", ret);
  878. goto reset_drvdata;
  879. }
  880. dev_info(dev, "fb%d: Arkmicro LCDC at 0x%08lx (mapped at %p), irq %d\n",
  881. info->node, info->fix.mmio_start, sinfo->mmio, sinfo->irq_base);
  882. #if 1////tmp test
  883. {
  884. int i;
  885. struct fb_info *info_tmp;
  886. for(i = 1; i < 5; i++){
  887. info_tmp = framebuffer_alloc(sizeof(struct fb_info), dev);
  888. if (!info_tmp) {
  889. dev_err(dev, "cannot allocate memory\n");
  890. ret = -ENOMEM;
  891. goto out;
  892. }
  893. memcpy(info_tmp, info, sizeof(struct fb_info));
  894. //strcpy(info->fix.id, "ark-fb2");
  895. register_framebuffer(info_tmp);
  896. }
  897. }
  898. #endif
  899. printk("%s success\n", __FUNCTION__);
  900. return 0;
  901. reset_drvdata:
  902. dev_set_drvdata(dev, NULL);
  903. fb_dealloc_cmap(&info->cmap);
  904. unregister_irqs:
  905. cancel_work_sync(&sinfo->task);
  906. free_irq(sinfo->irq_base, info);
  907. unmap_sysreg:
  908. iounmap(sinfo->sysreg);
  909. unmap_mmio:
  910. exit_backlight(sinfo);
  911. iounmap(sinfo->mmio);
  912. release_mem:
  913. release_mem_region(info->fix.mmio_start, info->fix.mmio_len);
  914. free_fb:
  915. if (map)
  916. iounmap(info->screen_base);
  917. else
  918. ark1668e_lcdfb_free_video_memory(sinfo);
  919. release_intmem:
  920. if (map)
  921. release_mem_region(info->fix.smem_start, info->fix.smem_len);
  922. stop_clk:
  923. /* ark1668e_lcdfb_stop_clock(sinfo); */
  924. clk_put(sinfo->lcdc_clk);
  925. free_info:
  926. framebuffer_release(info);
  927. out:
  928. dev_dbg(dev, "%s FAILED ret=%d.\n", __func__, ret);
  929. printk(KERN_ERR "***ERR: %s failed\n", __FUNCTION__);
  930. return ret;
  931. }
  932. static int __exit ark1668e_lcdfb_remove(struct platform_device *pdev)
  933. {
  934. struct device *dev = &pdev->dev;
  935. struct fb_info *info = dev_get_drvdata(dev);
  936. struct ark1668e_lcdfb_info *sinfo;
  937. struct ark1668e_lcdfb_pdata *pdata;
  938. if (!info || !info->par)
  939. return 0;
  940. sinfo = info->par;
  941. pdata = &sinfo->pdata;
  942. cancel_work_sync(&sinfo->task);
  943. exit_backlight(sinfo);
  944. ark1668e_lcdfb_power_control(sinfo, 0);
  945. unregister_framebuffer(info);
  946. /* ark1668e_lcdfb_stop_clock(sinfo); */
  947. clk_put(sinfo->lcdc_clk);
  948. fb_dealloc_cmap(&info->cmap);
  949. free_irq(sinfo->irq_base, info);
  950. iounmap(sinfo->sysreg);
  951. iounmap(sinfo->mmio);
  952. release_mem_region(info->fix.mmio_start, info->fix.mmio_len);
  953. if (platform_get_resource(pdev, IORESOURCE_MEM, 1)) {
  954. iounmap(info->screen_base);
  955. release_mem_region(info->fix.smem_start, info->fix.smem_len);
  956. } else {
  957. ark1668e_lcdfb_free_video_memory(sinfo);
  958. }
  959. framebuffer_release(info);
  960. return 0;
  961. }
  962. #ifdef CONFIG_PM
  963. static int ark1668e_lcdfb_suspend(struct platform_device *pdev, pm_message_t mesg)
  964. {
  965. return 0;
  966. }
  967. static int ark1668e_lcdfb_resume(struct platform_device *pdev)
  968. {
  969. return 0;
  970. }
  971. #else
  972. #define ark1668e_lcdfb_suspend NULL
  973. #define ark1668e_lcdfb_resume NULL
  974. #endif
  975. static struct platform_driver ark1668e_lcdfb_driver = {
  976. .probe = ark1668e_lcdfb_probe,
  977. .remove = __exit_p(ark1668e_lcdfb_remove),
  978. .suspend = ark1668e_lcdfb_suspend,
  979. .resume = ark1668e_lcdfb_resume,
  980. .driver = {
  981. .name = "ark1668e_lcdfb",
  982. .of_match_table = of_match_ptr(ark1668e_lcdfb_dt_ids),
  983. },
  984. };
  985. //module_platform_driver(ark1668e_lcdfb_driver);
  986. static int __init ark1668e_lcdfb_init(void)
  987. {
  988. int ret;
  989. ret = platform_driver_register(&ark1668e_lcdfb_driver);
  990. if (ret != 0) {
  991. printk(KERN_ERR "%s %d: failed to register ark1668e_lcdfb_driver\n",
  992. __FUNCTION__, __LINE__);
  993. }
  994. return ret;
  995. }
  996. subsys_initcall(ark1668e_lcdfb_init);
  997. MODULE_DESCRIPTION("Ark1668 LCD Controller framebuffer driver");
  998. MODULE_AUTHOR("Sim");
  999. MODULE_LICENSE("GPL v2");