sa1100fb.c 42 KB

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