sa1100fb.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579
  1. /*
  2. * linux/drivers/video/sa1100fb.c
  3. *
  4. * Copyright (C) 1999 Eric A. Thomas
  5. * Based on acornfb.c Copyright (C) Russell King.
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file COPYING in the main directory of this archive for
  9. * more details.
  10. *
  11. * StrongARM 1100 LCD Controller Frame Buffer Driver
  12. *
  13. * Please direct your questions and comments on this driver to the following
  14. * email address:
  15. *
  16. * linux-arm-kernel@lists.arm.linux.org.uk
  17. *
  18. * Clean patches should be sent to the ARM Linux Patch System. Please see the
  19. * following web page for more information:
  20. *
  21. * http://www.arm.linux.org.uk/developer/patches/info.shtml
  22. *
  23. * Thank you.
  24. *
  25. * Known problems:
  26. * - With the Neponset plugged into an Assabet, LCD powerdown
  27. * doesn't work (LCD stays powered up). Therefore we shouldn't
  28. * blank the screen.
  29. * - We don't limit the CPU clock rate nor the mode selection
  30. * according to the available SDRAM bandwidth.
  31. *
  32. * Other notes:
  33. * - Linear grayscale palettes and the kernel.
  34. * Such code does not belong in the kernel. The kernel frame buffer
  35. * drivers do not expect a linear colourmap, but a colourmap based on
  36. * the VT100 standard mapping.
  37. *
  38. * If your _userspace_ requires a linear colourmap, then the setup of
  39. * such a colourmap belongs _in userspace_, not in the kernel. Code
  40. * to set the colourmap correctly from user space has been sent to
  41. * David Neuer. It's around 8 lines of C code, plus another 4 to
  42. * detect if we are using grayscale.
  43. *
  44. * - The following must never be specified in a panel definition:
  45. * LCCR0_LtlEnd, LCCR3_PixClkDiv, LCCR3_VrtSnchL, LCCR3_HorSnchL
  46. *
  47. * - The following should be specified:
  48. * either LCCR0_Color or LCCR0_Mono
  49. * either LCCR0_Sngl or LCCR0_Dual
  50. * either LCCR0_Act or LCCR0_Pas
  51. * either LCCR3_OutEnH or LCCD3_OutEnL
  52. * either LCCR3_PixRsEdg or LCCR3_PixFlEdg
  53. * either LCCR3_ACBsDiv or LCCR3_ACBsCntOff
  54. *
  55. * Code Status:
  56. * 1999/04/01:
  57. * - Driver appears to be working for Brutus 320x200x8bpp mode. Other
  58. * resolutions are working, but only the 8bpp mode is supported.
  59. * Changes need to be made to the palette encode and decode routines
  60. * to support 4 and 16 bpp modes.
  61. * Driver is not designed to be a module. The FrameBuffer is statically
  62. * allocated since dynamic allocation of a 300k buffer cannot be
  63. * guaranteed.
  64. *
  65. * 1999/06/17:
  66. * - FrameBuffer memory is now allocated at run-time when the
  67. * driver is initialized.
  68. *
  69. * 2000/04/10: Nicolas Pitre <nico@cam.org>
  70. * - Big cleanup for dynamic selection of machine type at run time.
  71. *
  72. * 2000/07/19: Jamey Hicks <jamey@crl.dec.com>
  73. * - Support for Bitsy aka Compaq iPAQ H3600 added.
  74. *
  75. * 2000/08/07: Tak-Shing Chan <tchan.rd@idthk.com>
  76. * Jeff Sutherland <jsutherland@accelent.com>
  77. * - Resolved an issue caused by a change made to the Assabet's PLD
  78. * earlier this year which broke the framebuffer driver for newer
  79. * Phase 4 Assabets. Some other parameters were changed to optimize
  80. * for the Sharp display.
  81. *
  82. * 2000/08/09: Kunihiko IMAI <imai@vasara.co.jp>
  83. * - XP860 support added
  84. *
  85. * 2000/08/19: Mark Huang <mhuang@livetoy.com>
  86. * - Allows standard options to be passed on the kernel command line
  87. * for most common passive displays.
  88. *
  89. * 2000/08/29:
  90. * - s/save_flags_cli/local_irq_save/
  91. * - remove unneeded extra save_flags_cli in sa1100fb_enable_lcd_controller
  92. *
  93. * 2000/10/10: Erik Mouw <J.A.K.Mouw@its.tudelft.nl>
  94. * - Updated LART stuff. Fixed some minor bugs.
  95. *
  96. * 2000/10/30: Murphy Chen <murphy@mail.dialogue.com.tw>
  97. * - Pangolin support added
  98. *
  99. * 2000/10/31: Roman Jordan <jor@hoeft-wessel.de>
  100. * - Huw Webpanel support added
  101. *
  102. * 2000/11/23: Eric Peng <ericpeng@coventive.com>
  103. * - Freebird add
  104. *
  105. * 2001/02/07: Jamey Hicks <jamey.hicks@compaq.com>
  106. * Cliff Brake <cbrake@accelent.com>
  107. * - Added PM callback
  108. *
  109. * 2001/05/26: <rmk@arm.linux.org.uk>
  110. * - Fix 16bpp so that (a) we use the right colours rather than some
  111. * totally random colour depending on what was in page 0, and (b)
  112. * we don't de-reference a NULL pointer.
  113. * - remove duplicated implementation of consistent_alloc()
  114. * - convert dma address types to dma_addr_t
  115. * - remove unused 'montype' stuff
  116. * - remove redundant zero inits of init_var after the initial
  117. * memzero.
  118. * - remove allow_modeset (acornfb idea does not belong here)
  119. *
  120. * 2001/05/28: <rmk@arm.linux.org.uk>
  121. * - massive cleanup - move machine dependent data into structures
  122. * - I've left various #warnings in - if you see one, and know
  123. * the hardware concerned, please get in contact with me.
  124. *
  125. * 2001/05/31: <rmk@arm.linux.org.uk>
  126. * - Fix LCCR1 HSW value, fix all machine type specifications to
  127. * keep values in line. (Please check your machine type specs)
  128. *
  129. * 2001/06/10: <rmk@arm.linux.org.uk>
  130. * - Fiddle with the LCD controller from task context only; mainly
  131. * so that we can run with interrupts on, and sleep.
  132. * - Convert #warnings into #errors. No pain, no gain. ;)
  133. *
  134. * 2001/06/14: <rmk@arm.linux.org.uk>
  135. * - Make the palette BPS value for 12bpp come out correctly.
  136. * - Take notice of "greyscale" on any colour depth.
  137. * - Make truecolor visuals use the RGB channel encoding information.
  138. *
  139. * 2001/07/02: <rmk@arm.linux.org.uk>
  140. * - Fix colourmap problems.
  141. *
  142. * 2001/07/13: <abraham@2d3d.co.za>
  143. * - Added support for the ICP LCD-Kit01 on LART. This LCD is
  144. * manufactured by Prime View, model no V16C6448AB
  145. *
  146. * 2001/07/23: <rmk@arm.linux.org.uk>
  147. * - Hand merge version from handhelds.org CVS tree. See patch
  148. * notes for 595/1 for more information.
  149. * - Drop 12bpp (it's 16bpp with different colour register mappings).
  150. * - This hardware can not do direct colour. Therefore we don't
  151. * support it.
  152. *
  153. * 2001/07/27: <rmk@arm.linux.org.uk>
  154. * - Halve YRES on dual scan LCDs.
  155. *
  156. * 2001/08/22: <rmk@arm.linux.org.uk>
  157. * - Add b/w iPAQ pixclock value.
  158. *
  159. * 2001/10/12: <rmk@arm.linux.org.uk>
  160. * - Add patch 681/1 and clean up stork definitions.
  161. */
  162. #include <linux/module.h>
  163. #include <linux/kernel.h>
  164. #include <linux/sched.h>
  165. #include <linux/errno.h>
  166. #include <linux/string.h>
  167. #include <linux/interrupt.h>
  168. #include <linux/slab.h>
  169. #include <linux/mm.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 <linux/mutex.h>
  178. #include <mach/hardware.h>
  179. #include <asm/io.h>
  180. #include <asm/mach-types.h>
  181. #include <mach/assabet.h>
  182. #include <mach/shannon.h>
  183. /*
  184. * debugging?
  185. */
  186. #define DEBUG 0
  187. /*
  188. * Complain if VAR is out of range.
  189. */
  190. #define DEBUG_VAR 1
  191. #undef ASSABET_PAL_VIDEO
  192. #include "sa1100fb.h"
  193. extern void (*sa1100fb_backlight_power)(int on);
  194. extern void (*sa1100fb_lcd_power)(int on);
  195. /*
  196. * IMHO this looks wrong. In 8BPP, length should be 8.
  197. */
  198. static struct sa1100fb_rgb rgb_8 = {
  199. .red = { .offset = 0, .length = 4, },
  200. .green = { .offset = 0, .length = 4, },
  201. .blue = { .offset = 0, .length = 4, },
  202. .transp = { .offset = 0, .length = 0, },
  203. };
  204. static struct sa1100fb_rgb def_rgb_16 = {
  205. .red = { .offset = 11, .length = 5, },
  206. .green = { .offset = 5, .length = 6, },
  207. .blue = { .offset = 0, .length = 5, },
  208. .transp = { .offset = 0, .length = 0, },
  209. };
  210. #ifdef CONFIG_SA1100_ASSABET
  211. #ifndef ASSABET_PAL_VIDEO
  212. /*
  213. * The assabet uses a sharp LQ039Q2DS54 LCD module. It is actually
  214. * takes an RGB666 signal, but we provide it with an RGB565 signal
  215. * instead (def_rgb_16).
  216. */
  217. static struct sa1100fb_mach_info lq039q2ds54_info __initdata = {
  218. .pixclock = 171521, .bpp = 16,
  219. .xres = 320, .yres = 240,
  220. .hsync_len = 5, .vsync_len = 1,
  221. .left_margin = 61, .upper_margin = 3,
  222. .right_margin = 9, .lower_margin = 0,
  223. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  224. .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
  225. .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2),
  226. };
  227. #else
  228. static struct sa1100fb_mach_info pal_info __initdata = {
  229. .pixclock = 67797, .bpp = 16,
  230. .xres = 640, .yres = 512,
  231. .hsync_len = 64, .vsync_len = 6,
  232. .left_margin = 125, .upper_margin = 70,
  233. .right_margin = 115, .lower_margin = 36,
  234. .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
  235. .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(512),
  236. };
  237. #endif
  238. #endif
  239. #ifdef CONFIG_SA1100_H3800
  240. static struct sa1100fb_mach_info h3800_info __initdata = {
  241. .pixclock = 174757, .bpp = 16,
  242. .xres = 320, .yres = 240,
  243. .hsync_len = 3, .vsync_len = 3,
  244. .left_margin = 12, .upper_margin = 10,
  245. .right_margin = 17, .lower_margin = 1,
  246. .cmap_static = 1,
  247. .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
  248. .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2),
  249. };
  250. #endif
  251. #ifdef CONFIG_SA1100_H3600
  252. static struct sa1100fb_mach_info h3600_info __initdata = {
  253. .pixclock = 174757, .bpp = 16,
  254. .xres = 320, .yres = 240,
  255. .hsync_len = 3, .vsync_len = 3,
  256. .left_margin = 12, .upper_margin = 10,
  257. .right_margin = 17, .lower_margin = 1,
  258. .cmap_static = 1,
  259. .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
  260. .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2),
  261. };
  262. static struct sa1100fb_rgb h3600_rgb_16 = {
  263. .red = { .offset = 12, .length = 4, },
  264. .green = { .offset = 7, .length = 4, },
  265. .blue = { .offset = 1, .length = 4, },
  266. .transp = { .offset = 0, .length = 0, },
  267. };
  268. #endif
  269. #ifdef CONFIG_SA1100_H3100
  270. static struct sa1100fb_mach_info h3100_info __initdata = {
  271. .pixclock = 406977, .bpp = 4,
  272. .xres = 320, .yres = 240,
  273. .hsync_len = 26, .vsync_len = 41,
  274. .left_margin = 4, .upper_margin = 0,
  275. .right_margin = 4, .lower_margin = 0,
  276. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  277. .cmap_greyscale = 1,
  278. .cmap_inverse = 1,
  279. .lccr0 = LCCR0_Mono | LCCR0_4PixMono | LCCR0_Sngl | LCCR0_Pas,
  280. .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2),
  281. };
  282. #endif
  283. #ifdef CONFIG_SA1100_COLLIE
  284. static struct sa1100fb_mach_info collie_info __initdata = {
  285. .pixclock = 171521, .bpp = 16,
  286. .xres = 320, .yres = 240,
  287. .hsync_len = 5, .vsync_len = 1,
  288. .left_margin = 11, .upper_margin = 2,
  289. .right_margin = 30, .lower_margin = 0,
  290. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  291. .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
  292. .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(2),
  293. };
  294. #endif
  295. #ifdef LART_GREY_LCD
  296. static struct sa1100fb_mach_info lart_grey_info __initdata = {
  297. .pixclock = 150000, .bpp = 4,
  298. .xres = 320, .yres = 240,
  299. .hsync_len = 1, .vsync_len = 1,
  300. .left_margin = 4, .upper_margin = 0,
  301. .right_margin = 2, .lower_margin = 0,
  302. .cmap_greyscale = 1,
  303. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  304. .lccr0 = LCCR0_Mono | LCCR0_Sngl | LCCR0_Pas | LCCR0_4PixMono,
  305. .lccr3 = LCCR3_OutEnH | LCCR3_PixRsEdg | LCCR3_ACBsDiv(512),
  306. };
  307. #endif
  308. #ifdef LART_COLOR_LCD
  309. static struct sa1100fb_mach_info lart_color_info __initdata = {
  310. .pixclock = 150000, .bpp = 16,
  311. .xres = 320, .yres = 240,
  312. .hsync_len = 2, .vsync_len = 3,
  313. .left_margin = 69, .upper_margin = 14,
  314. .right_margin = 8, .lower_margin = 4,
  315. .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
  316. .lccr3 = LCCR3_OutEnH | LCCR3_PixFlEdg | LCCR3_ACBsDiv(512),
  317. };
  318. #endif
  319. #ifdef LART_VIDEO_OUT
  320. static struct sa1100fb_mach_info lart_video_info __initdata = {
  321. .pixclock = 39721, .bpp = 16,
  322. .xres = 640, .yres = 480,
  323. .hsync_len = 95, .vsync_len = 2,
  324. .left_margin = 40, .upper_margin = 32,
  325. .right_margin = 24, .lower_margin = 11,
  326. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  327. .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
  328. .lccr3 = LCCR3_OutEnL | LCCR3_PixFlEdg | LCCR3_ACBsDiv(512),
  329. };
  330. #endif
  331. #ifdef LART_KIT01_LCD
  332. static struct sa1100fb_mach_info lart_kit01_info __initdata = {
  333. .pixclock = 63291, .bpp = 16,
  334. .xres = 640, .yres = 480,
  335. .hsync_len = 64, .vsync_len = 3,
  336. .left_margin = 122, .upper_margin = 45,
  337. .right_margin = 10, .lower_margin = 10,
  338. .lccr0 = LCCR0_Color | LCCR0_Sngl | LCCR0_Act,
  339. .lccr3 = LCCR3_OutEnH | LCCR3_PixFlEdg
  340. };
  341. #endif
  342. #ifdef CONFIG_SA1100_SHANNON
  343. static struct sa1100fb_mach_info shannon_info __initdata = {
  344. .pixclock = 152500, .bpp = 8,
  345. .xres = 640, .yres = 480,
  346. .hsync_len = 4, .vsync_len = 3,
  347. .left_margin = 2, .upper_margin = 0,
  348. .right_margin = 1, .lower_margin = 0,
  349. .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  350. .lccr0 = LCCR0_Color | LCCR0_Dual | LCCR0_Pas,
  351. .lccr3 = LCCR3_ACBsDiv(512),
  352. };
  353. #endif
  354. static struct sa1100fb_mach_info * __init
  355. sa1100fb_get_machine_info(struct sa1100fb_info *fbi)
  356. {
  357. struct sa1100fb_mach_info *inf = NULL;
  358. /*
  359. * R G B T
  360. * default {11,5}, { 5,6}, { 0,5}, { 0,0}
  361. * h3600 {12,4}, { 7,4}, { 1,4}, { 0,0}
  362. * freebird { 8,4}, { 4,4}, { 0,4}, {12,4}
  363. */
  364. #ifdef CONFIG_SA1100_ASSABET
  365. if (machine_is_assabet()) {
  366. #ifndef ASSABET_PAL_VIDEO
  367. inf = &lq039q2ds54_info;
  368. #else
  369. inf = &pal_info;
  370. #endif
  371. }
  372. #endif
  373. #ifdef CONFIG_SA1100_H3100
  374. if (machine_is_h3100()) {
  375. inf = &h3100_info;
  376. }
  377. #endif
  378. #ifdef CONFIG_SA1100_H3600
  379. if (machine_is_h3600()) {
  380. inf = &h3600_info;
  381. fbi->rgb[RGB_16] = &h3600_rgb_16;
  382. }
  383. #endif
  384. #ifdef CONFIG_SA1100_H3800
  385. if (machine_is_h3800()) {
  386. inf = &h3800_info;
  387. }
  388. #endif
  389. #ifdef CONFIG_SA1100_COLLIE
  390. if (machine_is_collie()) {
  391. inf = &collie_info;
  392. }
  393. #endif
  394. #ifdef CONFIG_SA1100_LART
  395. if (machine_is_lart()) {
  396. #ifdef LART_GREY_LCD
  397. inf = &lart_grey_info;
  398. #endif
  399. #ifdef LART_COLOR_LCD
  400. inf = &lart_color_info;
  401. #endif
  402. #ifdef LART_VIDEO_OUT
  403. inf = &lart_video_info;
  404. #endif
  405. #ifdef LART_KIT01_LCD
  406. inf = &lart_kit01_info;
  407. #endif
  408. }
  409. #endif
  410. #ifdef CONFIG_SA1100_SHANNON
  411. if (machine_is_shannon()) {
  412. inf = &shannon_info;
  413. }
  414. #endif
  415. return inf;
  416. }
  417. static int sa1100fb_activate_var(struct fb_var_screeninfo *var, struct sa1100fb_info *);
  418. static void set_ctrlr_state(struct sa1100fb_info *fbi, u_int state);
  419. static inline void sa1100fb_schedule_work(struct sa1100fb_info *fbi, u_int state)
  420. {
  421. unsigned long flags;
  422. local_irq_save(flags);
  423. /*
  424. * We need to handle two requests being made at the same time.
  425. * There are two important cases:
  426. * 1. When we are changing VT (C_REENABLE) while unblanking (C_ENABLE)
  427. * We must perform the unblanking, which will do our REENABLE for us.
  428. * 2. When we are blanking, but immediately unblank before we have
  429. * blanked. We do the "REENABLE" thing here as well, just to be sure.
  430. */
  431. if (fbi->task_state == C_ENABLE && state == C_REENABLE)
  432. state = (u_int) -1;
  433. if (fbi->task_state == C_DISABLE && state == C_ENABLE)
  434. state = C_REENABLE;
  435. if (state != (u_int)-1) {
  436. fbi->task_state = state;
  437. schedule_work(&fbi->task);
  438. }
  439. local_irq_restore(flags);
  440. }
  441. static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf)
  442. {
  443. chan &= 0xffff;
  444. chan >>= 16 - bf->length;
  445. return chan << bf->offset;
  446. }
  447. /*
  448. * Convert bits-per-pixel to a hardware palette PBS value.
  449. */
  450. static inline u_int palette_pbs(struct fb_var_screeninfo *var)
  451. {
  452. int ret = 0;
  453. switch (var->bits_per_pixel) {
  454. case 4: ret = 0 << 12; break;
  455. case 8: ret = 1 << 12; break;
  456. case 16: ret = 2 << 12; break;
  457. }
  458. return ret;
  459. }
  460. static int
  461. sa1100fb_setpalettereg(u_int regno, u_int red, u_int green, u_int blue,
  462. u_int trans, struct fb_info *info)
  463. {
  464. struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
  465. u_int val, ret = 1;
  466. if (regno < fbi->palette_size) {
  467. val = ((red >> 4) & 0xf00);
  468. val |= ((green >> 8) & 0x0f0);
  469. val |= ((blue >> 12) & 0x00f);
  470. if (regno == 0)
  471. val |= palette_pbs(&fbi->fb.var);
  472. fbi->palette_cpu[regno] = val;
  473. ret = 0;
  474. }
  475. return ret;
  476. }
  477. static int
  478. sa1100fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  479. u_int trans, struct fb_info *info)
  480. {
  481. struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
  482. unsigned int val;
  483. int ret = 1;
  484. /*
  485. * If inverse mode was selected, invert all the colours
  486. * rather than the register number. The register number
  487. * is what you poke into the framebuffer to produce the
  488. * colour you requested.
  489. */
  490. if (fbi->cmap_inverse) {
  491. red = 0xffff - red;
  492. green = 0xffff - green;
  493. blue = 0xffff - blue;
  494. }
  495. /*
  496. * If greyscale is true, then we convert the RGB value
  497. * to greyscale no mater what visual we are using.
  498. */
  499. if (fbi->fb.var.grayscale)
  500. red = green = blue = (19595 * red + 38470 * green +
  501. 7471 * blue) >> 16;
  502. switch (fbi->fb.fix.visual) {
  503. case FB_VISUAL_TRUECOLOR:
  504. /*
  505. * 12 or 16-bit True Colour. We encode the RGB value
  506. * according to the RGB bitfield information.
  507. */
  508. if (regno < 16) {
  509. u32 *pal = fbi->fb.pseudo_palette;
  510. val = chan_to_field(red, &fbi->fb.var.red);
  511. val |= chan_to_field(green, &fbi->fb.var.green);
  512. val |= chan_to_field(blue, &fbi->fb.var.blue);
  513. pal[regno] = val;
  514. ret = 0;
  515. }
  516. break;
  517. case FB_VISUAL_STATIC_PSEUDOCOLOR:
  518. case FB_VISUAL_PSEUDOCOLOR:
  519. ret = sa1100fb_setpalettereg(regno, red, green, blue, trans, info);
  520. break;
  521. }
  522. return ret;
  523. }
  524. #ifdef CONFIG_CPU_FREQ
  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. #endif
  540. /*
  541. * sa1100fb_check_var():
  542. * Round up in the following order: bits_per_pixel, xres,
  543. * yres, xres_virtual, yres_virtual, xoffset, yoffset, grayscale,
  544. * bitfields, horizontal timing, vertical timing.
  545. */
  546. static int
  547. sa1100fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  548. {
  549. struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
  550. int rgbidx;
  551. if (var->xres < MIN_XRES)
  552. var->xres = MIN_XRES;
  553. if (var->yres < MIN_YRES)
  554. var->yres = MIN_YRES;
  555. if (var->xres > fbi->max_xres)
  556. var->xres = fbi->max_xres;
  557. if (var->yres > fbi->max_yres)
  558. var->yres = fbi->max_yres;
  559. var->xres_virtual = max(var->xres_virtual, var->xres);
  560. var->yres_virtual = max(var->yres_virtual, var->yres);
  561. DPRINTK("var->bits_per_pixel=%d\n", var->bits_per_pixel);
  562. switch (var->bits_per_pixel) {
  563. case 4:
  564. rgbidx = RGB_8;
  565. break;
  566. case 8:
  567. rgbidx = RGB_8;
  568. break;
  569. case 16:
  570. rgbidx = RGB_16;
  571. break;
  572. default:
  573. return -EINVAL;
  574. }
  575. /*
  576. * Copy the RGB parameters for this display
  577. * from the machine specific parameters.
  578. */
  579. var->red = fbi->rgb[rgbidx]->red;
  580. var->green = fbi->rgb[rgbidx]->green;
  581. var->blue = fbi->rgb[rgbidx]->blue;
  582. var->transp = fbi->rgb[rgbidx]->transp;
  583. DPRINTK("RGBT length = %d:%d:%d:%d\n",
  584. var->red.length, var->green.length, var->blue.length,
  585. var->transp.length);
  586. DPRINTK("RGBT offset = %d:%d:%d:%d\n",
  587. var->red.offset, var->green.offset, var->blue.offset,
  588. var->transp.offset);
  589. #ifdef CONFIG_CPU_FREQ
  590. printk(KERN_DEBUG "dma period = %d ps, clock = %d kHz\n",
  591. sa1100fb_display_dma_period(var),
  592. cpufreq_get(smp_processor_id()));
  593. #endif
  594. return 0;
  595. }
  596. static inline void sa1100fb_set_truecolor(u_int is_true_color)
  597. {
  598. if (machine_is_assabet()) {
  599. #if 1 // phase 4 or newer Assabet's
  600. if (is_true_color)
  601. ASSABET_BCR_set(ASSABET_BCR_LCD_12RGB);
  602. else
  603. ASSABET_BCR_clear(ASSABET_BCR_LCD_12RGB);
  604. #else
  605. // older Assabet's
  606. if (is_true_color)
  607. ASSABET_BCR_clear(ASSABET_BCR_LCD_12RGB);
  608. else
  609. ASSABET_BCR_set(ASSABET_BCR_LCD_12RGB);
  610. #endif
  611. }
  612. }
  613. /*
  614. * sa1100fb_set_par():
  615. * Set the user defined part of the display for the specified console
  616. */
  617. static int sa1100fb_set_par(struct fb_info *info)
  618. {
  619. struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
  620. struct fb_var_screeninfo *var = &info->var;
  621. unsigned long palette_mem_size;
  622. DPRINTK("set_par\n");
  623. if (var->bits_per_pixel == 16)
  624. fbi->fb.fix.visual = FB_VISUAL_TRUECOLOR;
  625. else if (!fbi->cmap_static)
  626. fbi->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
  627. else {
  628. /*
  629. * Some people have weird ideas about wanting static
  630. * pseudocolor maps. I suspect their user space
  631. * applications are broken.
  632. */
  633. fbi->fb.fix.visual = FB_VISUAL_STATIC_PSEUDOCOLOR;
  634. }
  635. fbi->fb.fix.line_length = var->xres_virtual *
  636. var->bits_per_pixel / 8;
  637. fbi->palette_size = var->bits_per_pixel == 8 ? 256 : 16;
  638. palette_mem_size = fbi->palette_size * sizeof(u16);
  639. DPRINTK("palette_mem_size = 0x%08lx\n", (u_long) palette_mem_size);
  640. fbi->palette_cpu = (u16 *)(fbi->map_cpu + PAGE_SIZE - palette_mem_size);
  641. fbi->palette_dma = fbi->map_dma + PAGE_SIZE - palette_mem_size;
  642. /*
  643. * Set (any) board control register to handle new color depth
  644. */
  645. sa1100fb_set_truecolor(fbi->fb.fix.visual == FB_VISUAL_TRUECOLOR);
  646. sa1100fb_activate_var(var, fbi);
  647. return 0;
  648. }
  649. #if 0
  650. static int
  651. sa1100fb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
  652. struct fb_info *info)
  653. {
  654. struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
  655. /*
  656. * Make sure the user isn't doing something stupid.
  657. */
  658. if (!kspc && (fbi->fb.var.bits_per_pixel == 16 || fbi->cmap_static))
  659. return -EINVAL;
  660. return gen_set_cmap(cmap, kspc, con, info);
  661. }
  662. #endif
  663. /*
  664. * Formal definition of the VESA spec:
  665. * On
  666. * This refers to the state of the display when it is in full operation
  667. * Stand-By
  668. * This defines an optional operating state of minimal power reduction with
  669. * the shortest recovery time
  670. * Suspend
  671. * This refers to a level of power management in which substantial power
  672. * reduction is achieved by the display. The display can have a longer
  673. * recovery time from this state than from the Stand-by state
  674. * Off
  675. * This indicates that the display is consuming the lowest level of power
  676. * and is non-operational. Recovery from this state may optionally require
  677. * the user to manually power on the monitor
  678. *
  679. * Now, the fbdev driver adds an additional state, (blank), where they
  680. * turn off the video (maybe by colormap tricks), but don't mess with the
  681. * video itself: think of it semantically between on and Stand-By.
  682. *
  683. * So here's what we should do in our fbdev blank routine:
  684. *
  685. * VESA_NO_BLANKING (mode 0) Video on, front/back light on
  686. * VESA_VSYNC_SUSPEND (mode 1) Video on, front/back light off
  687. * VESA_HSYNC_SUSPEND (mode 2) Video on, front/back light off
  688. * VESA_POWERDOWN (mode 3) Video off, front/back light off
  689. *
  690. * This will match the matrox implementation.
  691. */
  692. /*
  693. * sa1100fb_blank():
  694. * Blank the display by setting all palette values to zero. Note, the
  695. * 12 and 16 bpp modes don't really use the palette, so this will not
  696. * blank the display in all modes.
  697. */
  698. static int sa1100fb_blank(int blank, struct fb_info *info)
  699. {
  700. struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
  701. int i;
  702. DPRINTK("sa1100fb_blank: blank=%d\n", blank);
  703. switch (blank) {
  704. case FB_BLANK_POWERDOWN:
  705. case FB_BLANK_VSYNC_SUSPEND:
  706. case FB_BLANK_HSYNC_SUSPEND:
  707. case FB_BLANK_NORMAL:
  708. if (fbi->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR ||
  709. fbi->fb.fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)
  710. for (i = 0; i < fbi->palette_size; i++)
  711. sa1100fb_setpalettereg(i, 0, 0, 0, 0, info);
  712. sa1100fb_schedule_work(fbi, C_DISABLE);
  713. break;
  714. case FB_BLANK_UNBLANK:
  715. if (fbi->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR ||
  716. fbi->fb.fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)
  717. fb_set_cmap(&fbi->fb.cmap, info);
  718. sa1100fb_schedule_work(fbi, C_ENABLE);
  719. }
  720. return 0;
  721. }
  722. static int sa1100fb_mmap(struct fb_info *info,
  723. struct vm_area_struct *vma)
  724. {
  725. struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
  726. unsigned long start, len, off = vma->vm_pgoff << PAGE_SHIFT;
  727. if (off < info->fix.smem_len) {
  728. vma->vm_pgoff += 1; /* skip over the palette */
  729. return dma_mmap_writecombine(fbi->dev, vma, fbi->map_cpu,
  730. fbi->map_dma, fbi->map_size);
  731. }
  732. start = info->fix.mmio_start;
  733. len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.mmio_len);
  734. if ((vma->vm_end - vma->vm_start + off) > len)
  735. return -EINVAL;
  736. off += start & PAGE_MASK;
  737. vma->vm_pgoff = off >> PAGE_SHIFT;
  738. vma->vm_flags |= VM_IO;
  739. vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  740. return io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
  741. vma->vm_end - vma->vm_start,
  742. vma->vm_page_prot);
  743. }
  744. static struct fb_ops sa1100fb_ops = {
  745. .owner = THIS_MODULE,
  746. .fb_check_var = sa1100fb_check_var,
  747. .fb_set_par = sa1100fb_set_par,
  748. // .fb_set_cmap = sa1100fb_set_cmap,
  749. .fb_setcolreg = sa1100fb_setcolreg,
  750. .fb_fillrect = cfb_fillrect,
  751. .fb_copyarea = cfb_copyarea,
  752. .fb_imageblit = cfb_imageblit,
  753. .fb_blank = sa1100fb_blank,
  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)
  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. mutex_lock(&fbi->ctrlr_lock);
  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. mutex_unlock(&fbi->ctrlr_lock);
  1045. }
  1046. /*
  1047. * Our LCD controller task (which is called when we blank or unblank)
  1048. * via keventd.
  1049. */
  1050. static void sa1100fb_task(struct work_struct *w)
  1051. {
  1052. struct sa1100fb_info *fbi = container_of(w, struct sa1100fb_info, task);
  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 platform_device *dev, pm_message_t state)
  1145. {
  1146. struct sa1100fb_info *fbi = platform_get_drvdata(dev);
  1147. set_ctrlr_state(fbi, C_DISABLE_PM);
  1148. return 0;
  1149. }
  1150. static int sa1100fb_resume(struct platform_device *dev)
  1151. {
  1152. struct sa1100fb_info *fbi = platform_get_drvdata(dev);
  1153. set_ctrlr_state(fbi, C_ENABLE_PM);
  1154. return 0;
  1155. }
  1156. #else
  1157. #define sa1100fb_suspend NULL
  1158. #define sa1100fb_resume NULL
  1159. #endif
  1160. /*
  1161. * sa1100fb_map_video_memory():
  1162. * Allocates the DRAM memory for the frame buffer. This buffer is
  1163. * remapped into a non-cached, non-buffered, memory region to
  1164. * allow palette and pixel writes to occur without flushing the
  1165. * cache. Once this area is remapped, all virtual memory
  1166. * access to the video memory should occur at the new region.
  1167. */
  1168. static int __init sa1100fb_map_video_memory(struct sa1100fb_info *fbi)
  1169. {
  1170. /*
  1171. * We reserve one page for the palette, plus the size
  1172. * of the framebuffer.
  1173. */
  1174. fbi->map_size = PAGE_ALIGN(fbi->fb.fix.smem_len + PAGE_SIZE);
  1175. fbi->map_cpu = dma_alloc_writecombine(fbi->dev, fbi->map_size,
  1176. &fbi->map_dma, GFP_KERNEL);
  1177. if (fbi->map_cpu) {
  1178. fbi->fb.screen_base = fbi->map_cpu + PAGE_SIZE;
  1179. fbi->screen_dma = fbi->map_dma + PAGE_SIZE;
  1180. /*
  1181. * FIXME: this is actually the wrong thing to place in
  1182. * smem_start. But fbdev suffers from the problem that
  1183. * it needs an API which doesn't exist (in this case,
  1184. * dma_writecombine_mmap)
  1185. */
  1186. fbi->fb.fix.smem_start = fbi->screen_dma;
  1187. }
  1188. return fbi->map_cpu ? 0 : -ENOMEM;
  1189. }
  1190. /* Fake monspecs to fill in fbinfo structure */
  1191. static struct fb_monspecs monspecs __initdata = {
  1192. .hfmin = 30000,
  1193. .hfmax = 70000,
  1194. .vfmin = 50,
  1195. .vfmax = 65,
  1196. };
  1197. static struct sa1100fb_info * __init sa1100fb_init_fbinfo(struct device *dev)
  1198. {
  1199. struct sa1100fb_mach_info *inf;
  1200. struct sa1100fb_info *fbi;
  1201. fbi = kmalloc(sizeof(struct sa1100fb_info) + sizeof(u32) * 16,
  1202. GFP_KERNEL);
  1203. if (!fbi)
  1204. return NULL;
  1205. memset(fbi, 0, sizeof(struct sa1100fb_info));
  1206. fbi->dev = dev;
  1207. strcpy(fbi->fb.fix.id, SA1100_NAME);
  1208. fbi->fb.fix.type = FB_TYPE_PACKED_PIXELS;
  1209. fbi->fb.fix.type_aux = 0;
  1210. fbi->fb.fix.xpanstep = 0;
  1211. fbi->fb.fix.ypanstep = 0;
  1212. fbi->fb.fix.ywrapstep = 0;
  1213. fbi->fb.fix.accel = FB_ACCEL_NONE;
  1214. fbi->fb.var.nonstd = 0;
  1215. fbi->fb.var.activate = FB_ACTIVATE_NOW;
  1216. fbi->fb.var.height = -1;
  1217. fbi->fb.var.width = -1;
  1218. fbi->fb.var.accel_flags = 0;
  1219. fbi->fb.var.vmode = FB_VMODE_NONINTERLACED;
  1220. fbi->fb.fbops = &sa1100fb_ops;
  1221. fbi->fb.flags = FBINFO_DEFAULT;
  1222. fbi->fb.monspecs = monspecs;
  1223. fbi->fb.pseudo_palette = (fbi + 1);
  1224. fbi->rgb[RGB_8] = &rgb_8;
  1225. fbi->rgb[RGB_16] = &def_rgb_16;
  1226. inf = sa1100fb_get_machine_info(fbi);
  1227. /*
  1228. * People just don't seem to get this. We don't support
  1229. * anything but correct entries now, so panic if someone
  1230. * does something stupid.
  1231. */
  1232. if (inf->lccr3 & (LCCR3_VrtSnchL|LCCR3_HorSnchL|0xff) ||
  1233. inf->pixclock == 0)
  1234. panic("sa1100fb error: invalid LCCR3 fields set or zero "
  1235. "pixclock.");
  1236. fbi->max_xres = inf->xres;
  1237. fbi->fb.var.xres = inf->xres;
  1238. fbi->fb.var.xres_virtual = inf->xres;
  1239. fbi->max_yres = inf->yres;
  1240. fbi->fb.var.yres = inf->yres;
  1241. fbi->fb.var.yres_virtual = inf->yres;
  1242. fbi->max_bpp = inf->bpp;
  1243. fbi->fb.var.bits_per_pixel = inf->bpp;
  1244. fbi->fb.var.pixclock = inf->pixclock;
  1245. fbi->fb.var.hsync_len = inf->hsync_len;
  1246. fbi->fb.var.left_margin = inf->left_margin;
  1247. fbi->fb.var.right_margin = inf->right_margin;
  1248. fbi->fb.var.vsync_len = inf->vsync_len;
  1249. fbi->fb.var.upper_margin = inf->upper_margin;
  1250. fbi->fb.var.lower_margin = inf->lower_margin;
  1251. fbi->fb.var.sync = inf->sync;
  1252. fbi->fb.var.grayscale = inf->cmap_greyscale;
  1253. fbi->cmap_inverse = inf->cmap_inverse;
  1254. fbi->cmap_static = inf->cmap_static;
  1255. fbi->lccr0 = inf->lccr0;
  1256. fbi->lccr3 = inf->lccr3;
  1257. fbi->state = C_STARTUP;
  1258. fbi->task_state = (u_char)-1;
  1259. fbi->fb.fix.smem_len = fbi->max_xres * fbi->max_yres *
  1260. fbi->max_bpp / 8;
  1261. init_waitqueue_head(&fbi->ctrlr_wait);
  1262. INIT_WORK(&fbi->task, sa1100fb_task);
  1263. mutex_init(&fbi->ctrlr_lock);
  1264. return fbi;
  1265. }
  1266. static int __init sa1100fb_probe(struct platform_device *pdev)
  1267. {
  1268. struct sa1100fb_info *fbi;
  1269. int ret, irq;
  1270. irq = platform_get_irq(pdev, 0);
  1271. if (irq < 0)
  1272. return -EINVAL;
  1273. if (!request_mem_region(0xb0100000, 0x10000, "LCD"))
  1274. return -EBUSY;
  1275. fbi = sa1100fb_init_fbinfo(&pdev->dev);
  1276. ret = -ENOMEM;
  1277. if (!fbi)
  1278. goto failed;
  1279. /* Initialize video memory */
  1280. ret = sa1100fb_map_video_memory(fbi);
  1281. if (ret)
  1282. goto failed;
  1283. ret = request_irq(irq, sa1100fb_handle_irq, IRQF_DISABLED,
  1284. "LCD", fbi);
  1285. if (ret) {
  1286. printk(KERN_ERR "sa1100fb: request_irq failed: %d\n", ret);
  1287. goto failed;
  1288. }
  1289. #ifdef ASSABET_PAL_VIDEO
  1290. if (machine_is_assabet())
  1291. ASSABET_BCR_clear(ASSABET_BCR_LCD_ON);
  1292. #endif
  1293. /*
  1294. * This makes sure that our colour bitfield
  1295. * descriptors are correctly initialised.
  1296. */
  1297. sa1100fb_check_var(&fbi->fb.var, &fbi->fb);
  1298. platform_set_drvdata(pdev, fbi);
  1299. ret = register_framebuffer(&fbi->fb);
  1300. if (ret < 0)
  1301. goto err_free_irq;
  1302. #ifdef CONFIG_CPU_FREQ
  1303. fbi->freq_transition.notifier_call = sa1100fb_freq_transition;
  1304. fbi->freq_policy.notifier_call = sa1100fb_freq_policy;
  1305. cpufreq_register_notifier(&fbi->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
  1306. cpufreq_register_notifier(&fbi->freq_policy, CPUFREQ_POLICY_NOTIFIER);
  1307. #endif
  1308. /* This driver cannot be unloaded at the moment */
  1309. return 0;
  1310. err_free_irq:
  1311. free_irq(irq, fbi);
  1312. failed:
  1313. platform_set_drvdata(pdev, NULL);
  1314. kfree(fbi);
  1315. release_mem_region(0xb0100000, 0x10000);
  1316. return ret;
  1317. }
  1318. static struct platform_driver sa1100fb_driver = {
  1319. .probe = sa1100fb_probe,
  1320. .suspend = sa1100fb_suspend,
  1321. .resume = sa1100fb_resume,
  1322. .driver = {
  1323. .name = "sa11x0-fb",
  1324. },
  1325. };
  1326. int __init sa1100fb_init(void)
  1327. {
  1328. if (fb_get_options("sa1100fb", NULL))
  1329. return -ENODEV;
  1330. return platform_driver_register(&sa1100fb_driver);
  1331. }
  1332. int __init sa1100fb_setup(char *options)
  1333. {
  1334. #if 0
  1335. char *this_opt;
  1336. if (!options || !*options)
  1337. return 0;
  1338. while ((this_opt = strsep(&options, ",")) != NULL) {
  1339. if (!strncmp(this_opt, "bpp:", 4))
  1340. current_par.max_bpp =
  1341. simple_strtoul(this_opt + 4, NULL, 0);
  1342. if (!strncmp(this_opt, "lccr0:", 6))
  1343. lcd_shadow.lccr0 =
  1344. simple_strtoul(this_opt + 6, NULL, 0);
  1345. if (!strncmp(this_opt, "lccr1:", 6)) {
  1346. lcd_shadow.lccr1 =
  1347. simple_strtoul(this_opt + 6, NULL, 0);
  1348. current_par.max_xres =
  1349. (lcd_shadow.lccr1 & 0x3ff) + 16;
  1350. }
  1351. if (!strncmp(this_opt, "lccr2:", 6)) {
  1352. lcd_shadow.lccr2 =
  1353. simple_strtoul(this_opt + 6, NULL, 0);
  1354. current_par.max_yres =
  1355. (lcd_shadow.
  1356. lccr0 & LCCR0_SDS) ? ((lcd_shadow.
  1357. lccr2 & 0x3ff) +
  1358. 1) *
  1359. 2 : ((lcd_shadow.lccr2 & 0x3ff) + 1);
  1360. }
  1361. if (!strncmp(this_opt, "lccr3:", 6))
  1362. lcd_shadow.lccr3 =
  1363. simple_strtoul(this_opt + 6, NULL, 0);
  1364. }
  1365. #endif
  1366. return 0;
  1367. }
  1368. module_init(sa1100fb_init);
  1369. MODULE_DESCRIPTION("StrongARM-1100/1110 framebuffer driver");
  1370. MODULE_LICENSE("GPL");