ark1668e_lcdfb.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241
  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 + 64,
  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. if (pdata->fb_buffer_nums > 0)
  236. var->yres_virtual = var->yres * pdata->fb_buffer_nums;
  237. else
  238. var->yres_virtual = var->yres * 3;
  239. }
  240. /* Force same alignment for each line */
  241. var->xres = (var->xres + 3) & ~3UL;
  242. var->xres_virtual = (var->xres_virtual + 3) & ~3UL;
  243. var->red.msb_right = var->green.msb_right = var->blue.msb_right = 0;
  244. var->transp.msb_right = 0;
  245. var->transp.offset = var->transp.length = 0;
  246. var->xoffset = var->yoffset = 0;
  247. if (info->fix.smem_len) {
  248. unsigned int smem_len = (var->xres_virtual * var->yres_virtual
  249. * ((var->bits_per_pixel + 7) / 8));
  250. if (smem_len > info->fix.smem_len) {
  251. dev_err(dev, "Frame buffer is too small (%u) for screen size (need at least %u)\n",
  252. info->fix.smem_len, smem_len);
  253. return -EINVAL;
  254. }
  255. }
  256. /* Saturate vertical and horizontal timings at maximum values */
  257. var->vsync_len = min_t(u32, var->vsync_len,
  258. (ARK1668E_LCDC_VPW >> ARK1668E_LCDC_VPW_OFFSET) + 1);
  259. var->upper_margin = min_t(u32, var->upper_margin,
  260. ARK1668E_LCDC_VBP);
  261. var->lower_margin = min_t(u32, var->lower_margin,
  262. ARK1668E_LCDC_VFP >> ARK1668E_LCDC_VFP_OFFSET);
  263. var->right_margin = min_t(u32, var->right_margin,
  264. ARK1668E_LCDC_HFP + 1);
  265. var->hsync_len = min_t(u32, var->hsync_len,
  266. (ARK1668E_LCDC_HPW >> ARK1668E_LCDC_HPW_OFFSET) + 1);
  267. var->left_margin = min_t(u32, var->left_margin,
  268. (ARK1668E_LCDC_HBP >> ARK1668E_LCDC_HBP_OFFSET) + 1);
  269. /* Some parameters can't be zero */
  270. var->vsync_len = max_t(u32, var->vsync_len, 1);
  271. var->right_margin = max_t(u32, var->right_margin, 1);
  272. var->hsync_len = max_t(u32, var->hsync_len, 1);
  273. var->left_margin = max_t(u32, var->left_margin, 1);
  274. switch (var->bits_per_pixel) {
  275. case 1:
  276. case 2:
  277. case 4:
  278. case 8:
  279. var->red.offset = var->green.offset = var->blue.offset = 0;
  280. var->red.length = var->green.length = var->blue.length
  281. = var->bits_per_pixel;
  282. break;
  283. case 16:
  284. var->green.length = 6;
  285. var->red.offset = var->green.length + 5;
  286. var->blue.offset = 0;
  287. var->green.offset = 5;
  288. var->red.length = var->blue.length = 5;
  289. break;
  290. case 32:
  291. var->transp.offset = 24;
  292. var->transp.length = 8;
  293. /* fall through */
  294. case 24:
  295. var->red.offset = 16;
  296. var->blue.offset = 0;
  297. var->green.offset = 8;
  298. var->red.length = var->green.length = var->blue.length = 8;
  299. break;
  300. default:
  301. dev_err(dev, "color depth %d not supported\n",
  302. var->bits_per_pixel);
  303. return -EINVAL;
  304. }
  305. return 0;
  306. }
  307. /*
  308. * LCD reset sequence
  309. */
  310. /* static void ark1668e_lcdfb_reset(struct ark1668e_lcdfb_info *sinfo)
  311. {
  312. might_sleep();
  313. ark1668e_lcdfb_stop(sinfo);
  314. ark1668e_lcdfb_start(sinfo);
  315. } */
  316. static int ark1668e_lcdfb_pan_display(struct fb_var_screeninfo *var,
  317. struct fb_info *info)
  318. {
  319. struct ark1668e_lcdfb_info *sinfo = info->par;
  320. struct fb_fix_screeninfo *fix = &info->fix;
  321. unsigned long addr;
  322. u32 bytes_per_pixel = (var->bits_per_pixel + 7) / 8;
  323. addr = fix->smem_start + var->yoffset * fix->line_length
  324. + var->xoffset * bytes_per_pixel;
  325. if (addr == fix->smem_start + (var->yres_virtual - var->yres) * fix->line_length
  326. + var->xoffset * bytes_per_pixel) {
  327. *(volatile u32*)(info->screen_base + var->yres_virtual * fix->line_length) =
  328. *(volatile u32*)(info->screen_base + var->yres_virtual * fix->line_length - bytes_per_pixel);
  329. }
  330. sinfo->render_addr[ARK1668E_LCDC_LAYER_OSD2].yaddr = addr;
  331. //printk(KERN_ALERT "ark1668e_lcdfb_pan_display 0x%x.\n", addr);
  332. return 0;
  333. }
  334. /**
  335. * ark1668e_lcdfb_set_par - Alters the hardware state.
  336. * @info: frame buffer structure that represents a single frame buffer
  337. *
  338. * Using the fb_var_screeninfo in fb_info we set the resolution
  339. * of the this particular framebuffer. This function alters the
  340. * par AND the fb_fix_screeninfo stored in fb_info. It doesn't
  341. * not alter var in fb_info since we are using that data. This
  342. * means we depend on the data in var inside fb_info to be
  343. * supported by the hardware. ark1668e_lcdfb_check_var is always called
  344. * before ark1668e_lcdfb_set_par to ensure this. Again if you can't
  345. * change the resolution you don't need this function.
  346. *
  347. */
  348. static int ark1668e_lcdfb_set_par(struct fb_info *info)
  349. {
  350. //struct ark1668e_lcdfb_info *sinfo = info->par;
  351. //struct ark1668e_lcdfb_pdata *pdata = &sinfo->pdata;
  352. might_sleep();
  353. dev_dbg(info->device, "%s:\n", __func__);
  354. dev_dbg(info->device, " * DONE\n");
  355. return 0;
  356. }
  357. /* static int ark1668e_lcdfb_blank(int blank_mode, struct fb_info *info)
  358. {
  359. struct ark1668e_lcdfb_info *sinfo = info->par;
  360. switch (blank_mode) {
  361. case FB_BLANK_UNBLANK:
  362. case FB_BLANK_NORMAL:
  363. ark1668e_lcdfb_start(sinfo);
  364. break;
  365. case FB_BLANK_VSYNC_SUSPEND:
  366. case FB_BLANK_HSYNC_SUSPEND:
  367. break;
  368. case FB_BLANK_POWERDOWN:
  369. ark1668e_lcdfb_stop(sinfo);
  370. break;
  371. default:
  372. return -EINVAL;
  373. }
  374. return ((blank_mode == FB_BLANK_NORMAL) ? 1 : 0);
  375. } */
  376. static struct fb_ops ark1668e_lcdfb_ops = {
  377. .owner = THIS_MODULE,
  378. .fb_check_var = ark1668e_lcdfb_check_var,
  379. .fb_set_par = ark1668e_lcdfb_set_par,
  380. //.fb_blank = ark1668e_lcdfb_blank,
  381. .fb_pan_display = ark1668e_lcdfb_pan_display,
  382. .fb_fillrect = cfb_fillrect,
  383. .fb_copyarea = cfb_copyarea,
  384. .fb_imageblit = cfb_imageblit,
  385. .fb_ioctl = ark1668e_lcdfb_ioctl,
  386. };
  387. static irqreturn_t ark1668e_lcdfb_interrupt(int irq, void *dev_id)
  388. {
  389. struct fb_info *info = dev_id;
  390. struct ark1668e_lcdfb_info *sinfo = info->par;
  391. u32 status;
  392. int i;
  393. status = lcdc_readl(sinfo, ARK1668E_LCDC_INTERRUPT_STATUS);
  394. /* clear intr */
  395. lcdc_writel(sinfo, ARK1668E_LCDC_INTERRUPT_STATUS, 0);
  396. if (status & ARK1668E_LCDC_INT_LCD_FRAME) {
  397. for (i = 0; i < ARK1668E_LCDC_LAYER_MAX; i++) {
  398. if (sinfo->render_addr[i].yaddr) {
  399. if((i >= ARK1668E_LCDC_LAYER_OSD1) && (i <= ARK1668E_LCDC_LAYER_OSD3))
  400. ark1668e_lcdc_set_osd_addr(i, sinfo->render_addr[i].yaddr);
  401. else
  402. ark1668e_lcdc_set_video_addr(i, sinfo->render_addr[i].yaddr,
  403. sinfo->render_addr[i].cbaddr, sinfo->render_addr[i].craddr);
  404. sinfo->render_addr[i].yaddr = 0;
  405. }
  406. }
  407. if(sinfo->atomic_flag)
  408. ark1668e_lcdc_display_update_atomic(sinfo);
  409. sinfo->vsync_flag = 1;
  410. wake_up_interruptible(&sinfo->vsync_waitq);
  411. schedule_work(&sinfo->task);
  412. }
  413. return IRQ_HANDLED;
  414. }
  415. /*
  416. * LCD controller task (to reset the LCD)
  417. */
  418. static void ark1668e_lcdfb_task(struct work_struct *work)
  419. {
  420. /* struct ark1668e_lcdfb_info *sinfo =
  421. container_of(work, struct ark1668e_lcdfb_info, task); */
  422. #ifdef CONFIG_VIDEO_ARK1668E_VIN
  423. ark_vin_display_int_handler();
  424. #endif
  425. }
  426. static int __init ark1668e_lcdfb_init_fbinfo(struct ark1668e_lcdfb_info *sinfo)
  427. {
  428. struct fb_info *info = sinfo->info;
  429. int ret = 0;
  430. info->var.activate |= FB_ACTIVATE_FORCE | FB_ACTIVATE_NOW;
  431. dev_info(info->device,
  432. "%luKiB frame buffer at %08lx (mapped at %p)\n",
  433. (unsigned long)info->fix.smem_len / 1024,
  434. (unsigned long)info->fix.smem_start,
  435. info->screen_base);
  436. /* Allocate colormap */
  437. ret = fb_alloc_cmap(&info->cmap, 256, 0);
  438. if (ret < 0)
  439. dev_err(info->device, "Alloc color map failed\n");
  440. return ret;
  441. }
  442. /* static void ark1668e_lcdfb_start_clock(struct ark1668e_lcdfb_info *sinfo)
  443. {
  444. clk_prepare_enable(sinfo->lcdc_clk);
  445. }
  446. static void ark1668e_lcdfb_stop_clock(struct ark1668e_lcdfb_info *sinfo)
  447. {
  448. clk_disable_unprepare(sinfo->lcdc_clk);
  449. } */
  450. static const struct of_device_id ark1668e_lcdfb_dt_ids[] = {
  451. { .compatible = "arkmicro,ark1668e-lcdc",},
  452. { /* sentinel */ }
  453. };
  454. MODULE_DEVICE_TABLE(of, ark1668e_lcdfb_dt_ids);
  455. static const char *ark1668e_lcdfb_interface_types[] = {
  456. [ARK1668E_LCDC_INTERFACE_TTL] = "TTL",
  457. [ARK1668E_LCDC_INTERFACE_LVDS] = "LVDS",
  458. [ARK1668E_LCDC_INTERFACE_DUAL_LVDS] = "DLVDS",
  459. };
  460. static int ark1668e_lcdfb_get_of_interface_types(struct device_node *np)
  461. {
  462. const char *type;
  463. int err, i;
  464. err = of_property_read_string(np, "interface-type", &type);
  465. if (err < 0)
  466. return ARK1668E_LCDC_INTERFACE_TTL;
  467. for (i = 0; i < ARRAY_SIZE(ark1668e_lcdfb_interface_types); i++)
  468. if (!strcasecmp(type, ark1668e_lcdfb_interface_types[i]))
  469. return i;
  470. return -ENODEV;
  471. }
  472. static const char *ark1668e_lcdfb_wiring_modes[] = {
  473. [ARK1668E_LCDC_WIRING_BGR] = "BGR",
  474. [ARK1668E_LCDC_WIRING_GBR] = "GBR",
  475. [ARK1668E_LCDC_WIRING_RBG] = "RBG",
  476. [ARK1668E_LCDC_WIRING_BRG] = "BRG",
  477. [ARK1668E_LCDC_WIRING_GRB] = "GRB",
  478. [ARK1668E_LCDC_WIRING_RGB] = "RGB",
  479. };
  480. static int ark1668e_lcdfb_get_of_wiring_modes(struct device_node *np)
  481. {
  482. const char *mode;
  483. int err, i;
  484. err = of_property_read_string(np, "lcd-wiring-mode", &mode);
  485. if (err < 0)
  486. return ARK1668E_LCDC_WIRING_BGR;
  487. for (i = 0; i < ARRAY_SIZE(ark1668e_lcdfb_wiring_modes); i++)
  488. if (!strcasecmp(mode, ark1668e_lcdfb_wiring_modes[i]))
  489. return i;
  490. return -ENODEV;
  491. }
  492. static void ark1668e_lcdfb_power_control_gpio(struct ark1668e_lcdfb_pdata *pdata, int on)
  493. {
  494. struct ark1668e_lcdfb_power_ctrl_gpio *og;
  495. list_for_each_entry(og, &pdata->pwr_gpios, list)
  496. gpio_set_value(og->gpio, on ? !og->active_low : og->active_low);
  497. }
  498. /*
  499. * Timer function for delayed backlight power up/down
  500. */
  501. static void ark1668e_backlight_timer_func(struct timer_list *t)
  502. {
  503. struct ark1668e_lcdfb_info *sinfo = from_timer(sinfo, t, pdata.backlight_timer);
  504. struct ark1668e_lcdfb_pdata *pdata = &sinfo->pdata;
  505. ark1668e_lcdfb_power_control(sinfo, 1);
  506. //del_timer_sync(&pdata->backlight_timer);
  507. del_timer(&pdata->backlight_timer);
  508. }
  509. static int ark1668e_lcdfb_of_init(struct ark1668e_lcdfb_info *sinfo)
  510. {
  511. struct fb_info *info = sinfo->info;
  512. struct ark1668e_lcdfb_pdata *pdata = &sinfo->pdata;
  513. struct fb_var_screeninfo *var = &info->var;
  514. struct device *dev = &sinfo->pdev->dev;
  515. struct device_node *np =dev->of_node;
  516. struct device_node *display_np;
  517. struct device_node *timings_np;
  518. struct display_timings *timings;
  519. enum of_gpio_flags flags;
  520. struct ark1668e_lcdfb_power_ctrl_gpio *og;
  521. bool is_gpio_power = false;
  522. int ret = -ENOENT;
  523. int i, gpio;
  524. display_np = of_parse_phandle(np, "display", 0);
  525. if (!display_np) {
  526. dev_err(dev, "failed to find display phandle\n");
  527. return -ENOENT;
  528. }
  529. ret = of_property_read_u32(display_np, "bits-per-pixel", &var->bits_per_pixel);
  530. if (ret < 0) {
  531. dev_err(dev, "failed to get property bits-per-pixel\n");
  532. goto put_display_node;
  533. }
  534. ret = of_property_read_u32(display_np, "fb-buffer-nums", &pdata->fb_buffer_nums);
  535. INIT_LIST_HEAD(&pdata->pwr_gpios);
  536. ret = -ENOMEM;
  537. for (i = 0; i < of_gpio_named_count(display_np, "power-control-gpio"); i++) {
  538. gpio = of_get_named_gpio_flags(display_np, "power-control-gpio",
  539. i, &flags);
  540. if (gpio < 0)
  541. continue;
  542. og = devm_kzalloc(dev, sizeof(*og), GFP_KERNEL);
  543. if (!og)
  544. goto put_display_node;
  545. og->gpio = gpio;
  546. og->active_low = flags & OF_GPIO_ACTIVE_LOW;
  547. is_gpio_power = true;
  548. ret = devm_gpio_request(dev, gpio, "lcd-power-control-gpio");
  549. if (ret) {
  550. dev_err(dev, "request gpio %d failed\n", gpio);
  551. goto put_display_node;
  552. }
  553. ret = gpio_direction_output(gpio, og->active_low);
  554. if (ret) {
  555. dev_err(dev, "set direction output gpio %d failed\n", gpio);
  556. goto put_display_node;
  557. }
  558. list_add(&og->list, &pdata->pwr_gpios);
  559. }
  560. if (is_gpio_power)
  561. pdata->ark1668e_lcdfb_power_control = ark1668e_lcdfb_power_control_gpio;
  562. ret = ark1668e_lcdfb_get_of_interface_types(display_np);
  563. if (ret < 0) {
  564. dev_err(dev, "invalid interface-type\n");
  565. goto put_display_node;
  566. }
  567. pdata->interface_type = ret;
  568. if (pdata->interface_type == ARK1668E_LCDC_INTERFACE_LVDS) {
  569. ret = of_property_read_u32(display_np, "lvds-con", &pdata->lvds_con);
  570. if (ret < 0) {
  571. dev_err(dev, "failed to get property lvds-con\n");
  572. goto put_display_node;
  573. }
  574. ret = of_property_read_u32(display_np, "lvds-con2", &pdata->lvds_con2);
  575. if (ret < 0) {
  576. dev_err(dev, "failed to get property lvds-con2\n");
  577. goto put_display_node;
  578. }
  579. } else if (pdata->interface_type == ARK1668E_LCDC_INTERFACE_DUAL_LVDS) {
  580. ret = of_property_read_u32(display_np, "lvds-con", &pdata->lvds_con);
  581. if (ret < 0) {
  582. dev_err(dev, "failed to get property lvds-con\n");
  583. goto put_display_node;
  584. }
  585. ret = of_property_read_u32(display_np, "lvds-con2", &pdata->lvds_con2);
  586. if (ret < 0) {
  587. dev_err(dev, "failed to get property lvds-con2\n");
  588. goto put_display_node;
  589. }
  590. }
  591. ret = ark1668e_lcdfb_get_of_wiring_modes(display_np);
  592. if (ret < 0) {
  593. dev_err(dev, "invalid lcd-wiring-mode\n");
  594. goto put_display_node;
  595. }
  596. pdata->lcd_wiring_mode = ret;
  597. pdata->lcdcon_is_backlight = of_property_read_bool(display_np, "lcdcon-backlight");
  598. if (pdata->lcdcon_is_backlight) {
  599. pdata->pwm = devm_of_pwm_get(dev, display_np, NULL);
  600. if (IS_ERR(pdata->pwm) && PTR_ERR(pdata->pwm) != -EPROBE_DEFER) {
  601. dev_err(dev, "unable to request PWM\n");
  602. goto put_display_node;
  603. }
  604. ret = of_property_read_u32(display_np, "backlight-value", &pdata->backlight_value);
  605. if (ret < 0) {
  606. pdata->backlight_value = 30;
  607. }
  608. ret = of_property_read_u32(display_np, "backlight-delay", &pdata->backlight_delay);
  609. if (ret < 0) {
  610. pdata->backlight_delay = 100;
  611. }
  612. timer_setup(&pdata->backlight_timer, ark1668e_backlight_timer_func, 0);
  613. /* Deferred power up the LCDC screen */
  614. mod_timer(&pdata->backlight_timer,
  615. jiffies +
  616. msecs_to_jiffies(pdata->backlight_delay));
  617. }
  618. timings = of_get_display_timings(display_np);
  619. if (!timings) {
  620. dev_err(dev, "failed to get display timings\n");
  621. ret = -EINVAL;
  622. goto del_timer;
  623. }
  624. timings_np = of_get_child_by_name(display_np, "display-timings");
  625. if (!timings_np) {
  626. dev_err(dev, "failed to find display-timings node\n");
  627. ret = -ENODEV;
  628. goto del_timer;
  629. }
  630. for (i = 0; i < of_get_child_count(timings_np); i++) {
  631. struct videomode vm;
  632. struct fb_videomode fb_vm;
  633. ret = videomode_from_timings(timings, &vm, i);
  634. if (ret < 0)
  635. goto put_timings_node;
  636. ret = fb_videomode_from_videomode(&vm, &fb_vm);
  637. if (ret < 0)
  638. goto put_timings_node;
  639. fb_add_videomode(&fb_vm, &info->modelist);
  640. if (vm.flags & DISPLAY_FLAGS_DE_HIGH)
  641. pdata->de_active_high = true;
  642. if (vm.flags & DISPLAY_FLAGS_PIXDATA_POSEDGE)
  643. pdata->pixelclk_active_high = true;
  644. }
  645. /*
  646. * FIXME: Make sure we are not referencing any fields in display_np
  647. * and timings_np and drop our references to them before returning to
  648. * avoid leaking the nodes on probe deferral and driver unbind.
  649. */
  650. return 0;
  651. put_timings_node:
  652. of_node_put(timings_np);
  653. del_timer:
  654. if (pdata->lcdcon_is_backlight)
  655. del_timer_sync(&pdata->backlight_timer);
  656. put_display_node:
  657. of_node_put(display_np);
  658. return ret;
  659. }
  660. static int ark1668e_lcdc_dev_init(struct fb_info *info)
  661. {
  662. struct ark1668e_lcdfb_info *sinfo = info->par;
  663. struct ark1668e_lcdfb_pdata *pdata = &sinfo->pdata;
  664. unsigned long value;
  665. unsigned long bits_per_line;
  666. dev_dbg(info->device, " * resolution: %ux%u (%ux%u virtual)\n",
  667. info->var.xres, info->var.yres,
  668. info->var.xres_virtual, info->var.yres_virtual);
  669. if (info->var.bits_per_pixel == 1)
  670. info->fix.visual = FB_VISUAL_MONO01;
  671. else if (info->var.bits_per_pixel <= 8)
  672. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  673. else
  674. info->fix.visual = FB_VISUAL_TRUECOLOR;
  675. bits_per_line = info->var.xres_virtual * info->var.bits_per_pixel;
  676. info->fix.line_length = DIV_ROUND_UP(bits_per_line, 8);
  677. /* set lcd back color */
  678. lcdc_writel(sinfo, ARK1668E_LCDC_BACK_COLOR, BALCK_BACKCOLOR);
  679. /* Now, the LCDC core... */
  680. value = lcdc_readl_sys(sinfo, SYS_CLK_DELAY);
  681. if (pdata->pixelclk_active_high)
  682. value |= (1 << SYS_PIXEL_CLK_INV_OFFSET);
  683. else
  684. value &= ~(1 << SYS_PIXEL_CLK_INV_OFFSET);
  685. lcdc_writel_sys(sinfo, SYS_CLK_DELAY, value);
  686. /* Initialize control register */
  687. value = (6 << 23) | (1 << 0);
  688. /* set interrupt at the start of the front porch when vfp is not zero */
  689. if (info->var.lower_margin)
  690. value |= (3 << 21);
  691. value |= pdata->lcd_wiring_mode << 18;
  692. lcdc_writel(sinfo, ARK1668E_LCDC_CONTROL, value);
  693. /* timing */
  694. value = (info->var.hsync_len - 1) << ARK1668E_LCDC_HPW_OFFSET;
  695. value |= (info->var.left_margin - 1) << ARK1668E_LCDC_HBP_OFFSET;
  696. value |= (info->var.right_margin - 1);
  697. lcdc_writel(sinfo, ARK1668E_LCDC_TIMING0, value);
  698. value = info->var.lower_margin << ARK1668E_LCDC_VFP_OFFSET;
  699. value |= (info->var.vsync_len - 1) << ARK1668E_LCDC_VPW_OFFSET;
  700. value |= (info->var.xres - 1);
  701. lcdc_writel(sinfo, ARK1668E_LCDC_TIMING1, value);
  702. value = pdata->de_active_high << ARK1668E_LCDC_IOE_OFFSET;
  703. value |= !!(info->var.sync & FB_SYNC_HOR_HIGH_ACT) << ARK1668E_LCDC_IHS_OFFSET;
  704. value |= !!(info->var.sync & FB_SYNC_VERT_HIGH_ACT) << ARK1668E_LCDC_IVS_OFFSET;
  705. value |= (info->var.yres - 1) << ARK1668E_LCDC_LPS_OFFSET;
  706. value |= info->var.upper_margin;
  707. lcdc_writel(sinfo, ARK1668E_LCDC_TIMING2, value);
  708. /* Initialize specific screen type */
  709. if (pdata->interface_type == ARK1668E_LCDC_INTERFACE_LVDS) {
  710. lcdc_writel_sys(sinfo, SYS_CTL_2A, SWITCH_TTL_TO_LVDS);
  711. /* value = lcdc_readl_sys(sinfo, SYS_ANALOG_REG1);
  712. value |= (1 << 26);
  713. lcdc_writel_sys(sinfo, SYS_ANALOG_REG1, value);
  714. lcdc_writel_sys(sinfo, SYS_LVDS_CTRL_CFG, pdata->lvds_con); */
  715. lcdc_writel_sys(sinfo, SYS_LVDS_CTRL_CFG, pdata->lvds_con);
  716. lcdc_writel_sys(sinfo, SYS_LVDS_CTRL_CFG1, pdata->lvds_con2);
  717. } else if (pdata->interface_type == ARK1668E_LCDC_INTERFACE_DUAL_LVDS) {
  718. lcdc_writel_sys(sinfo, SYS_CTL_2A, SWITCH_TTL_TO_LVDS);
  719. lcdc_writel_sys(sinfo, SYS_LVDS_CTRL_CFG, pdata->lvds_con);
  720. lcdc_writel_sys(sinfo, SYS_LVDS_CTRL_CFG1, pdata->lvds_con2);
  721. }
  722. else if(pdata->interface_type == ARK1668E_LCDC_INTERFACE_TTL)
  723. {
  724. lcdc_writel_sys(sinfo, SYS_CTL_2A, SWITCH_LVDS_TO_TTL);
  725. }
  726. /* sync always on */
  727. lcdc_writel(sinfo, ARK1668E_LCDC_PARAMTERS_SYNC_SWITCH, 0x7f);
  728. /* Display osd layer1(fb0) size,pos,format,addr... */
  729. ark1668e_lcdfb_pan_display(&info->var, info);
  730. value = (info->var.yres << ARK1668E_LCDC_HEIGHT_OFFSET) | info->var.xres;
  731. lcdc_writel(sinfo, ARK1668E_LCDC_OSD2_SIZE, value);
  732. lcdc_writel(sinfo, ARK1668E_LCDC_OSD2_SOURCE_SIZE, value);
  733. lcdc_writel(sinfo, ARK1668E_LCDC_OSD2_POSITION, 0);
  734. lcdc_writel(sinfo, ARK1668E_LCDC_OSD2_WIN_POINT, 0);
  735. value = (1 << 17) | (ARK1668E_LCDC_FORMAT_RGBA888 << 12) | 0xff;
  736. lcdc_writel(sinfo, ARK1668E_LCDC_OSD2_CTL, value);
  737. /* open osd layer1 */
  738. value = lcdc_readl(sinfo, ARK1668E_LCDC_CONTROL);
  739. value |= (1 << ARK1668E_LCDC_OSD2_EN_OFFSET);
  740. lcdc_writel(sinfo, ARK1668E_LCDC_CONTROL, value);
  741. /* Clear all interrupts */
  742. lcdc_writel(sinfo, ARK1668E_LCDC_INTERRUPT_STATUS, 0);
  743. /* Enable frame interrupt */
  744. lcdc_writel(sinfo, ARK1668E_LCDC_INTERRUPT_CTL, ARK1668E_LCDC_INT_LCD_FRAME);
  745. /* set layer1(fb0) vp */
  746. lcdc_writel(sinfo, ARK1668E_LCDC_BLD_MODE_LCD_REG0, 0x00040301);
  747. lcdc_writel(sinfo, ARK1668E_LCDC_BLD_MODE_LCD_REG1, 0x0003f002);
  748. pdata->osd3_buffer_virtaddr= dma_alloc_wc(info->dev, 4,(dma_addr_t *)&pdata->osd3_buffer_phyaddr, GFP_KERNEL);
  749. if (!pdata->osd3_buffer_virtaddr){
  750. printk(KERN_ALERT "%s dma_alloc_wc fail\n", __func__);
  751. }
  752. //*osd3_buffer_virtaddr = 0x0;
  753. *pdata->osd3_buffer_virtaddr = 0x0;
  754. /* Display osd layer3(fb0) size,pos,format,addr... */
  755. ark1668e_lcdfb_pan_display(&info->var, info);
  756. value = (1 << ARK1668E_LCDC_HEIGHT_OFFSET) | 1;
  757. lcdc_writel(sinfo, ARK1668E_LCDC_OSD3_SIZE, value);
  758. lcdc_writel(sinfo, ARK1668E_LCDC_OSD3_SOURCE_SIZE, value);
  759. lcdc_writel(sinfo, ARK1668E_LCDC_OSD3_POSITION, 0);
  760. lcdc_writel(sinfo, ARK1668E_LCDC_OSD3_WIN_POINT, 0);
  761. value = (1 << 17) | (ARK1668E_LCDC_FORMAT_RGBA888 << 12) | 0xff;
  762. lcdc_writel(sinfo, ARK1668E_LCDC_OSD3_CTL, value);
  763. lcdc_writel(sinfo, ARK1668E_LCDC_OSD3_ADDR, pdata->osd3_buffer_phyaddr);
  764. /* open osd layer3 */
  765. value = lcdc_readl(sinfo, ARK1668E_LCDC_CONTROL);
  766. value |= (1 << ARK1668E_LCDC_OSD3_EN_OFFSET);
  767. lcdc_writel(sinfo, ARK1668E_LCDC_CONTROL, value);
  768. ark1668e_lcdfb_start(sinfo);
  769. return 0;
  770. }
  771. static int ark1668e_lcdfb_probe(struct platform_device *pdev)
  772. {
  773. struct device *dev = &pdev->dev;
  774. struct fb_info *info;
  775. struct ark1668e_lcdfb_info *sinfo;
  776. struct ark1668e_lcdfb_pdata *pdata = NULL;
  777. struct resource *regs = NULL;
  778. struct resource *map = NULL;
  779. struct fb_modelist *modelist;
  780. int ret;
  781. dev_dbg(dev, "%s BEGIN\n", __func__);
  782. info = framebuffer_alloc(sizeof(struct ark1668e_lcdfb_info), dev);
  783. if (!info) {
  784. dev_err(dev, "cannot allocate memory\n");
  785. ret = -ENOMEM;
  786. goto out;
  787. }
  788. sinfo = info->par;
  789. sinfo->pdev = pdev;
  790. sinfo->info = info;
  791. pdata = &sinfo->pdata;
  792. INIT_LIST_HEAD(&info->modelist);
  793. ret = ark1668e_lcdfb_of_init(sinfo);
  794. if (ret)
  795. goto free_info;
  796. info->flags = ARK1668E_LCDFB_FBINFO_DEFAULT;
  797. info->fbops = &ark1668e_lcdfb_ops;
  798. info->fix = ark1668e_lcdfb_fix;
  799. strcpy(info->fix.id, sinfo->pdev->name);
  800. /* Enable LCDC Clocks */
  801. sinfo->lcdc_clk = clk_get(dev, "lcdc_clk");
  802. if (IS_ERR(sinfo->lcdc_clk)) {
  803. ret = PTR_ERR(sinfo->lcdc_clk);
  804. goto free_info;
  805. }
  806. /* ark1668e_lcdfb_start_clock(sinfo); */
  807. modelist = list_first_entry(&info->modelist,
  808. struct fb_modelist, list);
  809. fb_videomode_to_var(&info->var, &modelist->mode);
  810. /* Set pixel clock */
  811. clk_set_rate(sinfo->lcdc_clk, PICOS2KHZ(info->var.pixclock) * 1000);
  812. info->var.pixclock = KHZ2PICOS(clk_get_rate(sinfo->lcdc_clk) / 1000);
  813. ark1668e_lcdfb_check_var(&info->var, info);
  814. regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  815. if (!regs) {
  816. dev_err(dev, "resources unusable\n");
  817. ret = -ENXIO;
  818. goto stop_clk;
  819. }
  820. /* LCDC registers */
  821. info->fix.mmio_start = regs->start;
  822. info->fix.mmio_len = resource_size(regs);
  823. if (!request_mem_region(info->fix.mmio_start,
  824. info->fix.mmio_len, pdev->name)) {
  825. ret = -EBUSY;
  826. goto free_fb;
  827. }
  828. sinfo->mmio = ioremap(info->fix.mmio_start, info->fix.mmio_len);
  829. if (!sinfo->mmio) {
  830. dev_err(dev, "cannot map LCDC registers\n");
  831. ret = -ENOMEM;
  832. goto release_mem;
  833. }
  834. sinfo->sysreg = ioremap(SYS_REG_BASE, 0x400);
  835. if (!sinfo->sysreg) {
  836. dev_err(dev, "cannot map sys registers\n");
  837. ret = -ENOMEM;
  838. goto unmap_mmio;
  839. }
  840. sinfo->irq_base = platform_get_irq(pdev, 0);
  841. if (sinfo->irq_base < 0) {
  842. dev_err(dev, "unable to get irq\n");
  843. ret = sinfo->irq_base;
  844. goto stop_clk;
  845. }
  846. /* Initialize video memory */
  847. map = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  848. if (map && map->start) {
  849. /* use a pre-allocated memory buffer */
  850. info->fix.smem_start = map->start;
  851. info->fix.smem_len = resource_size(map);
  852. if (!request_mem_region(info->fix.smem_start,
  853. info->fix.smem_len, pdev->name)) {
  854. ret = -EBUSY;
  855. goto stop_clk;
  856. }
  857. info->screen_base = ioremap_wc(info->fix.smem_start,
  858. info->fix.smem_len);
  859. if (!info->screen_base) {
  860. ret = -ENOMEM;
  861. goto release_intmem;
  862. }
  863. memset(info->screen_base, 0, info->var.xres * info->var.yres * 4);
  864. /*
  865. * Don't clear the framebuffer -- someone may have set
  866. * up a splash image.
  867. */
  868. } else {
  869. if(map && !map->start) {
  870. sinfo->smem_len = resource_size(map);
  871. }
  872. /* allocate memory buffer */
  873. ret = ark1668e_lcdfb_alloc_video_memory(sinfo);
  874. if (ret < 0) {
  875. dev_err(dev, "cannot allocate framebuffer: %d\n", ret);
  876. goto stop_clk;
  877. }
  878. }
  879. /* Initialize PWM for contrast or backlight ("off") */
  880. if (pdata->lcdcon_is_backlight)
  881. init_backlight(sinfo);
  882. /* interrupt */
  883. ret = request_irq(sinfo->irq_base, ark1668e_lcdfb_interrupt, 0, pdev->name, info);
  884. if (ret) {
  885. dev_err(dev, "request_irq failed: %d\n", ret);
  886. goto unmap_sysreg;
  887. }
  888. /* Some operations on the LCDC might sleep and
  889. * require a preemptible task context */
  890. INIT_WORK(&sinfo->task, ark1668e_lcdfb_task);
  891. init_waitqueue_head(&sinfo->vsync_waitq);
  892. ret = ark1668e_lcdfb_init_fbinfo(sinfo);
  893. if (ret < 0) {
  894. dev_err(dev, "init fbinfo failed: %d\n", ret);
  895. goto unregister_irqs;
  896. }
  897. ark1668e_lcdc_funcs_init(sinfo);
  898. ret = ark1668e_lcdc_dev_init(info);
  899. if (ret < 0) {
  900. dev_err(dev, "init lcdc dev failed: %d\n", ret);
  901. goto unregister_irqs;
  902. }
  903. dev_set_drvdata(dev, info);
  904. /*
  905. * Tell the world that we're ready to go
  906. */
  907. ret = register_framebuffer(info);
  908. if (ret < 0) {
  909. dev_err(dev, "failed to register framebuffer device: %d\n", ret);
  910. goto reset_drvdata;
  911. }
  912. dev_info(dev, "fb%d: Arkmicro LCDC at 0x%08lx (mapped at %p), irq %d\n",
  913. info->node, info->fix.mmio_start, sinfo->mmio, sinfo->irq_base);
  914. #if 1////tmp test
  915. {
  916. int i;
  917. struct fb_info *info_tmp;
  918. for(i = 1; i < 5; i++){
  919. info_tmp = framebuffer_alloc(sizeof(struct fb_info), dev);
  920. if (!info_tmp) {
  921. dev_err(dev, "cannot allocate memory\n");
  922. ret = -ENOMEM;
  923. goto out;
  924. }
  925. memcpy(info_tmp, info, sizeof(struct fb_info));
  926. //strcpy(info->fix.id, "ark-fb2");
  927. register_framebuffer(info_tmp);
  928. }
  929. }
  930. #endif
  931. printk("%s success\n", __FUNCTION__);
  932. return 0;
  933. reset_drvdata:
  934. dev_set_drvdata(dev, NULL);
  935. fb_dealloc_cmap(&info->cmap);
  936. unregister_irqs:
  937. cancel_work_sync(&sinfo->task);
  938. free_irq(sinfo->irq_base, info);
  939. unmap_sysreg:
  940. iounmap(sinfo->sysreg);
  941. unmap_mmio:
  942. exit_backlight(sinfo);
  943. iounmap(sinfo->mmio);
  944. release_mem:
  945. release_mem_region(info->fix.mmio_start, info->fix.mmio_len);
  946. free_fb:
  947. if (map)
  948. iounmap(info->screen_base);
  949. else
  950. ark1668e_lcdfb_free_video_memory(sinfo);
  951. release_intmem:
  952. if (map)
  953. release_mem_region(info->fix.smem_start, info->fix.smem_len);
  954. stop_clk:
  955. /* ark1668e_lcdfb_stop_clock(sinfo); */
  956. clk_put(sinfo->lcdc_clk);
  957. free_info:
  958. framebuffer_release(info);
  959. out:
  960. dev_dbg(dev, "%s FAILED ret=%d.\n", __func__, ret);
  961. printk(KERN_ERR "***ERR: %s failed\n", __FUNCTION__);
  962. return ret;
  963. }
  964. static int __exit ark1668e_lcdfb_remove(struct platform_device *pdev)
  965. {
  966. struct device *dev = &pdev->dev;
  967. struct fb_info *info = dev_get_drvdata(dev);
  968. struct ark1668e_lcdfb_info *sinfo;
  969. struct ark1668e_lcdfb_pdata *pdata;
  970. if (!info || !info->par)
  971. return 0;
  972. sinfo = info->par;
  973. pdata = &sinfo->pdata;
  974. cancel_work_sync(&sinfo->task);
  975. exit_backlight(sinfo);
  976. ark1668e_lcdfb_power_control(sinfo, 0);
  977. unregister_framebuffer(info);
  978. /* ark1668e_lcdfb_stop_clock(sinfo); */
  979. clk_put(sinfo->lcdc_clk);
  980. fb_dealloc_cmap(&info->cmap);
  981. free_irq(sinfo->irq_base, info);
  982. iounmap(sinfo->sysreg);
  983. iounmap(sinfo->mmio);
  984. release_mem_region(info->fix.mmio_start, info->fix.mmio_len);
  985. if (platform_get_resource(pdev, IORESOURCE_MEM, 1)) {
  986. iounmap(info->screen_base);
  987. release_mem_region(info->fix.smem_start, info->fix.smem_len);
  988. } else {
  989. ark1668e_lcdfb_free_video_memory(sinfo);
  990. }
  991. if(pdata->osd3_buffer_virtaddr)
  992. dma_free_wc(dev, 4,pdata->osd3_buffer_virtaddr,pdata->osd3_buffer_phyaddr);
  993. framebuffer_release(info);
  994. return 0;
  995. }
  996. #ifdef CONFIG_PM
  997. static int ark1668e_lcdfb_suspend(struct platform_device *pdev, pm_message_t mesg)
  998. {
  999. return 0;
  1000. }
  1001. static int ark1668e_lcdfb_resume(struct platform_device *pdev)
  1002. {
  1003. return 0;
  1004. }
  1005. #else
  1006. #define ark1668e_lcdfb_suspend NULL
  1007. #define ark1668e_lcdfb_resume NULL
  1008. #endif
  1009. static struct platform_driver ark1668e_lcdfb_driver = {
  1010. .probe = ark1668e_lcdfb_probe,
  1011. .remove = __exit_p(ark1668e_lcdfb_remove),
  1012. .suspend = ark1668e_lcdfb_suspend,
  1013. .resume = ark1668e_lcdfb_resume,
  1014. .driver = {
  1015. .name = "ark1668e_lcdfb",
  1016. .of_match_table = of_match_ptr(ark1668e_lcdfb_dt_ids),
  1017. },
  1018. };
  1019. //module_platform_driver(ark1668e_lcdfb_driver);
  1020. static int __init ark1668e_lcdfb_init(void)
  1021. {
  1022. int ret;
  1023. ret = platform_driver_register(&ark1668e_lcdfb_driver);
  1024. if (ret != 0) {
  1025. printk(KERN_ERR "%s %d: failed to register ark1668e_lcdfb_driver\n",
  1026. __FUNCTION__, __LINE__);
  1027. }
  1028. return ret;
  1029. }
  1030. subsys_initcall(ark1668e_lcdfb_init);
  1031. MODULE_DESCRIPTION("Ark1668 LCD Controller framebuffer driver");
  1032. MODULE_AUTHOR("Sim");
  1033. MODULE_LICENSE("GPL v2");