ark1668_lcdfb.c 34 KB

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