sm501fb.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943
  1. /* linux/drivers/video/sm501fb.c
  2. *
  3. * Copyright (c) 2006 Simtec Electronics
  4. * Vincent Sanders <vince@simtec.co.uk>
  5. * Ben Dooks <ben@simtec.co.uk>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * Framebuffer driver for the Silicon Motion SM501
  12. */
  13. #include <linux/module.h>
  14. #include <linux/kernel.h>
  15. #include <linux/errno.h>
  16. #include <linux/string.h>
  17. #include <linux/mm.h>
  18. #include <linux/tty.h>
  19. #include <linux/slab.h>
  20. #include <linux/delay.h>
  21. #include <linux/fb.h>
  22. #include <linux/init.h>
  23. #include <linux/vmalloc.h>
  24. #include <linux/dma-mapping.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/workqueue.h>
  27. #include <linux/wait.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/clk.h>
  30. #include <linux/console.h>
  31. #include <asm/io.h>
  32. #include <asm/uaccess.h>
  33. #include <asm/div64.h>
  34. #ifdef CONFIG_PM
  35. #include <linux/pm.h>
  36. #endif
  37. #include <linux/sm501.h>
  38. #include <linux/sm501-regs.h>
  39. #define NR_PALETTE 256
  40. enum sm501_controller {
  41. HEAD_CRT = 0,
  42. HEAD_PANEL = 1,
  43. };
  44. /* SM501 memory address.
  45. *
  46. * This structure is used to track memory usage within the SM501 framebuffer
  47. * allocation. The sm_addr field is stored as an offset as it is often used
  48. * against both the physical and mapped addresses.
  49. */
  50. struct sm501_mem {
  51. unsigned long size;
  52. unsigned long sm_addr; /* offset from base of sm501 fb. */
  53. void __iomem *k_addr;
  54. };
  55. /* private data that is shared between all frambuffers* */
  56. struct sm501fb_info {
  57. struct device *dev;
  58. struct fb_info *fb[2]; /* fb info for both heads */
  59. struct resource *fbmem_res; /* framebuffer resource */
  60. struct resource *regs_res; /* registers resource */
  61. struct sm501_platdata_fb *pdata; /* our platform data */
  62. unsigned long pm_crt_ctrl; /* pm: crt ctrl save */
  63. int irq;
  64. int swap_endian; /* set to swap rgb=>bgr */
  65. void __iomem *regs; /* remapped registers */
  66. void __iomem *fbmem; /* remapped framebuffer */
  67. size_t fbmem_len; /* length of remapped region */
  68. };
  69. /* per-framebuffer private data */
  70. struct sm501fb_par {
  71. u32 pseudo_palette[16];
  72. enum sm501_controller head;
  73. struct sm501_mem cursor;
  74. struct sm501_mem screen;
  75. struct fb_ops ops;
  76. void *store_fb;
  77. void *store_cursor;
  78. void __iomem *cursor_regs;
  79. struct sm501fb_info *info;
  80. };
  81. /* Helper functions */
  82. static inline int h_total(struct fb_var_screeninfo *var)
  83. {
  84. return var->xres + var->left_margin +
  85. var->right_margin + var->hsync_len;
  86. }
  87. static inline int v_total(struct fb_var_screeninfo *var)
  88. {
  89. return var->yres + var->upper_margin +
  90. var->lower_margin + var->vsync_len;
  91. }
  92. /* sm501fb_sync_regs()
  93. *
  94. * This call is mainly for PCI bus systems where we need to
  95. * ensure that any writes to the bus are completed before the
  96. * next phase, or after completing a function.
  97. */
  98. static inline void sm501fb_sync_regs(struct sm501fb_info *info)
  99. {
  100. readl(info->regs);
  101. }
  102. /* sm501_alloc_mem
  103. *
  104. * This is an attempt to lay out memory for the two framebuffers and
  105. * everything else
  106. *
  107. * |fbmem_res->start fbmem_res->end|
  108. * | |
  109. * |fb[0].fix.smem_start | |fb[1].fix.smem_start | 2K |
  110. * |-> fb[0].fix.smem_len <-| spare |-> fb[1].fix.smem_len <-|-> cursors <-|
  111. *
  112. * The "spare" space is for the 2d engine data
  113. * the fixed is space for the cursors (2x1Kbyte)
  114. *
  115. * we need to allocate memory for the 2D acceleration engine
  116. * command list and the data for the engine to deal with.
  117. *
  118. * - all allocations must be 128bit aligned
  119. * - cursors are 64x64x2 bits (1Kbyte)
  120. *
  121. */
  122. #define SM501_MEMF_CURSOR (1)
  123. #define SM501_MEMF_PANEL (2)
  124. #define SM501_MEMF_CRT (4)
  125. #define SM501_MEMF_ACCEL (8)
  126. static int sm501_alloc_mem(struct sm501fb_info *inf, struct sm501_mem *mem,
  127. unsigned int why, size_t size, u32 smem_len)
  128. {
  129. struct sm501fb_par *par;
  130. struct fb_info *fbi;
  131. unsigned int ptr;
  132. unsigned int end;
  133. switch (why) {
  134. case SM501_MEMF_CURSOR:
  135. ptr = inf->fbmem_len - size;
  136. inf->fbmem_len = ptr; /* adjust available memory. */
  137. break;
  138. case SM501_MEMF_PANEL:
  139. if (size > inf->fbmem_len)
  140. return -ENOMEM;
  141. ptr = inf->fbmem_len - size;
  142. fbi = inf->fb[HEAD_CRT];
  143. /* round down, some programs such as directfb do not draw
  144. * 0,0 correctly unless the start is aligned to a page start.
  145. */
  146. if (ptr > 0)
  147. ptr &= ~(PAGE_SIZE - 1);
  148. if (fbi && ptr < smem_len)
  149. return -ENOMEM;
  150. break;
  151. case SM501_MEMF_CRT:
  152. ptr = 0;
  153. /* check to see if we have panel memory allocated
  154. * which would put an limit on available memory. */
  155. fbi = inf->fb[HEAD_PANEL];
  156. if (fbi) {
  157. par = fbi->par;
  158. end = par->screen.k_addr ? par->screen.sm_addr : inf->fbmem_len;
  159. } else
  160. end = inf->fbmem_len;
  161. if ((ptr + size) > end)
  162. return -ENOMEM;
  163. break;
  164. case SM501_MEMF_ACCEL:
  165. fbi = inf->fb[HEAD_CRT];
  166. ptr = fbi ? smem_len : 0;
  167. fbi = inf->fb[HEAD_PANEL];
  168. if (fbi) {
  169. par = fbi->par;
  170. end = par->screen.sm_addr;
  171. } else
  172. end = inf->fbmem_len;
  173. if ((ptr + size) > end)
  174. return -ENOMEM;
  175. break;
  176. default:
  177. return -EINVAL;
  178. }
  179. mem->size = size;
  180. mem->sm_addr = ptr;
  181. mem->k_addr = inf->fbmem + ptr;
  182. dev_dbg(inf->dev, "%s: result %08lx, %p - %u, %zd\n",
  183. __func__, mem->sm_addr, mem->k_addr, why, size);
  184. return 0;
  185. }
  186. /* sm501fb_ps_to_hz
  187. *
  188. * Converts a period in picoseconds to Hz.
  189. *
  190. * Note, we try to keep this in Hz to minimise rounding with
  191. * the limited PLL settings on the SM501.
  192. */
  193. static unsigned long sm501fb_ps_to_hz(unsigned long psvalue)
  194. {
  195. unsigned long long numerator=1000000000000ULL;
  196. /* 10^12 / picosecond period gives frequency in Hz */
  197. do_div(numerator, psvalue);
  198. return (unsigned long)numerator;
  199. }
  200. /* sm501fb_hz_to_ps is identical to the oposite transform */
  201. #define sm501fb_hz_to_ps(x) sm501fb_ps_to_hz(x)
  202. /* sm501fb_setup_gamma
  203. *
  204. * Programs a linear 1.0 gamma ramp in case the gamma
  205. * correction is enabled without programming anything else.
  206. */
  207. static void sm501fb_setup_gamma(struct sm501fb_info *fbi,
  208. unsigned long palette)
  209. {
  210. unsigned long value = 0;
  211. int offset;
  212. /* set gamma values */
  213. for (offset = 0; offset < 256 * 4; offset += 4) {
  214. writel(value, fbi->regs + palette + offset);
  215. value += 0x010101; /* Advance RGB by 1,1,1.*/
  216. }
  217. }
  218. /* sm501fb_check_var
  219. *
  220. * check common variables for both panel and crt
  221. */
  222. static int sm501fb_check_var(struct fb_var_screeninfo *var,
  223. struct fb_info *info)
  224. {
  225. struct sm501fb_par *par = info->par;
  226. struct sm501fb_info *sm = par->info;
  227. unsigned long tmp;
  228. /* check we can fit these values into the registers */
  229. if (var->hsync_len > 255 || var->vsync_len > 63)
  230. return -EINVAL;
  231. /* hdisplay end and hsync start */
  232. if ((var->xres + var->right_margin) > 4096)
  233. return -EINVAL;
  234. /* vdisplay end and vsync start */
  235. if ((var->yres + var->lower_margin) > 2048)
  236. return -EINVAL;
  237. /* hard limits of device */
  238. if (h_total(var) > 4096 || v_total(var) > 2048)
  239. return -EINVAL;
  240. /* check our line length is going to be 128 bit aligned */
  241. tmp = (var->xres * var->bits_per_pixel) / 8;
  242. if ((tmp & 15) != 0)
  243. return -EINVAL;
  244. /* check the virtual size */
  245. if (var->xres_virtual > 4096 || var->yres_virtual > 2048)
  246. return -EINVAL;
  247. /* can cope with 8,16 or 32bpp */
  248. if (var->bits_per_pixel <= 8)
  249. var->bits_per_pixel = 8;
  250. else if (var->bits_per_pixel <= 16)
  251. var->bits_per_pixel = 16;
  252. else if (var->bits_per_pixel == 24)
  253. var->bits_per_pixel = 32;
  254. /* set r/g/b positions and validate bpp */
  255. switch(var->bits_per_pixel) {
  256. case 8:
  257. var->red.length = var->bits_per_pixel;
  258. var->red.offset = 0;
  259. var->green.length = var->bits_per_pixel;
  260. var->green.offset = 0;
  261. var->blue.length = var->bits_per_pixel;
  262. var->blue.offset = 0;
  263. var->transp.length = 0;
  264. var->transp.offset = 0;
  265. break;
  266. case 16:
  267. if (sm->pdata->flags & SM501_FBPD_SWAP_FB_ENDIAN) {
  268. var->blue.offset = 11;
  269. var->green.offset = 5;
  270. var->red.offset = 0;
  271. } else {
  272. var->red.offset = 11;
  273. var->green.offset = 5;
  274. var->blue.offset = 0;
  275. }
  276. var->transp.offset = 0;
  277. var->red.length = 5;
  278. var->green.length = 6;
  279. var->blue.length = 5;
  280. var->transp.length = 0;
  281. break;
  282. case 32:
  283. if (sm->pdata->flags & SM501_FBPD_SWAP_FB_ENDIAN) {
  284. var->transp.offset = 0;
  285. var->red.offset = 8;
  286. var->green.offset = 16;
  287. var->blue.offset = 24;
  288. } else {
  289. var->transp.offset = 24;
  290. var->red.offset = 16;
  291. var->green.offset = 8;
  292. var->blue.offset = 0;
  293. }
  294. var->red.length = 8;
  295. var->green.length = 8;
  296. var->blue.length = 8;
  297. var->transp.length = 0;
  298. break;
  299. default:
  300. return -EINVAL;
  301. }
  302. return 0;
  303. }
  304. /*
  305. * sm501fb_check_var_crt():
  306. *
  307. * check the parameters for the CRT head, and either bring them
  308. * back into range, or return -EINVAL.
  309. */
  310. static int sm501fb_check_var_crt(struct fb_var_screeninfo *var,
  311. struct fb_info *info)
  312. {
  313. return sm501fb_check_var(var, info);
  314. }
  315. /* sm501fb_check_var_pnl():
  316. *
  317. * check the parameters for the CRT head, and either bring them
  318. * back into range, or return -EINVAL.
  319. */
  320. static int sm501fb_check_var_pnl(struct fb_var_screeninfo *var,
  321. struct fb_info *info)
  322. {
  323. return sm501fb_check_var(var, info);
  324. }
  325. /* sm501fb_set_par_common
  326. *
  327. * set common registers for framebuffers
  328. */
  329. static int sm501fb_set_par_common(struct fb_info *info,
  330. struct fb_var_screeninfo *var)
  331. {
  332. struct sm501fb_par *par = info->par;
  333. struct sm501fb_info *fbi = par->info;
  334. unsigned long pixclock; /* pixelclock in Hz */
  335. unsigned long sm501pixclock; /* pixelclock the 501 can achive in Hz */
  336. unsigned int mem_type;
  337. unsigned int clock_type;
  338. unsigned int head_addr;
  339. unsigned int smem_len;
  340. dev_dbg(fbi->dev, "%s: %dx%d, bpp = %d, virtual %dx%d\n",
  341. __func__, var->xres, var->yres, var->bits_per_pixel,
  342. var->xres_virtual, var->yres_virtual);
  343. switch (par->head) {
  344. case HEAD_CRT:
  345. mem_type = SM501_MEMF_CRT;
  346. clock_type = SM501_CLOCK_V2XCLK;
  347. head_addr = SM501_DC_CRT_FB_ADDR;
  348. break;
  349. case HEAD_PANEL:
  350. mem_type = SM501_MEMF_PANEL;
  351. clock_type = SM501_CLOCK_P2XCLK;
  352. head_addr = SM501_DC_PANEL_FB_ADDR;
  353. break;
  354. default:
  355. mem_type = 0; /* stop compiler warnings */
  356. head_addr = 0;
  357. clock_type = 0;
  358. }
  359. switch (var->bits_per_pixel) {
  360. case 8:
  361. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  362. break;
  363. case 16:
  364. info->fix.visual = FB_VISUAL_TRUECOLOR;
  365. break;
  366. case 32:
  367. info->fix.visual = FB_VISUAL_TRUECOLOR;
  368. break;
  369. }
  370. /* allocate fb memory within 501 */
  371. info->fix.line_length = (var->xres_virtual * var->bits_per_pixel)/8;
  372. smem_len = info->fix.line_length * var->yres_virtual;
  373. dev_dbg(fbi->dev, "%s: line length = %u\n", __func__,
  374. info->fix.line_length);
  375. if (sm501_alloc_mem(fbi, &par->screen, mem_type, smem_len, smem_len)) {
  376. dev_err(fbi->dev, "no memory available\n");
  377. return -ENOMEM;
  378. }
  379. mutex_lock(&info->mm_lock);
  380. info->fix.smem_start = fbi->fbmem_res->start + par->screen.sm_addr;
  381. info->fix.smem_len = smem_len;
  382. mutex_unlock(&info->mm_lock);
  383. info->screen_base = fbi->fbmem + par->screen.sm_addr;
  384. info->screen_size = info->fix.smem_len;
  385. /* set start of framebuffer to the screen */
  386. writel(par->screen.sm_addr | SM501_ADDR_FLIP, fbi->regs + head_addr);
  387. /* program CRT clock */
  388. pixclock = sm501fb_ps_to_hz(var->pixclock);
  389. sm501pixclock = sm501_set_clock(fbi->dev->parent, clock_type,
  390. pixclock);
  391. /* update fb layer with actual clock used */
  392. var->pixclock = sm501fb_hz_to_ps(sm501pixclock);
  393. dev_dbg(fbi->dev, "%s: pixclock(ps) = %u, pixclock(Hz) = %lu, "
  394. "sm501pixclock = %lu, error = %ld%%\n",
  395. __func__, var->pixclock, pixclock, sm501pixclock,
  396. ((pixclock - sm501pixclock)*100)/pixclock);
  397. return 0;
  398. }
  399. /* sm501fb_set_par_geometry
  400. *
  401. * set the geometry registers for specified framebuffer.
  402. */
  403. static void sm501fb_set_par_geometry(struct fb_info *info,
  404. struct fb_var_screeninfo *var)
  405. {
  406. struct sm501fb_par *par = info->par;
  407. struct sm501fb_info *fbi = par->info;
  408. void __iomem *base = fbi->regs;
  409. unsigned long reg;
  410. if (par->head == HEAD_CRT)
  411. base += SM501_DC_CRT_H_TOT;
  412. else
  413. base += SM501_DC_PANEL_H_TOT;
  414. /* set framebuffer width and display width */
  415. reg = info->fix.line_length;
  416. reg |= ((var->xres * var->bits_per_pixel)/8) << 16;
  417. writel(reg, fbi->regs + (par->head == HEAD_CRT ?
  418. SM501_DC_CRT_FB_OFFSET : SM501_DC_PANEL_FB_OFFSET));
  419. /* program horizontal total */
  420. reg = (h_total(var) - 1) << 16;
  421. reg |= (var->xres - 1);
  422. writel(reg, base + SM501_OFF_DC_H_TOT);
  423. /* program horizontal sync */
  424. reg = var->hsync_len << 16;
  425. reg |= var->xres + var->right_margin - 1;
  426. writel(reg, base + SM501_OFF_DC_H_SYNC);
  427. /* program vertical total */
  428. reg = (v_total(var) - 1) << 16;
  429. reg |= (var->yres - 1);
  430. writel(reg, base + SM501_OFF_DC_V_TOT);
  431. /* program vertical sync */
  432. reg = var->vsync_len << 16;
  433. reg |= var->yres + var->lower_margin - 1;
  434. writel(reg, base + SM501_OFF_DC_V_SYNC);
  435. }
  436. /* sm501fb_pan_crt
  437. *
  438. * pan the CRT display output within an virtual framebuffer
  439. */
  440. static int sm501fb_pan_crt(struct fb_var_screeninfo *var,
  441. struct fb_info *info)
  442. {
  443. struct sm501fb_par *par = info->par;
  444. struct sm501fb_info *fbi = par->info;
  445. unsigned int bytes_pixel = var->bits_per_pixel / 8;
  446. unsigned long reg;
  447. unsigned long xoffs;
  448. xoffs = var->xoffset * bytes_pixel;
  449. reg = readl(fbi->regs + SM501_DC_CRT_CONTROL);
  450. reg &= ~SM501_DC_CRT_CONTROL_PIXEL_MASK;
  451. reg |= ((xoffs & 15) / bytes_pixel) << 4;
  452. writel(reg, fbi->regs + SM501_DC_CRT_CONTROL);
  453. reg = (par->screen.sm_addr + xoffs +
  454. var->yoffset * info->fix.line_length);
  455. writel(reg | SM501_ADDR_FLIP, fbi->regs + SM501_DC_CRT_FB_ADDR);
  456. sm501fb_sync_regs(fbi);
  457. return 0;
  458. }
  459. /* sm501fb_pan_pnl
  460. *
  461. * pan the panel display output within an virtual framebuffer
  462. */
  463. static int sm501fb_pan_pnl(struct fb_var_screeninfo *var,
  464. struct fb_info *info)
  465. {
  466. struct sm501fb_par *par = info->par;
  467. struct sm501fb_info *fbi = par->info;
  468. unsigned long reg;
  469. reg = var->xoffset | (var->xres_virtual << 16);
  470. writel(reg, fbi->regs + SM501_DC_PANEL_FB_WIDTH);
  471. reg = var->yoffset | (var->yres_virtual << 16);
  472. writel(reg, fbi->regs + SM501_DC_PANEL_FB_HEIGHT);
  473. sm501fb_sync_regs(fbi);
  474. return 0;
  475. }
  476. /* sm501fb_set_par_crt
  477. *
  478. * Set the CRT video mode from the fb_info structure
  479. */
  480. static int sm501fb_set_par_crt(struct fb_info *info)
  481. {
  482. struct sm501fb_par *par = info->par;
  483. struct sm501fb_info *fbi = par->info;
  484. struct fb_var_screeninfo *var = &info->var;
  485. unsigned long control; /* control register */
  486. int ret;
  487. /* activate new configuration */
  488. dev_dbg(fbi->dev, "%s(%p)\n", __func__, info);
  489. /* enable CRT DAC - note 0 is on!*/
  490. sm501_misc_control(fbi->dev->parent, 0, SM501_MISC_DAC_POWER);
  491. control = readl(fbi->regs + SM501_DC_CRT_CONTROL);
  492. control &= (SM501_DC_CRT_CONTROL_PIXEL_MASK |
  493. SM501_DC_CRT_CONTROL_GAMMA |
  494. SM501_DC_CRT_CONTROL_BLANK |
  495. SM501_DC_CRT_CONTROL_SEL |
  496. SM501_DC_CRT_CONTROL_CP |
  497. SM501_DC_CRT_CONTROL_TVP);
  498. /* set the sync polarities before we check data source */
  499. if ((var->sync & FB_SYNC_HOR_HIGH_ACT) == 0)
  500. control |= SM501_DC_CRT_CONTROL_HSP;
  501. if ((var->sync & FB_SYNC_VERT_HIGH_ACT) == 0)
  502. control |= SM501_DC_CRT_CONTROL_VSP;
  503. if ((control & SM501_DC_CRT_CONTROL_SEL) == 0) {
  504. /* the head is displaying panel data... */
  505. sm501_alloc_mem(fbi, &par->screen, SM501_MEMF_CRT, 0,
  506. info->fix.smem_len);
  507. goto out_update;
  508. }
  509. ret = sm501fb_set_par_common(info, var);
  510. if (ret) {
  511. dev_err(fbi->dev, "failed to set common parameters\n");
  512. return ret;
  513. }
  514. sm501fb_pan_crt(var, info);
  515. sm501fb_set_par_geometry(info, var);
  516. control |= SM501_FIFO_3; /* fill if >3 free slots */
  517. switch(var->bits_per_pixel) {
  518. case 8:
  519. control |= SM501_DC_CRT_CONTROL_8BPP;
  520. break;
  521. case 16:
  522. control |= SM501_DC_CRT_CONTROL_16BPP;
  523. sm501fb_setup_gamma(fbi, SM501_DC_CRT_PALETTE);
  524. break;
  525. case 32:
  526. control |= SM501_DC_CRT_CONTROL_32BPP;
  527. sm501fb_setup_gamma(fbi, SM501_DC_CRT_PALETTE);
  528. break;
  529. default:
  530. BUG();
  531. }
  532. control |= SM501_DC_CRT_CONTROL_SEL; /* CRT displays CRT data */
  533. control |= SM501_DC_CRT_CONTROL_TE; /* enable CRT timing */
  534. control |= SM501_DC_CRT_CONTROL_ENABLE; /* enable CRT plane */
  535. out_update:
  536. dev_dbg(fbi->dev, "new control is %08lx\n", control);
  537. writel(control, fbi->regs + SM501_DC_CRT_CONTROL);
  538. sm501fb_sync_regs(fbi);
  539. return 0;
  540. }
  541. static void sm501fb_panel_power(struct sm501fb_info *fbi, int to)
  542. {
  543. unsigned long control;
  544. void __iomem *ctrl_reg = fbi->regs + SM501_DC_PANEL_CONTROL;
  545. struct sm501_platdata_fbsub *pd = fbi->pdata->fb_pnl;
  546. control = readl(ctrl_reg);
  547. if (to && (control & SM501_DC_PANEL_CONTROL_VDD) == 0) {
  548. /* enable panel power */
  549. control |= SM501_DC_PANEL_CONTROL_VDD; /* FPVDDEN */
  550. writel(control, ctrl_reg);
  551. sm501fb_sync_regs(fbi);
  552. mdelay(10);
  553. control |= SM501_DC_PANEL_CONTROL_DATA; /* DATA */
  554. writel(control, ctrl_reg);
  555. sm501fb_sync_regs(fbi);
  556. mdelay(10);
  557. /* VBIASEN */
  558. if (!(pd->flags & SM501FB_FLAG_PANEL_NO_VBIASEN)) {
  559. if (pd->flags & SM501FB_FLAG_PANEL_INV_VBIASEN)
  560. control &= ~SM501_DC_PANEL_CONTROL_BIAS;
  561. else
  562. control |= SM501_DC_PANEL_CONTROL_BIAS;
  563. writel(control, ctrl_reg);
  564. sm501fb_sync_regs(fbi);
  565. mdelay(10);
  566. }
  567. if (!(pd->flags & SM501FB_FLAG_PANEL_NO_FPEN)) {
  568. if (pd->flags & SM501FB_FLAG_PANEL_INV_FPEN)
  569. control &= ~SM501_DC_PANEL_CONTROL_FPEN;
  570. else
  571. control |= SM501_DC_PANEL_CONTROL_FPEN;
  572. writel(control, ctrl_reg);
  573. sm501fb_sync_regs(fbi);
  574. mdelay(10);
  575. }
  576. } else if (!to && (control & SM501_DC_PANEL_CONTROL_VDD) != 0) {
  577. /* disable panel power */
  578. if (!(pd->flags & SM501FB_FLAG_PANEL_NO_FPEN)) {
  579. if (pd->flags & SM501FB_FLAG_PANEL_INV_FPEN)
  580. control |= SM501_DC_PANEL_CONTROL_FPEN;
  581. else
  582. control &= ~SM501_DC_PANEL_CONTROL_FPEN;
  583. writel(control, ctrl_reg);
  584. sm501fb_sync_regs(fbi);
  585. mdelay(10);
  586. }
  587. if (!(pd->flags & SM501FB_FLAG_PANEL_NO_VBIASEN)) {
  588. if (pd->flags & SM501FB_FLAG_PANEL_INV_VBIASEN)
  589. control |= SM501_DC_PANEL_CONTROL_BIAS;
  590. else
  591. control &= ~SM501_DC_PANEL_CONTROL_BIAS;
  592. writel(control, ctrl_reg);
  593. sm501fb_sync_regs(fbi);
  594. mdelay(10);
  595. }
  596. control &= ~SM501_DC_PANEL_CONTROL_DATA;
  597. writel(control, ctrl_reg);
  598. sm501fb_sync_regs(fbi);
  599. mdelay(10);
  600. control &= ~SM501_DC_PANEL_CONTROL_VDD;
  601. writel(control, ctrl_reg);
  602. sm501fb_sync_regs(fbi);
  603. mdelay(10);
  604. }
  605. sm501fb_sync_regs(fbi);
  606. }
  607. /* sm501fb_set_par_pnl
  608. *
  609. * Set the panel video mode from the fb_info structure
  610. */
  611. static int sm501fb_set_par_pnl(struct fb_info *info)
  612. {
  613. struct sm501fb_par *par = info->par;
  614. struct sm501fb_info *fbi = par->info;
  615. struct fb_var_screeninfo *var = &info->var;
  616. unsigned long control;
  617. unsigned long reg;
  618. int ret;
  619. dev_dbg(fbi->dev, "%s(%p)\n", __func__, info);
  620. /* activate this new configuration */
  621. ret = sm501fb_set_par_common(info, var);
  622. if (ret)
  623. return ret;
  624. sm501fb_pan_pnl(var, info);
  625. sm501fb_set_par_geometry(info, var);
  626. /* update control register */
  627. control = readl(fbi->regs + SM501_DC_PANEL_CONTROL);
  628. control &= (SM501_DC_PANEL_CONTROL_GAMMA |
  629. SM501_DC_PANEL_CONTROL_VDD |
  630. SM501_DC_PANEL_CONTROL_DATA |
  631. SM501_DC_PANEL_CONTROL_BIAS |
  632. SM501_DC_PANEL_CONTROL_FPEN |
  633. SM501_DC_PANEL_CONTROL_CP |
  634. SM501_DC_PANEL_CONTROL_CK |
  635. SM501_DC_PANEL_CONTROL_HP |
  636. SM501_DC_PANEL_CONTROL_VP |
  637. SM501_DC_PANEL_CONTROL_HPD |
  638. SM501_DC_PANEL_CONTROL_VPD);
  639. control |= SM501_FIFO_3; /* fill if >3 free slots */
  640. switch(var->bits_per_pixel) {
  641. case 8:
  642. control |= SM501_DC_PANEL_CONTROL_8BPP;
  643. break;
  644. case 16:
  645. control |= SM501_DC_PANEL_CONTROL_16BPP;
  646. sm501fb_setup_gamma(fbi, SM501_DC_PANEL_PALETTE);
  647. break;
  648. case 32:
  649. control |= SM501_DC_PANEL_CONTROL_32BPP;
  650. sm501fb_setup_gamma(fbi, SM501_DC_PANEL_PALETTE);
  651. break;
  652. default:
  653. BUG();
  654. }
  655. writel(0x0, fbi->regs + SM501_DC_PANEL_PANNING_CONTROL);
  656. /* panel plane top left and bottom right location */
  657. writel(0x00, fbi->regs + SM501_DC_PANEL_TL_LOC);
  658. reg = var->xres - 1;
  659. reg |= (var->yres - 1) << 16;
  660. writel(reg, fbi->regs + SM501_DC_PANEL_BR_LOC);
  661. /* program panel control register */
  662. control |= SM501_DC_PANEL_CONTROL_TE; /* enable PANEL timing */
  663. control |= SM501_DC_PANEL_CONTROL_EN; /* enable PANEL gfx plane */
  664. if ((var->sync & FB_SYNC_HOR_HIGH_ACT) == 0)
  665. control |= SM501_DC_PANEL_CONTROL_HSP;
  666. if ((var->sync & FB_SYNC_VERT_HIGH_ACT) == 0)
  667. control |= SM501_DC_PANEL_CONTROL_VSP;
  668. writel(control, fbi->regs + SM501_DC_PANEL_CONTROL);
  669. sm501fb_sync_regs(fbi);
  670. /* ensure the panel interface is not tristated at this point */
  671. sm501_modify_reg(fbi->dev->parent, SM501_SYSTEM_CONTROL,
  672. 0, SM501_SYSCTRL_PANEL_TRISTATE);
  673. /* power the panel up */
  674. sm501fb_panel_power(fbi, 1);
  675. return 0;
  676. }
  677. /* chan_to_field
  678. *
  679. * convert a colour value into a field position
  680. *
  681. * from pxafb.c
  682. */
  683. static inline unsigned int chan_to_field(unsigned int chan,
  684. struct fb_bitfield *bf)
  685. {
  686. chan &= 0xffff;
  687. chan >>= 16 - bf->length;
  688. return chan << bf->offset;
  689. }
  690. /* sm501fb_setcolreg
  691. *
  692. * set the colour mapping for modes that support palettised data
  693. */
  694. static int sm501fb_setcolreg(unsigned regno,
  695. unsigned red, unsigned green, unsigned blue,
  696. unsigned transp, struct fb_info *info)
  697. {
  698. struct sm501fb_par *par = info->par;
  699. struct sm501fb_info *fbi = par->info;
  700. void __iomem *base = fbi->regs;
  701. unsigned int val;
  702. if (par->head == HEAD_CRT)
  703. base += SM501_DC_CRT_PALETTE;
  704. else
  705. base += SM501_DC_PANEL_PALETTE;
  706. switch (info->fix.visual) {
  707. case FB_VISUAL_TRUECOLOR:
  708. /* true-colour, use pseuo-palette */
  709. if (regno < 16) {
  710. u32 *pal = par->pseudo_palette;
  711. val = chan_to_field(red, &info->var.red);
  712. val |= chan_to_field(green, &info->var.green);
  713. val |= chan_to_field(blue, &info->var.blue);
  714. pal[regno] = val;
  715. }
  716. break;
  717. case FB_VISUAL_PSEUDOCOLOR:
  718. if (regno < 256) {
  719. val = (red >> 8) << 16;
  720. val |= (green >> 8) << 8;
  721. val |= blue >> 8;
  722. writel(val, base + (regno * 4));
  723. }
  724. break;
  725. default:
  726. return 1; /* unknown type */
  727. }
  728. return 0;
  729. }
  730. /* sm501fb_blank_pnl
  731. *
  732. * Blank or un-blank the panel interface
  733. */
  734. static int sm501fb_blank_pnl(int blank_mode, struct fb_info *info)
  735. {
  736. struct sm501fb_par *par = info->par;
  737. struct sm501fb_info *fbi = par->info;
  738. dev_dbg(fbi->dev, "%s(mode=%d, %p)\n", __func__, blank_mode, info);
  739. switch (blank_mode) {
  740. case FB_BLANK_POWERDOWN:
  741. sm501fb_panel_power(fbi, 0);
  742. break;
  743. case FB_BLANK_UNBLANK:
  744. sm501fb_panel_power(fbi, 1);
  745. break;
  746. case FB_BLANK_NORMAL:
  747. case FB_BLANK_VSYNC_SUSPEND:
  748. case FB_BLANK_HSYNC_SUSPEND:
  749. default:
  750. return 1;
  751. }
  752. return 0;
  753. }
  754. /* sm501fb_blank_crt
  755. *
  756. * Blank or un-blank the crt interface
  757. */
  758. static int sm501fb_blank_crt(int blank_mode, struct fb_info *info)
  759. {
  760. struct sm501fb_par *par = info->par;
  761. struct sm501fb_info *fbi = par->info;
  762. unsigned long ctrl;
  763. dev_dbg(fbi->dev, "%s(mode=%d, %p)\n", __func__, blank_mode, info);
  764. ctrl = readl(fbi->regs + SM501_DC_CRT_CONTROL);
  765. switch (blank_mode) {
  766. case FB_BLANK_POWERDOWN:
  767. ctrl &= ~SM501_DC_CRT_CONTROL_ENABLE;
  768. sm501_misc_control(fbi->dev->parent, SM501_MISC_DAC_POWER, 0);
  769. case FB_BLANK_NORMAL:
  770. ctrl |= SM501_DC_CRT_CONTROL_BLANK;
  771. break;
  772. case FB_BLANK_UNBLANK:
  773. ctrl &= ~SM501_DC_CRT_CONTROL_BLANK;
  774. ctrl |= SM501_DC_CRT_CONTROL_ENABLE;
  775. sm501_misc_control(fbi->dev->parent, 0, SM501_MISC_DAC_POWER);
  776. break;
  777. case FB_BLANK_VSYNC_SUSPEND:
  778. case FB_BLANK_HSYNC_SUSPEND:
  779. default:
  780. return 1;
  781. }
  782. writel(ctrl, fbi->regs + SM501_DC_CRT_CONTROL);
  783. sm501fb_sync_regs(fbi);
  784. return 0;
  785. }
  786. /* sm501fb_cursor
  787. *
  788. * set or change the hardware cursor parameters
  789. */
  790. static int sm501fb_cursor(struct fb_info *info, struct fb_cursor *cursor)
  791. {
  792. struct sm501fb_par *par = info->par;
  793. struct sm501fb_info *fbi = par->info;
  794. void __iomem *base = fbi->regs;
  795. unsigned long hwc_addr;
  796. unsigned long fg, bg;
  797. dev_dbg(fbi->dev, "%s(%p,%p)\n", __func__, info, cursor);
  798. if (par->head == HEAD_CRT)
  799. base += SM501_DC_CRT_HWC_BASE;
  800. else
  801. base += SM501_DC_PANEL_HWC_BASE;
  802. /* check not being asked to exceed capabilities */
  803. if (cursor->image.width > 64)
  804. return -EINVAL;
  805. if (cursor->image.height > 64)
  806. return -EINVAL;
  807. if (cursor->image.depth > 1)
  808. return -EINVAL;
  809. hwc_addr = readl(base + SM501_OFF_HWC_ADDR);
  810. if (cursor->enable)
  811. writel(hwc_addr | SM501_HWC_EN, base + SM501_OFF_HWC_ADDR);
  812. else
  813. writel(hwc_addr & ~SM501_HWC_EN, base + SM501_OFF_HWC_ADDR);
  814. /* set data */
  815. if (cursor->set & FB_CUR_SETPOS) {
  816. unsigned int x = cursor->image.dx;
  817. unsigned int y = cursor->image.dy;
  818. if (x >= 2048 || y >= 2048 )
  819. return -EINVAL;
  820. dev_dbg(fbi->dev, "set position %d,%d\n", x, y);
  821. //y += cursor->image.height;
  822. writel(x | (y << 16), base + SM501_OFF_HWC_LOC);
  823. }
  824. if (cursor->set & FB_CUR_SETCMAP) {
  825. unsigned int bg_col = cursor->image.bg_color;
  826. unsigned int fg_col = cursor->image.fg_color;
  827. dev_dbg(fbi->dev, "%s: update cmap (%08x,%08x)\n",
  828. __func__, bg_col, fg_col);
  829. bg = ((info->cmap.red[bg_col] & 0xF8) << 8) |
  830. ((info->cmap.green[bg_col] & 0xFC) << 3) |
  831. ((info->cmap.blue[bg_col] & 0xF8) >> 3);
  832. fg = ((info->cmap.red[fg_col] & 0xF8) << 8) |
  833. ((info->cmap.green[fg_col] & 0xFC) << 3) |
  834. ((info->cmap.blue[fg_col] & 0xF8) >> 3);
  835. dev_dbg(fbi->dev, "fgcol %08lx, bgcol %08lx\n", fg, bg);
  836. writel(bg, base + SM501_OFF_HWC_COLOR_1_2);
  837. writel(fg, base + SM501_OFF_HWC_COLOR_3);
  838. }
  839. if (cursor->set & FB_CUR_SETSIZE ||
  840. cursor->set & (FB_CUR_SETIMAGE | FB_CUR_SETSHAPE)) {
  841. /* SM501 cursor is a two bpp 64x64 bitmap this routine
  842. * clears it to transparent then combines the cursor
  843. * shape plane with the colour plane to set the
  844. * cursor */
  845. int x, y;
  846. const unsigned char *pcol = cursor->image.data;
  847. const unsigned char *pmsk = cursor->mask;
  848. void __iomem *dst = par->cursor.k_addr;
  849. unsigned char dcol = 0;
  850. unsigned char dmsk = 0;
  851. unsigned int op;
  852. dev_dbg(fbi->dev, "%s: setting shape (%d,%d)\n",
  853. __func__, cursor->image.width, cursor->image.height);
  854. for (op = 0; op < (64*64*2)/8; op+=4)
  855. writel(0x0, dst + op);
  856. for (y = 0; y < cursor->image.height; y++) {
  857. for (x = 0; x < cursor->image.width; x++) {
  858. if ((x % 8) == 0) {
  859. dcol = *pcol++;
  860. dmsk = *pmsk++;
  861. } else {
  862. dcol >>= 1;
  863. dmsk >>= 1;
  864. }
  865. if (dmsk & 1) {
  866. op = (dcol & 1) ? 1 : 3;
  867. op <<= ((x % 4) * 2);
  868. op |= readb(dst + (x / 4));
  869. writeb(op, dst + (x / 4));
  870. }
  871. }
  872. dst += (64*2)/8;
  873. }
  874. }
  875. sm501fb_sync_regs(fbi); /* ensure cursor data flushed */
  876. return 0;
  877. }
  878. /* sm501fb_crtsrc_show
  879. *
  880. * device attribute code to show where the crt output is sourced from
  881. */
  882. static ssize_t sm501fb_crtsrc_show(struct device *dev,
  883. struct device_attribute *attr, char *buf)
  884. {
  885. struct sm501fb_info *info = dev_get_drvdata(dev);
  886. unsigned long ctrl;
  887. ctrl = readl(info->regs + SM501_DC_CRT_CONTROL);
  888. ctrl &= SM501_DC_CRT_CONTROL_SEL;
  889. return snprintf(buf, PAGE_SIZE, "%s\n", ctrl ? "crt" : "panel");
  890. }
  891. /* sm501fb_crtsrc_show
  892. *
  893. * device attribute code to set where the crt output is sourced from
  894. */
  895. static ssize_t sm501fb_crtsrc_store(struct device *dev,
  896. struct device_attribute *attr,
  897. const char *buf, size_t len)
  898. {
  899. struct sm501fb_info *info = dev_get_drvdata(dev);
  900. enum sm501_controller head;
  901. unsigned long ctrl;
  902. if (len < 1)
  903. return -EINVAL;
  904. if (strnicmp(buf, "crt", 3) == 0)
  905. head = HEAD_CRT;
  906. else if (strnicmp(buf, "panel", 5) == 0)
  907. head = HEAD_PANEL;
  908. else
  909. return -EINVAL;
  910. dev_info(dev, "setting crt source to head %d\n", head);
  911. ctrl = readl(info->regs + SM501_DC_CRT_CONTROL);
  912. if (head == HEAD_CRT) {
  913. ctrl |= SM501_DC_CRT_CONTROL_SEL;
  914. ctrl |= SM501_DC_CRT_CONTROL_ENABLE;
  915. ctrl |= SM501_DC_CRT_CONTROL_TE;
  916. } else {
  917. ctrl &= ~SM501_DC_CRT_CONTROL_SEL;
  918. ctrl &= ~SM501_DC_CRT_CONTROL_ENABLE;
  919. ctrl &= ~SM501_DC_CRT_CONTROL_TE;
  920. }
  921. writel(ctrl, info->regs + SM501_DC_CRT_CONTROL);
  922. sm501fb_sync_regs(info);
  923. return len;
  924. }
  925. /* Prepare the device_attr for registration with sysfs later */
  926. static DEVICE_ATTR(crt_src, 0666, sm501fb_crtsrc_show, sm501fb_crtsrc_store);
  927. /* sm501fb_show_regs
  928. *
  929. * show the primary sm501 registers
  930. */
  931. static int sm501fb_show_regs(struct sm501fb_info *info, char *ptr,
  932. unsigned int start, unsigned int len)
  933. {
  934. void __iomem *mem = info->regs;
  935. char *buf = ptr;
  936. unsigned int reg;
  937. for (reg = start; reg < (len + start); reg += 4)
  938. ptr += sprintf(ptr, "%08x = %08x\n", reg, readl(mem + reg));
  939. return ptr - buf;
  940. }
  941. /* sm501fb_debug_show_crt
  942. *
  943. * show the crt control and cursor registers
  944. */
  945. static ssize_t sm501fb_debug_show_crt(struct device *dev,
  946. struct device_attribute *attr, char *buf)
  947. {
  948. struct sm501fb_info *info = dev_get_drvdata(dev);
  949. char *ptr = buf;
  950. ptr += sm501fb_show_regs(info, ptr, SM501_DC_CRT_CONTROL, 0x40);
  951. ptr += sm501fb_show_regs(info, ptr, SM501_DC_CRT_HWC_BASE, 0x10);
  952. return ptr - buf;
  953. }
  954. static DEVICE_ATTR(fbregs_crt, 0444, sm501fb_debug_show_crt, NULL);
  955. /* sm501fb_debug_show_pnl
  956. *
  957. * show the panel control and cursor registers
  958. */
  959. static ssize_t sm501fb_debug_show_pnl(struct device *dev,
  960. struct device_attribute *attr, char *buf)
  961. {
  962. struct sm501fb_info *info = dev_get_drvdata(dev);
  963. char *ptr = buf;
  964. ptr += sm501fb_show_regs(info, ptr, 0x0, 0x40);
  965. ptr += sm501fb_show_regs(info, ptr, SM501_DC_PANEL_HWC_BASE, 0x10);
  966. return ptr - buf;
  967. }
  968. static DEVICE_ATTR(fbregs_pnl, 0444, sm501fb_debug_show_pnl, NULL);
  969. /* framebuffer ops */
  970. static struct fb_ops sm501fb_ops_crt = {
  971. .owner = THIS_MODULE,
  972. .fb_check_var = sm501fb_check_var_crt,
  973. .fb_set_par = sm501fb_set_par_crt,
  974. .fb_blank = sm501fb_blank_crt,
  975. .fb_setcolreg = sm501fb_setcolreg,
  976. .fb_pan_display = sm501fb_pan_crt,
  977. .fb_cursor = sm501fb_cursor,
  978. .fb_fillrect = cfb_fillrect,
  979. .fb_copyarea = cfb_copyarea,
  980. .fb_imageblit = cfb_imageblit,
  981. };
  982. static struct fb_ops sm501fb_ops_pnl = {
  983. .owner = THIS_MODULE,
  984. .fb_check_var = sm501fb_check_var_pnl,
  985. .fb_set_par = sm501fb_set_par_pnl,
  986. .fb_pan_display = sm501fb_pan_pnl,
  987. .fb_blank = sm501fb_blank_pnl,
  988. .fb_setcolreg = sm501fb_setcolreg,
  989. .fb_cursor = sm501fb_cursor,
  990. .fb_fillrect = cfb_fillrect,
  991. .fb_copyarea = cfb_copyarea,
  992. .fb_imageblit = cfb_imageblit,
  993. };
  994. /* sm501_init_cursor
  995. *
  996. * initialise hw cursor parameters
  997. */
  998. static int sm501_init_cursor(struct fb_info *fbi, unsigned int reg_base)
  999. {
  1000. struct sm501fb_par *par;
  1001. struct sm501fb_info *info;
  1002. int ret;
  1003. if (fbi == NULL)
  1004. return 0;
  1005. par = fbi->par;
  1006. info = par->info;
  1007. par->cursor_regs = info->regs + reg_base;
  1008. ret = sm501_alloc_mem(info, &par->cursor, SM501_MEMF_CURSOR, 1024,
  1009. fbi->fix.smem_len);
  1010. if (ret < 0)
  1011. return ret;
  1012. /* initialise the colour registers */
  1013. writel(par->cursor.sm_addr, par->cursor_regs + SM501_OFF_HWC_ADDR);
  1014. writel(0x00, par->cursor_regs + SM501_OFF_HWC_LOC);
  1015. writel(0x00, par->cursor_regs + SM501_OFF_HWC_COLOR_1_2);
  1016. writel(0x00, par->cursor_regs + SM501_OFF_HWC_COLOR_3);
  1017. sm501fb_sync_regs(info);
  1018. return 0;
  1019. }
  1020. /* sm501fb_info_start
  1021. *
  1022. * fills the par structure claiming resources and remapping etc.
  1023. */
  1024. static int sm501fb_start(struct sm501fb_info *info,
  1025. struct platform_device *pdev)
  1026. {
  1027. struct resource *res;
  1028. struct device *dev = &pdev->dev;
  1029. int k;
  1030. int ret;
  1031. info->irq = ret = platform_get_irq(pdev, 0);
  1032. if (ret < 0) {
  1033. /* we currently do not use the IRQ */
  1034. dev_warn(dev, "no irq for device\n");
  1035. }
  1036. /* allocate, reserve and remap resources for registers */
  1037. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1038. if (res == NULL) {
  1039. dev_err(dev, "no resource definition for registers\n");
  1040. ret = -ENOENT;
  1041. goto err_release;
  1042. }
  1043. info->regs_res = request_mem_region(res->start,
  1044. res->end - res->start,
  1045. pdev->name);
  1046. if (info->regs_res == NULL) {
  1047. dev_err(dev, "cannot claim registers\n");
  1048. ret = -ENXIO;
  1049. goto err_release;
  1050. }
  1051. info->regs = ioremap(res->start, (res->end - res->start)+1);
  1052. if (info->regs == NULL) {
  1053. dev_err(dev, "cannot remap registers\n");
  1054. ret = -ENXIO;
  1055. goto err_regs_res;
  1056. }
  1057. /* allocate, reserve resources for framebuffer */
  1058. res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
  1059. if (res == NULL) {
  1060. dev_err(dev, "no memory resource defined\n");
  1061. ret = -ENXIO;
  1062. goto err_regs_map;
  1063. }
  1064. info->fbmem_res = request_mem_region(res->start,
  1065. (res->end - res->start)+1,
  1066. pdev->name);
  1067. if (info->fbmem_res == NULL) {
  1068. dev_err(dev, "cannot claim framebuffer\n");
  1069. ret = -ENXIO;
  1070. goto err_regs_map;
  1071. }
  1072. info->fbmem = ioremap(res->start, (res->end - res->start)+1);
  1073. if (info->fbmem == NULL) {
  1074. dev_err(dev, "cannot remap framebuffer\n");
  1075. goto err_mem_res;
  1076. }
  1077. info->fbmem_len = (res->end - res->start)+1;
  1078. /* clear framebuffer memory - avoids garbage data on unused fb */
  1079. memset(info->fbmem, 0, info->fbmem_len);
  1080. /* clear palette ram - undefined at power on */
  1081. for (k = 0; k < (256 * 3); k++)
  1082. writel(0, info->regs + SM501_DC_PANEL_PALETTE + (k * 4));
  1083. /* enable display controller */
  1084. sm501_unit_power(dev->parent, SM501_GATE_DISPLAY, 1);
  1085. /* setup cursors */
  1086. sm501_init_cursor(info->fb[HEAD_CRT], SM501_DC_CRT_HWC_ADDR);
  1087. sm501_init_cursor(info->fb[HEAD_PANEL], SM501_DC_PANEL_HWC_ADDR);
  1088. return 0; /* everything is setup */
  1089. err_mem_res:
  1090. release_resource(info->fbmem_res);
  1091. kfree(info->fbmem_res);
  1092. err_regs_map:
  1093. iounmap(info->regs);
  1094. err_regs_res:
  1095. release_resource(info->regs_res);
  1096. kfree(info->regs_res);
  1097. err_release:
  1098. return ret;
  1099. }
  1100. static void sm501fb_stop(struct sm501fb_info *info)
  1101. {
  1102. /* disable display controller */
  1103. sm501_unit_power(info->dev->parent, SM501_GATE_DISPLAY, 0);
  1104. iounmap(info->fbmem);
  1105. release_resource(info->fbmem_res);
  1106. kfree(info->fbmem_res);
  1107. iounmap(info->regs);
  1108. release_resource(info->regs_res);
  1109. kfree(info->regs_res);
  1110. }
  1111. static int sm501fb_init_fb(struct fb_info *fb,
  1112. enum sm501_controller head,
  1113. const char *fbname)
  1114. {
  1115. struct sm501_platdata_fbsub *pd;
  1116. struct sm501fb_par *par = fb->par;
  1117. struct sm501fb_info *info = par->info;
  1118. unsigned long ctrl;
  1119. unsigned int enable;
  1120. int ret;
  1121. switch (head) {
  1122. case HEAD_CRT:
  1123. pd = info->pdata->fb_crt;
  1124. ctrl = readl(info->regs + SM501_DC_CRT_CONTROL);
  1125. enable = (ctrl & SM501_DC_CRT_CONTROL_ENABLE) ? 1 : 0;
  1126. /* ensure we set the correct source register */
  1127. if (info->pdata->fb_route != SM501_FB_CRT_PANEL) {
  1128. ctrl |= SM501_DC_CRT_CONTROL_SEL;
  1129. writel(ctrl, info->regs + SM501_DC_CRT_CONTROL);
  1130. }
  1131. break;
  1132. case HEAD_PANEL:
  1133. pd = info->pdata->fb_pnl;
  1134. ctrl = readl(info->regs + SM501_DC_PANEL_CONTROL);
  1135. enable = (ctrl & SM501_DC_PANEL_CONTROL_EN) ? 1 : 0;
  1136. break;
  1137. default:
  1138. pd = NULL; /* stop compiler warnings */
  1139. ctrl = 0;
  1140. enable = 0;
  1141. BUG();
  1142. }
  1143. dev_info(info->dev, "fb %s %sabled at start\n",
  1144. fbname, enable ? "en" : "dis");
  1145. /* check to see if our routing allows this */
  1146. if (head == HEAD_CRT && info->pdata->fb_route == SM501_FB_CRT_PANEL) {
  1147. ctrl &= ~SM501_DC_CRT_CONTROL_SEL;
  1148. writel(ctrl, info->regs + SM501_DC_CRT_CONTROL);
  1149. enable = 0;
  1150. }
  1151. strlcpy(fb->fix.id, fbname, sizeof(fb->fix.id));
  1152. memcpy(&par->ops,
  1153. (head == HEAD_CRT) ? &sm501fb_ops_crt : &sm501fb_ops_pnl,
  1154. sizeof(struct fb_ops));
  1155. /* update ops dependant on what we've been passed */
  1156. if ((pd->flags & SM501FB_FLAG_USE_HWCURSOR) == 0)
  1157. par->ops.fb_cursor = NULL;
  1158. fb->fbops = &par->ops;
  1159. fb->flags = FBINFO_FLAG_DEFAULT |
  1160. FBINFO_HWACCEL_XPAN | FBINFO_HWACCEL_YPAN;
  1161. /* fixed data */
  1162. fb->fix.type = FB_TYPE_PACKED_PIXELS;
  1163. fb->fix.type_aux = 0;
  1164. fb->fix.xpanstep = 1;
  1165. fb->fix.ypanstep = 1;
  1166. fb->fix.ywrapstep = 0;
  1167. fb->fix.accel = FB_ACCEL_NONE;
  1168. /* screenmode */
  1169. fb->var.nonstd = 0;
  1170. fb->var.activate = FB_ACTIVATE_NOW;
  1171. fb->var.accel_flags = 0;
  1172. fb->var.vmode = FB_VMODE_NONINTERLACED;
  1173. fb->var.bits_per_pixel = 16;
  1174. if (enable && (pd->flags & SM501FB_FLAG_USE_INIT_MODE) && 0) {
  1175. /* TODO read the mode from the current display */
  1176. } else {
  1177. if (pd->def_mode) {
  1178. dev_info(info->dev, "using supplied mode\n");
  1179. fb_videomode_to_var(&fb->var, pd->def_mode);
  1180. fb->var.bits_per_pixel = pd->def_bpp ? pd->def_bpp : 8;
  1181. fb->var.xres_virtual = fb->var.xres;
  1182. fb->var.yres_virtual = fb->var.yres;
  1183. } else {
  1184. ret = fb_find_mode(&fb->var, fb,
  1185. NULL, NULL, 0, NULL, 8);
  1186. if (ret == 0 || ret == 4) {
  1187. dev_err(info->dev,
  1188. "failed to get initial mode\n");
  1189. return -EINVAL;
  1190. }
  1191. }
  1192. }
  1193. /* initialise and set the palette */
  1194. if (fb_alloc_cmap(&fb->cmap, NR_PALETTE, 0)) {
  1195. dev_err(info->dev, "failed to allocate cmap memory\n");
  1196. return -ENOMEM;
  1197. }
  1198. fb_set_cmap(&fb->cmap, fb);
  1199. ret = (fb->fbops->fb_check_var)(&fb->var, fb);
  1200. if (ret)
  1201. dev_err(info->dev, "check_var() failed on initial setup?\n");
  1202. return 0;
  1203. }
  1204. /* default platform data if none is supplied (ie, PCI device) */
  1205. static struct sm501_platdata_fbsub sm501fb_pdata_crt = {
  1206. .flags = (SM501FB_FLAG_USE_INIT_MODE |
  1207. SM501FB_FLAG_USE_HWCURSOR |
  1208. SM501FB_FLAG_USE_HWACCEL |
  1209. SM501FB_FLAG_DISABLE_AT_EXIT),
  1210. };
  1211. static struct sm501_platdata_fbsub sm501fb_pdata_pnl = {
  1212. .flags = (SM501FB_FLAG_USE_INIT_MODE |
  1213. SM501FB_FLAG_USE_HWCURSOR |
  1214. SM501FB_FLAG_USE_HWACCEL |
  1215. SM501FB_FLAG_DISABLE_AT_EXIT),
  1216. };
  1217. static struct sm501_platdata_fb sm501fb_def_pdata = {
  1218. .fb_route = SM501_FB_OWN,
  1219. .fb_crt = &sm501fb_pdata_crt,
  1220. .fb_pnl = &sm501fb_pdata_pnl,
  1221. };
  1222. static char driver_name_crt[] = "sm501fb-crt";
  1223. static char driver_name_pnl[] = "sm501fb-panel";
  1224. static int __devinit sm501fb_probe_one(struct sm501fb_info *info,
  1225. enum sm501_controller head)
  1226. {
  1227. unsigned char *name = (head == HEAD_CRT) ? "crt" : "panel";
  1228. struct sm501_platdata_fbsub *pd;
  1229. struct sm501fb_par *par;
  1230. struct fb_info *fbi;
  1231. pd = (head == HEAD_CRT) ? info->pdata->fb_crt : info->pdata->fb_pnl;
  1232. /* Do not initialise if we've not been given any platform data */
  1233. if (pd == NULL) {
  1234. dev_info(info->dev, "no data for fb %s (disabled)\n", name);
  1235. return 0;
  1236. }
  1237. fbi = framebuffer_alloc(sizeof(struct sm501fb_par), info->dev);
  1238. if (fbi == NULL) {
  1239. dev_err(info->dev, "cannot allocate %s framebuffer\n", name);
  1240. return -ENOMEM;
  1241. }
  1242. par = fbi->par;
  1243. par->info = info;
  1244. par->head = head;
  1245. fbi->pseudo_palette = &par->pseudo_palette;
  1246. info->fb[head] = fbi;
  1247. return 0;
  1248. }
  1249. /* Free up anything allocated by sm501fb_init_fb */
  1250. static void sm501_free_init_fb(struct sm501fb_info *info,
  1251. enum sm501_controller head)
  1252. {
  1253. struct fb_info *fbi = info->fb[head];
  1254. fb_dealloc_cmap(&fbi->cmap);
  1255. }
  1256. static int __devinit sm501fb_start_one(struct sm501fb_info *info,
  1257. enum sm501_controller head,
  1258. const char *drvname)
  1259. {
  1260. struct fb_info *fbi = info->fb[head];
  1261. int ret;
  1262. if (!fbi)
  1263. return 0;
  1264. mutex_init(&info->fb[head]->mm_lock);
  1265. ret = sm501fb_init_fb(info->fb[head], head, drvname);
  1266. if (ret) {
  1267. dev_err(info->dev, "cannot initialise fb %s\n", drvname);
  1268. return ret;
  1269. }
  1270. ret = register_framebuffer(info->fb[head]);
  1271. if (ret) {
  1272. dev_err(info->dev, "failed to register fb %s\n", drvname);
  1273. sm501_free_init_fb(info, head);
  1274. return ret;
  1275. }
  1276. dev_info(info->dev, "fb%d: %s frame buffer\n", fbi->node, fbi->fix.id);
  1277. return 0;
  1278. }
  1279. static int __devinit sm501fb_probe(struct platform_device *pdev)
  1280. {
  1281. struct sm501fb_info *info;
  1282. struct device *dev = &pdev->dev;
  1283. int ret;
  1284. /* allocate our framebuffers */
  1285. info = kzalloc(sizeof(struct sm501fb_info), GFP_KERNEL);
  1286. if (!info) {
  1287. dev_err(dev, "failed to allocate state\n");
  1288. return -ENOMEM;
  1289. }
  1290. info->dev = dev = &pdev->dev;
  1291. platform_set_drvdata(pdev, info);
  1292. if (dev->parent->platform_data) {
  1293. struct sm501_platdata *pd = dev->parent->platform_data;
  1294. info->pdata = pd->fb;
  1295. }
  1296. if (info->pdata == NULL) {
  1297. dev_info(dev, "using default configuration data\n");
  1298. info->pdata = &sm501fb_def_pdata;
  1299. }
  1300. /* probe for the presence of each panel */
  1301. ret = sm501fb_probe_one(info, HEAD_CRT);
  1302. if (ret < 0) {
  1303. dev_err(dev, "failed to probe CRT\n");
  1304. goto err_alloc;
  1305. }
  1306. ret = sm501fb_probe_one(info, HEAD_PANEL);
  1307. if (ret < 0) {
  1308. dev_err(dev, "failed to probe PANEL\n");
  1309. goto err_probed_crt;
  1310. }
  1311. if (info->fb[HEAD_PANEL] == NULL &&
  1312. info->fb[HEAD_CRT] == NULL) {
  1313. dev_err(dev, "no framebuffers found\n");
  1314. goto err_alloc;
  1315. }
  1316. /* get the resources for both of the framebuffers */
  1317. ret = sm501fb_start(info, pdev);
  1318. if (ret) {
  1319. dev_err(dev, "cannot initialise SM501\n");
  1320. goto err_probed_panel;
  1321. }
  1322. ret = sm501fb_start_one(info, HEAD_CRT, driver_name_crt);
  1323. if (ret) {
  1324. dev_err(dev, "failed to start CRT\n");
  1325. goto err_started;
  1326. }
  1327. ret = sm501fb_start_one(info, HEAD_PANEL, driver_name_pnl);
  1328. if (ret) {
  1329. dev_err(dev, "failed to start Panel\n");
  1330. goto err_started_crt;
  1331. }
  1332. /* create device files */
  1333. ret = device_create_file(dev, &dev_attr_crt_src);
  1334. if (ret)
  1335. goto err_started_panel;
  1336. ret = device_create_file(dev, &dev_attr_fbregs_pnl);
  1337. if (ret)
  1338. goto err_attached_crtsrc_file;
  1339. ret = device_create_file(dev, &dev_attr_fbregs_crt);
  1340. if (ret)
  1341. goto err_attached_pnlregs_file;
  1342. /* we registered, return ok */
  1343. return 0;
  1344. err_attached_pnlregs_file:
  1345. device_remove_file(dev, &dev_attr_fbregs_pnl);
  1346. err_attached_crtsrc_file:
  1347. device_remove_file(dev, &dev_attr_crt_src);
  1348. err_started_panel:
  1349. unregister_framebuffer(info->fb[HEAD_PANEL]);
  1350. sm501_free_init_fb(info, HEAD_PANEL);
  1351. err_started_crt:
  1352. unregister_framebuffer(info->fb[HEAD_CRT]);
  1353. sm501_free_init_fb(info, HEAD_CRT);
  1354. err_started:
  1355. sm501fb_stop(info);
  1356. err_probed_panel:
  1357. framebuffer_release(info->fb[HEAD_PANEL]);
  1358. err_probed_crt:
  1359. framebuffer_release(info->fb[HEAD_CRT]);
  1360. err_alloc:
  1361. kfree(info);
  1362. return ret;
  1363. }
  1364. /*
  1365. * Cleanup
  1366. */
  1367. static int sm501fb_remove(struct platform_device *pdev)
  1368. {
  1369. struct sm501fb_info *info = platform_get_drvdata(pdev);
  1370. struct fb_info *fbinfo_crt = info->fb[0];
  1371. struct fb_info *fbinfo_pnl = info->fb[1];
  1372. device_remove_file(&pdev->dev, &dev_attr_fbregs_crt);
  1373. device_remove_file(&pdev->dev, &dev_attr_fbregs_pnl);
  1374. device_remove_file(&pdev->dev, &dev_attr_crt_src);
  1375. sm501_free_init_fb(info, HEAD_CRT);
  1376. sm501_free_init_fb(info, HEAD_PANEL);
  1377. unregister_framebuffer(fbinfo_crt);
  1378. unregister_framebuffer(fbinfo_pnl);
  1379. sm501fb_stop(info);
  1380. kfree(info);
  1381. framebuffer_release(fbinfo_pnl);
  1382. framebuffer_release(fbinfo_crt);
  1383. return 0;
  1384. }
  1385. #ifdef CONFIG_PM
  1386. static int sm501fb_suspend_fb(struct sm501fb_info *info,
  1387. enum sm501_controller head)
  1388. {
  1389. struct fb_info *fbi = info->fb[head];
  1390. struct sm501fb_par *par = fbi->par;
  1391. if (par->screen.size == 0)
  1392. return 0;
  1393. /* blank the relevant interface to ensure unit power minimised */
  1394. (par->ops.fb_blank)(FB_BLANK_POWERDOWN, fbi);
  1395. /* tell console/fb driver we are suspending */
  1396. acquire_console_sem();
  1397. fb_set_suspend(fbi, 1);
  1398. release_console_sem();
  1399. /* backup copies in case chip is powered down over suspend */
  1400. par->store_fb = vmalloc(par->screen.size);
  1401. if (par->store_fb == NULL) {
  1402. dev_err(info->dev, "no memory to store screen\n");
  1403. return -ENOMEM;
  1404. }
  1405. par->store_cursor = vmalloc(par->cursor.size);
  1406. if (par->store_cursor == NULL) {
  1407. dev_err(info->dev, "no memory to store cursor\n");
  1408. goto err_nocursor;
  1409. }
  1410. dev_dbg(info->dev, "suspending screen to %p\n", par->store_fb);
  1411. dev_dbg(info->dev, "suspending cursor to %p\n", par->store_cursor);
  1412. memcpy_fromio(par->store_fb, par->screen.k_addr, par->screen.size);
  1413. memcpy_fromio(par->store_cursor, par->cursor.k_addr, par->cursor.size);
  1414. return 0;
  1415. err_nocursor:
  1416. vfree(par->store_fb);
  1417. par->store_fb = NULL;
  1418. return -ENOMEM;
  1419. }
  1420. static void sm501fb_resume_fb(struct sm501fb_info *info,
  1421. enum sm501_controller head)
  1422. {
  1423. struct fb_info *fbi = info->fb[head];
  1424. struct sm501fb_par *par = fbi->par;
  1425. if (par->screen.size == 0)
  1426. return;
  1427. /* re-activate the configuration */
  1428. (par->ops.fb_set_par)(fbi);
  1429. /* restore the data */
  1430. dev_dbg(info->dev, "restoring screen from %p\n", par->store_fb);
  1431. dev_dbg(info->dev, "restoring cursor from %p\n", par->store_cursor);
  1432. if (par->store_fb)
  1433. memcpy_toio(par->screen.k_addr, par->store_fb,
  1434. par->screen.size);
  1435. if (par->store_cursor)
  1436. memcpy_toio(par->cursor.k_addr, par->store_cursor,
  1437. par->cursor.size);
  1438. acquire_console_sem();
  1439. fb_set_suspend(fbi, 0);
  1440. release_console_sem();
  1441. vfree(par->store_fb);
  1442. vfree(par->store_cursor);
  1443. }
  1444. /* suspend and resume support */
  1445. static int sm501fb_suspend(struct platform_device *pdev, pm_message_t state)
  1446. {
  1447. struct sm501fb_info *info = platform_get_drvdata(pdev);
  1448. /* store crt control to resume with */
  1449. info->pm_crt_ctrl = readl(info->regs + SM501_DC_CRT_CONTROL);
  1450. sm501fb_suspend_fb(info, HEAD_CRT);
  1451. sm501fb_suspend_fb(info, HEAD_PANEL);
  1452. /* turn off the clocks, in case the device is not powered down */
  1453. sm501_unit_power(info->dev->parent, SM501_GATE_DISPLAY, 0);
  1454. return 0;
  1455. }
  1456. #define SM501_CRT_CTRL_SAVE (SM501_DC_CRT_CONTROL_TVP | \
  1457. SM501_DC_CRT_CONTROL_SEL)
  1458. static int sm501fb_resume(struct platform_device *pdev)
  1459. {
  1460. struct sm501fb_info *info = platform_get_drvdata(pdev);
  1461. unsigned long crt_ctrl;
  1462. sm501_unit_power(info->dev->parent, SM501_GATE_DISPLAY, 1);
  1463. /* restore the items we want to be saved for crt control */
  1464. crt_ctrl = readl(info->regs + SM501_DC_CRT_CONTROL);
  1465. crt_ctrl &= ~SM501_CRT_CTRL_SAVE;
  1466. crt_ctrl |= info->pm_crt_ctrl & SM501_CRT_CTRL_SAVE;
  1467. writel(crt_ctrl, info->regs + SM501_DC_CRT_CONTROL);
  1468. sm501fb_resume_fb(info, HEAD_CRT);
  1469. sm501fb_resume_fb(info, HEAD_PANEL);
  1470. return 0;
  1471. }
  1472. #else
  1473. #define sm501fb_suspend NULL
  1474. #define sm501fb_resume NULL
  1475. #endif
  1476. static struct platform_driver sm501fb_driver = {
  1477. .probe = sm501fb_probe,
  1478. .remove = sm501fb_remove,
  1479. .suspend = sm501fb_suspend,
  1480. .resume = sm501fb_resume,
  1481. .driver = {
  1482. .name = "sm501-fb",
  1483. .owner = THIS_MODULE,
  1484. },
  1485. };
  1486. static int __devinit sm501fb_init(void)
  1487. {
  1488. return platform_driver_register(&sm501fb_driver);
  1489. }
  1490. static void __exit sm501fb_cleanup(void)
  1491. {
  1492. platform_driver_unregister(&sm501fb_driver);
  1493. }
  1494. module_init(sm501fb_init);
  1495. module_exit(sm501fb_cleanup);
  1496. MODULE_AUTHOR("Ben Dooks, Vincent Sanders");
  1497. MODULE_DESCRIPTION("SM501 Framebuffer driver");
  1498. MODULE_LICENSE("GPL v2");