au1200fb.c 48 KB

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