sa1100fb.c 42 KB

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