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/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. /*
  526. * sa1100fb_display_dma_period()
  527. * Calculate the minimum period (in picoseconds) between two DMA
  528. * requests for the LCD controller. If we hit this, it means we're
  529. * doing nothing but LCD DMA.
  530. */
  531. static inline unsigned int sa1100fb_display_dma_period(struct fb_var_screeninfo *var)
  532. {
  533. /*
  534. * Period = pixclock * bits_per_byte * bytes_per_transfer
  535. * / memory_bits_per_pixel;
  536. */
  537. return var->pixclock * 8 * 16 / var->bits_per_pixel;
  538. }
  539. /*
  540. * sa1100fb_check_var():
  541. * Round up in the following order: bits_per_pixel, xres,
  542. * yres, xres_virtual, yres_virtual, xoffset, yoffset, grayscale,
  543. * bitfields, horizontal timing, vertical timing.
  544. */
  545. static int
  546. sa1100fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  547. {
  548. struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
  549. int rgbidx;
  550. if (var->xres < MIN_XRES)
  551. var->xres = MIN_XRES;
  552. if (var->yres < MIN_YRES)
  553. var->yres = MIN_YRES;
  554. if (var->xres > fbi->max_xres)
  555. var->xres = fbi->max_xres;
  556. if (var->yres > fbi->max_yres)
  557. var->yres = fbi->max_yres;
  558. var->xres_virtual = max(var->xres_virtual, var->xres);
  559. var->yres_virtual = max(var->yres_virtual, var->yres);
  560. DPRINTK("var->bits_per_pixel=%d\n", var->bits_per_pixel);
  561. switch (var->bits_per_pixel) {
  562. case 4:
  563. rgbidx = RGB_8;
  564. break;
  565. case 8:
  566. rgbidx = RGB_8;
  567. break;
  568. case 16:
  569. rgbidx = RGB_16;
  570. break;
  571. default:
  572. return -EINVAL;
  573. }
  574. /*
  575. * Copy the RGB parameters for this display
  576. * from the machine specific parameters.
  577. */
  578. var->red = fbi->rgb[rgbidx]->red;
  579. var->green = fbi->rgb[rgbidx]->green;
  580. var->blue = fbi->rgb[rgbidx]->blue;
  581. var->transp = fbi->rgb[rgbidx]->transp;
  582. DPRINTK("RGBT length = %d:%d:%d:%d\n",
  583. var->red.length, var->green.length, var->blue.length,
  584. var->transp.length);
  585. DPRINTK("RGBT offset = %d:%d:%d:%d\n",
  586. var->red.offset, var->green.offset, var->blue.offset,
  587. var->transp.offset);
  588. #ifdef CONFIG_CPU_FREQ
  589. printk(KERN_DEBUG "dma period = %d ps, clock = %d kHz\n",
  590. sa1100fb_display_dma_period(var),
  591. cpufreq_get(smp_processor_id()));
  592. #endif
  593. return 0;
  594. }
  595. static inline void sa1100fb_set_truecolor(u_int is_true_color)
  596. {
  597. if (machine_is_assabet()) {
  598. #if 1 // phase 4 or newer Assabet's
  599. if (is_true_color)
  600. ASSABET_BCR_set(ASSABET_BCR_LCD_12RGB);
  601. else
  602. ASSABET_BCR_clear(ASSABET_BCR_LCD_12RGB);
  603. #else
  604. // older Assabet's
  605. if (is_true_color)
  606. ASSABET_BCR_clear(ASSABET_BCR_LCD_12RGB);
  607. else
  608. ASSABET_BCR_set(ASSABET_BCR_LCD_12RGB);
  609. #endif
  610. }
  611. }
  612. /*
  613. * sa1100fb_set_par():
  614. * Set the user defined part of the display for the specified console
  615. */
  616. static int sa1100fb_set_par(struct fb_info *info)
  617. {
  618. struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
  619. struct fb_var_screeninfo *var = &info->var;
  620. unsigned long palette_mem_size;
  621. DPRINTK("set_par\n");
  622. if (var->bits_per_pixel == 16)
  623. fbi->fb.fix.visual = FB_VISUAL_TRUECOLOR;
  624. else if (!fbi->cmap_static)
  625. fbi->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
  626. else {
  627. /*
  628. * Some people have weird ideas about wanting static
  629. * pseudocolor maps. I suspect their user space
  630. * applications are broken.
  631. */
  632. fbi->fb.fix.visual = FB_VISUAL_STATIC_PSEUDOCOLOR;
  633. }
  634. fbi->fb.fix.line_length = var->xres_virtual *
  635. var->bits_per_pixel / 8;
  636. fbi->palette_size = var->bits_per_pixel == 8 ? 256 : 16;
  637. palette_mem_size = fbi->palette_size * sizeof(u16);
  638. DPRINTK("palette_mem_size = 0x%08lx\n", (u_long) palette_mem_size);
  639. fbi->palette_cpu = (u16 *)(fbi->map_cpu + PAGE_SIZE - palette_mem_size);
  640. fbi->palette_dma = fbi->map_dma + PAGE_SIZE - palette_mem_size;
  641. /*
  642. * Set (any) board control register to handle new color depth
  643. */
  644. sa1100fb_set_truecolor(fbi->fb.fix.visual == FB_VISUAL_TRUECOLOR);
  645. sa1100fb_activate_var(var, fbi);
  646. return 0;
  647. }
  648. #if 0
  649. static int
  650. sa1100fb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
  651. struct fb_info *info)
  652. {
  653. struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
  654. /*
  655. * Make sure the user isn't doing something stupid.
  656. */
  657. if (!kspc && (fbi->fb.var.bits_per_pixel == 16 || fbi->cmap_static))
  658. return -EINVAL;
  659. return gen_set_cmap(cmap, kspc, con, info);
  660. }
  661. #endif
  662. /*
  663. * Formal definition of the VESA spec:
  664. * On
  665. * This refers to the state of the display when it is in full operation
  666. * Stand-By
  667. * This defines an optional operating state of minimal power reduction with
  668. * the shortest recovery time
  669. * Suspend
  670. * This refers to a level of power management in which substantial power
  671. * reduction is achieved by the display. The display can have a longer
  672. * recovery time from this state than from the Stand-by state
  673. * Off
  674. * This indicates that the display is consuming the lowest level of power
  675. * and is non-operational. Recovery from this state may optionally require
  676. * the user to manually power on the monitor
  677. *
  678. * Now, the fbdev driver adds an additional state, (blank), where they
  679. * turn off the video (maybe by colormap tricks), but don't mess with the
  680. * video itself: think of it semantically between on and Stand-By.
  681. *
  682. * So here's what we should do in our fbdev blank routine:
  683. *
  684. * VESA_NO_BLANKING (mode 0) Video on, front/back light on
  685. * VESA_VSYNC_SUSPEND (mode 1) Video on, front/back light off
  686. * VESA_HSYNC_SUSPEND (mode 2) Video on, front/back light off
  687. * VESA_POWERDOWN (mode 3) Video off, front/back light off
  688. *
  689. * This will match the matrox implementation.
  690. */
  691. /*
  692. * sa1100fb_blank():
  693. * Blank the display by setting all palette values to zero. Note, the
  694. * 12 and 16 bpp modes don't really use the palette, so this will not
  695. * blank the display in all modes.
  696. */
  697. static int sa1100fb_blank(int blank, struct fb_info *info)
  698. {
  699. struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
  700. int i;
  701. DPRINTK("sa1100fb_blank: blank=%d\n", blank);
  702. switch (blank) {
  703. case FB_BLANK_POWERDOWN:
  704. case FB_BLANK_VSYNC_SUSPEND:
  705. case FB_BLANK_HSYNC_SUSPEND:
  706. case FB_BLANK_NORMAL:
  707. if (fbi->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR ||
  708. fbi->fb.fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)
  709. for (i = 0; i < fbi->palette_size; i++)
  710. sa1100fb_setpalettereg(i, 0, 0, 0, 0, info);
  711. sa1100fb_schedule_work(fbi, C_DISABLE);
  712. break;
  713. case FB_BLANK_UNBLANK:
  714. if (fbi->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR ||
  715. fbi->fb.fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)
  716. fb_set_cmap(&fbi->fb.cmap, info);
  717. sa1100fb_schedule_work(fbi, C_ENABLE);
  718. }
  719. return 0;
  720. }
  721. static int sa1100fb_mmap(struct fb_info *info, struct file *file,
  722. struct vm_area_struct *vma)
  723. {
  724. struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
  725. unsigned long start, len, off = vma->vm_pgoff << PAGE_SHIFT;
  726. if (off < info->fix.smem_len) {
  727. vma->vm_pgoff += 1; /* skip over the palette */
  728. return dma_mmap_writecombine(fbi->dev, vma, fbi->map_cpu,
  729. fbi->map_dma, fbi->map_size);
  730. }
  731. start = info->fix.mmio_start;
  732. len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.mmio_len);
  733. if ((vma->vm_end - vma->vm_start + off) > len)
  734. return -EINVAL;
  735. off += start & PAGE_MASK;
  736. vma->vm_pgoff = off >> PAGE_SHIFT;
  737. vma->vm_flags |= VM_IO;
  738. vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  739. return io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
  740. vma->vm_end - vma->vm_start,
  741. vma->vm_page_prot);
  742. }
  743. static struct fb_ops sa1100fb_ops = {
  744. .owner = THIS_MODULE,
  745. .fb_check_var = sa1100fb_check_var,
  746. .fb_set_par = sa1100fb_set_par,
  747. // .fb_set_cmap = sa1100fb_set_cmap,
  748. .fb_setcolreg = sa1100fb_setcolreg,
  749. .fb_fillrect = cfb_fillrect,
  750. .fb_copyarea = cfb_copyarea,
  751. .fb_imageblit = cfb_imageblit,
  752. .fb_blank = sa1100fb_blank,
  753. .fb_cursor = soft_cursor,
  754. .fb_mmap = sa1100fb_mmap,
  755. };
  756. /*
  757. * Calculate the PCD value from the clock rate (in picoseconds).
  758. * We take account of the PPCR clock setting.
  759. */
  760. static inline unsigned int get_pcd(unsigned int pixclock, unsigned int cpuclock)
  761. {
  762. unsigned int pcd = cpuclock / 100;
  763. pcd *= pixclock;
  764. pcd /= 10000000;
  765. return pcd + 1; /* make up for integer math truncations */
  766. }
  767. /*
  768. * sa1100fb_activate_var():
  769. * Configures LCD Controller based on entries in var parameter. Settings are
  770. * only written to the controller if changes were made.
  771. */
  772. static int sa1100fb_activate_var(struct fb_var_screeninfo *var, struct sa1100fb_info *fbi)
  773. {
  774. struct sa1100fb_lcd_reg new_regs;
  775. u_int half_screen_size, yres, pcd;
  776. u_long flags;
  777. DPRINTK("Configuring SA1100 LCD\n");
  778. DPRINTK("var: xres=%d hslen=%d lm=%d rm=%d\n",
  779. var->xres, var->hsync_len,
  780. var->left_margin, var->right_margin);
  781. DPRINTK("var: yres=%d vslen=%d um=%d bm=%d\n",
  782. var->yres, var->vsync_len,
  783. var->upper_margin, var->lower_margin);
  784. #if DEBUG_VAR
  785. if (var->xres < 16 || var->xres > 1024)
  786. printk(KERN_ERR "%s: invalid xres %d\n",
  787. fbi->fb.fix.id, var->xres);
  788. if (var->hsync_len < 1 || var->hsync_len > 64)
  789. printk(KERN_ERR "%s: invalid hsync_len %d\n",
  790. fbi->fb.fix.id, var->hsync_len);
  791. if (var->left_margin < 1 || var->left_margin > 255)
  792. printk(KERN_ERR "%s: invalid left_margin %d\n",
  793. fbi->fb.fix.id, var->left_margin);
  794. if (var->right_margin < 1 || var->right_margin > 255)
  795. printk(KERN_ERR "%s: invalid right_margin %d\n",
  796. fbi->fb.fix.id, var->right_margin);
  797. if (var->yres < 1 || var->yres > 1024)
  798. printk(KERN_ERR "%s: invalid yres %d\n",
  799. fbi->fb.fix.id, var->yres);
  800. if (var->vsync_len < 1 || var->vsync_len > 64)
  801. printk(KERN_ERR "%s: invalid vsync_len %d\n",
  802. fbi->fb.fix.id, var->vsync_len);
  803. if (var->upper_margin < 0 || var->upper_margin > 255)
  804. printk(KERN_ERR "%s: invalid upper_margin %d\n",
  805. fbi->fb.fix.id, var->upper_margin);
  806. if (var->lower_margin < 0 || var->lower_margin > 255)
  807. printk(KERN_ERR "%s: invalid lower_margin %d\n",
  808. fbi->fb.fix.id, var->lower_margin);
  809. #endif
  810. new_regs.lccr0 = fbi->lccr0 |
  811. LCCR0_LEN | LCCR0_LDM | LCCR0_BAM |
  812. LCCR0_ERM | LCCR0_LtlEnd | LCCR0_DMADel(0);
  813. new_regs.lccr1 =
  814. LCCR1_DisWdth(var->xres) +
  815. LCCR1_HorSnchWdth(var->hsync_len) +
  816. LCCR1_BegLnDel(var->left_margin) +
  817. LCCR1_EndLnDel(var->right_margin);
  818. /*
  819. * If we have a dual scan LCD, then we need to halve
  820. * the YRES parameter.
  821. */
  822. yres = var->yres;
  823. if (fbi->lccr0 & LCCR0_Dual)
  824. yres /= 2;
  825. new_regs.lccr2 =
  826. LCCR2_DisHght(yres) +
  827. LCCR2_VrtSnchWdth(var->vsync_len) +
  828. LCCR2_BegFrmDel(var->upper_margin) +
  829. LCCR2_EndFrmDel(var->lower_margin);
  830. pcd = get_pcd(var->pixclock, cpufreq_get(0));
  831. new_regs.lccr3 = LCCR3_PixClkDiv(pcd) | fbi->lccr3 |
  832. (var->sync & FB_SYNC_HOR_HIGH_ACT ? LCCR3_HorSnchH : LCCR3_HorSnchL) |
  833. (var->sync & FB_SYNC_VERT_HIGH_ACT ? LCCR3_VrtSnchH : LCCR3_VrtSnchL);
  834. DPRINTK("nlccr0 = 0x%08lx\n", new_regs.lccr0);
  835. DPRINTK("nlccr1 = 0x%08lx\n", new_regs.lccr1);
  836. DPRINTK("nlccr2 = 0x%08lx\n", new_regs.lccr2);
  837. DPRINTK("nlccr3 = 0x%08lx\n", new_regs.lccr3);
  838. half_screen_size = var->bits_per_pixel;
  839. half_screen_size = half_screen_size * var->xres * var->yres / 16;
  840. /* Update shadow copy atomically */
  841. local_irq_save(flags);
  842. fbi->dbar1 = fbi->palette_dma;
  843. fbi->dbar2 = fbi->screen_dma + half_screen_size;
  844. fbi->reg_lccr0 = new_regs.lccr0;
  845. fbi->reg_lccr1 = new_regs.lccr1;
  846. fbi->reg_lccr2 = new_regs.lccr2;
  847. fbi->reg_lccr3 = new_regs.lccr3;
  848. local_irq_restore(flags);
  849. /*
  850. * Only update the registers if the controller is enabled
  851. * and something has changed.
  852. */
  853. if ((LCCR0 != fbi->reg_lccr0) || (LCCR1 != fbi->reg_lccr1) ||
  854. (LCCR2 != fbi->reg_lccr2) || (LCCR3 != fbi->reg_lccr3) ||
  855. (DBAR1 != fbi->dbar1) || (DBAR2 != fbi->dbar2))
  856. sa1100fb_schedule_work(fbi, C_REENABLE);
  857. return 0;
  858. }
  859. /*
  860. * NOTE! The following functions are purely helpers for set_ctrlr_state.
  861. * Do not call them directly; set_ctrlr_state does the correct serialisation
  862. * to ensure that things happen in the right way 100% of time time.
  863. * -- rmk
  864. */
  865. static inline void __sa1100fb_backlight_power(struct sa1100fb_info *fbi, int on)
  866. {
  867. DPRINTK("backlight o%s\n", on ? "n" : "ff");
  868. if (sa1100fb_backlight_power)
  869. sa1100fb_backlight_power(on);
  870. }
  871. static inline void __sa1100fb_lcd_power(struct sa1100fb_info *fbi, int on)
  872. {
  873. DPRINTK("LCD power o%s\n", on ? "n" : "ff");
  874. if (sa1100fb_lcd_power)
  875. sa1100fb_lcd_power(on);
  876. }
  877. static void sa1100fb_setup_gpio(struct sa1100fb_info *fbi)
  878. {
  879. u_int mask = 0;
  880. /*
  881. * Enable GPIO<9:2> for LCD use if:
  882. * 1. Active display, or
  883. * 2. Color Dual Passive display
  884. *
  885. * see table 11.8 on page 11-27 in the SA1100 manual
  886. * -- Erik.
  887. *
  888. * SA1110 spec update nr. 25 says we can and should
  889. * clear LDD15 to 12 for 4 or 8bpp modes with active
  890. * panels.
  891. */
  892. if ((fbi->reg_lccr0 & LCCR0_CMS) == LCCR0_Color &&
  893. (fbi->reg_lccr0 & (LCCR0_Dual|LCCR0_Act)) != 0) {
  894. mask = GPIO_LDD11 | GPIO_LDD10 | GPIO_LDD9 | GPIO_LDD8;
  895. if (fbi->fb.var.bits_per_pixel > 8 ||
  896. (fbi->reg_lccr0 & (LCCR0_Dual|LCCR0_Act)) == LCCR0_Dual)
  897. mask |= GPIO_LDD15 | GPIO_LDD14 | GPIO_LDD13 | GPIO_LDD12;
  898. }
  899. if (mask) {
  900. GPDR |= mask;
  901. GAFR |= mask;
  902. }
  903. }
  904. static void sa1100fb_enable_controller(struct sa1100fb_info *fbi)
  905. {
  906. DPRINTK("Enabling LCD controller\n");
  907. /*
  908. * Make sure the mode bits are present in the first palette entry
  909. */
  910. fbi->palette_cpu[0] &= 0xcfff;
  911. fbi->palette_cpu[0] |= palette_pbs(&fbi->fb.var);
  912. /* Sequence from 11.7.10 */
  913. LCCR3 = fbi->reg_lccr3;
  914. LCCR2 = fbi->reg_lccr2;
  915. LCCR1 = fbi->reg_lccr1;
  916. LCCR0 = fbi->reg_lccr0 & ~LCCR0_LEN;
  917. DBAR1 = fbi->dbar1;
  918. DBAR2 = fbi->dbar2;
  919. LCCR0 |= LCCR0_LEN;
  920. if (machine_is_shannon()) {
  921. GPDR |= SHANNON_GPIO_DISP_EN;
  922. GPSR |= SHANNON_GPIO_DISP_EN;
  923. }
  924. DPRINTK("DBAR1 = 0x%08x\n", DBAR1);
  925. DPRINTK("DBAR2 = 0x%08x\n", DBAR2);
  926. DPRINTK("LCCR0 = 0x%08x\n", LCCR0);
  927. DPRINTK("LCCR1 = 0x%08x\n", LCCR1);
  928. DPRINTK("LCCR2 = 0x%08x\n", LCCR2);
  929. DPRINTK("LCCR3 = 0x%08x\n", LCCR3);
  930. }
  931. static void sa1100fb_disable_controller(struct sa1100fb_info *fbi)
  932. {
  933. DECLARE_WAITQUEUE(wait, current);
  934. DPRINTK("Disabling LCD controller\n");
  935. if (machine_is_shannon()) {
  936. GPCR |= SHANNON_GPIO_DISP_EN;
  937. }
  938. set_current_state(TASK_UNINTERRUPTIBLE);
  939. add_wait_queue(&fbi->ctrlr_wait, &wait);
  940. LCSR = 0xffffffff; /* Clear LCD Status Register */
  941. LCCR0 &= ~LCCR0_LDM; /* Enable LCD Disable Done Interrupt */
  942. LCCR0 &= ~LCCR0_LEN; /* Disable LCD Controller */
  943. schedule_timeout(20 * HZ / 1000);
  944. remove_wait_queue(&fbi->ctrlr_wait, &wait);
  945. }
  946. /*
  947. * sa1100fb_handle_irq: Handle 'LCD DONE' interrupts.
  948. */
  949. static irqreturn_t sa1100fb_handle_irq(int irq, void *dev_id, struct pt_regs *regs)
  950. {
  951. struct sa1100fb_info *fbi = dev_id;
  952. unsigned int lcsr = LCSR;
  953. if (lcsr & LCSR_LDD) {
  954. LCCR0 |= LCCR0_LDM;
  955. wake_up(&fbi->ctrlr_wait);
  956. }
  957. LCSR = lcsr;
  958. return IRQ_HANDLED;
  959. }
  960. /*
  961. * This function must be called from task context only, since it will
  962. * sleep when disabling the LCD controller, or if we get two contending
  963. * processes trying to alter state.
  964. */
  965. static void set_ctrlr_state(struct sa1100fb_info *fbi, u_int state)
  966. {
  967. u_int old_state;
  968. down(&fbi->ctrlr_sem);
  969. old_state = fbi->state;
  970. /*
  971. * Hack around fbcon initialisation.
  972. */
  973. if (old_state == C_STARTUP && state == C_REENABLE)
  974. state = C_ENABLE;
  975. switch (state) {
  976. case C_DISABLE_CLKCHANGE:
  977. /*
  978. * Disable controller for clock change. If the
  979. * controller is already disabled, then do nothing.
  980. */
  981. if (old_state != C_DISABLE && old_state != C_DISABLE_PM) {
  982. fbi->state = state;
  983. sa1100fb_disable_controller(fbi);
  984. }
  985. break;
  986. case C_DISABLE_PM:
  987. case C_DISABLE:
  988. /*
  989. * Disable controller
  990. */
  991. if (old_state != C_DISABLE) {
  992. fbi->state = state;
  993. __sa1100fb_backlight_power(fbi, 0);
  994. if (old_state != C_DISABLE_CLKCHANGE)
  995. sa1100fb_disable_controller(fbi);
  996. __sa1100fb_lcd_power(fbi, 0);
  997. }
  998. break;
  999. case C_ENABLE_CLKCHANGE:
  1000. /*
  1001. * Enable the controller after clock change. Only
  1002. * do this if we were disabled for the clock change.
  1003. */
  1004. if (old_state == C_DISABLE_CLKCHANGE) {
  1005. fbi->state = C_ENABLE;
  1006. sa1100fb_enable_controller(fbi);
  1007. }
  1008. break;
  1009. case C_REENABLE:
  1010. /*
  1011. * Re-enable the controller only if it was already
  1012. * enabled. This is so we reprogram the control
  1013. * registers.
  1014. */
  1015. if (old_state == C_ENABLE) {
  1016. sa1100fb_disable_controller(fbi);
  1017. sa1100fb_setup_gpio(fbi);
  1018. sa1100fb_enable_controller(fbi);
  1019. }
  1020. break;
  1021. case C_ENABLE_PM:
  1022. /*
  1023. * Re-enable the controller after PM. This is not
  1024. * perfect - think about the case where we were doing
  1025. * a clock change, and we suspended half-way through.
  1026. */
  1027. if (old_state != C_DISABLE_PM)
  1028. break;
  1029. /* fall through */
  1030. case C_ENABLE:
  1031. /*
  1032. * Power up the LCD screen, enable controller, and
  1033. * turn on the backlight.
  1034. */
  1035. if (old_state != C_ENABLE) {
  1036. fbi->state = C_ENABLE;
  1037. sa1100fb_setup_gpio(fbi);
  1038. __sa1100fb_lcd_power(fbi, 1);
  1039. sa1100fb_enable_controller(fbi);
  1040. __sa1100fb_backlight_power(fbi, 1);
  1041. }
  1042. break;
  1043. }
  1044. up(&fbi->ctrlr_sem);
  1045. }
  1046. /*
  1047. * Our LCD controller task (which is called when we blank or unblank)
  1048. * via keventd.
  1049. */
  1050. static void sa1100fb_task(void *dummy)
  1051. {
  1052. struct sa1100fb_info *fbi = dummy;
  1053. u_int state = xchg(&fbi->task_state, -1);
  1054. set_ctrlr_state(fbi, state);
  1055. }
  1056. #ifdef CONFIG_CPU_FREQ
  1057. /*
  1058. * Calculate the minimum DMA period over all displays that we own.
  1059. * This, together with the SDRAM bandwidth defines the slowest CPU
  1060. * frequency that can be selected.
  1061. */
  1062. static unsigned int sa1100fb_min_dma_period(struct sa1100fb_info *fbi)
  1063. {
  1064. #if 0
  1065. unsigned int min_period = (unsigned int)-1;
  1066. int i;
  1067. for (i = 0; i < MAX_NR_CONSOLES; i++) {
  1068. struct display *disp = &fb_display[i];
  1069. unsigned int period;
  1070. /*
  1071. * Do we own this display?
  1072. */
  1073. if (disp->fb_info != &fbi->fb)
  1074. continue;
  1075. /*
  1076. * Ok, calculate its DMA period
  1077. */
  1078. period = sa1100fb_display_dma_period(&disp->var);
  1079. if (period < min_period)
  1080. min_period = period;
  1081. }
  1082. return min_period;
  1083. #else
  1084. /*
  1085. * FIXME: we need to verify _all_ consoles.
  1086. */
  1087. return sa1100fb_display_dma_period(&fbi->fb.var);
  1088. #endif
  1089. }
  1090. /*
  1091. * CPU clock speed change handler. We need to adjust the LCD timing
  1092. * parameters when the CPU clock is adjusted by the power management
  1093. * subsystem.
  1094. */
  1095. static int
  1096. sa1100fb_freq_transition(struct notifier_block *nb, unsigned long val,
  1097. void *data)
  1098. {
  1099. struct sa1100fb_info *fbi = TO_INF(nb, freq_transition);
  1100. struct cpufreq_freqs *f = data;
  1101. u_int pcd;
  1102. switch (val) {
  1103. case CPUFREQ_PRECHANGE:
  1104. set_ctrlr_state(fbi, C_DISABLE_CLKCHANGE);
  1105. break;
  1106. case CPUFREQ_POSTCHANGE:
  1107. pcd = get_pcd(fbi->fb.var.pixclock, f->new);
  1108. fbi->reg_lccr3 = (fbi->reg_lccr3 & ~0xff) | LCCR3_PixClkDiv(pcd);
  1109. set_ctrlr_state(fbi, C_ENABLE_CLKCHANGE);
  1110. break;
  1111. }
  1112. return 0;
  1113. }
  1114. static int
  1115. sa1100fb_freq_policy(struct notifier_block *nb, unsigned long val,
  1116. void *data)
  1117. {
  1118. struct sa1100fb_info *fbi = TO_INF(nb, freq_policy);
  1119. struct cpufreq_policy *policy = data;
  1120. switch (val) {
  1121. case CPUFREQ_ADJUST:
  1122. case CPUFREQ_INCOMPATIBLE:
  1123. printk(KERN_DEBUG "min dma period: %d ps, "
  1124. "new clock %d kHz\n", sa1100fb_min_dma_period(fbi),
  1125. policy->max);
  1126. /* todo: fill in min/max values */
  1127. break;
  1128. case CPUFREQ_NOTIFY:
  1129. do {} while(0);
  1130. /* todo: panic if min/max values aren't fulfilled
  1131. * [can't really happen unless there's a bug in the
  1132. * CPU policy verififcation process *
  1133. */
  1134. break;
  1135. }
  1136. return 0;
  1137. }
  1138. #endif
  1139. #ifdef CONFIG_PM
  1140. /*
  1141. * Power management hooks. Note that we won't be called from IRQ context,
  1142. * unlike the blank functions above, so we may sleep.
  1143. */
  1144. static int sa1100fb_suspend(struct device *dev, pm_message_t state, u32 level)
  1145. {
  1146. struct sa1100fb_info *fbi = dev_get_drvdata(dev);
  1147. if (level == SUSPEND_DISABLE || level == SUSPEND_POWER_DOWN)
  1148. set_ctrlr_state(fbi, C_DISABLE_PM);
  1149. return 0;
  1150. }
  1151. static int sa1100fb_resume(struct device *dev, u32 level)
  1152. {
  1153. struct sa1100fb_info *fbi = dev_get_drvdata(dev);
  1154. if (level == RESUME_ENABLE)
  1155. set_ctrlr_state(fbi, C_ENABLE_PM);
  1156. return 0;
  1157. }
  1158. #else
  1159. #define sa1100fb_suspend NULL
  1160. #define sa1100fb_resume NULL
  1161. #endif
  1162. /*
  1163. * sa1100fb_map_video_memory():
  1164. * Allocates the DRAM memory for the frame buffer. This buffer is
  1165. * remapped into a non-cached, non-buffered, memory region to
  1166. * allow palette and pixel writes to occur without flushing the
  1167. * cache. Once this area is remapped, all virtual memory
  1168. * access to the video memory should occur at the new region.
  1169. */
  1170. static int __init sa1100fb_map_video_memory(struct sa1100fb_info *fbi)
  1171. {
  1172. /*
  1173. * We reserve one page for the palette, plus the size
  1174. * of the framebuffer.
  1175. */
  1176. fbi->map_size = PAGE_ALIGN(fbi->fb.fix.smem_len + PAGE_SIZE);
  1177. fbi->map_cpu = dma_alloc_writecombine(fbi->dev, fbi->map_size,
  1178. &fbi->map_dma, GFP_KERNEL);
  1179. if (fbi->map_cpu) {
  1180. fbi->fb.screen_base = fbi->map_cpu + PAGE_SIZE;
  1181. fbi->screen_dma = fbi->map_dma + PAGE_SIZE;
  1182. /*
  1183. * FIXME: this is actually the wrong thing to place in
  1184. * smem_start. But fbdev suffers from the problem that
  1185. * it needs an API which doesn't exist (in this case,
  1186. * dma_writecombine_mmap)
  1187. */
  1188. fbi->fb.fix.smem_start = fbi->screen_dma;
  1189. }
  1190. return fbi->map_cpu ? 0 : -ENOMEM;
  1191. }
  1192. /* Fake monspecs to fill in fbinfo structure */
  1193. static struct fb_monspecs monspecs __initdata = {
  1194. .hfmin = 30000,
  1195. .hfmax = 70000,
  1196. .vfmin = 50,
  1197. .vfmax = 65,
  1198. };
  1199. static struct sa1100fb_info * __init sa1100fb_init_fbinfo(struct device *dev)
  1200. {
  1201. struct sa1100fb_mach_info *inf;
  1202. struct sa1100fb_info *fbi;
  1203. fbi = kmalloc(sizeof(struct sa1100fb_info) + sizeof(u32) * 16,
  1204. GFP_KERNEL);
  1205. if (!fbi)
  1206. return NULL;
  1207. memset(fbi, 0, sizeof(struct sa1100fb_info));
  1208. fbi->dev = dev;
  1209. strcpy(fbi->fb.fix.id, SA1100_NAME);
  1210. fbi->fb.fix.type = FB_TYPE_PACKED_PIXELS;
  1211. fbi->fb.fix.type_aux = 0;
  1212. fbi->fb.fix.xpanstep = 0;
  1213. fbi->fb.fix.ypanstep = 0;
  1214. fbi->fb.fix.ywrapstep = 0;
  1215. fbi->fb.fix.accel = FB_ACCEL_NONE;
  1216. fbi->fb.var.nonstd = 0;
  1217. fbi->fb.var.activate = FB_ACTIVATE_NOW;
  1218. fbi->fb.var.height = -1;
  1219. fbi->fb.var.width = -1;
  1220. fbi->fb.var.accel_flags = 0;
  1221. fbi->fb.var.vmode = FB_VMODE_NONINTERLACED;
  1222. fbi->fb.fbops = &sa1100fb_ops;
  1223. fbi->fb.flags = FBINFO_DEFAULT;
  1224. fbi->fb.monspecs = monspecs;
  1225. fbi->fb.pseudo_palette = (fbi + 1);
  1226. fbi->rgb[RGB_8] = &rgb_8;
  1227. fbi->rgb[RGB_16] = &def_rgb_16;
  1228. inf = sa1100fb_get_machine_info(fbi);
  1229. /*
  1230. * People just don't seem to get this. We don't support
  1231. * anything but correct entries now, so panic if someone
  1232. * does something stupid.
  1233. */
  1234. if (inf->lccr3 & (LCCR3_VrtSnchL|LCCR3_HorSnchL|0xff) ||
  1235. inf->pixclock == 0)
  1236. panic("sa1100fb error: invalid LCCR3 fields set or zero "
  1237. "pixclock.");
  1238. fbi->max_xres = inf->xres;
  1239. fbi->fb.var.xres = inf->xres;
  1240. fbi->fb.var.xres_virtual = inf->xres;
  1241. fbi->max_yres = inf->yres;
  1242. fbi->fb.var.yres = inf->yres;
  1243. fbi->fb.var.yres_virtual = inf->yres;
  1244. fbi->max_bpp = inf->bpp;
  1245. fbi->fb.var.bits_per_pixel = inf->bpp;
  1246. fbi->fb.var.pixclock = inf->pixclock;
  1247. fbi->fb.var.hsync_len = inf->hsync_len;
  1248. fbi->fb.var.left_margin = inf->left_margin;
  1249. fbi->fb.var.right_margin = inf->right_margin;
  1250. fbi->fb.var.vsync_len = inf->vsync_len;
  1251. fbi->fb.var.upper_margin = inf->upper_margin;
  1252. fbi->fb.var.lower_margin = inf->lower_margin;
  1253. fbi->fb.var.sync = inf->sync;
  1254. fbi->fb.var.grayscale = inf->cmap_greyscale;
  1255. fbi->cmap_inverse = inf->cmap_inverse;
  1256. fbi->cmap_static = inf->cmap_static;
  1257. fbi->lccr0 = inf->lccr0;
  1258. fbi->lccr3 = inf->lccr3;
  1259. fbi->state = C_STARTUP;
  1260. fbi->task_state = (u_char)-1;
  1261. fbi->fb.fix.smem_len = fbi->max_xres * fbi->max_yres *
  1262. fbi->max_bpp / 8;
  1263. init_waitqueue_head(&fbi->ctrlr_wait);
  1264. INIT_WORK(&fbi->task, sa1100fb_task, fbi);
  1265. init_MUTEX(&fbi->ctrlr_sem);
  1266. return fbi;
  1267. }
  1268. static int __init sa1100fb_probe(struct device *dev)
  1269. {
  1270. struct sa1100fb_info *fbi;
  1271. int ret;
  1272. if (!request_mem_region(0xb0100000, 0x10000, "LCD"))
  1273. return -EBUSY;
  1274. fbi = sa1100fb_init_fbinfo(dev);
  1275. ret = -ENOMEM;
  1276. if (!fbi)
  1277. goto failed;
  1278. /* Initialize video memory */
  1279. ret = sa1100fb_map_video_memory(fbi);
  1280. if (ret)
  1281. goto failed;
  1282. ret = request_irq(IRQ_LCD, sa1100fb_handle_irq, SA_INTERRUPT,
  1283. "LCD", fbi);
  1284. if (ret) {
  1285. printk(KERN_ERR "sa1100fb: request_irq failed: %d\n", ret);
  1286. goto failed;
  1287. }
  1288. #ifdef ASSABET_PAL_VIDEO
  1289. if (machine_is_assabet())
  1290. ASSABET_BCR_clear(ASSABET_BCR_LCD_ON);
  1291. #endif
  1292. /*
  1293. * This makes sure that our colour bitfield
  1294. * descriptors are correctly initialised.
  1295. */
  1296. sa1100fb_check_var(&fbi->fb.var, &fbi->fb);
  1297. dev_set_drvdata(dev, fbi);
  1298. ret = register_framebuffer(&fbi->fb);
  1299. if (ret < 0)
  1300. goto failed;
  1301. #ifdef CONFIG_CPU_FREQ
  1302. fbi->freq_transition.notifier_call = sa1100fb_freq_transition;
  1303. fbi->freq_policy.notifier_call = sa1100fb_freq_policy;
  1304. cpufreq_register_notifier(&fbi->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
  1305. cpufreq_register_notifier(&fbi->freq_policy, CPUFREQ_POLICY_NOTIFIER);
  1306. #endif
  1307. /* This driver cannot be unloaded at the moment */
  1308. return 0;
  1309. failed:
  1310. dev_set_drvdata(dev, NULL);
  1311. kfree(fbi);
  1312. release_mem_region(0xb0100000, 0x10000);
  1313. return ret;
  1314. }
  1315. static struct device_driver sa1100fb_driver = {
  1316. .name = "sa11x0-fb",
  1317. .bus = &platform_bus_type,
  1318. .probe = sa1100fb_probe,
  1319. .suspend = sa1100fb_suspend,
  1320. .resume = sa1100fb_resume,
  1321. };
  1322. int __init sa1100fb_init(void)
  1323. {
  1324. if (fb_get_options("sa1100fb", NULL))
  1325. return -ENODEV;
  1326. return 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");