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