au1200fb.c 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853
  1. /*
  2. * BRIEF MODULE DESCRIPTION
  3. * Au1200 LCD Driver.
  4. *
  5. * Copyright 2004-2005 AMD
  6. * Author: AMD
  7. *
  8. * Based on:
  9. * linux/drivers/video/skeletonfb.c -- Skeleton for a frame buffer device
  10. * Created 28 Dec 1997 by Geert Uytterhoeven
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the
  14. * Free Software Foundation; either version 2 of the License, or (at your
  15. * option) any later version.
  16. *
  17. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  20. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  23. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  24. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *
  28. * You should have received a copy of the GNU General Public License along
  29. * with this program; if not, write to the Free Software Foundation, Inc.,
  30. * 675 Mass Ave, Cambridge, MA 02139, USA.
  31. */
  32. #include <linux/clk.h>
  33. #include <linux/module.h>
  34. #include <linux/platform_device.h>
  35. #include <linux/kernel.h>
  36. #include <linux/errno.h>
  37. #include <linux/string.h>
  38. #include <linux/mm.h>
  39. #include <linux/fb.h>
  40. #include <linux/init.h>
  41. #include <linux/interrupt.h>
  42. #include <linux/ctype.h>
  43. #include <linux/dma-mapping.h>
  44. #include <linux/slab.h>
  45. #include <asm/mach-au1x00/au1000.h>
  46. #include <asm/mach-au1x00/au1200fb.h> /* platform_data */
  47. #include "au1200fb.h"
  48. #define DRIVER_NAME "au1200fb"
  49. #define DRIVER_DESC "LCD controller driver for AU1200 processors"
  50. #define DEBUG 0
  51. #define print_err(f, arg...) printk(KERN_ERR DRIVER_NAME ": " f "\n", ## arg)
  52. #define print_warn(f, arg...) printk(KERN_WARNING DRIVER_NAME ": " f "\n", ## arg)
  53. #define print_info(f, arg...) printk(KERN_INFO DRIVER_NAME ": " f "\n", ## arg)
  54. #if DEBUG
  55. #define print_dbg(f, arg...) printk(KERN_DEBUG __FILE__ ": " f "\n", ## arg)
  56. #else
  57. #define print_dbg(f, arg...) do {} while (0)
  58. #endif
  59. #define AU1200_LCD_FB_IOCTL 0x46FF
  60. #define AU1200_LCD_SET_SCREEN 1
  61. #define AU1200_LCD_GET_SCREEN 2
  62. #define AU1200_LCD_SET_WINDOW 3
  63. #define AU1200_LCD_GET_WINDOW 4
  64. #define AU1200_LCD_SET_PANEL 5
  65. #define AU1200_LCD_GET_PANEL 6
  66. #define SCREEN_SIZE (1<< 1)
  67. #define SCREEN_BACKCOLOR (1<< 2)
  68. #define SCREEN_BRIGHTNESS (1<< 3)
  69. #define SCREEN_COLORKEY (1<< 4)
  70. #define SCREEN_MASK (1<< 5)
  71. struct au1200_lcd_global_regs_t {
  72. unsigned int flags;
  73. unsigned int xsize;
  74. unsigned int ysize;
  75. unsigned int backcolor;
  76. unsigned int brightness;
  77. unsigned int colorkey;
  78. unsigned int mask;
  79. unsigned int panel_choice;
  80. char panel_desc[80];
  81. };
  82. #define WIN_POSITION (1<< 0)
  83. #define WIN_ALPHA_COLOR (1<< 1)
  84. #define WIN_ALPHA_MODE (1<< 2)
  85. #define WIN_PRIORITY (1<< 3)
  86. #define WIN_CHANNEL (1<< 4)
  87. #define WIN_BUFFER_FORMAT (1<< 5)
  88. #define WIN_COLOR_ORDER (1<< 6)
  89. #define WIN_PIXEL_ORDER (1<< 7)
  90. #define WIN_SIZE (1<< 8)
  91. #define WIN_COLORKEY_MODE (1<< 9)
  92. #define WIN_DOUBLE_BUFFER_MODE (1<< 10)
  93. #define WIN_RAM_ARRAY_MODE (1<< 11)
  94. #define WIN_BUFFER_SCALE (1<< 12)
  95. #define WIN_ENABLE (1<< 13)
  96. struct au1200_lcd_window_regs_t {
  97. unsigned int flags;
  98. unsigned int xpos;
  99. unsigned int ypos;
  100. unsigned int alpha_color;
  101. unsigned int alpha_mode;
  102. unsigned int priority;
  103. unsigned int channel;
  104. unsigned int buffer_format;
  105. unsigned int color_order;
  106. unsigned int pixel_order;
  107. unsigned int xsize;
  108. unsigned int ysize;
  109. unsigned int colorkey_mode;
  110. unsigned int double_buffer_mode;
  111. unsigned int ram_array_mode;
  112. unsigned int xscale;
  113. unsigned int yscale;
  114. unsigned int enable;
  115. };
  116. struct au1200_lcd_iodata_t {
  117. unsigned int subcmd;
  118. struct au1200_lcd_global_regs_t global;
  119. struct au1200_lcd_window_regs_t window;
  120. };
  121. #if defined(__BIG_ENDIAN)
  122. #define LCD_CONTROL_DEFAULT_PO LCD_CONTROL_PO_11
  123. #else
  124. #define LCD_CONTROL_DEFAULT_PO LCD_CONTROL_PO_00
  125. #endif
  126. #define LCD_CONTROL_DEFAULT_SBPPF LCD_CONTROL_SBPPF_565
  127. /* Private, per-framebuffer management information (independent of the panel itself) */
  128. struct au1200fb_device {
  129. struct fb_info *fb_info; /* FB driver info record */
  130. struct au1200fb_platdata *pd;
  131. int plane;
  132. unsigned char* fb_mem; /* FrameBuffer memory map */
  133. unsigned int fb_len;
  134. dma_addr_t fb_phys;
  135. };
  136. /********************************************************************/
  137. /* LCD controller restrictions */
  138. #define AU1200_LCD_MAX_XRES 1280
  139. #define AU1200_LCD_MAX_YRES 1024
  140. #define AU1200_LCD_MAX_BPP 32
  141. #define AU1200_LCD_MAX_CLK 96000000 /* fixme: this needs to go away ? */
  142. #define AU1200_LCD_NBR_PALETTE_ENTRIES 256
  143. /* Default number of visible screen buffer to allocate */
  144. #define AU1200FB_NBR_VIDEO_BUFFERS 1
  145. /* Default maximum number of fb devices to create */
  146. #define MAX_DEVICE_COUNT 4
  147. /* Default window configuration entry to use (see windows[]) */
  148. #define DEFAULT_WINDOW_INDEX 2
  149. /********************************************************************/
  150. static struct fb_info *_au1200fb_infos[MAX_DEVICE_COUNT];
  151. static struct au1200_lcd *lcd = (struct au1200_lcd *) AU1200_LCD_ADDR;
  152. static int device_count = MAX_DEVICE_COUNT;
  153. static int window_index = DEFAULT_WINDOW_INDEX; /* default is zero */
  154. static int panel_index = 2; /* default is zero */
  155. static struct window_settings *win;
  156. static struct panel_settings *panel;
  157. static int noblanking = 1;
  158. static int nohwcursor = 0;
  159. struct window_settings {
  160. unsigned char name[64];
  161. uint32 mode_backcolor;
  162. uint32 mode_colorkey;
  163. uint32 mode_colorkeymsk;
  164. struct {
  165. int xres;
  166. int yres;
  167. int xpos;
  168. int ypos;
  169. uint32 mode_winctrl1; /* winctrl1[FRM,CCO,PO,PIPE] */
  170. uint32 mode_winenable;
  171. } w[4];
  172. };
  173. #if defined(__BIG_ENDIAN)
  174. #define LCD_WINCTRL1_PO_16BPP LCD_WINCTRL1_PO_00
  175. #else
  176. #define LCD_WINCTRL1_PO_16BPP LCD_WINCTRL1_PO_01
  177. #endif
  178. /*
  179. * Default window configurations
  180. */
  181. static struct window_settings windows[] = {
  182. { /* Index 0 */
  183. "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
  184. /* mode_backcolor */ 0x006600ff,
  185. /* mode_colorkey,msk*/ 0, 0,
  186. {
  187. {
  188. /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
  189. /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
  190. LCD_WINCTRL1_PO_16BPP,
  191. /* mode_winenable*/ LCD_WINENABLE_WEN0,
  192. },
  193. {
  194. /* xres, yres, xpos, ypos */ 100, 100, 100, 100,
  195. /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
  196. LCD_WINCTRL1_PO_16BPP |
  197. LCD_WINCTRL1_PIPE,
  198. /* mode_winenable*/ LCD_WINENABLE_WEN1,
  199. },
  200. {
  201. /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
  202. /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
  203. LCD_WINCTRL1_PO_16BPP,
  204. /* mode_winenable*/ 0,
  205. },
  206. {
  207. /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
  208. /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
  209. LCD_WINCTRL1_PO_16BPP |
  210. LCD_WINCTRL1_PIPE,
  211. /* mode_winenable*/ 0,
  212. },
  213. },
  214. },
  215. { /* Index 1 */
  216. "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
  217. /* mode_backcolor */ 0x006600ff,
  218. /* mode_colorkey,msk*/ 0, 0,
  219. {
  220. {
  221. /* xres, yres, xpos, ypos */ 320, 240, 5, 5,
  222. /* mode_winctrl1 */ LCD_WINCTRL1_FRM_24BPP |
  223. LCD_WINCTRL1_PO_00,
  224. /* mode_winenable*/ LCD_WINENABLE_WEN0,
  225. },
  226. {
  227. /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
  228. /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565
  229. | LCD_WINCTRL1_PO_16BPP,
  230. /* mode_winenable*/ 0,
  231. },
  232. {
  233. /* xres, yres, xpos, ypos */ 100, 100, 0, 0,
  234. /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
  235. LCD_WINCTRL1_PO_16BPP |
  236. LCD_WINCTRL1_PIPE,
  237. /* mode_winenable*/ 0/*LCD_WINENABLE_WEN2*/,
  238. },
  239. {
  240. /* xres, yres, xpos, ypos */ 200, 25, 0, 0,
  241. /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
  242. LCD_WINCTRL1_PO_16BPP |
  243. LCD_WINCTRL1_PIPE,
  244. /* mode_winenable*/ 0,
  245. },
  246. },
  247. },
  248. { /* Index 2 */
  249. "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
  250. /* mode_backcolor */ 0x006600ff,
  251. /* mode_colorkey,msk*/ 0, 0,
  252. {
  253. {
  254. /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
  255. /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
  256. LCD_WINCTRL1_PO_16BPP,
  257. /* mode_winenable*/ LCD_WINENABLE_WEN0,
  258. },
  259. {
  260. /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
  261. /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
  262. LCD_WINCTRL1_PO_16BPP,
  263. /* mode_winenable*/ 0,
  264. },
  265. {
  266. /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
  267. /* mode_winctrl1 */ LCD_WINCTRL1_FRM_32BPP |
  268. LCD_WINCTRL1_PO_00|LCD_WINCTRL1_PIPE,
  269. /* mode_winenable*/ 0/*LCD_WINENABLE_WEN2*/,
  270. },
  271. {
  272. /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
  273. /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
  274. LCD_WINCTRL1_PO_16BPP |
  275. LCD_WINCTRL1_PIPE,
  276. /* mode_winenable*/ 0,
  277. },
  278. },
  279. },
  280. /* Need VGA 640 @ 24bpp, @ 32bpp */
  281. /* Need VGA 800 @ 24bpp, @ 32bpp */
  282. /* Need VGA 1024 @ 24bpp, @ 32bpp */
  283. };
  284. /*
  285. * Controller configurations for various panels.
  286. */
  287. struct panel_settings
  288. {
  289. const char name[25]; /* Full name <vendor>_<model> */
  290. struct fb_monspecs monspecs; /* FB monitor specs */
  291. /* panel timings */
  292. uint32 mode_screen;
  293. uint32 mode_horztiming;
  294. uint32 mode_verttiming;
  295. uint32 mode_clkcontrol;
  296. uint32 mode_pwmdiv;
  297. uint32 mode_pwmhi;
  298. uint32 mode_outmask;
  299. uint32 mode_fifoctrl;
  300. uint32 mode_backlight;
  301. uint32 lcdclk;
  302. #define Xres min_xres
  303. #define Yres min_yres
  304. u32 min_xres; /* Minimum horizontal resolution */
  305. u32 max_xres; /* Maximum horizontal resolution */
  306. u32 min_yres; /* Minimum vertical resolution */
  307. u32 max_yres; /* Maximum vertical resolution */
  308. };
  309. /********************************************************************/
  310. /* fixme: Maybe a modedb for the CRT ? otherwise panels should be as-is */
  311. /* List of panels known to work with the AU1200 LCD controller.
  312. * To add a new panel, enter the same specifications as the
  313. * Generic_TFT one, and MAKE SURE that it doesn't conflicts
  314. * with the controller restrictions. Restrictions are:
  315. *
  316. * STN color panels: max_bpp <= 12
  317. * STN mono panels: max_bpp <= 4
  318. * TFT panels: max_bpp <= 16
  319. * max_xres <= 800
  320. * max_yres <= 600
  321. */
  322. static struct panel_settings known_lcd_panels[] =
  323. {
  324. [0] = { /* QVGA 320x240 H:33.3kHz V:110Hz */
  325. .name = "QVGA_320x240",
  326. .monspecs = {
  327. .modedb = NULL,
  328. .modedb_len = 0,
  329. .hfmin = 30000,
  330. .hfmax = 70000,
  331. .vfmin = 60,
  332. .vfmax = 60,
  333. .dclkmin = 6000000,
  334. .dclkmax = 28000000,
  335. .input = FB_DISP_RGB,
  336. },
  337. .mode_screen = LCD_SCREEN_SX_N(320) |
  338. LCD_SCREEN_SY_N(240),
  339. .mode_horztiming = 0x00c4623b,
  340. .mode_verttiming = 0x00502814,
  341. .mode_clkcontrol = 0x00020002, /* /4=24Mhz */
  342. .mode_pwmdiv = 0x00000000,
  343. .mode_pwmhi = 0x00000000,
  344. .mode_outmask = 0x00FFFFFF,
  345. .mode_fifoctrl = 0x2f2f2f2f,
  346. .mode_backlight = 0x00000000,
  347. .lcdclk = 96,
  348. 320, 320,
  349. 240, 240,
  350. },
  351. [1] = { /* VGA 640x480 H:30.3kHz V:58Hz */
  352. .name = "VGA_640x480",
  353. .monspecs = {
  354. .modedb = NULL,
  355. .modedb_len = 0,
  356. .hfmin = 30000,
  357. .hfmax = 70000,
  358. .vfmin = 60,
  359. .vfmax = 60,
  360. .dclkmin = 6000000,
  361. .dclkmax = 28000000,
  362. .input = FB_DISP_RGB,
  363. },
  364. .mode_screen = 0x13f9df80,
  365. .mode_horztiming = 0x003c5859,
  366. .mode_verttiming = 0x00741201,
  367. .mode_clkcontrol = 0x00020001, /* /4=24Mhz */
  368. .mode_pwmdiv = 0x00000000,
  369. .mode_pwmhi = 0x00000000,
  370. .mode_outmask = 0x00FFFFFF,
  371. .mode_fifoctrl = 0x2f2f2f2f,
  372. .mode_backlight = 0x00000000,
  373. .lcdclk = 96,
  374. 640, 480,
  375. 640, 480,
  376. },
  377. [2] = { /* SVGA 800x600 H:46.1kHz V:69Hz */
  378. .name = "SVGA_800x600",
  379. .monspecs = {
  380. .modedb = NULL,
  381. .modedb_len = 0,
  382. .hfmin = 30000,
  383. .hfmax = 70000,
  384. .vfmin = 60,
  385. .vfmax = 60,
  386. .dclkmin = 6000000,
  387. .dclkmax = 28000000,
  388. .input = FB_DISP_RGB,
  389. },
  390. .mode_screen = 0x18fa5780,
  391. .mode_horztiming = 0x00dc7e77,
  392. .mode_verttiming = 0x00584805,
  393. .mode_clkcontrol = 0x00020000, /* /2=48Mhz */
  394. .mode_pwmdiv = 0x00000000,
  395. .mode_pwmhi = 0x00000000,
  396. .mode_outmask = 0x00FFFFFF,
  397. .mode_fifoctrl = 0x2f2f2f2f,
  398. .mode_backlight = 0x00000000,
  399. .lcdclk = 96,
  400. 800, 800,
  401. 600, 600,
  402. },
  403. [3] = { /* XVGA 1024x768 H:56.2kHz V:70Hz */
  404. .name = "XVGA_1024x768",
  405. .monspecs = {
  406. .modedb = NULL,
  407. .modedb_len = 0,
  408. .hfmin = 30000,
  409. .hfmax = 70000,
  410. .vfmin = 60,
  411. .vfmax = 60,
  412. .dclkmin = 6000000,
  413. .dclkmax = 28000000,
  414. .input = FB_DISP_RGB,
  415. },
  416. .mode_screen = 0x1ffaff80,
  417. .mode_horztiming = 0x007d0e57,
  418. .mode_verttiming = 0x00740a01,
  419. .mode_clkcontrol = 0x000A0000, /* /1 */
  420. .mode_pwmdiv = 0x00000000,
  421. .mode_pwmhi = 0x00000000,
  422. .mode_outmask = 0x00FFFFFF,
  423. .mode_fifoctrl = 0x2f2f2f2f,
  424. .mode_backlight = 0x00000000,
  425. .lcdclk = 72,
  426. 1024, 1024,
  427. 768, 768,
  428. },
  429. [4] = { /* XVGA XVGA 1280x1024 H:68.5kHz V:65Hz */
  430. .name = "XVGA_1280x1024",
  431. .monspecs = {
  432. .modedb = NULL,
  433. .modedb_len = 0,
  434. .hfmin = 30000,
  435. .hfmax = 70000,
  436. .vfmin = 60,
  437. .vfmax = 60,
  438. .dclkmin = 6000000,
  439. .dclkmax = 28000000,
  440. .input = FB_DISP_RGB,
  441. },
  442. .mode_screen = 0x27fbff80,
  443. .mode_horztiming = 0x00cdb2c7,
  444. .mode_verttiming = 0x00600002,
  445. .mode_clkcontrol = 0x000A0000, /* /1 */
  446. .mode_pwmdiv = 0x00000000,
  447. .mode_pwmhi = 0x00000000,
  448. .mode_outmask = 0x00FFFFFF,
  449. .mode_fifoctrl = 0x2f2f2f2f,
  450. .mode_backlight = 0x00000000,
  451. .lcdclk = 120,
  452. 1280, 1280,
  453. 1024, 1024,
  454. },
  455. [5] = { /* Samsung 1024x768 TFT */
  456. .name = "Samsung_1024x768_TFT",
  457. .monspecs = {
  458. .modedb = NULL,
  459. .modedb_len = 0,
  460. .hfmin = 30000,
  461. .hfmax = 70000,
  462. .vfmin = 60,
  463. .vfmax = 60,
  464. .dclkmin = 6000000,
  465. .dclkmax = 28000000,
  466. .input = FB_DISP_RGB,
  467. },
  468. .mode_screen = 0x1ffaff80,
  469. .mode_horztiming = 0x018cc677,
  470. .mode_verttiming = 0x00241217,
  471. .mode_clkcontrol = 0x00000000, /* SCB 0x1 /4=24Mhz */
  472. .mode_pwmdiv = 0x8000063f, /* SCB 0x0 */
  473. .mode_pwmhi = 0x03400000, /* SCB 0x0 */
  474. .mode_outmask = 0x00FFFFFF,
  475. .mode_fifoctrl = 0x2f2f2f2f,
  476. .mode_backlight = 0x00000000,
  477. .lcdclk = 96,
  478. 1024, 1024,
  479. 768, 768,
  480. },
  481. [6] = { /* Toshiba 640x480 TFT */
  482. .name = "Toshiba_640x480_TFT",
  483. .monspecs = {
  484. .modedb = NULL,
  485. .modedb_len = 0,
  486. .hfmin = 30000,
  487. .hfmax = 70000,
  488. .vfmin = 60,
  489. .vfmax = 60,
  490. .dclkmin = 6000000,
  491. .dclkmax = 28000000,
  492. .input = FB_DISP_RGB,
  493. },
  494. .mode_screen = LCD_SCREEN_SX_N(640) |
  495. LCD_SCREEN_SY_N(480),
  496. .mode_horztiming = LCD_HORZTIMING_HPW_N(96) |
  497. LCD_HORZTIMING_HND1_N(13) | LCD_HORZTIMING_HND2_N(51),
  498. .mode_verttiming = LCD_VERTTIMING_VPW_N(2) |
  499. LCD_VERTTIMING_VND1_N(11) | LCD_VERTTIMING_VND2_N(32),
  500. .mode_clkcontrol = 0x00000000, /* /4=24Mhz */
  501. .mode_pwmdiv = 0x8000063f,
  502. .mode_pwmhi = 0x03400000,
  503. .mode_outmask = 0x00fcfcfc,
  504. .mode_fifoctrl = 0x2f2f2f2f,
  505. .mode_backlight = 0x00000000,
  506. .lcdclk = 96,
  507. 640, 480,
  508. 640, 480,
  509. },
  510. [7] = { /* Sharp 320x240 TFT */
  511. .name = "Sharp_320x240_TFT",
  512. .monspecs = {
  513. .modedb = NULL,
  514. .modedb_len = 0,
  515. .hfmin = 12500,
  516. .hfmax = 20000,
  517. .vfmin = 38,
  518. .vfmax = 81,
  519. .dclkmin = 4500000,
  520. .dclkmax = 6800000,
  521. .input = FB_DISP_RGB,
  522. },
  523. .mode_screen = LCD_SCREEN_SX_N(320) |
  524. LCD_SCREEN_SY_N(240),
  525. .mode_horztiming = LCD_HORZTIMING_HPW_N(60) |
  526. LCD_HORZTIMING_HND1_N(13) | LCD_HORZTIMING_HND2_N(2),
  527. .mode_verttiming = LCD_VERTTIMING_VPW_N(2) |
  528. LCD_VERTTIMING_VND1_N(2) | LCD_VERTTIMING_VND2_N(5),
  529. .mode_clkcontrol = LCD_CLKCONTROL_PCD_N(7), /*16=6Mhz*/
  530. .mode_pwmdiv = 0x8000063f,
  531. .mode_pwmhi = 0x03400000,
  532. .mode_outmask = 0x00fcfcfc,
  533. .mode_fifoctrl = 0x2f2f2f2f,
  534. .mode_backlight = 0x00000000,
  535. .lcdclk = 96, /* 96MHz AUXPLL */
  536. 320, 320,
  537. 240, 240,
  538. },
  539. [8] = { /* Toppoly TD070WGCB2 7" 856x480 TFT */
  540. .name = "Toppoly_TD070WGCB2",
  541. .monspecs = {
  542. .modedb = NULL,
  543. .modedb_len = 0,
  544. .hfmin = 30000,
  545. .hfmax = 70000,
  546. .vfmin = 60,
  547. .vfmax = 60,
  548. .dclkmin = 6000000,
  549. .dclkmax = 28000000,
  550. .input = FB_DISP_RGB,
  551. },
  552. .mode_screen = LCD_SCREEN_SX_N(856) |
  553. LCD_SCREEN_SY_N(480),
  554. .mode_horztiming = LCD_HORZTIMING_HND2_N(43) |
  555. LCD_HORZTIMING_HND1_N(43) | LCD_HORZTIMING_HPW_N(114),
  556. .mode_verttiming = LCD_VERTTIMING_VND2_N(20) |
  557. LCD_VERTTIMING_VND1_N(21) | LCD_VERTTIMING_VPW_N(4),
  558. .mode_clkcontrol = 0x00020001, /* /4=24Mhz */
  559. .mode_pwmdiv = 0x8000063f,
  560. .mode_pwmhi = 0x03400000,
  561. .mode_outmask = 0x00fcfcfc,
  562. .mode_fifoctrl = 0x2f2f2f2f,
  563. .mode_backlight = 0x00000000,
  564. .lcdclk = 96,
  565. 856, 856,
  566. 480, 480,
  567. },
  568. [9] = {
  569. .name = "DB1300_800x480",
  570. .monspecs = {
  571. .modedb = NULL,
  572. .modedb_len = 0,
  573. .hfmin = 30000,
  574. .hfmax = 70000,
  575. .vfmin = 60,
  576. .vfmax = 60,
  577. .dclkmin = 6000000,
  578. .dclkmax = 28000000,
  579. .input = FB_DISP_RGB,
  580. },
  581. .mode_screen = LCD_SCREEN_SX_N(800) |
  582. LCD_SCREEN_SY_N(480),
  583. .mode_horztiming = LCD_HORZTIMING_HPW_N(5) |
  584. LCD_HORZTIMING_HND1_N(16) |
  585. LCD_HORZTIMING_HND2_N(8),
  586. .mode_verttiming = LCD_VERTTIMING_VPW_N(4) |
  587. LCD_VERTTIMING_VND1_N(8) |
  588. LCD_VERTTIMING_VND2_N(5),
  589. .mode_clkcontrol = LCD_CLKCONTROL_PCD_N(1) |
  590. LCD_CLKCONTROL_IV |
  591. LCD_CLKCONTROL_IH,
  592. .mode_pwmdiv = 0x00000000,
  593. .mode_pwmhi = 0x00000000,
  594. .mode_outmask = 0x00FFFFFF,
  595. .mode_fifoctrl = 0x2f2f2f2f,
  596. .mode_backlight = 0x00000000,
  597. .lcdclk = 96,
  598. 800, 800,
  599. 480, 480,
  600. },
  601. };
  602. #define NUM_PANELS (ARRAY_SIZE(known_lcd_panels))
  603. /********************************************************************/
  604. static int winbpp (unsigned int winctrl1)
  605. {
  606. int bits = 0;
  607. /* how many bits are needed for each pixel format */
  608. switch (winctrl1 & LCD_WINCTRL1_FRM) {
  609. case LCD_WINCTRL1_FRM_1BPP:
  610. bits = 1;
  611. break;
  612. case LCD_WINCTRL1_FRM_2BPP:
  613. bits = 2;
  614. break;
  615. case LCD_WINCTRL1_FRM_4BPP:
  616. bits = 4;
  617. break;
  618. case LCD_WINCTRL1_FRM_8BPP:
  619. bits = 8;
  620. break;
  621. case LCD_WINCTRL1_FRM_12BPP:
  622. case LCD_WINCTRL1_FRM_16BPP655:
  623. case LCD_WINCTRL1_FRM_16BPP565:
  624. case LCD_WINCTRL1_FRM_16BPP556:
  625. case LCD_WINCTRL1_FRM_16BPPI1555:
  626. case LCD_WINCTRL1_FRM_16BPPI5551:
  627. case LCD_WINCTRL1_FRM_16BPPA1555:
  628. case LCD_WINCTRL1_FRM_16BPPA5551:
  629. bits = 16;
  630. break;
  631. case LCD_WINCTRL1_FRM_24BPP:
  632. case LCD_WINCTRL1_FRM_32BPP:
  633. bits = 32;
  634. break;
  635. }
  636. return bits;
  637. }
  638. static int fbinfo2index (struct fb_info *fb_info)
  639. {
  640. int i;
  641. for (i = 0; i < device_count; ++i) {
  642. if (fb_info == _au1200fb_infos[i])
  643. return i;
  644. }
  645. printk("au1200fb: ERROR: fbinfo2index failed!\n");
  646. return -1;
  647. }
  648. static int au1200_setlocation (struct au1200fb_device *fbdev, int plane,
  649. int xpos, int ypos)
  650. {
  651. uint32 winctrl0, winctrl1, winenable, fb_offset = 0;
  652. int xsz, ysz;
  653. /* FIX!!! NOT CHECKING FOR COMPLETE OFFSCREEN YET */
  654. winctrl0 = lcd->window[plane].winctrl0;
  655. winctrl1 = lcd->window[plane].winctrl1;
  656. winctrl0 &= (LCD_WINCTRL0_A | LCD_WINCTRL0_AEN);
  657. winctrl1 &= ~(LCD_WINCTRL1_SZX | LCD_WINCTRL1_SZY);
  658. /* Check for off-screen adjustments */
  659. xsz = win->w[plane].xres;
  660. ysz = win->w[plane].yres;
  661. if ((xpos + win->w[plane].xres) > panel->Xres) {
  662. /* Off-screen to the right */
  663. xsz = panel->Xres - xpos; /* off by 1 ??? */
  664. /*printk("off screen right\n");*/
  665. }
  666. if ((ypos + win->w[plane].yres) > panel->Yres) {
  667. /* Off-screen to the bottom */
  668. ysz = panel->Yres - ypos; /* off by 1 ??? */
  669. /*printk("off screen bottom\n");*/
  670. }
  671. if (xpos < 0) {
  672. /* Off-screen to the left */
  673. xsz = win->w[plane].xres + xpos;
  674. fb_offset += (((0 - xpos) * winbpp(lcd->window[plane].winctrl1))/8);
  675. xpos = 0;
  676. /*printk("off screen left\n");*/
  677. }
  678. if (ypos < 0) {
  679. /* Off-screen to the top */
  680. ysz = win->w[plane].yres + ypos;
  681. /* fixme: fb_offset += ((0-ypos)*fb_pars[plane].line_length); */
  682. ypos = 0;
  683. /*printk("off screen top\n");*/
  684. }
  685. /* record settings */
  686. win->w[plane].xpos = xpos;
  687. win->w[plane].ypos = ypos;
  688. xsz -= 1;
  689. ysz -= 1;
  690. winctrl0 |= (xpos << 21);
  691. winctrl0 |= (ypos << 10);
  692. winctrl1 |= (xsz << 11);
  693. winctrl1 |= (ysz << 0);
  694. /* Disable the window while making changes, then restore WINEN */
  695. winenable = lcd->winenable & (1 << plane);
  696. wmb(); /* drain writebuffer */
  697. lcd->winenable &= ~(1 << plane);
  698. lcd->window[plane].winctrl0 = winctrl0;
  699. lcd->window[plane].winctrl1 = winctrl1;
  700. lcd->window[plane].winbuf0 =
  701. lcd->window[plane].winbuf1 = fbdev->fb_phys;
  702. lcd->window[plane].winbufctrl = 0; /* select winbuf0 */
  703. lcd->winenable |= winenable;
  704. wmb(); /* drain writebuffer */
  705. return 0;
  706. }
  707. static void au1200_setpanel(struct panel_settings *newpanel,
  708. struct au1200fb_platdata *pd)
  709. {
  710. /*
  711. * Perform global setup/init of LCD controller
  712. */
  713. uint32 winenable;
  714. /* Make sure all windows disabled */
  715. winenable = lcd->winenable;
  716. lcd->winenable = 0;
  717. wmb(); /* drain writebuffer */
  718. /*
  719. * Ensure everything is disabled before reconfiguring
  720. */
  721. if (lcd->screen & LCD_SCREEN_SEN) {
  722. /* Wait for vertical sync period */
  723. lcd->intstatus = LCD_INT_SS;
  724. while ((lcd->intstatus & LCD_INT_SS) == 0)
  725. ;
  726. lcd->screen &= ~LCD_SCREEN_SEN; /*disable the controller*/
  727. do {
  728. lcd->intstatus = lcd->intstatus; /*clear interrupts*/
  729. wmb(); /* drain writebuffer */
  730. /*wait for controller to shut down*/
  731. } while ((lcd->intstatus & LCD_INT_SD) == 0);
  732. /* Call shutdown of current panel (if up) */
  733. /* this must occur last, because if an external clock is driving
  734. the controller, the clock cannot be turned off before first
  735. shutting down the controller.
  736. */
  737. if (pd->panel_shutdown)
  738. pd->panel_shutdown();
  739. }
  740. /* Newpanel == NULL indicates a shutdown operation only */
  741. if (newpanel == NULL)
  742. return;
  743. panel = newpanel;
  744. printk("Panel(%s), %dx%d\n", panel->name, panel->Xres, panel->Yres);
  745. /*
  746. * Setup clocking if internal LCD clock source (assumes sys_auxpll valid)
  747. */
  748. if (!(panel->mode_clkcontrol & LCD_CLKCONTROL_EXT))
  749. {
  750. struct clk *c = clk_get(NULL, "lcd_intclk");
  751. long r, pc = panel->lcdclk * 1000000;
  752. if (!IS_ERR(c)) {
  753. r = clk_round_rate(c, pc);
  754. if ((pc - r) < (pc / 10)) { /* 10% slack */
  755. clk_set_rate(c, r);
  756. clk_prepare_enable(c);
  757. }
  758. clk_put(c);
  759. }
  760. }
  761. /*
  762. * Configure panel timings
  763. */
  764. lcd->screen = panel->mode_screen;
  765. lcd->horztiming = panel->mode_horztiming;
  766. lcd->verttiming = panel->mode_verttiming;
  767. lcd->clkcontrol = panel->mode_clkcontrol;
  768. lcd->pwmdiv = panel->mode_pwmdiv;
  769. lcd->pwmhi = panel->mode_pwmhi;
  770. lcd->outmask = panel->mode_outmask;
  771. lcd->fifoctrl = panel->mode_fifoctrl;
  772. wmb(); /* drain writebuffer */
  773. /* fixme: Check window settings to make sure still valid
  774. * for new geometry */
  775. #if 0
  776. au1200_setlocation(fbdev, 0, win->w[0].xpos, win->w[0].ypos);
  777. au1200_setlocation(fbdev, 1, win->w[1].xpos, win->w[1].ypos);
  778. au1200_setlocation(fbdev, 2, win->w[2].xpos, win->w[2].ypos);
  779. au1200_setlocation(fbdev, 3, win->w[3].xpos, win->w[3].ypos);
  780. #endif
  781. lcd->winenable = winenable;
  782. /*
  783. * Re-enable screen now that it is configured
  784. */
  785. lcd->screen |= LCD_SCREEN_SEN;
  786. wmb(); /* drain writebuffer */
  787. /* Call init of panel */
  788. if (pd->panel_init)
  789. pd->panel_init();
  790. /* FIX!!!! not appropriate on panel change!!! Global setup/init */
  791. lcd->intenable = 0;
  792. lcd->intstatus = ~0;
  793. lcd->backcolor = win->mode_backcolor;
  794. /* Setup Color Key - FIX!!! */
  795. lcd->colorkey = win->mode_colorkey;
  796. lcd->colorkeymsk = win->mode_colorkeymsk;
  797. /* Setup HWCursor - FIX!!! Need to support this eventually */
  798. lcd->hwc.cursorctrl = 0;
  799. lcd->hwc.cursorpos = 0;
  800. lcd->hwc.cursorcolor0 = 0;
  801. lcd->hwc.cursorcolor1 = 0;
  802. lcd->hwc.cursorcolor2 = 0;
  803. lcd->hwc.cursorcolor3 = 0;
  804. #if 0
  805. #define D(X) printk("%25s: %08X\n", #X, X)
  806. D(lcd->screen);
  807. D(lcd->horztiming);
  808. D(lcd->verttiming);
  809. D(lcd->clkcontrol);
  810. D(lcd->pwmdiv);
  811. D(lcd->pwmhi);
  812. D(lcd->outmask);
  813. D(lcd->fifoctrl);
  814. D(lcd->window[0].winctrl0);
  815. D(lcd->window[0].winctrl1);
  816. D(lcd->window[0].winctrl2);
  817. D(lcd->window[0].winbuf0);
  818. D(lcd->window[0].winbuf1);
  819. D(lcd->window[0].winbufctrl);
  820. D(lcd->window[1].winctrl0);
  821. D(lcd->window[1].winctrl1);
  822. D(lcd->window[1].winctrl2);
  823. D(lcd->window[1].winbuf0);
  824. D(lcd->window[1].winbuf1);
  825. D(lcd->window[1].winbufctrl);
  826. D(lcd->window[2].winctrl0);
  827. D(lcd->window[2].winctrl1);
  828. D(lcd->window[2].winctrl2);
  829. D(lcd->window[2].winbuf0);
  830. D(lcd->window[2].winbuf1);
  831. D(lcd->window[2].winbufctrl);
  832. D(lcd->window[3].winctrl0);
  833. D(lcd->window[3].winctrl1);
  834. D(lcd->window[3].winctrl2);
  835. D(lcd->window[3].winbuf0);
  836. D(lcd->window[3].winbuf1);
  837. D(lcd->window[3].winbufctrl);
  838. D(lcd->winenable);
  839. D(lcd->intenable);
  840. D(lcd->intstatus);
  841. D(lcd->backcolor);
  842. D(lcd->winenable);
  843. D(lcd->colorkey);
  844. D(lcd->colorkeymsk);
  845. D(lcd->hwc.cursorctrl);
  846. D(lcd->hwc.cursorpos);
  847. D(lcd->hwc.cursorcolor0);
  848. D(lcd->hwc.cursorcolor1);
  849. D(lcd->hwc.cursorcolor2);
  850. D(lcd->hwc.cursorcolor3);
  851. #endif
  852. }
  853. static void au1200_setmode(struct au1200fb_device *fbdev)
  854. {
  855. int plane = fbdev->plane;
  856. /* Window/plane setup */
  857. lcd->window[plane].winctrl1 = ( 0
  858. | LCD_WINCTRL1_PRI_N(plane)
  859. | win->w[plane].mode_winctrl1 /* FRM,CCO,PO,PIPE */
  860. ) ;
  861. au1200_setlocation(fbdev, plane, win->w[plane].xpos, win->w[plane].ypos);
  862. lcd->window[plane].winctrl2 = ( 0
  863. | LCD_WINCTRL2_CKMODE_00
  864. | LCD_WINCTRL2_DBM
  865. | LCD_WINCTRL2_BX_N(fbdev->fb_info->fix.line_length)
  866. | LCD_WINCTRL2_SCX_1
  867. | LCD_WINCTRL2_SCY_1
  868. ) ;
  869. lcd->winenable |= win->w[plane].mode_winenable;
  870. wmb(); /* drain writebuffer */
  871. }
  872. /* Inline helpers */
  873. /*#define panel_is_dual(panel) ((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/
  874. /*#define panel_is_active(panel)((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/
  875. #define panel_is_color(panel) ((panel->mode_screen & LCD_SCREEN_PT) <= LCD_SCREEN_PT_CDSTN)
  876. /* Bitfields format supported by the controller. */
  877. static struct fb_bitfield rgb_bitfields[][4] = {
  878. /* Red, Green, Blue, Transp */
  879. [LCD_WINCTRL1_FRM_16BPP655 >> 25] =
  880. { { 10, 6, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
  881. [LCD_WINCTRL1_FRM_16BPP565 >> 25] =
  882. { { 11, 5, 0 }, { 5, 6, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
  883. [LCD_WINCTRL1_FRM_16BPP556 >> 25] =
  884. { { 11, 5, 0 }, { 6, 5, 0 }, { 0, 6, 0 }, { 0, 0, 0 } },
  885. [LCD_WINCTRL1_FRM_16BPPI1555 >> 25] =
  886. { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
  887. [LCD_WINCTRL1_FRM_16BPPI5551 >> 25] =
  888. { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 0, 0 } },
  889. [LCD_WINCTRL1_FRM_16BPPA1555 >> 25] =
  890. { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 15, 1, 0 } },
  891. [LCD_WINCTRL1_FRM_16BPPA5551 >> 25] =
  892. { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 1, 0 } },
  893. [LCD_WINCTRL1_FRM_24BPP >> 25] =
  894. { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 0, 0, 0 } },
  895. [LCD_WINCTRL1_FRM_32BPP >> 25] =
  896. { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 24, 0, 0 } },
  897. };
  898. /*-------------------------------------------------------------------------*/
  899. /* Helpers */
  900. static void au1200fb_update_fbinfo(struct fb_info *fbi)
  901. {
  902. /* FIX!!!! This also needs to take the window pixel format into account!!! */
  903. /* Update var-dependent FB info */
  904. if (panel_is_color(panel)) {
  905. if (fbi->var.bits_per_pixel <= 8) {
  906. /* palettized */
  907. fbi->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  908. fbi->fix.line_length = fbi->var.xres_virtual /
  909. (8/fbi->var.bits_per_pixel);
  910. } else {
  911. /* non-palettized */
  912. fbi->fix.visual = FB_VISUAL_TRUECOLOR;
  913. fbi->fix.line_length = fbi->var.xres_virtual * (fbi->var.bits_per_pixel / 8);
  914. }
  915. } else {
  916. /* mono FIX!!! mono 8 and 4 bits */
  917. fbi->fix.visual = FB_VISUAL_MONO10;
  918. fbi->fix.line_length = fbi->var.xres_virtual / 8;
  919. }
  920. fbi->screen_size = fbi->fix.line_length * fbi->var.yres_virtual;
  921. print_dbg("line length: %d\n", fbi->fix.line_length);
  922. print_dbg("bits_per_pixel: %d\n", fbi->var.bits_per_pixel);
  923. }
  924. /*-------------------------------------------------------------------------*/
  925. /* AU1200 framebuffer driver */
  926. /* fb_check_var
  927. * Validate var settings with hardware restrictions and modify it if necessary
  928. */
  929. static int au1200fb_fb_check_var(struct fb_var_screeninfo *var,
  930. struct fb_info *fbi)
  931. {
  932. struct au1200fb_device *fbdev = fbi->par;
  933. u32 pixclock;
  934. int screen_size, plane;
  935. plane = fbdev->plane;
  936. /* Make sure that the mode respect all LCD controller and
  937. * panel restrictions. */
  938. var->xres = win->w[plane].xres;
  939. var->yres = win->w[plane].yres;
  940. /* No need for virtual resolution support */
  941. var->xres_virtual = var->xres;
  942. var->yres_virtual = var->yres;
  943. var->bits_per_pixel = winbpp(win->w[plane].mode_winctrl1);
  944. screen_size = var->xres_virtual * var->yres_virtual;
  945. if (var->bits_per_pixel > 8) screen_size *= (var->bits_per_pixel / 8);
  946. else screen_size /= (8/var->bits_per_pixel);
  947. if (fbdev->fb_len < screen_size)
  948. return -EINVAL; /* Virtual screen is to big, abort */
  949. /* FIX!!!! what are the implicaitons of ignoring this for windows ??? */
  950. /* The max LCD clock is fixed to 48MHz (value of AUX_CLK). The pixel
  951. * clock can only be obtain by dividing this value by an even integer.
  952. * Fallback to a slower pixel clock if necessary. */
  953. pixclock = max((u32)(PICOS2KHZ(var->pixclock) * 1000), fbi->monspecs.dclkmin);
  954. pixclock = min3(pixclock, fbi->monspecs.dclkmax, (u32)AU1200_LCD_MAX_CLK/2);
  955. if (AU1200_LCD_MAX_CLK % pixclock) {
  956. int diff = AU1200_LCD_MAX_CLK % pixclock;
  957. pixclock -= diff;
  958. }
  959. var->pixclock = KHZ2PICOS(pixclock/1000);
  960. #if 0
  961. if (!panel_is_active(panel)) {
  962. int pcd = AU1200_LCD_MAX_CLK / (pixclock * 2) - 1;
  963. if (!panel_is_color(panel)
  964. && (panel->control_base & LCD_CONTROL_MPI) && (pcd < 3)) {
  965. /* STN 8bit mono panel support is up to 6MHz pixclock */
  966. var->pixclock = KHZ2PICOS(6000);
  967. } else if (!pcd) {
  968. /* Other STN panel support is up to 12MHz */
  969. var->pixclock = KHZ2PICOS(12000);
  970. }
  971. }
  972. #endif
  973. /* Set bitfield accordingly */
  974. switch (var->bits_per_pixel) {
  975. case 16:
  976. {
  977. /* 16bpp True color.
  978. * These must be set to MATCH WINCTRL[FORM] */
  979. int idx;
  980. idx = (win->w[0].mode_winctrl1 & LCD_WINCTRL1_FRM) >> 25;
  981. var->red = rgb_bitfields[idx][0];
  982. var->green = rgb_bitfields[idx][1];
  983. var->blue = rgb_bitfields[idx][2];
  984. var->transp = rgb_bitfields[idx][3];
  985. break;
  986. }
  987. case 32:
  988. {
  989. /* 32bpp True color.
  990. * These must be set to MATCH WINCTRL[FORM] */
  991. int idx;
  992. idx = (win->w[0].mode_winctrl1 & LCD_WINCTRL1_FRM) >> 25;
  993. var->red = rgb_bitfields[idx][0];
  994. var->green = rgb_bitfields[idx][1];
  995. var->blue = rgb_bitfields[idx][2];
  996. var->transp = rgb_bitfields[idx][3];
  997. break;
  998. }
  999. default:
  1000. print_dbg("Unsupported depth %dbpp", var->bits_per_pixel);
  1001. return -EINVAL;
  1002. }
  1003. return 0;
  1004. }
  1005. /* fb_set_par
  1006. * Set hardware with var settings. This will enable the controller with a
  1007. * specific mode, normally validated with the fb_check_var method
  1008. */
  1009. static int au1200fb_fb_set_par(struct fb_info *fbi)
  1010. {
  1011. struct au1200fb_device *fbdev = fbi->par;
  1012. au1200fb_update_fbinfo(fbi);
  1013. au1200_setmode(fbdev);
  1014. return 0;
  1015. }
  1016. /* fb_setcolreg
  1017. * Set color in LCD palette.
  1018. */
  1019. static int au1200fb_fb_setcolreg(unsigned regno, unsigned red, unsigned green,
  1020. unsigned blue, unsigned transp, struct fb_info *fbi)
  1021. {
  1022. volatile u32 *palette = lcd->palette;
  1023. u32 value;
  1024. if (regno > (AU1200_LCD_NBR_PALETTE_ENTRIES - 1))
  1025. return -EINVAL;
  1026. if (fbi->var.grayscale) {
  1027. /* Convert color to grayscale */
  1028. red = green = blue =
  1029. (19595 * red + 38470 * green + 7471 * blue) >> 16;
  1030. }
  1031. if (fbi->fix.visual == FB_VISUAL_TRUECOLOR) {
  1032. /* Place color in the pseudopalette */
  1033. if (regno > 16)
  1034. return -EINVAL;
  1035. palette = (u32*) fbi->pseudo_palette;
  1036. red >>= (16 - fbi->var.red.length);
  1037. green >>= (16 - fbi->var.green.length);
  1038. blue >>= (16 - fbi->var.blue.length);
  1039. value = (red << fbi->var.red.offset) |
  1040. (green << fbi->var.green.offset)|
  1041. (blue << fbi->var.blue.offset);
  1042. value &= 0xFFFF;
  1043. } else if (1 /*FIX!!! panel_is_active(fbdev->panel)*/) {
  1044. /* COLOR TFT PALLETTIZED (use RGB 565) */
  1045. value = (red & 0xF800)|((green >> 5) &
  1046. 0x07E0)|((blue >> 11) & 0x001F);
  1047. value &= 0xFFFF;
  1048. } else if (0 /*panel_is_color(fbdev->panel)*/) {
  1049. /* COLOR STN MODE */
  1050. value = 0x1234;
  1051. value &= 0xFFF;
  1052. } else {
  1053. /* MONOCHROME MODE */
  1054. value = (green >> 12) & 0x000F;
  1055. value &= 0xF;
  1056. }
  1057. palette[regno] = value;
  1058. return 0;
  1059. }
  1060. /* fb_blank
  1061. * Blank the screen. Depending on the mode, the screen will be
  1062. * activated with the backlight color, or desactivated
  1063. */
  1064. static int au1200fb_fb_blank(int blank_mode, struct fb_info *fbi)
  1065. {
  1066. struct au1200fb_device *fbdev = fbi->par;
  1067. /* Short-circuit screen blanking */
  1068. if (noblanking)
  1069. return 0;
  1070. switch (blank_mode) {
  1071. case FB_BLANK_UNBLANK:
  1072. case FB_BLANK_NORMAL:
  1073. /* printk("turn on panel\n"); */
  1074. au1200_setpanel(panel, fbdev->pd);
  1075. break;
  1076. case FB_BLANK_VSYNC_SUSPEND:
  1077. case FB_BLANK_HSYNC_SUSPEND:
  1078. case FB_BLANK_POWERDOWN:
  1079. /* printk("turn off panel\n"); */
  1080. au1200_setpanel(NULL, fbdev->pd);
  1081. break;
  1082. default:
  1083. break;
  1084. }
  1085. /* FB_BLANK_NORMAL is a soft blank */
  1086. return (blank_mode == FB_BLANK_NORMAL) ? -EINVAL : 0;
  1087. }
  1088. /* fb_mmap
  1089. * Map video memory in user space. We don't use the generic fb_mmap
  1090. * method mainly to allow the use of the TLB streaming flag (CCA=6)
  1091. */
  1092. static int au1200fb_fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
  1093. {
  1094. struct au1200fb_device *fbdev = info->par;
  1095. vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  1096. pgprot_val(vma->vm_page_prot) |= _CACHE_MASK; /* CCA=7 */
  1097. return vm_iomap_memory(vma, fbdev->fb_phys, fbdev->fb_len);
  1098. }
  1099. static void set_global(u_int cmd, struct au1200_lcd_global_regs_t *pdata)
  1100. {
  1101. unsigned int hi1, divider;
  1102. /* SCREEN_SIZE: user cannot reset size, must switch panel choice */
  1103. if (pdata->flags & SCREEN_BACKCOLOR)
  1104. lcd->backcolor = pdata->backcolor;
  1105. if (pdata->flags & SCREEN_BRIGHTNESS) {
  1106. // limit brightness pwm duty to >= 30/1600
  1107. if (pdata->brightness < 30) {
  1108. pdata->brightness = 30;
  1109. }
  1110. divider = (lcd->pwmdiv & 0x3FFFF) + 1;
  1111. hi1 = (((pdata->brightness & 0xFF)+1) * divider >> 8);
  1112. lcd->pwmhi &= 0xFFFF;
  1113. lcd->pwmhi |= (hi1 << 16);
  1114. }
  1115. if (pdata->flags & SCREEN_COLORKEY)
  1116. lcd->colorkey = pdata->colorkey;
  1117. if (pdata->flags & SCREEN_MASK)
  1118. lcd->colorkeymsk = pdata->mask;
  1119. wmb(); /* drain writebuffer */
  1120. }
  1121. static void get_global(u_int cmd, struct au1200_lcd_global_regs_t *pdata)
  1122. {
  1123. unsigned int hi1, divider;
  1124. pdata->xsize = ((lcd->screen & LCD_SCREEN_SX) >> 19) + 1;
  1125. pdata->ysize = ((lcd->screen & LCD_SCREEN_SY) >> 8) + 1;
  1126. pdata->backcolor = lcd->backcolor;
  1127. pdata->colorkey = lcd->colorkey;
  1128. pdata->mask = lcd->colorkeymsk;
  1129. // brightness
  1130. hi1 = (lcd->pwmhi >> 16) + 1;
  1131. divider = (lcd->pwmdiv & 0x3FFFF) + 1;
  1132. pdata->brightness = ((hi1 << 8) / divider) - 1;
  1133. wmb(); /* drain writebuffer */
  1134. }
  1135. static void set_window(unsigned int plane,
  1136. struct au1200_lcd_window_regs_t *pdata)
  1137. {
  1138. unsigned int val, bpp;
  1139. /* Window control register 0 */
  1140. if (pdata->flags & WIN_POSITION) {
  1141. val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_OX |
  1142. LCD_WINCTRL0_OY);
  1143. val |= ((pdata->xpos << 21) & LCD_WINCTRL0_OX);
  1144. val |= ((pdata->ypos << 10) & LCD_WINCTRL0_OY);
  1145. lcd->window[plane].winctrl0 = val;
  1146. }
  1147. if (pdata->flags & WIN_ALPHA_COLOR) {
  1148. val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_A);
  1149. val |= ((pdata->alpha_color << 2) & LCD_WINCTRL0_A);
  1150. lcd->window[plane].winctrl0 = val;
  1151. }
  1152. if (pdata->flags & WIN_ALPHA_MODE) {
  1153. val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_AEN);
  1154. val |= ((pdata->alpha_mode << 1) & LCD_WINCTRL0_AEN);
  1155. lcd->window[plane].winctrl0 = val;
  1156. }
  1157. /* Window control register 1 */
  1158. if (pdata->flags & WIN_PRIORITY) {
  1159. val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PRI);
  1160. val |= ((pdata->priority << 30) & LCD_WINCTRL1_PRI);
  1161. lcd->window[plane].winctrl1 = val;
  1162. }
  1163. if (pdata->flags & WIN_CHANNEL) {
  1164. val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PIPE);
  1165. val |= ((pdata->channel << 29) & LCD_WINCTRL1_PIPE);
  1166. lcd->window[plane].winctrl1 = val;
  1167. }
  1168. if (pdata->flags & WIN_BUFFER_FORMAT) {
  1169. val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_FRM);
  1170. val |= ((pdata->buffer_format << 25) & LCD_WINCTRL1_FRM);
  1171. lcd->window[plane].winctrl1 = val;
  1172. }
  1173. if (pdata->flags & WIN_COLOR_ORDER) {
  1174. val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_CCO);
  1175. val |= ((pdata->color_order << 24) & LCD_WINCTRL1_CCO);
  1176. lcd->window[plane].winctrl1 = val;
  1177. }
  1178. if (pdata->flags & WIN_PIXEL_ORDER) {
  1179. val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PO);
  1180. val |= ((pdata->pixel_order << 22) & LCD_WINCTRL1_PO);
  1181. lcd->window[plane].winctrl1 = val;
  1182. }
  1183. if (pdata->flags & WIN_SIZE) {
  1184. val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_SZX |
  1185. LCD_WINCTRL1_SZY);
  1186. val |= (((pdata->xsize << 11) - 1) & LCD_WINCTRL1_SZX);
  1187. val |= (((pdata->ysize) - 1) & LCD_WINCTRL1_SZY);
  1188. lcd->window[plane].winctrl1 = val;
  1189. /* program buffer line width */
  1190. bpp = winbpp(val) / 8;
  1191. val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_BX);
  1192. val |= (((pdata->xsize * bpp) << 8) & LCD_WINCTRL2_BX);
  1193. lcd->window[plane].winctrl2 = val;
  1194. }
  1195. /* Window control register 2 */
  1196. if (pdata->flags & WIN_COLORKEY_MODE) {
  1197. val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_CKMODE);
  1198. val |= ((pdata->colorkey_mode << 24) & LCD_WINCTRL2_CKMODE);
  1199. lcd->window[plane].winctrl2 = val;
  1200. }
  1201. if (pdata->flags & WIN_DOUBLE_BUFFER_MODE) {
  1202. val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_DBM);
  1203. val |= ((pdata->double_buffer_mode << 23) & LCD_WINCTRL2_DBM);
  1204. lcd->window[plane].winctrl2 = val;
  1205. }
  1206. if (pdata->flags & WIN_RAM_ARRAY_MODE) {
  1207. val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_RAM);
  1208. val |= ((pdata->ram_array_mode << 21) & LCD_WINCTRL2_RAM);
  1209. lcd->window[plane].winctrl2 = val;
  1210. }
  1211. /* Buffer line width programmed with WIN_SIZE */
  1212. if (pdata->flags & WIN_BUFFER_SCALE) {
  1213. val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_SCX |
  1214. LCD_WINCTRL2_SCY);
  1215. val |= ((pdata->xsize << 11) & LCD_WINCTRL2_SCX);
  1216. val |= ((pdata->ysize) & LCD_WINCTRL2_SCY);
  1217. lcd->window[plane].winctrl2 = val;
  1218. }
  1219. if (pdata->flags & WIN_ENABLE) {
  1220. val = lcd->winenable;
  1221. val &= ~(1<<plane);
  1222. val |= (pdata->enable & 1) << plane;
  1223. lcd->winenable = val;
  1224. }
  1225. wmb(); /* drain writebuffer */
  1226. }
  1227. static void get_window(unsigned int plane,
  1228. struct au1200_lcd_window_regs_t *pdata)
  1229. {
  1230. /* Window control register 0 */
  1231. pdata->xpos = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_OX) >> 21;
  1232. pdata->ypos = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_OY) >> 10;
  1233. pdata->alpha_color = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_A) >> 2;
  1234. pdata->alpha_mode = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_AEN) >> 1;
  1235. /* Window control register 1 */
  1236. pdata->priority = (lcd->window[plane].winctrl1& LCD_WINCTRL1_PRI) >> 30;
  1237. pdata->channel = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_PIPE) >> 29;
  1238. pdata->buffer_format = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_FRM) >> 25;
  1239. pdata->color_order = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_CCO) >> 24;
  1240. pdata->pixel_order = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_PO) >> 22;
  1241. pdata->xsize = ((lcd->window[plane].winctrl1 & LCD_WINCTRL1_SZX) >> 11) + 1;
  1242. pdata->ysize = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_SZY) + 1;
  1243. /* Window control register 2 */
  1244. pdata->colorkey_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_CKMODE) >> 24;
  1245. pdata->double_buffer_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_DBM) >> 23;
  1246. pdata->ram_array_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_RAM) >> 21;
  1247. pdata->enable = (lcd->winenable >> plane) & 1;
  1248. wmb(); /* drain writebuffer */
  1249. }
  1250. static int au1200fb_ioctl(struct fb_info *info, unsigned int cmd,
  1251. unsigned long arg)
  1252. {
  1253. struct au1200fb_device *fbdev = info->par;
  1254. int plane;
  1255. int val;
  1256. plane = fbinfo2index(info);
  1257. print_dbg("au1200fb: ioctl %d on plane %d\n", cmd, plane);
  1258. if (cmd == AU1200_LCD_FB_IOCTL) {
  1259. struct au1200_lcd_iodata_t iodata;
  1260. if (copy_from_user(&iodata, (void __user *) arg, sizeof(iodata)))
  1261. return -EFAULT;
  1262. print_dbg("FB IOCTL called\n");
  1263. switch (iodata.subcmd) {
  1264. case AU1200_LCD_SET_SCREEN:
  1265. print_dbg("AU1200_LCD_SET_SCREEN\n");
  1266. set_global(cmd, &iodata.global);
  1267. break;
  1268. case AU1200_LCD_GET_SCREEN:
  1269. print_dbg("AU1200_LCD_GET_SCREEN\n");
  1270. get_global(cmd, &iodata.global);
  1271. break;
  1272. case AU1200_LCD_SET_WINDOW:
  1273. print_dbg("AU1200_LCD_SET_WINDOW\n");
  1274. set_window(plane, &iodata.window);
  1275. break;
  1276. case AU1200_LCD_GET_WINDOW:
  1277. print_dbg("AU1200_LCD_GET_WINDOW\n");
  1278. get_window(plane, &iodata.window);
  1279. break;
  1280. case AU1200_LCD_SET_PANEL:
  1281. print_dbg("AU1200_LCD_SET_PANEL\n");
  1282. if ((iodata.global.panel_choice >= 0) &&
  1283. (iodata.global.panel_choice <
  1284. NUM_PANELS))
  1285. {
  1286. struct panel_settings *newpanel;
  1287. panel_index = iodata.global.panel_choice;
  1288. newpanel = &known_lcd_panels[panel_index];
  1289. au1200_setpanel(newpanel, fbdev->pd);
  1290. }
  1291. break;
  1292. case AU1200_LCD_GET_PANEL:
  1293. print_dbg("AU1200_LCD_GET_PANEL\n");
  1294. iodata.global.panel_choice = panel_index;
  1295. break;
  1296. default:
  1297. return -EINVAL;
  1298. }
  1299. val = copy_to_user((void __user *) arg, &iodata, sizeof(iodata));
  1300. if (val) {
  1301. print_dbg("error: could not copy %d bytes\n", val);
  1302. return -EFAULT;
  1303. }
  1304. }
  1305. return 0;
  1306. }
  1307. static struct fb_ops au1200fb_fb_ops = {
  1308. .owner = THIS_MODULE,
  1309. .fb_check_var = au1200fb_fb_check_var,
  1310. .fb_set_par = au1200fb_fb_set_par,
  1311. .fb_setcolreg = au1200fb_fb_setcolreg,
  1312. .fb_blank = au1200fb_fb_blank,
  1313. .fb_fillrect = sys_fillrect,
  1314. .fb_copyarea = sys_copyarea,
  1315. .fb_imageblit = sys_imageblit,
  1316. .fb_read = fb_sys_read,
  1317. .fb_write = fb_sys_write,
  1318. .fb_sync = NULL,
  1319. .fb_ioctl = au1200fb_ioctl,
  1320. .fb_mmap = au1200fb_fb_mmap,
  1321. };
  1322. /*-------------------------------------------------------------------------*/
  1323. static irqreturn_t au1200fb_handle_irq(int irq, void* dev_id)
  1324. {
  1325. /* Nothing to do for now, just clear any pending interrupt */
  1326. lcd->intstatus = lcd->intstatus;
  1327. wmb(); /* drain writebuffer */
  1328. return IRQ_HANDLED;
  1329. }
  1330. /*-------------------------------------------------------------------------*/
  1331. /* AU1200 LCD device probe helpers */
  1332. static int au1200fb_init_fbinfo(struct au1200fb_device *fbdev)
  1333. {
  1334. struct fb_info *fbi = fbdev->fb_info;
  1335. int bpp;
  1336. fbi->fbops = &au1200fb_fb_ops;
  1337. bpp = winbpp(win->w[fbdev->plane].mode_winctrl1);
  1338. /* Copy monitor specs from panel data */
  1339. /* fixme: we're setting up LCD controller windows, so these dont give a
  1340. damn as to what the monitor specs are (the panel itself does, but that
  1341. isn't done here...so maybe need a generic catchall monitor setting??? */
  1342. memcpy(&fbi->monspecs, &panel->monspecs, sizeof(struct fb_monspecs));
  1343. /* We first try the user mode passed in argument. If that failed,
  1344. * or if no one has been specified, we default to the first mode of the
  1345. * panel list. Note that after this call, var data will be set */
  1346. if (!fb_find_mode(&fbi->var,
  1347. fbi,
  1348. NULL, /* drv_info.opt_mode, */
  1349. fbi->monspecs.modedb,
  1350. fbi->monspecs.modedb_len,
  1351. fbi->monspecs.modedb,
  1352. bpp)) {
  1353. print_err("Cannot find valid mode for panel %s", panel->name);
  1354. return -EFAULT;
  1355. }
  1356. fbi->pseudo_palette = kcalloc(16, sizeof(u32), GFP_KERNEL);
  1357. if (!fbi->pseudo_palette) {
  1358. return -ENOMEM;
  1359. }
  1360. if (fb_alloc_cmap(&fbi->cmap, AU1200_LCD_NBR_PALETTE_ENTRIES, 0) < 0) {
  1361. print_err("Fail to allocate colormap (%d entries)",
  1362. AU1200_LCD_NBR_PALETTE_ENTRIES);
  1363. kfree(fbi->pseudo_palette);
  1364. return -EFAULT;
  1365. }
  1366. strncpy(fbi->fix.id, "AU1200", sizeof(fbi->fix.id));
  1367. fbi->fix.smem_start = fbdev->fb_phys;
  1368. fbi->fix.smem_len = fbdev->fb_len;
  1369. fbi->fix.type = FB_TYPE_PACKED_PIXELS;
  1370. fbi->fix.xpanstep = 0;
  1371. fbi->fix.ypanstep = 0;
  1372. fbi->fix.mmio_start = 0;
  1373. fbi->fix.mmio_len = 0;
  1374. fbi->fix.accel = FB_ACCEL_NONE;
  1375. fbi->screen_base = (char __iomem *) fbdev->fb_mem;
  1376. au1200fb_update_fbinfo(fbi);
  1377. return 0;
  1378. }
  1379. /*-------------------------------------------------------------------------*/
  1380. static int au1200fb_setup(struct au1200fb_platdata *pd)
  1381. {
  1382. char *options = NULL;
  1383. char *this_opt, *endptr;
  1384. int num_panels = ARRAY_SIZE(known_lcd_panels);
  1385. int panel_idx = -1;
  1386. fb_get_options(DRIVER_NAME, &options);
  1387. if (!options)
  1388. goto out;
  1389. while ((this_opt = strsep(&options, ",")) != NULL) {
  1390. /* Panel option - can be panel name,
  1391. * "bs" for board-switch, or number/index */
  1392. if (!strncmp(this_opt, "panel:", 6)) {
  1393. int i;
  1394. long int li;
  1395. char *endptr;
  1396. this_opt += 6;
  1397. /* First check for index, which allows
  1398. * to short circuit this mess */
  1399. li = simple_strtol(this_opt, &endptr, 0);
  1400. if (*endptr == '\0')
  1401. panel_idx = (int)li;
  1402. else if (strcmp(this_opt, "bs") == 0)
  1403. panel_idx = pd->panel_index();
  1404. else {
  1405. for (i = 0; i < num_panels; i++) {
  1406. if (!strcmp(this_opt,
  1407. known_lcd_panels[i].name)) {
  1408. panel_idx = i;
  1409. break;
  1410. }
  1411. }
  1412. }
  1413. if ((panel_idx < 0) || (panel_idx >= num_panels))
  1414. print_warn("Panel %s not supported!", this_opt);
  1415. else
  1416. panel_index = panel_idx;
  1417. } else if (strncmp(this_opt, "nohwcursor", 10) == 0)
  1418. nohwcursor = 1;
  1419. else if (strncmp(this_opt, "devices:", 8) == 0) {
  1420. this_opt += 8;
  1421. device_count = simple_strtol(this_opt, &endptr, 0);
  1422. if ((device_count < 0) ||
  1423. (device_count > MAX_DEVICE_COUNT))
  1424. device_count = MAX_DEVICE_COUNT;
  1425. } else if (strncmp(this_opt, "wincfg:", 7) == 0) {
  1426. this_opt += 7;
  1427. window_index = simple_strtol(this_opt, &endptr, 0);
  1428. if ((window_index < 0) ||
  1429. (window_index >= ARRAY_SIZE(windows)))
  1430. window_index = DEFAULT_WINDOW_INDEX;
  1431. } else if (strncmp(this_opt, "off", 3) == 0)
  1432. return 1;
  1433. else
  1434. print_warn("Unsupported option \"%s\"", this_opt);
  1435. }
  1436. out:
  1437. return 0;
  1438. }
  1439. /* AU1200 LCD controller device driver */
  1440. static int au1200fb_drv_probe(struct platform_device *dev)
  1441. {
  1442. struct au1200fb_device *fbdev;
  1443. struct au1200fb_platdata *pd;
  1444. struct fb_info *fbi = NULL;
  1445. unsigned long page;
  1446. int bpp, plane, ret, irq;
  1447. print_info("" DRIVER_DESC "");
  1448. pd = dev->dev.platform_data;
  1449. if (!pd)
  1450. return -ENODEV;
  1451. /* Setup driver with options */
  1452. if (au1200fb_setup(pd))
  1453. return -ENODEV;
  1454. /* Point to the panel selected */
  1455. panel = &known_lcd_panels[panel_index];
  1456. win = &windows[window_index];
  1457. printk(DRIVER_NAME ": Panel %d %s\n", panel_index, panel->name);
  1458. printk(DRIVER_NAME ": Win %d %s\n", window_index, win->name);
  1459. /* shut gcc up */
  1460. ret = 0;
  1461. fbdev = NULL;
  1462. for (plane = 0; plane < device_count; ++plane) {
  1463. bpp = winbpp(win->w[plane].mode_winctrl1);
  1464. if (win->w[plane].xres == 0)
  1465. win->w[plane].xres = panel->Xres;
  1466. if (win->w[plane].yres == 0)
  1467. win->w[plane].yres = panel->Yres;
  1468. fbi = framebuffer_alloc(sizeof(struct au1200fb_device),
  1469. &dev->dev);
  1470. if (!fbi)
  1471. goto failed;
  1472. _au1200fb_infos[plane] = fbi;
  1473. fbdev = fbi->par;
  1474. fbdev->fb_info = fbi;
  1475. fbdev->pd = pd;
  1476. fbdev->plane = plane;
  1477. /* Allocate the framebuffer to the maximum screen size */
  1478. fbdev->fb_len = (win->w[plane].xres * win->w[plane].yres * bpp) / 8;
  1479. fbdev->fb_mem = dmam_alloc_noncoherent(&dev->dev,
  1480. PAGE_ALIGN(fbdev->fb_len),
  1481. &fbdev->fb_phys, GFP_KERNEL);
  1482. if (!fbdev->fb_mem) {
  1483. print_err("fail to allocate frambuffer (size: %dK))",
  1484. fbdev->fb_len / 1024);
  1485. return -ENOMEM;
  1486. }
  1487. /*
  1488. * Set page reserved so that mmap will work. This is necessary
  1489. * since we'll be remapping normal memory.
  1490. */
  1491. for (page = (unsigned long)fbdev->fb_phys;
  1492. page < PAGE_ALIGN((unsigned long)fbdev->fb_phys +
  1493. fbdev->fb_len);
  1494. page += PAGE_SIZE) {
  1495. SetPageReserved(pfn_to_page(page >> PAGE_SHIFT)); /* LCD DMA is NOT coherent on Au1200 */
  1496. }
  1497. print_dbg("Framebuffer memory map at %p", fbdev->fb_mem);
  1498. print_dbg("phys=0x%08x, size=%dK", fbdev->fb_phys, fbdev->fb_len / 1024);
  1499. /* Init FB data */
  1500. if ((ret = au1200fb_init_fbinfo(fbdev)) < 0)
  1501. goto failed;
  1502. /* Register new framebuffer */
  1503. ret = register_framebuffer(fbi);
  1504. if (ret < 0) {
  1505. print_err("cannot register new framebuffer");
  1506. goto failed;
  1507. }
  1508. au1200fb_fb_set_par(fbi);
  1509. #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
  1510. if (plane == 0)
  1511. if (fb_prepare_logo(fbi, FB_ROTATE_UR)) {
  1512. /* Start display and show logo on boot */
  1513. fb_set_cmap(&fbi->cmap, fbi);
  1514. fb_show_logo(fbi, FB_ROTATE_UR);
  1515. }
  1516. #endif
  1517. }
  1518. /* Now hook interrupt too */
  1519. irq = platform_get_irq(dev, 0);
  1520. ret = request_irq(irq, au1200fb_handle_irq,
  1521. IRQF_SHARED, "lcd", (void *)dev);
  1522. if (ret) {
  1523. print_err("fail to request interrupt line %d (err: %d)",
  1524. irq, ret);
  1525. goto failed;
  1526. }
  1527. platform_set_drvdata(dev, pd);
  1528. /* Kickstart the panel */
  1529. au1200_setpanel(panel, pd);
  1530. return 0;
  1531. failed:
  1532. /* NOTE: This only does the current plane/window that failed; others are still active */
  1533. if (fbi) {
  1534. if (fbi->cmap.len != 0)
  1535. fb_dealloc_cmap(&fbi->cmap);
  1536. kfree(fbi->pseudo_palette);
  1537. }
  1538. if (plane == 0)
  1539. free_irq(AU1200_LCD_INT, (void*)dev);
  1540. return ret;
  1541. }
  1542. static int au1200fb_drv_remove(struct platform_device *dev)
  1543. {
  1544. struct au1200fb_platdata *pd = platform_get_drvdata(dev);
  1545. struct au1200fb_device *fbdev;
  1546. struct fb_info *fbi;
  1547. int plane;
  1548. /* Turn off the panel */
  1549. au1200_setpanel(NULL, pd);
  1550. for (plane = 0; plane < device_count; ++plane) {
  1551. fbi = _au1200fb_infos[plane];
  1552. fbdev = fbi->par;
  1553. /* Clean up all probe data */
  1554. unregister_framebuffer(fbi);
  1555. if (fbi->cmap.len != 0)
  1556. fb_dealloc_cmap(&fbi->cmap);
  1557. kfree(fbi->pseudo_palette);
  1558. framebuffer_release(fbi);
  1559. _au1200fb_infos[plane] = NULL;
  1560. }
  1561. free_irq(platform_get_irq(dev, 0), (void *)dev);
  1562. return 0;
  1563. }
  1564. #ifdef CONFIG_PM
  1565. static int au1200fb_drv_suspend(struct device *dev)
  1566. {
  1567. struct au1200fb_platdata *pd = dev_get_drvdata(dev);
  1568. au1200_setpanel(NULL, pd);
  1569. lcd->outmask = 0;
  1570. wmb(); /* drain writebuffer */
  1571. return 0;
  1572. }
  1573. static int au1200fb_drv_resume(struct device *dev)
  1574. {
  1575. struct au1200fb_platdata *pd = dev_get_drvdata(dev);
  1576. struct fb_info *fbi;
  1577. int i;
  1578. /* Kickstart the panel */
  1579. au1200_setpanel(panel, pd);
  1580. for (i = 0; i < device_count; i++) {
  1581. fbi = _au1200fb_infos[i];
  1582. au1200fb_fb_set_par(fbi);
  1583. }
  1584. return 0;
  1585. }
  1586. static const struct dev_pm_ops au1200fb_pmops = {
  1587. .suspend = au1200fb_drv_suspend,
  1588. .resume = au1200fb_drv_resume,
  1589. .freeze = au1200fb_drv_suspend,
  1590. .thaw = au1200fb_drv_resume,
  1591. };
  1592. #define AU1200FB_PMOPS (&au1200fb_pmops)
  1593. #else
  1594. #define AU1200FB_PMOPS NULL
  1595. #endif /* CONFIG_PM */
  1596. static struct platform_driver au1200fb_driver = {
  1597. .driver = {
  1598. .name = "au1200-lcd",
  1599. .pm = AU1200FB_PMOPS,
  1600. },
  1601. .probe = au1200fb_drv_probe,
  1602. .remove = au1200fb_drv_remove,
  1603. };
  1604. module_platform_driver(au1200fb_driver);
  1605. MODULE_DESCRIPTION(DRIVER_DESC);
  1606. MODULE_LICENSE("GPL");