arkn141_lcdfb.c 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769
  1. /*
  2. * Arkmicro arkn141 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 "arkn141_lcdc.h"
  24. #define BACKLIGHT_PWM_PERIOD 50000
  25. #define BACKLIGHT_MAX_BRIGHTNESS 100
  26. #define SYS_REG_BASE 0x40408000
  27. #define SYS_LCD_CLK_CFG 0x54
  28. #define SYS_PIXEL_CLK_INV_OFFSET 8
  29. struct arkn141_lcdfb_power_ctrl_gpio {
  30. int gpio;
  31. int active_low;
  32. struct list_head list;
  33. };
  34. #define lcdc_readl(sinfo, reg) __raw_readl((sinfo)->mmio+(reg))
  35. #define lcdc_writel(sinfo, reg, val) __raw_writel((val), (sinfo)->mmio+(reg))
  36. #define lcdc_readl_sys(sinfo, reg) __raw_readl((sinfo)->sysreg+(reg))
  37. #define lcdc_writel_sys(sinfo, reg, val) __raw_writel((val), (sinfo)->sysreg+(reg))
  38. #define ARKN141_LCDFB_FBINFO_DEFAULT (FBINFO_DEFAULT \
  39. | FBINFO_HWACCEL_NONE)
  40. static int arkn141_set_backlight(struct arkn141_lcdfb_pdata *pdata,
  41. int brightness)
  42. {
  43. int duty = brightness * BACKLIGHT_PWM_PERIOD / BACKLIGHT_MAX_BRIGHTNESS;
  44. pwm_enable(pdata->pwm);
  45. pwm_config(pdata->pwm, duty, BACKLIGHT_PWM_PERIOD);
  46. pdata->backlight_value = brightness;
  47. return 0;
  48. }
  49. /* some bl->props field just changed */
  50. static int arkn141_bl_update_status(struct backlight_device *bl)
  51. {
  52. struct arkn141_lcdfb_info *sinfo = bl_get_data(bl);
  53. struct arkn141_lcdfb_pdata *pdata = &sinfo->pdata;
  54. int power = sinfo->bl_power;
  55. int brightness = bl->props.brightness;
  56. /* REVISIT there may be a meaningful difference between
  57. * fb_blank and power ... there seem to be some cases
  58. * this doesn't handle correctly.
  59. */
  60. if (bl->props.fb_blank != sinfo->bl_power)
  61. power = bl->props.fb_blank;
  62. else if (bl->props.power != sinfo->bl_power)
  63. power = bl->props.power;
  64. if (brightness < 0 && power == FB_BLANK_UNBLANK)
  65. brightness = pdata->backlight_value;
  66. else if (power != FB_BLANK_UNBLANK)
  67. brightness = 0;
  68. arkn141_set_backlight(pdata, brightness);
  69. bl->props.fb_blank = bl->props.power = sinfo->bl_power = power;
  70. return 0;
  71. }
  72. static int arkn141_bl_get_brightness(struct backlight_device *bl)
  73. {
  74. struct arkn141_lcdfb_info *sinfo = bl_get_data(bl);
  75. struct arkn141_lcdfb_pdata *pdata = &sinfo->pdata;
  76. return pdata->backlight_value;
  77. }
  78. static const struct backlight_ops arkn141_lcdc_bl_ops = {
  79. .update_status = arkn141_bl_update_status,
  80. .get_brightness = arkn141_bl_get_brightness,
  81. };
  82. static void init_backlight(struct arkn141_lcdfb_info *sinfo)
  83. {
  84. struct arkn141_lcdfb_pdata *pdata = &sinfo->pdata;
  85. struct backlight_properties props;
  86. struct backlight_device *bl;
  87. sinfo->bl_power = FB_BLANK_UNBLANK;
  88. if (sinfo->backlight)
  89. return;
  90. memset(&props, 0, sizeof(struct backlight_properties));
  91. props.type = BACKLIGHT_RAW;
  92. props.max_brightness = BACKLIGHT_MAX_BRIGHTNESS;
  93. bl = backlight_device_register("backlight", &sinfo->pdev->dev, sinfo,
  94. &arkn141_lcdc_bl_ops, &props);
  95. if (IS_ERR(bl)) {
  96. dev_err(&sinfo->pdev->dev, "error %ld on backlight register\n",
  97. PTR_ERR(bl));
  98. return;
  99. }
  100. sinfo->backlight = bl;
  101. bl->props.power = FB_BLANK_UNBLANK;
  102. bl->props.fb_blank = FB_BLANK_UNBLANK;
  103. bl->props.brightness = arkn141_bl_get_brightness(bl);
  104. arkn141_set_backlight(pdata, pdata->backlight_value);
  105. }
  106. static void exit_backlight(struct arkn141_lcdfb_info *sinfo)
  107. {
  108. if (!sinfo->backlight)
  109. return;
  110. if (sinfo->backlight->ops) {
  111. sinfo->backlight->props.power = FB_BLANK_POWERDOWN;
  112. sinfo->backlight->ops->update_status(sinfo->backlight);
  113. }
  114. backlight_device_unregister(sinfo->backlight);
  115. }
  116. static inline void arkn141_lcdfb_power_control(struct arkn141_lcdfb_info *sinfo, int on)
  117. {
  118. struct arkn141_lcdfb_pdata *pdata = &sinfo->pdata;
  119. if (pdata->arkn141_lcdfb_power_control)
  120. pdata->arkn141_lcdfb_power_control(pdata, on);
  121. }
  122. static const struct fb_fix_screeninfo arkn141_lcdfb_fix __initconst = {
  123. .type = FB_TYPE_PACKED_PIXELS,
  124. .visual = FB_VISUAL_TRUECOLOR,
  125. .xpanstep = 0,
  126. .ypanstep = 1,
  127. .ywrapstep = 0,
  128. .accel = FB_ACCEL_NONE,
  129. };
  130. /* static void arkn141_lcdfb_stop(struct arkn141_lcdfb_info *sinfo)
  131. {
  132. lcdc_writel(sinfo, ARKN141_LCDC_PARAM0, 0);
  133. } */
  134. static void arkn141_lcdfb_start(struct arkn141_lcdfb_info *sinfo)
  135. {
  136. lcdc_writel(sinfo, ARKN141_LCDC_PARAM0, lcdc_readl(sinfo, ARKN141_LCDC_PARAM0) | 1);
  137. }
  138. static inline void arkn141_lcdfb_free_video_memory(struct arkn141_lcdfb_info *sinfo)
  139. {
  140. struct fb_info *info = sinfo->info;
  141. dma_free_wc(info->device, info->fix.smem_len, info->screen_base,
  142. info->fix.smem_start);
  143. }
  144. /**
  145. * arkn141_lcdfb_alloc_video_memory - Allocate framebuffer memory
  146. * @sinfo: the frame buffer to allocate memory for
  147. *
  148. * This function is called only from the arkn141_lcdfb_probe()
  149. * so no locking by fb_info->mm_lock around smem_len setting is needed.
  150. */
  151. static int arkn141_lcdfb_alloc_video_memory(struct arkn141_lcdfb_info *sinfo)
  152. {
  153. struct fb_info *info = sinfo->info;
  154. struct fb_var_screeninfo *var = &info->var;
  155. unsigned int smem_len;
  156. smem_len = (var->xres_virtual * var->yres_virtual
  157. * ((var->bits_per_pixel + 7) / 8));
  158. info->fix.smem_len = max(smem_len, sinfo->smem_len);
  159. info->screen_base = dma_alloc_wc(info->device, info->fix.smem_len,
  160. (dma_addr_t *)&info->fix.smem_start,
  161. GFP_KERNEL);
  162. if (!info->screen_base) {
  163. return -ENOMEM;
  164. }
  165. memset(info->screen_base, 0, info->fix.smem_len);
  166. return 0;
  167. }
  168. static const struct fb_videomode *arkn141_lcdfb_choose_mode(struct fb_var_screeninfo *var,
  169. struct fb_info *info)
  170. {
  171. struct fb_videomode varfbmode;
  172. const struct fb_videomode *fbmode = NULL;
  173. fb_var_to_videomode(&varfbmode, var);
  174. fbmode = fb_find_nearest_mode(&varfbmode, &info->modelist);
  175. if (fbmode)
  176. fb_videomode_to_var(var, fbmode);
  177. return fbmode;
  178. }
  179. /**
  180. * arkn141_lcdfb_check_var - Validates a var passed in.
  181. * @var: frame buffer variable screen structure
  182. * @info: frame buffer structure that represents a single frame buffer
  183. *
  184. * Checks to see if the hardware supports the state requested by
  185. * var passed in. This function does not alter the hardware
  186. * state!!! This means the data stored in struct fb_info and
  187. * struct arkn141_lcdfb_info do not change. This includes the var
  188. * inside of struct fb_info. Do NOT change these. This function
  189. * can be called on its own if we intent to only test a mode and
  190. * not actually set it. The stuff in modedb.c is a example of
  191. * this. If the var passed in is slightly off by what the
  192. * hardware can support then we alter the var PASSED in to what
  193. * we can do. If the hardware doesn't support mode change a
  194. * -EINVAL will be returned by the upper layers. You don't need
  195. * to implement this function then. If you hardware doesn't
  196. * support changing the resolution then this function is not
  197. * needed. In this case the driver would just provide a var that
  198. * represents the static state the screen is in.
  199. *
  200. * Returns negative errno on error, or zero on success.
  201. */
  202. static int arkn141_lcdfb_check_var(struct fb_var_screeninfo *var,
  203. struct fb_info *info)
  204. {
  205. struct device *dev = info->device;
  206. struct arkn141_lcdfb_info *sinfo = info->par;
  207. struct arkn141_lcdfb_pdata *pdata = &sinfo->pdata;
  208. unsigned long clk_value_khz;
  209. if(pdata->lcd_clk_freq_autoupdate) {
  210. if(var->pixclock != info->var.pixclock)
  211. clk_set_rate(sinfo->lcdc_clk, PICOS2KHZ(var->pixclock) * 1000);
  212. }
  213. clk_value_khz = clk_get_rate(sinfo->lcdc_clk) / 1000;
  214. //printk("### %s clk:%ldKHZ, pixclock:%ldKHZ\n", __FUNCTION__, clk_value_khz, PICOS2KHZ(var->pixclock));
  215. dev_dbg(dev, "%s:\n", __func__);
  216. if (!(var->pixclock && var->bits_per_pixel)) {
  217. /* choose a suitable mode if possible */
  218. if (!arkn141_lcdfb_choose_mode(var, info)) {
  219. dev_err(dev, "needed value not specified\n");
  220. return -EINVAL;
  221. }
  222. }
  223. dev_dbg(dev, " resolution: %ux%u\n", var->xres, var->yres);
  224. dev_dbg(dev, " pixclk: %lu KHz\n", PICOS2KHZ(var->pixclock));
  225. dev_dbg(dev, " bpp: %u\n", var->bits_per_pixel);
  226. dev_dbg(dev, " clk: %lu KHz\n", clk_value_khz);
  227. /* Do not allow to have real resoulution larger than virtual */
  228. if (var->xres > var->xres_virtual)
  229. var->xres_virtual = var->xres;
  230. if (var->yres > var->yres_virtual)
  231. var->yres_virtual = var->yres * 2;
  232. /* Force same alignment for each line */
  233. var->xres = (var->xres + 3) & ~3UL;
  234. var->xres_virtual = (var->xres_virtual + 3) & ~3UL;
  235. var->red.msb_right = var->green.msb_right = var->blue.msb_right = 0;
  236. var->transp.msb_right = 0;
  237. var->transp.offset = var->transp.length = 0;
  238. var->xoffset = var->yoffset = 0;
  239. if (info->fix.smem_len) {
  240. unsigned int smem_len = (var->xres_virtual * var->yres_virtual
  241. * ((var->bits_per_pixel + 7) / 8));
  242. if (smem_len > info->fix.smem_len) {
  243. dev_err(dev, "Frame buffer is too small (%u) for screen size (need at least %u)\n",
  244. info->fix.smem_len, smem_len);
  245. return -EINVAL;
  246. }
  247. }
  248. /* Saturate vertical and horizontal timings at maximum values */
  249. var->vsync_len = min_t(u32, var->vsync_len, 1024);
  250. var->upper_margin = min_t(u32, var->upper_margin, 1024);
  251. var->lower_margin = min_t(u32, var->lower_margin, 1024);
  252. var->right_margin = min_t(u32, var->right_margin, 1024);
  253. var->hsync_len = min_t(u32, var->hsync_len, 1024);
  254. var->left_margin = min_t(u32, var->left_margin, 1024);
  255. /* Some parameters can't be zero */
  256. var->vsync_len = max_t(u32, var->vsync_len, 1);
  257. var->right_margin = max_t(u32, var->right_margin, 1);
  258. var->hsync_len = max_t(u32, var->hsync_len, 1);
  259. var->left_margin = max_t(u32, var->left_margin, 1);
  260. switch (var->bits_per_pixel) {
  261. case 1:
  262. case 2:
  263. case 4:
  264. case 8:
  265. var->red.offset = var->green.offset = var->blue.offset = 0;
  266. var->red.length = var->green.length = var->blue.length
  267. = var->bits_per_pixel;
  268. break;
  269. case 16:
  270. var->green.length = 6;
  271. var->red.offset = var->green.length + 5;
  272. var->blue.offset = 0;
  273. var->green.offset = 5;
  274. var->red.length = var->blue.length = 5;
  275. break;
  276. case 32:
  277. var->transp.offset = 24;
  278. var->transp.length = 8;
  279. /* fall through */
  280. case 24:
  281. var->red.offset = 16;
  282. var->blue.offset = 0;
  283. var->green.offset = 8;
  284. var->red.length = var->green.length = var->blue.length = 8;
  285. break;
  286. default:
  287. dev_err(dev, "color depth %d not supported\n",
  288. var->bits_per_pixel);
  289. return -EINVAL;
  290. }
  291. return 0;
  292. }
  293. /*
  294. * LCD reset sequence
  295. */
  296. /* static void arkn141_lcdfb_reset(struct arkn141_lcdfb_info *sinfo)
  297. {
  298. might_sleep();
  299. arkn141_lcdfb_stop(sinfo);
  300. arkn141_lcdfb_start(sinfo);
  301. } */
  302. static int arkn141_lcdfb_pan_display(struct fb_var_screeninfo *var,
  303. struct fb_info *info)
  304. {
  305. struct arkn141_lcdfb_info *sinfo = info->par;
  306. struct fb_fix_screeninfo *fix = &info->fix;
  307. unsigned long addr;
  308. addr = fix->smem_start + var->yoffset * fix->line_length
  309. + var->xoffset * info->var.bits_per_pixel / 8;
  310. lcdc_writel(sinfo, ARKN141_LCDC_OSD1_PARAM2, addr);
  311. lcdc_writel(sinfo, ARKN141_LCDC_OSD_COEF_SYNC,
  312. lcdc_readl(sinfo, ARKN141_LCDC_OSD_COEF_SYNC) | (1 << 1));
  313. return 0;
  314. }
  315. static int arkn141_lcd_itu601_init(struct fb_info *info)
  316. {
  317. struct arkn141_lcdfb_info *sinfo = info->par;
  318. struct arkn141_lcdfb_pdata *pdata = &sinfo->pdata;
  319. unsigned long value;
  320. unsigned int direct_enable = 0;
  321. unsigned int mem_lcd_enable = 0;
  322. unsigned int range_coeff_y = 0;
  323. unsigned int range_coeff_uv = 0;
  324. unsigned int dac_for_video = 0;
  325. unsigned int lcd_done_intr_enable = 1; //ʹ\C4\DC\D6ж\CF=1 \BD\FBֹ\D6ж\CF=0 lcd_done_intr
  326. unsigned int dac_for_cvbs = 0;
  327. unsigned int lcd_interlace_flag = 0;
  328. unsigned int screen_type = 2; //pRGB_i 0 pRGB_p 1 sRGB_p 2 ITU656 3
  329. unsigned int VSW1_enable = 0;
  330. unsigned int LcdVComp = 0;
  331. unsigned int itu_pal_ntsc = 0;
  332. //unsigned int hsync_ivs = 0;
  333. //unsigned int vsync_ivs = 0;
  334. unsigned int lcd_ac_ivs = 0;
  335. unsigned int test_on_flag = 0;
  336. unsigned int back_color = 0;//(137<<16)|(143<<8)|(105); //(200<<16)|(100<<8)|(16)
  337. unsigned int cpu_screen_csn_bit = 0;
  338. unsigned int cpu_screen_wen_bit = 9;
  339. unsigned int stop_lcd = 0;
  340. // ITU656ʱ\D0\F2\C9\FA\B3ɼĴ\E6\C6\F7
  341. unsigned int sav_pos = 556;
  342. unsigned int f1_vblk_start = 5;
  343. unsigned int f1_vblk_end = 45;
  344. unsigned int f2_vblk_start = 5; //pal 315 ntsc 265
  345. unsigned int f2_vblk_end = 45;
  346. unsigned int f2_start = 313;
  347. unsigned int f2_end = 625;
  348. unsigned int binary_thres = 128;
  349. unsigned int binary_big = 240;
  350. unsigned int binary_small = 16;
  351. value =
  352. (info->var.xres << 1) |
  353. (pdata->lcd_wiring_mode << 13) |
  354. (direct_enable << 16) |
  355. (mem_lcd_enable << 17) |
  356. (range_coeff_y << 18) |
  357. (range_coeff_uv << 22) |
  358. (lcd_done_intr_enable << 26) |
  359. (dac_for_video << 27) |
  360. (dac_for_cvbs << 28) |
  361. (1<<30) |
  362. (stop_lcd<<31);
  363. lcdc_writel(sinfo, ARKN141_LCDC_PARAM0, value);
  364. value =
  365. (lcd_interlace_flag << 0) |
  366. //(pdata->interface_type << 1) |
  367. (screen_type << 1) |
  368. (VSW1_enable << 13) |
  369. (LcdVComp << 14) |
  370. (itu_pal_ntsc << 15) |
  371. (!!(info->var.sync & FB_SYNC_HOR_HIGH_ACT) << 17) |
  372. (!!(info->var.sync & FB_SYNC_VERT_HIGH_ACT) << 18) |
  373. (lcd_ac_ivs << 19) |
  374. (0 << 20) |
  375. (1 << 21) |
  376. (1 << 22) | //itu656_out_sel(0:normal itur=656; 1: prograssive itu656)
  377. (1 << 23) |
  378. (test_on_flag << 31);
  379. lcdc_writel(sinfo, ARKN141_LCDC_PARAM1, value);
  380. value =
  381. (back_color << 0) |
  382. (cpu_screen_csn_bit << 24) |
  383. (cpu_screen_wen_bit << 28);
  384. lcdc_writel(sinfo, ARKN141_LCDC_PARAM2, value);
  385. /* Initialize color convert table */
  386. value = 66 | (129 << 9) | (25 << 18);
  387. lcdc_writel(sinfo, ARKN141_LCDC_PARAM12, value);
  388. value = 38 | (74 << 9) | (112 << 18);
  389. lcdc_writel(sinfo, ARKN141_LCDC_PARAM13, value);
  390. value = 112 | (94 << 9) | (18 << 18);
  391. lcdc_writel(sinfo, ARKN141_LCDC_PARAM14, value);
  392. value = 298 | (0 << 9) | (409 << 18);
  393. lcdc_writel(sinfo, ARKN141_LCDC_PARAM15, value);
  394. value = 299 | (100 << 9) | (208 << 18);
  395. lcdc_writel(sinfo, ARKN141_LCDC_PARAM16, value);
  396. value = 298 | (517 << 9) | (0 << 19);
  397. lcdc_writel(sinfo, ARKN141_LCDC_PARAM17, value);
  398. value = (sav_pos << 0);
  399. lcdc_writel(sinfo, ARKN141_LCDC_PARAM18, value);
  400. value = (f1_vblk_start << 0) | (f1_vblk_end << 12);
  401. lcdc_writel(sinfo, ARKN141_LCDC_PARAM19, value);
  402. value = (f2_vblk_start << 0) | (f2_vblk_end << 12);
  403. lcdc_writel(sinfo, ARKN141_LCDC_PARAM20, value);
  404. value = (f2_start << 0) | (f2_end << 12);
  405. lcdc_writel(sinfo, ARKN141_LCDC_PARAM21, value);
  406. value = (binary_thres << 16) | (binary_big << 8) | (binary_small << 0);
  407. lcdc_writel(sinfo, ARKN141_LCDC_PARAM22, value);
  408. /* timing */
  409. #if 0
  410. value = info->var.hsync_len + info->var.left_margin + info->var.right_margin;
  411. value = ((value + info->var.xres) << 12) | value;
  412. lcdc_writel(sinfo, ARKN141_LCDC_PARAM3, value);
  413. value = info->var.vsync_len + info->var.lower_margin + info->var.upper_margin;
  414. value = ((value + info->var.yres) << 12) | value;
  415. lcdc_writel(sinfo, ARKN141_LCDC_PARAM4, value);
  416. lcdc_writel(sinfo, ARKN141_LCDC_PARAM5, value);
  417. #else
  418. value = info->var.hsync_len + info->var.left_margin + info->var.right_margin - 5;
  419. value = ((value + info->var.xres) << 12) | value;
  420. lcdc_writel(sinfo, ARKN141_LCDC_PARAM3, value);
  421. value = info->var.vsync_len + info->var.lower_margin + info->var.upper_margin - 1;
  422. value = ((value + info->var.yres) << 12) | value;
  423. lcdc_writel(sinfo, ARKN141_LCDC_PARAM4, value);
  424. lcdc_writel(sinfo, ARKN141_LCDC_PARAM5, value);
  425. #endif
  426. value = ((info->var.vsync_len + info->var.lower_margin + info->var.upper_margin + info->var.yres) << 12) |
  427. (info->var.hsync_len + info->var.left_margin + info->var.right_margin + info->var.xres);
  428. lcdc_writel(sinfo, ARKN141_LCDC_PARAM6, value);
  429. value = ((info->var.hsync_len + info->var.right_margin) << 12) | info->var.right_margin;
  430. lcdc_writel(sinfo, ARKN141_LCDC_PARAM7, value);
  431. value = ((info->var.vsync_len + info->var.lower_margin) << 12) | info->var.lower_margin;
  432. lcdc_writel(sinfo, ARKN141_LCDC_PARAM8, value);
  433. lcdc_writel(sinfo, ARKN141_LCDC_PARAM10, value);
  434. lcdc_writel(sinfo, ARKN141_LCDC_PARAM9, value);
  435. lcdc_writel(sinfo, ARKN141_LCDC_PARAM11, value);
  436. value = lcdc_readl(sinfo, ARKN141_LCDC_OSD_012_PARAM);
  437. value |= (1<<12); //osd0: 1:y_uv420 mode, UV store togeter.
  438. lcdc_writel(sinfo, ARKN141_LCDC_OSD_012_PARAM, value);
  439. /* */
  440. value = (0 << 11) // Srgb_disable
  441. // 1: srgb output disable, 0 is output
  442. // 0: srgb output enable.
  443. | (1 << 10) // srgb_yuv_sel
  444. // 1: yuv data is select;
  445. // 0: rgb data is select.
  446. | (2 << 0) // Srgb_mode
  447. // 00: through mode, R G B R G B\A1\AD
  448. // 01: sRGB dummy, R G B 0 R G B 0\A1\AD
  449. // 10: sYUV422, Cb Y Cr Y Cb Y Cr Y\A1\AD
  450. // 11: 0 is output
  451. | (3 << 2)
  452. | (3 << 5)
  453. | (0 << 25)
  454. ;
  455. lcdc_writel(sinfo, ARKN141_LCDC_SRGB_CFG, value);
  456. lcdc_writel(sinfo, ARKN141_LCDC_VP_RGB2YCBCR_COEF0, 0x10650242);
  457. lcdc_writel(sinfo, ARKN141_LCDC_VP_RGB2YCBCR_COEF1, 0x01c09426);
  458. lcdc_writel(sinfo, ARKN141_LCDC_VP_RGB2YCBCR_COEF2, 0x0048bc70);
  459. lcdc_writel(sinfo, ARKN141_LCDC_VP_CONTROL, (0xF|(64 << 8))); // VDE
  460. lcdc_writel(sinfo, ARKN141_LCDC_VP_ADJUSTEMENT, 0x00308080); // ȱʡֵ
  461. /* Initialize dithing */
  462. value = (1 << 7) | (1 << 15) | (5 << 24);
  463. lcdc_writel(sinfo, ARKN141_LCDC_DITHING, value);
  464. /* osd0 used for video display layer */
  465. value = (1 << 0) | (ARKN141_LCDC_FORMAT_YUV420 <<3) | (info->var.xres << 6) | (info->var.yres <<18) | (1 <<31);
  466. lcdc_writel(sinfo, ARKN141_LCDC_OSD0_PARAM0, value);
  467. value = (63 << 24) | info->var.xres;
  468. lcdc_writel(sinfo, ARKN141_LCDC_OSD0_PARAM5, value);
  469. //value = lcdc_readl(sinfo, ARKN141_LCDC_OSD0_PARAM1);
  470. //value &= ~0xffffff;
  471. value = (255<<24);
  472. lcdc_writel(sinfo, ARKN141_LCDC_OSD0_PARAM1, value);
  473. /* enable/disable osd layer0 */
  474. value = lcdc_readl(sinfo, ARKN141_LCDC_OSD0_PARAM0);
  475. value |= (0 << 1); //0:disable, 1:enable
  476. lcdc_writel(sinfo, ARKN141_LCDC_OSD0_PARAM0, value);
  477. /* sync osd layer0 param */
  478. value = lcdc_readl(sinfo, ARKN141_LCDC_OSD_COEF_SYNC);
  479. value |= (1 << 0);
  480. lcdc_writel(sinfo, ARKN141_LCDC_OSD_COEF_SYNC, value);
  481. return 0;
  482. }
  483. static int arkn141_lcd_srgb_init(struct fb_info *info)
  484. {
  485. struct arkn141_lcdfb_info *sinfo = info->par;
  486. struct arkn141_lcdfb_pdata *pdata = &sinfo->pdata;
  487. unsigned long value;
  488. unsigned int direct_enable = 0;
  489. unsigned int mem_lcd_enable = 0;
  490. unsigned int range_coeff_y = 0;
  491. unsigned int range_coeff_uv = 0;
  492. unsigned int dac_for_video = 0;
  493. unsigned int lcd_done_intr_enable = 1; //ʹ\C4\DC\D6ж\CF=1 \BD\FBֹ\D6ж\CF=0 lcd_done_intr
  494. unsigned int dac_for_cvbs = 0;
  495. unsigned int lcd_interlace_flag = 0;
  496. unsigned int screen_type = 2; //pRGB_i 0 pRGB_p 1 sRGB_p 2 ITU656 3
  497. unsigned int VSW1_enable = 0;
  498. unsigned int LcdVComp = 0;
  499. unsigned int itu_pal_ntsc = 0;
  500. unsigned int hsync_ivs = 1;
  501. unsigned int vsync_ivs = 1;
  502. unsigned int lcd_ac_ivs = 0;
  503. unsigned int test_on_flag = 0;
  504. unsigned int back_color = (0x22<<16)|(0x44<<8)|(0x88);
  505. unsigned int cpu_screen_csn_bit = 0;
  506. unsigned int cpu_screen_wen_bit = 9;
  507. unsigned int stop_lcd = 0;
  508. #if 0
  509. // ITU656ʱ\D0\F2\C9\FA\B3ɼĴ\E6\C6\F7
  510. unsigned int sav_pos = 288;
  511. unsigned int f1_vblk_start = 624;
  512. unsigned int f1_vblk_end = 23;
  513. unsigned int f2_vblk_start = 311; //pal 315 ntsc 265
  514. unsigned int f2_vblk_end = 336;
  515. unsigned int f2_start = 313;
  516. unsigned int f2_end = 625;
  517. unsigned int binary_thres = 128;
  518. unsigned int binary_big = 240;
  519. unsigned int binary_small = 16;
  520. #endif
  521. value =
  522. (info->var.xres << 1) |
  523. (pdata->lcd_wiring_mode << 13) |
  524. (direct_enable << 16) |
  525. (mem_lcd_enable << 17) |
  526. (range_coeff_y << 18) |
  527. (range_coeff_uv << 22) |
  528. (lcd_done_intr_enable << 26) |
  529. (dac_for_video << 27) |
  530. (dac_for_cvbs << 28) |
  531. (1<<30) |
  532. (stop_lcd<<31);
  533. lcdc_writel(sinfo, ARKN141_LCDC_PARAM0, value);
  534. value =
  535. (lcd_interlace_flag << 0) |
  536. (screen_type << 1) |
  537. (VSW1_enable << 13) |
  538. (LcdVComp << 14) |
  539. (itu_pal_ntsc << 15) |
  540. (hsync_ivs << 17) |
  541. (vsync_ivs << 18) |
  542. (lcd_ac_ivs << 19) |
  543. (1 << 21) |
  544. (1 << 23) |
  545. (test_on_flag << 31);
  546. lcdc_writel(sinfo, ARKN141_LCDC_PARAM1, value);
  547. value =
  548. (back_color << 0) |
  549. (cpu_screen_csn_bit << 24) |
  550. (cpu_screen_wen_bit << 28);
  551. lcdc_writel(sinfo, ARKN141_LCDC_PARAM2, value);
  552. /* Initialize color convert table */
  553. value = 66 | (129 << 9) | (25 << 18);
  554. lcdc_writel(sinfo, ARKN141_LCDC_PARAM12, value);
  555. value = 38 | (74 << 9) | (112 << 18);
  556. lcdc_writel(sinfo, ARKN141_LCDC_PARAM13, value);
  557. value = 112 | (94 << 9) | (18 << 18);
  558. lcdc_writel(sinfo, ARKN141_LCDC_PARAM14, value);
  559. value = 256 | (0 << 9) | (394 << 18);
  560. lcdc_writel(sinfo, ARKN141_LCDC_PARAM15, value);
  561. value = 256 | (47 << 9) | (118 << 18);
  562. lcdc_writel(sinfo, ARKN141_LCDC_PARAM16, value);
  563. value = 256 | (465 << 9) | (0 << 19);
  564. lcdc_writel(sinfo, ARKN141_LCDC_PARAM17, value);
  565. #if 0
  566. value = (sav_pos << 0);
  567. lcdc_writel(sinfo, ARKN141_LCDC_PARAM18, value);
  568. value = (f1_vblk_start << 0) | (f1_vblk_end << 12);
  569. lcdc_writel(sinfo, ARKN141_LCDC_PARAM19, value);
  570. value = (f2_vblk_start << 0) | (f2_vblk_end << 12);
  571. lcdc_writel(sinfo, ARKN141_LCDC_PARAM20, value);
  572. value = (f2_start << 0) | (f2_end << 12);
  573. lcdc_writel(sinfo, ARKN141_LCDC_PARAM21, value);
  574. value = (binary_thres << 16) | (binary_big << 8) | (binary_small << 0);
  575. lcdc_writel(sinfo, ARKN141_LCDC_PARAM22, value);
  576. #endif
  577. /* timing */
  578. value = info->var.hsync_len + info->var.left_margin + info->var.right_margin;
  579. value = ((value + info->var.xres) << 12) | value;
  580. lcdc_writel(sinfo, ARKN141_LCDC_PARAM3, value);
  581. value = info->var.vsync_len + info->var.lower_margin + info->var.upper_margin;
  582. value = ((value + info->var.yres) << 12) | value;
  583. lcdc_writel(sinfo, ARKN141_LCDC_PARAM4, value);
  584. lcdc_writel(sinfo, ARKN141_LCDC_PARAM5, value);
  585. value = ((info->var.vsync_len + info->var.lower_margin + info->var.upper_margin + info->var.yres) << 12) |
  586. (info->var.hsync_len + info->var.left_margin + info->var.right_margin + info->var.xres);
  587. lcdc_writel(sinfo, ARKN141_LCDC_PARAM6, value);
  588. value = ((info->var.hsync_len + info->var.right_margin) << 12) | info->var.right_margin;
  589. lcdc_writel(sinfo, ARKN141_LCDC_PARAM7, value);
  590. lcdc_writel(sinfo, ARKN141_LCDC_PARAM9, value);
  591. lcdc_writel(sinfo, ARKN141_LCDC_PARAM11, value);
  592. value = ((info->var.vsync_len + info->var.lower_margin) << 12) | info->var.lower_margin;
  593. lcdc_writel(sinfo, ARKN141_LCDC_PARAM8, value);
  594. lcdc_writel(sinfo, ARKN141_LCDC_PARAM10, value);
  595. //value = lcdc_readl(sinfo, ARKN141_LCDC_OSD_012_PARAM);
  596. //value |= (1<<12); //osd0: 1:y_uv420 mode, UV store togeter.
  597. //lcdc_writel(sinfo, ARKN141_LCDC_OSD_012_PARAM, value);
  598. /* */
  599. value = (0 << 11) // Srgb_disable
  600. // 1: srgb output disable, 0 is output
  601. // 0: srgb output enable.
  602. | (0 << 10) // srgb_yuv_sel
  603. // 1: yuv data is select;
  604. // 0: rgb data is select.
  605. | (0 << 0) // Srgb_mode
  606. // 00: through mode, R G B R G B\A1\AD
  607. // 01: sRGB dummy, R G B 0 R G B 0\A1\AD
  608. // 10: sYUV422, Cb Y Cr Y Cb Y Cr Y\A1\AD
  609. // 11: 0 is output
  610. | (2 << 2)
  611. | (5 << 5)
  612. | (0 << 25)
  613. ;
  614. lcdc_writel(sinfo, ARKN141_LCDC_SRGB_CFG, value);
  615. lcdc_writel(sinfo, ARKN141_LCDC_VP_RGB2YCBCR_COEF0, 0x10650242);
  616. lcdc_writel(sinfo, ARKN141_LCDC_VP_RGB2YCBCR_COEF1, 0x01c09426);
  617. lcdc_writel(sinfo, ARKN141_LCDC_VP_RGB2YCBCR_COEF2, 0x0048bc70);
  618. lcdc_writel(sinfo, ARKN141_LCDC_VP_CONTROL, (0xF|(64 << 8))); // VDE
  619. lcdc_writel(sinfo, ARKN141_LCDC_VP_ADJUSTEMENT, 0x00408080); // ȱʡֵ
  620. /* Initialize dithing */
  621. value = (1 << 7) | (1 << 15) | (5 << 24);
  622. lcdc_writel(sinfo, ARKN141_LCDC_DITHING, value);
  623. /* osd0 used for video display layer */
  624. value = (1 << 0) | (ARKN141_LCDC_FORMAT_YUV420 <<3) | (info->var.xres << 6) | (info->var.yres <<18) | (1 <<31);
  625. lcdc_writel(sinfo, ARKN141_LCDC_OSD0_PARAM0, value);
  626. value = (63 << 24) | info->var.xres;
  627. lcdc_writel(sinfo, ARKN141_LCDC_OSD0_PARAM5, value);
  628. //value = lcdc_readl(sinfo, ARKN141_LCDC_OSD0_PARAM1);
  629. //value &= ~0xffffff;
  630. value = (255<<24);
  631. lcdc_writel(sinfo, ARKN141_LCDC_OSD0_PARAM1, value);
  632. /* enable/disable osd layer0 */
  633. value = lcdc_readl(sinfo, ARKN141_LCDC_OSD0_PARAM0);
  634. value |= (0 << 1); //0:disable, 1:enable
  635. lcdc_writel(sinfo, ARKN141_LCDC_OSD0_PARAM0, value);
  636. /* sync osd layer0 param */
  637. value = lcdc_readl(sinfo, ARKN141_LCDC_OSD_COEF_SYNC);
  638. value |= (1 << 0);
  639. lcdc_writel(sinfo, ARKN141_LCDC_OSD_COEF_SYNC, value);
  640. return 0;
  641. }
  642. static int arkn141_lcd_rgb_init(struct fb_info *info)
  643. {
  644. struct arkn141_lcdfb_info *sinfo = info->par;
  645. struct arkn141_lcdfb_pdata *pdata = &sinfo->pdata;
  646. unsigned long value;
  647. /* Initialize control register */
  648. unsigned int direct_enable = 0;
  649. unsigned int mem_lcd_enable = 0;
  650. unsigned int range_coeff_y = 0;
  651. unsigned int range_coeff_uv = 0;
  652. unsigned int lcd_done_intr_enable = 1;
  653. unsigned int dac_for_video = 0;
  654. unsigned int dac_for_cvbs = 0;
  655. unsigned int lcd_interlace_flag = 0;
  656. unsigned int screen_type = 1; //pRGB_i 0 pRGB_p 1 sRGB_p 2 ITU656 3
  657. unsigned int VSW1_enable = 0;
  658. unsigned int LcdVComp = 0;
  659. unsigned int itu_pal_ntsc = 0;
  660. unsigned int lcd_ac_ivs = 0;
  661. unsigned int test_on_flag = 0;
  662. unsigned int back_color = (0x22<<16)|(0x44<<8)|(0x88 ); // \u65e0\u80cc\u666f\u8272
  663. unsigned int cpu_screen_csn_bit = 0;
  664. unsigned int cpu_screen_wen_bit = 9;
  665. #if 0
  666. unsigned int sav_pos = 288;
  667. unsigned int f1_vblk_start = 624;
  668. unsigned int f1_vblk_end = 23;
  669. unsigned int f2_vblk_start = 311;
  670. unsigned int f2_vblk_end = 336;
  671. unsigned int f2_start = 313;
  672. unsigned int f2_end = 625;
  673. unsigned int binary_thres = 128;
  674. unsigned int binary_big = 240;
  675. unsigned int binary_small = 16;
  676. #endif
  677. value =
  678. (info->var.xres << 1) |
  679. (pdata->lcd_wiring_mode << 13) |
  680. (direct_enable << 16) |
  681. (mem_lcd_enable << 17) |
  682. (range_coeff_y << 18) |
  683. (range_coeff_uv << 22) |
  684. (lcd_done_intr_enable << 26) |
  685. (dac_for_video << 27) |
  686. (dac_for_cvbs << 28);
  687. lcdc_writel(sinfo, ARKN141_LCDC_PARAM0, value);
  688. value =
  689. (lcd_interlace_flag << 0) |
  690. (screen_type << 1) |
  691. (VSW1_enable << 13) |
  692. (LcdVComp << 14) |
  693. (itu_pal_ntsc << 15) |
  694. (!!(info->var.sync & FB_SYNC_HOR_HIGH_ACT) << 17) |
  695. (!!(info->var.sync & FB_SYNC_VERT_HIGH_ACT) << 18) |
  696. (lcd_ac_ivs << 19) |
  697. (1 << 21) |
  698. (1 << 23) |
  699. (test_on_flag << 31);
  700. lcdc_writel(sinfo, ARKN141_LCDC_PARAM1, value);
  701. value =
  702. (back_color << 0) |
  703. (cpu_screen_csn_bit << 24) |
  704. (cpu_screen_wen_bit << 28);
  705. lcdc_writel(sinfo, ARKN141_LCDC_PARAM2, value);
  706. /* Initialize color convert table */
  707. value = 66 | (129 << 9) | (25 << 18);
  708. lcdc_writel(sinfo, ARKN141_LCDC_PARAM12, value);
  709. value = 38 | (74 << 9) | (112 << 18);
  710. lcdc_writel(sinfo, ARKN141_LCDC_PARAM13, value);
  711. value = 112 | (94 << 9) | (18 << 18);
  712. lcdc_writel(sinfo, ARKN141_LCDC_PARAM14, value);
  713. value = 256 | (0 << 9) | (394 << 18);
  714. lcdc_writel(sinfo, ARKN141_LCDC_PARAM15, value);
  715. value = 256 | (47 << 9) | (118 << 18);
  716. lcdc_writel(sinfo, ARKN141_LCDC_PARAM16, value);
  717. value = 256 | (465 << 9) | (0 << 19);
  718. lcdc_writel(sinfo, ARKN141_LCDC_PARAM17, value);
  719. #if 0
  720. value = (sav_pos << 0);
  721. lcdc_writel(sinfo, ARKN141_LCDC_PARAM18, value);
  722. value = (f1_vblk_start << 0) | (f1_vblk_end << 12) ;
  723. lcdc_writel(sinfo, ARKN141_LCDC_PARAM19, value);
  724. value = (f2_vblk_start << 0) | (f2_vblk_end << 12);
  725. lcdc_writel(sinfo, ARKN141_LCDC_PARAM20, value);
  726. value = (f2_start << 0) | (f2_end << 12);
  727. lcdc_writel(sinfo, ARKN141_LCDC_PARAM21, value);
  728. value = (binary_thres << 16) | (binary_big << 8) | (binary_small << 0);
  729. lcdc_writel(sinfo, ARKN141_LCDC_PARAM22, value);
  730. #endif
  731. /* Initialize dithing */
  732. value = (1 << 7) | (1 << 15) | (5 << 24);
  733. lcdc_writel(sinfo, ARKN141_LCDC_DITHING, value);
  734. /* timing */
  735. value = info->var.hsync_len + info->var.left_margin + info->var.right_margin;
  736. value = ((value + info->var.xres) << 12) | value;
  737. lcdc_writel(sinfo, ARKN141_LCDC_PARAM3, value);
  738. value = info->var.vsync_len + info->var.lower_margin + info->var.upper_margin;
  739. value = ((value + info->var.yres) << 12) | value;
  740. lcdc_writel(sinfo, ARKN141_LCDC_PARAM4, value);
  741. lcdc_writel(sinfo, ARKN141_LCDC_PARAM5, value);
  742. value = ((info->var.vsync_len + info->var.lower_margin + info->var.upper_margin +
  743. info->var.yres) << 12) | (info->var.hsync_len + info->var.left_margin +
  744. info->var.right_margin + value + info->var.xres);
  745. lcdc_writel(sinfo, ARKN141_LCDC_PARAM6, value);
  746. value = ((info->var.hsync_len + info->var.right_margin) << 12) | info->var.right_margin;
  747. lcdc_writel(sinfo, ARKN141_LCDC_PARAM7, value);
  748. lcdc_writel(sinfo, ARKN141_LCDC_PARAM9, value);
  749. lcdc_writel(sinfo, ARKN141_LCDC_PARAM11, value);
  750. value = ((info->var.vsync_len + info->var.lower_margin) << 12) | info->var.lower_margin;
  751. lcdc_writel(sinfo, ARKN141_LCDC_PARAM8, value);
  752. lcdc_writel(sinfo, ARKN141_LCDC_PARAM10, value);
  753. //value = lcdc_readl(sinfo, ARKN141_LCDC_OSD_012_PARAM);
  754. //value |= (1<<12); //osd0: 1:y_uv420 mode, UV store togeter.
  755. //lcdc_writel(sinfo, ARKN141_LCDC_OSD_012_PARAM, value);
  756. /* */
  757. value = (0 << 11) // Srgb_disable
  758. // 1: srgb output disable, 0 is output
  759. // 0: srgb output enable.
  760. | (0 << 10) // srgb_yuv_sel
  761. // 1: yuv data is select;
  762. // 0: rgb data is select.
  763. | (0 << 0) // Srgb_mode
  764. // 00: through mode, R G B R G B\A1\AD
  765. // 01: sRGB dummy, R G B 0 R G B 0\A1\AD
  766. // 10: sYUV422, Cb Y Cr Y Cb Y Cr Y\A1\AD
  767. // 11: 0 is output
  768. | (2 << 2)
  769. | (5 << 5)
  770. | (0 << 25)
  771. ;
  772. lcdc_writel(sinfo, ARKN141_LCDC_SRGB_CFG, value);
  773. lcdc_writel(sinfo, ARKN141_LCDC_VP_RGB2YCBCR_COEF0, 0x10650242);
  774. lcdc_writel(sinfo, ARKN141_LCDC_VP_RGB2YCBCR_COEF1, 0x01c09426);
  775. lcdc_writel(sinfo, ARKN141_LCDC_VP_RGB2YCBCR_COEF2, 0x0048bc70);
  776. lcdc_writel(sinfo, ARKN141_LCDC_VP_CONTROL, (0xF|(64 << 8))); // VDE
  777. lcdc_writel(sinfo, ARKN141_LCDC_VP_ADJUSTEMENT, 0x00408080); // ȱʡֵ
  778. /* Initialize dithing */
  779. value = (1 << 7) | (1 << 15) | (5 << 24);
  780. lcdc_writel(sinfo, ARKN141_LCDC_DITHING, value);
  781. /* osd0 used for video display layer */
  782. value = (1 << 0) | (ARKN141_LCDC_FORMAT_YUV420 <<3) | (info->var.xres << 6) | (info->var.yres <<18) | (1 <<31);
  783. lcdc_writel(sinfo, ARKN141_LCDC_OSD0_PARAM0, value);
  784. value = (63 << 24) | info->var.xres;
  785. lcdc_writel(sinfo, ARKN141_LCDC_OSD0_PARAM5, value);
  786. //value = lcdc_readl(sinfo, ARKN141_LCDC_OSD0_PARAM1);
  787. //value &= ~0xffffff;
  788. value = (255<<24);
  789. lcdc_writel(sinfo, ARKN141_LCDC_OSD0_PARAM1, value);
  790. /* enable/disable osd layer0 */
  791. value = lcdc_readl(sinfo, ARKN141_LCDC_OSD0_PARAM0);
  792. value |= (0 << 1); //0:disable, 1:enable
  793. lcdc_writel(sinfo, ARKN141_LCDC_OSD0_PARAM0, value);
  794. /* sync osd layer0 param */
  795. value = lcdc_readl(sinfo, ARKN141_LCDC_OSD_COEF_SYNC);
  796. value |= (1 << 0);
  797. lcdc_writel(sinfo, ARKN141_LCDC_OSD_COEF_SYNC, value);
  798. return 0;
  799. }
  800. /**
  801. * arkn141_lcdfb_set_par - Alters the hardware state.
  802. * @info: frame buffer structure that represents a single frame buffer
  803. *
  804. * Using the fb_var_screeninfo in fb_info we set the resolution
  805. * of the this particular framebuffer. This function alters the
  806. * par AND the fb_fix_screeninfo stored in fb_info. It doesn't
  807. * not alter var in fb_info since we are using that data. This
  808. * means we depend on the data in var inside fb_info to be
  809. * supported by the hardware. arkn141_lcdfb_check_var is always called
  810. * before arkn141_lcdfb_set_par to ensure this. Again if you can't
  811. * change the resolution you don't need this function.
  812. *
  813. */
  814. static int arkn141_lcdfb_set_par(struct fb_info *info)
  815. {
  816. struct arkn141_lcdfb_info *sinfo = info->par;
  817. struct arkn141_lcdfb_pdata *pdata = &sinfo->pdata;
  818. unsigned long value;
  819. unsigned long bits_per_line;
  820. might_sleep();
  821. dev_dbg(info->device, "%s:\n", __func__);
  822. dev_dbg(info->device, " * resolution: %ux%u (%ux%u virtual)\n",
  823. info->var.xres, info->var.yres,
  824. info->var.xres_virtual, info->var.yres_virtual);
  825. if (info->var.bits_per_pixel == 1)
  826. info->fix.visual = FB_VISUAL_MONO01;
  827. else if (info->var.bits_per_pixel <= 8)
  828. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  829. else
  830. info->fix.visual = FB_VISUAL_TRUECOLOR;
  831. bits_per_line = info->var.xres_virtual * info->var.bits_per_pixel;
  832. info->fix.line_length = DIV_ROUND_UP(bits_per_line, 8);
  833. if (pdata->interface_type == ARKN141_LCDC_INTERFACE_SRGBP) { //itu601out
  834. // set itu601 outpiut clock: 720P-->74.25MHz
  835. value = lcdc_readl_sys(sinfo, SYS_LCD_CLK_CFG);
  836. value &= ~((0x7 << 15) | (0x3 << 8));
  837. value |= (2 << 15) | (1 << 9);
  838. lcdc_writel_sys(sinfo, SYS_LCD_CLK_CFG, value);
  839. //itu601 init
  840. arkn141_lcd_itu601_init(info);
  841. } else if (pdata->interface_type == ARKN141_LCDC_INTERFACE_SRGB) { //srgb
  842. //srgb init
  843. value = lcdc_readl_sys(sinfo, SYS_LCD_CLK_CFG);
  844. value &= ~((0x7 << 15) | (0x3 << 8));
  845. value |= (3 << 15) | (1 << 9) | (1 << 8); //bit8:lcd_clk(bit clk) inversal; bit9:lcd_clk(pixel clk) inversal
  846. lcdc_writel_sys(sinfo, SYS_LCD_CLK_CFG, value);
  847. arkn141_lcd_srgb_init(info);
  848. } else if (pdata->interface_type == ARKN141_LCDC_INTERFACE_RGB) { //rgb888
  849. //rgb init
  850. value = lcdc_readl_sys(sinfo, SYS_LCD_CLK_CFG);
  851. value &= ~((0x7 << 15) | (0x3 << 8));
  852. value |= (1 << 15); //bit8:lcd_clk(bit clk) inversal; bit9:lcd_clk(pixel clk) inversal
  853. lcdc_writel_sys(sinfo, SYS_LCD_CLK_CFG, value);
  854. arkn141_lcd_rgb_init(info);
  855. } else { //argb888
  856. /* Initialize control register */
  857. unsigned int direct_enable = 0;
  858. unsigned int mem_lcd_enable = 0;
  859. unsigned int range_coeff_y = 0;
  860. unsigned int range_coeff_uv = 0;
  861. unsigned int lcd_done_intr_enable = 1;
  862. unsigned int dac_for_video = 0;
  863. unsigned int dac_for_cvbs = 0;
  864. unsigned int lcd_interlace_flag = 0;
  865. unsigned int VSW1_enable = 0;
  866. unsigned int LcdVComp = 0;
  867. unsigned int itu_pal_ntsc = 0;
  868. unsigned int lcd_ac_ivs = 0;
  869. unsigned int test_on_flag = 0;
  870. unsigned int back_color = (0x22<<16)|(0x44<<8)|(0x88 ); // \u65e0\u80cc\u666f\u8272
  871. unsigned int cpu_screen_csn_bit = 0;
  872. unsigned int cpu_screen_wen_bit = 9;
  873. /* Now, the LCDC core... */
  874. value = lcdc_readl_sys(sinfo, SYS_LCD_CLK_CFG);
  875. if (pdata->pixelclk_active_high)
  876. value |= (1 << SYS_PIXEL_CLK_INV_OFFSET);
  877. else
  878. value &= ~(1 << SYS_PIXEL_CLK_INV_OFFSET);
  879. lcdc_writel_sys(sinfo, SYS_LCD_CLK_CFG, value);
  880. value =
  881. (info->var.xres << 1) |
  882. (pdata->lcd_wiring_mode << 13) |
  883. (direct_enable << 16) |
  884. (mem_lcd_enable << 17) |
  885. (range_coeff_y << 18) |
  886. (range_coeff_uv << 22) |
  887. (lcd_done_intr_enable << 26) |
  888. (dac_for_video << 27) |
  889. (dac_for_cvbs << 28);
  890. lcdc_writel(sinfo, ARKN141_LCDC_PARAM0, value);
  891. value =
  892. (lcd_interlace_flag << 0) |
  893. (pdata->interface_type << 1) |
  894. (VSW1_enable << 13) |
  895. (LcdVComp << 14) |
  896. (itu_pal_ntsc << 15) |
  897. (!!(info->var.sync & FB_SYNC_HOR_HIGH_ACT) << 17) |
  898. (!!(info->var.sync & FB_SYNC_VERT_HIGH_ACT) << 18) |
  899. (lcd_ac_ivs << 19) |
  900. (1 << 21) |
  901. (1 << 23) |
  902. (test_on_flag << 31);
  903. lcdc_writel(sinfo, ARKN141_LCDC_PARAM1, value);
  904. value =
  905. (back_color << 0) |
  906. (cpu_screen_csn_bit << 24) |
  907. (cpu_screen_wen_bit << 28);
  908. lcdc_writel(sinfo, ARKN141_LCDC_PARAM2, value);
  909. /* Initialize color convert table */
  910. value = 66 | (129 << 9) | (25 << 18);
  911. lcdc_writel(sinfo, ARKN141_LCDC_PARAM12, value);
  912. value = 38 | (74 << 9) | (112 << 18);
  913. lcdc_writel(sinfo, ARKN141_LCDC_PARAM13, value);
  914. value = 112 | (94 << 9) | (18 << 18);
  915. lcdc_writel(sinfo, ARKN141_LCDC_PARAM14, value);
  916. value = 256 | (0 << 9) | (394 << 18);
  917. lcdc_writel(sinfo, ARKN141_LCDC_PARAM15, value);
  918. value = 256 | (47 << 9) | (118 << 18);
  919. lcdc_writel(sinfo, ARKN141_LCDC_PARAM16, value);
  920. value = 256 | (465 << 9) | (0 << 19);
  921. lcdc_writel(sinfo, ARKN141_LCDC_PARAM17, value);
  922. /* Initialize dithing */
  923. value = (1 << 7) | (1 << 15) | (5 << 24);
  924. lcdc_writel(sinfo, ARKN141_LCDC_DITHING, value);
  925. /* timing */
  926. value = info->var.hsync_len + info->var.left_margin + info->var.right_margin;
  927. value = ((value + info->var.xres) << 12) | value;
  928. lcdc_writel(sinfo, ARKN141_LCDC_PARAM3, value);
  929. value = info->var.vsync_len + info->var.lower_margin + info->var.upper_margin;
  930. value = ((value + info->var.yres) << 12) | value;
  931. lcdc_writel(sinfo, ARKN141_LCDC_PARAM4, value);
  932. lcdc_writel(sinfo, ARKN141_LCDC_PARAM5, value);
  933. value = ((info->var.vsync_len + info->var.lower_margin + info->var.upper_margin +
  934. info->var.yres + 21) << 12) | (info->var.hsync_len + info->var.left_margin +
  935. info->var.right_margin + value + info->var.xres + 1);
  936. lcdc_writel(sinfo, ARKN141_LCDC_PARAM6, value);
  937. value = ((info->var.hsync_len + info->var.right_margin) << 12) | info->var.right_margin;
  938. lcdc_writel(sinfo, ARKN141_LCDC_PARAM7, value);
  939. lcdc_writel(sinfo, ARKN141_LCDC_PARAM9, value);
  940. lcdc_writel(sinfo, ARKN141_LCDC_PARAM11, value);
  941. value = ((info->var.vsync_len + info->var.lower_margin) << 12) | info->var.lower_margin;
  942. lcdc_writel(sinfo, ARKN141_LCDC_PARAM8, value);
  943. lcdc_writel(sinfo, ARKN141_LCDC_PARAM10, value);
  944. /* Initialize specific screen type */
  945. if (pdata->interface_type == ARKN141_LCDC_INTERFACE_SRGB) {
  946. }
  947. }
  948. /* Display osd layer1(fb0) size,pos,format,addr... */
  949. arkn141_lcdfb_pan_display(&info->var, info);
  950. value = (ARKN141_LCDC_FORMAT_ARGB888 << 3) | (info->var.xres << 6) | (info->var.yres << 18) | 1;
  951. lcdc_writel(sinfo, ARKN141_LCDC_OSD1_PARAM0, value);
  952. value = (63 << 24) | info->var.xres;
  953. lcdc_writel(sinfo, ARKN141_LCDC_OSD1_PARAM5, value);
  954. value = lcdc_readl(sinfo, ARKN141_LCDC_OSD1_PARAM1);
  955. value &= ~0xffffff;
  956. lcdc_writel(sinfo, ARKN141_LCDC_OSD1_PARAM1, value);
  957. /* open osd layer1 */
  958. value = lcdc_readl(sinfo, ARKN141_LCDC_OSD1_PARAM0);
  959. value |= (1 << 1);
  960. lcdc_writel(sinfo, ARKN141_LCDC_OSD1_PARAM0, value);
  961. /* sync osd layer1 param */
  962. value = lcdc_readl(sinfo, ARKN141_LCDC_OSD_COEF_SYNC);
  963. value |= (1 << 1);
  964. lcdc_writel(sinfo, ARKN141_LCDC_OSD_COEF_SYNC, value);
  965. /* Clear all interrupts */
  966. lcdc_writel(sinfo, ARKN141_LCDC_INTR_CLR, 7);
  967. /* Enable frame interrupt */
  968. value = lcdc_readl(sinfo, ARKN141_LCDC_PARAM0);
  969. value |= 1 << 30;
  970. lcdc_writel(sinfo, ARKN141_LCDC_PARAM0, value);
  971. arkn141_lcdfb_start(sinfo);
  972. dev_dbg(info->device, " * DONE\n");
  973. return 0;
  974. }
  975. /* static int arkn141_lcdfb_blank(int blank_mode, struct fb_info *info)
  976. {
  977. struct arkn141_lcdfb_info *sinfo = info->par;
  978. switch (blank_mode) {
  979. case FB_BLANK_UNBLANK:
  980. case FB_BLANK_NORMAL:
  981. arkn141_lcdfb_start(sinfo);
  982. break;
  983. case FB_BLANK_VSYNC_SUSPEND:
  984. case FB_BLANK_HSYNC_SUSPEND:
  985. break;
  986. case FB_BLANK_POWERDOWN:
  987. arkn141_lcdfb_stop(sinfo);
  988. break;
  989. default:
  990. return -EINVAL;
  991. }
  992. return ((blank_mode == FB_BLANK_NORMAL) ? 1 : 0);
  993. } */
  994. static struct fb_ops arkn141_lcdfb_ops = {
  995. .owner = THIS_MODULE,
  996. .fb_check_var = arkn141_lcdfb_check_var,
  997. .fb_set_par = arkn141_lcdfb_set_par,
  998. //.fb_blank = arkn141_lcdfb_blank,
  999. .fb_pan_display = arkn141_lcdfb_pan_display,
  1000. .fb_fillrect = cfb_fillrect,
  1001. .fb_copyarea = cfb_copyarea,
  1002. .fb_imageblit = cfb_imageblit,
  1003. .fb_ioctl = arkn141_lcdfb_ioctl,
  1004. };
  1005. volatile int arkn141_lcdc_frame_sync = 0;
  1006. static irqreturn_t arkn141_lcdfb_interrupt(int irq, void *dev_id)
  1007. {
  1008. struct fb_info *info = dev_id;
  1009. struct arkn141_lcdfb_info *sinfo = info->par;
  1010. unsigned long flags;
  1011. u32 status;
  1012. status = lcdc_readl(sinfo, ARKN141_LCDC_STATUS);
  1013. /* clear intr except scale writeback intr */
  1014. lcdc_writel(sinfo, ARKN141_LCDC_INTR_CLR, 0x7);
  1015. if (status & ARKN141_LCDC_INT_LCD_FRAME) {
  1016. sinfo->vsync_flag = 1;
  1017. spin_lock_irqsave(&sinfo->lock, flags);
  1018. sinfo->frame_vsync = 1;
  1019. spin_unlock_irqrestore(&sinfo->lock, flags);
  1020. wake_up_interruptible(&sinfo->vsync_waitq);
  1021. schedule_work(&sinfo->task);
  1022. }
  1023. return IRQ_HANDLED;
  1024. }
  1025. /*
  1026. * LCD controller task (to reset the LCD)
  1027. */
  1028. static void arkn141_lcdfb_task(struct work_struct *work)
  1029. {
  1030. /* struct arkn141_lcdfb_info *sinfo =
  1031. container_of(work, struct arkn141_lcdfb_info, task); */
  1032. }
  1033. static int __init arkn141_lcdfb_init_fbinfo(struct arkn141_lcdfb_info *sinfo)
  1034. {
  1035. struct fb_info *info = sinfo->info;
  1036. int ret = 0;
  1037. info->var.activate |= FB_ACTIVATE_FORCE | FB_ACTIVATE_NOW;
  1038. dev_info(info->device,
  1039. "%luKiB frame buffer at %08lx (mapped at %p)\n",
  1040. (unsigned long)info->fix.smem_len / 1024,
  1041. (unsigned long)info->fix.smem_start,
  1042. info->screen_base);
  1043. /* Allocate colormap */
  1044. ret = fb_alloc_cmap(&info->cmap, 256, 0);
  1045. if (ret < 0)
  1046. dev_err(info->device, "Alloc color map failed\n");
  1047. return ret;
  1048. }
  1049. static void arkn141_lcdfb_start_clock(struct arkn141_lcdfb_info *sinfo)
  1050. {
  1051. clk_prepare_enable(sinfo->lcdc_clk);
  1052. }
  1053. static void arkn141_lcdfb_stop_clock(struct arkn141_lcdfb_info *sinfo)
  1054. {
  1055. clk_disable_unprepare(sinfo->lcdc_clk);
  1056. }
  1057. static const struct of_device_id arkn141_lcdfb_dt_ids[] = {
  1058. { .compatible = "arkmicro,arkn141-lcdc",},
  1059. { /* sentinel */ }
  1060. };
  1061. MODULE_DEVICE_TABLE(of, arkn141_lcdfb_dt_ids);
  1062. static const char *arkn141_lcdfb_interface_types[] = {
  1063. [ARKN141_LCDC_INTERFACE_TTL] = "TTL",
  1064. [ARKN141_LCDC_INTERFACE_RGB] = "RGB",
  1065. [ARKN141_LCDC_INTERFACE_SRGB] = "SRGB",
  1066. [ARKN141_LCDC_INTERFACE_SRGBP] = "SRGB-P",
  1067. };
  1068. static int arkn141_lcdfb_get_of_interface_types(struct device_node *np)
  1069. {
  1070. const char *type;
  1071. int err, i;
  1072. err = of_property_read_string(np, "interface-type", &type);
  1073. if (err < 0)
  1074. return ARKN141_LCDC_INTERFACE_TTL;
  1075. for (i = 0; i < ARRAY_SIZE(arkn141_lcdfb_interface_types); i++)
  1076. if (!strcasecmp(type, arkn141_lcdfb_interface_types[i]))
  1077. return i;
  1078. return -ENODEV;
  1079. }
  1080. static const char *arkn141_lcdfb_wiring_modes[] = {
  1081. [ARK_LCDC_WIRING_BGR] = "BGR",
  1082. [ARK_LCDC_WIRING_GBR] = "GBR",
  1083. [ARK_LCDC_WIRING_RBG] = "RBG",
  1084. [ARK_LCDC_WIRING_BRG] = "BRG",
  1085. [ARK_LCDC_WIRING_GRB] = "GRB",
  1086. [ARK_LCDC_WIRING_RGB] = "RGB",
  1087. };
  1088. static int arkn141_lcdfb_get_of_wiring_modes(struct device_node *np)
  1089. {
  1090. const char *mode;
  1091. int err, i;
  1092. err = of_property_read_string(np, "lcd-wiring-mode", &mode);
  1093. if (err < 0)
  1094. return ARK_LCDC_WIRING_BGR;
  1095. for (i = 0; i < ARRAY_SIZE(arkn141_lcdfb_wiring_modes); i++)
  1096. if (!strcasecmp(mode, arkn141_lcdfb_wiring_modes[i]))
  1097. return i;
  1098. return -ENODEV;
  1099. }
  1100. static void arkn141_lcdfb_power_control_gpio(struct arkn141_lcdfb_pdata *pdata, int on)
  1101. {
  1102. struct arkn141_lcdfb_power_ctrl_gpio *og;
  1103. list_for_each_entry(og, &pdata->pwr_gpios, list)
  1104. gpio_set_value(og->gpio, on ? !og->active_low : og->active_low);
  1105. }
  1106. /*
  1107. * Timer function for delayed backlight power up/down
  1108. */
  1109. static void arkn141_backlight_timer_func(struct timer_list *t)
  1110. {
  1111. struct arkn141_lcdfb_info *sinfo = from_timer(sinfo, t, pdata.backlight_timer);
  1112. struct arkn141_lcdfb_pdata *pdata = &sinfo->pdata;
  1113. arkn141_lcdfb_power_control(sinfo, 1);
  1114. del_timer_sync(&pdata->backlight_timer);
  1115. }
  1116. static int arkn141_lcdfb_of_init(struct arkn141_lcdfb_info *sinfo)
  1117. {
  1118. struct fb_info *info = sinfo->info;
  1119. struct arkn141_lcdfb_pdata *pdata = &sinfo->pdata;
  1120. struct fb_var_screeninfo *var = &info->var;
  1121. struct device *dev = &sinfo->pdev->dev;
  1122. struct device_node *np =dev->of_node;
  1123. struct device_node *display_np;
  1124. struct device_node *timings_np;
  1125. struct display_timings *timings;
  1126. enum of_gpio_flags flags;
  1127. struct arkn141_lcdfb_power_ctrl_gpio *og;
  1128. bool is_gpio_power = false;
  1129. int ret = -ENOENT;
  1130. int i, gpio;
  1131. display_np = of_parse_phandle(np, "display", 0);
  1132. if (!display_np) {
  1133. dev_err(dev, "failed to find display phandle\n");
  1134. return -ENOENT;
  1135. }
  1136. ret = of_property_read_u32(display_np, "bits-per-pixel", &var->bits_per_pixel);
  1137. if (ret < 0) {
  1138. dev_err(dev, "failed to get property bits-per-pixel\n");
  1139. goto put_display_node;
  1140. }
  1141. INIT_LIST_HEAD(&pdata->pwr_gpios);
  1142. ret = -ENOMEM;
  1143. for (i = 0; i < of_gpio_named_count(display_np, "power-control-gpio"); i++) {
  1144. gpio = of_get_named_gpio_flags(display_np, "power-control-gpio",
  1145. i, &flags);
  1146. if (gpio < 0)
  1147. continue;
  1148. og = devm_kzalloc(dev, sizeof(*og), GFP_KERNEL);
  1149. if (!og)
  1150. goto put_display_node;
  1151. og->gpio = gpio;
  1152. og->active_low = flags & OF_GPIO_ACTIVE_LOW;
  1153. is_gpio_power = true;
  1154. ret = devm_gpio_request(dev, gpio, "lcd-power-control-gpio");
  1155. if (ret) {
  1156. dev_err(dev, "request gpio %d failed\n", gpio);
  1157. goto put_display_node;
  1158. }
  1159. ret = gpio_direction_output(gpio, og->active_low);
  1160. if (ret) {
  1161. dev_err(dev, "set direction output gpio %d failed\n", gpio);
  1162. goto put_display_node;
  1163. }
  1164. list_add(&og->list, &pdata->pwr_gpios);
  1165. }
  1166. if (is_gpio_power)
  1167. pdata->arkn141_lcdfb_power_control = arkn141_lcdfb_power_control_gpio;
  1168. ret = arkn141_lcdfb_get_of_interface_types(display_np);
  1169. if (ret < 0) {
  1170. dev_err(dev, "invalid interface-type\n");
  1171. goto put_display_node;
  1172. }
  1173. pdata->interface_type = ret;
  1174. ret = arkn141_lcdfb_get_of_wiring_modes(display_np);
  1175. if (ret < 0) {
  1176. dev_err(dev, "invalid lcd-wiring-mode\n");
  1177. goto put_display_node;
  1178. }
  1179. pdata->lcd_wiring_mode = ret;
  1180. pdata->lcdcon_is_backlight = of_property_read_bool(display_np, "lcdcon-backlight");
  1181. if (pdata->lcdcon_is_backlight) {
  1182. pdata->pwm = devm_of_pwm_get(dev, display_np, NULL);
  1183. if (IS_ERR(pdata->pwm) && PTR_ERR(pdata->pwm) != -EPROBE_DEFER) {
  1184. dev_err(dev, "unable to request PWM\n");
  1185. goto put_display_node;
  1186. }
  1187. ret = of_property_read_u32(display_np, "backlight-value", &pdata->backlight_value);
  1188. if (ret < 0) {
  1189. pdata->backlight_value = 30;
  1190. }
  1191. ret = of_property_read_u32(display_np, "backlight-delay", &pdata->backlight_delay);
  1192. if (ret < 0) {
  1193. pdata->backlight_delay = 100;
  1194. }
  1195. timer_setup(&pdata->backlight_timer, arkn141_backlight_timer_func, 0);
  1196. /* Deferred power up the LCDC screen */
  1197. mod_timer(&pdata->backlight_timer,
  1198. jiffies +
  1199. msecs_to_jiffies(pdata->backlight_delay));
  1200. }
  1201. pdata->lcd_clk_freq_autoupdate = of_property_read_bool(display_np, "clk-freq-autoupdate");
  1202. timings = of_get_display_timings(display_np);
  1203. if (!timings) {
  1204. dev_err(dev, "failed to get display timings\n");
  1205. ret = -EINVAL;
  1206. goto del_timer;
  1207. }
  1208. timings_np = of_get_child_by_name(display_np, "display-timings");
  1209. if (!timings_np) {
  1210. dev_err(dev, "failed to find display-timings node\n");
  1211. ret = -ENODEV;
  1212. goto del_timer;
  1213. }
  1214. for (i = 0; i < of_get_child_count(timings_np); i++) {
  1215. struct videomode vm;
  1216. struct fb_videomode fb_vm;
  1217. ret = videomode_from_timings(timings, &vm, i);
  1218. if (ret < 0)
  1219. goto put_timings_node;
  1220. ret = fb_videomode_from_videomode(&vm, &fb_vm);
  1221. if (ret < 0)
  1222. goto put_timings_node;
  1223. fb_add_videomode(&fb_vm, &info->modelist);
  1224. if (vm.flags & DISPLAY_FLAGS_DE_HIGH)
  1225. pdata->de_active_high = true;
  1226. if (vm.flags & DISPLAY_FLAGS_PIXDATA_POSEDGE)
  1227. pdata->pixelclk_active_high = true;
  1228. }
  1229. /*
  1230. * FIXME: Make sure we are not referencing any fields in display_np
  1231. * and timings_np and drop our references to them before returning to
  1232. * avoid leaking the nodes on probe deferral and driver unbind.
  1233. */
  1234. return 0;
  1235. put_timings_node:
  1236. of_node_put(timings_np);
  1237. del_timer:
  1238. if (pdata->lcdcon_is_backlight)
  1239. del_timer_sync(&pdata->backlight_timer);
  1240. put_display_node:
  1241. of_node_put(display_np);
  1242. return ret;
  1243. }
  1244. static int arkn141_lcdc_dev_init(struct arkn141_lcdfb_info *sinfo)
  1245. {
  1246. /* set layer blend coff */
  1247. lcdc_writel(sinfo, ARKN141_LCDC_OSD0_PARAM1,
  1248. lcdc_readl(sinfo, ARKN141_LCDC_OSD0_PARAM1) | (0xFF << 24));
  1249. lcdc_writel(sinfo, ARKN141_LCDC_OSD1_PARAM1,
  1250. lcdc_readl(sinfo, ARKN141_LCDC_OSD1_PARAM1) | (0xFF << 24));
  1251. lcdc_writel(sinfo, ARKN141_LCDC_OSD2_PARAM1,
  1252. lcdc_readl(sinfo, ARKN141_LCDC_OSD2_PARAM1) | (0xFF << 24));
  1253. return 0;
  1254. }
  1255. static int arkn141_lcdfb_probe(struct platform_device *pdev)
  1256. {
  1257. struct device *dev = &pdev->dev;
  1258. struct fb_info *info, *info_tmp;
  1259. struct arkn141_lcdfb_info *sinfo;
  1260. struct arkn141_lcdfb_pdata *pdata = NULL;
  1261. struct resource *regs = NULL;
  1262. struct resource *map = NULL;
  1263. struct fb_modelist *modelist;
  1264. int ret, i;
  1265. dev_dbg(dev, "%s BEGIN\n", __func__);
  1266. info = framebuffer_alloc(sizeof(struct arkn141_lcdfb_info), dev);
  1267. if (!info) {
  1268. dev_err(dev, "cannot allocate memory\n");
  1269. ret = -ENOMEM;
  1270. goto out;
  1271. }
  1272. sinfo = info->par;
  1273. sinfo->pdev = pdev;
  1274. sinfo->info = info;
  1275. pdata = &sinfo->pdata;
  1276. INIT_LIST_HEAD(&info->modelist);
  1277. ret = arkn141_lcdfb_of_init(sinfo);
  1278. if (ret)
  1279. goto free_info;
  1280. info->flags = ARKN141_LCDFB_FBINFO_DEFAULT;
  1281. info->fbops = &arkn141_lcdfb_ops;
  1282. info->fix = arkn141_lcdfb_fix;
  1283. strcpy(info->fix.id, sinfo->pdev->name);
  1284. /* Enable LCDC Clocks */
  1285. sinfo->lcdc_clk = clk_get(dev, "lcdc_clk");
  1286. if (IS_ERR(sinfo->lcdc_clk)) {
  1287. ret = PTR_ERR(sinfo->lcdc_clk);
  1288. goto free_info;
  1289. }
  1290. arkn141_lcdfb_start_clock(sinfo);
  1291. modelist = list_first_entry(&info->modelist,
  1292. struct fb_modelist, list);
  1293. fb_videomode_to_var(&info->var, &modelist->mode);
  1294. /* Set pixel clock */
  1295. clk_set_rate(sinfo->lcdc_clk, PICOS2KHZ(info->var.pixclock) * 1000);
  1296. info->var.pixclock = KHZ2PICOS(clk_get_rate(sinfo->lcdc_clk) / 1000);
  1297. if (arkn141_lcdfb_check_var(&info->var, info) < 0) {
  1298. dev_err(dev, "arkn141_lcdfb_check_var fail.\n");
  1299. goto stop_clk;
  1300. }
  1301. regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1302. if (!regs) {
  1303. dev_err(dev, "resources unusable\n");
  1304. ret = -ENXIO;
  1305. goto stop_clk;
  1306. }
  1307. /* LCDC registers */
  1308. info->fix.mmio_start = regs->start;
  1309. info->fix.mmio_len = resource_size(regs);
  1310. if (!request_mem_region(info->fix.mmio_start,
  1311. info->fix.mmio_len, pdev->name)) {
  1312. ret = -EBUSY;
  1313. goto free_fb;
  1314. }
  1315. sinfo->mmio = ioremap(info->fix.mmio_start, info->fix.mmio_len);
  1316. if (!sinfo->mmio) {
  1317. dev_err(dev, "cannot map LCDC registers\n");
  1318. ret = -ENOMEM;
  1319. goto release_mem;
  1320. }
  1321. sinfo->sysreg = ioremap(SYS_REG_BASE, 0x400);
  1322. if (!sinfo->sysreg) {
  1323. dev_err(dev, "cannot map sys registers\n");
  1324. ret = -ENOMEM;
  1325. goto unmap_mmio;
  1326. }
  1327. sinfo->irq_base = platform_get_irq(pdev, 0);
  1328. if (sinfo->irq_base < 0) {
  1329. dev_err(dev, "unable to get irq\n");
  1330. ret = sinfo->irq_base;
  1331. goto stop_clk;
  1332. }
  1333. /* Initialize video memory */
  1334. map = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  1335. if (map && map->start) {
  1336. /* use a pre-allocated memory buffer */
  1337. info->fix.smem_start = map->start;
  1338. info->fix.smem_len = resource_size(map);
  1339. if (!request_mem_region(info->fix.smem_start,
  1340. info->fix.smem_len, pdev->name)) {
  1341. ret = -EBUSY;
  1342. goto stop_clk;
  1343. }
  1344. info->screen_base = ioremap_wc(info->fix.smem_start,
  1345. info->fix.smem_len);
  1346. if (!info->screen_base) {
  1347. ret = -ENOMEM;
  1348. goto release_intmem;
  1349. }
  1350. //memset(info->screen_base, 0, info->var.xres * info->var.yres * 4);
  1351. memset(info->screen_base, 0, info->fix.smem_len);
  1352. /*
  1353. * Don't clear the framebuffer -- someone may have set
  1354. * up a splash image.
  1355. */
  1356. } else {
  1357. if(map && !map->start) {
  1358. sinfo->smem_len = resource_size(map);
  1359. }
  1360. /* allocate memory buffer */
  1361. ret = arkn141_lcdfb_alloc_video_memory(sinfo);
  1362. if (ret < 0) {
  1363. dev_err(dev, "cannot allocate framebuffer: %d\n", ret);
  1364. goto stop_clk;
  1365. }
  1366. }
  1367. /* Initialize PWM for contrast or backlight ("off") */
  1368. if (pdata->lcdcon_is_backlight)
  1369. init_backlight(sinfo);
  1370. spin_lock_init(&sinfo->lock);
  1371. mutex_init(&sinfo->mutex_lock);
  1372. /* interrupt */
  1373. ret = request_irq(sinfo->irq_base, arkn141_lcdfb_interrupt, 0, pdev->name, info);
  1374. if (ret) {
  1375. dev_err(dev, "request_irq failed: %d\n", ret);
  1376. goto unmap_sysreg;
  1377. }
  1378. /* Some operations on the LCDC might sleep and
  1379. * require a preemptible task context */
  1380. INIT_WORK(&sinfo->task, arkn141_lcdfb_task);
  1381. init_waitqueue_head(&sinfo->vsync_waitq);
  1382. ret = arkn141_lcdfb_init_fbinfo(sinfo);
  1383. if (ret < 0) {
  1384. dev_err(dev, "init fbinfo failed: %d\n", ret);
  1385. goto unregister_irqs;
  1386. }
  1387. arkn141_lcdc_funcs_init(sinfo);
  1388. ret = arkn141_lcdc_dev_init(sinfo);
  1389. if (ret < 0) {
  1390. dev_err(dev, "init lcdc dev failed: %d\n", ret);
  1391. goto unregister_irqs;
  1392. }
  1393. ret = arkn141_lcdfb_set_par(info);
  1394. if (ret < 0) {
  1395. dev_err(dev, "set par failed: %d\n", ret);
  1396. goto unregister_irqs;
  1397. }
  1398. dev_set_drvdata(dev, info);
  1399. /*
  1400. * Tell the world that we're ready to go
  1401. */
  1402. ret = register_framebuffer(info);
  1403. if (ret < 0) {
  1404. dev_err(dev, "failed to register framebuffer device: %d\n", ret);
  1405. goto reset_drvdata;
  1406. }
  1407. dev_info(dev, "fb%d: Atmel LCDC at 0x%08lx (mapped at %p), irq %d\n",
  1408. info->node, info->fix.mmio_start, sinfo->mmio, sinfo->irq_base);
  1409. for(i = 0; i < 2; i++){
  1410. info_tmp = framebuffer_alloc(sizeof(struct fb_info), dev);
  1411. if (!info_tmp) {
  1412. dev_err(dev, "cannot allocate memory\n");
  1413. ret = -ENOMEM;
  1414. goto out;
  1415. }
  1416. memcpy(info_tmp, info, sizeof(struct fb_info));
  1417. register_framebuffer(info_tmp);
  1418. }
  1419. sinfo->atomic_flag = 0;
  1420. memset(&sinfo->patomic, 0, sizeof(struct ark_disp_atomic) * OSD_LAYER_MAX);
  1421. printk("%s success\n", __FUNCTION__);
  1422. return 0;
  1423. reset_drvdata:
  1424. dev_set_drvdata(dev, NULL);
  1425. fb_dealloc_cmap(&info->cmap);
  1426. unregister_irqs:
  1427. cancel_work_sync(&sinfo->task);
  1428. free_irq(sinfo->irq_base, info);
  1429. unmap_sysreg:
  1430. iounmap(sinfo->sysreg);
  1431. mutex_destroy(&sinfo->mutex_lock);
  1432. unmap_mmio:
  1433. exit_backlight(sinfo);
  1434. iounmap(sinfo->mmio);
  1435. release_mem:
  1436. release_mem_region(info->fix.mmio_start, info->fix.mmio_len);
  1437. free_fb:
  1438. if (map)
  1439. iounmap(info->screen_base);
  1440. else
  1441. arkn141_lcdfb_free_video_memory(sinfo);
  1442. release_intmem:
  1443. if (map)
  1444. release_mem_region(info->fix.smem_start, info->fix.smem_len);
  1445. stop_clk:
  1446. arkn141_lcdfb_stop_clock(sinfo);
  1447. clk_put(sinfo->lcdc_clk);
  1448. free_info:
  1449. framebuffer_release(info);
  1450. out:
  1451. dev_dbg(dev, "%s FAILED ret=%d.\n", __func__, ret);
  1452. printk(KERN_ERR "### %s failed\n", __FUNCTION__);
  1453. return ret;
  1454. }
  1455. static int __exit arkn141_lcdfb_remove(struct platform_device *pdev)
  1456. {
  1457. struct device *dev = &pdev->dev;
  1458. struct fb_info *info = dev_get_drvdata(dev);
  1459. struct arkn141_lcdfb_info *sinfo;
  1460. struct arkn141_lcdfb_pdata *pdata;
  1461. if (!info || !info->par)
  1462. return 0;
  1463. sinfo = info->par;
  1464. pdata = &sinfo->pdata;
  1465. cancel_work_sync(&sinfo->task);
  1466. exit_backlight(sinfo);
  1467. arkn141_lcdfb_power_control(sinfo, 0);
  1468. unregister_framebuffer(info);
  1469. arkn141_lcdfb_stop_clock(sinfo);
  1470. clk_put(sinfo->lcdc_clk);
  1471. fb_dealloc_cmap(&info->cmap);
  1472. free_irq(sinfo->irq_base, info);
  1473. iounmap(sinfo->sysreg);
  1474. iounmap(sinfo->mmio);
  1475. mutex_destroy(&sinfo->mutex_lock);
  1476. release_mem_region(info->fix.mmio_start, info->fix.mmio_len);
  1477. if (platform_get_resource(pdev, IORESOURCE_MEM, 1)) {
  1478. iounmap(info->screen_base);
  1479. release_mem_region(info->fix.smem_start, info->fix.smem_len);
  1480. } else {
  1481. arkn141_lcdfb_free_video_memory(sinfo);
  1482. }
  1483. framebuffer_release(info);
  1484. return 0;
  1485. }
  1486. #ifdef CONFIG_PM
  1487. static int arkn141_lcdfb_suspend(struct platform_device *pdev, pm_message_t mesg)
  1488. {
  1489. return 0;
  1490. }
  1491. static int arkn141_lcdfb_resume(struct platform_device *pdev)
  1492. {
  1493. return 0;
  1494. }
  1495. #else
  1496. #define arkn141_lcdfb_suspend NULL
  1497. #define arkn141_lcdfb_resume NULL
  1498. #endif
  1499. static struct platform_driver arkn141_lcdfb_driver = {
  1500. .probe = arkn141_lcdfb_probe,
  1501. .remove = __exit_p(arkn141_lcdfb_remove),
  1502. .suspend = arkn141_lcdfb_suspend,
  1503. .resume = arkn141_lcdfb_resume,
  1504. .driver = {
  1505. .name = "arkn141_lcdfb",
  1506. .of_match_table = of_match_ptr(arkn141_lcdfb_dt_ids),
  1507. },
  1508. };
  1509. module_platform_driver(arkn141_lcdfb_driver);
  1510. /* static int __init arkn141_lcdfb_init(void)
  1511. {
  1512. int ret;
  1513. ret = platform_driver_register(&arkn141_lcdfb_driver);
  1514. if (ret != 0) {
  1515. printk(KERN_ERR "%s %d: failed to register arkn141_lcdfb_driver\n",
  1516. __FUNCTION__, __LINE__);
  1517. }
  1518. return ret;
  1519. }
  1520. arch_initcall(arkn141_lcdfb_init); */
  1521. MODULE_DESCRIPTION("Arkn141 LCD Controller framebuffer driver");
  1522. MODULE_AUTHOR("Sim");
  1523. MODULE_LICENSE("GPL v2");