sa1100fb.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577
  1. /*
  2. * linux/drivers/video/sa1100fb.c
  3. *
  4. * Copyright (C) 1999 Eric A. Thomas
  5. * Based on acornfb.c Copyright (C) Russell King.
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file COPYING in the main directory of this archive for
  9. * more details.
  10. *
  11. * StrongARM 1100 LCD Controller Frame Buffer Driver
  12. *
  13. * Please direct your questions and comments on this driver to the following
  14. * email address:
  15. *
  16. * linux-arm-kernel@lists.arm.linux.org.uk
  17. *
  18. * Clean patches should be sent to the ARM Linux Patch System. Please see the
  19. * following web page for more information:
  20. *
  21. * http://www.arm.linux.org.uk/developer/patches/info.shtml
  22. *
  23. * Thank you.
  24. *
  25. * Known problems:
  26. * - With the Neponset plugged into an Assabet, LCD powerdown
  27. * doesn't work (LCD stays powered up). Therefore we shouldn't
  28. * blank the screen.
  29. * - We don't limit the CPU clock rate nor the mode selection
  30. * according to the available SDRAM bandwidth.
  31. *
  32. * Other notes:
  33. * - Linear grayscale palettes and the kernel.
  34. * Such code does not belong in the kernel. The kernel frame buffer
  35. * drivers do not expect a linear colourmap, but a colourmap based on
  36. * the VT100 standard mapping.
  37. *
  38. * If your _userspace_ requires a linear colourmap, then the setup of
  39. * such a colourmap belongs _in userspace_, not in the kernel. Code
  40. * to set the colourmap correctly from user space has been sent to
  41. * David Neuer. It's around 8 lines of C code, plus another 4 to
  42. * detect if we are using grayscale.
  43. *
  44. * - The following must never be specified in a panel definition:
  45. * LCCR0_LtlEnd, LCCR3_PixClkDiv, LCCR3_VrtSnchL, LCCR3_HorSnchL
  46. *
  47. * - The following should be specified:
  48. * either LCCR0_Color or LCCR0_Mono
  49. * either LCCR0_Sngl or LCCR0_Dual
  50. * either LCCR0_Act or LCCR0_Pas
  51. * either LCCR3_OutEnH or LCCD3_OutEnL
  52. * either LCCR3_PixRsEdg or LCCR3_PixFlEdg
  53. * either LCCR3_ACBsDiv or LCCR3_ACBsCntOff
  54. *
  55. * Code Status:
  56. * 1999/04/01:
  57. * - Driver appears to be working for Brutus 320x200x8bpp mode. Other
  58. * resolutions are working, but only the 8bpp mode is supported.
  59. * Changes need to be made to the palette encode and decode routines
  60. * to support 4 and 16 bpp modes.
  61. * Driver is not designed to be a module. The FrameBuffer is statically
  62. * allocated since dynamic allocation of a 300k buffer cannot be
  63. * guaranteed.
  64. *
  65. * 1999/06/17:
  66. * - FrameBuffer memory is now allocated at run-time when the
  67. * driver is initialized.
  68. *
  69. * 2000/04/10: Nicolas Pitre <nico@cam.org>
  70. * - Big cleanup for dynamic selection of machine type at run time.
  71. *
  72. * 2000/07/19: Jamey Hicks <jamey@crl.dec.com>
  73. * - Support for Bitsy aka Compaq iPAQ H3600 added.
  74. *
  75. * 2000/08/07: Tak-Shing Chan <tchan.rd@idthk.com>
  76. * Jeff Sutherland <jsutherland@accelent.com>
  77. * - Resolved an issue caused by a change made to the Assabet's PLD
  78. * earlier this year which broke the framebuffer driver for newer
  79. * Phase 4 Assabets. Some other parameters were changed to optimize
  80. * for the Sharp display.
  81. *
  82. * 2000/08/09: Kunihiko IMAI <imai@vasara.co.jp>
  83. * - XP860 support added
  84. *
  85. * 2000/08/19: Mark Huang <mhuang@livetoy.com>
  86. * - Allows standard options to be passed on the kernel command line
  87. * for most common passive displays.
  88. *
  89. * 2000/08/29:
  90. * - s/save_flags_cli/local_irq_save/
  91. * - remove unneeded extra save_flags_cli in sa1100fb_enable_lcd_controller
  92. *
  93. * 2000/10/10: Erik Mouw <J.A.K.Mouw@its.tudelft.nl>
  94. * - Updated LART stuff. Fixed some minor bugs.
  95. *
  96. * 2000/10/30: Murphy Chen <murphy@mail.dialogue.com.tw>
  97. * - Pangolin support added
  98. *
  99. * 2000/10/31: Roman Jordan <jor@hoeft-wessel.de>
  100. * - Huw Webpanel support added
  101. *
  102. * 2000/11/23: Eric Peng <ericpeng@coventive.com>
  103. * - Freebird add
  104. *
  105. * 2001/02/07: Jamey Hicks <jamey.hicks@compaq.com>
  106. * Cliff Brake <cbrake@accelent.com>
  107. * - Added PM callback
  108. *
  109. * 2001/05/26: <rmk@arm.linux.org.uk>
  110. * - Fix 16bpp so that (a) we use the right colours rather than some
  111. * totally random colour depending on what was in page 0, and (b)
  112. * we don't de-reference a NULL pointer.
  113. * - remove duplicated implementation of consistent_alloc()
  114. * - convert dma address types to dma_addr_t
  115. * - remove unused 'montype' stuff
  116. * - remove redundant zero inits of init_var after the initial
  117. * memzero.
  118. * - remove allow_modeset (acornfb idea does not belong here)
  119. *
  120. * 2001/05/28: <rmk@arm.linux.org.uk>
  121. * - massive cleanup - move machine dependent data into structures
  122. * - I've left various #warnings in - if you see one, and know
  123. * the hardware concerned, please get in contact with me.
  124. *
  125. * 2001/05/31: <rmk@arm.linux.org.uk>
  126. * - Fix LCCR1 HSW value, fix all machine type specifications to
  127. * keep values in line. (Please check your machine type specs)
  128. *
  129. * 2001/06/10: <rmk@arm.linux.org.uk>
  130. * - Fiddle with the LCD controller from task context only; mainly
  131. * so that we can run with interrupts on, and sleep.
  132. * - Convert #warnings into #errors. No pain, no gain. ;)
  133. *
  134. * 2001/06/14: <rmk@arm.linux.org.uk>
  135. * - Make the palette BPS value for 12bpp come out correctly.
  136. * - Take notice of "greyscale" on any colour depth.
  137. * - Make truecolor visuals use the RGB channel encoding information.
  138. *
  139. * 2001/07/02: <rmk@arm.linux.org.uk>
  140. * - Fix colourmap problems.
  141. *
  142. * 2001/07/13: <abraham@2d3d.co.za>
  143. * - Added support for the ICP LCD-Kit01 on LART. This LCD is
  144. * manufactured by Prime View, model no V16C6448AB
  145. *
  146. * 2001/07/23: <rmk@arm.linux.org.uk>
  147. * - Hand merge version from handhelds.org CVS tree. See patch
  148. * notes for 595/1 for more information.
  149. * - Drop 12bpp (it's 16bpp with different colour register mappings).
  150. * - This hardware can not do direct colour. Therefore we don't
  151. * support it.
  152. *
  153. * 2001/07/27: <rmk@arm.linux.org.uk>
  154. * - Halve YRES on dual scan LCDs.
  155. *
  156. * 2001/08/22: <rmk@arm.linux.org.uk>
  157. * - Add b/w iPAQ pixclock value.
  158. *
  159. * 2001/10/12: <rmk@arm.linux.org.uk>
  160. * - Add patch 681/1 and clean up stork definitions.
  161. */
  162. #include <linux/module.h>
  163. #include <linux/kernel.h>
  164. #include <linux/sched.h>
  165. #include <linux/errno.h>
  166. #include <linux/string.h>
  167. #include <linux/interrupt.h>
  168. #include <linux/slab.h>
  169. #include <linux/fb.h>
  170. #include <linux/delay.h>
  171. #include <linux/init.h>
  172. #include <linux/ioport.h>
  173. #include <linux/cpufreq.h>
  174. #include <linux/platform_device.h>
  175. #include <linux/dma-mapping.h>
  176. #include <asm/hardware.h>
  177. #include <asm/io.h>
  178. #include <asm/mach-types.h>
  179. #include <asm/arch/assabet.h>
  180. #include <asm/arch/shannon.h>
  181. /*
  182. * debugging?
  183. */
  184. #define DEBUG 0
  185. /*
  186. * Complain if VAR is out of range.
  187. */
  188. #define DEBUG_VAR 1
  189. #undef ASSABET_PAL_VIDEO
  190. #include "sa1100fb.h"
  191. extern void (*sa1100fb_backlight_power)(int on);
  192. extern void (*sa1100fb_lcd_power)(int on);
  193. /*
  194. * IMHO this looks wrong. In 8BPP, length should be 8.
  195. */
  196. static struct sa1100fb_rgb rgb_8 = {
  197. .red = { .offset = 0, .length = 4, },
  198. .green = { .offset = 0, .length = 4, },
  199. .blue = { .offset = 0, .length = 4, },
  200. .transp = { .offset = 0, .length = 0, },
  201. };
  202. static struct sa1100fb_rgb def_rgb_16 = {
  203. .red = { .offset = 11, .length = 5, },
  204. .green = { .offset = 5, .length = 6, },
  205. .blue = { .offset = 0, .length = 5, },
  206. .transp = { .offset = 0, .length = 0, },
  207. };
  208. #ifdef CONFIG_SA1100_ASSABET
  209. #ifndef ASSABET_PAL_VIDEO
  210. /*
  211. * The assabet uses a sharp LQ039Q2DS54 LCD module. It is actually
  212. * takes an RGB666 signal, but we provide it with an RGB565 signal
  213. * instead (def_rgb_16).
  214. */
  215. static struct sa1100fb_mach_info lq039q2ds54_info __initdata = {
  216. .pixclock = 171521, .bpp = 16,
  217. .xres = 320, .yres = 240,
  218. .hsync_len = 5, .vsync_len = 1,
  219. .left_margin = 61, .upper_margin = 3,
  220. .right_margin = 9, .lower_margin = 0,
  221. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  222. .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
  223. .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2),
  224. };
  225. #else
  226. static struct sa1100fb_mach_info pal_info __initdata = {
  227. .pixclock = 67797, .bpp = 16,
  228. .xres = 640, .yres = 512,
  229. .hsync_len = 64, .vsync_len = 6,
  230. .left_margin = 125, .upper_margin = 70,
  231. .right_margin = 115, .lower_margin = 36,
  232. .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
  233. .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(512),
  234. };
  235. #endif
  236. #endif
  237. #ifdef CONFIG_SA1100_H3800
  238. static struct sa1100fb_mach_info h3800_info __initdata = {
  239. .pixclock = 174757, .bpp = 16,
  240. .xres = 320, .yres = 240,
  241. .hsync_len = 3, .vsync_len = 3,
  242. .left_margin = 12, .upper_margin = 10,
  243. .right_margin = 17, .lower_margin = 1,
  244. .cmap_static = 1,
  245. .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
  246. .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2),
  247. };
  248. #endif
  249. #ifdef CONFIG_SA1100_H3600
  250. static struct sa1100fb_mach_info h3600_info __initdata = {
  251. .pixclock = 174757, .bpp = 16,
  252. .xres = 320, .yres = 240,
  253. .hsync_len = 3, .vsync_len = 3,
  254. .left_margin = 12, .upper_margin = 10,
  255. .right_margin = 17, .lower_margin = 1,
  256. .cmap_static = 1,
  257. .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
  258. .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2),
  259. };
  260. static struct sa1100fb_rgb h3600_rgb_16 = {
  261. .red = { .offset = 12, .length = 4, },
  262. .green = { .offset = 7, .length = 4, },
  263. .blue = { .offset = 1, .length = 4, },
  264. .transp = { .offset = 0, .length = 0, },
  265. };
  266. #endif
  267. #ifdef CONFIG_SA1100_H3100
  268. static struct sa1100fb_mach_info h3100_info __initdata = {
  269. .pixclock = 406977, .bpp = 4,
  270. .xres = 320, .yres = 240,
  271. .hsync_len = 26, .vsync_len = 41,
  272. .left_margin = 4, .upper_margin = 0,
  273. .right_margin = 4, .lower_margin = 0,
  274. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  275. .cmap_greyscale = 1,
  276. .cmap_inverse = 1,
  277. .lccr0 = LCCR0_Mono | LCCR0_4PixMono | LCCR0_Sngl | LCCR0_Pas,
  278. .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2),
  279. };
  280. #endif
  281. #ifdef CONFIG_SA1100_COLLIE
  282. static struct sa1100fb_mach_info collie_info __initdata = {
  283. .pixclock = 171521, .bpp = 16,
  284. .xres = 320, .yres = 240,
  285. .hsync_len = 5, .vsync_len = 1,
  286. .left_margin = 11, .upper_margin = 2,
  287. .right_margin = 30, .lower_margin = 0,
  288. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  289. .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
  290. .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2),
  291. };
  292. #endif
  293. #ifdef LART_GREY_LCD
  294. static struct sa1100fb_mach_info lart_grey_info __initdata = {
  295. .pixclock = 150000, .bpp = 4,
  296. .xres = 320, .yres = 240,
  297. .hsync_len = 1, .vsync_len = 1,
  298. .left_margin = 4, .upper_margin = 0,
  299. .right_margin = 2, .lower_margin = 0,
  300. .cmap_greyscale = 1,
  301. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  302. .lccr0 = LCCR0_Mono | LCCR0_Sngl | LCCR0_Pas | LCCR0_4PixMono,
  303. .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(512),
  304. };
  305. #endif
  306. #ifdef LART_COLOR_LCD
  307. static struct sa1100fb_mach_info lart_color_info __initdata = {
  308. .pixclock = 150000, .bpp = 16,
  309. .xres = 320, .yres = 240,
  310. .hsync_len = 2, .vsync_len = 3,
  311. .left_margin = 69, .upper_margin = 14,
  312. .right_margin = 8, .lower_margin = 4,
  313. .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
  314. .lccr3 = LCCR3_OutEnH | LCCR3_PixFlEdg | LCCR3_ACBsDiv(512),
  315. };
  316. #endif
  317. #ifdef LART_VIDEO_OUT
  318. static struct sa1100fb_mach_info lart_video_info __initdata = {
  319. .pixclock = 39721, .bpp = 16,
  320. .xres = 640, .yres = 480,
  321. .hsync_len = 95, .vsync_len = 2,
  322. .left_margin = 40, .upper_margin = 32,
  323. .right_margin = 24, .lower_margin = 11,
  324. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  325. .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
  326. .lccr3 = LCCR3_OutEnL | LCCR3_PixFlEdg | LCCR3_ACBsDiv(512),
  327. };
  328. #endif
  329. #ifdef LART_KIT01_LCD
  330. static struct sa1100fb_mach_info lart_kit01_info __initdata = {
  331. .pixclock = 63291, .bpp = 16,
  332. .xres = 640, .yres = 480,
  333. .hsync_len = 64, .vsync_len = 3,
  334. .left_margin = 122, .upper_margin = 45,
  335. .right_margin = 10, .lower_margin = 10,
  336. .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
  337. .lccr3 = LCCR3_OutEnH | LCCR3_PixFlEdg
  338. };
  339. #endif
  340. #ifdef CONFIG_SA1100_SHANNON
  341. static struct sa1100fb_mach_info shannon_info __initdata = {
  342. .pixclock = 152500, .bpp = 8,
  343. .xres = 640, .yres = 480,
  344. .hsync_len = 4, .vsync_len = 3,
  345. .left_margin = 2, .upper_margin = 0,
  346. .right_margin = 1, .lower_margin = 0,
  347. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  348. .lccr0 = LCCR0_Color | LCCR0_Dual | LCCR0_Pas,
  349. .lccr3 = LCCR3_ACBsDiv(512),
  350. };
  351. #endif
  352. static struct sa1100fb_mach_info * __init
  353. sa1100fb_get_machine_info(struct sa1100fb_info *fbi)
  354. {
  355. struct sa1100fb_mach_info *inf = NULL;
  356. /*
  357. * R G B T
  358. * default {11,5}, { 5,6}, { 0,5}, { 0,0}
  359. * h3600 {12,4}, { 7,4}, { 1,4}, { 0,0}
  360. * freebird { 8,4}, { 4,4}, { 0,4}, {12,4}
  361. */
  362. #ifdef CONFIG_SA1100_ASSABET
  363. if (machine_is_assabet()) {
  364. #ifndef ASSABET_PAL_VIDEO
  365. inf = &lq039q2ds54_info;
  366. #else
  367. inf = &pal_info;
  368. #endif
  369. }
  370. #endif
  371. #ifdef CONFIG_SA1100_H3100
  372. if (machine_is_h3100()) {
  373. inf = &h3100_info;
  374. }
  375. #endif
  376. #ifdef CONFIG_SA1100_H3600
  377. if (machine_is_h3600()) {
  378. inf = &h3600_info;
  379. fbi->rgb[RGB_16] = &h3600_rgb_16;
  380. }
  381. #endif
  382. #ifdef CONFIG_SA1100_H3800
  383. if (machine_is_h3800()) {
  384. inf = &h3800_info;
  385. }
  386. #endif
  387. #ifdef CONFIG_SA1100_COLLIE
  388. if (machine_is_collie()) {
  389. inf = &collie_info;
  390. }
  391. #endif
  392. #ifdef CONFIG_SA1100_LART
  393. if (machine_is_lart()) {
  394. #ifdef LART_GREY_LCD
  395. inf = &lart_grey_info;
  396. #endif
  397. #ifdef LART_COLOR_LCD
  398. inf = &lart_color_info;
  399. #endif
  400. #ifdef LART_VIDEO_OUT
  401. inf = &lart_video_info;
  402. #endif
  403. #ifdef LART_KIT01_LCD
  404. inf = &lart_kit01_info;
  405. #endif
  406. }
  407. #endif
  408. #ifdef CONFIG_SA1100_SHANNON
  409. if (machine_is_shannon()) {
  410. inf = &shannon_info;
  411. }
  412. #endif
  413. return inf;
  414. }
  415. static int sa1100fb_activate_var(struct fb_var_screeninfo *var, struct sa1100fb_info *);
  416. static void set_ctrlr_state(struct sa1100fb_info *fbi, u_int state);
  417. static inline void sa1100fb_schedule_work(struct sa1100fb_info *fbi, u_int state)
  418. {
  419. unsigned long flags;
  420. local_irq_save(flags);
  421. /*
  422. * We need to handle two requests being made at the same time.
  423. * There are two important cases:
  424. * 1. When we are changing VT (C_REENABLE) while unblanking (C_ENABLE)
  425. * We must perform the unblanking, which will do our REENABLE for us.
  426. * 2. When we are blanking, but immediately unblank before we have
  427. * blanked. We do the "REENABLE" thing here as well, just to be sure.
  428. */
  429. if (fbi->task_state == C_ENABLE && state == C_REENABLE)
  430. state = (u_int) -1;
  431. if (fbi->task_state == C_DISABLE && state == C_ENABLE)
  432. state = C_REENABLE;
  433. if (state != (u_int)-1) {
  434. fbi->task_state = state;
  435. schedule_work(&fbi->task);
  436. }
  437. local_irq_restore(flags);
  438. }
  439. static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf)
  440. {
  441. chan &= 0xffff;
  442. chan >>= 16 - bf->length;
  443. return chan << bf->offset;
  444. }
  445. /*
  446. * Convert bits-per-pixel to a hardware palette PBS value.
  447. */
  448. static inline u_int palette_pbs(struct fb_var_screeninfo *var)
  449. {
  450. int ret = 0;
  451. switch (var->bits_per_pixel) {
  452. case 4: ret = 0 << 12; break;
  453. case 8: ret = 1 << 12; break;
  454. case 16: ret = 2 << 12; break;
  455. }
  456. return ret;
  457. }
  458. static int
  459. sa1100fb_setpalettereg(u_int regno, u_int red, u_int green, u_int blue,
  460. u_int trans, struct fb_info *info)
  461. {
  462. struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
  463. u_int val, ret = 1;
  464. if (regno < fbi->palette_size) {
  465. val = ((red >> 4) & 0xf00);
  466. val |= ((green >> 8) & 0x0f0);
  467. val |= ((blue >> 12) & 0x00f);
  468. if (regno == 0)
  469. val |= palette_pbs(&fbi->fb.var);
  470. fbi->palette_cpu[regno] = val;
  471. ret = 0;
  472. }
  473. return ret;
  474. }
  475. static int
  476. sa1100fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  477. u_int trans, struct fb_info *info)
  478. {
  479. struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
  480. unsigned int val;
  481. int ret = 1;
  482. /*
  483. * If inverse mode was selected, invert all the colours
  484. * rather than the register number. The register number
  485. * is what you poke into the framebuffer to produce the
  486. * colour you requested.
  487. */
  488. if (fbi->cmap_inverse) {
  489. red = 0xffff - red;
  490. green = 0xffff - green;
  491. blue = 0xffff - blue;
  492. }
  493. /*
  494. * If greyscale is true, then we convert the RGB value
  495. * to greyscale no mater what visual we are using.
  496. */
  497. if (fbi->fb.var.grayscale)
  498. red = green = blue = (19595 * red + 38470 * green +
  499. 7471 * blue) >> 16;
  500. switch (fbi->fb.fix.visual) {
  501. case FB_VISUAL_TRUECOLOR:
  502. /*
  503. * 12 or 16-bit True Colour. We encode the RGB value
  504. * according to the RGB bitfield information.
  505. */
  506. if (regno < 16) {
  507. u32 *pal = fbi->fb.pseudo_palette;
  508. val = chan_to_field(red, &fbi->fb.var.red);
  509. val |= chan_to_field(green, &fbi->fb.var.green);
  510. val |= chan_to_field(blue, &fbi->fb.var.blue);
  511. pal[regno] = val;
  512. ret = 0;
  513. }
  514. break;
  515. case FB_VISUAL_STATIC_PSEUDOCOLOR:
  516. case FB_VISUAL_PSEUDOCOLOR:
  517. ret = sa1100fb_setpalettereg(regno, red, green, blue, trans, info);
  518. break;
  519. }
  520. return ret;
  521. }
  522. #ifdef CONFIG_CPU_FREQ
  523. /*
  524. * sa1100fb_display_dma_period()
  525. * Calculate the minimum period (in picoseconds) between two DMA
  526. * requests for the LCD controller. If we hit this, it means we're
  527. * doing nothing but LCD DMA.
  528. */
  529. static inline unsigned int sa1100fb_display_dma_period(struct fb_var_screeninfo *var)
  530. {
  531. /*
  532. * Period = pixclock * bits_per_byte * bytes_per_transfer
  533. * / memory_bits_per_pixel;
  534. */
  535. return var->pixclock * 8 * 16 / var->bits_per_pixel;
  536. }
  537. #endif
  538. /*
  539. * sa1100fb_check_var():
  540. * Round up in the following order: bits_per_pixel, xres,
  541. * yres, xres_virtual, yres_virtual, xoffset, yoffset, grayscale,
  542. * bitfields, horizontal timing, vertical timing.
  543. */
  544. static int
  545. sa1100fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  546. {
  547. struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
  548. int rgbidx;
  549. if (var->xres < MIN_XRES)
  550. var->xres = MIN_XRES;
  551. if (var->yres < MIN_YRES)
  552. var->yres = MIN_YRES;
  553. if (var->xres > fbi->max_xres)
  554. var->xres = fbi->max_xres;
  555. if (var->yres > fbi->max_yres)
  556. var->yres = fbi->max_yres;
  557. var->xres_virtual = max(var->xres_virtual, var->xres);
  558. var->yres_virtual = max(var->yres_virtual, var->yres);
  559. DPRINTK("var->bits_per_pixel=%d\n", var->bits_per_pixel);
  560. switch (var->bits_per_pixel) {
  561. case 4:
  562. rgbidx = RGB_8;
  563. break;
  564. case 8:
  565. rgbidx = RGB_8;
  566. break;
  567. case 16:
  568. rgbidx = RGB_16;
  569. break;
  570. default:
  571. return -EINVAL;
  572. }
  573. /*
  574. * Copy the RGB parameters for this display
  575. * from the machine specific parameters.
  576. */
  577. var->red = fbi->rgb[rgbidx]->red;
  578. var->green = fbi->rgb[rgbidx]->green;
  579. var->blue = fbi->rgb[rgbidx]->blue;
  580. var->transp = fbi->rgb[rgbidx]->transp;
  581. DPRINTK("RGBT length = %d:%d:%d:%d\n",
  582. var->red.length, var->green.length, var->blue.length,
  583. var->transp.length);
  584. DPRINTK("RGBT offset = %d:%d:%d:%d\n",
  585. var->red.offset, var->green.offset, var->blue.offset,
  586. var->transp.offset);
  587. #ifdef CONFIG_CPU_FREQ
  588. printk(KERN_DEBUG "dma period = %d ps, clock = %d kHz\n",
  589. sa1100fb_display_dma_period(var),
  590. cpufreq_get(smp_processor_id()));
  591. #endif
  592. return 0;
  593. }
  594. static inline void sa1100fb_set_truecolor(u_int is_true_color)
  595. {
  596. if (machine_is_assabet()) {
  597. #if 1 // phase 4 or newer Assabet's
  598. if (is_true_color)
  599. ASSABET_BCR_set(ASSABET_BCR_LCD_12RGB);
  600. else
  601. ASSABET_BCR_clear(ASSABET_BCR_LCD_12RGB);
  602. #else
  603. // older Assabet's
  604. if (is_true_color)
  605. ASSABET_BCR_clear(ASSABET_BCR_LCD_12RGB);
  606. else
  607. ASSABET_BCR_set(ASSABET_BCR_LCD_12RGB);
  608. #endif
  609. }
  610. }
  611. /*
  612. * sa1100fb_set_par():
  613. * Set the user defined part of the display for the specified console
  614. */
  615. static int sa1100fb_set_par(struct fb_info *info)
  616. {
  617. struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
  618. struct fb_var_screeninfo *var = &info->var;
  619. unsigned long palette_mem_size;
  620. DPRINTK("set_par\n");
  621. if (var->bits_per_pixel == 16)
  622. fbi->fb.fix.visual = FB_VISUAL_TRUECOLOR;
  623. else if (!fbi->cmap_static)
  624. fbi->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
  625. else {
  626. /*
  627. * Some people have weird ideas about wanting static
  628. * pseudocolor maps. I suspect their user space
  629. * applications are broken.
  630. */
  631. fbi->fb.fix.visual = FB_VISUAL_STATIC_PSEUDOCOLOR;
  632. }
  633. fbi->fb.fix.line_length = var->xres_virtual *
  634. var->bits_per_pixel / 8;
  635. fbi->palette_size = var->bits_per_pixel == 8 ? 256 : 16;
  636. palette_mem_size = fbi->palette_size * sizeof(u16);
  637. DPRINTK("palette_mem_size = 0x%08lx\n", (u_long) palette_mem_size);
  638. fbi->palette_cpu = (u16 *)(fbi->map_cpu + PAGE_SIZE - palette_mem_size);
  639. fbi->palette_dma = fbi->map_dma + PAGE_SIZE - palette_mem_size;
  640. /*
  641. * Set (any) board control register to handle new color depth
  642. */
  643. sa1100fb_set_truecolor(fbi->fb.fix.visual == FB_VISUAL_TRUECOLOR);
  644. sa1100fb_activate_var(var, fbi);
  645. return 0;
  646. }
  647. #if 0
  648. static int
  649. sa1100fb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
  650. struct fb_info *info)
  651. {
  652. struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
  653. /*
  654. * Make sure the user isn't doing something stupid.
  655. */
  656. if (!kspc && (fbi->fb.var.bits_per_pixel == 16 || fbi->cmap_static))
  657. return -EINVAL;
  658. return gen_set_cmap(cmap, kspc, con, info);
  659. }
  660. #endif
  661. /*
  662. * Formal definition of the VESA spec:
  663. * On
  664. * This refers to the state of the display when it is in full operation
  665. * Stand-By
  666. * This defines an optional operating state of minimal power reduction with
  667. * the shortest recovery time
  668. * Suspend
  669. * This refers to a level of power management in which substantial power
  670. * reduction is achieved by the display. The display can have a longer
  671. * recovery time from this state than from the Stand-by state
  672. * Off
  673. * This indicates that the display is consuming the lowest level of power
  674. * and is non-operational. Recovery from this state may optionally require
  675. * the user to manually power on the monitor
  676. *
  677. * Now, the fbdev driver adds an additional state, (blank), where they
  678. * turn off the video (maybe by colormap tricks), but don't mess with the
  679. * video itself: think of it semantically between on and Stand-By.
  680. *
  681. * So here's what we should do in our fbdev blank routine:
  682. *
  683. * VESA_NO_BLANKING (mode 0) Video on, front/back light on
  684. * VESA_VSYNC_SUSPEND (mode 1) Video on, front/back light off
  685. * VESA_HSYNC_SUSPEND (mode 2) Video on, front/back light off
  686. * VESA_POWERDOWN (mode 3) Video off, front/back light off
  687. *
  688. * This will match the matrox implementation.
  689. */
  690. /*
  691. * sa1100fb_blank():
  692. * Blank the display by setting all palette values to zero. Note, the
  693. * 12 and 16 bpp modes don't really use the palette, so this will not
  694. * blank the display in all modes.
  695. */
  696. static int sa1100fb_blank(int blank, struct fb_info *info)
  697. {
  698. struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
  699. int i;
  700. DPRINTK("sa1100fb_blank: blank=%d\n", blank);
  701. switch (blank) {
  702. case FB_BLANK_POWERDOWN:
  703. case FB_BLANK_VSYNC_SUSPEND:
  704. case FB_BLANK_HSYNC_SUSPEND:
  705. case FB_BLANK_NORMAL:
  706. if (fbi->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR ||
  707. fbi->fb.fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)
  708. for (i = 0; i < fbi->palette_size; i++)
  709. sa1100fb_setpalettereg(i, 0, 0, 0, 0, info);
  710. sa1100fb_schedule_work(fbi, C_DISABLE);
  711. break;
  712. case FB_BLANK_UNBLANK:
  713. if (fbi->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR ||
  714. fbi->fb.fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)
  715. fb_set_cmap(&fbi->fb.cmap, info);
  716. sa1100fb_schedule_work(fbi, C_ENABLE);
  717. }
  718. return 0;
  719. }
  720. static int sa1100fb_mmap(struct fb_info *info,
  721. struct vm_area_struct *vma)
  722. {
  723. struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
  724. unsigned long start, len, off = vma->vm_pgoff << PAGE_SHIFT;
  725. if (off < info->fix.smem_len) {
  726. vma->vm_pgoff += 1; /* skip over the palette */
  727. return dma_mmap_writecombine(fbi->dev, vma, fbi->map_cpu,
  728. fbi->map_dma, fbi->map_size);
  729. }
  730. start = info->fix.mmio_start;
  731. len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.mmio_len);
  732. if ((vma->vm_end - vma->vm_start + off) > len)
  733. return -EINVAL;
  734. off += start & PAGE_MASK;
  735. vma->vm_pgoff = off >> PAGE_SHIFT;
  736. vma->vm_flags |= VM_IO;
  737. vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  738. return io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
  739. vma->vm_end - vma->vm_start,
  740. vma->vm_page_prot);
  741. }
  742. static struct fb_ops sa1100fb_ops = {
  743. .owner = THIS_MODULE,
  744. .fb_check_var = sa1100fb_check_var,
  745. .fb_set_par = sa1100fb_set_par,
  746. // .fb_set_cmap = sa1100fb_set_cmap,
  747. .fb_setcolreg = sa1100fb_setcolreg,
  748. .fb_fillrect = cfb_fillrect,
  749. .fb_copyarea = cfb_copyarea,
  750. .fb_imageblit = cfb_imageblit,
  751. .fb_blank = sa1100fb_blank,
  752. .fb_mmap = sa1100fb_mmap,
  753. };
  754. /*
  755. * Calculate the PCD value from the clock rate (in picoseconds).
  756. * We take account of the PPCR clock setting.
  757. */
  758. static inline unsigned int get_pcd(unsigned int pixclock, unsigned int cpuclock)
  759. {
  760. unsigned int pcd = cpuclock / 100;
  761. pcd *= pixclock;
  762. pcd /= 10000000;
  763. return pcd + 1; /* make up for integer math truncations */
  764. }
  765. /*
  766. * sa1100fb_activate_var():
  767. * Configures LCD Controller based on entries in var parameter. Settings are
  768. * only written to the controller if changes were made.
  769. */
  770. static int sa1100fb_activate_var(struct fb_var_screeninfo *var, struct sa1100fb_info *fbi)
  771. {
  772. struct sa1100fb_lcd_reg new_regs;
  773. u_int half_screen_size, yres, pcd;
  774. u_long flags;
  775. DPRINTK("Configuring SA1100 LCD\n");
  776. DPRINTK("var: xres=%d hslen=%d lm=%d rm=%d\n",
  777. var->xres, var->hsync_len,
  778. var->left_margin, var->right_margin);
  779. DPRINTK("var: yres=%d vslen=%d um=%d bm=%d\n",
  780. var->yres, var->vsync_len,
  781. var->upper_margin, var->lower_margin);
  782. #if DEBUG_VAR
  783. if (var->xres < 16 || var->xres > 1024)
  784. printk(KERN_ERR "%s: invalid xres %d\n",
  785. fbi->fb.fix.id, var->xres);
  786. if (var->hsync_len < 1 || var->hsync_len > 64)
  787. printk(KERN_ERR "%s: invalid hsync_len %d\n",
  788. fbi->fb.fix.id, var->hsync_len);
  789. if (var->left_margin < 1 || var->left_margin > 255)
  790. printk(KERN_ERR "%s: invalid left_margin %d\n",
  791. fbi->fb.fix.id, var->left_margin);
  792. if (var->right_margin < 1 || var->right_margin > 255)
  793. printk(KERN_ERR "%s: invalid right_margin %d\n",
  794. fbi->fb.fix.id, var->right_margin);
  795. if (var->yres < 1 || var->yres > 1024)
  796. printk(KERN_ERR "%s: invalid yres %d\n",
  797. fbi->fb.fix.id, var->yres);
  798. if (var->vsync_len < 1 || var->vsync_len > 64)
  799. printk(KERN_ERR "%s: invalid vsync_len %d\n",
  800. fbi->fb.fix.id, var->vsync_len);
  801. if (var->upper_margin < 0 || var->upper_margin > 255)
  802. printk(KERN_ERR "%s: invalid upper_margin %d\n",
  803. fbi->fb.fix.id, var->upper_margin);
  804. if (var->lower_margin < 0 || var->lower_margin > 255)
  805. printk(KERN_ERR "%s: invalid lower_margin %d\n",
  806. fbi->fb.fix.id, var->lower_margin);
  807. #endif
  808. new_regs.lccr0 = fbi->lccr0 |
  809. LCCR0_LEN | LCCR0_LDM | LCCR0_BAM |
  810. LCCR0_ERM | LCCR0_LtlEnd | LCCR0_DMADel(0);
  811. new_regs.lccr1 =
  812. LCCR1_DisWdth(var->xres) +
  813. LCCR1_HorSnchWdth(var->hsync_len) +
  814. LCCR1_BegLnDel(var->left_margin) +
  815. LCCR1_EndLnDel(var->right_margin);
  816. /*
  817. * If we have a dual scan LCD, then we need to halve
  818. * the YRES parameter.
  819. */
  820. yres = var->yres;
  821. if (fbi->lccr0 & LCCR0_Dual)
  822. yres /= 2;
  823. new_regs.lccr2 =
  824. LCCR2_DisHght(yres) +
  825. LCCR2_VrtSnchWdth(var->vsync_len) +
  826. LCCR2_BegFrmDel(var->upper_margin) +
  827. LCCR2_EndFrmDel(var->lower_margin);
  828. pcd = get_pcd(var->pixclock, cpufreq_get(0));
  829. new_regs.lccr3 = LCCR3_PixClkDiv(pcd) | fbi->lccr3 |
  830. (var->sync & FB_SYNC_HOR_HIGH_ACT ? LCCR3_HorSnchH : LCCR3_HorSnchL) |
  831. (var->sync & FB_SYNC_VERT_HIGH_ACT ? LCCR3_VrtSnchH : LCCR3_VrtSnchL);
  832. DPRINTK("nlccr0 = 0x%08lx\n", new_regs.lccr0);
  833. DPRINTK("nlccr1 = 0x%08lx\n", new_regs.lccr1);
  834. DPRINTK("nlccr2 = 0x%08lx\n", new_regs.lccr2);
  835. DPRINTK("nlccr3 = 0x%08lx\n", new_regs.lccr3);
  836. half_screen_size = var->bits_per_pixel;
  837. half_screen_size = half_screen_size * var->xres * var->yres / 16;
  838. /* Update shadow copy atomically */
  839. local_irq_save(flags);
  840. fbi->dbar1 = fbi->palette_dma;
  841. fbi->dbar2 = fbi->screen_dma + half_screen_size;
  842. fbi->reg_lccr0 = new_regs.lccr0;
  843. fbi->reg_lccr1 = new_regs.lccr1;
  844. fbi->reg_lccr2 = new_regs.lccr2;
  845. fbi->reg_lccr3 = new_regs.lccr3;
  846. local_irq_restore(flags);
  847. /*
  848. * Only update the registers if the controller is enabled
  849. * and something has changed.
  850. */
  851. if ((LCCR0 != fbi->reg_lccr0) || (LCCR1 != fbi->reg_lccr1) ||
  852. (LCCR2 != fbi->reg_lccr2) || (LCCR3 != fbi->reg_lccr3) ||
  853. (DBAR1 != fbi->dbar1) || (DBAR2 != fbi->dbar2))
  854. sa1100fb_schedule_work(fbi, C_REENABLE);
  855. return 0;
  856. }
  857. /*
  858. * NOTE! The following functions are purely helpers for set_ctrlr_state.
  859. * Do not call them directly; set_ctrlr_state does the correct serialisation
  860. * to ensure that things happen in the right way 100% of time time.
  861. * -- rmk
  862. */
  863. static inline void __sa1100fb_backlight_power(struct sa1100fb_info *fbi, int on)
  864. {
  865. DPRINTK("backlight o%s\n", on ? "n" : "ff");
  866. if (sa1100fb_backlight_power)
  867. sa1100fb_backlight_power(on);
  868. }
  869. static inline void __sa1100fb_lcd_power(struct sa1100fb_info *fbi, int on)
  870. {
  871. DPRINTK("LCD power o%s\n", on ? "n" : "ff");
  872. if (sa1100fb_lcd_power)
  873. sa1100fb_lcd_power(on);
  874. }
  875. static void sa1100fb_setup_gpio(struct sa1100fb_info *fbi)
  876. {
  877. u_int mask = 0;
  878. /*
  879. * Enable GPIO<9:2> for LCD use if:
  880. * 1. Active display, or
  881. * 2. Color Dual Passive display
  882. *
  883. * see table 11.8 on page 11-27 in the SA1100 manual
  884. * -- Erik.
  885. *
  886. * SA1110 spec update nr. 25 says we can and should
  887. * clear LDD15 to 12 for 4 or 8bpp modes with active
  888. * panels.
  889. */
  890. if ((fbi->reg_lccr0 & LCCR0_CMS) == LCCR0_Color &&
  891. (fbi->reg_lccr0 & (LCCR0_Dual|LCCR0_Act)) != 0) {
  892. mask = GPIO_LDD11 | GPIO_LDD10 | GPIO_LDD9 | GPIO_LDD8;
  893. if (fbi->fb.var.bits_per_pixel > 8 ||
  894. (fbi->reg_lccr0 & (LCCR0_Dual|LCCR0_Act)) == LCCR0_Dual)
  895. mask |= GPIO_LDD15 | GPIO_LDD14 | GPIO_LDD13 | GPIO_LDD12;
  896. }
  897. if (mask) {
  898. GPDR |= mask;
  899. GAFR |= mask;
  900. }
  901. }
  902. static void sa1100fb_enable_controller(struct sa1100fb_info *fbi)
  903. {
  904. DPRINTK("Enabling LCD controller\n");
  905. /*
  906. * Make sure the mode bits are present in the first palette entry
  907. */
  908. fbi->palette_cpu[0] &= 0xcfff;
  909. fbi->palette_cpu[0] |= palette_pbs(&fbi->fb.var);
  910. /* Sequence from 11.7.10 */
  911. LCCR3 = fbi->reg_lccr3;
  912. LCCR2 = fbi->reg_lccr2;
  913. LCCR1 = fbi->reg_lccr1;
  914. LCCR0 = fbi->reg_lccr0 & ~LCCR0_LEN;
  915. DBAR1 = fbi->dbar1;
  916. DBAR2 = fbi->dbar2;
  917. LCCR0 |= LCCR0_LEN;
  918. if (machine_is_shannon()) {
  919. GPDR |= SHANNON_GPIO_DISP_EN;
  920. GPSR |= SHANNON_GPIO_DISP_EN;
  921. }
  922. DPRINTK("DBAR1 = 0x%08x\n", DBAR1);
  923. DPRINTK("DBAR2 = 0x%08x\n", DBAR2);
  924. DPRINTK("LCCR0 = 0x%08x\n", LCCR0);
  925. DPRINTK("LCCR1 = 0x%08x\n", LCCR1);
  926. DPRINTK("LCCR2 = 0x%08x\n", LCCR2);
  927. DPRINTK("LCCR3 = 0x%08x\n", LCCR3);
  928. }
  929. static void sa1100fb_disable_controller(struct sa1100fb_info *fbi)
  930. {
  931. DECLARE_WAITQUEUE(wait, current);
  932. DPRINTK("Disabling LCD controller\n");
  933. if (machine_is_shannon()) {
  934. GPCR |= SHANNON_GPIO_DISP_EN;
  935. }
  936. set_current_state(TASK_UNINTERRUPTIBLE);
  937. add_wait_queue(&fbi->ctrlr_wait, &wait);
  938. LCSR = 0xffffffff; /* Clear LCD Status Register */
  939. LCCR0 &= ~LCCR0_LDM; /* Enable LCD Disable Done Interrupt */
  940. LCCR0 &= ~LCCR0_LEN; /* Disable LCD Controller */
  941. schedule_timeout(20 * HZ / 1000);
  942. remove_wait_queue(&fbi->ctrlr_wait, &wait);
  943. }
  944. /*
  945. * sa1100fb_handle_irq: Handle 'LCD DONE' interrupts.
  946. */
  947. static irqreturn_t sa1100fb_handle_irq(int irq, void *dev_id)
  948. {
  949. struct sa1100fb_info *fbi = dev_id;
  950. unsigned int lcsr = LCSR;
  951. if (lcsr & LCSR_LDD) {
  952. LCCR0 |= LCCR0_LDM;
  953. wake_up(&fbi->ctrlr_wait);
  954. }
  955. LCSR = lcsr;
  956. return IRQ_HANDLED;
  957. }
  958. /*
  959. * This function must be called from task context only, since it will
  960. * sleep when disabling the LCD controller, or if we get two contending
  961. * processes trying to alter state.
  962. */
  963. static void set_ctrlr_state(struct sa1100fb_info *fbi, u_int state)
  964. {
  965. u_int old_state;
  966. down(&fbi->ctrlr_sem);
  967. old_state = fbi->state;
  968. /*
  969. * Hack around fbcon initialisation.
  970. */
  971. if (old_state == C_STARTUP && state == C_REENABLE)
  972. state = C_ENABLE;
  973. switch (state) {
  974. case C_DISABLE_CLKCHANGE:
  975. /*
  976. * Disable controller for clock change. If the
  977. * controller is already disabled, then do nothing.
  978. */
  979. if (old_state != C_DISABLE && old_state != C_DISABLE_PM) {
  980. fbi->state = state;
  981. sa1100fb_disable_controller(fbi);
  982. }
  983. break;
  984. case C_DISABLE_PM:
  985. case C_DISABLE:
  986. /*
  987. * Disable controller
  988. */
  989. if (old_state != C_DISABLE) {
  990. fbi->state = state;
  991. __sa1100fb_backlight_power(fbi, 0);
  992. if (old_state != C_DISABLE_CLKCHANGE)
  993. sa1100fb_disable_controller(fbi);
  994. __sa1100fb_lcd_power(fbi, 0);
  995. }
  996. break;
  997. case C_ENABLE_CLKCHANGE:
  998. /*
  999. * Enable the controller after clock change. Only
  1000. * do this if we were disabled for the clock change.
  1001. */
  1002. if (old_state == C_DISABLE_CLKCHANGE) {
  1003. fbi->state = C_ENABLE;
  1004. sa1100fb_enable_controller(fbi);
  1005. }
  1006. break;
  1007. case C_REENABLE:
  1008. /*
  1009. * Re-enable the controller only if it was already
  1010. * enabled. This is so we reprogram the control
  1011. * registers.
  1012. */
  1013. if (old_state == C_ENABLE) {
  1014. sa1100fb_disable_controller(fbi);
  1015. sa1100fb_setup_gpio(fbi);
  1016. sa1100fb_enable_controller(fbi);
  1017. }
  1018. break;
  1019. case C_ENABLE_PM:
  1020. /*
  1021. * Re-enable the controller after PM. This is not
  1022. * perfect - think about the case where we were doing
  1023. * a clock change, and we suspended half-way through.
  1024. */
  1025. if (old_state != C_DISABLE_PM)
  1026. break;
  1027. /* fall through */
  1028. case C_ENABLE:
  1029. /*
  1030. * Power up the LCD screen, enable controller, and
  1031. * turn on the backlight.
  1032. */
  1033. if (old_state != C_ENABLE) {
  1034. fbi->state = C_ENABLE;
  1035. sa1100fb_setup_gpio(fbi);
  1036. __sa1100fb_lcd_power(fbi, 1);
  1037. sa1100fb_enable_controller(fbi);
  1038. __sa1100fb_backlight_power(fbi, 1);
  1039. }
  1040. break;
  1041. }
  1042. up(&fbi->ctrlr_sem);
  1043. }
  1044. /*
  1045. * Our LCD controller task (which is called when we blank or unblank)
  1046. * via keventd.
  1047. */
  1048. static void sa1100fb_task(struct work_struct *w)
  1049. {
  1050. struct sa1100fb_info *fbi = container_of(w, struct sa1100fb_info, task);
  1051. u_int state = xchg(&fbi->task_state, -1);
  1052. set_ctrlr_state(fbi, state);
  1053. }
  1054. #ifdef CONFIG_CPU_FREQ
  1055. /*
  1056. * Calculate the minimum DMA period over all displays that we own.
  1057. * This, together with the SDRAM bandwidth defines the slowest CPU
  1058. * frequency that can be selected.
  1059. */
  1060. static unsigned int sa1100fb_min_dma_period(struct sa1100fb_info *fbi)
  1061. {
  1062. #if 0
  1063. unsigned int min_period = (unsigned int)-1;
  1064. int i;
  1065. for (i = 0; i < MAX_NR_CONSOLES; i++) {
  1066. struct display *disp = &fb_display[i];
  1067. unsigned int period;
  1068. /*
  1069. * Do we own this display?
  1070. */
  1071. if (disp->fb_info != &fbi->fb)
  1072. continue;
  1073. /*
  1074. * Ok, calculate its DMA period
  1075. */
  1076. period = sa1100fb_display_dma_period(&disp->var);
  1077. if (period < min_period)
  1078. min_period = period;
  1079. }
  1080. return min_period;
  1081. #else
  1082. /*
  1083. * FIXME: we need to verify _all_ consoles.
  1084. */
  1085. return sa1100fb_display_dma_period(&fbi->fb.var);
  1086. #endif
  1087. }
  1088. /*
  1089. * CPU clock speed change handler. We need to adjust the LCD timing
  1090. * parameters when the CPU clock is adjusted by the power management
  1091. * subsystem.
  1092. */
  1093. static int
  1094. sa1100fb_freq_transition(struct notifier_block *nb, unsigned long val,
  1095. void *data)
  1096. {
  1097. struct sa1100fb_info *fbi = TO_INF(nb, freq_transition);
  1098. struct cpufreq_freqs *f = data;
  1099. u_int pcd;
  1100. switch (val) {
  1101. case CPUFREQ_PRECHANGE:
  1102. set_ctrlr_state(fbi, C_DISABLE_CLKCHANGE);
  1103. break;
  1104. case CPUFREQ_POSTCHANGE:
  1105. pcd = get_pcd(fbi->fb.var.pixclock, f->new);
  1106. fbi->reg_lccr3 = (fbi->reg_lccr3 & ~0xff) | LCCR3_PixClkDiv(pcd);
  1107. set_ctrlr_state(fbi, C_ENABLE_CLKCHANGE);
  1108. break;
  1109. }
  1110. return 0;
  1111. }
  1112. static int
  1113. sa1100fb_freq_policy(struct notifier_block *nb, unsigned long val,
  1114. void *data)
  1115. {
  1116. struct sa1100fb_info *fbi = TO_INF(nb, freq_policy);
  1117. struct cpufreq_policy *policy = data;
  1118. switch (val) {
  1119. case CPUFREQ_ADJUST:
  1120. case CPUFREQ_INCOMPATIBLE:
  1121. printk(KERN_DEBUG "min dma period: %d ps, "
  1122. "new clock %d kHz\n", sa1100fb_min_dma_period(fbi),
  1123. policy->max);
  1124. /* todo: fill in min/max values */
  1125. break;
  1126. case CPUFREQ_NOTIFY:
  1127. do {} while(0);
  1128. /* todo: panic if min/max values aren't fulfilled
  1129. * [can't really happen unless there's a bug in the
  1130. * CPU policy verififcation process *
  1131. */
  1132. break;
  1133. }
  1134. return 0;
  1135. }
  1136. #endif
  1137. #ifdef CONFIG_PM
  1138. /*
  1139. * Power management hooks. Note that we won't be called from IRQ context,
  1140. * unlike the blank functions above, so we may sleep.
  1141. */
  1142. static int sa1100fb_suspend(struct platform_device *dev, pm_message_t state)
  1143. {
  1144. struct sa1100fb_info *fbi = platform_get_drvdata(dev);
  1145. set_ctrlr_state(fbi, C_DISABLE_PM);
  1146. return 0;
  1147. }
  1148. static int sa1100fb_resume(struct platform_device *dev)
  1149. {
  1150. struct sa1100fb_info *fbi = platform_get_drvdata(dev);
  1151. set_ctrlr_state(fbi, C_ENABLE_PM);
  1152. return 0;
  1153. }
  1154. #else
  1155. #define sa1100fb_suspend NULL
  1156. #define sa1100fb_resume NULL
  1157. #endif
  1158. /*
  1159. * sa1100fb_map_video_memory():
  1160. * Allocates the DRAM memory for the frame buffer. This buffer is
  1161. * remapped into a non-cached, non-buffered, memory region to
  1162. * allow palette and pixel writes to occur without flushing the
  1163. * cache. Once this area is remapped, all virtual memory
  1164. * access to the video memory should occur at the new region.
  1165. */
  1166. static int __init sa1100fb_map_video_memory(struct sa1100fb_info *fbi)
  1167. {
  1168. /*
  1169. * We reserve one page for the palette, plus the size
  1170. * of the framebuffer.
  1171. */
  1172. fbi->map_size = PAGE_ALIGN(fbi->fb.fix.smem_len + PAGE_SIZE);
  1173. fbi->map_cpu = dma_alloc_writecombine(fbi->dev, fbi->map_size,
  1174. &fbi->map_dma, GFP_KERNEL);
  1175. if (fbi->map_cpu) {
  1176. fbi->fb.screen_base = fbi->map_cpu + PAGE_SIZE;
  1177. fbi->screen_dma = fbi->map_dma + PAGE_SIZE;
  1178. /*
  1179. * FIXME: this is actually the wrong thing to place in
  1180. * smem_start. But fbdev suffers from the problem that
  1181. * it needs an API which doesn't exist (in this case,
  1182. * dma_writecombine_mmap)
  1183. */
  1184. fbi->fb.fix.smem_start = fbi->screen_dma;
  1185. }
  1186. return fbi->map_cpu ? 0 : -ENOMEM;
  1187. }
  1188. /* Fake monspecs to fill in fbinfo structure */
  1189. static struct fb_monspecs monspecs __initdata = {
  1190. .hfmin = 30000,
  1191. .hfmax = 70000,
  1192. .vfmin = 50,
  1193. .vfmax = 65,
  1194. };
  1195. static struct sa1100fb_info * __init sa1100fb_init_fbinfo(struct device *dev)
  1196. {
  1197. struct sa1100fb_mach_info *inf;
  1198. struct sa1100fb_info *fbi;
  1199. fbi = kmalloc(sizeof(struct sa1100fb_info) + sizeof(u32) * 16,
  1200. GFP_KERNEL);
  1201. if (!fbi)
  1202. return NULL;
  1203. memset(fbi, 0, sizeof(struct sa1100fb_info));
  1204. fbi->dev = dev;
  1205. strcpy(fbi->fb.fix.id, SA1100_NAME);
  1206. fbi->fb.fix.type = FB_TYPE_PACKED_PIXELS;
  1207. fbi->fb.fix.type_aux = 0;
  1208. fbi->fb.fix.xpanstep = 0;
  1209. fbi->fb.fix.ypanstep = 0;
  1210. fbi->fb.fix.ywrapstep = 0;
  1211. fbi->fb.fix.accel = FB_ACCEL_NONE;
  1212. fbi->fb.var.nonstd = 0;
  1213. fbi->fb.var.activate = FB_ACTIVATE_NOW;
  1214. fbi->fb.var.height = -1;
  1215. fbi->fb.var.width = -1;
  1216. fbi->fb.var.accel_flags = 0;
  1217. fbi->fb.var.vmode = FB_VMODE_NONINTERLACED;
  1218. fbi->fb.fbops = &sa1100fb_ops;
  1219. fbi->fb.flags = FBINFO_DEFAULT;
  1220. fbi->fb.monspecs = monspecs;
  1221. fbi->fb.pseudo_palette = (fbi + 1);
  1222. fbi->rgb[RGB_8] = &rgb_8;
  1223. fbi->rgb[RGB_16] = &def_rgb_16;
  1224. inf = sa1100fb_get_machine_info(fbi);
  1225. /*
  1226. * People just don't seem to get this. We don't support
  1227. * anything but correct entries now, so panic if someone
  1228. * does something stupid.
  1229. */
  1230. if (inf->lccr3 & (LCCR3_VrtSnchL|LCCR3_HorSnchL|0xff) ||
  1231. inf->pixclock == 0)
  1232. panic("sa1100fb error: invalid LCCR3 fields set or zero "
  1233. "pixclock.");
  1234. fbi->max_xres = inf->xres;
  1235. fbi->fb.var.xres = inf->xres;
  1236. fbi->fb.var.xres_virtual = inf->xres;
  1237. fbi->max_yres = inf->yres;
  1238. fbi->fb.var.yres = inf->yres;
  1239. fbi->fb.var.yres_virtual = inf->yres;
  1240. fbi->max_bpp = inf->bpp;
  1241. fbi->fb.var.bits_per_pixel = inf->bpp;
  1242. fbi->fb.var.pixclock = inf->pixclock;
  1243. fbi->fb.var.hsync_len = inf->hsync_len;
  1244. fbi->fb.var.left_margin = inf->left_margin;
  1245. fbi->fb.var.right_margin = inf->right_margin;
  1246. fbi->fb.var.vsync_len = inf->vsync_len;
  1247. fbi->fb.var.upper_margin = inf->upper_margin;
  1248. fbi->fb.var.lower_margin = inf->lower_margin;
  1249. fbi->fb.var.sync = inf->sync;
  1250. fbi->fb.var.grayscale = inf->cmap_greyscale;
  1251. fbi->cmap_inverse = inf->cmap_inverse;
  1252. fbi->cmap_static = inf->cmap_static;
  1253. fbi->lccr0 = inf->lccr0;
  1254. fbi->lccr3 = inf->lccr3;
  1255. fbi->state = C_STARTUP;
  1256. fbi->task_state = (u_char)-1;
  1257. fbi->fb.fix.smem_len = fbi->max_xres * fbi->max_yres *
  1258. fbi->max_bpp / 8;
  1259. init_waitqueue_head(&fbi->ctrlr_wait);
  1260. INIT_WORK(&fbi->task, sa1100fb_task);
  1261. init_MUTEX(&fbi->ctrlr_sem);
  1262. return fbi;
  1263. }
  1264. static int __init sa1100fb_probe(struct platform_device *pdev)
  1265. {
  1266. struct sa1100fb_info *fbi;
  1267. int ret, irq;
  1268. irq = platform_get_irq(pdev, 0);
  1269. if (irq < 0)
  1270. return -EINVAL;
  1271. if (!request_mem_region(0xb0100000, 0x10000, "LCD"))
  1272. return -EBUSY;
  1273. fbi = sa1100fb_init_fbinfo(&pdev->dev);
  1274. ret = -ENOMEM;
  1275. if (!fbi)
  1276. goto failed;
  1277. /* Initialize video memory */
  1278. ret = sa1100fb_map_video_memory(fbi);
  1279. if (ret)
  1280. goto failed;
  1281. ret = request_irq(irq, sa1100fb_handle_irq, IRQF_DISABLED,
  1282. "LCD", fbi);
  1283. if (ret) {
  1284. printk(KERN_ERR "sa1100fb: request_irq failed: %d\n", ret);
  1285. goto failed;
  1286. }
  1287. #ifdef ASSABET_PAL_VIDEO
  1288. if (machine_is_assabet())
  1289. ASSABET_BCR_clear(ASSABET_BCR_LCD_ON);
  1290. #endif
  1291. /*
  1292. * This makes sure that our colour bitfield
  1293. * descriptors are correctly initialised.
  1294. */
  1295. sa1100fb_check_var(&fbi->fb.var, &fbi->fb);
  1296. platform_set_drvdata(pdev, fbi);
  1297. ret = register_framebuffer(&fbi->fb);
  1298. if (ret < 0)
  1299. goto err_free_irq;
  1300. #ifdef CONFIG_CPU_FREQ
  1301. fbi->freq_transition.notifier_call = sa1100fb_freq_transition;
  1302. fbi->freq_policy.notifier_call = sa1100fb_freq_policy;
  1303. cpufreq_register_notifier(&fbi->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
  1304. cpufreq_register_notifier(&fbi->freq_policy, CPUFREQ_POLICY_NOTIFIER);
  1305. #endif
  1306. /* This driver cannot be unloaded at the moment */
  1307. return 0;
  1308. err_free_irq:
  1309. free_irq(irq, fbi);
  1310. failed:
  1311. platform_set_drvdata(pdev, NULL);
  1312. kfree(fbi);
  1313. release_mem_region(0xb0100000, 0x10000);
  1314. return ret;
  1315. }
  1316. static struct platform_driver sa1100fb_driver = {
  1317. .probe = sa1100fb_probe,
  1318. .suspend = sa1100fb_suspend,
  1319. .resume = sa1100fb_resume,
  1320. .driver = {
  1321. .name = "sa11x0-fb",
  1322. },
  1323. };
  1324. int __init sa1100fb_init(void)
  1325. {
  1326. if (fb_get_options("sa1100fb", NULL))
  1327. return -ENODEV;
  1328. return platform_driver_register(&sa1100fb_driver);
  1329. }
  1330. int __init sa1100fb_setup(char *options)
  1331. {
  1332. #if 0
  1333. char *this_opt;
  1334. if (!options || !*options)
  1335. return 0;
  1336. while ((this_opt = strsep(&options, ",")) != NULL) {
  1337. if (!strncmp(this_opt, "bpp:", 4))
  1338. current_par.max_bpp =
  1339. simple_strtoul(this_opt + 4, NULL, 0);
  1340. if (!strncmp(this_opt, "lccr0:", 6))
  1341. lcd_shadow.lccr0 =
  1342. simple_strtoul(this_opt + 6, NULL, 0);
  1343. if (!strncmp(this_opt, "lccr1:", 6)) {
  1344. lcd_shadow.lccr1 =
  1345. simple_strtoul(this_opt + 6, NULL, 0);
  1346. current_par.max_xres =
  1347. (lcd_shadow.lccr1 & 0x3ff) + 16;
  1348. }
  1349. if (!strncmp(this_opt, "lccr2:", 6)) {
  1350. lcd_shadow.lccr2 =
  1351. simple_strtoul(this_opt + 6, NULL, 0);
  1352. current_par.max_yres =
  1353. (lcd_shadow.
  1354. lccr0 & LCCR0_SDS) ? ((lcd_shadow.
  1355. lccr2 & 0x3ff) +
  1356. 1) *
  1357. 2 : ((lcd_shadow.lccr2 & 0x3ff) + 1);
  1358. }
  1359. if (!strncmp(this_opt, "lccr3:", 6))
  1360. lcd_shadow.lccr3 =
  1361. simple_strtoul(this_opt + 6, NULL, 0);
  1362. }
  1363. #endif
  1364. return 0;
  1365. }
  1366. module_init(sa1100fb_init);
  1367. MODULE_DESCRIPTION("StrongARM-1100/1110 framebuffer driver");
  1368. MODULE_LICENSE("GPL");